easy-devops 1.3.5 → 1.4.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.
Files changed (69) hide show
  1. package/README.md +1 -0
  2. package/dist/ui/assets/index-Bu7af-Kj.css +1 -0
  3. package/dist/ui/assets/index-gndgYe3K.js +532 -0
  4. package/dist/ui/assets/socket-Bv0wCEgi.js +65 -0
  5. package/dist/ui/index.html +2 -2
  6. package/package.json +2 -2
  7. package/src/cli/index.js +8 -0
  8. package/src/cli/managers/domain-manager.js +37 -6
  9. package/src/cli/managers/nginx-manager.js +14 -5
  10. package/src/cli/managers/node-manager.js +19 -13
  11. package/src/cli/managers/ssl-manager.js +89 -26
  12. package/src/cli/menu.js +8 -2
  13. package/src/cli/menus/cleanup.js +4 -2
  14. package/src/cli/menus/dashboard.js +22 -15
  15. package/src/cli/menus/hub.js +381 -0
  16. package/src/cli/menus/runtime.js +12 -0
  17. package/src/cli/menus/service.js +28 -10
  18. package/src/cli/menus/settings.js +46 -12
  19. package/src/cli/menus/uninstall.js +13 -5
  20. package/src/cli/menus/update.js +24 -14
  21. package/src/cli/ui/page.js +123 -0
  22. package/src/core/cert-operations.js +34 -4
  23. package/src/core/cert-reader.js +67 -22
  24. package/src/core/cert-renewal.js +65 -9
  25. package/src/core/cert-suggest.js +120 -0
  26. package/src/core/cleanup.js +221 -1
  27. package/src/core/cloudflare-ips.js +161 -0
  28. package/src/core/daemon/ipc.js +1 -1
  29. package/src/core/daemon/lock.js +296 -9
  30. package/src/core/dashboardProcess.js +134 -6
  31. package/src/core/deploy/apps.js +36 -62
  32. package/src/core/deploy/deployKey.js +331 -0
  33. package/src/core/deploy/domainLink.js +280 -23
  34. package/src/core/deploy/engine.js +382 -63
  35. package/src/core/deploy/ezfile.js +496 -29
  36. package/src/core/deploy/githubApi.js +100 -13
  37. package/src/core/deploy/hubCommands.js +158 -18
  38. package/src/core/deploy/status.js +28 -1
  39. package/src/core/domains-db.js +1 -0
  40. package/src/core/hub/agent.js +238 -32
  41. package/src/core/hub/deployProgress.js +411 -0
  42. package/src/core/hubConnect.js +205 -0
  43. package/src/core/hubPermissions.js +48 -10
  44. package/src/core/jobs/bus.js +1 -1
  45. package/src/core/jobs/owner.js +268 -6
  46. package/src/core/nginx-conf-generator.js +124 -19
  47. package/src/core/notifications/claim.js +26 -3
  48. package/src/core/permissions.js +277 -59
  49. package/src/core/platform.js +48 -2
  50. package/src/core/runner.js +96 -40
  51. package/src/core/ssl/preflight.js +548 -0
  52. package/src/core/ssl/progress.js +196 -0
  53. package/src/core/ssl-issuer.js +502 -148
  54. package/src/core/validators.js +24 -0
  55. package/src/dashboard/controllers/authController.js +12 -5
  56. package/src/dashboard/controllers/deploymentsController.js +76 -11
  57. package/src/dashboard/controllers/domainsController.js +35 -1
  58. package/src/dashboard/controllers/hubController.js +4 -3
  59. package/src/dashboard/controllers/settingsController.js +73 -68
  60. package/src/dashboard/controllers/sslController.js +135 -15
  61. package/src/dashboard/public/js/app.js +42 -7
  62. package/src/dashboard/routes/deployments.js +2 -0
  63. package/src/dashboard/routes/domains.js +1 -0
  64. package/src/dashboard/server.js +73 -8
  65. package/src/dashboard/socketManager.js +19 -25
  66. package/src/dashboard/views/partials/settings-panel.ejs +29 -10
  67. package/dist/ui/assets/index-BUpPxWmp.css +0 -1
  68. package/dist/ui/assets/index-DD0JjK0Q.js +0 -475
  69. package/dist/ui/assets/socket-4tfdap-e.js +0 -65
