easy-devops 1.0.1 โ 1.1.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 +22 -8
- package/install.ps1 +2 -2
- package/install.sh +1 -1
- package/package.json +1 -1
- package/src/cli/managers/domain-manager.js +13 -9
- package/src/cli/managers/nginx-manager.js +87 -46
- package/src/cli/managers/ssl-manager.js +16 -2
- package/src/cli/menus/settings.js +23 -0
- package/src/core/db.js +24 -1
- package/src/core/permissions.js +71 -0
- package/src/core/platform.js +16 -0
- package/src/dashboard/lib/nginx-service.js +72 -27
- package/src/dashboard/public/js/app.js +24 -1
- package/src/dashboard/routes/domains.js +42 -17
- package/src/dashboard/routes/settings.js +108 -0
- package/src/dashboard/views/partials/settings-panel.ejs +33 -0
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<p align="center">
|
|
2
|
-
<img src="dashboard/public/img/icon.png" alt="Easy DevOps" width="100" />
|
|
2
|
+
<img src="src/dashboard/public/img/icon.png" alt="Easy DevOps" width="100" />
|
|
3
3
|
</p>
|
|
4
4
|
|
|
5
5
|
# Easy DevOps
|
|
@@ -12,6 +12,8 @@ A unified DevOps management tool with interactive CLI and web dashboard for mana
|
|
|
12
12
|
|
|
13
13
|
No external ACME binaries required โ SSL certificates are issued via [`acme-client`](https://www.npmjs.com/package/acme-client) (pure Node.js, Let's Encrypt).
|
|
14
14
|
|
|
15
|
+
> **Tip:** Two CLI commands are available: **`easy-devops`** (full name) and **`ezz`** (short alias). Both are registered in the npm bin and do exactly the same thing.
|
|
16
|
+
|
|
15
17
|
## Features
|
|
16
18
|
|
|
17
19
|
- **๐ฅ๏ธ Interactive CLI** โ Arrow-key menus with real-time status indicators
|
|
@@ -38,6 +40,7 @@ If you have **Node.js 18+** installed, run:
|
|
|
38
40
|
|
|
39
41
|
```bash
|
|
40
42
|
npm install -g easy-devops && easy-devops
|
|
43
|
+
# Short alias also available: ezz
|
|
41
44
|
```
|
|
42
45
|
|
|
43
46
|
If you **don't have Node.js** yet, use the bootstrap installer:
|
|
@@ -77,7 +80,7 @@ powershell -ExecutionPolicy Bypass -Command "Invoke-WebRequest -Uri 'https://raw
|
|
|
77
80
|
|
|
78
81
|
```bash
|
|
79
82
|
npm install -g easy-devops
|
|
80
|
-
easy-devops
|
|
83
|
+
easy-devops # or: ezz
|
|
81
84
|
```
|
|
82
85
|
|
|
83
86
|
### From Source
|
|
@@ -86,7 +89,7 @@ easy-devops
|
|
|
86
89
|
git clone https://github.com/omar00050/Easy-DevOps.git
|
|
87
90
|
cd Easy-DevOps
|
|
88
91
|
npm install
|
|
89
|
-
npm start
|
|
92
|
+
npm start # or: easy-devops / ezz
|
|
90
93
|
```
|
|
91
94
|
|
|
92
95
|
## Quick Start
|
|
@@ -95,7 +98,10 @@ npm start
|
|
|
95
98
|
# Start the interactive CLI
|
|
96
99
|
easy-devops
|
|
97
100
|
|
|
98
|
-
#
|
|
101
|
+
# Short alias โ same thing, faster to type
|
|
102
|
+
ezz
|
|
103
|
+
|
|
104
|
+
# Or run without installing
|
|
99
105
|
npx easy-devops
|
|
100
106
|
```
|
|
101
107
|
|
|
@@ -104,7 +110,7 @@ npx easy-devops
|
|
|
104
110
|
### CLI Overview
|
|
105
111
|
|
|
106
112
|
```
|
|
107
|
-
โโโโโโโโโโโโโโโโ Easy DevOps v1.0.
|
|
113
|
+
โโโโโโโโโโโโโโโโ Easy DevOps v1.0.2
|
|
108
114
|
โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโ
|
|
109
115
|
โโโโโโ โโโโ CLI & Web Dashboard
|
|
110
116
|
โโโโโโ โโโโ Nginx ยท SSL ยท Domains ยท Node.js
|
|
@@ -242,7 +248,9 @@ Default credentials:
|
|
|
242
248
|
| **Nginx** | Start/stop controls, config editor, error logs |
|
|
243
249
|
| **SSL** | Certificate list, renewal actions, expiry badges |
|
|
244
250
|
| **Domains** | Add/edit form with collapsible sections, table view |
|
|
245
|
-
| **Settings** | Port, password, directory configuration |
|
|
251
|
+
| **Settings** | Port, password, directory configuration, Linux permissions setup |
|
|
252
|
+
|
|
253
|
+
> **Linux users:** After launching the dashboard for the first time, open **Settings โ Linux Permissions** and click **Setup Permissions**. This writes `/etc/sudoers.d/easy-devops` with NOPASSWD rules for `systemctl` so nginx start/stop/reload/restart work from the dashboard without a terminal. Without this step, nginx service control will return "Linux permissions not configured" errors.
|
|
246
254
|
|
|
247
255
|
---
|
|
248
256
|
|
|
@@ -267,12 +275,18 @@ The dashboard exposes RESTful API endpoints:
|
|
|
267
275
|
| `/api/ssl/create-confirm` | POST | Confirm DNS challenge |
|
|
268
276
|
| `/api/ssl/renew/:domain` | POST | Renew certificate |
|
|
269
277
|
| `/api/settings` | GET/POST | Dashboard settings |
|
|
278
|
+
| `/api/settings/permissions` | GET | Linux sudo permissions status |
|
|
279
|
+
| `/api/settings/permissions/setup` | POST | Configure NOPASSWD sudoers (Linux) |
|
|
270
280
|
|
|
271
281
|
---
|
|
272
282
|
|
|
273
283
|
## Configuration
|
|
274
284
|
|
|
275
|
-
All configuration is stored in
|
|
285
|
+
All configuration is stored in a persistent user directory (never inside the npm package, so it survives updates):
|
|
286
|
+
|
|
287
|
+
**Database location:**
|
|
288
|
+
- Linux/macOS: `~/.config/easy-devops/easy-devops.sqlite`
|
|
289
|
+
- Windows: `%APPDATA%\easy-devops\easy-devops.sqlite`
|
|
276
290
|
|
|
277
291
|
| Key | Contents |
|
|
278
292
|
|-----|----------|
|
|
@@ -349,7 +363,7 @@ cd Easy-DevOps
|
|
|
349
363
|
npm install
|
|
350
364
|
|
|
351
365
|
# Run CLI
|
|
352
|
-
npm start
|
|
366
|
+
npm start # or: easy-devops / ezz
|
|
353
367
|
|
|
354
368
|
# Run dashboard
|
|
355
369
|
npm run dashboard
|
package/install.ps1
CHANGED
|
@@ -752,11 +752,11 @@ if ($allOK) {
|
|
|
752
752
|
Write-Host " All steps completed successfully!" -ForegroundColor Green
|
|
753
753
|
Write-Host ""
|
|
754
754
|
Write-Host " Run the CLI:" -ForegroundColor White
|
|
755
|
-
Write-Host " easy-devops" -ForegroundColor Cyan
|
|
755
|
+
Write-Host " easy-devops or ezz" -ForegroundColor Cyan
|
|
756
756
|
} else {
|
|
757
757
|
Write-Host " Some steps need attention -- see warnings above." -ForegroundColor Yellow
|
|
758
758
|
Write-Host ""
|
|
759
759
|
Write-Host " Fallback:" -ForegroundColor White
|
|
760
|
-
Write-Host " node cli/index.js" -ForegroundColor Cyan
|
|
760
|
+
Write-Host " node src/cli/index.js" -ForegroundColor Cyan
|
|
761
761
|
}
|
|
762
762
|
Write-Host ""
|
package/install.sh
CHANGED
|
@@ -490,7 +490,7 @@ if [ "$_allOK" = "true" ]; then
|
|
|
490
490
|
printf ' To use immediately in this terminal, run:\n'
|
|
491
491
|
printf ' source ~/.bashrc\n\n'
|
|
492
492
|
printf ' Or open a new terminal, then run:\n'
|
|
493
|
-
printf ' easy-devops\n'
|
|
493
|
+
printf ' easy-devops\n or ezz\n'
|
|
494
494
|
else
|
|
495
495
|
printf ' Some steps need attention -- see warnings above.\n\n'
|
|
496
496
|
printf ' Fallback:\n'
|
package/package.json
CHANGED
|
@@ -20,7 +20,7 @@ import { loadConfig } from '../../core/config.js';
|
|
|
20
20
|
import { getDomains, saveDomains, findDomain, createDomain, DOMAIN_DEFAULTS } from '../../dashboard/lib/domains-db.js';
|
|
21
21
|
import { generateConf, buildConf } from '../../core/nginx-conf-generator.js';
|
|
22
22
|
import { issueCert } from './ssl-manager.js';
|
|
23
|
-
import { isWindows, nginxTestCmd, nginxReloadCmd, combineOutput } from '../../core/platform.js';
|
|
23
|
+
import { isWindows, nginxTestCmd, nginxReloadCmd, combineOutput, isNginxTestOk } from '../../core/platform.js';
|
|
24
24
|
|
|
25
25
|
// โโโ List Domains โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
26
26
|
|
|
@@ -300,9 +300,10 @@ async function addDomainAction() {
|
|
|
300
300
|
}
|
|
301
301
|
|
|
302
302
|
spinner.text = 'Testing config...';
|
|
303
|
-
const
|
|
303
|
+
const testCmd = isWindows ? nginxTestCmd(nginxDir) : 'nginx -t';
|
|
304
|
+
const testResult = await run(testCmd, { cwd: nginxDir });
|
|
304
305
|
|
|
305
|
-
if (!testResult
|
|
306
|
+
if (!isNginxTestOk(testResult)) {
|
|
306
307
|
spinner.fail('Config test failed');
|
|
307
308
|
console.log(chalk.red('\n' + combineOutput(testResult)));
|
|
308
309
|
// Clean up failed config
|
|
@@ -376,9 +377,10 @@ async function editDomainAction() {
|
|
|
376
377
|
}
|
|
377
378
|
|
|
378
379
|
spinner.text = 'Testing config...';
|
|
379
|
-
const
|
|
380
|
+
const testCmd = isWindows ? nginxTestCmd(nginxDir) : 'nginx -t';
|
|
381
|
+
const testResult = await run(testCmd, { cwd: nginxDir });
|
|
380
382
|
|
|
381
|
-
if (!testResult
|
|
383
|
+
if (!isNginxTestOk(testResult)) {
|
|
382
384
|
spinner.fail('Config test failed');
|
|
383
385
|
console.log(chalk.red('\n' + combineOutput(testResult)));
|
|
384
386
|
return;
|
|
@@ -451,8 +453,9 @@ async function reloadNginxAfterChange() {
|
|
|
451
453
|
const { nginxDir } = loadConfig();
|
|
452
454
|
const spinner = ora('Reloading nginx...').start();
|
|
453
455
|
|
|
454
|
-
const
|
|
455
|
-
|
|
456
|
+
const testCmd = isWindows ? nginxTestCmd(nginxDir) : 'nginx -t';
|
|
457
|
+
const testResult = await run(testCmd, { cwd: nginxDir });
|
|
458
|
+
if (!isNginxTestOk(testResult)) {
|
|
456
459
|
spinner.fail('Config test failed');
|
|
457
460
|
console.log(chalk.red('\n' + combineOutput(testResult)));
|
|
458
461
|
return false;
|
|
@@ -526,8 +529,9 @@ async function toggleDomainAction() {
|
|
|
526
529
|
} else {
|
|
527
530
|
await fs.rename(disabledPath, enabledPath);
|
|
528
531
|
// Test config before reload
|
|
529
|
-
const
|
|
530
|
-
|
|
532
|
+
const testCmd = isWindows ? nginxTestCmd(nginxDir) : 'nginx -t';
|
|
533
|
+
const testResult = await run(testCmd, { cwd: nginxDir });
|
|
534
|
+
if (!isNginxTestOk(testResult)) {
|
|
531
535
|
await fs.rename(enabledPath, disabledPath).catch(() => {});
|
|
532
536
|
spinner.fail('Config test failed โ rolled back');
|
|
533
537
|
console.log(chalk.red('\n' + combineOutput(testResult)));
|
|
@@ -16,7 +16,8 @@ import ora from 'ora';
|
|
|
16
16
|
import { run, runLive, runInteractive } from '../../core/shell.js';
|
|
17
17
|
import { loadConfig } from '../../core/config.js';
|
|
18
18
|
import { ensureNginxInclude } from '../../core/nginx-conf-generator.js';
|
|
19
|
-
import { isWindows } from '../../core/platform.js';
|
|
19
|
+
import { isWindows, isNginxTestOk } from '../../core/platform.js';
|
|
20
|
+
import path from 'path';
|
|
20
21
|
|
|
21
22
|
// โโโ Helpers โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
22
23
|
import { access } from 'fs/promises';
|
|
@@ -66,23 +67,45 @@ async function testConfig(nginxExe, nginxDir) {
|
|
|
66
67
|
await ensureNginxInclude(nginxDir);
|
|
67
68
|
const cmd = isWindows ? `& "${nginxExe}" -t` : 'nginx -t';
|
|
68
69
|
const result = await run(cmd, { cwd: nginxDir });
|
|
69
|
-
const PathDomain = await pathExists(`${nginxDir}\\conf\\conf.d`);
|
|
70
|
-
const willKnown = await pathExists(`${nginxDir}\\html\\.well-known`);
|
|
71
70
|
|
|
72
|
-
|
|
71
|
+
// On Linux: conf.d is directly under nginxDir (/etc/nginx/conf.d)
|
|
72
|
+
// On Windows: conf.d is under the conf sub-directory (C:\nginx\conf\conf.d)
|
|
73
|
+
const confDPath = isWindows
|
|
74
|
+
? path.join(nginxDir, 'conf', 'conf.d')
|
|
75
|
+
: path.join(nginxDir, 'conf.d');
|
|
76
|
+
const wellKnownPath = path.join(nginxDir, 'html', '.well-known');
|
|
77
|
+
const acmePath = path.join(wellKnownPath, 'acme-challenge');
|
|
78
|
+
|
|
79
|
+
const hasConfD = await pathExists(confDPath);
|
|
80
|
+
const hasWellKnown = await pathExists(wellKnownPath);
|
|
81
|
+
|
|
82
|
+
if (!hasConfD) {
|
|
73
83
|
console.warn(chalk.yellow(`Warning: conf.d directory not found in ${nginxDir} โ creating it now...`));
|
|
74
|
-
|
|
84
|
+
if (isWindows) {
|
|
85
|
+
await import('fs/promises').then(fs => fs.mkdir(confDPath, { recursive: true }));
|
|
86
|
+
} else {
|
|
87
|
+
const mkResult = await runInteractive(`sudo mkdir -p "${confDPath}"`);
|
|
88
|
+
if (!mkResult.success) {
|
|
89
|
+
console.warn(chalk.red(` Failed to create ${confDPath} โ run manually: sudo mkdir -p ${confDPath}`));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
75
92
|
}
|
|
76
93
|
|
|
77
|
-
if (!
|
|
78
|
-
console.warn(chalk.yellow(`Warning: .well-known/acme-challenge directory not found
|
|
79
|
-
|
|
80
|
-
|
|
94
|
+
if (!hasWellKnown) {
|
|
95
|
+
console.warn(chalk.yellow(`Warning: .well-known/acme-challenge directory not found โ creating it now...`));
|
|
96
|
+
if (isWindows) {
|
|
97
|
+
await import('fs/promises').then(fs => fs.mkdir(acmePath, { recursive: true }));
|
|
98
|
+
} else {
|
|
99
|
+
const mkResult = await runInteractive(`sudo mkdir -p "${acmePath}"`);
|
|
100
|
+
if (!mkResult.success) {
|
|
101
|
+
console.warn(chalk.red(` Failed to create ${acmePath} โ run manually: sudo mkdir -p ${acmePath}`));
|
|
102
|
+
}
|
|
103
|
+
}
|
|
81
104
|
}
|
|
82
105
|
|
|
83
106
|
return {
|
|
84
|
-
success: result
|
|
85
|
-
output: (result.stdout + '\n' + result.stderr).trim(),
|
|
107
|
+
success: isNginxTestOk(result),
|
|
108
|
+
output: ((result.stdout || '') + '\n' + (result.stderr || '')).trim(),
|
|
86
109
|
};
|
|
87
110
|
}
|
|
88
111
|
|
|
@@ -99,8 +122,12 @@ async function reloadNginx(nginxExe, nginxDir) {
|
|
|
99
122
|
}
|
|
100
123
|
|
|
101
124
|
spinner.text = 'Reloading nginxโฆ';
|
|
102
|
-
|
|
103
|
-
|
|
125
|
+
let result;
|
|
126
|
+
if (isWindows) {
|
|
127
|
+
result = await run(`& "${nginxExe}" -s reload`, { cwd: nginxDir });
|
|
128
|
+
} else {
|
|
129
|
+
result = await runInteractive('sudo /usr/bin/systemctl reload nginx');
|
|
130
|
+
}
|
|
104
131
|
|
|
105
132
|
if (result.success) {
|
|
106
133
|
spinner.succeed('nginx reloaded successfully');
|
|
@@ -111,7 +138,7 @@ async function reloadNginx(nginxExe, nginxDir) {
|
|
|
111
138
|
return {
|
|
112
139
|
success: result.success,
|
|
113
140
|
message: result.success ? 'nginx reloaded successfully' : 'Reload failed',
|
|
114
|
-
output: (result.stdout + '\n' + result.stderr).trim(),
|
|
141
|
+
output: ((result.stdout || '') + '\n' + (result.stderr || '')).trim(),
|
|
115
142
|
};
|
|
116
143
|
}
|
|
117
144
|
|
|
@@ -134,7 +161,7 @@ async function restartNginx(nginxExe, nginxDir) {
|
|
|
134
161
|
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
135
162
|
result = await run(`& "${nginxExe}"`, { cwd: nginxDir });
|
|
136
163
|
} else {
|
|
137
|
-
result = await
|
|
164
|
+
result = await runInteractive('sudo /usr/bin/systemctl restart nginx');
|
|
138
165
|
}
|
|
139
166
|
|
|
140
167
|
if (result.success) {
|
|
@@ -146,7 +173,7 @@ async function restartNginx(nginxExe, nginxDir) {
|
|
|
146
173
|
return {
|
|
147
174
|
success: result.success,
|
|
148
175
|
message: result.success ? 'nginx restarted successfully' : 'Restart failed',
|
|
149
|
-
output: (result.stdout + '\n' + result.stderr).trim(),
|
|
176
|
+
output: ((result.stdout || '') + '\n' + (result.stderr || '')).trim(),
|
|
150
177
|
};
|
|
151
178
|
}
|
|
152
179
|
|
|
@@ -187,10 +214,9 @@ async function startNginx(nginxExe, nginxDir) {
|
|
|
187
214
|
const startCmd = `Start-Process -FilePath "${nginxExe}" -WorkingDirectory "${nginxDir}" -WindowStyle Hidden`;
|
|
188
215
|
await run(startCmd, { timeout: 10000 });
|
|
189
216
|
} else {
|
|
190
|
-
const result = await
|
|
217
|
+
const result = await runInteractive('sudo /usr/bin/systemctl start nginx');
|
|
191
218
|
if (!result.success) {
|
|
192
219
|
spinner.fail('Start failed');
|
|
193
|
-
console.log(chalk.red('\n' + (result.stderr || result.stdout)));
|
|
194
220
|
return { success: false };
|
|
195
221
|
}
|
|
196
222
|
}
|
|
@@ -236,40 +262,61 @@ async function startNginx(nginxExe, nginxDir) {
|
|
|
236
262
|
|
|
237
263
|
async function stopNginx(nginxDir) {
|
|
238
264
|
const spinner = ora('Stopping nginxโฆ').start();
|
|
239
|
-
|
|
240
|
-
|
|
265
|
+
let result;
|
|
266
|
+
if (isWindows) {
|
|
267
|
+
result = await run('taskkill /f /IM nginx.exe', { cwd: nginxDir });
|
|
268
|
+
} else {
|
|
269
|
+
result = await runInteractive('sudo /usr/bin/systemctl stop nginx');
|
|
270
|
+
}
|
|
271
|
+
|
|
241
272
|
if (result.success) {
|
|
242
273
|
spinner.succeed('nginx stopped');
|
|
243
274
|
} else {
|
|
244
275
|
spinner.fail('Stop failed');
|
|
245
|
-
|
|
276
|
+
if (result.stderr || result.stdout) {
|
|
277
|
+
console.log(chalk.red('\n' + (result.stderr || result.stdout)));
|
|
278
|
+
}
|
|
246
279
|
}
|
|
247
|
-
return { success: result.success, output: (result.stdout + '\n' + result.stderr).trim() };
|
|
280
|
+
return { success: result.success, output: ((result.stdout || '') + '\n' + (result.stderr || '')).trim() };
|
|
248
281
|
}
|
|
249
282
|
|
|
250
283
|
// โโโ installNginx โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
251
284
|
|
|
252
285
|
async function installNginx() {
|
|
253
286
|
if (!isWindows) {
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
287
|
+
const spinner = ora('Installing nginxโฆ').start();
|
|
288
|
+
const result = await runInteractive('sudo apt-get install -y nginx');
|
|
289
|
+
if (!result.success) {
|
|
290
|
+
spinner.fail('Installation failed');
|
|
291
|
+
console.log(chalk.gray('\n Manual instructions: https://nginx.org/en/docs/install.html\n'));
|
|
292
|
+
return { success: false, message: 'Installation failed', output: '' };
|
|
293
|
+
}
|
|
294
|
+
spinner.succeed('nginx installed successfully');
|
|
257
295
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
296
|
+
const { nginxDir } = loadConfig();
|
|
297
|
+
const confDPath = path.join(nginxDir, 'conf.d');
|
|
298
|
+
const acmePath = path.join(nginxDir, 'html', '.well-known', 'acme-challenge');
|
|
299
|
+
|
|
300
|
+
// Create conf.d directory for domain config files
|
|
301
|
+
const confSpinner = ora(`Creating ${confDPath}โฆ`).start();
|
|
302
|
+
const confResult = await runInteractive(`sudo mkdir -p "${confDPath}"`);
|
|
303
|
+
if (confResult.success) {
|
|
304
|
+
confSpinner.succeed(`Created ${confDPath}`);
|
|
305
|
+
} else {
|
|
306
|
+
confSpinner.warn(`Could not create ${confDPath} โ run manually: sudo mkdir -p ${confDPath}`);
|
|
261
307
|
}
|
|
262
308
|
|
|
263
|
-
|
|
264
|
-
const
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
309
|
+
// Create html/.well-known/acme-challenge directory for SSL certificate verification
|
|
310
|
+
const acmeSpinner = ora(`Creating ${acmePath}โฆ`).start();
|
|
311
|
+
const acmeResult = await runInteractive(`sudo mkdir -p "${acmePath}"`);
|
|
312
|
+
if (acmeResult.success) {
|
|
313
|
+
await runInteractive(`sudo touch "${path.join(acmePath, '.keep')}"`);
|
|
314
|
+
acmeSpinner.succeed(`Created ${acmePath}`);
|
|
315
|
+
} else {
|
|
316
|
+
acmeSpinner.warn(`Could not create ${acmePath} โ run manually: sudo mkdir -p ${acmePath}`);
|
|
268
317
|
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
console.log(chalk.gray('\n Manual instructions: https://nginx.org/en/docs/install.html\n'));
|
|
272
|
-
return { success: false, message: 'Installation failed', output: result.stderr || result.stdout };
|
|
318
|
+
|
|
319
|
+
return { success: true, message: 'nginx installed successfully', output: '' };
|
|
273
320
|
}
|
|
274
321
|
|
|
275
322
|
// โโ Windows โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
@@ -348,17 +395,11 @@ async function installNginx() {
|
|
|
348
395
|
}
|
|
349
396
|
|
|
350
397
|
// Create conf/conf.d directory for domain config files
|
|
351
|
-
await import('fs/promises').then(fs => fs.mkdir(
|
|
398
|
+
await import('fs/promises').then(fs => fs.mkdir(path.join(nginxDir, 'conf', 'conf.d'), { recursive: true }));
|
|
352
399
|
|
|
353
|
-
await import('fs/promises').then(fs => fs.mkdir(`${nginxDir}\\html\\.well-known\\`, { recursive: true }));
|
|
354
400
|
// Create html/.well-known/acme-challenge directory for SSL certificate verification
|
|
355
|
-
await import('fs/promises').then(fs => fs.
|
|
356
|
-
|
|
357
|
-
console.error(chalk.red(`Failed to create acme-challenge directory: ${err.message}`));
|
|
358
|
-
} else {
|
|
359
|
-
console.log(chalk.green('Created acme-challenge directory for SSL certificate verification'));
|
|
360
|
-
}
|
|
361
|
-
}));
|
|
401
|
+
await import('fs/promises').then(fs => fs.mkdir(path.join(nginxDir, 'html', '.well-known', 'acme-challenge'), { recursive: true }));
|
|
402
|
+
await import('fs/promises').then(fs => fs.writeFile(path.join(nginxDir, 'html', '.well-known', 'acme-challenge', '.keep'), ''));
|
|
362
403
|
|
|
363
404
|
spinner.succeed(`nginx ${nginxVersion} installed to ${nginxDir}`);
|
|
364
405
|
return { success: true, message: `nginx ${nginxVersion} installed successfully`, output: '' };
|
|
@@ -19,6 +19,7 @@ import path from 'path';
|
|
|
19
19
|
import http from 'http';
|
|
20
20
|
import net from 'net';
|
|
21
21
|
import * as acme from 'acme-client';
|
|
22
|
+
import os from 'os';
|
|
22
23
|
import { run, runLive } from '../../core/shell.js';
|
|
23
24
|
import { loadConfig } from '../../core/config.js';
|
|
24
25
|
import { isWindows } from '../../core/platform.js';
|
|
@@ -36,7 +37,14 @@ function getSslDir() {
|
|
|
36
37
|
*/
|
|
37
38
|
async function getAccountKey(sslDir) {
|
|
38
39
|
const keyPath = path.join(sslDir, '.account', 'account.key');
|
|
39
|
-
|
|
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
|
+
}
|
|
40
48
|
try {
|
|
41
49
|
return await fs.readFile(keyPath);
|
|
42
50
|
} catch {
|
|
@@ -223,7 +231,13 @@ export async function issueCert(domainName, {
|
|
|
223
231
|
|
|
224
232
|
// Ensure certificate directory exists
|
|
225
233
|
const certDir = path.join(sslDir, domainName);
|
|
226
|
-
|
|
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
|
+
}
|
|
227
241
|
|
|
228
242
|
// Load or create account key
|
|
229
243
|
const accountKey = await getAccountKey(sslDir);
|
|
@@ -2,6 +2,7 @@ import chalk from 'chalk';
|
|
|
2
2
|
import inquirer from 'inquirer';
|
|
3
3
|
import { loadConfig, saveConfig } from '../../core/config.js';
|
|
4
4
|
import { dbGet } from '../../core/db.js';
|
|
5
|
+
import { setupLinuxPermissions, checkPermissionsConfigured } from '../../core/permissions.js';
|
|
5
6
|
|
|
6
7
|
export default async function settingsMenu() {
|
|
7
8
|
// T021: detect missing/corrupted config before loadConfig() creates defaults
|
|
@@ -17,6 +18,9 @@ export default async function settingsMenu() {
|
|
|
17
18
|
const passwordDisplay = config.dashboardPassword ? '***' : '(not set)';
|
|
18
19
|
const emailDisplay = config.acmeEmail || '(not set)';
|
|
19
20
|
|
|
21
|
+
const isLinux = process.platform !== 'win32';
|
|
22
|
+
const permsOk = isLinux ? await checkPermissionsConfigured() : true;
|
|
23
|
+
|
|
20
24
|
console.log();
|
|
21
25
|
console.log(chalk.bold('โ๏ธ Settings'));
|
|
22
26
|
console.log(chalk.gray('โ'.repeat(40)));
|
|
@@ -38,12 +42,31 @@ export default async function settingsMenu() {
|
|
|
38
42
|
{ name: `Nginx Directory (${config.nginxDir})`, value: 'nginxDir' },
|
|
39
43
|
{ name: `SSL Directory (${config.sslDir})`, value: 'sslDir' },
|
|
40
44
|
{ name: `ACME Email (${emailDisplay})`, value: 'acmeEmail' },
|
|
45
|
+
...(isLinux ? [{
|
|
46
|
+
name: permsOk
|
|
47
|
+
? '๐ Linux Permissions โ
configured'
|
|
48
|
+
: '๐ Setup Linux Permissions โ required',
|
|
49
|
+
value: 'permissions',
|
|
50
|
+
}] : []),
|
|
41
51
|
{ name: 'โ Back', value: 'back' },
|
|
42
52
|
],
|
|
43
53
|
}]);
|
|
44
54
|
|
|
45
55
|
if (field === 'back') return;
|
|
46
56
|
|
|
57
|
+
if (field === 'permissions') {
|
|
58
|
+
if (process.platform !== 'win32') {
|
|
59
|
+
console.log(chalk.yellow('\n You will be prompted for your sudo password once.\n'));
|
|
60
|
+
const result = await setupLinuxPermissions();
|
|
61
|
+
if (result.success) {
|
|
62
|
+
console.log(chalk.green('\n โ
Permissions configured! No more password prompts.\n'));
|
|
63
|
+
} else {
|
|
64
|
+
console.log(chalk.red(`\n โ Failed: ${result.reason || 'unknown error'}\n`));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
|
|
47
70
|
if (field === 'dashboardPort') {
|
|
48
71
|
// T015: port validation with inline error + re-prompt
|
|
49
72
|
const { value } = await inquirer.prompt([{
|
package/src/core/db.js
CHANGED
|
@@ -1,12 +1,35 @@
|
|
|
1
1
|
import { GoodDB, SQLiteDriver } from 'good.db';
|
|
2
2
|
import fs from 'fs';
|
|
3
3
|
import path from 'path';
|
|
4
|
+
import os from 'os';
|
|
4
5
|
import { fileURLToPath } from 'url';
|
|
5
6
|
|
|
6
7
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
7
|
-
|
|
8
|
+
|
|
9
|
+
// Store the database in the user's home directory so it survives npm updates.
|
|
10
|
+
// Linux/macOS: ~/.config/easy-devops/
|
|
11
|
+
// Windows: %APPDATA%\easy-devops\ (falls back to home dir if APPDATA unset)
|
|
12
|
+
const DATA_DIR = process.platform === 'win32'
|
|
13
|
+
? path.join(process.env.APPDATA || os.homedir(), 'easy-devops')
|
|
14
|
+
: path.join(os.homedir(), '.config', 'easy-devops');
|
|
15
|
+
|
|
8
16
|
const DB_PATH = path.join(DATA_DIR, 'easy-devops.sqlite');
|
|
9
17
|
|
|
18
|
+
// โโโ One-time migration from old package-relative location โโโโโโโโโโโโโโโโโโโ
|
|
19
|
+
const OLD_DATA_DIR = path.join(__dirname, '..', '..', 'data');
|
|
20
|
+
const OLD_DB_PATH = path.join(OLD_DATA_DIR, 'easy-devops.sqlite');
|
|
21
|
+
function migrateIfNeeded() {
|
|
22
|
+
try {
|
|
23
|
+
if (fs.existsSync(OLD_DB_PATH) && !fs.existsSync(DB_PATH)) {
|
|
24
|
+
fs.mkdirSync(DATA_DIR, { recursive: true });
|
|
25
|
+
fs.copyFileSync(OLD_DB_PATH, DB_PATH);
|
|
26
|
+
// Rename old file so migration doesn't run again
|
|
27
|
+
fs.renameSync(OLD_DB_PATH, OLD_DB_PATH + '.migrated');
|
|
28
|
+
}
|
|
29
|
+
} catch { /* non-fatal โ new install will start fresh */ }
|
|
30
|
+
}
|
|
31
|
+
migrateIfNeeded();
|
|
32
|
+
|
|
10
33
|
try {
|
|
11
34
|
fs.mkdirSync(DATA_DIR, { recursive: true });
|
|
12
35
|
} catch (err) {
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { runInteractive, run } from './shell.js';
|
|
2
|
+
import os from 'os';
|
|
3
|
+
|
|
4
|
+
async function findNginxPath() {
|
|
5
|
+
const result = await run('which nginx');
|
|
6
|
+
if (result.success && result.stdout.trim()) {
|
|
7
|
+
return result.stdout.trim().split('\n')[0].trim();
|
|
8
|
+
}
|
|
9
|
+
throw new Error('nginx not found. Is nginx installed?');
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export async function checkPermissionsConfigured() {
|
|
13
|
+
const result = await run('sudo -n /usr/bin/systemctl status nginx 2>/dev/null');
|
|
14
|
+
return result.success || !result.stderr?.includes('password');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export async function setupLinuxPermissions() {
|
|
18
|
+
if (process.platform === 'win32') return { success: false, reason: 'Windows not supported' };
|
|
19
|
+
|
|
20
|
+
const user = os.userInfo().username;
|
|
21
|
+
|
|
22
|
+
let nginxPath;
|
|
23
|
+
try {
|
|
24
|
+
nginxPath = await findNginxPath();
|
|
25
|
+
} catch (err) {
|
|
26
|
+
return { success: false, reason: err.message };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Step 1: authenticate sudo
|
|
30
|
+
const auth = await runInteractive('sudo -v');
|
|
31
|
+
if (!auth.success) return { success: false, reason: 'sudo authentication failed' };
|
|
32
|
+
|
|
33
|
+
// Step 2: create required directories and set ownership
|
|
34
|
+
const dirs = ['/etc/easy-devops', '/var/log/easy-devops'];
|
|
35
|
+
for (const dir of dirs) {
|
|
36
|
+
const mkResult = await runInteractive(`sudo mkdir -p ${dir}`);
|
|
37
|
+
if (mkResult.success) {
|
|
38
|
+
await runInteractive(`sudo chown ${user}:${user} ${dir}`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Step 3: fix nginx conf.d ownership
|
|
43
|
+
await runInteractive(`sudo chown -R ${user}:${user} /etc/nginx/conf.d 2>/dev/null || true`);
|
|
44
|
+
|
|
45
|
+
// Step 4: write sudoers file
|
|
46
|
+
const SUDO_RULES = [
|
|
47
|
+
'/usr/bin/systemctl start nginx',
|
|
48
|
+
'/usr/bin/systemctl stop nginx',
|
|
49
|
+
'/usr/bin/systemctl reload nginx',
|
|
50
|
+
'/usr/bin/systemctl restart nginx',
|
|
51
|
+
'/usr/bin/systemctl',
|
|
52
|
+
`${nginxPath}`,
|
|
53
|
+
`${nginxPath} -t`,
|
|
54
|
+
`${nginxPath} -s reload`,
|
|
55
|
+
`${nginxPath} -s stop`,
|
|
56
|
+
`${nginxPath} -s quit`,
|
|
57
|
+
'/usr/bin/certbot',
|
|
58
|
+
'/usr/bin/mkdir',
|
|
59
|
+
'/usr/bin/cp',
|
|
60
|
+
'/usr/bin/chmod',
|
|
61
|
+
'/usr/bin/chown',
|
|
62
|
+
'/usr/bin/tee',
|
|
63
|
+
].join(', ');
|
|
64
|
+
|
|
65
|
+
const sudoersContent = `${user} ALL=(ALL) NOPASSWD: ${SUDO_RULES}`;
|
|
66
|
+
const result = await runInteractive(
|
|
67
|
+
`echo '${sudoersContent}' | sudo tee /etc/sudoers.d/easy-devops > /dev/null && sudo chmod 440 /etc/sudoers.d/easy-devops`
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
return { success: result.success };
|
|
71
|
+
}
|
package/src/core/platform.js
CHANGED
|
@@ -59,3 +59,19 @@ export function nginxReloadCmd(nginxDir) {
|
|
|
59
59
|
export function combineOutput(result) {
|
|
60
60
|
return [result.stdout, result.stderr].filter(Boolean).join('\n').trim();
|
|
61
61
|
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Returns true if an `nginx -t` result indicates a valid config.
|
|
65
|
+
*
|
|
66
|
+
* Without root, nginx exits with code 1 after printing "syntax is ok" because
|
|
67
|
+
* it cannot write /run/nginx.pid (Permission denied). The config itself is
|
|
68
|
+
* valid in that case โ we check the output text rather than the exit code.
|
|
69
|
+
*
|
|
70
|
+
* @param {{ success: boolean, stdout: string, stderr: string }} result
|
|
71
|
+
* @returns {boolean}
|
|
72
|
+
*/
|
|
73
|
+
export function isNginxTestOk(result) {
|
|
74
|
+
if (result.success) return true;
|
|
75
|
+
const output = (result.stdout || '') + (result.stderr || '');
|
|
76
|
+
return output.includes('syntax is ok');
|
|
77
|
+
}
|
|
@@ -3,7 +3,7 @@ import path from 'path';
|
|
|
3
3
|
import { run } from '../../core/shell.js';
|
|
4
4
|
import { loadConfig } from '../../core/config.js';
|
|
5
5
|
import { ensureNginxInclude, getConfDDir } from '../../core/nginx-conf-generator.js';
|
|
6
|
-
import { isWindows, getNginxExe, nginxTestCmd, combineOutput } from '../../core/platform.js';
|
|
6
|
+
import { isWindows, getNginxExe, nginxTestCmd, combineOutput, isNginxTestOk } from '../../core/platform.js';
|
|
7
7
|
|
|
8
8
|
// โโโ Error Types โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
9
9
|
|
|
@@ -41,6 +41,25 @@ export function validateFilename(filename) {
|
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
const SUDO_PERMISSION_MSG = 'Linux permissions not configured. Open Settings โ Setup Linux Permissions.';
|
|
45
|
+
|
|
46
|
+
function isSudoPermissionError(result) {
|
|
47
|
+
const output = (result.stderr || result.stdout || '');
|
|
48
|
+
return (
|
|
49
|
+
output.includes('password is required') ||
|
|
50
|
+
output.includes('a terminal is required') ||
|
|
51
|
+
output.includes('sudo:')
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async function findNginxPath() {
|
|
56
|
+
const result = await run('which nginx');
|
|
57
|
+
if (result.success && result.stdout.trim()) {
|
|
58
|
+
return result.stdout.trim().split('\n')[0].trim();
|
|
59
|
+
}
|
|
60
|
+
throw new Error('nginx binary not found');
|
|
61
|
+
}
|
|
62
|
+
|
|
44
63
|
/** Checks if nginx is installed and throws NginxNotFoundError if not. */
|
|
45
64
|
async function assertNginxInstalled(nginxExe) {
|
|
46
65
|
const versionResult = await run(`${nginxExe} -v`);
|
|
@@ -95,8 +114,11 @@ export async function reload() {
|
|
|
95
114
|
|
|
96
115
|
const result = isWindows
|
|
97
116
|
? await run(`${nginxExe} -s reload`, { cwd: nginxDir, timeout: 15000 })
|
|
98
|
-
: await run('
|
|
99
|
-
|
|
117
|
+
: await run('sudo -n /usr/bin/systemctl reload nginx');
|
|
118
|
+
if (!result.success && !isWindows && isSudoPermissionError(result)) {
|
|
119
|
+
return { success: false, output: SUDO_PERMISSION_MSG };
|
|
120
|
+
}
|
|
121
|
+
return { success: result.success, output: combineOutput(result) || '' };
|
|
100
122
|
}
|
|
101
123
|
|
|
102
124
|
export async function restart() {
|
|
@@ -104,18 +126,22 @@ export async function restart() {
|
|
|
104
126
|
const nginxExe = getNginxExe(nginxDir);
|
|
105
127
|
await assertNginxInstalled(nginxExe);
|
|
106
128
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
129
|
+
if (isWindows) {
|
|
130
|
+
const stopResult = await run('taskkill /f /IM nginx.exe');
|
|
131
|
+
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
132
|
+
const startResult = await run(nginxExe, { cwd: nginxDir, timeout: 15000 });
|
|
133
|
+
const output = [combineOutput(stopResult), combineOutput(startResult)]
|
|
134
|
+
.filter(Boolean)
|
|
135
|
+
.join('\n')
|
|
136
|
+
.trim();
|
|
137
|
+
return { success: startResult.success, output };
|
|
138
|
+
}
|
|
112
139
|
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
return { success: startResult.success, output };
|
|
140
|
+
const result = await run('sudo -n /usr/bin/systemctl restart nginx');
|
|
141
|
+
if (!result.success && isSudoPermissionError(result)) {
|
|
142
|
+
return { success: false, output: SUDO_PERMISSION_MSG };
|
|
143
|
+
}
|
|
144
|
+
return { success: result.success, output: combineOutput(result) || '' };
|
|
119
145
|
}
|
|
120
146
|
|
|
121
147
|
export async function start() {
|
|
@@ -131,9 +157,15 @@ export async function start() {
|
|
|
131
157
|
|
|
132
158
|
// Test config before starting
|
|
133
159
|
await ensureNginxInclude(nginxDir);
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
|
|
160
|
+
const nginxPath = isWindows ? null : await findNginxPath();
|
|
161
|
+
const testResult = isWindows
|
|
162
|
+
? await run(nginxTestCmd(nginxDir), { cwd: nginxDir })
|
|
163
|
+
: await run(`${nginxPath} -t`);
|
|
164
|
+
if (!isNginxTestOk(testResult)) {
|
|
165
|
+
return {
|
|
166
|
+
success: false,
|
|
167
|
+
output: !isWindows && isSudoPermissionError(testResult) ? SUDO_PERMISSION_MSG : combineOutput(testResult),
|
|
168
|
+
};
|
|
137
169
|
}
|
|
138
170
|
|
|
139
171
|
// Start nginx
|
|
@@ -142,9 +174,9 @@ export async function start() {
|
|
|
142
174
|
const startCmd = `Start-Process -FilePath "${path.join(nginxDir, 'nginx.exe')}" -ArgumentList '-c','"${confPath}"' -WorkingDirectory "${nginxDir}" -WindowStyle Hidden`;
|
|
143
175
|
await run(startCmd, { cwd: nginxDir, timeout: 10000 });
|
|
144
176
|
} else {
|
|
145
|
-
const result = await run('
|
|
177
|
+
const result = await run('sudo -n /usr/bin/systemctl start nginx');
|
|
146
178
|
if (!result.success) {
|
|
147
|
-
return { success: false, output: combineOutput(result) };
|
|
179
|
+
return { success: false, output: isSudoPermissionError(result) ? SUDO_PERMISSION_MSG : combineOutput(result) || '' };
|
|
148
180
|
}
|
|
149
181
|
}
|
|
150
182
|
|
|
@@ -156,8 +188,8 @@ export async function start() {
|
|
|
156
188
|
const check = await run('tasklist /FI "IMAGENAME eq nginx.exe" /NH');
|
|
157
189
|
running = check.success && check.stdout.toLowerCase().includes('nginx.exe');
|
|
158
190
|
} else {
|
|
159
|
-
const check = await run('
|
|
160
|
-
running = check.
|
|
191
|
+
const check = await run('systemctl is-active nginx');
|
|
192
|
+
running = check.stdout.trim() === 'active';
|
|
161
193
|
}
|
|
162
194
|
|
|
163
195
|
if (running) {
|
|
@@ -186,8 +218,11 @@ export async function stop() {
|
|
|
186
218
|
|
|
187
219
|
const result = isWindows
|
|
188
220
|
? await run('taskkill /f /IM nginx.exe')
|
|
189
|
-
: await run('
|
|
221
|
+
: await run('sudo -n /usr/bin/systemctl stop nginx');
|
|
190
222
|
|
|
223
|
+
if (!result.success && !isWindows && isSudoPermissionError(result)) {
|
|
224
|
+
return { success: false, output: SUDO_PERMISSION_MSG };
|
|
225
|
+
}
|
|
191
226
|
return { success: result.success, output: combineOutput(result) || 'nginx stopped' };
|
|
192
227
|
}
|
|
193
228
|
|
|
@@ -199,8 +234,15 @@ export async function test() {
|
|
|
199
234
|
await assertNginxInstalled(nginxExe);
|
|
200
235
|
|
|
201
236
|
await ensureNginxInclude(nginxDir);
|
|
202
|
-
const
|
|
203
|
-
|
|
237
|
+
const nginxPath = isWindows ? null : await findNginxPath();
|
|
238
|
+
const result = isWindows
|
|
239
|
+
? await run(nginxTestCmd(nginxDir), { cwd: nginxDir })
|
|
240
|
+
: await run(`${nginxPath} -t`);
|
|
241
|
+
if (!result.success && !isWindows && isSudoPermissionError(result)) {
|
|
242
|
+
return { success: false, output: SUDO_PERMISSION_MSG };
|
|
243
|
+
}
|
|
244
|
+
const output = combineOutput(result);
|
|
245
|
+
return { success: isNginxTestOk(result), output };
|
|
204
246
|
}
|
|
205
247
|
|
|
206
248
|
// โโโ US4: Config File Management โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
@@ -246,14 +288,17 @@ export async function saveConfig(filename, content) {
|
|
|
246
288
|
|
|
247
289
|
const nginxExe = getNginxExe(nginxDir);
|
|
248
290
|
await ensureNginxInclude(nginxDir);
|
|
249
|
-
const
|
|
250
|
-
|
|
291
|
+
const nginxPath = isWindows ? null : await findNginxPath();
|
|
292
|
+
const testCmd = isWindows ? nginxTestCmd(nginxDir) : `${nginxPath} -t`;
|
|
293
|
+
const result = await run(testCmd, { cwd: nginxDir });
|
|
294
|
+
if (!isNginxTestOk(result)) {
|
|
251
295
|
if (hasBackup) {
|
|
252
296
|
await fs.copyFile(backupPath, confPath);
|
|
253
297
|
} else {
|
|
254
298
|
try { await fs.unlink(confPath); } catch { /* ignore */ }
|
|
255
299
|
}
|
|
256
|
-
|
|
300
|
+
const output = !isWindows && isSudoPermissionError(result) ? SUDO_PERMISSION_MSG : combineOutput(result);
|
|
301
|
+
throw new NginxConfigError(output);
|
|
257
302
|
}
|
|
258
303
|
|
|
259
304
|
return { success: true, output: combineOutput(result) };
|
|
@@ -108,6 +108,10 @@ createApp({
|
|
|
108
108
|
password: '', loading: false, msg: '', error: '',
|
|
109
109
|
platform: 'linux', // T022: Platform from settings API
|
|
110
110
|
},
|
|
111
|
+
|
|
112
|
+
permissions: {
|
|
113
|
+
configured: false, loading: false, password: '', msg: '', error: '',
|
|
114
|
+
},
|
|
111
115
|
};
|
|
112
116
|
},
|
|
113
117
|
|
|
@@ -254,7 +258,7 @@ createApp({
|
|
|
254
258
|
await Promise.all([this.loadNginxStatus(), this.loadNginxConfigs(), this.loadNginxLogs()]);
|
|
255
259
|
} else if (p === 'ssl') { await this.loadSSL(); }
|
|
256
260
|
else if (p === 'domains') { await this.loadDomains(); }
|
|
257
|
-
else if (p === 'settings') { await this.loadSettings(); }
|
|
261
|
+
else if (p === 'settings') { await Promise.all([this.loadSettings(), this.loadPermissionsStatus()]); }
|
|
258
262
|
},
|
|
259
263
|
|
|
260
264
|
// โโ Collapsible Sections โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
@@ -707,6 +711,25 @@ createApp({
|
|
|
707
711
|
}
|
|
708
712
|
},
|
|
709
713
|
|
|
714
|
+
async loadPermissionsStatus() {
|
|
715
|
+
if (this.settings.platform === 'win32') { this.permissions.configured = true; return; }
|
|
716
|
+
const r = await this.api('GET', '/api/settings/permissions');
|
|
717
|
+
if (r.ok) this.permissions.configured = r.data.configured;
|
|
718
|
+
},
|
|
719
|
+
|
|
720
|
+
async setupPermissions() {
|
|
721
|
+
this.permissions.loading = true; this.permissions.msg = ''; this.permissions.error = '';
|
|
722
|
+
const r = await this.api('POST', '/api/settings/permissions/setup', { password: this.permissions.password });
|
|
723
|
+
this.permissions.loading = false;
|
|
724
|
+
if (r.ok) {
|
|
725
|
+
this.permissions.configured = true;
|
|
726
|
+
this.permissions.msg = 'Permissions configured โ';
|
|
727
|
+
this.permissions.password = '';
|
|
728
|
+
} else {
|
|
729
|
+
this.permissions.error = r.data?.error || 'Setup failed';
|
|
730
|
+
}
|
|
731
|
+
},
|
|
732
|
+
|
|
710
733
|
async saveSettings() {
|
|
711
734
|
this.settings.loading = true; this.settings.msg = ''; this.settings.error = '';
|
|
712
735
|
const payload = {
|
|
@@ -6,7 +6,7 @@ import { loadConfig } from '../../core/config.js';
|
|
|
6
6
|
import { getDomains, saveDomains, findDomain, createDomain, DOMAIN_DEFAULTS } from '../lib/domains-db.js';
|
|
7
7
|
import { generateConf, getDefaultCertPaths } from '../lib/nginx-conf-generator.js';
|
|
8
8
|
import { getCertExpiry } from '../lib/cert-reader.js';
|
|
9
|
-
import { nginxTestCmd, nginxReloadCmd } from '../../core/platform.js';
|
|
9
|
+
import { isWindows, nginxTestCmd, nginxReloadCmd, isNginxTestOk } from '../../core/platform.js';
|
|
10
10
|
import {
|
|
11
11
|
validateDomainName, validatePort, validateUpstreamType,
|
|
12
12
|
validateMaxBodySize, validatePositiveInteger,
|
|
@@ -124,10 +124,15 @@ router.post('/', async (req, res) => {
|
|
|
124
124
|
return res.status(500).json({ error: 'Failed to write nginx conf', details: err.message });
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
-
const
|
|
128
|
-
|
|
127
|
+
const testCmd = isWindows ? nginxTestCmd(nginxDir) : 'nginx -t';
|
|
128
|
+
const testResult = await run(testCmd, { cwd: nginxDir });
|
|
129
|
+
if (!isNginxTestOk(testResult)) {
|
|
129
130
|
try { await fs.unlink(domain.configFile); } catch { /* ignore */ }
|
|
130
|
-
|
|
131
|
+
const output = testResult.stderr || testResult.stdout;
|
|
132
|
+
const error = !isWindows && output.includes('password is required')
|
|
133
|
+
? 'Linux permissions not configured. Open Settings โ Setup Linux Permissions.'
|
|
134
|
+
: 'nginx config test failed';
|
|
135
|
+
return res.status(500).json({ error, output });
|
|
131
136
|
}
|
|
132
137
|
|
|
133
138
|
const domains = getDomains();
|
|
@@ -200,12 +205,17 @@ router.put('/:name', async (req, res) => {
|
|
|
200
205
|
return res.status(500).json({ error: 'Failed to write nginx conf', details: err.message });
|
|
201
206
|
}
|
|
202
207
|
|
|
203
|
-
const
|
|
204
|
-
|
|
208
|
+
const testCmd = isWindows ? nginxTestCmd(nginxDir) : 'nginx -t';
|
|
209
|
+
const testResult = await run(testCmd, { cwd: nginxDir });
|
|
210
|
+
if (!isNginxTestOk(testResult)) {
|
|
205
211
|
if (bakPath) {
|
|
206
212
|
try { await fs.rename(bakPath, existing.configFile); } catch { /* ignore */ }
|
|
207
213
|
}
|
|
208
|
-
|
|
214
|
+
const output = testResult.stderr || testResult.stdout;
|
|
215
|
+
const error = !isWindows && output.includes('password is required')
|
|
216
|
+
? 'Linux permissions not configured. Open Settings โ Setup Linux Permissions.'
|
|
217
|
+
: 'nginx config test failed';
|
|
218
|
+
return res.status(500).json({ error, output });
|
|
209
219
|
}
|
|
210
220
|
|
|
211
221
|
const domains = getDomains();
|
|
@@ -288,7 +298,7 @@ router.put('/:name/toggle', async (req, res) => {
|
|
|
288
298
|
saveDomains(domains);
|
|
289
299
|
|
|
290
300
|
// Reload so nginx stops serving this domain
|
|
291
|
-
await run(nginxReloadCmd(nginxDir), { cwd: nginxDir });
|
|
301
|
+
await run(isWindows ? nginxReloadCmd(nginxDir) : 'sudo -n /usr/bin/systemctl reload nginx', { cwd: nginxDir });
|
|
292
302
|
|
|
293
303
|
return res.json({ enabled: false });
|
|
294
304
|
} else {
|
|
@@ -299,11 +309,16 @@ router.put('/:name/toggle', async (req, res) => {
|
|
|
299
309
|
return res.status(500).json({ error: 'Failed to rename config file', details: err.message });
|
|
300
310
|
}
|
|
301
311
|
|
|
302
|
-
const
|
|
303
|
-
|
|
312
|
+
const testCmd = isWindows ? nginxTestCmd(nginxDir) : 'nginx -t';
|
|
313
|
+
const testResult = await run(testCmd, { cwd: nginxDir });
|
|
314
|
+
if (!isNginxTestOk(testResult)) {
|
|
304
315
|
// Roll back rename
|
|
305
316
|
await fs.rename(enabledPath, disabledPath).catch(() => {});
|
|
306
|
-
|
|
317
|
+
const output = testResult.stderr || testResult.stdout;
|
|
318
|
+
const error = !isWindows && output.includes('password is required')
|
|
319
|
+
? 'Linux permissions not configured. Open Settings โ Setup Linux Permissions.'
|
|
320
|
+
: 'nginx config test failed';
|
|
321
|
+
return res.status(500).json({ error, output });
|
|
307
322
|
}
|
|
308
323
|
|
|
309
324
|
const domains = getDomains();
|
|
@@ -311,7 +326,7 @@ router.put('/:name/toggle', async (req, res) => {
|
|
|
311
326
|
domains[idx] = { ...domain, enabled: true, configFile: enabledPath, updatedAt: new Date().toISOString() };
|
|
312
327
|
saveDomains(domains);
|
|
313
328
|
|
|
314
|
-
await run(nginxReloadCmd(nginxDir), { cwd: nginxDir });
|
|
329
|
+
await run(isWindows ? nginxReloadCmd(nginxDir) : 'sudo -n /usr/bin/systemctl reload nginx', { cwd: nginxDir });
|
|
315
330
|
|
|
316
331
|
return res.json({ enabled: true });
|
|
317
332
|
}
|
|
@@ -327,14 +342,24 @@ router.post('/:name/reload', async (req, res) => {
|
|
|
327
342
|
|
|
328
343
|
const { nginxDir } = loadConfig();
|
|
329
344
|
|
|
330
|
-
const
|
|
331
|
-
|
|
332
|
-
|
|
345
|
+
const testCmd = isWindows ? nginxTestCmd(nginxDir) : 'nginx -t';
|
|
346
|
+
const testResult = await run(testCmd, { cwd: nginxDir });
|
|
347
|
+
if (!isNginxTestOk(testResult)) {
|
|
348
|
+
const output = testResult.stderr || testResult.stdout;
|
|
349
|
+
const error = !isWindows && output.includes('password is required')
|
|
350
|
+
? 'Linux permissions not configured. Open Settings โ Setup Linux Permissions.'
|
|
351
|
+
: 'nginx config test failed';
|
|
352
|
+
return res.status(500).json({ error, output });
|
|
333
353
|
}
|
|
334
354
|
|
|
335
|
-
const
|
|
355
|
+
const reloadCmd = isWindows ? nginxReloadCmd(nginxDir) : 'sudo -n /usr/bin/systemctl reload nginx';
|
|
356
|
+
const reloadResult = await run(reloadCmd, { cwd: nginxDir });
|
|
336
357
|
if (!reloadResult.success) {
|
|
337
|
-
|
|
358
|
+
const output = reloadResult.stderr || reloadResult.stdout;
|
|
359
|
+
const error = !isWindows && output.includes('password is required')
|
|
360
|
+
? 'Linux permissions not configured. Open Settings โ Setup Linux Permissions.'
|
|
361
|
+
: 'nginx reload failed';
|
|
362
|
+
return res.status(500).json({ error, output });
|
|
338
363
|
}
|
|
339
364
|
|
|
340
365
|
res.json({ message: 'nginx reloaded successfully' });
|
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
import express from 'express';
|
|
2
|
+
import { spawn } from 'child_process';
|
|
3
|
+
import fs from 'fs/promises';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import os from 'os';
|
|
2
6
|
import { loadConfig, saveConfig } from '../../core/config.js';
|
|
3
7
|
import { validatePort, validateEmail } from '../../core/validators.js';
|
|
8
|
+
import { run } from '../../core/shell.js';
|
|
9
|
+
import { checkPermissionsConfigured } from '../../core/permissions.js';
|
|
10
|
+
|
|
11
|
+
// Run a bash command with sudo -S (password read from stdin โ no terminal needed)
|
|
12
|
+
function runSudoS(bashCmd, password) {
|
|
13
|
+
return new Promise((resolve) => {
|
|
14
|
+
const child = spawn('sudo', ['-S', 'bash', '-c', bashCmd], {
|
|
15
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
16
|
+
});
|
|
17
|
+
let stdout = '', stderr = '';
|
|
18
|
+
child.stdout.on('data', d => { stdout += d; });
|
|
19
|
+
child.stderr.on('data', d => { stderr += d; });
|
|
20
|
+
child.stdin.write(password + '\n');
|
|
21
|
+
child.stdin.end();
|
|
22
|
+
child.on('close', code => resolve({ success: code === 0, stdout: stdout.trim(), stderr: stderr.trim() }));
|
|
23
|
+
child.on('error', err => resolve({ success: false, stdout: '', stderr: err.message }));
|
|
24
|
+
});
|
|
25
|
+
}
|
|
4
26
|
|
|
5
27
|
const router = express.Router();
|
|
6
28
|
|
|
@@ -83,4 +105,90 @@ router.post('/settings', (req, res) => {
|
|
|
83
105
|
}
|
|
84
106
|
});
|
|
85
107
|
|
|
108
|
+
// โโโ GET /api/settings/permissions โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
109
|
+
|
|
110
|
+
router.get('/settings/permissions', async (req, res) => {
|
|
111
|
+
if (process.platform === 'win32') return res.json({ configured: true });
|
|
112
|
+
try {
|
|
113
|
+
const configured = await checkPermissionsConfigured();
|
|
114
|
+
res.json({ configured });
|
|
115
|
+
} catch {
|
|
116
|
+
res.json({ configured: false });
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
// โโโ POST /api/settings/permissions/setup โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
121
|
+
|
|
122
|
+
router.post('/settings/permissions/setup', async (req, res) => {
|
|
123
|
+
if (process.platform === 'win32') {
|
|
124
|
+
return res.status(400).json({ error: 'Not applicable on Windows' });
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const { password } = req.body ?? {};
|
|
128
|
+
if (!password || typeof password !== 'string') {
|
|
129
|
+
return res.status(400).json({ error: 'Password is required' });
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Resolve nginx binary path
|
|
133
|
+
const whichResult = await run('which nginx');
|
|
134
|
+
if (!whichResult.success || !whichResult.stdout.trim()) {
|
|
135
|
+
return res.status(500).json({ error: 'nginx not found. Is nginx installed?' });
|
|
136
|
+
}
|
|
137
|
+
const nginxPath = whichResult.stdout.trim().split('\n')[0].trim();
|
|
138
|
+
const user = os.userInfo().username;
|
|
139
|
+
|
|
140
|
+
// Build sudoers rules with the detected nginx path
|
|
141
|
+
const sudoRules = [
|
|
142
|
+
'/usr/bin/systemctl start nginx',
|
|
143
|
+
'/usr/bin/systemctl stop nginx',
|
|
144
|
+
'/usr/bin/systemctl reload nginx',
|
|
145
|
+
'/usr/bin/systemctl restart nginx',
|
|
146
|
+
'/usr/bin/systemctl',
|
|
147
|
+
nginxPath,
|
|
148
|
+
`${nginxPath} -t`,
|
|
149
|
+
`${nginxPath} -s reload`,
|
|
150
|
+
`${nginxPath} -s stop`,
|
|
151
|
+
`${nginxPath} -s quit`,
|
|
152
|
+
'/usr/bin/certbot',
|
|
153
|
+
'/usr/bin/mkdir',
|
|
154
|
+
'/usr/bin/cp',
|
|
155
|
+
'/usr/bin/chmod',
|
|
156
|
+
'/usr/bin/chown',
|
|
157
|
+
'/usr/bin/tee',
|
|
158
|
+
].join(', ');
|
|
159
|
+
|
|
160
|
+
const sudoersContent = `${user} ALL=(ALL) NOPASSWD: ${sudoRules}\n`;
|
|
161
|
+
|
|
162
|
+
// Write content to a temp file (no sudo needed for /tmp)
|
|
163
|
+
const tmpFile = path.join('/tmp', `easy-devops-sudoers-${Date.now()}`);
|
|
164
|
+
try {
|
|
165
|
+
await fs.writeFile(tmpFile, sudoersContent, { mode: 0o600 });
|
|
166
|
+
} catch (err) {
|
|
167
|
+
return res.status(500).json({ error: 'Failed to write temp file', output: err.message });
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Run all setup steps in a single sudo -S invocation
|
|
171
|
+
const setupCmd = [
|
|
172
|
+
`mkdir -p /etc/easy-devops /var/log/easy-devops`,
|
|
173
|
+
`chown ${user}:${user} /etc/easy-devops /var/log/easy-devops`,
|
|
174
|
+
`chown -R ${user}:${user} /etc/nginx/conf.d 2>/dev/null || true`,
|
|
175
|
+
`cp '${tmpFile}' /etc/sudoers.d/easy-devops`,
|
|
176
|
+
`chmod 440 /etc/sudoers.d/easy-devops`,
|
|
177
|
+
].join(' && ');
|
|
178
|
+
|
|
179
|
+
const result = await runSudoS(setupCmd, password);
|
|
180
|
+
await fs.unlink(tmpFile).catch(() => {});
|
|
181
|
+
|
|
182
|
+
if (!result.success) {
|
|
183
|
+
const output = result.stderr || result.stdout;
|
|
184
|
+
const wrongPassword = output.includes('incorrect password') || output.includes('Sorry, try again') || output.includes('3 incorrect');
|
|
185
|
+
return res.status(wrongPassword ? 401 : 500).json({
|
|
186
|
+
error: wrongPassword ? 'Incorrect password' : 'Setup failed',
|
|
187
|
+
output,
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
res.json({ success: true });
|
|
192
|
+
});
|
|
193
|
+
|
|
86
194
|
export default router;
|
|
@@ -65,4 +65,37 @@
|
|
|
65
65
|
</div>
|
|
66
66
|
</div>
|
|
67
67
|
</div>
|
|
68
|
+
|
|
69
|
+
<!-- Linux Permissions card (hidden on Windows) -->
|
|
70
|
+
<div v-if="settings.platform !== 'win32'" class="stat-card overflow-hidden relative mt-6">
|
|
71
|
+
<div class="absolute top-0 left-0 w-full h-1" :class="permissions.configured ? 'bg-green-500/40' : 'bg-yellow-500/40'"></div>
|
|
72
|
+
<div class="p-6 border-b border-border/50 bg-black/5 dark:bg-white/5 flex items-center justify-between">
|
|
73
|
+
<div>
|
|
74
|
+
<h3 class="form-label !mb-0 font-bold">Linux Permissions</h3>
|
|
75
|
+
<p class="text-[11px] text-muted mt-1 font-bold tracking-wide uppercase opacity-70">Passwordless sudo for nginx and systemctl</p>
|
|
76
|
+
</div>
|
|
77
|
+
<span v-if="permissions.configured" class="text-green-500 text-xs font-bold px-2.5 py-1 rounded-lg bg-green-500/10 border border-green-500/20">โ Configured</span>
|
|
78
|
+
<span v-else class="text-yellow-500 text-xs font-bold px-2.5 py-1 rounded-lg bg-yellow-500/10 border border-yellow-500/20">โ Required</span>
|
|
79
|
+
</div>
|
|
80
|
+
<div class="p-8 bg-background">
|
|
81
|
+
<p v-if="permissions.configured" class="text-sm text-muted">Passwordless sudo is configured. The dashboard can manage nginx and systemctl without prompting for a password.</p>
|
|
82
|
+
<div v-else>
|
|
83
|
+
<p class="text-sm text-muted mb-6">The dashboard needs passwordless sudo to control nginx and systemctl. Enter your sudo password once to configure it.</p>
|
|
84
|
+
<div class="w-full max-w-md">
|
|
85
|
+
<label class="form-label">Sudo Password</label>
|
|
86
|
+
<input v-model="permissions.password" type="password" class="form-input" placeholder="Enter your sudo password" @keyup.enter="setupPermissions" />
|
|
87
|
+
</div>
|
|
88
|
+
</div>
|
|
89
|
+
</div>
|
|
90
|
+
<div v-if="!permissions.configured" class="p-5 border-t border-border bg-black/5 dark:bg-white/5 flex flex-col sm:flex-row sm:items-center justify-between gap-4">
|
|
91
|
+
<button @click="setupPermissions" :disabled="permissions.loading || !permissions.password" class="btn btn-primary min-w-[180px] shadow-sm">
|
|
92
|
+
<svg v-if="permissions.loading" class="w-4 h-4 animate-spin -ml-1 mr-2 inline-block" fill="none" viewBox="0 0 24 24"><circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle><path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"></path></svg>
|
|
93
|
+
{{ permissions.loading ? 'Setting up...' : 'Setup Permissions' }}
|
|
94
|
+
</button>
|
|
95
|
+
<div>
|
|
96
|
+
<span v-if="permissions.msg" class="text-green-500 text-[13px] font-bold px-3 py-1.5 rounded-[10px] bg-green-500/10 border border-green-500/20">{{ permissions.msg }}</span>
|
|
97
|
+
<span v-if="permissions.error" class="text-red-500 text-[13px] font-bold px-3 py-1.5 rounded-[10px] bg-red-500/10 border border-red-500/20">{{ permissions.error }}</span>
|
|
98
|
+
</div>
|
|
99
|
+
</div>
|
|
100
|
+
</div>
|
|
68
101
|
</div>
|