@andy.ian/dsh-homing 0.0.0-stage → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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/watchdog.mjs +158 -0
- package/cordis.patch.yml +30 -0
- package/icon.svg +9 -0
- package/index.js +3339 -0
- package/lib/csrf.mjs +60 -0
- package/lib/devices.mjs +221 -0
- package/lib/files-page.mjs +391 -0
- package/lib/files.mjs +464 -0
- package/lib/git.mjs +154 -0
- package/lib/limits.mjs +135 -0
- package/lib/pty.mjs +354 -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-now.ps1 +247 -0
- package/package.json +69 -4
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* 续期公网证书(CSR 模式:私钥只在本机,服务器只负责走 ACME)。
|
|
4
|
+
*
|
|
5
|
+
* 用法:
|
|
6
|
+
* node bin/renew-cert.mjs 续期并安装
|
|
7
|
+
* node bin/renew-cert.mjs --dry-run 只生成 CSR,不请求证书
|
|
8
|
+
*
|
|
9
|
+
* 为什么这么做:TLS 在你这台电脑终止,服务器只做 TCP 透传。
|
|
10
|
+
* 用 CSR 模式可以把私钥永远留在本机,服务器上不存任何私钥。
|
|
11
|
+
*/
|
|
12
|
+
import fs from 'node:fs';
|
|
13
|
+
import os from 'node:os';
|
|
14
|
+
import path from 'node:path';
|
|
15
|
+
import { spawn, spawnSync } from 'node:child_process';
|
|
16
|
+
import { fileURLToPath } from 'node:url';
|
|
17
|
+
import tls from 'node:tls';
|
|
18
|
+
|
|
19
|
+
const HERE = path.dirname(fileURLToPath(import.meta.url));
|
|
20
|
+
const DIR = path.join(process.env.DSH_HOME || path.join(os.homedir(), '.dsh'), 'integrations', 'dsh-mobile');
|
|
21
|
+
const SETTINGS = path.join(DIR, 'settings.json');
|
|
22
|
+
const CERTS = path.join(DIR, 'certs');
|
|
23
|
+
const dryRun = process.argv.includes('--dry-run');
|
|
24
|
+
|
|
25
|
+
const settings = (() => {
|
|
26
|
+
try { return JSON.parse(fs.readFileSync(SETTINGS, 'utf8')); } catch { return {}; }
|
|
27
|
+
})();
|
|
28
|
+
const publicUrl = settings.publicUrl || '';
|
|
29
|
+
const domain = publicUrl ? new URL(publicUrl).hostname : '';
|
|
30
|
+
if (!domain) {
|
|
31
|
+
console.error('settings.json 里没有 publicUrl,无法确定要续期的域名');
|
|
32
|
+
process.exit(2);
|
|
33
|
+
}
|
|
34
|
+
const serverHost = settings.serverHost;
|
|
35
|
+
const sshUser = settings.sshUser || 'ubuntu';
|
|
36
|
+
const sshPort = Number(settings.sshPort || 22);
|
|
37
|
+
const sshKey = settings.sshKey || path.join(os.homedir(), '.ssh', 'dsh_tunnel');
|
|
38
|
+
|
|
39
|
+
if (!serverHost) {
|
|
40
|
+
console.error('settings.json 里没有 serverHost,无法续期');
|
|
41
|
+
process.exit(2);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function findOpenssl() {
|
|
45
|
+
const candidates = process.platform === 'win32'
|
|
46
|
+
? [
|
|
47
|
+
path.join(process.env['ProgramFiles'] ?? 'C:\\Program Files', 'Git', 'usr', 'bin', 'openssl.exe'),
|
|
48
|
+
path.join(process.env['ProgramFiles'] ?? 'C:\\Program Files', 'Git', 'mingw64', 'bin', 'openssl.exe'),
|
|
49
|
+
'openssl.exe',
|
|
50
|
+
]
|
|
51
|
+
: ['/usr/bin/openssl', '/usr/local/bin/openssl', '/opt/homebrew/bin/openssl', 'openssl'];
|
|
52
|
+
for (const candidate of candidates) {
|
|
53
|
+
if (candidate.includes(path.sep) && !fs.existsSync(candidate)) continue;
|
|
54
|
+
return candidate;
|
|
55
|
+
}
|
|
56
|
+
throw new Error('找不到 openssl');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const openssl = findOpenssl();
|
|
60
|
+
const work = fs.mkdtempSync(path.join(os.tmpdir(), 'dsh-csr-'));
|
|
61
|
+
const keyPath = path.join(work, 'privkey.pem');
|
|
62
|
+
const csrPath = path.join(work, 'req.csr');
|
|
63
|
+
|
|
64
|
+
console.log(`==> 生成本机私钥 + CSR(${domain})`);
|
|
65
|
+
const gen = spawnSync(openssl, [
|
|
66
|
+
'req', '-new', '-newkey', 'ec', '-pkeyopt', 'ec_paramgen_curve:prime256v1', '-nodes',
|
|
67
|
+
'-keyout', keyPath, '-out', csrPath,
|
|
68
|
+
'-subj', `/CN=${domain}`, '-addext', `subjectAltName=DNS:${domain}`,
|
|
69
|
+
], { stdio: 'ignore' });
|
|
70
|
+
if (gen.status !== 0 || !fs.existsSync(csrPath)) {
|
|
71
|
+
console.error('生成 CSR 失败');
|
|
72
|
+
process.exit(1);
|
|
73
|
+
}
|
|
74
|
+
console.log(` ${csrPath}`);
|
|
75
|
+
|
|
76
|
+
if (dryRun) {
|
|
77
|
+
console.log('DryRun:CSR 已生成,未请求证书');
|
|
78
|
+
process.exit(0);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const command = `set -e
|
|
82
|
+
cat > /tmp/dsh-renew.csr <<'CSREOF'
|
|
83
|
+
${fs.readFileSync(csrPath, 'utf8').trim()}
|
|
84
|
+
CSREOF
|
|
85
|
+
sudo certbot certonly --webroot -w /var/www/html -d ${domain} --csr /tmp/dsh-renew.csr --cert-path /tmp/dsh-renew.crt --chain-path /tmp/dsh-renew.chain --fullchain-path /tmp/dsh-renew.fullchain.pem --non-interactive --agree-tos --register-unsafely-without-email >/dev/null 2>&1
|
|
86
|
+
sudo cat /tmp/dsh-renew.fullchain.pem
|
|
87
|
+
sudo rm -f /tmp/dsh-renew.csr /tmp/dsh-renew.crt /tmp/dsh-renew.chain /tmp/dsh-renew.fullchain.pem
|
|
88
|
+
`;
|
|
89
|
+
|
|
90
|
+
console.log('==> 请服务器走 ACME 签发');
|
|
91
|
+
const child = spawn('ssh', [
|
|
92
|
+
'-i', sshKey,
|
|
93
|
+
'-p', String(sshPort),
|
|
94
|
+
'-o', 'BatchMode=yes',
|
|
95
|
+
'-o', 'IdentitiesOnly=yes',
|
|
96
|
+
'-o', 'StrictHostKeyChecking=accept-new',
|
|
97
|
+
`${sshUser}@${serverHost}`,
|
|
98
|
+
'bash -s',
|
|
99
|
+
], { stdio: ['pipe', 'pipe', 'inherit'] });
|
|
100
|
+
|
|
101
|
+
let output = '';
|
|
102
|
+
child.stdout.on('data', (chunk) => { output += chunk; });
|
|
103
|
+
child.stdin.end(command);
|
|
104
|
+
|
|
105
|
+
const code = await new Promise((resolve) => child.on('close', resolve));
|
|
106
|
+
if (code !== 0 || !output.includes('BEGIN CERTIFICATE')) {
|
|
107
|
+
console.error('签发失败(服务器上可能有更详细的 certbot 日志)');
|
|
108
|
+
process.exit(1);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
fs.mkdirSync(CERTS, { recursive: true });
|
|
112
|
+
fs.writeFileSync(path.join(CERTS, 'fullchain.pem'), `${output.trim()}\n`, { mode: 0o600 });
|
|
113
|
+
fs.writeFileSync(path.join(CERTS, 'privkey.pem'), fs.readFileSync(keyPath), { mode: 0o600 });
|
|
114
|
+
fs.chmodSync(keyPath, 0o600);
|
|
115
|
+
|
|
116
|
+
// 用私钥和证书对一次,防止装错
|
|
117
|
+
const certPub = spawnSync(openssl, ['x509', '-in', path.join(CERTS, 'fullchain.pem'), '-noout', '-pubkey']).stdout?.toString().trim();
|
|
118
|
+
const keyPub = spawnSync(openssl, ['pkey', '-in', path.join(CERTS, 'privkey.pem'), '-pubout']).stdout?.toString().trim();
|
|
119
|
+
if (!certPub || certPub !== keyPub) {
|
|
120
|
+
console.error('校验失败:证书与私钥不匹配,保持原文件不动');
|
|
121
|
+
process.exit(1);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const parsed = new tls.X509Certificate(fs.readFileSync(path.join(CERTS, 'fullchain.pem')));
|
|
125
|
+
console.log(`==> 已安装:${CERTS}`);
|
|
126
|
+
console.log(` 到期时间:${parsed.validTo}`);
|
|
127
|
+
console.log(' 重启插件(禁用→启用)或重启 DSH 后生效');
|
package/bin/watchdog.mjs
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
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
|
+
|
|
33
|
+
const run = (args, opts = {}) => spawnSync(EXE, args, { encoding: 'utf8', windowsHide: true, ...opts })
|
|
34
|
+
const ps = (script) => run(['-NoProfile', '-ExecutionPolicy', 'Bypass', '-Command', script])
|
|
35
|
+
const psFile = (file, extra = []) => {
|
|
36
|
+
// 中文 Windows 的 PowerShell 默认按 GBK 输出,Node 按 utf8 读会乱码;
|
|
37
|
+
// 这里先设 [Console]::OutputEncoding 再执行脚本,保证能读懂结果。
|
|
38
|
+
const quoted = "'" + file.replaceAll("'", "''") + "'"
|
|
39
|
+
// 开关参数必须原样传(加引号会变成位置参数,被 ValidateSet 拒绝)
|
|
40
|
+
const args = extra.join(' ')
|
|
41
|
+
return run(['-NoProfile', '-ExecutionPolicy', 'Bypass', '-Command',
|
|
42
|
+
`[Console]::OutputEncoding=[System.Text.Encoding]::UTF8; & ${quoted} ${args}`])
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function requireWindows() {
|
|
46
|
+
if (process.platform !== 'win32') {
|
|
47
|
+
console.error('这个命令只支持 Windows(用 PowerShell + 计划任务实现)。')
|
|
48
|
+
process.exit(1)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function install() {
|
|
53
|
+
requireWindows()
|
|
54
|
+
if (!fs.existsSync(sourceDir)) {
|
|
55
|
+
console.error(`找不到脚本目录:${sourceDir}`)
|
|
56
|
+
process.exit(1)
|
|
57
|
+
}
|
|
58
|
+
fs.mkdirSync(targetDir, { recursive: true })
|
|
59
|
+
for (const name of fs.readdirSync(sourceDir)) {
|
|
60
|
+
if (!name.endsWith('.ps1')) continue
|
|
61
|
+
fs.copyFileSync(path.join(sourceDir, name), path.join(targetDir, name))
|
|
62
|
+
console.log(` ✓ 已复制 ${name}`)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const watchdog = path.join(targetDir, 'dsh-watchdog.ps1')
|
|
66
|
+
const register = `
|
|
67
|
+
$action = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument '-NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File "${watchdog}"'
|
|
68
|
+
$trigger1 = New-ScheduledTaskTrigger -Once -At (Get-Date).AddMinutes(2) -RepetitionInterval (New-TimeSpan -Minutes 5)
|
|
69
|
+
$trigger2 = New-ScheduledTaskTrigger -AtLogOn
|
|
70
|
+
$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -StartWhenAvailable -MultipleInstances IgnoreNew -ExecutionTimeLimit (New-TimeSpan -Minutes 10)
|
|
71
|
+
$principal = New-ScheduledTaskPrincipal -UserId "$env:USERDOMAIN\\$env:USERNAME" -LogonType Interactive -RunLevel Limited
|
|
72
|
+
Register-ScheduledTask -TaskName '${TASK_WATCHDOG}' -Action $action -Trigger $trigger1,$trigger2 -Settings $settings -Principal $principal -Force | Out-Null
|
|
73
|
+
Write-Output 'registered'
|
|
74
|
+
`
|
|
75
|
+
const registered = ps(register)
|
|
76
|
+
if (!String(registered.stdout).includes('registered')) {
|
|
77
|
+
console.error('注册看门狗计划任务失败:' + (registered.stderr || registered.stdout || '').slice(0, 400))
|
|
78
|
+
process.exit(1)
|
|
79
|
+
}
|
|
80
|
+
console.log(` ✓ 已注册计划任务 ${TASK_WATCHDOG}(每 5 分钟体检)`)
|
|
81
|
+
console.log('\n装好了。常用命令:')
|
|
82
|
+
console.log(' dsh-homing-watchdog status 查看状态与能否重启')
|
|
83
|
+
console.log(' dsh-homing-watchdog restart 重启 DSH(等空闲)')
|
|
84
|
+
console.log(' dsh-homing-watchdog restart --immediate 一空闲就重启')
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function status() {
|
|
88
|
+
requireWindows()
|
|
89
|
+
const restart = path.join(targetDir, 'restart-now.ps1')
|
|
90
|
+
if (!fs.existsSync(restart)) {
|
|
91
|
+
console.error('还没安装:先跑 dsh-homing-watchdog install')
|
|
92
|
+
process.exit(1)
|
|
93
|
+
}
|
|
94
|
+
const result = psFile(restart, ['-Check'])
|
|
95
|
+
const text = String(result.stdout || '').replace(/^\uFEFF/u, '')
|
|
96
|
+
if (text.trim() === '') {
|
|
97
|
+
console.error('读取状态失败:' + (result.stderr || '').slice(0, 300))
|
|
98
|
+
process.exit(1)
|
|
99
|
+
}
|
|
100
|
+
console.log(text.trim())
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function remove() {
|
|
104
|
+
requireWindows()
|
|
105
|
+
const result = ps(`Unregister-ScheduledTask -TaskName '${TASK_WATCHDOG}' -Confirm:$false -ErrorAction SilentlyContinue; Unregister-ScheduledTask -TaskName '${TASK_RESTART}' -Confirm:$false -ErrorAction SilentlyContinue; Write-Output 'removed'`)
|
|
106
|
+
if (String(result.stdout).includes('removed')) {
|
|
107
|
+
console.log(` ✓ 已卸载计划任务(脚本仍保留在 ${targetDir})`)
|
|
108
|
+
} else {
|
|
109
|
+
console.error('卸载失败:' + (result.stderr || '').slice(0, 300))
|
|
110
|
+
process.exit(1)
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function restart({ immediate }) {
|
|
115
|
+
requireWindows()
|
|
116
|
+
const script = path.join(targetDir, 'restart-now.ps1')
|
|
117
|
+
if (!fs.existsSync(script)) {
|
|
118
|
+
console.error('还没安装:先跑 dsh-homing-watchdog install')
|
|
119
|
+
process.exit(1)
|
|
120
|
+
}
|
|
121
|
+
const mode = immediate ? 'immediate' : 'default'
|
|
122
|
+
const reason = immediate ? '命令行请求(立即)' : '命令行请求'
|
|
123
|
+
// 用计划任务跑,避免重启时把当前调用它的进程一起杀掉
|
|
124
|
+
const cmd = `
|
|
125
|
+
$action = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument '-NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File "${script}" -Mode ${mode} -Reason "${reason}"'
|
|
126
|
+
$trigger = New-ScheduledTaskTrigger -Once -At (Get-Date).AddSeconds(5)
|
|
127
|
+
$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -StartWhenAvailable -MultipleInstances IgnoreNew -ExecutionTimeLimit (New-TimeSpan -Minutes 30)
|
|
128
|
+
$principal = New-ScheduledTaskPrincipal -UserId "$env:USERDOMAIN\\$env:USERNAME" -LogonType Interactive -RunLevel Limited
|
|
129
|
+
Register-ScheduledTask -TaskName '${TASK_RESTART}' -Action $action -Trigger $trigger -Settings $settings -Principal $principal -Force | Out-Null
|
|
130
|
+
Write-Output 'queued'
|
|
131
|
+
`
|
|
132
|
+
const result = ps(cmd)
|
|
133
|
+
if (String(result.stdout).includes('queued')) {
|
|
134
|
+
console.log(`已排队(模式 ${mode}),5 秒后开始等空闲;日志:${path.join(targetDir, 'restart.log')}`)
|
|
135
|
+
} else {
|
|
136
|
+
console.error('排队失败:' + (result.stderr || '').slice(0, 300))
|
|
137
|
+
process.exit(1)
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const [command, ...rest] = process.argv.slice(2)
|
|
142
|
+
const has = (flag) => rest.includes(flag)
|
|
143
|
+
|
|
144
|
+
switch (command) {
|
|
145
|
+
case 'install': install(); break
|
|
146
|
+
case 'status': status(); break
|
|
147
|
+
case 'remove': remove(); break
|
|
148
|
+
case 'restart': restart({ immediate: has('--immediate') || has('-i') }); break
|
|
149
|
+
default:
|
|
150
|
+
console.log(`用法: dsh-homing-watchdog <install|status|remove|restart> [--immediate]
|
|
151
|
+
|
|
152
|
+
install 安装/更新重启脚本与看门狗计划任务(换电脑后跑这个)
|
|
153
|
+
status 查看进程、端口、会话活动与能否重启
|
|
154
|
+
remove 卸载计划任务(保留脚本文件)
|
|
155
|
+
restart 重启 DSH;默认等会话空闲,加 --immediate 则一空闲就重启
|
|
156
|
+
`)
|
|
157
|
+
process.exit(command === undefined ? 0 : 1)
|
|
158
|
+
}
|
package/cordis.patch.yml
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# dsh-mobile:把本机 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-mobile/auth.json)
|
|
13
|
+
# tls 'auto' = 自动生成自签证书(局域网也是 HTTPS);'files' = 用 tlsCert/tlsKey;'off' = 明文(仅本机调试)
|
|
14
|
+
# tlsCert/tlsKey tls=files 时的证书与私钥路径
|
|
15
|
+
- insert:
|
|
16
|
+
- id: dsh-mobile
|
|
17
|
+
name: '@andy.ian/dsh-homing'
|
|
18
|
+
config:
|
|
19
|
+
serverHost: '' # 服务器地址建议写在 $DSH_HOME/integrations/dsh-mobile/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>
|