easy-devops 1.2.1 → 1.3.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/README.md +97 -6
- package/dist/ui/assets/index-B6zdwEnG.css +1 -0
- package/dist/ui/assets/index-Cy0oNmul.js +442 -0
- package/dist/ui/assets/socket-DwLPrgsr.js +1 -0
- package/dist/ui/assets/socket-K5ttLD2q.js +65 -0
- package/dist/ui/brand/apple-touch-icon.png +0 -0
- package/dist/ui/brand/favicon-16.png +0 -0
- package/dist/ui/brand/favicon-32.png +0 -0
- package/dist/ui/brand/favicon-light-16.png +0 -0
- package/dist/ui/brand/favicon-light-32.png +0 -0
- package/dist/ui/brand/favicon.ico +0 -0
- package/dist/ui/brand/icon-192.png +0 -0
- package/dist/ui/brand/icon-48.png +0 -0
- package/dist/ui/brand/icon-512.png +0 -0
- package/dist/ui/brand/icon-64-light.png +0 -0
- package/dist/ui/brand/icon-64.png +0 -0
- package/dist/ui/brand/logo-dark.png +0 -0
- package/dist/ui/brand/logo-light.png +0 -0
- package/dist/ui/brand/mark-dark.png +0 -0
- package/dist/ui/brand/mark-light.png +0 -0
- package/dist/ui/index.html +71 -0
- package/install.ps1 +188 -1
- package/install.sh +254 -29
- package/package.json +15 -4
- package/src/cli/dash.js +110 -0
- package/src/cli/index.js +237 -106
- package/src/cli/managers/domain-manager.js +60 -40
- package/src/cli/managers/ssl-manager.js +47 -330
- package/src/cli/menu.js +156 -0
- package/src/cli/menus/cleanup.js +205 -0
- package/src/cli/menus/dashboard.js +92 -1
- package/src/cli/menus/runtime.js +236 -0
- package/src/cli/menus/service.js +764 -0
- package/src/cli/menus/settings.js +176 -8
- package/src/cli/menus/uninstall.js +167 -0
- package/src/cli/menus/update.js +221 -65
- package/src/core/acme-challenge.js +273 -0
- package/src/core/cert-operations.js +189 -0
- package/src/{dashboard/lib → core}/cert-reader.js +2 -2
- package/src/core/cert-renewal.js +494 -0
- package/src/core/cleanup.js +600 -0
- package/src/core/config.js +169 -2
- package/src/core/daemon/ipc.js +292 -0
- package/src/core/daemon/lock.js +294 -0
- package/src/core/daemon/run.js +241 -0
- package/src/core/daemon/stopRequest.js +162 -0
- package/src/core/db.js +37 -8
- package/src/core/deploy/apps.js +491 -0
- package/src/core/deploy/domainLink.js +200 -0
- package/src/core/deploy/engine.js +973 -0
- package/src/core/deploy/ezfile.js +361 -0
- package/src/core/deploy/github.js +239 -0
- package/src/core/deploy/githubApi.js +261 -0
- package/src/core/deploy/hookServer.js +325 -0
- package/src/core/deploy/hubCommands.js +267 -0
- package/src/core/deploy/launcher.js +57 -0
- package/src/core/deploy/status.js +91 -0
- package/src/core/deploy/store.js +398 -0
- package/src/core/domainNotifier.js +94 -28
- package/src/core/domains-db.js +234 -0
- package/src/core/events.js +94 -2
- package/src/core/hub/agent.js +842 -0
- package/src/core/hubLink.js +306 -0
- package/src/core/hubPermissions.js +430 -0
- package/src/core/installSource.js +162 -0
- package/src/core/jobs/bus.js +120 -0
- package/src/core/jobs/index.js +371 -0
- package/src/core/jobs/monitors.js +368 -0
- package/src/core/jobs/owner.js +217 -0
- package/src/core/jobs/revisionWatcher.js +106 -0
- package/src/core/nginx-apply.js +213 -0
- package/src/core/nginx-conf-generator.js +253 -17
- package/src/{dashboard/lib → core}/nginx-service.js +18 -9
- package/src/core/notifications/claim.js +214 -0
- package/src/core/notifications/dispatch.js +154 -0
- package/src/core/notifier.js +31 -1
- package/src/core/passwords.js +172 -0
- package/src/core/permissions.js +8 -4
- package/src/core/platform.js +709 -2
- package/src/core/probeCache.js +258 -0
- package/src/core/purge.js +372 -0
- package/src/core/runner.js +488 -0
- package/src/core/service/acl.js +226 -0
- package/src/core/service/dataDir.js +345 -0
- package/src/core/service/index.js +1128 -0
- package/src/core/service/legacy.js +218 -0
- package/src/core/service/runtime.js +446 -0
- package/src/core/service/runtimeUpdate.js +800 -0
- package/src/core/service/systemd.js +458 -0
- package/src/core/service/windowsPersonal.js +530 -0
- package/src/core/service/windowsService.js +576 -0
- package/src/core/service/winsw.js +260 -0
- package/src/core/setupCode.js +331 -0
- package/src/core/shell.js +70 -7
- package/src/core/ssl-issuer.js +627 -0
- package/src/core/updater.js +295 -0
- package/src/core/validators.js +99 -0
- package/src/dashboard/controllers/authController.js +302 -15
- package/src/dashboard/controllers/deploymentsController.js +479 -0
- package/src/dashboard/controllers/domainsController.js +39 -52
- package/src/dashboard/controllers/hubController.js +135 -0
- package/src/dashboard/controllers/nginxController.js +21 -3
- package/src/dashboard/controllers/processesController.js +368 -0
- package/src/dashboard/controllers/settingsController.js +180 -12
- package/src/dashboard/controllers/sslController.js +171 -10
- package/src/dashboard/lib/daemonBridge.js +163 -0
- package/src/dashboard/lib/localRequest.js +235 -0
- package/src/dashboard/lib/loginRateLimit.js +119 -0
- package/src/dashboard/lib/requireAuth.js +80 -0
- package/src/dashboard/public/js/app.js +489 -19
- package/src/dashboard/routes/auth.js +10 -10
- package/src/dashboard/routes/deployments.js +46 -0
- package/src/dashboard/routes/domains.js +9 -0
- package/src/dashboard/routes/hub.js +22 -0
- package/src/dashboard/routes/nginx.js +9 -0
- package/src/dashboard/routes/processes.js +29 -0
- package/src/dashboard/routes/settings.js +9 -0
- package/src/dashboard/routes/ssl.js +9 -0
- package/src/dashboard/server.js +288 -21
- package/src/dashboard/socketManager.js +171 -207
- package/src/dashboard/views/index.ejs +1 -0
- package/src/dashboard/views/partials/login.ejs +68 -7
- package/src/dashboard/views/partials/processes-panel.ejs +261 -0
- package/src/dashboard/views/partials/settings-panel.ejs +287 -0
- package/src/dashboard/views/partials/sidebar.ejs +2 -0
- package/src/dashboard/lib/domains-db.js +0 -51
|
@@ -16,13 +16,10 @@ import inquirer from 'inquirer';
|
|
|
16
16
|
import ora from 'ora';
|
|
17
17
|
import fs from 'fs/promises';
|
|
18
18
|
import path from 'path';
|
|
19
|
-
import
|
|
20
|
-
import net from 'net';
|
|
21
|
-
import * as acme from 'acme-client';
|
|
22
|
-
import os from 'os';
|
|
23
|
-
import { run, runLive } from '../../core/shell.js';
|
|
19
|
+
import { run } from '../../core/shell.js';
|
|
24
20
|
import { loadConfig } from '../../core/config.js';
|
|
25
|
-
import {
|
|
21
|
+
import { issueCertificate, describeIssuance } from '../../core/ssl-issuer.js';
|
|
22
|
+
import { renewCertificate, describeRenewal, failureReason } from '../../core/cert-renewal.js';
|
|
26
23
|
|
|
27
24
|
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
|
28
25
|
|
|
@@ -31,63 +28,6 @@ function getSslDir() {
|
|
|
31
28
|
return sslDir;
|
|
32
29
|
}
|
|
33
30
|
|
|
34
|
-
/**
|
|
35
|
-
* Loads or generates the ACME account private key.
|
|
36
|
-
* The key is persisted at {sslDir}/.account/account.key
|
|
37
|
-
*/
|
|
38
|
-
async function getAccountKey(sslDir) {
|
|
39
|
-
const keyPath = path.join(sslDir, '.account', 'account.key');
|
|
40
|
-
const accountDir = path.dirname(keyPath);
|
|
41
|
-
if (!isWindows) {
|
|
42
|
-
const user = os.userInfo().username;
|
|
43
|
-
await run(`sudo -n mkdir -p "${accountDir}"`);
|
|
44
|
-
await run(`sudo -n chown ${user}:${user} "${accountDir}"`);
|
|
45
|
-
} else {
|
|
46
|
-
await fs.mkdir(accountDir, { recursive: true });
|
|
47
|
-
}
|
|
48
|
-
try {
|
|
49
|
-
return await fs.readFile(keyPath);
|
|
50
|
-
} catch {
|
|
51
|
-
const key = await acme.crypto.createPrivateKey();
|
|
52
|
-
await fs.writeFile(keyPath, key);
|
|
53
|
-
return key;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Checks if port 80 is free (can be bound).
|
|
59
|
-
* Used for HTTP-01 challenge validation.
|
|
60
|
-
*/
|
|
61
|
-
async function isPort80Free() {
|
|
62
|
-
return new Promise((resolve) => {
|
|
63
|
-
const srv = net.createServer();
|
|
64
|
-
srv.listen(80, () => {
|
|
65
|
-
srv.close(() => resolve(true));
|
|
66
|
-
});
|
|
67
|
-
srv.on('error', () => resolve(false));
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Stops nginx to free port 80 for HTTP-01 challenge.
|
|
73
|
-
*/
|
|
74
|
-
async function stopNginx() {
|
|
75
|
-
const cmd = isWindows
|
|
76
|
-
? 'taskkill /f /IM nginx.exe'
|
|
77
|
-
: 'systemctl stop nginx';
|
|
78
|
-
await run(cmd);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Starts nginx after HTTP-01 challenge completes.
|
|
83
|
-
*/
|
|
84
|
-
async function startNginx() {
|
|
85
|
-
const { nginxDir } = loadConfig();
|
|
86
|
-
const cmd = isWindows
|
|
87
|
-
? `& "${nginxDir}\\nginx.exe"`
|
|
88
|
-
: 'systemctl start nginx';
|
|
89
|
-
await run(cmd);
|
|
90
|
-
}
|
|
91
31
|
|
|
92
32
|
// ─── Certificate Listing ──────────────────────────────────────────────────────
|
|
93
33
|
|
|
@@ -188,287 +128,51 @@ function renderCertRow(cert) {
|
|
|
188
128
|
// ─── Certificate Issuance ─────────────────────────────────────────────────────
|
|
189
129
|
|
|
190
130
|
/**
|
|
191
|
-
* Issues
|
|
131
|
+
* Issues (or renews) a certificate for a domain.
|
|
192
132
|
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
133
|
+
* Thin wrapper over core/ssl-issuer.js, which is the single implementation
|
|
134
|
+
* shared by the CLI, the dashboard API and the Hub command path. It keeps
|
|
135
|
+
* nginx running by default — see that module for the challenge strategy.
|
|
195
136
|
*
|
|
196
|
-
* @param {string} domainName
|
|
197
|
-
* @param {
|
|
198
|
-
*
|
|
199
|
-
* validationMethod?: 'http' | 'dns',
|
|
200
|
-
* email?: string | null,
|
|
201
|
-
* onDnsChallenge?: (txtName: string, txtValue: string) => Promise<void>
|
|
202
|
-
* }} options
|
|
203
|
-
* @returns {Promise<{ success: boolean, certPath: string|null, keyPath: string|null, error: object|null }>}
|
|
137
|
+
* @param {string} domainName
|
|
138
|
+
* @param {Object} options See issueCertificate() in core/ssl-issuer.js
|
|
139
|
+
* @returns {Promise<Object>} Result object from issueCertificate()
|
|
204
140
|
*/
|
|
205
|
-
export async function issueCert(domainName, {
|
|
206
|
-
|
|
207
|
-
wildcard = false,
|
|
208
|
-
validationMethod = 'http',
|
|
209
|
-
email = null,
|
|
210
|
-
onDnsChallenge = null,
|
|
211
|
-
} = {}) {
|
|
212
|
-
const sslDir = getSslDir();
|
|
213
|
-
const config = loadConfig();
|
|
214
|
-
|
|
215
|
-
// Email is required for Let's Encrypt
|
|
216
|
-
const acmeEmail = email || config.acmeEmail;
|
|
217
|
-
if (!acmeEmail) {
|
|
218
|
-
return {
|
|
219
|
-
success: false,
|
|
220
|
-
certPath: null,
|
|
221
|
-
keyPath: null,
|
|
222
|
-
error: {
|
|
223
|
-
step: 'email configuration',
|
|
224
|
-
cause: 'No email address configured. Let\'s Encrypt requires an email for account creation.',
|
|
225
|
-
consequence: 'No certificate was issued. Configure acmeEmail in settings or provide email parameter.',
|
|
226
|
-
nginxRunning: true,
|
|
227
|
-
configSaved: false,
|
|
228
|
-
},
|
|
229
|
-
};
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
// Ensure certificate directory exists
|
|
233
|
-
const certDir = path.join(sslDir, domainName);
|
|
234
|
-
if (!isWindows) {
|
|
235
|
-
const user = os.userInfo().username;
|
|
236
|
-
await run(`sudo -n mkdir -p "${certDir}"`);
|
|
237
|
-
await run(`sudo -n chown ${user}:${user} "${certDir}"`);
|
|
238
|
-
} else {
|
|
239
|
-
await fs.mkdir(certDir, { recursive: true });
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
// Load or create account key
|
|
243
|
-
const accountKey = await getAccountKey(sslDir);
|
|
244
|
-
|
|
245
|
-
// Create ACME client (Let's Encrypt production)
|
|
246
|
-
const client = new acme.Client({
|
|
247
|
-
directoryUrl: acme.directory.letsencrypt.production,
|
|
248
|
-
accountKey,
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
// Wildcard requires DNS-01 — enforce it here
|
|
252
|
-
if (wildcard && validationMethod === 'http') {
|
|
253
|
-
return {
|
|
254
|
-
success: false,
|
|
255
|
-
certPath: null,
|
|
256
|
-
keyPath: null,
|
|
257
|
-
error: {
|
|
258
|
-
step: 'validation method',
|
|
259
|
-
cause: 'Wildcard certificates require DNS-01 validation, not HTTP-01.',
|
|
260
|
-
consequence: 'No certificate was issued. Change validation method to DNS.',
|
|
261
|
-
nginxRunning: true,
|
|
262
|
-
configSaved: false,
|
|
263
|
-
},
|
|
264
|
-
};
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
// altNames: wildcard includes both bare domain and *.domain
|
|
268
|
-
const altNames = wildcard
|
|
269
|
-
? [domainName, `*.${domainName}`]
|
|
270
|
-
: (www ? [domainName, `www.${domainName}`] : [domainName]);
|
|
271
|
-
const [domainKey, csr] = await acme.crypto.createCsr({
|
|
272
|
-
commonName: domainName,
|
|
273
|
-
altNames,
|
|
274
|
-
});
|
|
275
|
-
|
|
276
|
-
// ─── HTTP-01 Challenge ─────────────────────────────────────────────────────
|
|
277
|
-
if (validationMethod === 'http') {
|
|
278
|
-
// Stop nginx to free port 80
|
|
279
|
-
await stopNginx();
|
|
280
|
-
|
|
281
|
-
// Check port 80 is free
|
|
282
|
-
const portFree = await isPort80Free();
|
|
283
|
-
if (!portFree) {
|
|
284
|
-
await startNginx();
|
|
285
|
-
return {
|
|
286
|
-
success: false,
|
|
287
|
-
certPath: null,
|
|
288
|
-
keyPath: null,
|
|
289
|
-
error: {
|
|
290
|
-
step: 'port 80 check',
|
|
291
|
-
cause: 'Port 80 is still in use after stopping nginx. Another process may be binding it.',
|
|
292
|
-
consequence: 'No certificate was issued. nginx has been restarted.',
|
|
293
|
-
nginxRunning: true,
|
|
294
|
-
configSaved: false,
|
|
295
|
-
},
|
|
296
|
-
};
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
// Create temporary HTTP server for challenge
|
|
300
|
-
const challengeTokens = new Map();
|
|
301
|
-
let httpServer;
|
|
302
|
-
|
|
303
|
-
const challengeCreateFn = async (authz, challenge, keyAuthorization) => {
|
|
304
|
-
challengeTokens.set(challenge.token, keyAuthorization);
|
|
305
|
-
};
|
|
306
|
-
|
|
307
|
-
const challengeRemoveFn = async (authz, challenge, keyAuthorization) => {
|
|
308
|
-
challengeTokens.delete(challenge.token);
|
|
309
|
-
};
|
|
310
|
-
|
|
311
|
-
// Start temp HTTP server on port 80
|
|
312
|
-
httpServer = http.createServer((req, res) => {
|
|
313
|
-
const url = new URL(req.url, `http://${req.headers.host}`);
|
|
314
|
-
if (url.pathname.startsWith('/.well-known/acme-challenge/')) {
|
|
315
|
-
const token = url.pathname.split('/').pop();
|
|
316
|
-
const keyAuth = challengeTokens.get(token);
|
|
317
|
-
if (keyAuth) {
|
|
318
|
-
res.writeHead(200, { 'Content-Type': 'application/octet-stream' });
|
|
319
|
-
res.end(keyAuth);
|
|
320
|
-
return;
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
res.writeHead(404);
|
|
324
|
-
res.end('Not found');
|
|
325
|
-
});
|
|
326
|
-
|
|
327
|
-
await new Promise((resolve, reject) => {
|
|
328
|
-
httpServer.listen(80, (err) => {
|
|
329
|
-
if (err) reject(err);
|
|
330
|
-
else resolve();
|
|
331
|
-
});
|
|
332
|
-
});
|
|
333
|
-
|
|
334
|
-
try {
|
|
335
|
-
// Execute ACME challenge — returns the signed certificate PEM
|
|
336
|
-
// challengePriority forces http-01 only so acme-client never falls back to dns-01
|
|
337
|
-
const cert = await client.auto({
|
|
338
|
-
csr,
|
|
339
|
-
email: acmeEmail,
|
|
340
|
-
termsOfServiceAgreed: true,
|
|
341
|
-
challengePriority: ['http-01'],
|
|
342
|
-
challengeCreateFn,
|
|
343
|
-
challengeRemoveFn,
|
|
344
|
-
});
|
|
345
|
-
|
|
346
|
-
// Close HTTP server
|
|
347
|
-
await new Promise((resolve) => httpServer.close(resolve));
|
|
348
|
-
|
|
349
|
-
// Restart nginx
|
|
350
|
-
await startNginx();
|
|
351
|
-
|
|
352
|
-
// Write certificate files
|
|
353
|
-
const certPath = path.join(certDir, 'fullchain.pem');
|
|
354
|
-
const keyPath = path.join(certDir, 'privkey.pem');
|
|
355
|
-
|
|
356
|
-
await fs.writeFile(keyPath, domainKey);
|
|
357
|
-
await fs.writeFile(certPath, cert);
|
|
358
|
-
|
|
359
|
-
return { success: true, certPath, keyPath, error: null };
|
|
360
|
-
} catch (err) {
|
|
361
|
-
// Ensure server is closed and nginx restarted on error
|
|
362
|
-
await new Promise((resolve) => httpServer.close(resolve));
|
|
363
|
-
await startNginx();
|
|
364
|
-
return {
|
|
365
|
-
success: false,
|
|
366
|
-
certPath: null,
|
|
367
|
-
keyPath: null,
|
|
368
|
-
error: {
|
|
369
|
-
step: 'ACME validation',
|
|
370
|
-
cause: err.message || 'HTTP-01 challenge failed.',
|
|
371
|
-
consequence: 'No certificate was issued. nginx has been restarted.',
|
|
372
|
-
nginxRunning: true,
|
|
373
|
-
configSaved: false,
|
|
374
|
-
},
|
|
375
|
-
};
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
// ─── DNS-01 Challenge ──────────────────────────────────────────────────────
|
|
380
|
-
if (validationMethod === 'dns') {
|
|
381
|
-
const challengeCreateFn = async (authz, challenge, keyAuthorization) => {
|
|
382
|
-
const txtName = `_acme-challenge.${domainName}`;
|
|
383
|
-
const txtValue = keyAuthorization;
|
|
384
|
-
|
|
385
|
-
// Yield TXT record to caller and pause until they confirm DNS is set.
|
|
386
|
-
// onDnsChallenge is async — it returns only after the user confirms
|
|
387
|
-
// (dashboard: /create-confirm resolves the deferred; CLI: inquirer prompt).
|
|
388
|
-
if (onDnsChallenge) {
|
|
389
|
-
await onDnsChallenge(txtName, txtValue);
|
|
390
|
-
}
|
|
391
|
-
// challengeCreateFn returning here signals acme-client to proceed with validation.
|
|
392
|
-
};
|
|
393
|
-
|
|
394
|
-
const challengeRemoveFn = async () => {
|
|
395
|
-
// No-op: TXT record cleanup is the user's responsibility.
|
|
396
|
-
};
|
|
397
|
-
|
|
398
|
-
try {
|
|
399
|
-
// Execute ACME challenge — returns the signed certificate PEM
|
|
400
|
-
// challengePriority forces dns-01 only so acme-client never tries http-01
|
|
401
|
-
|
|
402
|
-
const cert = await client.auto({
|
|
403
|
-
csr,
|
|
404
|
-
email: acmeEmail,
|
|
405
|
-
termsOfServiceAgreed: true,
|
|
406
|
-
challengePriority: ['dns-01'],
|
|
407
|
-
challengeCreateFn,
|
|
408
|
-
challengeRemoveFn,
|
|
409
|
-
});
|
|
410
|
-
|
|
411
|
-
// Write certificate files
|
|
412
|
-
const certPath = path.join(certDir, 'fullchain.pem');
|
|
413
|
-
const keyPath = path.join(certDir, 'privkey.pem');
|
|
414
|
-
|
|
415
|
-
await fs.writeFile(keyPath, domainKey);
|
|
416
|
-
await fs.writeFile(certPath, cert);
|
|
417
|
-
|
|
418
|
-
return { success: true, certPath, keyPath, error: null };
|
|
419
|
-
} catch (err) {
|
|
420
|
-
return {
|
|
421
|
-
success: false,
|
|
422
|
-
certPath: null,
|
|
423
|
-
keyPath: null,
|
|
424
|
-
error: {
|
|
425
|
-
step: 'ACME validation',
|
|
426
|
-
cause: err.message || 'DNS-01 challenge failed.',
|
|
427
|
-
consequence: 'No certificate was issued. nginx was not affected.',
|
|
428
|
-
nginxRunning: true,
|
|
429
|
-
configSaved: false,
|
|
430
|
-
},
|
|
431
|
-
};
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
// Invalid validation method
|
|
436
|
-
return {
|
|
437
|
-
success: false,
|
|
438
|
-
certPath: null,
|
|
439
|
-
keyPath: null,
|
|
440
|
-
error: {
|
|
441
|
-
step: 'validation method',
|
|
442
|
-
cause: `Invalid validation method: ${validationMethod}. Must be 'http' or 'dns'.`,
|
|
443
|
-
consequence: 'No certificate was issued.',
|
|
444
|
-
nginxRunning: true,
|
|
445
|
-
configSaved: false,
|
|
446
|
-
},
|
|
447
|
-
};
|
|
141
|
+
export async function issueCert(domainName, options = {}) {
|
|
142
|
+
return issueCertificate(domainName, options);
|
|
448
143
|
}
|
|
449
144
|
|
|
450
145
|
/**
|
|
451
|
-
* Renews a certificate
|
|
452
|
-
*
|
|
146
|
+
* Renews a certificate.
|
|
147
|
+
*
|
|
148
|
+
* Goes through core/cert-renewal.js, the one renewal path: it keeps the names
|
|
149
|
+
* the certificate already covers (a `www` certificate stays one), prepares the
|
|
150
|
+
* nginx config, and reloads nginx so the new certificate is the one served.
|
|
151
|
+
* A DNS-01 / wildcard certificate is refused with `skipped: 'manual'` rather
|
|
152
|
+
* than silently replaced by a single-name HTTP-01 certificate.
|
|
453
153
|
*/
|
|
454
154
|
export async function renewCert(domainName, options = {}) {
|
|
455
|
-
return
|
|
155
|
+
return renewCertificate(domainName, { email: options.email ?? null, mode: options.mode ?? null });
|
|
456
156
|
}
|
|
457
157
|
|
|
458
158
|
/**
|
|
459
159
|
* Renews all certificates expiring within 30 days.
|
|
460
160
|
*/
|
|
461
|
-
export async function renewExpiring(certs) {
|
|
161
|
+
export async function renewExpiring(certs, options = {}) {
|
|
462
162
|
const expiring = certs.filter(c => c.daysLeft !== null && c.daysLeft < 30);
|
|
463
163
|
if (expiring.length === 0) return [];
|
|
464
164
|
|
|
465
165
|
const results = [];
|
|
466
166
|
for (const cert of expiring) {
|
|
467
|
-
const result = await
|
|
167
|
+
const result = await renewCert(cert.domain, options);
|
|
468
168
|
results.push({
|
|
469
169
|
domain: cert.domain,
|
|
470
170
|
success: result.success,
|
|
471
171
|
exitCode: result.success ? 0 : 1,
|
|
172
|
+
manual: result.skipped === 'manual',
|
|
173
|
+
configRegenerated: Boolean(result.configRegenerated),
|
|
174
|
+
error: result.success ? null : failureReason(result),
|
|
175
|
+
summary: describeRenewal(result),
|
|
472
176
|
});
|
|
473
177
|
}
|
|
474
178
|
return results;
|
|
@@ -607,7 +311,14 @@ export async function showSslManager() {
|
|
|
607
311
|
if (result.success) {
|
|
608
312
|
console.log(chalk.green('\n ✓ Certificate created successfully'));
|
|
609
313
|
console.log(chalk.gray(` Cert: ${result.certPath}`));
|
|
610
|
-
console.log(chalk.gray(` Key: ${result.keyPath}
|
|
314
|
+
console.log(chalk.gray(` Key: ${result.keyPath}`));
|
|
315
|
+
// Say whether nginx stayed up, or fell back and for how long.
|
|
316
|
+
const summary = describeIssuance(result);
|
|
317
|
+
if (summary) {
|
|
318
|
+
const warn = result.fellBack || result.staging || result.nginxRestored === false;
|
|
319
|
+
console.log((warn ? chalk.yellow : chalk.gray)(` ${summary}`));
|
|
320
|
+
}
|
|
321
|
+
console.log();
|
|
611
322
|
} else {
|
|
612
323
|
const e = result.error;
|
|
613
324
|
console.log(chalk.red('\n ✗ Certificate creation failed'));
|
|
@@ -640,14 +351,18 @@ export async function showSslManager() {
|
|
|
640
351
|
|
|
641
352
|
const config = loadConfig();
|
|
642
353
|
const spinner = ora(`Renewing certificate for ${selectedDomain}…`).start();
|
|
643
|
-
const result = await renewCert(selectedDomain, {
|
|
644
|
-
validationMethod: 'http',
|
|
645
|
-
email: config.acmeEmail,
|
|
646
|
-
});
|
|
354
|
+
const result = await renewCert(selectedDomain, { email: config.acmeEmail });
|
|
647
355
|
spinner.stop();
|
|
648
356
|
|
|
649
357
|
if (result.success) {
|
|
650
|
-
console.log(chalk.green('\n ✓ Renewed successfully
|
|
358
|
+
console.log(chalk.green('\n ✓ Renewed successfully'));
|
|
359
|
+
const summary = describeRenewal(result);
|
|
360
|
+
if (summary) console.log(chalk.gray(` ${summary}`));
|
|
361
|
+
console.log();
|
|
362
|
+
} else if (result.skipped === 'manual') {
|
|
363
|
+
console.log(chalk.yellow('\n ⚠ This certificate cannot be renewed over HTTP'));
|
|
364
|
+
console.log(chalk.yellow(` ${result.error.cause}`));
|
|
365
|
+
console.log(chalk.gray(' Use "Create new certificate" with the DNS challenge to renew it.\n'));
|
|
651
366
|
} else {
|
|
652
367
|
const e = result.error;
|
|
653
368
|
console.log(chalk.red('\n ✗ Renewal failed'));
|
|
@@ -666,9 +381,11 @@ export async function showSslManager() {
|
|
|
666
381
|
console.log();
|
|
667
382
|
for (const r of results) {
|
|
668
383
|
if (r.success) {
|
|
669
|
-
console.log(` ${chalk.green('✓ ' + r.domain)}`);
|
|
384
|
+
console.log(` ${chalk.green('✓ ' + r.domain)}${r.summary ? chalk.gray(` ${r.summary}`) : ''}`);
|
|
385
|
+
} else if (r.manual) {
|
|
386
|
+
console.log(` ${chalk.yellow('⚠ ' + r.domain)}${chalk.gray(' DNS-validated — renew it manually')}`);
|
|
670
387
|
} else {
|
|
671
|
-
console.log(` ${chalk.red('✗ ' + r.domain)}`);
|
|
388
|
+
console.log(` ${chalk.red('✗ ' + r.domain)}${r.error ? chalk.gray(` ${r.error}`) : ''}`);
|
|
672
389
|
}
|
|
673
390
|
}
|
|
674
391
|
console.log();
|
package/src/cli/menu.js
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* cli/menu.js
|
|
3
|
+
*
|
|
4
|
+
* The interactive CLI application: banner, main menu and dispatch.
|
|
5
|
+
*
|
|
6
|
+
* Moved here from cli/index.js so that index.js can stay a thin bootstrap with
|
|
7
|
+
* no static imports that reach core/db.js. ESM evaluates static imports before
|
|
8
|
+
* any module body runs, so the data directory must be chosen (via
|
|
9
|
+
* EASY_DEVOPS_DATA_DIR) before this module is dynamically imported.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { createRequire } from 'module';
|
|
13
|
+
import chalk from 'chalk';
|
|
14
|
+
import ora from 'ora';
|
|
15
|
+
import inquirer from 'inquirer';
|
|
16
|
+
import { runDetection, showSystemStatus, formatStatusLine } from '../core/detector.js';
|
|
17
|
+
import { getDataDir, isDevDataDir } from '../core/platform.js';
|
|
18
|
+
|
|
19
|
+
import nodejsMenu from './menus/nodejs.js';
|
|
20
|
+
import nginxMenu from './menus/nginx.js';
|
|
21
|
+
import sslMenu from './menus/ssl.js';
|
|
22
|
+
import domainsMenu from './menus/domains.js';
|
|
23
|
+
import dashboardMenu from './menus/dashboard.js';
|
|
24
|
+
import settingsMenu from './menus/settings.js';
|
|
25
|
+
import updateMenu from './menus/update.js';
|
|
26
|
+
|
|
27
|
+
const require = createRequire(import.meta.url);
|
|
28
|
+
const { version } = require('../../package.json');
|
|
29
|
+
|
|
30
|
+
// ─── Detection cache — only re-run if stale (>60s) ───────────────────────────
|
|
31
|
+
const DETECTION_TTL_MS = 60_000;
|
|
32
|
+
let lastDetectionAt = 0;
|
|
33
|
+
|
|
34
|
+
async function runDetectionIfStale() {
|
|
35
|
+
const now = Date.now();
|
|
36
|
+
if (now - lastDetectionAt >= DETECTION_TTL_MS) {
|
|
37
|
+
await runDetection();
|
|
38
|
+
lastDetectionAt = now;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function renderBanner() {
|
|
43
|
+
const c = chalk.hex('#d64a29');
|
|
44
|
+
const dim = chalk.hex('#d64a29').dim;
|
|
45
|
+
|
|
46
|
+
// Compact "EZ" logo — 6 lines, ~20 chars wide, fits any 80-col terminal
|
|
47
|
+
const logo = [
|
|
48
|
+
'███████╗███████╗',
|
|
49
|
+
'██╔════╝╚════██╗',
|
|
50
|
+
'█████╗ ██╔╝',
|
|
51
|
+
'██╔══╝ ██╔╝ ',
|
|
52
|
+
'███████╗ ██████╗',
|
|
53
|
+
'╚══════╝ ╚═════╝',
|
|
54
|
+
];
|
|
55
|
+
|
|
56
|
+
const gap = ' ';
|
|
57
|
+
const info = [
|
|
58
|
+
chalk.bold.white('Easy DevOps') + ' ' + chalk.hex('#d64a29')(`v${version}`),
|
|
59
|
+
dim('─────────────────────'),
|
|
60
|
+
chalk.hex('#888888')('CLI & Web Dashboard'),
|
|
61
|
+
chalk.hex('#888888')('Nginx · SSL · Domains · Node.js'),
|
|
62
|
+
'',
|
|
63
|
+
'',
|
|
64
|
+
];
|
|
65
|
+
|
|
66
|
+
console.log();
|
|
67
|
+
logo.forEach((line, i) => {
|
|
68
|
+
console.log(' ' + c(line) + gap + (info[i] ?? ''));
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// Always show which database this process is on, and shout when it is an
|
|
72
|
+
// isolated one. The CLI and the dashboard are separate processes: if they
|
|
73
|
+
// disagree about the data directory they edit different domain lists, which
|
|
74
|
+
// looks exactly like the Hub failing to sync rather than a wrong directory.
|
|
75
|
+
if (isDevDataDir()) {
|
|
76
|
+
console.log(' ' + chalk.bgYellow.black(' DEV MODE ') + ' ' +
|
|
77
|
+
chalk.yellow(`data: ${getDataDir()}`));
|
|
78
|
+
console.log(' ' + chalk.yellow(' the dashboard must use the same --dev / EASY_DEVOPS_DATA_DIR'));
|
|
79
|
+
} else {
|
|
80
|
+
console.log(' ' + chalk.hex('#666666')(`data: ${getDataDir()}`));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
console.log();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async function showMainMenu() {
|
|
87
|
+
const answers = await inquirer.prompt([{
|
|
88
|
+
type: 'list',
|
|
89
|
+
name: 'choice',
|
|
90
|
+
message: 'Select an option:',
|
|
91
|
+
choices: [
|
|
92
|
+
'📦 Node.js Manager',
|
|
93
|
+
'🌐 Nginx Manager',
|
|
94
|
+
'🔒 SSL Manager',
|
|
95
|
+
'🔗 Domain Manager',
|
|
96
|
+
'🎛️ Open Dashboard',
|
|
97
|
+
'⚙️ Settings',
|
|
98
|
+
'🔄 Check for Updates',
|
|
99
|
+
'✖ Exit',
|
|
100
|
+
],
|
|
101
|
+
}]);
|
|
102
|
+
return answers.choice;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
async function dispatch(choice) {
|
|
106
|
+
switch (choice) {
|
|
107
|
+
case '📦 Node.js Manager': await nodejsMenu(); break;
|
|
108
|
+
case '🌐 Nginx Manager': await nginxMenu(); break;
|
|
109
|
+
case '🔒 SSL Manager': await sslMenu(); break;
|
|
110
|
+
case '🔗 Domain Manager': await domainsMenu(); break;
|
|
111
|
+
case '🎛️ Open Dashboard': await dashboardMenu(); break;
|
|
112
|
+
case '⚙️ Settings': await settingsMenu(); break;
|
|
113
|
+
case '🔄 Check for Updates': await updateMenu(); break;
|
|
114
|
+
case '✖ Exit': process.exit(0);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
async function main() {
|
|
119
|
+
while (true) {
|
|
120
|
+
const spinner = ora('Checking system…').start();
|
|
121
|
+
await runDetectionIfStale();
|
|
122
|
+
spinner.stop();
|
|
123
|
+
|
|
124
|
+
try {
|
|
125
|
+
renderBanner();
|
|
126
|
+
console.log(' ' + formatStatusLine());
|
|
127
|
+
console.log();
|
|
128
|
+
} catch {
|
|
129
|
+
console.log(`\n=== Easy DevOps v${version} ===\n`);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
try {
|
|
133
|
+
const choice = await showMainMenu();
|
|
134
|
+
await dispatch(choice);
|
|
135
|
+
} catch (err) {
|
|
136
|
+
if (err.name === 'ExitPromptError') {
|
|
137
|
+
process.exit(0);
|
|
138
|
+
}
|
|
139
|
+
throw err;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Runs the interactive CLI loop. Never returns — exits via the menu.
|
|
146
|
+
*/
|
|
147
|
+
export async function run() {
|
|
148
|
+
await main();
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** Prints detected system info once and returns. */
|
|
152
|
+
export async function systemInfo() {
|
|
153
|
+
await runDetection();
|
|
154
|
+
showSystemStatus();
|
|
155
|
+
}
|
|
156
|
+
|