@andy.ian/dsh-homing 0.0.0-stage → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (226) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +71 -2
  3. package/bin/auth.mjs +159 -0
  4. package/bin/backup.mjs +118 -0
  5. package/bin/bootstrap-server.mjs +436 -0
  6. package/bin/entry-link.mjs +69 -0
  7. package/bin/nginx-dsh.template.conf +91 -0
  8. package/bin/nginx-gate.conf +9 -0
  9. package/bin/nginx-ws-map.conf +5 -0
  10. package/bin/renew-cert.mjs +127 -0
  11. package/bin/watchdog.mjs +158 -0
  12. package/cordis.patch.yml +30 -0
  13. package/icon.svg +9 -0
  14. package/index.js +3339 -0
  15. package/lib/csrf.mjs +60 -0
  16. package/lib/devices.mjs +221 -0
  17. package/lib/files-page.mjs +391 -0
  18. package/lib/files.mjs +464 -0
  19. package/lib/git.mjs +154 -0
  20. package/lib/limits.mjs +135 -0
  21. package/lib/pty.mjs +354 -0
  22. package/lib/session.mjs +216 -0
  23. package/lib/shell-page.mjs +430 -0
  24. package/lib/shell.mjs +274 -0
  25. package/lib/term-app.js +318 -0
  26. package/lib/term-page.mjs +117 -0
  27. package/lib/vendor/fonts/JetBrainsMono-Regular.ttf +0 -0
  28. package/lib/vendor/fonts/jetbrains-mono-400.woff2 +0 -0
  29. package/lib/vendor/fonts/jetbrains-mono-700.woff2 +0 -0
  30. package/lib/vendor/node_modules/@xterm/addon-fit/LICENSE +19 -0
  31. package/lib/vendor/node_modules/@xterm/addon-fit/README.md +24 -0
  32. package/lib/vendor/node_modules/@xterm/addon-fit/lib/addon-fit.js +2 -0
  33. package/lib/vendor/node_modules/@xterm/addon-fit/lib/addon-fit.js.map +1 -0
  34. package/lib/vendor/node_modules/@xterm/addon-fit/package.json +26 -0
  35. package/lib/vendor/node_modules/@xterm/addon-fit/src/FitAddon.ts +90 -0
  36. package/lib/vendor/node_modules/@xterm/addon-fit/typings/addon-fit.d.ts +55 -0
  37. package/lib/vendor/node_modules/asn1/Jenkinsfile +65 -0
  38. package/lib/vendor/node_modules/asn1/LICENSE +19 -0
  39. package/lib/vendor/node_modules/asn1/README.md +50 -0
  40. package/lib/vendor/node_modules/asn1/lib/ber/errors.js +13 -0
  41. package/lib/vendor/node_modules/asn1/lib/ber/index.js +27 -0
  42. package/lib/vendor/node_modules/asn1/lib/ber/reader.js +262 -0
  43. package/lib/vendor/node_modules/asn1/lib/ber/types.js +36 -0
  44. package/lib/vendor/node_modules/asn1/lib/ber/writer.js +317 -0
  45. package/lib/vendor/node_modules/asn1/lib/index.js +20 -0
  46. package/lib/vendor/node_modules/asn1/package.json +31 -0
  47. package/lib/vendor/node_modules/bcrypt-pbkdf/CONTRIBUTING.md +13 -0
  48. package/lib/vendor/node_modules/bcrypt-pbkdf/LICENSE +66 -0
  49. package/lib/vendor/node_modules/bcrypt-pbkdf/README.md +45 -0
  50. package/lib/vendor/node_modules/bcrypt-pbkdf/index.js +556 -0
  51. package/lib/vendor/node_modules/bcrypt-pbkdf/package.json +15 -0
  52. package/lib/vendor/node_modules/safer-buffer/LICENSE +21 -0
  53. package/lib/vendor/node_modules/safer-buffer/Porting-Buffer.md +268 -0
  54. package/lib/vendor/node_modules/safer-buffer/Readme.md +156 -0
  55. package/lib/vendor/node_modules/safer-buffer/dangerous.js +58 -0
  56. package/lib/vendor/node_modules/safer-buffer/package.json +34 -0
  57. package/lib/vendor/node_modules/safer-buffer/safer.js +77 -0
  58. package/lib/vendor/node_modules/safer-buffer/tests.js +406 -0
  59. package/lib/vendor/node_modules/ssh2/.eslintignore +4 -0
  60. package/lib/vendor/node_modules/ssh2/.eslintrc.js +5 -0
  61. package/lib/vendor/node_modules/ssh2/.github/workflows/ci.yml +110 -0
  62. package/lib/vendor/node_modules/ssh2/.github/workflows/lint.yml +27 -0
  63. package/lib/vendor/node_modules/ssh2/LICENSE +19 -0
  64. package/lib/vendor/node_modules/ssh2/README.md +1529 -0
  65. package/lib/vendor/node_modules/ssh2/SFTP.md +413 -0
  66. package/lib/vendor/node_modules/ssh2/examples/server-chat.js +238 -0
  67. package/lib/vendor/node_modules/ssh2/examples/sftp-server-download-only.js +134 -0
  68. package/lib/vendor/node_modules/ssh2/install.js +27 -0
  69. package/lib/vendor/node_modules/ssh2/lib/Channel.js +295 -0
  70. package/lib/vendor/node_modules/ssh2/lib/agent.js +1123 -0
  71. package/lib/vendor/node_modules/ssh2/lib/client.js +2176 -0
  72. package/lib/vendor/node_modules/ssh2/lib/http-agents.js +84 -0
  73. package/lib/vendor/node_modules/ssh2/lib/index.js +44 -0
  74. package/lib/vendor/node_modules/ssh2/lib/keygen.js +582 -0
  75. package/lib/vendor/node_modules/ssh2/lib/protocol/Protocol.js +2136 -0
  76. package/lib/vendor/node_modules/ssh2/lib/protocol/SFTP.js +4052 -0
  77. package/lib/vendor/node_modules/ssh2/lib/protocol/constants.js +356 -0
  78. package/lib/vendor/node_modules/ssh2/lib/protocol/crypto/binding.gyp +23 -0
  79. package/lib/vendor/node_modules/ssh2/lib/protocol/crypto/poly1305.js +43 -0
  80. package/lib/vendor/node_modules/ssh2/lib/protocol/crypto/src/binding.cc +2300 -0
  81. package/lib/vendor/node_modules/ssh2/lib/protocol/crypto.js +1602 -0
  82. package/lib/vendor/node_modules/ssh2/lib/protocol/handlers.js +16 -0
  83. package/lib/vendor/node_modules/ssh2/lib/protocol/handlers.misc.js +1285 -0
  84. package/lib/vendor/node_modules/ssh2/lib/protocol/kex.js +1908 -0
  85. package/lib/vendor/node_modules/ssh2/lib/protocol/keyParser.js +1484 -0
  86. package/lib/vendor/node_modules/ssh2/lib/protocol/node-fs-compat.js +115 -0
  87. package/lib/vendor/node_modules/ssh2/lib/protocol/utils.js +356 -0
  88. package/lib/vendor/node_modules/ssh2/lib/protocol/zlib.js +255 -0
  89. package/lib/vendor/node_modules/ssh2/lib/server.js +1380 -0
  90. package/lib/vendor/node_modules/ssh2/lib/utils.js +336 -0
  91. package/lib/vendor/node_modules/ssh2/package.json +49 -0
  92. package/lib/vendor/node_modules/ssh2/test/common.js +316 -0
  93. package/lib/vendor/node_modules/ssh2/test/fixtures/bad_rsa_private_key +26 -0
  94. package/lib/vendor/node_modules/ssh2/test/fixtures/https_cert.pem +33 -0
  95. package/lib/vendor/node_modules/ssh2/test/fixtures/https_key.pem +52 -0
  96. package/lib/vendor/node_modules/ssh2/test/fixtures/id_dsa +12 -0
  97. package/lib/vendor/node_modules/ssh2/test/fixtures/id_ecdsa +5 -0
  98. package/lib/vendor/node_modules/ssh2/test/fixtures/id_rsa +15 -0
  99. package/lib/vendor/node_modules/ssh2/test/fixtures/id_rsa.ppk +26 -0
  100. package/lib/vendor/node_modules/ssh2/test/fixtures/id_rsa_enc +30 -0
  101. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa +21 -0
  102. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa.pub +1 -0
  103. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa.pub.result +7 -0
  104. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa.result +7 -0
  105. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc +22 -0
  106. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc.pub +1 -0
  107. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc.pub.result +7 -0
  108. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc.result +7 -0
  109. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc_gcm +23 -0
  110. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc_gcm.pub +1 -0
  111. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc_gcm.pub.result +7 -0
  112. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc_gcm.result +7 -0
  113. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa +9 -0
  114. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa.pub +1 -0
  115. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa.pub.result +7 -0
  116. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa.result +7 -0
  117. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc +10 -0
  118. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc.pub +1 -0
  119. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc.pub.result +8 -0
  120. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc.result +7 -0
  121. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc_gcm +10 -0
  122. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc_gcm.pub +1 -0
  123. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc_gcm.pub.result +8 -0
  124. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc_gcm.result +7 -0
  125. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ed25519 +7 -0
  126. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ed25519.pub +1 -0
  127. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ed25519.pub.result +7 -0
  128. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ed25519.result +7 -0
  129. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa +27 -0
  130. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa.pub +1 -0
  131. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa.pub.result +7 -0
  132. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa.result +7 -0
  133. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc +28 -0
  134. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc.pub +1 -0
  135. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc.pub.result +8 -0
  136. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc.result +7 -0
  137. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc_gcm +29 -0
  138. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc_gcm.pub +1 -0
  139. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc_gcm.pub.result +8 -0
  140. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc_gcm.result +7 -0
  141. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa +12 -0
  142. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa.pub +1 -0
  143. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa.pub.result +7 -0
  144. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa.result +7 -0
  145. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa_enc +15 -0
  146. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa_enc.pub +1 -0
  147. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa_enc.pub.result +8 -0
  148. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa_enc.result +7 -0
  149. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa +5 -0
  150. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa.pub +1 -0
  151. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa.pub.result +7 -0
  152. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa.result +7 -0
  153. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa_enc +8 -0
  154. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa_enc.pub +1 -0
  155. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa_enc.pub.result +8 -0
  156. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa_enc.result +7 -0
  157. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa +27 -0
  158. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa.pub +1 -0
  159. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa.pub.result +7 -0
  160. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa.result +7 -0
  161. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc +30 -0
  162. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc.pub +1 -0
  163. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc.pub.result +8 -0
  164. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc.result +7 -0
  165. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc_aes256 +54 -0
  166. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc_aes256.pub +1 -0
  167. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc_aes256.pub.result +6 -0
  168. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc_aes256.result +6 -0
  169. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_dsa_enc +17 -0
  170. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_dsa_enc.result +7 -0
  171. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_rsa +26 -0
  172. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_rsa.result +7 -0
  173. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_rsa_enc +18 -0
  174. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_rsa_enc.result +7 -0
  175. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa.pub +9 -0
  176. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa.pub.result +7 -0
  177. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa2.pub +10 -0
  178. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa2.pub.result +7 -0
  179. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa3.pub +11 -0
  180. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa3.pub.result +7 -0
  181. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa4.pub +11 -0
  182. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa4.pub.result +7 -0
  183. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa5.pub +8 -0
  184. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa5.pub.result +7 -0
  185. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa6.pub +13 -0
  186. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa6.pub.result +7 -0
  187. package/lib/vendor/node_modules/ssh2/test/fixtures/openssh_new_rsa +27 -0
  188. package/lib/vendor/node_modules/ssh2/test/fixtures/ssh_host_dsa_key +12 -0
  189. package/lib/vendor/node_modules/ssh2/test/fixtures/ssh_host_ecdsa_key +5 -0
  190. package/lib/vendor/node_modules/ssh2/test/fixtures/ssh_host_rsa_key +15 -0
  191. package/lib/vendor/node_modules/ssh2/test/test-exec.js +578 -0
  192. package/lib/vendor/node_modules/ssh2/test/test-integration-openssh.js +486 -0
  193. package/lib/vendor/node_modules/ssh2/test/test-keygen.js +60 -0
  194. package/lib/vendor/node_modules/ssh2/test/test-misc-client-server.js +1460 -0
  195. package/lib/vendor/node_modules/ssh2/test/test-openssh.js +261 -0
  196. package/lib/vendor/node_modules/ssh2/test/test-protocol-crypto.js +631 -0
  197. package/lib/vendor/node_modules/ssh2/test/test-protocol-keyparser.js +177 -0
  198. package/lib/vendor/node_modules/ssh2/test/test-server-hostkeys.js +138 -0
  199. package/lib/vendor/node_modules/ssh2/test/test-sftp.js +842 -0
  200. package/lib/vendor/node_modules/ssh2/test/test-shell.js +109 -0
  201. package/lib/vendor/node_modules/ssh2/test/test-userauth-agent-openssh.js +110 -0
  202. package/lib/vendor/node_modules/ssh2/test/test-userauth-agent.js +171 -0
  203. package/lib/vendor/node_modules/ssh2/test/test-userauth.js +611 -0
  204. package/lib/vendor/node_modules/ssh2/test/test-worker-imports.js +25 -0
  205. package/lib/vendor/node_modules/ssh2/test/test.js +20 -0
  206. package/lib/vendor/node_modules/ssh2/util/build_pagent.bat +2 -0
  207. package/lib/vendor/node_modules/ssh2/util/pagent.c +88 -0
  208. package/lib/vendor/node_modules/ssh2/util/pagent.exe +0 -0
  209. package/lib/vendor/node_modules/tweetnacl/AUTHORS.md +27 -0
  210. package/lib/vendor/node_modules/tweetnacl/CHANGELOG.md +283 -0
  211. package/lib/vendor/node_modules/tweetnacl/LICENSE +24 -0
  212. package/lib/vendor/node_modules/tweetnacl/PULL_REQUEST_TEMPLATE.md +20 -0
  213. package/lib/vendor/node_modules/tweetnacl/README.md +494 -0
  214. package/lib/vendor/node_modules/tweetnacl/nacl-fast.js +2391 -0
  215. package/lib/vendor/node_modules/tweetnacl/nacl-fast.min.js +1 -0
  216. package/lib/vendor/node_modules/tweetnacl/nacl.d.ts +98 -0
  217. package/lib/vendor/node_modules/tweetnacl/nacl.js +1178 -0
  218. package/lib/vendor/node_modules/tweetnacl/nacl.min.js +1 -0
  219. package/lib/vendor/node_modules/tweetnacl/package.json +56 -0
  220. package/lib/vendor/xterm.css +218 -0
  221. package/lib/vendor/xterm.js +2 -0
  222. package/locale/en.json +6 -0
  223. package/locale/zh.json +6 -0
  224. package/ops/watchdog/dsh-watchdog.ps1 +105 -0
  225. package/ops/watchdog/restart-now.ps1 +247 -0
  226. package/package.json +69 -4
