easy-devops 1.3.6 → 1.4.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/README.md +1 -0
- package/dist/ui/assets/index-Bu7af-Kj.css +1 -0
- package/dist/ui/assets/index-gndgYe3K.js +532 -0
- package/dist/ui/assets/socket-Bv0wCEgi.js +65 -0
- package/dist/ui/index.html +2 -2
- package/install.bat +14 -7
- package/package.json +2 -2
- package/src/cli/index.js +8 -0
- package/src/cli/managers/domain-manager.js +37 -6
- package/src/cli/managers/nginx-manager.js +14 -5
- package/src/cli/managers/node-manager.js +19 -13
- package/src/cli/managers/ssl-manager.js +89 -26
- package/src/cli/menu.js +8 -2
- package/src/cli/menus/cleanup.js +4 -2
- package/src/cli/menus/dashboard.js +22 -15
- package/src/cli/menus/hub.js +402 -0
- package/src/cli/menus/runtime.js +12 -0
- package/src/cli/menus/service.js +80 -13
- package/src/cli/menus/settings.js +46 -12
- package/src/cli/menus/uninstall.js +13 -5
- package/src/cli/menus/update.js +24 -14
- package/src/cli/ui/page.js +123 -0
- package/src/core/cert-operations.js +34 -4
- package/src/core/cert-reader.js +67 -22
- package/src/core/cert-renewal.js +65 -9
- package/src/core/cert-suggest.js +120 -0
- package/src/core/cleanup.js +221 -1
- package/src/core/cloudflare-ips.js +161 -0
- package/src/core/daemon/ipc.js +1 -1
- package/src/core/daemon/lock.js +296 -9
- package/src/core/daemon/run.js +12 -0
- package/src/core/daemon/stateFile.js +128 -0
- package/src/core/dashboardProcess.js +134 -6
- package/src/core/db.js +26 -1
- package/src/core/deploy/apps.js +36 -62
- package/src/core/deploy/deployKey.js +331 -0
- package/src/core/deploy/domainLink.js +280 -23
- package/src/core/deploy/engine.js +382 -63
- package/src/core/deploy/ezfile.js +496 -29
- package/src/core/deploy/githubApi.js +100 -13
- package/src/core/deploy/hubCommands.js +158 -18
- package/src/core/deploy/status.js +28 -1
- package/src/core/domains-db.js +1 -0
- package/src/core/hub/agent.js +238 -32
- package/src/core/hub/deployProgress.js +411 -0
- package/src/core/hubConnect.js +205 -0
- package/src/core/hubPermissions.js +48 -10
- package/src/core/jobs/bus.js +1 -1
- package/src/core/jobs/owner.js +268 -6
- package/src/core/nginx-conf-generator.js +124 -19
- package/src/core/notifications/claim.js +26 -3
- package/src/core/permissions.js +277 -59
- package/src/core/platform.js +73 -2
- package/src/core/runner.js +96 -40
- package/src/core/service/dataDir.js +34 -9
- package/src/core/service/index.js +203 -24
- package/src/core/service/runtime.js +40 -3
- package/src/core/service/windowsService.js +452 -107
- package/src/core/service/winsw.js +44 -3
- package/src/core/ssl/preflight.js +548 -0
- package/src/core/ssl/progress.js +196 -0
- package/src/core/ssl-issuer.js +502 -148
- package/src/core/validators.js +24 -0
- package/src/dashboard/controllers/authController.js +12 -5
- package/src/dashboard/controllers/deploymentsController.js +76 -11
- package/src/dashboard/controllers/domainsController.js +35 -1
- package/src/dashboard/controllers/hubController.js +4 -3
- package/src/dashboard/controllers/settingsController.js +73 -68
- package/src/dashboard/controllers/sslController.js +135 -15
- package/src/dashboard/public/js/app.js +42 -7
- package/src/dashboard/routes/deployments.js +2 -0
- package/src/dashboard/routes/domains.js +1 -0
- package/src/dashboard/server.js +42 -7
- package/src/dashboard/socketManager.js +19 -25
- package/src/dashboard/views/partials/settings-panel.ejs +29 -10
- package/dist/ui/assets/index-BUpPxWmp.css +0 -1
- package/dist/ui/assets/index-DD0JjK0Q.js +0 -475
- package/dist/ui/assets/socket-4tfdap-e.js +0 -65
|
@@ -8,22 +8,28 @@ import {
|
|
|
8
8
|
hashPassword, validateNewPassword, MIN_PASSWORD_LENGTH,
|
|
9
9
|
} from '../../core/passwords.js';
|
|
10
10
|
import { dbGet } from '../../core/db.js';
|
|
11
|
-
import {
|
|
11
|
+
import { isWindows } from '../../core/platform.js';
|
|
12
|
+
import {
|
|
13
|
+
setupLinuxPermissions, checkPermissionsConfigured, buildSetupScript, deriveOwnDirs,
|
|
14
|
+
} from '../../core/permissions.js';
|
|
12
15
|
import {
|
|
13
16
|
getAutoRenewSettings, normalizeAutoRenewDays, MIN_AUTO_RENEW_DAYS, MAX_AUTO_RENEW_DAYS,
|
|
14
17
|
} from '../../core/cert-renewal.js';
|
|
15
18
|
import { deployRoot, defaultDeployRoot, validateDeployDir } from '../../core/deploy/store.js';
|
|
19
|
+
import { page, pause, BACK } from '../ui/page.js';
|
|
16
20
|
|
|
17
21
|
export default async function settingsMenu() {
|
|
18
22
|
// T021: detect missing/corrupted config before loadConfig() creates defaults
|
|
19
23
|
const wasStored = dbGet('config') !== undefined;
|
|
20
24
|
const config = loadConfig();
|
|
21
|
-
|
|
22
|
-
if (!wasStored) {
|
|
23
|
-
console.log(chalk.yellow('\nDefaults applied — config not found or reset.'));
|
|
24
|
-
}
|
|
25
|
+
let announceDefaults = !wasStored;
|
|
25
26
|
|
|
26
27
|
while (true) {
|
|
28
|
+
page(['Settings']);
|
|
29
|
+
if (announceDefaults) {
|
|
30
|
+
announceDefaults = false;
|
|
31
|
+
console.log(chalk.yellow('Defaults applied — config not found or reset.'));
|
|
32
|
+
}
|
|
27
33
|
// T013: display current values
|
|
28
34
|
const authMode = effectiveAuthMode(config);
|
|
29
35
|
const hasPassword = Boolean(config.dashboardPasswordHash || config.dashboardPassword);
|
|
@@ -40,11 +46,9 @@ export default async function settingsMenu() {
|
|
|
40
46
|
? `on, ${autoRenew.days} day${autoRenew.days === 1 ? '' : 's'} before expiry`
|
|
41
47
|
: 'off';
|
|
42
48
|
|
|
43
|
-
const isLinux =
|
|
49
|
+
const isLinux = !isWindows;
|
|
44
50
|
const permsOk = isLinux ? await checkPermissionsConfigured() : true;
|
|
45
51
|
|
|
46
|
-
console.log();
|
|
47
|
-
console.log(chalk.bold('⚙️ Settings'));
|
|
48
52
|
console.log(chalk.gray('─'.repeat(40)));
|
|
49
53
|
console.log(` Dashboard Port: ${chalk.cyan(config.dashboardPort)}`);
|
|
50
54
|
console.log(` Dashboard Auth: ${chalk.cyan(authDisplay)}`);
|
|
@@ -76,22 +80,43 @@ export default async function settingsMenu() {
|
|
|
76
80
|
: '🔓 Setup Linux Permissions ⚠ required',
|
|
77
81
|
value: 'permissions',
|
|
78
82
|
}] : []),
|
|
79
|
-
{ name:
|
|
83
|
+
{ name: BACK, value: 'back' },
|
|
80
84
|
],
|
|
81
85
|
}]);
|
|
82
86
|
|
|
83
87
|
if (field === 'back') return;
|
|
84
88
|
|
|
85
89
|
if (field === 'permissions') {
|
|
86
|
-
if (
|
|
87
|
-
|
|
88
|
-
|
|
90
|
+
if (!isWindows) {
|
|
91
|
+
// Same derivation and same script as the dashboard's
|
|
92
|
+
// POST /api/settings/permissions/setup: one source, so the two can
|
|
93
|
+
// never show or run different rules. The commands are printed BEFORE
|
|
94
|
+
// anything runs, so they can be copied into a terminal by hand.
|
|
95
|
+
const { ownDirs, refused } = deriveOwnDirs(config);
|
|
96
|
+
const script = buildSetupScript({ ownDirs });
|
|
97
|
+
|
|
98
|
+
for (const item of refused) {
|
|
99
|
+
console.log(chalk.yellow(`\n Skipped ${item.dir}: ${item.reason}`));
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (!script.ok) {
|
|
103
|
+
console.log(chalk.red(`\n ✗ Failed: ${script.reason}\n`));
|
|
104
|
+
await pause();
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
console.log(chalk.bold('\n These commands will run now:'));
|
|
109
|
+
for (const line of script.lines) console.log(chalk.gray(` ${line}`));
|
|
110
|
+
console.log(chalk.gray('\n sudo asks for YOUR password in this terminal; Easy DevOps never sees it.\n'));
|
|
111
|
+
|
|
112
|
+
const result = await setupLinuxPermissions({ ownDirs });
|
|
89
113
|
if (result.success) {
|
|
90
114
|
console.log(chalk.green('\n ✅ Permissions configured! No more password prompts.\n'));
|
|
91
115
|
} else {
|
|
92
116
|
console.log(chalk.red(`\n ✗ Failed: ${result.reason || 'unknown error'}\n`));
|
|
93
117
|
}
|
|
94
118
|
}
|
|
119
|
+
await pause();
|
|
95
120
|
continue;
|
|
96
121
|
}
|
|
97
122
|
|
|
@@ -143,12 +168,14 @@ export default async function settingsMenu() {
|
|
|
143
168
|
if (!loopbackBound) {
|
|
144
169
|
console.log(chalk.yellow(`\n Not allowed while listening on ${config.dashboardBindAddress}.`));
|
|
145
170
|
console.log(chalk.gray(' Set "Listen On" to this machine only first.\n'));
|
|
171
|
+
await pause();
|
|
146
172
|
continue;
|
|
147
173
|
}
|
|
148
174
|
config.dashboardAuth = AUTH_MODES.NONE;
|
|
149
175
|
saveConfig(config);
|
|
150
176
|
console.log(chalk.green('\n ✓ The dashboard will no longer ask for a password.'));
|
|
151
177
|
console.log(chalk.gray(' It stays reachable from this machine only.\n'));
|
|
178
|
+
await pause();
|
|
152
179
|
continue;
|
|
153
180
|
}
|
|
154
181
|
|
|
@@ -164,12 +191,14 @@ export default async function settingsMenu() {
|
|
|
164
191
|
config.dashboardAuth = AUTH_MODES.PASSWORD;
|
|
165
192
|
saveConfig(config);
|
|
166
193
|
console.log(chalk.green('\n ✓ A password is now required.\n'));
|
|
194
|
+
await pause();
|
|
167
195
|
continue;
|
|
168
196
|
}
|
|
169
197
|
|
|
170
198
|
const problem = validateNewPassword(value);
|
|
171
199
|
if (problem) {
|
|
172
200
|
console.log(chalk.red(`\n ${problem}\n`));
|
|
201
|
+
await pause();
|
|
173
202
|
continue;
|
|
174
203
|
}
|
|
175
204
|
|
|
@@ -200,6 +229,7 @@ export default async function settingsMenu() {
|
|
|
200
229
|
if (!isLoopbackBind(value) && authMode === AUTH_MODES.NONE) {
|
|
201
230
|
console.log(chalk.yellow('\n This dashboard has no password, so it can only listen on this machine.'));
|
|
202
231
|
console.log(chalk.gray(' Set a password first (Dashboard Auth), then change this.\n'));
|
|
232
|
+
await pause();
|
|
203
233
|
continue;
|
|
204
234
|
}
|
|
205
235
|
|
|
@@ -289,5 +319,9 @@ export default async function settingsMenu() {
|
|
|
289
319
|
config[field] = value;
|
|
290
320
|
saveConfig(config); // T016
|
|
291
321
|
}
|
|
322
|
+
|
|
323
|
+
// The menu clears the screen when it redraws, so a saved value would
|
|
324
|
+
// otherwise vanish before it could be read.
|
|
325
|
+
await pause();
|
|
292
326
|
}
|
|
293
327
|
}
|
|
@@ -18,6 +18,7 @@ import { getDataDir } from '../../core/platform.js';
|
|
|
18
18
|
import { loadConfig } from '../../core/config.js';
|
|
19
19
|
import * as purgeCore from '../../core/purge.js';
|
|
20
20
|
import { humanBytes } from '../../core/cleanup.js';
|
|
21
|
+
import { page, pause } from '../ui/page.js';
|
|
21
22
|
|
|
22
23
|
/**
|
|
23
24
|
* @param {Object} [opts]
|
|
@@ -25,10 +26,18 @@ import { humanBytes } from '../../core/cleanup.js';
|
|
|
25
26
|
* @param {boolean} [opts.yes]
|
|
26
27
|
* @returns {Promise<number>} Process exit code
|
|
27
28
|
*/
|
|
28
|
-
export async function uninstallCommand(
|
|
29
|
+
export async function uninstallCommand(options = {}) {
|
|
30
|
+
const code = await runUninstall(options);
|
|
31
|
+
|
|
32
|
+
// Purging is the long operation: hold its outcome (and the one command left
|
|
33
|
+
// to run) until Enter. A no-op without a TTY.
|
|
34
|
+
if (options.purge) await pause();
|
|
35
|
+
return code;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function runUninstall({ purge = false, yes = false } = {}) {
|
|
29
39
|
if (!purge) {
|
|
30
|
-
|
|
31
|
-
console.log(' ' + chalk.bold('Uninstall'));
|
|
40
|
+
page(['Uninstall'], { clear: false });
|
|
32
41
|
console.log(' ' + chalk.gray('-'.repeat(58)));
|
|
33
42
|
console.log();
|
|
34
43
|
console.log(' ' + chalk.white('Two different things are called "uninstall":'));
|
|
@@ -53,8 +62,7 @@ export async function uninstallCommand({ purge = false, yes = false } = {}) {
|
|
|
53
62
|
const dataDir = getDataDir();
|
|
54
63
|
const config = loadConfig();
|
|
55
64
|
|
|
56
|
-
|
|
57
|
-
console.log(' ' + chalk.bold('Remove Easy DevOps'));
|
|
65
|
+
page(['Uninstall', 'Purge'], { clear: false });
|
|
58
66
|
console.log(' ' + chalk.gray('-'.repeat(58)));
|
|
59
67
|
console.log();
|
|
60
68
|
|
package/src/cli/menus/update.js
CHANGED
|
@@ -25,6 +25,7 @@ import ora from 'ora';
|
|
|
25
25
|
import { dbGet, dbSet } from '../../core/db.js';
|
|
26
26
|
import { loadConfig } from '../../core/config.js';
|
|
27
27
|
import { getDashboardStatus, startDashboard, stopDashboard } from '../../core/dashboardProcess.js';
|
|
28
|
+
import { page, pause } from '../ui/page.js';
|
|
28
29
|
|
|
29
30
|
|
|
30
31
|
// ─── Recover interrupted update ───────────────────────────────────────────────
|
|
@@ -150,15 +151,29 @@ async function warnStaleDaemon(targetVersion) {
|
|
|
150
151
|
*
|
|
151
152
|
* @param {Object} [opts]
|
|
152
153
|
* @param {boolean} [opts.yes] Skip the confirmation
|
|
154
|
+
* @param {boolean} [opts.heading] Print the "Update Easy DevOps" heading
|
|
153
155
|
* @returns {Promise<number>} Process exit code
|
|
154
156
|
*/
|
|
155
|
-
export async function updateCommand({ yes = false } = {}) {
|
|
157
|
+
export async function updateCommand({ yes = false, heading = true } = {}) {
|
|
158
|
+
const code = await runUpdate({ yes, heading });
|
|
159
|
+
|
|
160
|
+
// A long operation's outcome is read, not scrolled past. No-op without a
|
|
161
|
+
// TTY, so `ezz update` in a script is unaffected. A dismissed confirmation
|
|
162
|
+
// (code 2) ran nothing and has nothing to read.
|
|
163
|
+
if (code !== 2) await pause();
|
|
164
|
+
|
|
165
|
+
return code;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
async function runUpdate({ yes = false, heading = true } = {}) {
|
|
156
169
|
const updater = await import('../../core/updater.js');
|
|
157
170
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
171
|
+
if (heading) {
|
|
172
|
+
console.log();
|
|
173
|
+
console.log(' ' + chalk.bold('Update Easy DevOps'));
|
|
174
|
+
console.log(' ' + chalk.gray('-'.repeat(58)));
|
|
175
|
+
console.log();
|
|
176
|
+
}
|
|
162
177
|
|
|
163
178
|
const spinner = ora('Checking the registry...').start();
|
|
164
179
|
const check = await updater.checkForUpdate();
|
|
@@ -282,18 +297,13 @@ export default async function updateMenu() {
|
|
|
282
297
|
// A crashed previous update is finished before another one is offered.
|
|
283
298
|
await recoverIfNeeded();
|
|
284
299
|
|
|
285
|
-
|
|
300
|
+
page(['Update']);
|
|
301
|
+
|
|
286
302
|
try {
|
|
287
|
-
|
|
303
|
+
// The page header is the heading; the command's own title would repeat it.
|
|
304
|
+
await updateCommand({ heading: false });
|
|
288
305
|
} catch (err) {
|
|
289
306
|
if (err.name === 'ExitPromptError') return;
|
|
290
307
|
throw err;
|
|
291
308
|
}
|
|
292
|
-
|
|
293
|
-
// Dismissed at the confirmation prompt: nothing ran, nothing to read.
|
|
294
|
-
if (code === 2) return;
|
|
295
|
-
|
|
296
|
-
try {
|
|
297
|
-
await inquirer.prompt([{ type: 'input', name: '_', message: 'Press Enter to continue...' }]);
|
|
298
|
-
} catch { /* ExitPromptError on the pause */ }
|
|
299
309
|
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* cli/ui/page.js
|
|
3
|
+
*
|
|
4
|
+
* One way to draw a CLI page, so every menu looks the same and the screen holds
|
|
5
|
+
* one menu instead of a scrollback of every menu visited on the way here.
|
|
6
|
+
*
|
|
7
|
+
* page(['SSL', 'Issue']);
|
|
8
|
+
*
|
|
9
|
+
* clears the screen (only where that is safe) and prints the breadcrumb
|
|
10
|
+
*
|
|
11
|
+
* Easy DevOps > SSL > Issue
|
|
12
|
+
*
|
|
13
|
+
* before the page body. `pause()` is the other half: a long operation leaves
|
|
14
|
+
* its result on screen until Enter, and returns at once when nobody can press
|
|
15
|
+
* it (a pipe, a script, CI), so `ezz service start | tee log` still works.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import chalk from 'chalk';
|
|
19
|
+
import inquirer from 'inquirer';
|
|
20
|
+
|
|
21
|
+
/** The one label every submenu uses for "leave this menu". */
|
|
22
|
+
export const BACK = '← Back';
|
|
23
|
+
/** The one label the main menu uses for "leave the program". */
|
|
24
|
+
export const EXIT = '✖ Exit';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The clear sequence.
|
|
28
|
+
*
|
|
29
|
+
* `ESC[2J` erases the visible screen, `ESC[3J` erases the scrollback (so the
|
|
30
|
+
* previous menu cannot be scrolled back into view, which is the whole point),
|
|
31
|
+
* and `ESC[H` homes the cursor. Windows Terminal, PowerShell 7 and every
|
|
32
|
+
* mainstream Linux terminal (xterm, VTE, kitty, alacritty) understand all
|
|
33
|
+
* three. The legacy conhost window does not implement `ESC[3J`; it ignores
|
|
34
|
+
* that one parameter and still clears and homes on the other two, which is
|
|
35
|
+
* why this sequence is used rather than `console.clear()`: Node's
|
|
36
|
+
* `console.clear()` writes the same kind of escape on POSIX but a bare form
|
|
37
|
+
* feed on some Windows consoles, which leaves the previous page visible.
|
|
38
|
+
*
|
|
39
|
+
* Colour is never part of this: chalk is left to decide for itself, so a pipe
|
|
40
|
+
* gets plain text.
|
|
41
|
+
*/
|
|
42
|
+
const CLEAR_SEQUENCE = '\x1b[2J\x1b[3J\x1b[H';
|
|
43
|
+
|
|
44
|
+
/** What "truthy" means for an environment variable: set and not '0'. */
|
|
45
|
+
function envTruthy(value) {
|
|
46
|
+
if (value === undefined || value === null) return false;
|
|
47
|
+
const text = String(value).trim().toLowerCase();
|
|
48
|
+
return text !== '' && text !== '0' && text !== 'false';
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Whether the screen may be cleared, as a pure decision so it can be tested
|
|
53
|
+
* without a terminal.
|
|
54
|
+
*
|
|
55
|
+
* Clearing is allowed ONLY when:
|
|
56
|
+
* - stdout is a real TTY (a pipe or a file gets every line, never an escape);
|
|
57
|
+
* - CI is not set, because a CI log is read later and must stay complete;
|
|
58
|
+
* - this is not an EZ_TEST-driven run with no TTY, where the output is being
|
|
59
|
+
* captured by a suite and a clear would only add noise to the assertion.
|
|
60
|
+
*
|
|
61
|
+
* @param {Object} [opts]
|
|
62
|
+
* @param {boolean} [opts.isTTY] Defaults to process.stdout.isTTY
|
|
63
|
+
* @param {Object} [opts.env] Defaults to process.env
|
|
64
|
+
* @returns {boolean}
|
|
65
|
+
*/
|
|
66
|
+
export function shouldClearScreen({
|
|
67
|
+
isTTY = Boolean(process.stdout.isTTY),
|
|
68
|
+
env = process.env,
|
|
69
|
+
} = {}) {
|
|
70
|
+
const inCI = envTruthy(env.CI);
|
|
71
|
+
const testCapture = envTruthy(env.EZ_TEST) && !isTTY;
|
|
72
|
+
return Boolean(isTTY) && !inCI && !testCapture;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** `Easy DevOps > SSL > Issue`, with the product name in the brand colour. */
|
|
76
|
+
function breadcrumb(titlePath) {
|
|
77
|
+
const parts = ['Easy DevOps', ...titlePath.filter(Boolean).map(String)];
|
|
78
|
+
const separator = chalk.gray(' > ');
|
|
79
|
+
return parts
|
|
80
|
+
.map((part, index) => (index === 0 ? chalk.hex('#d64a29').bold(part) : chalk.bold.white(part)))
|
|
81
|
+
.join(separator);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Starts a page: clears the screen where that is safe, then prints the
|
|
86
|
+
* breadcrumb. Pass `{ clear: false }` for a command whose output is not a
|
|
87
|
+
* menu screen (`ezz service status`, `ezz cleanup`): it gets no escape code
|
|
88
|
+
* even in a terminal.
|
|
89
|
+
*
|
|
90
|
+
* @param {string[]} [titlePath] e.g. ['SSL', 'Issue']
|
|
91
|
+
* @param {Object} [opts]
|
|
92
|
+
* @param {boolean} [opts.clear] Force the decision one way or the other
|
|
93
|
+
*/
|
|
94
|
+
export function page(titlePath = [], { clear } = {}) {
|
|
95
|
+
const clearNow = clear === undefined
|
|
96
|
+
? shouldClearScreen()
|
|
97
|
+
: Boolean(clear) && Boolean(process.stdout.isTTY) && !envTruthy(process.env.CI);
|
|
98
|
+
|
|
99
|
+
if (clearNow) process.stdout.write(CLEAR_SEQUENCE);
|
|
100
|
+
process.stdout.write(`${breadcrumb(titlePath)}\n`);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** True only when a person can actually see a prompt and answer it. */
|
|
104
|
+
export function isInteractiveIO() {
|
|
105
|
+
return Boolean(process.stdin.isTTY && process.stdout.isTTY);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Waits for Enter so a result stays on screen — and returns immediately when
|
|
110
|
+
* there is no TTY (or in CI), because a prompt there would hang a script.
|
|
111
|
+
*
|
|
112
|
+
* @param {string} [message]
|
|
113
|
+
*/
|
|
114
|
+
export async function pause(message = 'Press Enter to continue') {
|
|
115
|
+
if (!isInteractiveIO() || envTruthy(process.env.CI)) return;
|
|
116
|
+
|
|
117
|
+
try {
|
|
118
|
+
await inquirer.prompt([{ type: 'input', name: '_', message }]);
|
|
119
|
+
} catch (err) {
|
|
120
|
+
// Ctrl+C at the pause is the user leaving, not a failed command.
|
|
121
|
+
if (err?.name !== 'ExitPromptError') throw err;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
@@ -16,6 +16,7 @@ import { describeIssuance, issueCertificate, prepareDomainForHttpChallenge } fro
|
|
|
16
16
|
import { renewCertificate, describeRenewal, failureReason } from './cert-renewal.js';
|
|
17
17
|
import { bumpHubRevision } from './hubLink.js';
|
|
18
18
|
import { listAllCerts } from './cert-reader.js';
|
|
19
|
+
import { findCertificateForDomain } from './cert-suggest.js';
|
|
19
20
|
import { getDomains, findDomain } from './domains-db.js';
|
|
20
21
|
|
|
21
22
|
/** Shape shared by every SSL result so the Hub can render it uniformly. */
|
|
@@ -63,13 +64,23 @@ async function prepare(domainName) {
|
|
|
63
64
|
/**
|
|
64
65
|
* Handles a hub:manageSSL command.
|
|
65
66
|
*
|
|
66
|
-
* @param {Object} payload { action, domain?, www? }
|
|
67
|
+
* @param {Object} payload { action, domain?, www?, opId? }
|
|
68
|
+
* @param {Object} [options]
|
|
69
|
+
* @param {(step: string, status: string, detail?: string) => void} [options.onProgress]
|
|
70
|
+
* Live command progress from core/hub/agent.js. Step is the SSL stage name.
|
|
67
71
|
* @returns {Promise<Object>} { ok, error, ... }
|
|
68
72
|
*/
|
|
69
|
-
export async function handleHubSslCommand(payload) {
|
|
73
|
+
export async function handleHubSslCommand(payload, options = {}) {
|
|
70
74
|
const { action, domain } = payload ?? {};
|
|
75
|
+
const { onProgress = null } = options ?? {};
|
|
71
76
|
const config = loadConfig();
|
|
72
77
|
|
|
78
|
+
// Every SSL stage belongs to a name; the Hub needs that to show renewAll
|
|
79
|
+
// per domain. The agent's onProgress accepts it as its fourth argument.
|
|
80
|
+
const progressFor = (name) => (typeof onProgress === 'function'
|
|
81
|
+
? (step, status, detail) => onProgress(step, status, detail, name)
|
|
82
|
+
: null);
|
|
83
|
+
|
|
73
84
|
switch (action) {
|
|
74
85
|
// ── Renew one ─────────────────────────────────────────────────────────
|
|
75
86
|
case 'renew': {
|
|
@@ -79,7 +90,11 @@ export async function handleHubSslCommand(payload) {
|
|
|
79
90
|
// renewCertificate() keeps the names the certificate already covers
|
|
80
91
|
// (a `www` certificate stays a `www` certificate), prepares the nginx
|
|
81
92
|
// config, and reloads nginx afterwards.
|
|
82
|
-
const result = await renewCertificate(domain, {
|
|
93
|
+
const result = await renewCertificate(domain, {
|
|
94
|
+
email: config.acmeEmail,
|
|
95
|
+
opId: payload?.opId,
|
|
96
|
+
onProgress: progressFor(domain),
|
|
97
|
+
});
|
|
83
98
|
const out = renewalResult(domain, result);
|
|
84
99
|
if (out.ok) bumpHubRevision();
|
|
85
100
|
console.log('[hubAgent] ssl renew:', domain, out.ok ? 'OK' : 'FAILED', '—', out.summary || out.error);
|
|
@@ -97,7 +112,11 @@ export async function handleHubSslCommand(payload) {
|
|
|
97
112
|
const renewed = [];
|
|
98
113
|
|
|
99
114
|
for (const cert of expiring) {
|
|
100
|
-
const result = await renewCertificate(cert.domain, {
|
|
115
|
+
const result = await renewCertificate(cert.domain, {
|
|
116
|
+
email: config.acmeEmail,
|
|
117
|
+
opId: payload?.opId,
|
|
118
|
+
onProgress: progressFor(cert.domain),
|
|
119
|
+
});
|
|
101
120
|
renewed.push(renewalResult(cert.domain, result));
|
|
102
121
|
}
|
|
103
122
|
|
|
@@ -131,6 +150,8 @@ export async function handleHubSslCommand(payload) {
|
|
|
131
150
|
www: Boolean(payload?.www),
|
|
132
151
|
validationMethod: 'http',
|
|
133
152
|
email: config.acmeEmail,
|
|
153
|
+
opId: payload?.opId,
|
|
154
|
+
onProgress: progressFor(domain),
|
|
134
155
|
});
|
|
135
156
|
|
|
136
157
|
const out = issuanceResult(domain, result);
|
|
@@ -139,6 +160,15 @@ export async function handleHubSslCommand(payload) {
|
|
|
139
160
|
return out;
|
|
140
161
|
}
|
|
141
162
|
|
|
163
|
+
// ── Suggest an existing certificate ──────────────────────────────────
|
|
164
|
+
// Read-only, like the server's own dashboard: it reports which
|
|
165
|
+
// certificate could serve the domain and the paths that hold it. The Hub
|
|
166
|
+
// fills them into the form and the operator still has to save.
|
|
167
|
+
case 'suggest': {
|
|
168
|
+
if (!domain) return { ok: false, error: 'domain is required' };
|
|
169
|
+
return { ok: true, ...(await findCertificateForDomain(domain)) };
|
|
170
|
+
}
|
|
171
|
+
|
|
142
172
|
// ── Delete a certificate ──────────────────────────────────────────────
|
|
143
173
|
case 'delete': {
|
|
144
174
|
if (!domain) return { ok: false, error: 'domain is required' };
|
package/src/core/cert-reader.js
CHANGED
|
@@ -1,11 +1,24 @@
|
|
|
1
1
|
import fs from 'fs/promises';
|
|
2
2
|
import path from 'path';
|
|
3
|
+
import { X509Certificate } from 'node:crypto';
|
|
3
4
|
import { run } from './shell.js';
|
|
4
5
|
import { loadConfig } from './config.js';
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Reads every certificate directory.
|
|
9
|
+
*
|
|
10
|
+
* Two different "there is no usable certificate here" cases are kept apart:
|
|
11
|
+
*
|
|
12
|
+
* not_issued the directory exists but no fullchain.pem was ever written
|
|
13
|
+
* (a failed first issuance leaves exactly this), label
|
|
14
|
+
* "Not issued yet"
|
|
15
|
+
* unreadable fullchain.pem exists but neither Node nor openssl can parse it
|
|
16
|
+
*
|
|
17
|
+
* Collapsing them into one "error" made a domain whose certificate had simply
|
|
18
|
+
* not been requested yet look broken.
|
|
19
|
+
*/
|
|
20
|
+
export async function listAllCerts({ sslDir, includeUnusable = false } = {}) {
|
|
21
|
+
const liveDir = sslDir ?? loadConfig().sslDir;
|
|
9
22
|
let entries;
|
|
10
23
|
try {
|
|
11
24
|
entries = await fs.readdir(liveDir, { withFileTypes: true });
|
|
@@ -16,10 +29,13 @@ export async function listAllCerts() {
|
|
|
16
29
|
const dirs = entries.filter(e => e.isDirectory() && !e.name.startsWith('.'));
|
|
17
30
|
const certs = [];
|
|
18
31
|
for (const dir of dirs) {
|
|
19
|
-
const
|
|
32
|
+
const info = await getCertExpiry(dir.name, { sslDir: liveDir });
|
|
33
|
+
const { expiry, daysLeft } = info;
|
|
20
34
|
let status;
|
|
21
|
-
if (
|
|
22
|
-
status = '
|
|
35
|
+
if (info.state === 'not_issued') {
|
|
36
|
+
status = 'not_issued';
|
|
37
|
+
} else if (info.state === 'unreadable' || daysLeft === null) {
|
|
38
|
+
status = 'unreadable';
|
|
23
39
|
} else if (daysLeft <= 0) {
|
|
24
40
|
status = 'expired';
|
|
25
41
|
} else if (daysLeft < 30) {
|
|
@@ -27,33 +43,62 @@ export async function listAllCerts() {
|
|
|
27
43
|
} else {
|
|
28
44
|
status = 'valid';
|
|
29
45
|
}
|
|
30
|
-
|
|
46
|
+
// Callers that act on certificates (suggestion, renewal, monitoring) must
|
|
47
|
+
// see only usable ones; the SSL list passes includeUnusable so it can show
|
|
48
|
+
// "Not issued yet" instead of silently omitting the domain.
|
|
49
|
+
if (!includeUnusable && (status === 'not_issued' || status === 'unreadable')) continue;
|
|
50
|
+
certs.push({
|
|
51
|
+
domain: dir.name,
|
|
52
|
+
expiry: expiry?.toISOString() ?? null,
|
|
53
|
+
daysLeft,
|
|
54
|
+
status,
|
|
55
|
+
label: status === 'not_issued' ? 'Not issued yet' : null,
|
|
56
|
+
});
|
|
31
57
|
}
|
|
32
58
|
return certs;
|
|
33
59
|
}
|
|
34
60
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
61
|
+
/**
|
|
62
|
+
* Expiry of one certificate, with the reason when there is none.
|
|
63
|
+
*
|
|
64
|
+
* @returns {Promise<{ expiry: Date|null, daysLeft: number|null,
|
|
65
|
+
* valid: boolean|null, state: 'ok'|'not_issued'|'unreadable' }>}
|
|
66
|
+
*/
|
|
67
|
+
export async function getCertExpiry(name, { sslDir } = {}) {
|
|
68
|
+
const certPath = path.join(sslDir ?? loadConfig().sslDir, name, 'fullchain.pem');
|
|
38
69
|
|
|
39
|
-
|
|
70
|
+
let pem = null;
|
|
71
|
+
try {
|
|
72
|
+
pem = await fs.readFile(certPath, 'utf8');
|
|
73
|
+
} catch (err) {
|
|
74
|
+
if (err.code === 'ENOENT') {
|
|
75
|
+
return { expiry: null, daysLeft: null, valid: null, state: 'not_issued' };
|
|
76
|
+
}
|
|
77
|
+
return { expiry: null, daysLeft: null, valid: null, state: 'unreadable' };
|
|
78
|
+
}
|
|
40
79
|
|
|
80
|
+
// Node's own parser first: it works on Windows without an openssl binary.
|
|
81
|
+
try {
|
|
82
|
+
const cert = new X509Certificate(pem);
|
|
83
|
+
const expiry = new Date(cert.validTo);
|
|
84
|
+
if (!Number.isNaN(expiry.getTime())) {
|
|
85
|
+
const daysLeft = Math.floor((expiry - Date.now()) / 86400000);
|
|
86
|
+
return { expiry, daysLeft, valid: daysLeft > 0, state: 'ok' };
|
|
87
|
+
}
|
|
88
|
+
} catch { /* fall through to openssl */ }
|
|
89
|
+
|
|
90
|
+
// openssl remains the fallback for a PEM chain or an older/odd encoding.
|
|
91
|
+
const result = await run(`openssl x509 -enddate -noout -in "${certPath}"`);
|
|
41
92
|
if (result.success && result.stdout) {
|
|
42
93
|
const match = result.stdout.match(/notAfter=(.+)/);
|
|
43
94
|
if (match) {
|
|
44
95
|
const expiry = new Date(match[1].trim());
|
|
45
|
-
|
|
46
|
-
|
|
96
|
+
if (!Number.isNaN(expiry.getTime())) {
|
|
97
|
+
const daysLeft = Math.floor((expiry - Date.now()) / 86400000);
|
|
98
|
+
return { expiry, daysLeft, valid: daysLeft > 0, state: 'ok' };
|
|
99
|
+
}
|
|
47
100
|
}
|
|
48
101
|
}
|
|
49
102
|
|
|
50
|
-
|
|
51
|
-
try {
|
|
52
|
-
const stat = await fs.stat(certPath);
|
|
53
|
-
const expiry = new Date(stat.mtime.getTime() + 90 * 86400000);
|
|
54
|
-
const daysLeft = Math.floor((expiry - Date.now()) / 86400000);
|
|
55
|
-
return { expiry, daysLeft, valid: daysLeft > 0 };
|
|
56
|
-
} catch {
|
|
57
|
-
return { expiry: null, daysLeft: null, valid: null };
|
|
58
|
-
}
|
|
103
|
+
return { expiry: null, daysLeft: null, valid: null, state: 'unreadable' };
|
|
59
104
|
}
|