easy-devops 0.2.5 → 0.2.7
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/cli/managers/domain-manager.js +62 -0
- package/cli/managers/nginx-manager.js +51 -91
- package/cli/managers/ssl-manager.js +147 -0
- package/core/nginx-conf-generator.js +1 -1
- package/dashboard/public/js/app.js +74 -1
- package/dashboard/routes/domains.js +14 -0
- package/dashboard/routes/ssl.js +35 -0
- package/dashboard/views/partials/domain-form.ejs +28 -0
- package/dashboard/views/partials/ssl-panel.ejs +46 -4
- package/package.json +1 -1
|
@@ -13,11 +13,13 @@
|
|
|
13
13
|
import chalk from 'chalk';
|
|
14
14
|
import inquirer from 'inquirer';
|
|
15
15
|
import ora from 'ora';
|
|
16
|
+
import fs from 'fs/promises';
|
|
16
17
|
import Table from 'cli-table3';
|
|
17
18
|
import { run } from '../../core/shell.js';
|
|
18
19
|
import { loadConfig } from '../../core/config.js';
|
|
19
20
|
import { getDomains, saveDomains, findDomain, createDomain, DOMAIN_DEFAULTS } from '../../dashboard/lib/domains-db.js';
|
|
20
21
|
import { generateConf, buildConf } from '../../core/nginx-conf-generator.js';
|
|
22
|
+
import { issueCert } from './ssl-manager.js';
|
|
21
23
|
|
|
22
24
|
const isWindows = process.platform === 'win32';
|
|
23
25
|
|
|
@@ -139,6 +141,66 @@ async function addDomainAction() {
|
|
|
139
141
|
ssl = { ...ssl, ...sslDetails };
|
|
140
142
|
}
|
|
141
143
|
|
|
144
|
+
// Cert existence check (FR-001, FR-002)
|
|
145
|
+
if (ssl.enabled) {
|
|
146
|
+
let certExists = false;
|
|
147
|
+
try {
|
|
148
|
+
await fs.access(ssl.certPath, fs.constants.F_OK);
|
|
149
|
+
certExists = true;
|
|
150
|
+
} catch {
|
|
151
|
+
certExists = false;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (!certExists) {
|
|
155
|
+
console.log(chalk.yellow(`\n ⚠ Certificate not found at: ${ssl.certPath}`));
|
|
156
|
+
|
|
157
|
+
let certAction;
|
|
158
|
+
try {
|
|
159
|
+
({ certAction } = await inquirer.prompt([{
|
|
160
|
+
type: 'list',
|
|
161
|
+
name: 'certAction',
|
|
162
|
+
message: 'What would you like to do?',
|
|
163
|
+
choices: ['Create certificate now', 'Disable SSL', 'Cancel'],
|
|
164
|
+
}]));
|
|
165
|
+
} catch (err) {
|
|
166
|
+
if (err.name === 'ExitPromptError') return;
|
|
167
|
+
throw err;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (certAction === 'Cancel') {
|
|
171
|
+
console.log(chalk.gray('\n Cancelled.\n'));
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (certAction === 'Disable SSL') {
|
|
176
|
+
ssl.enabled = false;
|
|
177
|
+
console.log(chalk.gray(' SSL disabled. Domain will be saved as HTTP-only.\n'));
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (certAction === 'Create certificate now') {
|
|
181
|
+
const spinner = ora(`Creating certificate for ${basic.name}…`).start();
|
|
182
|
+
const result = await issueCert(basic.name, { www: basic.www });
|
|
183
|
+
spinner.stop();
|
|
184
|
+
|
|
185
|
+
if (result.success) {
|
|
186
|
+
console.log(chalk.green('\n ✓ Certificate created successfully'));
|
|
187
|
+
console.log(chalk.gray(` Cert: ${result.certPath}`));
|
|
188
|
+
console.log(chalk.gray(` Key: ${result.keyPath}\n`));
|
|
189
|
+
ssl.certPath = result.certPath;
|
|
190
|
+
ssl.keyPath = result.keyPath;
|
|
191
|
+
} else {
|
|
192
|
+
const e = result.error;
|
|
193
|
+
console.log(chalk.red('\n ✗ Certificate creation failed — domain was not saved'));
|
|
194
|
+
console.log(chalk.yellow(` Step: ${e.step}`));
|
|
195
|
+
console.log(chalk.yellow(` Cause: ${e.cause}`));
|
|
196
|
+
console.log(chalk.yellow(` Consequence: ${e.consequence}`));
|
|
197
|
+
console.log(chalk.gray(` nginx running: ${e.nginxRunning ? 'yes' : 'no'}\n`));
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
142
204
|
// Section 3: Proxy Behavior
|
|
143
205
|
const proxy = await inquirer.prompt([
|
|
144
206
|
{ type: 'input', name: 'maxBodySize', message: 'Max body size:', default: '10m' },
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Nginx Manager — full control over nginx from the CLI.
|
|
5
5
|
*
|
|
6
6
|
* Exported functions:
|
|
7
|
-
*
|
|
7
|
+
* - showNginxManager() — interactive menu for managing nginx
|
|
8
8
|
*
|
|
9
9
|
* All shell calls go through core/shell.js (run / runLive).
|
|
10
10
|
* Platform differences (Windows/Linux) are handled via isWindows guards.
|
|
@@ -14,9 +14,8 @@ import chalk from 'chalk';
|
|
|
14
14
|
import inquirer from 'inquirer';
|
|
15
15
|
import ora from 'ora';
|
|
16
16
|
import { run, runLive } from '../../core/shell.js';
|
|
17
|
-
import { loadConfig
|
|
17
|
+
import { loadConfig } from '../../core/config.js';
|
|
18
18
|
import { ensureNginxInclude } from '../../core/nginx-conf-generator.js';
|
|
19
|
-
import { runDetection } from '../../core/detector.js';
|
|
20
19
|
|
|
21
20
|
const isWindows = process.platform === 'win32';
|
|
22
21
|
|
|
@@ -56,6 +55,18 @@ async function testConfig(nginxExe, nginxDir) {
|
|
|
56
55
|
await ensureNginxInclude(nginxDir);
|
|
57
56
|
const cmd = isWindows ? `& "${nginxExe}" -t` : 'nginx -t';
|
|
58
57
|
const result = await run(cmd, { cwd: nginxDir });
|
|
58
|
+
const PathDomain = await import('fs/promises').then(fs => fs.exists(`${nginxDir}\\conf\\conf.d`));
|
|
59
|
+
|
|
60
|
+
if (!PathDomain) {
|
|
61
|
+
const createPath = await import('fs/promises').then(fs => fs.mkdir(`${nginxDir}\\conf\\conf.d`, { recursive: true }));
|
|
62
|
+
if (!createPath) {
|
|
63
|
+
return {
|
|
64
|
+
success: false,
|
|
65
|
+
output: `Failed to create conf.d directory at ${nginxDir}\\conf\\conf.d`,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
59
70
|
return {
|
|
60
71
|
success: result.success,
|
|
61
72
|
output: (result.stdout + '\n' + result.stderr).trim(),
|
|
@@ -137,7 +148,7 @@ async function viewErrorLog(logPath) {
|
|
|
137
148
|
if (result.success && result.stdout) {
|
|
138
149
|
console.log('\n' + result.stdout);
|
|
139
150
|
} else {
|
|
140
|
-
console.log(chalk.yellow('\n
|
|
151
|
+
console.log(chalk.yellow('\n No errors logged yet (log file not found or empty)\n'));
|
|
141
152
|
}
|
|
142
153
|
}
|
|
143
154
|
|
|
@@ -197,11 +208,11 @@ async function startNginx(nginxExe, nginxDir) {
|
|
|
197
208
|
: `tail -n 20 "${logPath}" 2>/dev/null`;
|
|
198
209
|
const logResult = await run(logCmd);
|
|
199
210
|
|
|
200
|
-
console.log(chalk.yellow('\n
|
|
211
|
+
console.log(chalk.yellow('\n Recent error log:'));
|
|
201
212
|
if (logResult.success && logResult.stdout) {
|
|
202
213
|
console.log(chalk.red(logResult.stdout));
|
|
203
214
|
} else {
|
|
204
|
-
console.log(chalk.gray('
|
|
215
|
+
console.log(chalk.gray(' (error log not found or empty)'));
|
|
205
216
|
}
|
|
206
217
|
|
|
207
218
|
return { success: false };
|
|
@@ -234,113 +245,62 @@ async function installNginx() {
|
|
|
234
245
|
}
|
|
235
246
|
spinner.fail('Installation failed');
|
|
236
247
|
console.log(chalk.red(result.stderr || result.stdout));
|
|
237
|
-
console.log(chalk.gray('\n
|
|
248
|
+
console.log(chalk.gray('\n Manual instructions: https://nginx.org/en/docs/install.html\n'));
|
|
238
249
|
return { success: false, message: 'Installation failed', output: result.stderr || result.stdout };
|
|
239
250
|
}
|
|
240
251
|
|
|
241
252
|
// ── Windows ──────────────────────────────────────────────────────────────────
|
|
242
253
|
const spinner = ora('Checking for winget…').start();
|
|
254
|
+
//! Winget is not reliably available on all Windows versions (missing from Windows Server, and some users report it missing on Windows 10 desktop), so we'll skip it for now and go straight to the direct download method. We can revisit this in the future if winget becomes more ubiquitous.
|
|
243
255
|
|
|
244
256
|
// Try winget first (available on Windows 10/11 desktop; not on Windows Server by default)
|
|
245
|
-
const wingetCheck = await run('where.exe winget 2>$null');
|
|
246
|
-
const hasWinget = wingetCheck.success && wingetCheck.stdout.trim().length > 0;
|
|
247
|
-
|
|
248
|
-
if (hasWinget) {
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
'C:\\nginx',
|
|
264
|
-
`${process.env.ProgramFiles}\\nginx`,
|
|
265
|
-
`${process.env.LOCALAPPDATA}\\Programs\\nginx`,
|
|
266
|
-
`${process.env.ProgramW6432}\\nginx`,
|
|
267
|
-
];
|
|
268
|
-
|
|
269
|
-
let foundPath = null;
|
|
270
|
-
for (const p of commonPaths) {
|
|
271
|
-
if (!p) continue;
|
|
272
|
-
const check = await run(`Test-Path "${p}\\nginx.exe"`);
|
|
273
|
-
if (check.stdout.trim().toLowerCase() === 'true') {
|
|
274
|
-
foundPath = p;
|
|
275
|
-
break;
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
if (foundPath) {
|
|
280
|
-
// Update config if different from current
|
|
281
|
-
const currentConfig = loadConfig();
|
|
282
|
-
if (currentConfig.nginxDir !== foundPath) {
|
|
283
|
-
currentConfig.nginxDir = foundPath;
|
|
284
|
-
saveConfig(currentConfig);
|
|
285
|
-
}
|
|
286
|
-
spinner.succeed(`nginx installed at ${foundPath}`);
|
|
287
|
-
} else {
|
|
288
|
-
spinner.succeed('nginx installed successfully');
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
// Re-run detection to update the stored info
|
|
292
|
-
await runDetection();
|
|
293
|
-
return { success: true, message: 'nginx installed successfully', output: result.stdout };
|
|
294
|
-
}
|
|
295
|
-
spinner.fail('winget install failed');
|
|
296
|
-
console.log(chalk.red(result.stderr || result.stdout));
|
|
297
|
-
console.log(chalk.gray('\n Manual instructions: https://nginx.org/en/docs/install.html\n'));
|
|
298
|
-
return { success: false, message: 'Installation failed', output: result.stderr || result.stdout };
|
|
299
|
-
}
|
|
257
|
+
// const wingetCheck = await run('where.exe winget 2>$null');
|
|
258
|
+
// const hasWinget = wingetCheck.success && wingetCheck.stdout.trim().length > 0;
|
|
259
|
+
|
|
260
|
+
// if (hasWinget) {
|
|
261
|
+
// spinner.text = 'Installing nginx via winget…';
|
|
262
|
+
// const result = await run(
|
|
263
|
+
// 'winget install -e --id Nginx.Nginx --accept-package-agreements --accept-source-agreements',
|
|
264
|
+
// { timeout: 120000 },
|
|
265
|
+
// );
|
|
266
|
+
// if (result.success) {
|
|
267
|
+
// spinner.succeed('nginx installed successfully');
|
|
268
|
+
// return { success: true, message: 'nginx installed successfully', output: result.stdout };
|
|
269
|
+
// }
|
|
270
|
+
// spinner.fail('winget install failed');
|
|
271
|
+
// console.log(chalk.red(result.stderr || result.stdout));
|
|
272
|
+
// console.log(chalk.gray('\n Manual instructions: https://nginx.org/en/docs/install.html\n'));
|
|
273
|
+
// return { success: false, message: 'Installation failed', output: result.stderr || result.stdout };
|
|
274
|
+
// }
|
|
300
275
|
|
|
301
276
|
// ── Fallback: direct download from nginx.org ─────────────────────────────────
|
|
302
277
|
spinner.text = 'Fetching latest nginx version…';
|
|
303
278
|
|
|
304
279
|
// Try to resolve the current stable version; fall back to a known-good release
|
|
305
|
-
const FALLBACK_VERSION = '1.
|
|
280
|
+
const FALLBACK_VERSION = '1.29.6';
|
|
306
281
|
let nginxVersion = FALLBACK_VERSION;
|
|
307
282
|
|
|
308
283
|
const fetchVersionResult = await run(
|
|
309
|
-
`
|
|
284
|
+
`try { $p=(Invoke-WebRequest -Uri 'https://nginx.org/en/download.html' -UseBasicParsing -TimeoutSec 15).Content; if($p -match 'nginx-(\\d+\\.\\d+\\.\\d+)\\.zip'){$Matches[1]}else{''} } catch { '' }`,
|
|
310
285
|
{ timeout: 20000 },
|
|
311
286
|
);
|
|
312
287
|
const fetched = (fetchVersionResult.stdout || '').trim();
|
|
313
288
|
if (/^\d+\.\d+\.\d+$/.test(fetched)) nginxVersion = fetched;
|
|
314
289
|
|
|
315
|
-
|
|
290
|
+
const { nginxDir } = loadConfig();
|
|
316
291
|
const zipUrl = `https://nginx.org/download/nginx-${nginxVersion}.zip`;
|
|
317
|
-
const zipDest = `$env:TEMP\\nginx-${nginxVersion}.zip`;
|
|
318
292
|
|
|
319
293
|
spinner.text = `Downloading nginx ${nginxVersion}…`;
|
|
320
294
|
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
let downloadResult = await run(
|
|
324
|
-
`[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $ProgressPreference='SilentlyContinue'; Invoke-WebRequest -Uri '${zipUrl}' -OutFile "${zipDest}" -UseBasicParsing -TimeoutSec 120`,
|
|
295
|
+
const downloadResult = await run(
|
|
296
|
+
`$ProgressPreference='SilentlyContinue'; Invoke-WebRequest -Uri '${zipUrl}' -OutFile "$env:TEMP\\nginx-${nginxVersion}.zip" -UseBasicParsing -TimeoutSec 120`,
|
|
325
297
|
{ timeout: 130000 },
|
|
326
298
|
);
|
|
327
|
-
if (downloadResult.success) {
|
|
328
|
-
downloadOk = true;
|
|
329
|
-
} else {
|
|
330
|
-
const hasCurl = (await run('where.exe curl.exe 2>$null')).success;
|
|
331
|
-
if (hasCurl) {
|
|
332
|
-
downloadResult = await run(
|
|
333
|
-
`curl.exe -L --silent --show-error --max-time 120 -o "${zipDest}" "${zipUrl}"`,
|
|
334
|
-
{ timeout: 130000 },
|
|
335
|
-
);
|
|
336
|
-
if (downloadResult.success) downloadOk = true;
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
299
|
|
|
340
|
-
if (!
|
|
300
|
+
if (!downloadResult.success) {
|
|
341
301
|
spinner.fail('Download failed');
|
|
342
302
|
console.log(chalk.red(downloadResult.stderr || downloadResult.stdout));
|
|
343
|
-
console.log(chalk.gray(`\n
|
|
303
|
+
console.log(chalk.gray(`\n Download nginx manually from: https://nginx.org/en/download.html\n`));
|
|
344
304
|
return { success: false, message: 'Download failed', output: downloadResult.stderr || downloadResult.stdout };
|
|
345
305
|
}
|
|
346
306
|
|
|
@@ -364,8 +324,8 @@ async function installNginx() {
|
|
|
364
324
|
return { success: false, message: 'nginx.exe not found after extraction' };
|
|
365
325
|
}
|
|
366
326
|
|
|
367
|
-
//
|
|
368
|
-
await
|
|
327
|
+
// Create conf/conf.d directory for domain config files
|
|
328
|
+
await import('fs/promises').then(fs => fs.mkdir(`${nginxDir}\\conf\\conf.d`, { recursive: true }));
|
|
369
329
|
|
|
370
330
|
spinner.succeed(`nginx ${nginxVersion} installed to ${nginxDir}`);
|
|
371
331
|
return { success: true, message: `nginx ${nginxVersion} installed successfully`, output: '' };
|
|
@@ -378,14 +338,14 @@ export async function showNginxManager() {
|
|
|
378
338
|
const { nginxDir } = loadConfig();
|
|
379
339
|
const status = await getNginxStatus(nginxDir);
|
|
380
340
|
|
|
381
|
-
console.log(chalk.bold('\n
|
|
382
|
-
console.log(chalk.gray('
|
|
341
|
+
console.log(chalk.bold('\n Nginx Manager'));
|
|
342
|
+
console.log(chalk.gray(' ' + '─'.repeat(40)));
|
|
383
343
|
|
|
384
344
|
if (status.version) {
|
|
385
345
|
const statusIcon = status.running ? chalk.green('✅ Running') : chalk.red('❌ Stopped');
|
|
386
|
-
console.log(`
|
|
346
|
+
console.log(` ${statusIcon} | v${status.version} | ${status.nginxDir}`);
|
|
387
347
|
} else {
|
|
388
|
-
console.log(`
|
|
348
|
+
console.log(` ${chalk.yellow('⚠ Not installed')}`);
|
|
389
349
|
}
|
|
390
350
|
console.log();
|
|
391
351
|
|
|
@@ -435,7 +395,7 @@ export async function showNginxManager() {
|
|
|
435
395
|
case 'Test config': {
|
|
436
396
|
const result = await testConfig(status.nginxExe, status.nginxDir);
|
|
437
397
|
console.log(
|
|
438
|
-
'\n
|
|
398
|
+
'\n Config test: ' +
|
|
439
399
|
(result.success ? chalk.green('✓ OK') : chalk.red('✗ Failed')) +
|
|
440
400
|
'\n',
|
|
441
401
|
);
|
|
@@ -680,6 +680,107 @@ async function installCertbot() {
|
|
|
680
680
|
return { success: false };
|
|
681
681
|
}
|
|
682
682
|
|
|
683
|
+
// ─── issueCert ────────────────────────────────────────────────────────────────
|
|
684
|
+
|
|
685
|
+
/**
|
|
686
|
+
* Issues a new SSL certificate using the installed ACME client.
|
|
687
|
+
* Stops nginx before the challenge and restarts it afterwards (always).
|
|
688
|
+
*
|
|
689
|
+
* @param {string} domainName - The primary domain name
|
|
690
|
+
* @param {{ www?: boolean }} options
|
|
691
|
+
* @returns {Promise<{ success: boolean, certPath: string|null, keyPath: string|null, error: object|null }>}
|
|
692
|
+
*/
|
|
693
|
+
export async function issueCert(domainName, { www = false } = {}) {
|
|
694
|
+
// Guard: ACME client must be installed
|
|
695
|
+
const certbotExe = await getCertbotExe();
|
|
696
|
+
if (!certbotExe) {
|
|
697
|
+
return {
|
|
698
|
+
success: false,
|
|
699
|
+
certPath: null,
|
|
700
|
+
keyPath: null,
|
|
701
|
+
error: {
|
|
702
|
+
step: 'ACME client detection',
|
|
703
|
+
cause: 'No ACME client (certbot or win-acme) is installed on this server.',
|
|
704
|
+
consequence: 'No certificate was issued. Install certbot or win-acme using the SSL Manager first.',
|
|
705
|
+
nginxRunning: true,
|
|
706
|
+
configSaved: false,
|
|
707
|
+
},
|
|
708
|
+
};
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
const clientType = await getAcmeClientType();
|
|
712
|
+
|
|
713
|
+
// Stop nginx (tolerate failure — nginx may not have been running)
|
|
714
|
+
await stopNginx();
|
|
715
|
+
|
|
716
|
+
try {
|
|
717
|
+
// Check port 80 is free for the standalone challenge
|
|
718
|
+
const portCheck = await isPort80Busy();
|
|
719
|
+
if (portCheck.busy) {
|
|
720
|
+
await startNginx();
|
|
721
|
+
return {
|
|
722
|
+
success: false,
|
|
723
|
+
certPath: null,
|
|
724
|
+
keyPath: null,
|
|
725
|
+
error: {
|
|
726
|
+
step: 'port 80 check',
|
|
727
|
+
cause: `Port 80 is still in use: ${portCheck.detail}. Stop that process before creating a certificate.`,
|
|
728
|
+
consequence: 'The standalone ACME challenge cannot bind to port 80. No certificate was issued. nginx has been restarted.',
|
|
729
|
+
nginxRunning: true,
|
|
730
|
+
configSaved: false,
|
|
731
|
+
},
|
|
732
|
+
};
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
// Build and run the ACME command
|
|
736
|
+
const domainArgs = www ? `-d "${domainName}" -d "www.${domainName}"` : `-d "${domainName}"`;
|
|
737
|
+
const cmd = clientType === 'winacme'
|
|
738
|
+
? certbotExe
|
|
739
|
+
: `${certbotExe} certonly --standalone --non-interactive --agree-tos ${domainArgs}`;
|
|
740
|
+
|
|
741
|
+
const exitCode = await runLive(cmd, { timeout: 120000 });
|
|
742
|
+
|
|
743
|
+
if (exitCode !== 0) {
|
|
744
|
+
await startNginx();
|
|
745
|
+
return {
|
|
746
|
+
success: false,
|
|
747
|
+
certPath: null,
|
|
748
|
+
keyPath: null,
|
|
749
|
+
error: {
|
|
750
|
+
step: 'ACME domain validation',
|
|
751
|
+
cause: 'The ACME challenge failed. Common causes: domain DNS does not point to this server, or port 80 is blocked by a firewall.',
|
|
752
|
+
consequence: 'No certificate was issued. nginx has been restarted.',
|
|
753
|
+
nginxRunning: true,
|
|
754
|
+
configSaved: false,
|
|
755
|
+
},
|
|
756
|
+
};
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
// Derive cert paths from the certbot live directory
|
|
760
|
+
const liveDir = getCertbotDir();
|
|
761
|
+
const certPath = path.join(liveDir, domainName, 'fullchain.pem');
|
|
762
|
+
const keyPath = path.join(liveDir, domainName, 'privkey.pem');
|
|
763
|
+
|
|
764
|
+
await startNginx();
|
|
765
|
+
|
|
766
|
+
return { success: true, certPath, keyPath, error: null };
|
|
767
|
+
} catch (err) {
|
|
768
|
+
try { await startNginx(); } catch { /* best effort */ }
|
|
769
|
+
return {
|
|
770
|
+
success: false,
|
|
771
|
+
certPath: null,
|
|
772
|
+
keyPath: null,
|
|
773
|
+
error: {
|
|
774
|
+
step: 'certificate issuance',
|
|
775
|
+
cause: err.message,
|
|
776
|
+
consequence: 'An unexpected error occurred during certificate issuance. nginx restart was attempted.',
|
|
777
|
+
nginxRunning: false,
|
|
778
|
+
configSaved: false,
|
|
779
|
+
},
|
|
780
|
+
};
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
|
|
683
784
|
// ─── showSslManager ───────────────────────────────────────────────────────────
|
|
684
785
|
|
|
685
786
|
export async function showSslManager() {
|
|
@@ -703,6 +804,7 @@ export async function showSslManager() {
|
|
|
703
804
|
console.log();
|
|
704
805
|
|
|
705
806
|
const choices = [
|
|
807
|
+
'Create new certificate',
|
|
706
808
|
'Renew a certificate',
|
|
707
809
|
'Renew all expiring (< 30 days)',
|
|
708
810
|
'Install certbot',
|
|
@@ -724,6 +826,51 @@ export async function showSslManager() {
|
|
|
724
826
|
}
|
|
725
827
|
|
|
726
828
|
switch (choice) {
|
|
829
|
+
case 'Create new certificate': {
|
|
830
|
+
const installed = await isCertbotInstalled();
|
|
831
|
+
if (!installed) {
|
|
832
|
+
console.log(chalk.yellow('\n ⚠ certbot/win-acme not found — select "Install certbot" first\n'));
|
|
833
|
+
break;
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
let domainInput, wwwInput;
|
|
837
|
+
try {
|
|
838
|
+
({ domainInput } = await inquirer.prompt([{
|
|
839
|
+
type: 'input',
|
|
840
|
+
name: 'domainInput',
|
|
841
|
+
message: 'Domain name:',
|
|
842
|
+
validate: v => v.trim() ? true : 'Required',
|
|
843
|
+
}]));
|
|
844
|
+
({ wwwInput } = await inquirer.prompt([{
|
|
845
|
+
type: 'confirm',
|
|
846
|
+
name: 'wwwInput',
|
|
847
|
+
message: 'Include www subdomain?',
|
|
848
|
+
default: false,
|
|
849
|
+
}]));
|
|
850
|
+
} catch (err) {
|
|
851
|
+
if (err.name === 'ExitPromptError') return;
|
|
852
|
+
throw err;
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
const spinner = ora(`Creating certificate for ${domainInput.trim()}…`).start();
|
|
856
|
+
const result = await issueCert(domainInput.trim(), { www: wwwInput });
|
|
857
|
+
spinner.stop();
|
|
858
|
+
|
|
859
|
+
if (result.success) {
|
|
860
|
+
console.log(chalk.green('\n ✓ Certificate created successfully'));
|
|
861
|
+
console.log(chalk.gray(` Cert: ${result.certPath}`));
|
|
862
|
+
console.log(chalk.gray(` Key: ${result.keyPath}\n`));
|
|
863
|
+
} else {
|
|
864
|
+
const e = result.error;
|
|
865
|
+
console.log(chalk.red('\n ✗ Certificate creation failed'));
|
|
866
|
+
console.log(chalk.yellow(` Step: ${e.step}`));
|
|
867
|
+
console.log(chalk.yellow(` Cause: ${e.cause}`));
|
|
868
|
+
console.log(chalk.yellow(` Consequence: ${e.consequence}`));
|
|
869
|
+
console.log(chalk.gray(` nginx running: ${e.nginxRunning ? 'yes' : 'no'}\n`));
|
|
870
|
+
}
|
|
871
|
+
break;
|
|
872
|
+
}
|
|
873
|
+
|
|
727
874
|
case 'Renew a certificate': {
|
|
728
875
|
const installed = await isCertbotInstalled();
|
|
729
876
|
if (!installed) {
|
|
@@ -17,7 +17,7 @@ const isWindows = process.platform === 'win32';
|
|
|
17
17
|
function getConfDDir(nginxDir) {
|
|
18
18
|
return isWindows
|
|
19
19
|
? path.join(nginxDir, 'conf', 'conf.d')
|
|
20
|
-
: path.join(nginxDir, 'conf.d');
|
|
20
|
+
: path.join(nginxDir, 'conf.d', 'conf.d');
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
/** Returns the path to nginx.conf. */
|
|
@@ -63,7 +63,12 @@ createApp({
|
|
|
63
63
|
logs: [], logsLoading: false,
|
|
64
64
|
},
|
|
65
65
|
|
|
66
|
-
ssl: {
|
|
66
|
+
ssl: {
|
|
67
|
+
certs: [], loading: false, error: '', renewingDomain: null,
|
|
68
|
+
showCreateForm: false,
|
|
69
|
+
createDomain: '', createWww: false,
|
|
70
|
+
creating: false, createResult: null, createError: null,
|
|
71
|
+
},
|
|
67
72
|
|
|
68
73
|
// T017-T019: Updated domains state
|
|
69
74
|
domains: {
|
|
@@ -73,6 +78,9 @@ createApp({
|
|
|
73
78
|
saving: false,
|
|
74
79
|
dirty: false, // T019: Track unsaved changes
|
|
75
80
|
form: JSON.parse(JSON.stringify(DEFAULT_FORM)), // T025: Nested v2 structure
|
|
81
|
+
certMissing: null, // { certPath, keyPath, hint } set when POST /api/domains returns 422
|
|
82
|
+
certCreating: false, // true while POST /api/ssl/create is in-flight
|
|
83
|
+
certCreateError: null, // structured error from a failed cert creation
|
|
76
84
|
},
|
|
77
85
|
|
|
78
86
|
// T018: Collapsible section state
|
|
@@ -273,6 +281,30 @@ createApp({
|
|
|
273
281
|
await this.loadSSL();
|
|
274
282
|
},
|
|
275
283
|
|
|
284
|
+
async createCert() {
|
|
285
|
+
if (!this.ssl.createDomain.trim()) return;
|
|
286
|
+
this.ssl.creating = true;
|
|
287
|
+
this.ssl.createResult = null;
|
|
288
|
+
this.ssl.createError = null;
|
|
289
|
+
const r = await this.api('POST', '/api/ssl/create', {
|
|
290
|
+
domain: this.ssl.createDomain.trim(),
|
|
291
|
+
www: this.ssl.createWww,
|
|
292
|
+
});
|
|
293
|
+
this.ssl.creating = false;
|
|
294
|
+
if (r.ok) {
|
|
295
|
+
this.ssl.createResult = r.data;
|
|
296
|
+
this.ssl.createDomain = '';
|
|
297
|
+
this.ssl.createWww = false;
|
|
298
|
+
await this.loadSSL();
|
|
299
|
+
} else if (r.status === 503) {
|
|
300
|
+
this.ssl.createError = { step: 'ACME client detection', cause: r.data.hint, consequence: 'Install certbot or win-acme first using the SSL Manager CLI.', nginxRunning: true };
|
|
301
|
+
} else if (r.status === 409) {
|
|
302
|
+
this.ssl.createError = { step: 'port 80 check', cause: r.data.detail, consequence: r.data.hint, nginxRunning: true };
|
|
303
|
+
} else {
|
|
304
|
+
this.ssl.createError = r.data.error || { step: 'certificate issuance', cause: 'Unknown error', consequence: 'No certificate was issued.' };
|
|
305
|
+
}
|
|
306
|
+
},
|
|
307
|
+
|
|
276
308
|
certStatus(cert) {
|
|
277
309
|
if (cert.daysLeft === null || cert.daysLeft === undefined) return 'Unknown';
|
|
278
310
|
if (cert.daysLeft > 30) return 'Healthy';
|
|
@@ -323,6 +355,8 @@ createApp({
|
|
|
323
355
|
this.domains.editingName = null;
|
|
324
356
|
this.domains.dirty = false;
|
|
325
357
|
this.domains.error = '';
|
|
358
|
+
this.domains.certMissing = null;
|
|
359
|
+
this.domains.certCreateError = null;
|
|
326
360
|
// Reset sections
|
|
327
361
|
this.sections = {
|
|
328
362
|
basic: true,
|
|
@@ -422,11 +456,50 @@ createApp({
|
|
|
422
456
|
this.domains.editingName = null;
|
|
423
457
|
this.resetDomainForm();
|
|
424
458
|
await this.loadDomains();
|
|
459
|
+
} else if (r.status === 422 && r.data.error === 'cert_missing') {
|
|
460
|
+
this.domains.certMissing = r.data;
|
|
461
|
+
this.domains.certCreateError = null;
|
|
425
462
|
} else {
|
|
426
463
|
this.domains.error = r.data.error || 'Failed to save domain';
|
|
427
464
|
}
|
|
428
465
|
},
|
|
429
466
|
|
|
467
|
+
async createCertAndRetry() {
|
|
468
|
+
this.domains.certCreating = true;
|
|
469
|
+
this.domains.certCreateError = null;
|
|
470
|
+
const domain = this.domains.form.name;
|
|
471
|
+
const www = this.domains.form.www;
|
|
472
|
+
const r = await this.api('POST', '/api/ssl/create', { domain, www });
|
|
473
|
+
this.domains.certCreating = false;
|
|
474
|
+
|
|
475
|
+
if (r.ok) {
|
|
476
|
+
// Update cert paths in the form with what certbot actually wrote
|
|
477
|
+
this.domains.form.ssl.certPath = r.data.certPath;
|
|
478
|
+
this.domains.form.ssl.keyPath = r.data.keyPath;
|
|
479
|
+
this.domains.certMissing = null;
|
|
480
|
+
// Retry the domain save now that the cert exists
|
|
481
|
+
await this.saveDomain();
|
|
482
|
+
} else if (r.status === 503) {
|
|
483
|
+
this.domains.certCreateError = { step: 'ACME client detection', cause: r.data.hint, consequence: 'Install certbot or win-acme first.', nginxRunning: true };
|
|
484
|
+
} else if (r.status === 409) {
|
|
485
|
+
this.domains.certCreateError = { step: 'port 80 check', cause: r.data.detail, consequence: r.data.hint, nginxRunning: true };
|
|
486
|
+
} else {
|
|
487
|
+
this.domains.certCreateError = r.data.error || { step: 'certificate issuance', cause: 'Unknown error', consequence: 'No certificate was issued.' };
|
|
488
|
+
}
|
|
489
|
+
},
|
|
490
|
+
|
|
491
|
+
disableSslAndSave() {
|
|
492
|
+
this.domains.form.ssl.enabled = false;
|
|
493
|
+
this.domains.certMissing = null;
|
|
494
|
+
this.domains.certCreateError = null;
|
|
495
|
+
this.saveDomain();
|
|
496
|
+
},
|
|
497
|
+
|
|
498
|
+
dismissCertMissing() {
|
|
499
|
+
this.domains.certMissing = null;
|
|
500
|
+
this.domains.certCreateError = null;
|
|
501
|
+
},
|
|
502
|
+
|
|
430
503
|
async deleteDomain(name) {
|
|
431
504
|
if (!confirm(`Delete domain "${name}"? This cannot be undone.`)) return;
|
|
432
505
|
await this.api('DELETE', `/api/domains/${name}`);
|
|
@@ -156,6 +156,20 @@ router.post('/', async (req, res) => {
|
|
|
156
156
|
},
|
|
157
157
|
});
|
|
158
158
|
|
|
159
|
+
// Cert existence check (FR-001): prevent saving a config that references non-existent cert files
|
|
160
|
+
if (domain.ssl.enabled && domain.ssl.certPath) {
|
|
161
|
+
try {
|
|
162
|
+
await fs.access(domain.ssl.certPath, fs.constants.F_OK);
|
|
163
|
+
} catch {
|
|
164
|
+
return res.status(422).json({
|
|
165
|
+
error: 'cert_missing',
|
|
166
|
+
certPath: domain.ssl.certPath,
|
|
167
|
+
keyPath: domain.ssl.keyPath,
|
|
168
|
+
hint: 'The SSL certificate files do not exist at the configured paths. Create the certificate first, or disable SSL.',
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
159
173
|
const { nginxDir } = loadConfig();
|
|
160
174
|
|
|
161
175
|
try {
|
package/dashboard/routes/ssl.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import express from 'express';
|
|
2
2
|
import { run } from '../../core/shell.js';
|
|
3
3
|
import { listAllCerts } from '../lib/cert-reader.js';
|
|
4
|
+
import { issueCert } from '../../cli/managers/ssl-manager.js';
|
|
4
5
|
|
|
5
6
|
const router = express.Router();
|
|
6
7
|
|
|
@@ -48,6 +49,40 @@ async function renewDomain(domain, certbotCmd) {
|
|
|
48
49
|
return { success: certResult.success, output };
|
|
49
50
|
}
|
|
50
51
|
|
|
52
|
+
// ─── POST /api/ssl/create ─────────────────────────────────────────────────────
|
|
53
|
+
|
|
54
|
+
router.post('/create', async (req, res) => {
|
|
55
|
+
const { domain, www = false } = req.body ?? {};
|
|
56
|
+
|
|
57
|
+
if (!domain || typeof domain !== 'string' || !domain.trim()) {
|
|
58
|
+
return res.status(400).json({ error: 'domain is required' });
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const result = await issueCert(domain.trim(), { www: !!www });
|
|
62
|
+
|
|
63
|
+
if (result.success) {
|
|
64
|
+
return res.json({ success: true, certPath: result.certPath, keyPath: result.keyPath });
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const { step } = result.error;
|
|
68
|
+
if (step === 'ACME client detection') {
|
|
69
|
+
return res.status(503).json({
|
|
70
|
+
error: 'no_acme_client',
|
|
71
|
+
hint: 'Install certbot or win-acme first using the SSL Manager.',
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
if (step === 'port 80 check') {
|
|
75
|
+
return res.status(409).json({
|
|
76
|
+
error: 'port_busy',
|
|
77
|
+
detail: result.error.cause,
|
|
78
|
+
hint: 'Stop the process using port 80 and try again.',
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
return res.status(500).json({ success: false, error: result.error });
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
// ─── GET /api/ssl ─────────────────────────────────────────────────────────────
|
|
85
|
+
|
|
51
86
|
router.get('/', async (req, res) => {
|
|
52
87
|
const certbotCmd = await getCertbotCmd();
|
|
53
88
|
if (!certbotCmd) {
|
|
@@ -14,6 +14,34 @@
|
|
|
14
14
|
{{ domains.error }}
|
|
15
15
|
</p>
|
|
16
16
|
|
|
17
|
+
<!-- cert_missing 422 handler -->
|
|
18
|
+
<div v-if="domains.certMissing" class="mx-4 mt-4 p-4 rounded-lg bg-yellow-500/10 border border-yellow-500/20">
|
|
19
|
+
<p class="text-yellow-400 text-sm font-semibold mb-1">SSL certificate not found</p>
|
|
20
|
+
<p class="text-slate-400 text-xs mb-3 font-mono">{{ domains.certMissing.certPath }}</p>
|
|
21
|
+
<p class="text-slate-400 text-xs mb-4">{{ domains.certMissing.hint }}</p>
|
|
22
|
+
|
|
23
|
+
<!-- Structured error from a failed cert creation attempt -->
|
|
24
|
+
<div v-if="domains.certCreateError" class="mb-4 p-3 rounded-lg bg-red-500/10 border border-red-500/20 text-xs space-y-1">
|
|
25
|
+
<p class="text-red-400 font-semibold">Certificate creation failed</p>
|
|
26
|
+
<p class="text-slate-400"><span class="text-slate-300">Step:</span> {{ domains.certCreateError.step }}</p>
|
|
27
|
+
<p class="text-slate-400"><span class="text-slate-300">Cause:</span> {{ domains.certCreateError.cause }}</p>
|
|
28
|
+
<p class="text-slate-400"><span class="text-slate-300">Consequence:</span> {{ domains.certCreateError.consequence }}</p>
|
|
29
|
+
<p class="text-slate-400"><span class="text-slate-300">nginx running:</span> {{ domains.certCreateError.nginxRunning ? 'yes' : 'no' }}</p>
|
|
30
|
+
</div>
|
|
31
|
+
|
|
32
|
+
<div class="flex gap-2">
|
|
33
|
+
<button @click="createCertAndRetry()" :disabled="domains.certCreating" class="btn btn-primary btn-sm">
|
|
34
|
+
{{ domains.certCreating ? 'Creating...' : 'Create Certificate' }}
|
|
35
|
+
</button>
|
|
36
|
+
<button @click="disableSslAndSave()" :disabled="domains.certCreating" class="btn btn-secondary btn-sm">
|
|
37
|
+
Disable SSL
|
|
38
|
+
</button>
|
|
39
|
+
<button @click="dismissCertMissing()" :disabled="domains.certCreating" class="btn btn-secondary btn-sm">
|
|
40
|
+
Cancel
|
|
41
|
+
</button>
|
|
42
|
+
</div>
|
|
43
|
+
</div>
|
|
44
|
+
|
|
17
45
|
<!-- Basic Section -->
|
|
18
46
|
<div class="border-b border-slate-800">
|
|
19
47
|
<div @click="toggleSection('basic')" class="section-header">
|
|
@@ -2,11 +2,53 @@
|
|
|
2
2
|
<div v-show="page === 'ssl'" class="max-w-6xl mx-auto">
|
|
3
3
|
<div class="flex items-center justify-between mb-2">
|
|
4
4
|
<h2 class="text-2xl font-bold">SSL Certificates</h2>
|
|
5
|
-
<
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
<div class="flex gap-2">
|
|
6
|
+
<button @click="ssl.showCreateForm = !ssl.showCreateForm; ssl.createResult = null; ssl.createError = null" class="btn btn-secondary btn-sm">
|
|
7
|
+
{{ ssl.showCreateForm ? 'Cancel' : 'New Certificate' }}
|
|
8
|
+
</button>
|
|
9
|
+
<button @click="renewAll" :disabled="ssl.renewingDomain !== null" class="btn btn-primary btn-sm">
|
|
10
|
+
{{ ssl.renewingDomain === 'all' ? 'Renewing...' : 'Renew Expiring' }}
|
|
11
|
+
</button>
|
|
12
|
+
</div>
|
|
13
|
+
</div>
|
|
14
|
+
<p class="text-slate-400 mb-4">Let's Encrypt certificates managed by certbot</p>
|
|
15
|
+
|
|
16
|
+
<!-- New Certificate inline form -->
|
|
17
|
+
<div v-if="ssl.showCreateForm" class="card p-4 mb-6">
|
|
18
|
+
<h3 class="font-semibold mb-3 text-sm">Create New Certificate</h3>
|
|
19
|
+
<div class="flex items-end gap-3 flex-wrap">
|
|
20
|
+
<div class="input-group flex-1 min-w-48">
|
|
21
|
+
<input v-model="ssl.createDomain" placeholder=" " @keyup.enter="createCert()" />
|
|
22
|
+
<label>Domain name</label>
|
|
23
|
+
</div>
|
|
24
|
+
<div class="flex items-center gap-2 pb-1">
|
|
25
|
+
<label class="switch">
|
|
26
|
+
<input type="checkbox" v-model="ssl.createWww" />
|
|
27
|
+
<span class="slider"></span>
|
|
28
|
+
</label>
|
|
29
|
+
<span class="text-sm text-slate-400">Include www</span>
|
|
30
|
+
</div>
|
|
31
|
+
<button @click="createCert()" :disabled="ssl.creating || !ssl.createDomain.trim()" class="btn btn-primary btn-sm">
|
|
32
|
+
{{ ssl.creating ? 'Creating...' : 'Create' }}
|
|
33
|
+
</button>
|
|
34
|
+
</div>
|
|
35
|
+
|
|
36
|
+
<!-- Success result -->
|
|
37
|
+
<div v-if="ssl.createResult" class="mt-3 p-3 rounded-lg bg-green-500/10 border border-green-500/20 text-xs">
|
|
38
|
+
<p class="text-green-400 font-semibold mb-1">Certificate created successfully</p>
|
|
39
|
+
<p class="text-slate-400 font-mono">Cert: {{ ssl.createResult.certPath }}</p>
|
|
40
|
+
<p class="text-slate-400 font-mono">Key: {{ ssl.createResult.keyPath }}</p>
|
|
41
|
+
</div>
|
|
42
|
+
|
|
43
|
+
<!-- Structured error -->
|
|
44
|
+
<div v-if="ssl.createError" class="mt-3 p-3 rounded-lg bg-red-500/10 border border-red-500/20 text-xs space-y-1">
|
|
45
|
+
<p class="text-red-400 font-semibold">Certificate creation failed</p>
|
|
46
|
+
<p class="text-slate-400"><span class="text-slate-300">Step:</span> {{ ssl.createError.step }}</p>
|
|
47
|
+
<p class="text-slate-400"><span class="text-slate-300">Cause:</span> {{ ssl.createError.cause }}</p>
|
|
48
|
+
<p class="text-slate-400"><span class="text-slate-300">Consequence:</span> {{ ssl.createError.consequence }}</p>
|
|
49
|
+
<p class="text-slate-400"><span class="text-slate-300">nginx running:</span> {{ ssl.createError.nginxRunning ? 'yes' : 'no' }}</p>
|
|
50
|
+
</div>
|
|
8
51
|
</div>
|
|
9
|
-
<p class="text-slate-400 mb-8">Let's Encrypt certificates managed by certbot</p>
|
|
10
52
|
|
|
11
53
|
<div v-if="ssl.error" class="card p-4 mb-6 bg-red-500/10 border-red-500/20 text-red-400">
|
|
12
54
|
{{ ssl.error }}
|
package/package.json
CHANGED