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

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 (230) 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/supervisor.mjs +488 -0
  12. package/bin/watchdog.mjs +163 -0
  13. package/client.js +79 -0
  14. package/cordis.patch.yml +30 -0
  15. package/icon.svg +9 -0
  16. package/index.js +3526 -0
  17. package/lib/csrf.mjs +60 -0
  18. package/lib/devices.mjs +221 -0
  19. package/lib/files-page.mjs +592 -0
  20. package/lib/files.mjs +551 -0
  21. package/lib/git.mjs +154 -0
  22. package/lib/limits.mjs +135 -0
  23. package/lib/pty.mjs +361 -0
  24. package/lib/session.mjs +216 -0
  25. package/lib/shell-page.mjs +430 -0
  26. package/lib/shell.mjs +274 -0
  27. package/lib/term-app.js +318 -0
  28. package/lib/term-page.mjs +117 -0
  29. package/lib/vendor/fonts/JetBrainsMono-Regular.ttf +0 -0
  30. package/lib/vendor/fonts/jetbrains-mono-400.woff2 +0 -0
  31. package/lib/vendor/fonts/jetbrains-mono-700.woff2 +0 -0
  32. package/lib/vendor/node_modules/@xterm/addon-fit/LICENSE +19 -0
  33. package/lib/vendor/node_modules/@xterm/addon-fit/README.md +24 -0
  34. package/lib/vendor/node_modules/@xterm/addon-fit/lib/addon-fit.js +2 -0
  35. package/lib/vendor/node_modules/@xterm/addon-fit/lib/addon-fit.js.map +1 -0
  36. package/lib/vendor/node_modules/@xterm/addon-fit/package.json +26 -0
  37. package/lib/vendor/node_modules/@xterm/addon-fit/src/FitAddon.ts +90 -0
  38. package/lib/vendor/node_modules/@xterm/addon-fit/typings/addon-fit.d.ts +55 -0
  39. package/lib/vendor/node_modules/asn1/Jenkinsfile +65 -0
  40. package/lib/vendor/node_modules/asn1/LICENSE +19 -0
  41. package/lib/vendor/node_modules/asn1/README.md +50 -0
  42. package/lib/vendor/node_modules/asn1/lib/ber/errors.js +13 -0
  43. package/lib/vendor/node_modules/asn1/lib/ber/index.js +27 -0
  44. package/lib/vendor/node_modules/asn1/lib/ber/reader.js +262 -0
  45. package/lib/vendor/node_modules/asn1/lib/ber/types.js +36 -0
  46. package/lib/vendor/node_modules/asn1/lib/ber/writer.js +317 -0
  47. package/lib/vendor/node_modules/asn1/lib/index.js +20 -0
  48. package/lib/vendor/node_modules/asn1/package.json +31 -0
  49. package/lib/vendor/node_modules/bcrypt-pbkdf/CONTRIBUTING.md +13 -0
  50. package/lib/vendor/node_modules/bcrypt-pbkdf/LICENSE +66 -0
  51. package/lib/vendor/node_modules/bcrypt-pbkdf/README.md +45 -0
  52. package/lib/vendor/node_modules/bcrypt-pbkdf/index.js +556 -0
  53. package/lib/vendor/node_modules/bcrypt-pbkdf/package.json +15 -0
  54. package/lib/vendor/node_modules/safer-buffer/LICENSE +21 -0
  55. package/lib/vendor/node_modules/safer-buffer/Porting-Buffer.md +268 -0
  56. package/lib/vendor/node_modules/safer-buffer/Readme.md +156 -0
  57. package/lib/vendor/node_modules/safer-buffer/dangerous.js +58 -0
  58. package/lib/vendor/node_modules/safer-buffer/package.json +34 -0
  59. package/lib/vendor/node_modules/safer-buffer/safer.js +77 -0
  60. package/lib/vendor/node_modules/safer-buffer/tests.js +406 -0
  61. package/lib/vendor/node_modules/ssh2/.eslintignore +4 -0
  62. package/lib/vendor/node_modules/ssh2/.eslintrc.js +5 -0
  63. package/lib/vendor/node_modules/ssh2/.github/workflows/ci.yml +110 -0
  64. package/lib/vendor/node_modules/ssh2/.github/workflows/lint.yml +27 -0
  65. package/lib/vendor/node_modules/ssh2/LICENSE +19 -0
  66. package/lib/vendor/node_modules/ssh2/README.md +1529 -0
  67. package/lib/vendor/node_modules/ssh2/SFTP.md +413 -0
  68. package/lib/vendor/node_modules/ssh2/examples/server-chat.js +238 -0
  69. package/lib/vendor/node_modules/ssh2/examples/sftp-server-download-only.js +134 -0
  70. package/lib/vendor/node_modules/ssh2/install.js +27 -0
  71. package/lib/vendor/node_modules/ssh2/lib/Channel.js +295 -0
  72. package/lib/vendor/node_modules/ssh2/lib/agent.js +1123 -0
  73. package/lib/vendor/node_modules/ssh2/lib/client.js +2176 -0
  74. package/lib/vendor/node_modules/ssh2/lib/http-agents.js +84 -0
  75. package/lib/vendor/node_modules/ssh2/lib/index.js +44 -0
  76. package/lib/vendor/node_modules/ssh2/lib/keygen.js +582 -0
  77. package/lib/vendor/node_modules/ssh2/lib/protocol/Protocol.js +2136 -0
  78. package/lib/vendor/node_modules/ssh2/lib/protocol/SFTP.js +4052 -0
  79. package/lib/vendor/node_modules/ssh2/lib/protocol/constants.js +356 -0
  80. package/lib/vendor/node_modules/ssh2/lib/protocol/crypto/binding.gyp +23 -0
  81. package/lib/vendor/node_modules/ssh2/lib/protocol/crypto/poly1305.js +43 -0
  82. package/lib/vendor/node_modules/ssh2/lib/protocol/crypto/src/binding.cc +2300 -0
  83. package/lib/vendor/node_modules/ssh2/lib/protocol/crypto.js +1602 -0
  84. package/lib/vendor/node_modules/ssh2/lib/protocol/handlers.js +16 -0
  85. package/lib/vendor/node_modules/ssh2/lib/protocol/handlers.misc.js +1285 -0
  86. package/lib/vendor/node_modules/ssh2/lib/protocol/kex.js +1908 -0
  87. package/lib/vendor/node_modules/ssh2/lib/protocol/keyParser.js +1484 -0
  88. package/lib/vendor/node_modules/ssh2/lib/protocol/node-fs-compat.js +115 -0
  89. package/lib/vendor/node_modules/ssh2/lib/protocol/utils.js +356 -0
  90. package/lib/vendor/node_modules/ssh2/lib/protocol/zlib.js +255 -0
  91. package/lib/vendor/node_modules/ssh2/lib/server.js +1380 -0
  92. package/lib/vendor/node_modules/ssh2/lib/utils.js +336 -0
  93. package/lib/vendor/node_modules/ssh2/package.json +49 -0
  94. package/lib/vendor/node_modules/ssh2/test/common.js +316 -0
  95. package/lib/vendor/node_modules/ssh2/test/fixtures/bad_rsa_private_key +26 -0
  96. package/lib/vendor/node_modules/ssh2/test/fixtures/https_cert.pem +33 -0
  97. package/lib/vendor/node_modules/ssh2/test/fixtures/https_key.pem +52 -0
  98. package/lib/vendor/node_modules/ssh2/test/fixtures/id_dsa +12 -0
  99. package/lib/vendor/node_modules/ssh2/test/fixtures/id_ecdsa +5 -0
  100. package/lib/vendor/node_modules/ssh2/test/fixtures/id_rsa +15 -0
  101. package/lib/vendor/node_modules/ssh2/test/fixtures/id_rsa.ppk +26 -0
  102. package/lib/vendor/node_modules/ssh2/test/fixtures/id_rsa_enc +30 -0
  103. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa +21 -0
  104. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa.pub +1 -0
  105. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa.pub.result +7 -0
  106. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa.result +7 -0
  107. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc +22 -0
  108. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc.pub +1 -0
  109. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc.pub.result +7 -0
  110. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc.result +7 -0
  111. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc_gcm +23 -0
  112. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc_gcm.pub +1 -0
  113. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc_gcm.pub.result +7 -0
  114. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc_gcm.result +7 -0
  115. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa +9 -0
  116. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa.pub +1 -0
  117. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa.pub.result +7 -0
  118. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa.result +7 -0
  119. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc +10 -0
  120. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc.pub +1 -0
  121. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc.pub.result +8 -0
  122. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc.result +7 -0
  123. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc_gcm +10 -0
  124. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc_gcm.pub +1 -0
  125. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc_gcm.pub.result +8 -0
  126. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc_gcm.result +7 -0
  127. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ed25519 +7 -0
  128. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ed25519.pub +1 -0
  129. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ed25519.pub.result +7 -0
  130. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ed25519.result +7 -0
  131. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa +27 -0
  132. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa.pub +1 -0
  133. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa.pub.result +7 -0
  134. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa.result +7 -0
  135. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc +28 -0
  136. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc.pub +1 -0
  137. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc.pub.result +8 -0
  138. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc.result +7 -0
  139. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc_gcm +29 -0
  140. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc_gcm.pub +1 -0
  141. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc_gcm.pub.result +8 -0
  142. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc_gcm.result +7 -0
  143. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa +12 -0
  144. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa.pub +1 -0
  145. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa.pub.result +7 -0
  146. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa.result +7 -0
  147. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa_enc +15 -0
  148. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa_enc.pub +1 -0
  149. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa_enc.pub.result +8 -0
  150. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa_enc.result +7 -0
  151. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa +5 -0
  152. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa.pub +1 -0
  153. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa.pub.result +7 -0
  154. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa.result +7 -0
  155. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa_enc +8 -0
  156. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa_enc.pub +1 -0
  157. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa_enc.pub.result +8 -0
  158. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa_enc.result +7 -0
  159. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa +27 -0
  160. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa.pub +1 -0
  161. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa.pub.result +7 -0
  162. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa.result +7 -0
  163. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc +30 -0
  164. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc.pub +1 -0
  165. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc.pub.result +8 -0
  166. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc.result +7 -0
  167. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc_aes256 +54 -0
  168. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc_aes256.pub +1 -0
  169. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc_aes256.pub.result +6 -0
  170. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc_aes256.result +6 -0
  171. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_dsa_enc +17 -0
  172. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_dsa_enc.result +7 -0
  173. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_rsa +26 -0
  174. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_rsa.result +7 -0
  175. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_rsa_enc +18 -0
  176. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_rsa_enc.result +7 -0
  177. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa.pub +9 -0
  178. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa.pub.result +7 -0
  179. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa2.pub +10 -0
  180. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa2.pub.result +7 -0
  181. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa3.pub +11 -0
  182. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa3.pub.result +7 -0
  183. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa4.pub +11 -0
  184. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa4.pub.result +7 -0
  185. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa5.pub +8 -0
  186. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa5.pub.result +7 -0
  187. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa6.pub +13 -0
  188. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa6.pub.result +7 -0
  189. package/lib/vendor/node_modules/ssh2/test/fixtures/openssh_new_rsa +27 -0
  190. package/lib/vendor/node_modules/ssh2/test/fixtures/ssh_host_dsa_key +12 -0
  191. package/lib/vendor/node_modules/ssh2/test/fixtures/ssh_host_ecdsa_key +5 -0
  192. package/lib/vendor/node_modules/ssh2/test/fixtures/ssh_host_rsa_key +15 -0
  193. package/lib/vendor/node_modules/ssh2/test/test-exec.js +578 -0
  194. package/lib/vendor/node_modules/ssh2/test/test-integration-openssh.js +486 -0
  195. package/lib/vendor/node_modules/ssh2/test/test-keygen.js +60 -0
  196. package/lib/vendor/node_modules/ssh2/test/test-misc-client-server.js +1460 -0
  197. package/lib/vendor/node_modules/ssh2/test/test-openssh.js +261 -0
  198. package/lib/vendor/node_modules/ssh2/test/test-protocol-crypto.js +631 -0
  199. package/lib/vendor/node_modules/ssh2/test/test-protocol-keyparser.js +177 -0
  200. package/lib/vendor/node_modules/ssh2/test/test-server-hostkeys.js +138 -0
  201. package/lib/vendor/node_modules/ssh2/test/test-sftp.js +842 -0
  202. package/lib/vendor/node_modules/ssh2/test/test-shell.js +109 -0
  203. package/lib/vendor/node_modules/ssh2/test/test-userauth-agent-openssh.js +110 -0
  204. package/lib/vendor/node_modules/ssh2/test/test-userauth-agent.js +171 -0
  205. package/lib/vendor/node_modules/ssh2/test/test-userauth.js +611 -0
  206. package/lib/vendor/node_modules/ssh2/test/test-worker-imports.js +25 -0
  207. package/lib/vendor/node_modules/ssh2/test/test.js +20 -0
  208. package/lib/vendor/node_modules/ssh2/util/build_pagent.bat +2 -0
  209. package/lib/vendor/node_modules/ssh2/util/pagent.c +88 -0
  210. package/lib/vendor/node_modules/ssh2/util/pagent.exe +0 -0
  211. package/lib/vendor/node_modules/tweetnacl/AUTHORS.md +27 -0
  212. package/lib/vendor/node_modules/tweetnacl/CHANGELOG.md +283 -0
  213. package/lib/vendor/node_modules/tweetnacl/LICENSE +24 -0
  214. package/lib/vendor/node_modules/tweetnacl/PULL_REQUEST_TEMPLATE.md +20 -0
  215. package/lib/vendor/node_modules/tweetnacl/README.md +494 -0
  216. package/lib/vendor/node_modules/tweetnacl/nacl-fast.js +2391 -0
  217. package/lib/vendor/node_modules/tweetnacl/nacl-fast.min.js +1 -0
  218. package/lib/vendor/node_modules/tweetnacl/nacl.d.ts +98 -0
  219. package/lib/vendor/node_modules/tweetnacl/nacl.js +1178 -0
  220. package/lib/vendor/node_modules/tweetnacl/nacl.min.js +1 -0
  221. package/lib/vendor/node_modules/tweetnacl/package.json +56 -0
  222. package/lib/vendor/xterm.css +218 -0
  223. package/lib/vendor/xterm.js +2 -0
  224. package/locale/en.json +6 -0
  225. package/locale/zh.json +6 -0
  226. package/ops/watchdog/dsh-watchdog.ps1 +105 -0
  227. package/ops/watchdog/restart-hidden.vbs +7 -0
  228. package/ops/watchdog/restart-now.ps1 +261 -0
  229. package/ops/watchdog/run-hidden.vbs +4 -0
  230. package/package.json +71 -4