package/locale/en.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Mobile Access",
4
+ "description": "Expose this DSH to your phone or WeChat browser through an SSH reverse tunnel: HTTPS, sign-in, and mobile layout fixes. Starts with DSH."
5
+ }
6
+ }
package/locale/zh.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "手机访问",
4
+ "description": "通过 SSH 反向隧道把本机 DSH 安全开放到手机/微信浏览器:HTTPS、账号登录、移动端布局适配,随 DSH 自动启动。"
5
+ }
6
+ }
@@ -0,0 +1,105 @@
1
+ # DSH 看门狗:每 5 分钟检查一次,DSH 没跑就拉起来,连续不健康就重启。
2
+ # 设计原则:只在"确实不健康"时动手,避免把正在启动的进程误杀。
3
+ $ErrorActionPreference = 'SilentlyContinue'
4
+
5
+ $root = Join-Path $env:USERPROFILE '.dsh\watchdog'
6
+ New-Item -ItemType Directory -Force -Path $root | Out-Null
7
+ $logFile = Join-Path $root 'watchdog.log'
8
+ $stateFile = Join-Path $root 'state.json'
9
+
10
+ $exe = Find-DshExe
11
+ $procName = 'DeepSeek Harness'
12
+
13
+ /**
14
+ * 找 DeepSeek Harness 的可执行文件。
15
+ * 不能写死路径:换台电脑后用户名和安装位置都可能不同。
16
+ */
17
+ function Find-DshExe {
18
+ $candidates = @(
19
+ (Join-Path $env:LOCALAPPDATA 'Programs\DeepSeek Harness\DeepSeek Harness.exe'),
20
+ (Join-Path $env:ProgramFiles 'DeepSeek Harness\DeepSeek Harness.exe'),
21
+ (Join-Path ${env:ProgramFiles(x86)} 'DeepSeek Harness\DeepSeek Harness.exe'),
22
+ (Join-Path $env:ProgramData 'DeepSeek Harness\DeepSeek Harness.exe')
23
+ )
24
+ foreach ($candidate in $candidates) {
25
+ if ($candidate -and (Test-Path -LiteralPath $candidate)) { return $candidate }
26
+ }
27
+ # 兜底:正在运行的进程能告诉我们它装在哪
28
+ $running = Get-Process -Name 'DeepSeek Harness' -ErrorAction SilentlyContinue | Select-Object -First 1
29
+ if ($running -and $running.Path) { return $running.Path }
30
+ return $null
31
+ }
32
+ # 健康判据:进程存在,且它自己至少有一个 LISTEN 端口。
33
+ # 不写死端口号 —— DSH Web 每次启动可能换端口(实测 57291 → 56218),
34
+ # 写死会把健康实例误判成故障,反复重启。
35
+ $failThreshold = 3
36
+ $startupGraceSeconds = 180
37
+
38
+ function Write-Log([string]$message) {
39
+ $line = '{0} {1}' -f (Get-Date -Format 'yyyy-MM-dd HH:mm:ss'), $message
40
+ Add-Content -LiteralPath $logFile -Value $line -Encoding UTF8
41
+ try {
42
+ $all = @(Get-Content -LiteralPath $logFile)
43
+ if ($all.Count -gt 2000) {
44
+ $all | Select-Object -Last 1500 | Set-Content -LiteralPath $logFile -Encoding UTF8
45
+ }
46
+ }
47
+ catch { }
48
+ }
49
+
50
+ function Test-Port([int]$port) {
51
+ $client = New-Object System.Net.Sockets.TcpClient
52
+ try {
53
+ $iar = $client.BeginConnect('127.0.0.1', $port, $null, $null)
54
+ if (-not $iar.AsyncWaitHandle.WaitOne(1200)) { return $false }
55
+ $client.EndConnect($iar)
56
+ return $true
57
+ }
58
+ catch { return $false }
59
+ finally { $client.Close() }
60
+ }
61
+
62
+ $failures = 0
63
+ if (Test-Path -LiteralPath $stateFile) {
64
+ try { $failures = [int](Get-Content -LiteralPath $stateFile -Raw | ConvertFrom-Json).failures } catch { $failures = 0 }
65
+ }
66
+
67
+ $processes = @(Get-Process -Name $procName -ErrorAction SilentlyContinue)
68
+
69
+ if ($processes.Count -eq 0) {
70
+ Write-Log 'DSH 未运行 -> 启动'
71
+ Start-Process -FilePath $exe | Out-Null
72
+ $failures = 0
73
+ }
74
+ else {
75
+ # 最新启动的那个进程刚起来的话,给足启动时间,不计数
76
+ $newest = $processes | Sort-Object StartTime -Descending | Select-Object -First 1
77
+ $ageSeconds = if ($newest.StartTime) { ((Get-Date) - $newest.StartTime).TotalSeconds } else { 9999 }
78
+
79
+ $listening = @(Get-NetTCPConnection -State Listen -ErrorAction SilentlyContinue |
80
+ Where-Object { $processes.Id -contains $_.OwningProcess } |
81
+ Select-Object -ExpandProperty LocalPort -Unique)
82
+ $down = if ($listening.Count -eq 0) { @('none') } else { @() }
83
+
84
+ if ($down.Count -eq 0) {
85
+ if ($failures -ne 0) { Write-Log "已恢复正常(之前累计 $failures 次)" } else { Write-Log '检查: 健康' }
86
+ $failures = 0
87
+ }
88
+ elseif ($ageSeconds -lt $startupGraceSeconds) {
89
+ Write-Log ('启动中,暂不计数(已运行 {0:N0} 秒,缺端口 {1})' -f $ageSeconds, ($down -join ','))
90
+ }
91
+ else {
92
+ $failures += 1
93
+ Write-Log ('没有任何监听端口(连续第 {0} 次)' -f $failures)
94
+ if ($failures -ge $failThreshold) {
95
+ Write-Log "连续 $failThreshold 次不健康 -> 重启 DSH"
96
+ $processes | Stop-Process -Force
97
+ Start-Sleep -Seconds 5
98
+ Start-Process -FilePath $exe | Out-Null
99
+ $failures = 0
100
+ }
101
+ }
102
+ }
103
+
104
+ @{ failures = $failures; checkedAt = (Get-Date).ToString('o') } | ConvertTo-Json |
105
+ Set-Content -LiteralPath $stateFile -Encoding UTF8
@@ -0,0 +1,247 @@
1
+ # 一次性重启 DSH:由计划任务(或手动)独立执行,不依赖被重启的进程本身。
2
+ #
3
+ # 两种模式(关键区别就是"等多久"):
4
+ # -Mode immediate 用户说了"立马重启":这边一空下来(没有在途对话、没有键盘/点击活动)
5
+ # 就立刻重启,安静阈值默认 3 秒。
6
+ # -Mode default 默认保守模式:安静 120 秒才算空闲,宁可晚一点也不打断。
7
+ #
8
+ # 用法:
9
+ # powershell -File restart-now.ps1 -Mode immediate -Reason "部署 v1.15.0"
10
+ # powershell -File restart-now.ps1 # 等同 -Mode default
11
+ # powershell -File restart-now.ps1 -Check # 只体检,不杀不启(安全)
12
+ # powershell -File restart-now.ps1 -DryRun # 走完整逻辑但不杀不启
13
+ #
14
+ # 流程:抢锁 -> **等空闲** -> 优雅关闭 -> 强杀兜底 -> 等端口释放 -> 启动 -> 等就绪 -> 写日志 -> 删任务 -> 放锁
15
+ #
16
+ # 硬规则(都是被坑出来的):
17
+ # 1. 同一时刻只允许一个重启在跑(restart.lock),否则会出现两个实例抢 8787;
18
+ # 2. 端口没释放干净就**不要启动**(宁可失败也不要 EADDRINUSE 半死不活);
19
+ # 3. 每次重启都记录触发原因,方便事后看"到底谁让它重启的";
20
+ # 4. **用户还在操作就不许重启**:会话文件在写、或手机端还在敲键盘/滑动(activity.json 信标),
21
+ # 都算"忙";等不到空闲就放弃(人可以再叫一次)。
22
+ param(
23
+ [switch]$Check,
24
+ [switch]$DryRun,
25
+ [ValidateSet('immediate', 'default')]
26
+ [string]$Mode = 'default',
27
+ [string]$Reason = '未注明',
28
+ [int]$IdleSeconds = -1,
29
+ [int]$MaxWaitMinutes = 10
30
+ )
31
+
32
+ $ErrorActionPreference = 'SilentlyContinue'
33
+
34
+ $root = Join-Path $env:USERPROFILE '.dsh\watchdog'
35
+ $log = Join-Path $root 'restart.log'
36
+ $lockFile = Join-Path $root 'restart.lock'
37
+ $sessionsDir = Join-Path $env:USERPROFILE '.dsh\storages\session_projcache\sessions'
38
+ $activityFile = Join-Path $env:USERPROFILE '.dsh\integrations\dsh-mobile\activity.json'
39
+ $exe = Find-DshExe
40
+ $procName = 'DeepSeek Harness'
41
+
42
+ /**
43
+ * 找 DeepSeek Harness 的可执行文件。
44
+ * 不能写死路径:换台电脑后用户名和安装位置都可能不同。
45
+ */
46
+ function Find-DshExe {
47
+ $candidates = @(
48
+ (Join-Path $env:LOCALAPPDATA 'Programs\DeepSeek Harness\DeepSeek Harness.exe'),
49
+ (Join-Path $env:ProgramFiles 'DeepSeek Harness\DeepSeek Harness.exe'),
50
+ (Join-Path ${env:ProgramFiles(x86)} 'DeepSeek Harness\DeepSeek Harness.exe'),
51
+ (Join-Path $env:ProgramData 'DeepSeek Harness\DeepSeek Harness.exe')
52
+ )
53
+ foreach ($candidate in $candidates) {
54
+ if ($candidate -and (Test-Path -LiteralPath $candidate)) { return $candidate }
55
+ }
56
+ # 兜底:正在运行的进程能告诉我们它装在哪
57
+ $running = Get-Process -Name 'DeepSeek Harness' -ErrorAction SilentlyContinue | Select-Object -First 1
58
+ if ($running -and $running.Path) { return $running.Path }
59
+ return $null
60
+ }
61
+ $bridgePort = 8787
62
+
63
+ # 安静阈值:immediate 只要 3 秒(用户明确要求"一空闲就重启"),default 保持 120 秒
64
+ if ($IdleSeconds -lt 0) {
65
+ $IdleSeconds = if ($Mode -eq 'immediate') { 3 } else { 120 }
66
+ }
67
+
68
+ # 两个活动信号取"最近的":
69
+ # - 会话 json 的修改时间:一轮对话在跑时会不断更新
70
+ # - activity.json:手机端键盘/触摸信标(打字时不会改会话文件,只有这个能反映"人在用")
71
+ function Get-Activity {
72
+ $age = 99999
73
+ $source = 'none'
74
+ if (Test-Path $sessionsDir) {
75
+ $newest = Get-ChildItem -LiteralPath $sessionsDir -Filter *.json -ErrorAction SilentlyContinue |
76
+ Sort-Object LastWriteTime -Descending | Select-Object -First 1
77
+ if ($newest) { $age = ((Get-Date) - $newest.LastWriteTime).TotalSeconds; $source = 'session:' + $newest.Name }
78
+ }
79
+ if (Test-Path $activityFile) {
80
+ $stamp = (Get-Item $activityFile).LastWriteTime
81
+ $age2 = ((Get-Date) - $stamp).TotalSeconds
82
+ if ($age2 -lt $age) { $age = $age2; $source = 'beacon' }
83
+ }
84
+ return @{ ageSeconds = $age; source = $source }
85
+ }
86
+
87
+ function Test-Idle {
88
+ $activity = Get-Activity
89
+ return @{ idle = ($activity.ageSeconds -ge $IdleSeconds); age = $activity.ageSeconds; source = $activity.source }
90
+ }
91
+
92
+
93
+ function Write-Log([string]$message) {
94
+ $line = '{0} {1}' -f (Get-Date -Format 'yyyy-MM-dd HH:mm:ss'), $message
95
+ Add-Content -LiteralPath $log -Value $line -Encoding UTF8
96
+ }
97
+
98
+ function Test-Port([int]$port) {
99
+ $client = New-Object System.Net.Sockets.TcpClient
100
+ try {
101
+ $iar = $client.BeginConnect('127.0.0.1', $port, $null, $null)
102
+ if (-not $iar.AsyncWaitHandle.WaitOne(1000)) { return $false }
103
+ $client.EndConnect($iar)
104
+ return $true
105
+ }
106
+ catch { return $false }
107
+ finally { $client.Close() }
108
+ }
109
+
110
+ function Get-DshProcesses {
111
+ return @(Get-Process -Name $procName -ErrorAction SilentlyContinue)
112
+ }
113
+
114
+ # ---------- 体检模式:只看状态,不动任何东西 ----------
115
+ if ($Check) {
116
+ $procs = Get-DshProcesses
117
+ Write-Output ("进程数: " + $procs.Count)
118
+ $procs | ForEach-Object { Write-Output (" PID " + $_.Id + " 启动 " + $_.StartTime) }
119
+ Write-Output ("8787 监听: " + (Test-Port $bridgePort))
120
+ $idle = Test-Idle
121
+ Write-Output ("活动信号: 最近 {0:N0} 秒前(来源 {1}) -> {2}" -f $idle.age, $idle.source, $(if ($idle.idle) { '空闲,可重启' } else { '活跃,不应重启' }))
122
+ Write-Output ("判定阈值: 空闲需静默 " + $IdleSeconds + " 秒")
123
+ Write-Output ("锁文件存在: " + (Test-Path $lockFile))
124
+ $task = Get-ScheduledTask -TaskName 'DSH-Restart-Now' -ErrorAction SilentlyContinue
125
+ Write-Output ("待执行重启任务: " + $(if ($task) { $task.State } else { '无' }))
126
+ Write-Output ("最近一次重启: " + ((Get-Content $log -Tail 1) -join ''))
127
+ exit 0
128
+ }
129
+
130
+ # ---------- 抢锁:防止两个重启同时跑 ----------
131
+ # 特例:immediate 允许**抢占**正在等待的 default。
132
+ # 场景:先排了 default 在等 120 秒空闲,用户改口"立马重启"——不该被锁挡回去,
133
+ # 而应停掉那个等待中的进程,立刻按立即模式执行。
134
+ if (Test-Path $lockFile) {
135
+ $age = (Get-Date) - (Get-Item $lockFile).LastWriteTime
136
+ if ($age.TotalSeconds -lt 180) {
137
+ if ($Mode -eq 'immediate') {
138
+ Write-Log ('立即模式抢占:停掉正在等待的重启(锁 {0:N0} 秒前创建)' -f $age.TotalSeconds)
139
+ $mine = $PID
140
+ Get-CimInstance Win32_Process -Filter "Name = 'powershell.exe'" -ErrorAction SilentlyContinue |
141
+ Where-Object { $_.CommandLine -like '*restart-now.ps1*' -and $_.ProcessId -ne $mine } |
142
+ ForEach-Object {
143
+ Write-Log (' 终止等待进程 PID ' + $_.ProcessId)
144
+ Stop-Process -Id $_.ProcessId -Force -ErrorAction SilentlyContinue
145
+ }
146
+ Start-Sleep -Seconds 1
147
+ Remove-Item $lockFile -Force -ErrorAction SilentlyContinue
148
+ }
149
+ else {
150
+ Write-Log ("跳过:已有重启在进行(锁 {0:N0} 秒前创建;要抢占请用 -Mode immediate)" -f $age.TotalSeconds)
151
+ exit 1
152
+ }
153
+ }
154
+ else {
155
+ Write-Log ("清理过期锁({0:N0} 秒前)" -f $age.TotalSeconds)
156
+ Remove-Item $lockFile -Force -ErrorAction SilentlyContinue
157
+ }
158
+ }
159
+ Set-Content -LiteralPath $lockFile -Value (Get-Date -Format 'o') -Encoding UTF8
160
+
161
+ try {
162
+ Write-Log ("=== 重启请求(模式:{0},安静阈值 {1}s,原因:{2}){3}===" -f $Mode, $IdleSeconds, $Reason, $(if ($DryRun) { ' [DryRun]' } else { '' }))
163
+
164
+ # ---------- 关键:等会话空闲,别在别人对话中途把进程杀掉 ----------
165
+ $waitStart = Get-Date
166
+ $deferred = $false
167
+ while ($true) {
168
+ $idle = Test-Idle
169
+ if ($idle.idle) {
170
+ Write-Log ("已空闲(最近活动 {0:N0} 秒前,来源 {1},阈值 {2} 秒)-> 继续重启" -f $idle.age, $idle.source, $IdleSeconds)
171
+ break
172
+ }
173
+ $waited = ((Get-Date) - $waitStart).TotalMinutes
174
+ if ($waited -ge $MaxWaitMinutes) {
175
+ Write-Log ("放弃重启:仍在活跃(最近活动 {0:N0} 秒前,来源 {1},已等待 {2:N1} 分钟)" -f $idle.age, $idle.source, $waited)
176
+ Write-Log '=== 重启结束(因会话活跃而放弃)==='
177
+ $deferred = $true
178
+ break
179
+ }
180
+ if ($waited -eq 0 -or [int]($waited * 4) -ne [int](($waited - 0.05) * 4)) {
181
+ Write-Log ("等空闲…(最近活动 {0:N0} 秒前,来源 {1},已等 {2:N0} 秒)" -f $idle.age, $idle.source, ($waited * 60))
182
+ }
183
+ Start-Sleep -Seconds 15
184
+ }
185
+ if ($deferred) { exit 2 }
186
+
187
+ if ($DryRun) {
188
+ $procs = Get-DshProcesses
189
+ Write-Log ("[DryRun] 到这里会关闭 {0} 个进程并重启;本次不执行" -f $procs.Count)
190
+ Write-Log '=== 重启结束(DryRun)==='
191
+ exit 0
192
+ }
193
+
194
+ $before = Get-DshProcesses
195
+ Write-Log ("关闭前进程数:{0}" -f $before.Count)
196
+
197
+ if ($before.Count -gt 0) {
198
+ $before | ForEach-Object { $_.CloseMainWindow() | Out-Null }
199
+ Start-Sleep -Seconds 4
200
+ $left = Get-DshProcesses
201
+ if ($left.Count -gt 0) {
202
+ Write-Log ("仍有 {0} 个进程,强制结束" -f $left.Count)
203
+ $left | Stop-Process -Force
204
+ Start-Sleep -Seconds 3
205
+ }
206
+ }
207
+
208
+ $still = Get-DshProcesses
209
+ Write-Log ("关闭后进程数:{0}" -f $still.Count)
210
+
211
+ # 端口必须释放干净;释放不了就失败退出,绝不硬起第二个实例
212
+ $waited = 0
213
+ while ($waited -lt 60 -and (Test-Port $bridgePort)) {
214
+ Start-Sleep -Milliseconds 500
215
+ $waited += 1
216
+ }
217
+ if (Test-Port $bridgePort) {
218
+ Write-Log ("失败:8787 仍被占用(等待 {0} 次),已放弃启动以避免双实例" -f $waited)
219
+ Write-Log '=== 重启结束(失败)==='
220
+ exit 1
221
+ }
222
+ Write-Log ("8787 已释放(等待 {0} 次)" -f $waited)
223
+
224
+ Start-Process -FilePath $exe
225
+ Write-Log '已发起启动'
226
+
227
+ # 就绪判断:进程活着 + 8787 在听
228
+ $ok = $false
229
+ for ($i = 0; $i -lt 120; $i += 1) {
230
+ Start-Sleep -Seconds 1
231
+ if ((Get-DshProcesses).Count -gt 0 -and (Test-Port $bridgePort)) { $ok = $true; break }
232
+ }
233
+ $main = Get-DshProcesses | Sort-Object StartTime | Select-Object -First 1
234
+ Write-Log ("启动结果:{0};首次进程启动时间 {1};8787 监听 {2}" -f `
235
+ $(if ($ok) { '成功' } else { '超时未就绪' }), $main.StartTime, (Test-Port $bridgePort))
236
+
237
+ $entry = Join-Path $env:USERPROFILE '.dsh\integrations\dsh-mobile\entry.txt'
238
+ if (Test-Path $entry) {
239
+ Write-Log ("entry.txt 更新时间:{0}" -f (Get-Item $entry).LastWriteTime)
240
+ }
241
+ Write-Log '=== 重启结束 ==='
242
+ }
243
+ finally {
244
+ Remove-Item $lockFile -Force
245
+ # 无论成功失败都删掉一次性任务,避免下次意外又触发
246
+ schtasks /Delete /TN 'DSH-Restart-Now' /F 2>$null | Out-Null
247
+ }
package/package.json CHANGED
@@ -1,6 +1,71 @@
1
1
  {
2
2
  "name": "@andy.ian/dsh-homing",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "2.0.0",
4
+ "type": "module",
5
+ "description": "把本机 DSH 通过 SSH 反向隧道安全开放到手机浏览器:TLS 端到端(服务器只透传)、账号 + TOTP、局域网与公网双入口,随 DSH 启动。",
6
+ "keywords": [
7
+ "dsh",
8
+ "deepseek-harness",
9
+ "cordis",
10
+ "plugin",
11
+ "remote-access",
12
+ "tunnel",
13
+ "https",
14
+ "totp",
15
+ "remote",
16
+ "gateway",
17
+ "homing"
18
+ ],
19
+ "license": "MIT",
20
+ "author": "andy.ian",
21
+ "homepage": "https://www.npmjs.com/package/@andy.ian/dsh-homing",
22
+ "engines": {
23
+ "node": ">=20"
24
+ },
25
+ "icon": "./icon.svg",
26
+ "bin": {
27
+ "dsh-homing-bootstrap": "./bin/bootstrap-server.mjs",
28
+ "dsh-homing-renew-cert": "./bin/renew-cert.mjs",
29
+ "dsh-homing-auth": "./bin/auth.mjs",
30
+ "dsh-homing-backup": "./bin/backup.mjs",
31
+ "dsh-homing-entry": "./bin/entry-link.mjs",
32
+ "dsh-homing-watchdog": "./bin/watchdog.mjs"
33
+ },
34
+ "exports": {
35
+ ".": "./index.js",
36
+ "./locale/*.json": "./locale/*.json",
37
+ "./icon": "./icon.svg"
38
+ },
39
+ "files": [
40
+ "index.js",
41
+ "bin/bootstrap-server.mjs",
42
+ "bin/entry-link.mjs",
43
+ "bin/renew-cert.mjs",
44
+ "bin/auth.mjs",
45
+ "bin/backup.mjs",
46
+ "bin/nginx-dsh.template.conf",
47
+ "bin/nginx-gate.conf",
48
+ "bin/nginx-ws-map.conf",
49
+ "lib/*.mjs",
50
+ "lib/*.js",
51
+ "cordis.patch.yml",
52
+ "locale/*.json",
53
+ "icon.svg",
54
+ "README.md",
55
+ "LICENSE",
56
+ "lib/vendor/**",
57
+ "ops/**"
58
+ ],
59
+ "publishConfig": {
60
+ "access": "public",
61
+ "registry": "https://registry.npmjs.org/"
62
+ },
63
+ "dsh": {
64
+ "bundle": {
65
+ "patch": "./cordis.patch.yml"
66
+ }
67
+ },
68
+ "scripts": {
69
+ "test": "node --test --test-concurrency=1"
70
+ }
71
+ }