@@ -0,0 +1,381 @@
1
+ /**
2
+ * cli/menus/hub.js
3
+ *
4
+ * `ezz hub connect | status | unlink` and the interactive Hub menu.
5
+ *
6
+ * Anything that reaches core/db.js lives here rather than in cli/index.js:
7
+ * index.js is a thin bootstrap that decides the data directory before this
8
+ * module is dynamically imported.
9
+ *
10
+ * The rule this file exists to keep: the connection string, the secret and the
11
+ * one-time token are credentials. Nothing here prints them. The operator sees
12
+ * the Hub's origin and the server id — which identify the pairing without
13
+ * revealing anything that could be used to authenticate.
14
+ */
15
+
16
+ import chalk from 'chalk';
17
+ import inquirer from 'inquirer';
18
+
19
+ import {
20
+ CONNECT_ERRORS,
21
+ linkOrigin,
22
+ resolveConnectInput,
23
+ } from '../../core/hubConnect.js';
24
+ import {
25
+ clearHubLink,
26
+ describeRejection,
27
+ getHubLink,
28
+ getLinkStatus,
29
+ parseConnectionString,
30
+ resolveHubOrigin,
31
+ saveConnectionString,
32
+ } from '../../core/hubLink.js';
33
+ import { inspect } from '../../core/daemon/lock.js';
34
+ import { connectToDaemon } from '../../core/daemon/ipc.js';
35
+ import { page, pause, BACK } from '../ui/page.js';
36
+
37
+ const ACTIONS = ['connect', 'status', 'unlink'];
38
+
39
+ /** How long `connect` waits for the agent to report its first real outcome. */
40
+ const CONNECT_WAIT_MS = 30_000;
41
+ /** A status read must not make an ordinary command feel hung. */
42
+ const STATUS_WAIT_MS = 2_500;
43
+
44
+ /**
45
+ * A test-only override for the link fetch timeout. Honoured only under
46
+ * EZ_TEST=1, so a normal installation cannot change how long a pairing request
47
+ * may take by setting an environment variable.
48
+ */
49
+ const TEST_TIMEOUT_ENV = 'EZ_HUB_CONNECT_TIMEOUT_MS';
50
+
51
+ function connectDeps() {
52
+ if (process.env.EZ_TEST !== '1') return {};
53
+ const ms = Number(process.env[TEST_TIMEOUT_ENV]);
54
+ return Number.isFinite(ms) && ms > 0 ? { timeoutMs: ms } : {};
55
+ }
56
+
57
+ function isInteractive() {
58
+ return Boolean(process.stdin.isTTY && process.stdout.isTTY);
59
+ }
60
+
61
+ /** The Hub's origin, never a path or token. */
62
+ function displayOrigin(hubUrl) {
63
+ const resolved = resolveHubOrigin(hubUrl);
64
+ return linkOrigin(resolved) ?? resolved;
65
+ }
66
+
67
+ function say(line = '') {
68
+ process.stdout.write(`${line}\n`);
69
+ }
70
+
71
+ /**
72
+ * Waits, with a bound, for the daemon to tell us the agent's state.
73
+ *
74
+ * The daemon already publishes `hub:agentState` on the job bus and forwards its
75
+ * frames over IPC (server → client only). Its hello frame carries the state at
76
+ * connect time, so a CLI that starts after the agent connected still sees it.
77
+ *
78
+ * @param {Object} opts
79
+ * @param {number} opts.timeoutMs
80
+ * @param {(state: Object|null) => boolean} [opts.until]
81
+ * @returns {Promise<{ state: Object|null, timedOut: boolean }>}
82
+ */
83
+ function waitForAgentState({ timeoutMs, until = () => false }) {
84
+ return new Promise((resolve) => {
85
+ let latest = null;
86
+ let finished = false;
87
+ let client = null;
88
+
89
+ const finish = (timedOut) => {
90
+ if (finished) return;
91
+ finished = true;
92
+ clearTimeout(timer);
93
+ try { client?.close(); } catch { /* already closed */ }
94
+ resolve({ state: latest, timedOut });
95
+ };
96
+
97
+ const timer = setTimeout(() => finish(true), timeoutMs);
98
+
99
+ client = connectToDaemon({
100
+ onEvent(event, payload) {
101
+ if (finished) return;
102
+ if (event === 'daemon:hello') latest = payload?.hub ?? null;
103
+ else if (event === 'hub:agentState') latest = payload;
104
+
105
+ if (until(latest)) finish(false);
106
+ },
107
+ // Connecting is not yet state: the hello frame is what carries it.
108
+ onStatus() {},
109
+ });
110
+ });
111
+ }
112
+
113
+ function printFailure(failure) {
114
+ // hubConnect.js's messages never contain the token or connection string.
115
+ say(chalk.red(failure.error));
116
+ if (failure.code === CONNECT_ERRORS.REVOKED) {
117
+ say(chalk.gray('A revoked link means the server was deleted on the Hub, or its secret changed.'));
118
+ }
119
+ if (failure.retryAfterSeconds) {
120
+ say(chalk.gray(`The Hub asked to wait ${failure.retryAfterSeconds}s before trying again.`));
121
+ }
122
+ return 1;
123
+ }
124
+
125
+ /**
126
+ * Reports the agent's state after a pairing was saved. Never prints a secret;
127
+ * the only identifiers are the Hub origin and the server id.
128
+ */
129
+ async function reportConnection(origin, serverId) {
130
+ say(`Linked to ${chalk.bold(origin)}.`);
131
+ say(` Server: ${serverId}`);
132
+
133
+ const daemon = inspect();
134
+ if (!daemon.running) {
135
+ say(chalk.yellow('The background service is not running, so the server is not connected yet — ')
136
+ + 'run ' + chalk.bold('`ezz service start`') + ' (or open the dashboard).');
137
+ return 0;
138
+ }
139
+
140
+ say(chalk.gray('Waiting for the background service to report the agent…'));
141
+ const { state, timedOut } = await waitForAgentState({
142
+ timeoutMs: CONNECT_WAIT_MS,
143
+ until: (s) => s?.status === 'connected' || s?.status === 'rejected',
144
+ });
145
+
146
+ if (!state) {
147
+ say(chalk.yellow(`The background service is running but did not report the agent's state `
148
+ + `within ${Math.round(CONNECT_WAIT_MS / 1000)}s.`));
149
+ say(chalk.gray('Check it with `ezz hub status`.'));
150
+ return 0;
151
+ }
152
+
153
+ if (state.status === 'connected') {
154
+ say(chalk.green(`Connected to ${origin}.`));
155
+ return 0;
156
+ }
157
+
158
+ if (state.status === 'rejected') {
159
+ say(chalk.red('The Hub rejected this pairing.'));
160
+ say(' ' + (state.lastError || describeRejection('INVALID_SECRET')));
161
+ say(chalk.gray('Create a new link in the Hub and run the new command.'));
162
+ return 1;
163
+ }
164
+
165
+ if (state.status === 'unreachable') {
166
+ say(chalk.yellow(`Saved, but the server cannot reach ${origin} yet.`));
167
+ if (state.lastError) say(' ' + state.lastError);
168
+ say(chalk.gray('It keeps retrying in the background.'));
169
+ return 0;
170
+ }
171
+
172
+ // Still connecting, or the daemon answered with a state this CLI does not
173
+ // recognise. Both are "not connected yet", which is the honest answer.
174
+ say(chalk.yellow(timedOut
175
+ ? `Still connecting to ${origin} after ${Math.round(CONNECT_WAIT_MS / 1000)}s.`
176
+ : `Saved. The agent is ${state.status ?? 'not reported'} — it will keep trying in the background.`));
177
+ return 0;
178
+ }
179
+
180
+ async function connect(target, { yes = false } = {}) {
181
+ if (!target) {
182
+ say(chalk.red('Missing pairing link.'));
183
+ say(' ezz hub connect <link-or-ezops-string> [--yes]');
184
+ return 1;
185
+ }
186
+
187
+ let resolved;
188
+ try {
189
+ resolved = await resolveConnectInput(target, connectDeps());
190
+ } catch {
191
+ // resolveConnectInput() returns failures rather than throwing; this is a
192
+ // belt-and-braces guard that still says nothing about the input.
193
+ say(chalk.red('Could not read the pairing link or connection string.'));
194
+ return 1;
195
+ }
196
+
197
+ if (!resolved.ok) return printFailure(resolved);
198
+
199
+ const parsed = parseConnectionString(resolved.connectionString);
200
+ if (!parsed.ok) {
201
+ say(chalk.red(parsed.error));
202
+ return 1;
203
+ }
204
+
205
+ const next = parsed.link;
206
+ const nextOrigin = displayOrigin(next.hubUrl);
207
+
208
+ const current = getHubLink();
209
+ if (current) {
210
+ const sameHub = resolveHubOrigin(current.hubUrl) === resolveHubOrigin(next.hubUrl);
211
+ const sameServer = current.serverId === next.serverId;
212
+ if (!sameHub || !sameServer) {
213
+ const currentOrigin = displayOrigin(current.hubUrl);
214
+
215
+ if (!yes && !isInteractive()) {
216
+ say(chalk.yellow(`This server is already linked to ${currentOrigin} as server ${current.serverId}.`));
217
+ say('Run the same command with ' + chalk.bold('--yes') + ' to replace that link.');
218
+ return 1;
219
+ }
220
+
221
+ if (!yes) {
222
+ const { replace } = await inquirer.prompt([{
223
+ type: 'confirm',
224
+ name: 'replace',
225
+ message: `Replace the existing link to ${currentOrigin} (server ${current.serverId})?`,
226
+ default: false,
227
+ }]);
228
+ if (!replace) {
229
+ say('Nothing was changed.');
230
+ return 0;
231
+ }
232
+ }
233
+ }
234
+ }
235
+
236
+ const saved = saveConnectionString(resolved.connectionString);
237
+ if (!saved.ok) {
238
+ say(chalk.red(saved.error));
239
+ return 1;
240
+ }
241
+
242
+ return reportConnection(nextOrigin, next.serverId);
243
+ }
244
+
245
+ async function status() {
246
+ const link = getLinkStatus();
247
+
248
+ say(chalk.bold('Hub pairing'));
249
+ if (!link.linked) {
250
+ say(' Not linked.');
251
+ say(chalk.gray('Pair with: ') + 'ezz hub connect <link-or-ezops-string>');
252
+ return 0;
253
+ }
254
+
255
+ const origin = displayOrigin(link.hubUrl);
256
+ const enabled = Object.entries(link.permissions ?? {})
257
+ .filter(([, value]) => value === true)
258
+ .map(([id]) => id);
259
+
260
+ say(` Hub : ${origin}`);
261
+ say(` Server : ${link.serverId}`);
262
+ say(` Permissions: ${enabled.length ? `${enabled.length} granted — ${enabled.join(', ')}` : 'none granted'}`);
263
+
264
+ const daemon = inspect();
265
+ if (!daemon.running) {
266
+ say(' Agent : the background service is not running, so the server is not connected');
267
+ return 0;
268
+ }
269
+
270
+ const { state } = await waitForAgentState({
271
+ timeoutMs: STATUS_WAIT_MS,
272
+ until: (s) => Boolean(s),
273
+ });
274
+
275
+ if (!state) {
276
+ say(' Agent : not reported by the background service yet');
277
+ return 0;
278
+ }
279
+
280
+ const suffix = state.lastError ? ` — ${state.lastError}` : '';
281
+ say(` Agent : ${state.status ?? 'unknown'}${suffix}`);
282
+ return 0;
283
+ }
284
+
285
+ async function unlink({ yes = false } = {}) {
286
+ const link = getLinkStatus();
287
+ if (!link.linked) {
288
+ say('Not linked to a Hub.');
289
+ return 0;
290
+ }
291
+
292
+ const origin = displayOrigin(link.hubUrl);
293
+
294
+ if (!yes) {
295
+ if (!isInteractive()) {
296
+ say(chalk.yellow(`This server is linked to ${origin}.`));
297
+ say('Run ' + chalk.bold('ezz hub unlink --yes') + ' to remove the link.');
298
+ return 1;
299
+ }
300
+
301
+ const { confirm } = await inquirer.prompt([{
302
+ type: 'confirm',
303
+ name: 'confirm',
304
+ message: `Unlink this server from ${origin}?`,
305
+ default: false,
306
+ }]);
307
+ if (!confirm) {
308
+ say('Nothing was changed.');
309
+ return 0;
310
+ }
311
+ }
312
+
313
+ clearHubLink();
314
+ say(`Unlinked from ${origin}.`);
315
+ say(chalk.gray('The server stays listed in the Hub as offline until you delete it there.'));
316
+ return 0;
317
+ }
318
+
319
+ /**
320
+ * @param {string} [action]
321
+ * @param {string[]} [args] Positional arguments after the action
322
+ * @param {{ yes?: boolean }} [opts]
323
+ * @returns {Promise<number>} Process exit code
324
+ */
325
+ export async function hubCommand(action = 'status', args = [], { yes = false } = {}) {
326
+ if (!ACTIONS.includes(action)) {
327
+ process.stderr.write(
328
+ `Unknown hub action: ${action}\n` +
329
+ `Available: ${ACTIONS.join(', ')}\n`,
330
+ );
331
+ return 1;
332
+ }
333
+
334
+ if (action === 'connect') return connect(args[0], { yes });
335
+ if (action === 'status') return status();
336
+ return unlink({ yes });
337
+ }
338
+
339
+ /** The interactive Hub menu. */
340
+ export async function hubMenu() {
341
+ page(['Hub']);
342
+
343
+ const { choice } = await inquirer.prompt([{
344
+ type: 'list',
345
+ name: 'choice',
346
+ message: 'Hub:',
347
+ choices: ['Connect / re-pair', 'Status', 'Unlink', new inquirer.Separator(), BACK],
348
+ }]);
349
+
350
+ if (choice === BACK) return;
351
+
352
+ if (choice === 'Status') {
353
+ page(['Hub', 'Status']);
354
+ await status();
355
+ await pause();
356
+ return;
357
+ }
358
+
359
+ if (choice === 'Unlink') {
360
+ page(['Hub', 'Unlink']);
361
+ await unlink({ yes: false });
362
+ await pause();
363
+ return;
364
+ }
365
+
366
+ page(['Hub', 'Connect']);
367
+ const { target } = await inquirer.prompt([{
368
+ type: 'password',
369
+ name: 'target',
370
+ mask: '*',
371
+ message: 'Paste the pairing link or ezops:// connection string:',
372
+ }]);
373
+
374
+ await connect(target, { yes: false });
375
+ await pause();
376
+ }
377
+
378
+ // Every other file in menus/ is imported as a default by cli/menu.js. This
379
+ // file's primary export is the non-interactive command, so the interactive
380
+ // menu is exported as the default as well.
381
+ export default hubMenu;
@@ -19,6 +19,7 @@ import ora from 'ora';
19
19
  import { isWindows } from '../../core/platform.js';
