@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
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 dsh-mobile contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,72 @@
1
- # Temporary Holding Version
1
+ # dsh-homing(DSH Host 插件)
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ > **v1.4.0 变更(务必先读)**
4
+ >
5
+ > - 入口从「常量暗号 `?func=dsh-view` + 可伪造的 `dshview=1` Cookie」改为 **HMAC 签名、带过期的入口令牌 `?k=`**。
6
+ > - 令牌打开一次后换成 **逐设备令牌** `dsh-homing-device`(HttpOnly / SameSite=Lax / Secure,180 天),设备可在
7
+ > `/dsh_homing/devices` 单独吊销,吊销即时生效。
8
+ > - 生成入口:`node bin/entry-link.mjs`(或 `dsh-homing-entry`),默认 30 天有效;书签只存 `https://域名/`。
9
+ > - 旧链接 `?func=dsh-view` **默认失效**;如确需兼容,配置 `legacyFunc: true`。
10
+ > - 新增:写操作来源校验(Origin + Sec-Fetch-Site,含 WebSocket)、登录失败分桶锁定 + 全局延迟、
11
+ > 请求体上限 `maxBodyBytes`(默认 300 MiB,补回 TLS 透传后 nginx 失去的那一层)、配对设备上限 `maxDevices`。
12
+ >
13
+
14
+
15
+ 把本机 DSH 通过 SSH 反向隧道安全地开放到手机 / 微信浏览器,**随 DSH 启动,跨平台(Windows / Linux / macOS)**。
16
+
17
+ ```
18
+ 手机 ──HTTPS──> 云服务器 nginx ──SSH 反向隧道──> 本机插件(127.0.0.1:8787) ──> DSH 自己的 Web 服务
19
+ ```
20
+
21
+ ## 它做什么
22
+
23
+ | 能力 | 实现 |
24
+ |---|---|
25
+ | 找 DSH 端口 | `ctx.webServer.getOrigin()`,不扫进程、不依赖平台 |
26
+ | 注入登录态 | `ctx.credentials.readRecord('client-connection/browser-session')` 取签名密钥,签 `dsh-auth-*` Cookie |
27
+ | 账号登录 | 登录页 + scrypt 哈希 + 7 天签名 Cookie,失败限速 |
28
+ | 入口令牌 | 首次必须带 `?k=<签名令牌>`,之后靠 `dsh-homing-device` Cookie;两者都没有则 `404` |
29
+ | 移动端适配 | 注入 CSS/JS:窄屏隐藏右侧边栏、选完会话自动收起抽屉 |
30
+ | 反向隧道 | 调系统自带 `ssh -N -R`,断线 5 秒重连,日志写 `$DSH_HOME/integrations/dsh-homing/tunnel.log` |
31
+ | 生命周期 | 全部资源在 `ctx.effect()` 里注册,插件卸载时关闭监听并杀掉 ssh 子进程 |
32
+
33
+ ## 配置(cordis.patch.yml 的 config)
34
+
35
+ | 字段 | 说明 | 默认 |
36
+ |---|---|---|
37
+ | `serverHost` | 云服务器 IP;**留空则只在本机/局域网跑,不起隧道** | 空 |
38
+ | `sshUser` / `sshPort` / `sshKey` | SSH 登录信息;`sshKey` 留空用 `~/.ssh/dsh_tunnel` | ubuntu / 22 / 空 |
39
+ | `listenPort` | 本机插件监听的端口(冲突了自己改,服务器不用动) | 8787 |
40
+ | `remotePort` | 服务器上 ssh 隧道占用的回环端口,**必须等于 nginx 的 proxy_pass** | 8787 |
41
+ | `syncPortFromServer` | 启动时和每 10 分钟向服务器查询 proxy_pass 端口,不一致就以服务器为准改本地 | true |
42
+ | `bindAddress` | `127.0.0.1` 只给隧道用;`::` 局域网也能直连 | 127.0.0.1 |
43
+ | `publicUrl` | 手机访问入口,用于日志/二维码 | 空 |
44
+ | `legacyFunc` | 是否仍接受旧版 `?func=` 常量暗号(默认 `false`) | `false` |
45
+ | `login` | 是否要求账号密码 | `true` |
46
+
47
+ ## 账号
48
+
49
+ 首次启动自动生成随机账号,打印在 DSH 日志里;存在
50
+ `$DSH_HOME/integrations/dsh-homing/auth.json`(scrypt 哈希 + 会话签名密钥)。
51
+ 删掉该文件重启即可重置。
52
+
53
+ ## 服务器初始化脚本
54
+
55
+ 包内自带 in/bootstrap-server.mjs(跨平台 Node 脚本),一次性把服务器配好(nginx + 证书 + 反代):
56
+
57
+ ```bash
58
+ node bin/bootstrap-server.mjs --server <服务器IP> --domain <域名> [--install-key] [--dry-run]
59
+ ```
60
+
61
+ 安装后如果 bin 已链接到 profile,也可以直接跑 `dsh-homing-bootstrap`。
62
+
63
+ ## 服务器侧
64
+
65
+ 需要一台公网服务器配好 nginx:443 终止 TLS(Let's Encrypt)、把请求反代到 `127.0.0.1:<listenPort>`,并把 80 端口除 ACME 校验外直接断开。
66
+ 配置在同仓库 `deploy/nginx-*.conf`。
67
+
68
+ ## 跨平台说明
69
+
70
+ - **Windows**:自带 OpenSSH 客户端(`C:\Windows\System32\OpenSSH\ssh.exe`),Windows 10 1809+ 默认就有;
71
+ - **Linux / macOS**:系统自带 `/usr/bin/ssh`;
72
+ - 插件本身没有原生依赖,全部用 Node 标准库。
package/bin/auth.mjs ADDED
@@ -0,0 +1,159 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * DSH 手机入口的账号管理。
4
+ *
5
+ * 用法:
6
+ * node auth.mjs set <用户名> <密码> 设置/覆盖用户名和密码(密码至少 8 位)
7
+ * node auth.mjs random 随机生成一个密码并设置(用户名沿用现有的,默认 dsh)
8
+ * node auth.mjs show 查看当前用户名(不会显示密码)
9
+ *
10
+ * 凭据只保存在本机 auth.json:密码用 scrypt 加盐哈希,明文不落盘;
11
+ * sessionKey 用来给登录后的 Cookie 签名。
12
+ */
13
+ import fs from 'node:fs';
14
+ import os from 'node:os';
15
+ import path from 'node:path';
16
+ import crypto from 'node:crypto';
17
+
18
+ const DATA_DIR = path.join(process.env.DSH_HOME || path.join(os.homedir(), '.dsh'), 'integrations', 'dsh-homing');
19
+ const AUTH_FILE = process.env.DSH_HOMING_AUTH || path.join(DATA_DIR, 'auth.json');
20
+ fs.mkdirSync(path.dirname(AUTH_FILE), { recursive: true });
21
+ const SCRYPT_KEYLEN = 64;
22
+
23
+ const base64url = (buf) => Buffer.from(buf).toString('base64')
24
+ .replaceAll('+', '-')
25
+ .replaceAll('/', '_')
26
+ .replace(/=+$/u, '');
27
+
28
+ function hashPassword(password, saltBase64) {
29
+ const salt = Buffer.from(saltBase64, 'base64');
30
+ return base64url(crypto.scryptSync(password, salt, SCRYPT_KEYLEN));
31
+ }
32
+
33
+ function writeAuth(username, password, { keepSessions = false } = {}) {
34
+ const salt = crypto.randomBytes(16);
35
+ let existing = {};
36
+ try { existing = JSON.parse(fs.readFileSync(AUTH_FILE, 'utf8')); } catch { /* 首次 */ }
37
+ const record = {
38
+ username,
39
+ salt: salt.toString('base64'),
40
+ hash: hashPassword(password, salt.toString('base64')),
41
+ // 换密码默认同时换会话密钥:已经拿到过的旧 Cookie 立即失效
42
+ sessionKey: keepSessions && existing.sessionKey ? existing.sessionKey : base64url(crypto.randomBytes(32)),
43
+ updatedAt: new Date().toISOString(),
44
+ };
45
+ // 换密码不关闭已经开启的二次验证
46
+ if (existing.totpSecret) record.totpSecret = existing.totpSecret;
47
+ fs.writeFileSync(AUTH_FILE, `${JSON.stringify(record, null, 2)}\n`, { encoding: 'utf8', mode: 0o600 });
48
+ return record;
49
+ }
50
+
51
+ const BASE32_ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
52
+
53
+ function base32Encode(buffer) {
54
+ let bits = 0;
55
+ let value = 0;
56
+ let out = '';
57
+ for (const byte of buffer) {
58
+ value = (value << 8) | byte;
59
+ bits += 8;
60
+ while (bits >= 5) {
61
+ out += BASE32_ALPHABET[(value >>> (bits - 5)) & 31];
62
+ bits -= 5;
63
+ }
64
+ }
65
+ if (bits > 0) out += BASE32_ALPHABET[(value << (5 - bits)) & 31];
66
+ return out;
67
+ }
68
+
69
+ function readRecord() {
70
+ try {
71
+ const record = JSON.parse(fs.readFileSync(AUTH_FILE, 'utf8'));
72
+ return record && record.username ? record : undefined;
73
+ } catch {
74
+ return undefined;
75
+ }
76
+ }
77
+
78
+ /** 不把密码打到 stdout(可能进日志/聊天记录),而是写到只有本人能读的文件里。 */
79
+ function writePasswordFile(username, password) {
80
+ const file = path.join(path.dirname(AUTH_FILE), 'auth-initial.txt');
81
+ fs.writeFileSync(file, `用户名:${username}\n密码:${password}\n(登录成功后请删除本文件)\n`, { encoding: 'utf8', mode: 0o600 });
82
+ return file;
83
+ }
84
+
85
+ const [command, ...rest] = process.argv.slice(2);
86
+ const keepSessions = rest.includes('--keep-sessions');
87
+ const toFile = rest.includes('--to-file');
88
+
89
+ if (command === 'set') {
90
+ const positional = rest.filter((item) => !item.startsWith('--'));
91
+ const username = positional[0];
92
+ const password = positional[1];
93
+ if (!username || !password) {
94
+ console.error('用法:node auth.mjs set <用户名> <密码> [--keep-sessions]');
95
+ process.exit(2);
96
+ }
97
+ if (password.length < 8) {
98
+ console.error('密码至少 8 位。');
99
+ process.exit(2);
100
+ }
101
+ writeAuth(username, password, { keepSessions });
102
+ console.log(`已设置:用户名 ${username}(密码只存哈希;已让旧会话全部失效${keepSessions ? ',保留会话' : ''})`);
103
+ } else if (command === 'random' || command === 'reset') {
104
+ const forceFile = command === 'reset';
105
+ let username = 'dsh';
106
+ try { username = JSON.parse(fs.readFileSync(AUTH_FILE, 'utf8')).username ?? username; } catch { /* 默认 */ }
107
+ const password = base64url(crypto.randomBytes(9));
108
+ writeAuth(username, password, { keepSessions });
109
+ if (toFile || forceFile) {
110
+ const file = writePasswordFile(username, password);
111
+ console.log(`用户名:${username}`);
112
+ console.log(`新密码已写入:${file}(只有你能读,用完后删掉)`);
113
+ } else {
114
+ console.log(`用户名:${username}`);
115
+ console.log(`密码:${password}`);
116
+ console.log('请自己保存好;想换成好记的:node auth.mjs set <用户名> <新密码>');
117
+ }
118
+ } else if (command === 'totp') {
119
+ const record = readRecord();
120
+ if (!record) {
121
+ console.error('还没有账号:先运行 node auth.mjs random --to-file');
122
+ process.exit(2);
123
+ }
124
+ if (rest.includes('--disable')) {
125
+ const { totpSecret, ...rest2 } = record;
126
+ fs.writeFileSync(AUTH_FILE, `${JSON.stringify({ ...rest2, sessionKey: base64url(crypto.randomBytes(32)) }, null, 2)}\n`, { encoding: 'utf8', mode: 0o600 });
127
+ console.log('已关闭二次验证(同时让所有会话失效)。');
128
+ process.exit(0);
129
+ }
130
+ const secret = base32Encode(crypto.randomBytes(20));
131
+ const uri = `otpauth://totp/${encodeURIComponent('DSH Mobile')}:${encodeURIComponent(record.username)}?secret=${secret}&issuer=${encodeURIComponent('DSH Mobile')}&algorithm=SHA1&digits=6&period=30`;
132
+ const next = { ...record, totpSecret: secret, updatedAt: new Date().toISOString() };
133
+ fs.writeFileSync(AUTH_FILE, `${JSON.stringify(next, null, 2)}\n`, { encoding: 'utf8', mode: 0o600 });
134
+ const file = path.join(path.dirname(AUTH_FILE), 'auth-totp.txt');
135
+ fs.writeFileSync(file, [
136
+ `账号:${record.username}`,
137
+ `密钥(Base32):${secret}`,
138
+ `otpauth:${uri}`,
139
+ '',
140
+ '在验证器 App(Google Authenticator / 1Password / Bitwarden / Microsoft Authenticator)里手动添加账号,',
141
+ '类型选「基于时间(TOTP)」,粘贴上面的密钥即可;或直接导入 otpauth 链接。',
142
+ '添加完成后请删除本文件。',
143
+ ].join('\n'), { encoding: 'utf8', mode: 0o600 });
144
+ console.log(`已开启二次验证,密钥已写入:${file}(只有你能读)`);
145
+ console.log('现在起登录需要输入验证器里的 6 位验证码。');
146
+ } else if (command === 'show') {
147
+ try {
148
+ const record = JSON.parse(fs.readFileSync(AUTH_FILE, 'utf8'));
149
+ console.log(`用户名:${record.username}`);
150
+ console.log(`更新时间:${record.updatedAt}`);
151
+ } catch {
152
+ console.log('还没有设置账号,先运行:node auth.mjs set <用户名> <密码>');
153
+ }
154
+ } else {
155
+ console.log('用法:');
156
+ console.log(' node auth.mjs set <用户名> <密码>');
157
+ console.log(' node auth.mjs random');
158
+ console.log(' node auth.mjs show');
159
+ }
package/bin/backup.mjs ADDED
@@ -0,0 +1,118 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * 备份 DSH 手机入口的关键状态(账号哈希、证书、私钥、配置)。
4
+ *
5
+ * 用法:
6
+ * node bin/backup.mjs 备份到 <dataDir>/backups/backup-<时间>/
7
+ * DSH_HOMING_BACKUP_PASS=xxx node ... 额外生成一个加密包(AES-256)
8
+ * node bin/backup.mjs --list 列出已有备份
9
+ * node bin/backup.mjs --restore <目录> 从备份恢复(覆盖前会先备份当前状态)
10
+ *
11
+ * 备份里含私钥和 CA 私钥,别放到公共位置。
12
+ */
13
+ import fs from 'node:fs';
14
+ import os from 'node:os';
15
+ import path from 'node:path';
16
+ import { spawnSync } from 'node:child_process';
17
+
18
+ const DIR = path.join(process.env.DSH_HOME || path.join(os.homedir(), '.dsh'), 'integrations', 'dsh-homing');
19
+ const BACKUPS = path.join(DIR, 'backups');
20
+ const KEEP = 10;
21
+ const ITEMS = [
22
+ 'auth.json',
23
+ 'settings.json',
24
+ 'ca-cert.pem',
25
+ 'ca-key.pem',
26
+ 'server-cert.pem',
27
+ 'server-key.pem',
28
+ 'certs/fullchain.pem',
29
+ 'certs/privkey.pem',
30
+ ];
31
+
32
+ function stamp() {
33
+ return new Date().toISOString().replace(/[:.]/gu, '-').slice(0, 19);
34
+ }
35
+
36
+ function list() {
37
+ if (!fs.existsSync(BACKUPS)) {
38
+ console.log('还没有备份');
39
+ return;
40
+ }
41
+ for (const name of fs.readdirSync(BACKUPS).sort()) {
42
+ const full = path.join(BACKUPS, name);
43
+ const size = fs.statSync(full).isDirectory()
44
+ ? fs.readdirSync(full).reduce((sum, file) => sum + fs.statSync(path.join(full, file)).size, 0)
45
+ : fs.statSync(full).size;
46
+ console.log(`${name} ${(size / 1024).toFixed(1)} KB`);
47
+ }
48
+ }
49
+
50
+ function backup() {
51
+ const target = path.join(BACKUPS, `backup-${stamp()}`);
52
+ fs.mkdirSync(target, { recursive: true });
53
+ const copied = [];
54
+ for (const item of ITEMS) {
55
+ const from = path.join(DIR, item);
56
+ if (!fs.existsSync(from)) continue;
57
+ const to = path.join(target, item.replaceAll('/', '__'));
58
+ fs.copyFileSync(from, to);
59
+ copied.push(item);
60
+ }
61
+ fs.writeFileSync(
62
+ path.join(target, 'manifest.json'),
63
+ `${JSON.stringify({ createdAt: new Date().toISOString(), files: copied }, null, 2)}\n`,
64
+ 'utf8',
65
+ );
66
+ console.log(`已备份 ${copied.length} 个文件到 ${target}`);
67
+
68
+ // 可选加密包
69
+ const password = process.env.DSH_HOMING_BACKUP_PASS;
70
+ if (password) {
71
+ const openssl = process.platform === 'win32' ? 'openssl.exe' : 'openssl';
72
+ const archive = `${target}.enc.tgz`;
73
+ const tar = spawnSync('tar', ['-czf', '-', '-C', target, '.'], { maxBuffer: 64 * 1024 * 1024 });
74
+ if (tar.status === 0) {
75
+ const enc = spawnSync(openssl, ['enc', '-aes-256-cbc', '-pbkdf2', '-salt', '-pass', 'env:DSH_HOMING_BACKUP_PASS'], {
76
+ input: tar.stdout,
77
+ maxBuffer: 64 * 1024 * 1024,
78
+ });
79
+ if (enc.status === 0) {
80
+ fs.writeFileSync(archive, enc.stdout);
81
+ console.log(`已生成加密包:${archive}`);
82
+ }
83
+ }
84
+ }
85
+
86
+ // 只保留最近 KEEP 份
87
+ const entries = fs.readdirSync(BACKUPS).filter((name) => name.startsWith('backup-')).sort();
88
+ for (const name of entries.slice(0, Math.max(0, entries.length - KEEP))) {
89
+ fs.rmSync(path.join(BACKUPS, name), { recursive: true, force: true });
90
+ }
91
+ }
92
+
93
+ function restore(source) {
94
+ if (!fs.existsSync(source)) {
95
+ console.error(`备份目录不存在:${source}`);
96
+ process.exit(2);
97
+ }
98
+ backup(); // 先把手上的状态存一份,便于再回滚
99
+ const manifest = path.join(source, 'manifest.json');
100
+ const files = fs.existsSync(manifest)
101
+ ? JSON.parse(fs.readFileSync(manifest, 'utf8')).files
102
+ : [];
103
+ let count = 0;
104
+ for (const item of files) {
105
+ const from = path.join(source, item.replaceAll('/', '__'));
106
+ const to = path.join(DIR, item);
107
+ if (!fs.existsSync(from)) continue;
108
+ fs.mkdirSync(path.dirname(to), { recursive: true });
109
+ fs.copyFileSync(from, to);
110
+ count += 1;
111
+ }
112
+ console.log(`已恢复 ${count} 个文件;重启插件(禁用→启用)后生效`);
113
+ }
114
+
115
+ const args = process.argv.slice(2);
116
+ if (args.includes('--list')) list();
117
+ else if (args.includes('--restore')) restore(args[args.indexOf('--restore') + 1]);
118
+ else backup();