@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.
- package/LICENSE +21 -0
- package/README.md +71 -2
- package/bin/auth.mjs +159 -0
- package/bin/backup.mjs +118 -0
- package/bin/bootstrap-server.mjs +436 -0
- package/bin/entry-link.mjs +69 -0
- package/bin/nginx-dsh.template.conf +91 -0
- package/bin/nginx-gate.conf +9 -0
- package/bin/nginx-ws-map.conf +5 -0
- package/bin/renew-cert.mjs +127 -0
- package/bin/supervisor.mjs +488 -0
- package/bin/watchdog.mjs +163 -0
- package/client.js +79 -0
- package/cordis.patch.yml +30 -0
- package/icon.svg +9 -0
- package/index.js +3526 -0
- package/lib/csrf.mjs +60 -0
- package/lib/devices.mjs +221 -0
- package/lib/files-page.mjs +592 -0
- package/lib/files.mjs +551 -0
- package/lib/git.mjs +154 -0
- package/lib/limits.mjs +135 -0
- package/lib/pty.mjs +361 -0
- package/lib/session.mjs +216 -0
- package/lib/shell-page.mjs +430 -0
- package/lib/shell.mjs +274 -0
- package/lib/term-app.js +318 -0
- package/lib/term-page.mjs +117 -0
- package/lib/vendor/fonts/JetBrainsMono-Regular.ttf +0 -0
- package/lib/vendor/fonts/jetbrains-mono-400.woff2 +0 -0
- package/lib/vendor/fonts/jetbrains-mono-700.woff2 +0 -0
- package/lib/vendor/node_modules/@xterm/addon-fit/LICENSE +19 -0
- package/lib/vendor/node_modules/@xterm/addon-fit/README.md +24 -0
- package/lib/vendor/node_modules/@xterm/addon-fit/lib/addon-fit.js +2 -0
- package/lib/vendor/node_modules/@xterm/addon-fit/lib/addon-fit.js.map +1 -0
- package/lib/vendor/node_modules/@xterm/addon-fit/package.json +26 -0
- package/lib/vendor/node_modules/@xterm/addon-fit/src/FitAddon.ts +90 -0
- package/lib/vendor/node_modules/@xterm/addon-fit/typings/addon-fit.d.ts +55 -0
- package/lib/vendor/node_modules/asn1/Jenkinsfile +65 -0
- package/lib/vendor/node_modules/asn1/LICENSE +19 -0
- package/lib/vendor/node_modules/asn1/README.md +50 -0
- package/lib/vendor/node_modules/asn1/lib/ber/errors.js +13 -0
- package/lib/vendor/node_modules/asn1/lib/ber/index.js +27 -0
- package/lib/vendor/node_modules/asn1/lib/ber/reader.js +262 -0
- package/lib/vendor/node_modules/asn1/lib/ber/types.js +36 -0
- package/lib/vendor/node_modules/asn1/lib/ber/writer.js +317 -0
- package/lib/vendor/node_modules/asn1/lib/index.js +20 -0
- package/lib/vendor/node_modules/asn1/package.json +31 -0
- package/lib/vendor/node_modules/bcrypt-pbkdf/CONTRIBUTING.md +13 -0
- package/lib/vendor/node_modules/bcrypt-pbkdf/LICENSE +66 -0
- package/lib/vendor/node_modules/bcrypt-pbkdf/README.md +45 -0
- package/lib/vendor/node_modules/bcrypt-pbkdf/index.js +556 -0
- package/lib/vendor/node_modules/bcrypt-pbkdf/package.json +15 -0
- package/lib/vendor/node_modules/safer-buffer/LICENSE +21 -0
- package/lib/vendor/node_modules/safer-buffer/Porting-Buffer.md +268 -0
- package/lib/vendor/node_modules/safer-buffer/Readme.md +156 -0
- package/lib/vendor/node_modules/safer-buffer/dangerous.js +58 -0
- package/lib/vendor/node_modules/safer-buffer/package.json +34 -0
- package/lib/vendor/node_modules/safer-buffer/safer.js +77 -0
- package/lib/vendor/node_modules/safer-buffer/tests.js +406 -0
- package/lib/vendor/node_modules/ssh2/.eslintignore +4 -0
- package/lib/vendor/node_modules/ssh2/.eslintrc.js +5 -0
- package/lib/vendor/node_modules/ssh2/.github/workflows/ci.yml +110 -0
- package/lib/vendor/node_modules/ssh2/.github/workflows/lint.yml +27 -0
- package/lib/vendor/node_modules/ssh2/LICENSE +19 -0
- package/lib/vendor/node_modules/ssh2/README.md +1529 -0
- package/lib/vendor/node_modules/ssh2/SFTP.md +413 -0
- package/lib/vendor/node_modules/ssh2/examples/server-chat.js +238 -0
- package/lib/vendor/node_modules/ssh2/examples/sftp-server-download-only.js +134 -0
- package/lib/vendor/node_modules/ssh2/install.js +27 -0
- package/lib/vendor/node_modules/ssh2/lib/Channel.js +295 -0
- package/lib/vendor/node_modules/ssh2/lib/agent.js +1123 -0
- package/lib/vendor/node_modules/ssh2/lib/client.js +2176 -0
- package/lib/vendor/node_modules/ssh2/lib/http-agents.js +84 -0
- package/lib/vendor/node_modules/ssh2/lib/index.js +44 -0
- package/lib/vendor/node_modules/ssh2/lib/keygen.js +582 -0
- package/lib/vendor/node_modules/ssh2/lib/protocol/Protocol.js +2136 -0
- package/lib/vendor/node_modules/ssh2/lib/protocol/SFTP.js +4052 -0
- package/lib/vendor/node_modules/ssh2/lib/protocol/constants.js +356 -0
- package/lib/vendor/node_modules/ssh2/lib/protocol/crypto/binding.gyp +23 -0
- package/lib/vendor/node_modules/ssh2/lib/protocol/crypto/poly1305.js +43 -0
- package/lib/vendor/node_modules/ssh2/lib/protocol/crypto/src/binding.cc +2300 -0
- package/lib/vendor/node_modules/ssh2/lib/protocol/crypto.js +1602 -0
- package/lib/vendor/node_modules/ssh2/lib/protocol/handlers.js +16 -0
- package/lib/vendor/node_modules/ssh2/lib/protocol/handlers.misc.js +1285 -0
- package/lib/vendor/node_modules/ssh2/lib/protocol/kex.js +1908 -0
- package/lib/vendor/node_modules/ssh2/lib/protocol/keyParser.js +1484 -0
- package/lib/vendor/node_modules/ssh2/lib/protocol/node-fs-compat.js +115 -0
- package/lib/vendor/node_modules/ssh2/lib/protocol/utils.js +356 -0
- package/lib/vendor/node_modules/ssh2/lib/protocol/zlib.js +255 -0
- package/lib/vendor/node_modules/ssh2/lib/server.js +1380 -0
- package/lib/vendor/node_modules/ssh2/lib/utils.js +336 -0
- package/lib/vendor/node_modules/ssh2/package.json +49 -0
- package/lib/vendor/node_modules/ssh2/test/common.js +316 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/bad_rsa_private_key +26 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/https_cert.pem +33 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/https_key.pem +52 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/id_dsa +12 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/id_ecdsa +5 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/id_rsa +15 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/id_rsa.ppk +26 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/id_rsa_enc +30 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa +21 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa.pub +1 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa.pub.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc +22 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc.pub +1 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc.pub.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc_gcm +23 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc_gcm.pub +1 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc_gcm.pub.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc_gcm.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa +9 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa.pub +1 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa.pub.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc +10 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc.pub +1 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc.pub.result +8 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc_gcm +10 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc_gcm.pub +1 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc_gcm.pub.result +8 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc_gcm.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ed25519 +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ed25519.pub +1 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ed25519.pub.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ed25519.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa +27 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa.pub +1 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa.pub.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc +28 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc.pub +1 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc.pub.result +8 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc_gcm +29 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc_gcm.pub +1 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc_gcm.pub.result +8 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc_gcm.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa +12 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa.pub +1 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa.pub.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa_enc +15 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa_enc.pub +1 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa_enc.pub.result +8 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa_enc.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa +5 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa.pub +1 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa.pub.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa_enc +8 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa_enc.pub +1 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa_enc.pub.result +8 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa_enc.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa +27 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa.pub +1 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa.pub.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc +30 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc.pub +1 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc.pub.result +8 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc_aes256 +54 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc_aes256.pub +1 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc_aes256.pub.result +6 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc_aes256.result +6 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_dsa_enc +17 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_dsa_enc.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_rsa +26 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_rsa.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_rsa_enc +18 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_rsa_enc.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa.pub +9 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa.pub.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa2.pub +10 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa2.pub.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa3.pub +11 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa3.pub.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa4.pub +11 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa4.pub.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa5.pub +8 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa5.pub.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa6.pub +13 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa6.pub.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/openssh_new_rsa +27 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/ssh_host_dsa_key +12 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/ssh_host_ecdsa_key +5 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/ssh_host_rsa_key +15 -0
- package/lib/vendor/node_modules/ssh2/test/test-exec.js +578 -0
- package/lib/vendor/node_modules/ssh2/test/test-integration-openssh.js +486 -0
- package/lib/vendor/node_modules/ssh2/test/test-keygen.js +60 -0
- package/lib/vendor/node_modules/ssh2/test/test-misc-client-server.js +1460 -0
- package/lib/vendor/node_modules/ssh2/test/test-openssh.js +261 -0
- package/lib/vendor/node_modules/ssh2/test/test-protocol-crypto.js +631 -0
- package/lib/vendor/node_modules/ssh2/test/test-protocol-keyparser.js +177 -0
- package/lib/vendor/node_modules/ssh2/test/test-server-hostkeys.js +138 -0
- package/lib/vendor/node_modules/ssh2/test/test-sftp.js +842 -0
- package/lib/vendor/node_modules/ssh2/test/test-shell.js +109 -0
- package/lib/vendor/node_modules/ssh2/test/test-userauth-agent-openssh.js +110 -0
- package/lib/vendor/node_modules/ssh2/test/test-userauth-agent.js +171 -0
- package/lib/vendor/node_modules/ssh2/test/test-userauth.js +611 -0
- package/lib/vendor/node_modules/ssh2/test/test-worker-imports.js +25 -0
- package/lib/vendor/node_modules/ssh2/test/test.js +20 -0
- package/lib/vendor/node_modules/ssh2/util/build_pagent.bat +2 -0
- package/lib/vendor/node_modules/ssh2/util/pagent.c +88 -0
- package/lib/vendor/node_modules/ssh2/util/pagent.exe +0 -0
- package/lib/vendor/node_modules/tweetnacl/AUTHORS.md +27 -0
- package/lib/vendor/node_modules/tweetnacl/CHANGELOG.md +283 -0
- package/lib/vendor/node_modules/tweetnacl/LICENSE +24 -0
- package/lib/vendor/node_modules/tweetnacl/PULL_REQUEST_TEMPLATE.md +20 -0
- package/lib/vendor/node_modules/tweetnacl/README.md +494 -0
- package/lib/vendor/node_modules/tweetnacl/nacl-fast.js +2391 -0
- package/lib/vendor/node_modules/tweetnacl/nacl-fast.min.js +1 -0
- package/lib/vendor/node_modules/tweetnacl/nacl.d.ts +98 -0
- package/lib/vendor/node_modules/tweetnacl/nacl.js +1178 -0
- package/lib/vendor/node_modules/tweetnacl/nacl.min.js +1 -0
- package/lib/vendor/node_modules/tweetnacl/package.json +56 -0
- package/lib/vendor/xterm.css +218 -0
- package/lib/vendor/xterm.js +2 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/ops/watchdog/dsh-watchdog.ps1 +105 -0
- package/ops/watchdog/restart-hidden.vbs +7 -0
- package/ops/watchdog/restart-now.ps1 +261 -0
- package/ops/watchdog/run-hidden.vbs +4 -0
- package/package.json +71 -4
package/bin/watchdog.mjs
ADDED
|
@@ -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
|
+
})
|
package/cordis.patch.yml
ADDED
|
@@ -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>
|