20
20
  import * as runtimeUpdate from '../../core/service/runtimeUpdate.js';
21
21
  import * as service from '../../core/service/index.js';
22
+ import { page, pause } from '../ui/page.js';
22
23
 
23
24
  const ACTIONS = ['status', 'update'];
24
25
 
@@ -128,6 +129,17 @@ async function showStatus() {
128
129
  }
129
130
 
130
131
  async function doUpdate({ yes = false } = {}) {
132
+ // `ezz runtime status` stays a plain command page: it is read-only output
133
+ // that people pipe. Moving the runtime is an operation, so it gets a page of
134
+ // its own and its outcome is held until Enter (a no-op without a TTY).
135
+ page(['Runtime', 'Update']);
136
+
137
+ const code = await runUpdate({ yes });
138
+ await pause();
139
+ return code;
140
+ }
141
+
142
+ async function runUpdate({ yes = false } = {}) {
131
143
  const targets = await loadAndPrint();
132
144
 
133
145
  // Nothing is installed to update: say so rather than offering to re-pin a
@@ -20,9 +20,17 @@ import ora from 'ora';
20
20
  import { isWindows, isDevDataDir, getDataDir } from '../../core/platform.js';
21
21
  import * as service from '../../core/service/index.js';
22
22
  import { describeLegacy } from '../../core/service/legacy.js';
23
+ import { page, pause } from '../ui/page.js';
23
24
 
24
25
  const ACTIONS = ['install', 'uninstall', 'status', 'start', 'stop', 'restart', 'logs', 'repair'];
25
26
 
27
+ /**
28
+ * Actions that change something, as opposed to read-only ones (`status`,
29
+ * `logs`). Only these get a page heading and hold their result until Enter;
30
+ * the read-only pair must stay pipeable, so it does neither.
31
+ */
32
+ const MUTATING_ACTIONS = new Set(['install', 'uninstall', 'start', 'stop', 'restart', 'repair']);
33
+
26
34
  /**
27
35
  * Entry point for the `service` command.
28
36
  * @param {string} action
@@ -37,17 +45,21 @@ export async function serviceCommand(action) {
37
45
  return 1;
38
46
  }
39
47
 
48
+ let code;
40
49
  switch (action) {
41
- case 'status': return showStatus();
42
- case 'install': return doInstall();
43
- case 'uninstall': return doUninstall();
44
- case 'start': return doStart();
45
- case 'stop': return doStop();
46
- case 'restart': return doRestart();
47
- case 'logs': return showLogs();
48
- case 'repair': return doRepair();
49
- default: return 1;
50
- }
50
+ case 'status': code = await showStatus(); break;
51
+ case 'install': code = await doInstall(); break;
52
+ case 'uninstall': code = await doUninstall(); break;
53
+ case 'start': code = await doStart(); break;
54
+ case 'stop': code = await doStop(); break;
55
+ case 'restart': code = await doRestart(); break;
56
+ case 'logs': code = await showLogs(); break;
57
+ case 'repair': code = await doRepair(); break;
58
+ default: code = 1;
59
+ }
60
+
61
+ if (MUTATING_ACTIONS.has(action)) await pause();
62
+ return code;
51
63
  }
52
64
 
53
65
  // ─── Shared rendering ─────────────────────────────────────────────────────────
@@ -206,6 +218,7 @@ function describeBoot(enabled) {
206
218
  // ─── install ──────────────────────────────────────────────────────────────────
207
219
 
208
220
  async function doInstall() {
221
+ page(['Service', 'Install']);
209
222
  console.log();
210
223
  console.log(' ' + chalk.bold('Install the Easy DevOps background service'));
211
224
  console.log(' ' + chalk.gray('─'.repeat(58)));
@@ -421,6 +434,7 @@ async function offerToStart() {
421
434
  // ─── uninstall ────────────────────────────────────────────────────────────────
422
435
 
423
436
  async function doUninstall() {
437
+ page(['Service', 'Uninstall']);
424
438
  const current = await service.status().catch(() => null);
425
439
 
426
440
  console.log();
@@ -587,6 +601,7 @@ async function doUninstall() {
587
601
  // ─── stop / start ─────────────────────────────────────────────────────────────
588
602
 
589
603
  async function doStop() {
604
+ page(['Service', 'Stop']);
590
605
  const spinner = ora('Stopping the background service…').start();
591
606
  const lines = [];
592
607
 
@@ -626,6 +641,7 @@ async function doStop() {
626
641
  }
627
642
 
628
643
  async function doStart() {
644
+ page(['Service', 'Start']);
629
645
  const spinner = ora('Starting the background service…').start();
630
646
  const lines = [];
631
647
 
@@ -667,6 +683,7 @@ async function doStart() {
667
683
  // ─── restart ──────────────────────────────────────────────────────────────────
668
684
 
669
685
  async function doRestart() {
686
+ page(['Service', 'Restart']);
670
687
  const spinner = ora('Restarting the service…').start();
671
688
 
672
689
  let result;
@@ -722,6 +739,7 @@ async function showLogs() {
722
739
  // ─── repair ───────────────────────────────────────────────────────────────────
723
740
 
724
741
  async function doRepair() {
742
+ page(['Service', 'Repair']);
725
743
  console.log();
726
744
  console.log(' ' + chalk.bold('Repair the Easy DevOps service'));
727
745
  console.log(' ' + chalk.gray('─'.repeat(58)));
@@ -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 { setupLinuxPermissions, checkPermissionsConfigured } from '../../core/permissions.js';
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 = process.platform !== 'win32';
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: '← Back', value: 'back' },
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 (process.platform !== 'win32') {
87
- console.log(chalk.yellow('\n You will be prompted for your sudo password once.\n'));
88
- const result = await setupLinuxPermissions();
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({ purge = false, yes = false } = {}) {
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
- console.log();
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
- console.log();
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