@@ -0,0 +1,163 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * 看门狗 / 重启脚本的安装器。
4
+ *
5
+ * 为什么需要它:
6
+ * 重启脚本必须跑在 DSH 之外(它要杀掉承载插件的进程),所以不能由插件自己在运行时执行。
7
+ * 换电脑后,插件包装好了,但 ~/.dsh/watchdog 下的脚本和计划任务都不会自动跟过来。
8
+ * 这个命令把这件事变成一条:
9
+ *
10
+ * dsh-homing-watchdog install # 装脚本 + 注册看门狗计划任务
11
+ * dsh-homing-watchdog status # 看状态(等价 restart-now.ps1 -Check)
12
+ * dsh-homing-watchdog remove # 卸载计划任务(保留脚本)
13
+ * dsh-homing-watchdog restart # 立刻重启 DSH(默认等空闲)
14
+ * dsh-homing-watchdog restart --immediate # 一空闲就重启
15
+ *
16
+ * 只支持 Windows(脚本是 PowerShell + 计划任务)。
17
+ */
18
+ import fs from 'node:fs'
19
+ import path from 'node:path'
20
+ import { spawnSync } from 'node:child_process'
21
+ import { fileURLToPath } from 'node:url'
22
+
23
+ const here = path.dirname(fileURLToPath(import.meta.url))
24
+ const pkgRoot = path.resolve(here, '..')
25
+ const sourceDir = path.join(pkgRoot, 'ops', 'watchdog')
26
+ const dshHome = process.env.DSH_HOME ?? path.join(process.env.USERPROFILE ?? '', '.dsh')
27
+ const targetDir = path.join(dshHome, 'watchdog')
28
+
29
+ const TASK_WATCHDOG = 'DSH-Watchdog'
30
+ const TASK_RESTART = 'DSH-Restart-Now'
31
+ const EXE = 'powershell.exe'
32
+ const NODE = process.execPath
33
+
34
+ const run = (args, opts = {}) => spawnSync(EXE, args, { encoding: 'utf8', windowsHide: true, ...opts })
35
+ const ps = (script) => run(['-NoProfile', '-ExecutionPolicy', 'Bypass', '-Command', script])
36
+ const psFile = (file, extra = []) => {
37
+ // 中文 Windows 的 PowerShell 默认按 GBK 输出,Node 按 utf8 读会乱码;
38
+ // 这里先设 [Console]::OutputEncoding 再执行脚本,保证能读懂结果。
39
+ const quoted = "'" + file.replaceAll("'", "''") + "'"
40
+ // 开关参数必须原样传(加引号会变成位置参数,被 ValidateSet 拒绝)
41
+ const args = extra.join(' ')
42
+ return run(['-NoProfile', '-ExecutionPolicy', 'Bypass', '-Command',
43
+ `[Console]::OutputEncoding=[System.Text.Encoding]::UTF8; & ${quoted} ${args}`])
44
+ }
45
+
46
+ function requireWindows() {
47
+ if (process.platform !== 'win32') {
48
+ console.error('这个命令只支持 Windows(用 PowerShell + 计划任务实现)。')
49
+ process.exit(1)
50
+ }
51
+ }
52
+
53
+ function install() {
54
+ requireWindows()
55
+ if (!fs.existsSync(sourceDir)) {
56
+ console.error(`找不到脚本目录:${sourceDir}`)
57
+ process.exit(1)
58
+ }
59
+ fs.mkdirSync(targetDir, { recursive: true })
60
+ for (const name of fs.readdirSync(sourceDir)) {
61
+ if (!name.endsWith('.ps1')) continue
62
+ fs.copyFileSync(path.join(sourceDir, name), path.join(targetDir, name))
63
+ console.log(` ✓ 已复制 ${name}`)
64
+ }
65
+
66
+ const watchdog = path.join(targetDir, 'dsh-watchdog.ps1')
67
+ const register = `
68
+ $action = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument '-NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File "${watchdog}"'
69
+ $trigger1 = New-ScheduledTaskTrigger -Once -At (Get-Date).AddMinutes(2) -RepetitionInterval (New-TimeSpan -Minutes 5)
70
+ $trigger2 = New-ScheduledTaskTrigger -AtLogOn
71
+ $settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -StartWhenAvailable -MultipleInstances IgnoreNew -ExecutionTimeLimit (New-TimeSpan -Minutes 10)
72
+ $principal = New-ScheduledTaskPrincipal -UserId "$env:USERDOMAIN\\$env:USERNAME" -LogonType Interactive -RunLevel Limited
73
+ Register-ScheduledTask -TaskName '${TASK_WATCHDOG}' -Action $action -Trigger $trigger1,$trigger2 -Settings $settings -Principal $principal -Force | Out-Null
74
+ Write-Output 'registered'
75
+ `
76
+ const registered = ps(register)
77
+ if (!String(registered.stdout).includes('registered')) {
78
+ console.error('注册看门狗计划任务失败:' + (registered.stderr || registered.stdout || '').slice(0, 400))
79
+ process.exit(1)
80
+ }
81
+ console.log(` ✓ 已注册计划任务 ${TASK_WATCHDOG}(每 5 分钟体检)`)
82
+ console.log('\n装好了。常用命令:')
83
+ console.log(' dsh-homing-watchdog status 查看状态与能否重启')
84
+ console.log(' dsh-homing-watchdog restart 重启 DSH(等空闲)')
85
+ console.log(' dsh-homing-watchdog restart --immediate 一空闲就重启')
86
+ }
87
+
88
+ function status() {
89
+ requireWindows()
90
+ const restart = path.join(targetDir, 'restart-now.ps1')
91
+ if (!fs.existsSync(restart)) {
92
+ console.error('还没安装:先跑 dsh-homing-watchdog install')
93
+ process.exit(1)
94
+ }
95
+ const result = psFile(restart, ['-Check'])
96
+ const text = String(result.stdout || '').replace(/^\uFEFF/u, '')
97
+ if (text.trim() === '') {
98
+ console.error('读取状态失败:' + (result.stderr || '').slice(0, 300))
99
+ process.exit(1)
100
+ }
101
+ console.log(text.trim())
102
+ }
103
+
104
+ function remove() {
105
+ requireWindows()
106
+ const result = ps(`Unregister-ScheduledTask -TaskName '${TASK_WATCHDOG}' -Confirm:$false -ErrorAction SilentlyContinue; Unregister-ScheduledTask -TaskName '${TASK_RESTART}' -Confirm:$false -ErrorAction SilentlyContinue; Write-Output 'removed'`)
107
+ if (String(result.stdout).includes('removed')) {
108
+ console.log(` ✓ 已卸载计划任务(脚本仍保留在 ${targetDir})`)
109
+ } else {
110
+ console.error('卸载失败:' + (result.stderr || '').slice(0, 300))
111
+ process.exit(1)
112
+ }
113
+ }
114
+
115
+ function restart({ immediate }) {
116
+ requireWindows()
117
+ const mode = immediate ? 'immediate' : 'default'
118
+ // 优先走常驻守护进程(无闪窗、事件驱动);它不在时退回旧计划任务
119
+ const request = spawnSync(NODE, [path.join(pkgRoot, 'bin', 'supervisor.mjs'), '--restart', ...(immediate ? ['--immediate'] : [])], {
120
+ encoding: 'utf8', windowsHide: true,
121
+ })
122
+ if (request.status === 0) {
123
+ console.log(String(request.stdout).trim() || `已请求守护进程重启(模式 ${mode})`)
124
+ return
125
+ }
126
+ // 守护进程不在:退回计划任务(仍然可用,但会有闪窗)
127
+ const script = path.join(targetDir, 'restart-now.ps1')
128
+ if (!fs.existsSync(script)) {
129
+ console.error('守护进程没有运行,且找不到 restart-now.ps1。先启动守护进程:dsh-homing-supervisor --detach')
130
+ process.exit(1)
131
+ }
132
+ console.warn('守护进程未运行,退回计划任务方式(可能闪窗)')
133
+ const cmd = `
134
+ $action = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument '-NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File "${script}" -Mode ${mode} -Reason "命令行请求"'
135
+ $trigger = New-ScheduledTaskTrigger -Once -At (Get-Date).AddSeconds(5)
136
+ $settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -StartWhenAvailable -MultipleInstances IgnoreNew -ExecutionTimeLimit (New-TimeSpan -Minutes 30)
137
+ $principal = New-ScheduledTaskPrincipal -UserId "$env:USERDOMAIN\\$env:USERNAME" -LogonType Interactive -RunLevel Limited
138
+ Register-ScheduledTask -TaskName 'DSH-Restart-Now' -Action $action -Trigger $trigger -Settings $settings -Principal $principal -Force | Out-Null
139
+ Write-Output 'queued'
140
+ `
141
+ const result = ps(cmd)
142
+ if (String(result.stdout).includes('queued')) console.log(`已排队(模式 ${mode})`)
143
+ else { console.error('排队失败:' + (result.stderr || '').slice(0, 300)); process.exit(1) }
144
+ }
145
+
146
+ const [command, ...rest] = process.argv.slice(2)
147
+ const has = (flag) => rest.includes(flag)
148
+
149
+ switch (command) {
150
+ case 'install': install(); break
151
+ case 'status': status(); break
152
+ case 'remove': remove(); break
153
+ case 'restart': restart({ immediate: has('--immediate') || has('-i') }); break
154
+ default:
155
+ console.log(`用法: dsh-homing-watchdog <install|status|remove|restart> [--immediate]
156
+
157
+ install 安装/更新重启脚本与看门狗计划任务(换电脑后跑这个)
158
+ status 查看进程、端口、会话活动与能否重启
159
+ remove 卸载计划任务(保留脚本文件)
160
+ restart 重启 DSH;默认等会话空闲,加 --immediate 则一空闲就重启
161
+ `)
162
+ process.exit(command === undefined ? 0 : 1)
163
+ }
package/client.js ADDED
@@ -0,0 +1,79 @@
1
+ /**
2
+ * dsh-homing 的浏览器端:在侧边栏底部放一组守护进程控制按钮。
3
+ *
4
+ * 为什么放在客户端:用户要求用按钮代替命令行,且不要用 PowerShell。
5
+ * 按钮直接调用本机守护进程的控制接口(http://127.0.0.1:8790),
6
+ * 该接口已在 supervisor.mjs 里放行跨端口请求(CORS)。
7
+ *
8
+ * 契约参考 DSH 客户端插件(window.__ModuleLoader__.load + slots 注册)。
9
+ */
10
+ window.__ModuleLoader__.load({
11
+ id: '@andy.ian/dsh-homing',
12
+ factory(require) {
13
+ const React = require('react')
14
+ const h = React.createElement
15
+
16
+ const CONTROL = 'http://127.0.0.1:8790'
17
+
18
+ async function call(pathname) {
19
+ const res = await fetch(CONTROL + pathname, { method: 'POST' })
20
+ return res.json()
21
+ }
22
+
23
+ function Controls() {
24
+ const [notice, setNotice] = React.useState('')
25
+ const [busy, setBusy] = React.useState(false)
26
+
27
+ async function run(pathname, text) {
28
+ if (busy) return
29
+ setBusy(true)
30
+ try {
31
+ await call(pathname)
32
+ setNotice(text)
33
+ } catch (error) {
34
+ setNotice('守护进程未运行')
35
+ } finally {
36
+ setBusy(false)
37
+ setTimeout(() => setNotice(''), 4000)
38
+ }
39
+ }
40
+
41
+ const button = (label, title, pathname, text) => h('button', {
42
+ type: 'button',
43
+ title,
44
+ disabled: busy,
45
+ onClick: () => void run(pathname, text),
46
+ style: {
47
+ background: 'transparent',
48
+ border: '1px solid rgba(255,255,255,.18)',
49
+ borderRadius: '6px',
50
+ color: 'inherit',
51
+ cursor: busy ? 'default' : 'pointer',
52
+ fontSize: '12px',
53
+ padding: '4px 8px',
54
+ },
55
+ }, label)
56
+
57
+ return h('div', { style: { display: 'flex', gap: '6px', alignItems: 'center', padding: '4px 8px' } },
58
+ button('⏻', '重启 DSH(等空闲)', '/restart?mode=default', '已请求重启'),
59
+ button('⚡', '立即重启 DSH', '/restart?mode=immediate', '已请求立即重启'),
60
+ button('⏸', '暂停自动拉起 30 分钟', '/pause?minutes=30', '已暂停 30 分钟'),
61
+ button('▶', '恢复自动拉起', '/resume', '已恢复'),
62
+ button('⏹', '停止守护进程(不再拉起)', '/stop', '守护进程已退出'),
63
+ notice ? h('span', { style: { fontSize: '11px', opacity: 0.7 } }, notice) : null,
64
+ )
65
+ }
66
+
67
+ return {
68
+ name: 'ui-dsh-homing',
69
+ inject: ['slots'],
70
+ apply(ctx) {
71
+ const dispose = ctx.slots.inject('sidebar.footer.action', () => ctx.slots.register(
72
+ { name: 'sidebar.footer.action', id: 'dsh-homing', order: 11 },
73
+ Controls,
74
+ ))
75
+ if (typeof ctx.effect === 'function') ctx.effect(() => dispose, 'dsh-homing: sidebar controls')
76
+ },
77
+ }
78
+ },
79
+ })
@@ -0,0 +1,30 @@
1
+ # dsh-homing:把本机 DSH 开放给手机/微信(随 DSH 启动)
2
+ #
3
+ # 配置说明:
4
+ # serverHost 云服务器 IP(留空则只在本机/局域网提供服务,不起隧道)
5
+ # sshUser 服务器 SSH 用户
6
+ # sshPort SSH 端口
7
+ # sshKey 私钥路径(留空 = ~/.ssh/dsh_tunnel)
8
+ # listenPort 本机监听端口,也是隧道在服务器上占用的回环端口
9
+ # bindAddress 本机监听地址;'::' 表示局域网 + 回环都监听(默认)
10
+ # publicUrl 手机通过公网访问的入口,只用于启动日志
11
+ # funcValue 入口暗号:必须带 ?func=<这个值>,留空则关闭该闸门
12
+ # login 是否要求用户名密码登录(账号密码存在 $DSH_HOME/integrations/dsh-homing/auth.json)
13
+ # tls 'auto' = 自动生成自签证书(局域网也是 HTTPS);'files' = 用 tlsCert/tlsKey;'off' = 明文(仅本机调试)
14
+ # tlsCert/tlsKey tls=files 时的证书与私钥路径
15
+ - insert:
16
+ - id: dsh-homing
17
+ name: '@andy.ian/dsh-homing'
18
+ config:
19
+ serverHost: '' # 服务器地址建议写在 $DSH_HOME/integrations/dsh-homing/settings.json,改完自动重连
20
+ sshUser: ubuntu
21
+ sshPort: 22
22
+ sshKey: ''
23
+ listenPort: 8787
24
+ bindAddress: '::'
25
+ publicUrl: '' # 例如 https://dsh.example.com/?func=dsh-view
26
+ funcValue: dsh-view
27
+ login: true
28
+ tls: auto
29
+ tlsCert: ''
30
+ tlsKey: ''
package/icon.svg ADDED
@@ -0,0 +1,9 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" fill="none">
2
+ <rect x="4" y="6" width="24" height="20" rx="4" fill="#4f7cff" fill-opacity="0.14" stroke="#4f7cff" stroke-width="1.6"/>
3
+ <rect x="11" y="3" width="10" height="18" rx="2.6" fill="#0e1014" stroke="#4f7cff" stroke-width="1.6"/>
4
+ <path d="M14.2 7.5h3.6" stroke="#4f7cff" stroke-width="1.4" stroke-linecap="round"/>
5
+ <circle cx="16" cy="16.4" r="2.4" stroke="#4f7cff" stroke-width="1.4"/>
6
+ <path d="M16 12.6c1.9 2.2 1.9 4.4 0 6.6M16 12.6c-1.9 2.2-1.9 4.4 0 6.6" stroke="#4f7cff" stroke-width="1.1" stroke-linecap="round"/>
7
+ <path d="M22.5 11.5h4M22.5 14.5h4M22.5 17.5h4" stroke="#4f7cff" stroke-width="1.3" stroke-linecap="round" stroke-opacity="0.75"/>
8
+ <path d="M5.5 25.5h21" stroke="#4f7cff" stroke-width="1.4" stroke-linecap="round" stroke-opacity="0.6"/>
9
+ </svg>