easy-devops 1.0.0 → 1.0.2
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 +24 -23
- package/install.sh +27 -4
- package/package.json +10 -13
- package/{cli → src/cli}/index.js +1 -1
- package/{cli → src/cli}/managers/domain-manager.js +13 -9
- package/{cli → src/cli}/managers/nginx-manager.js +90 -40
- package/{cli → src/cli}/managers/ssl-manager.js +16 -2
- package/{cli → src/cli}/menus/dashboard.js +1 -1
- package/{cli → src/cli}/menus/settings.js +23 -0
- package/{cli → src/cli}/menus/update.js +1 -1
- package/{core → src/core}/db.js +1 -1
- package/src/core/permissions.js +71 -0
- package/{core → src/core}/platform.js +16 -0
- package/{core → src/core}/shell.js +36 -0
- package/{dashboard → src/dashboard}/lib/nginx-service.js +72 -27
- package/{dashboard → src/dashboard}/public/js/app.js +37 -2
- package/{dashboard → src/dashboard}/routes/domains.js +42 -17
- package/src/dashboard/routes/settings.js +194 -0
- package/{dashboard → src/dashboard}/views/index.ejs +111 -7
- package/{dashboard → src/dashboard}/views/partials/domain-form.ejs +30 -7
- package/{dashboard → src/dashboard}/views/partials/domains-panel.ejs +0 -3
- package/{dashboard → src/dashboard}/views/partials/nginx-panel.ejs +25 -4
- package/{dashboard → src/dashboard}/views/partials/settings-panel.ejs +34 -1
- package/{lib → src/lib}/installer/picker.sh +4 -4
- package/dashboard/routes/settings.js +0 -86
- /package/{cli → src/cli}/managers/node-manager.js +0 -0
- /package/{cli → src/cli}/menus/.gitkeep +0 -0
- /package/{cli → src/cli}/menus/domains.js +0 -0
- /package/{cli → src/cli}/menus/nginx.js +0 -0
- /package/{cli → src/cli}/menus/nodejs.js +0 -0
- /package/{cli → src/cli}/menus/ssl.js +0 -0
- /package/{core → src/core}/config.js +0 -0
- /package/{core → src/core}/detector.js +0 -0
- /package/{core → src/core}/nginx-conf-generator.js +0 -0
- /package/{core → src/core}/validators.js +0 -0
- /package/{dashboard → src/dashboard}/lib/.gitkeep +0 -0
- /package/{dashboard → src/dashboard}/lib/cert-reader.js +0 -0
- /package/{dashboard → src/dashboard}/lib/domains-db.js +0 -0
- /package/{dashboard → src/dashboard}/lib/nginx-conf-generator.js +0 -0
- /package/{dashboard → src/dashboard}/public/img/icon.png +0 -0
- /package/{dashboard → src/dashboard}/public/img/icon_b.png +0 -0
- /package/{dashboard → src/dashboard}/routes/.gitkeep +0 -0
- /package/{dashboard → src/dashboard}/routes/auth.js +0 -0
- /package/{dashboard → src/dashboard}/routes/nginx.js +0 -0
- /package/{dashboard → src/dashboard}/routes/ssl.js +0 -0
- /package/{dashboard → src/dashboard}/server.js +0 -0
- /package/{dashboard → src/dashboard}/views/partials/login.ejs +0 -0
- /package/{dashboard → src/dashboard}/views/partials/overview.ejs +0 -0
- /package/{dashboard → src/dashboard}/views/partials/sidebar.ejs +0 -0
- /package/{dashboard → src/dashboard}/views/partials/ssl-panel.ejs +0 -0
- /package/{lib → src/lib}/installer/.gitkeep +0 -0
- /package/{lib → src/lib}/installer/detect.sh +0 -0
- /package/{lib → src/lib}/installer/node-versions.sh +0 -0
- /package/{lib → src/lib}/installer/nvm-bootstrap.sh +0 -0
- /package/{lib → src/lib}/installer/progress.sh +0 -0
- /package/{lib → src/lib}/installer/winget-install.ps1 +0 -0
|
@@ -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
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
* - getShell() — Returns OS-resolved shell descriptor { shell, flag }
|
|
10
10
|
* - run(cmd, options) — Executes a command and captures output; never throws
|
|
11
11
|
* - runLive(cmd, options) — Executes a command, streaming output to the terminal; never throws
|
|
12
|
+
* - runInteractive(cmd, options) — Executes a command with full stdio inheritance (Linux only); never throws
|
|
12
13
|
*
|
|
13
14
|
* CommandResult shape (returned by run()):
|
|
14
15
|
* { success: boolean, stdout: string, stderr: string, exitCode: number|null, command: string }
|
|
@@ -149,3 +150,38 @@ export function runLive(cmd, options = {}) {
|
|
|
149
150
|
});
|
|
150
151
|
});
|
|
151
152
|
}
|
|
153
|
+
|
|
154
|
+
// ─── runInteractive ───────────────────────────────────────────────────────────
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Executes a shell command with full stdio inheritance (stdin/stdout/stderr all
|
|
158
|
+
* pass through to the terminal). Intended for Linux-only interactive commands
|
|
159
|
+
* such as `sudo -v` that need to read a password from the user.
|
|
160
|
+
*
|
|
161
|
+
* Never throws.
|
|
162
|
+
*
|
|
163
|
+
* @param {string} cmd - The command string to execute.
|
|
164
|
+
* @param {{ cwd?: string }} [options]
|
|
165
|
+
* @param {string} [options.cwd=process.cwd()] - Working directory for the child process.
|
|
166
|
+
* @returns {Promise<{ success: boolean, exitCode: number|null }>}
|
|
167
|
+
*/
|
|
168
|
+
export function runInteractive(cmd, options = {}) {
|
|
169
|
+
const { cwd = process.cwd() } = options;
|
|
170
|
+
const { shell, flag } = getShell();
|
|
171
|
+
|
|
172
|
+
return new Promise((resolve) => {
|
|
173
|
+
const child = spawn(shell, [flag, cmd], {
|
|
174
|
+
cwd,
|
|
175
|
+
stdio: 'inherit',
|
|
176
|
+
windowsHide: true,
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
child.on('close', (exitCode) => {
|
|
180
|
+
resolve({ success: exitCode === 0, exitCode });
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
child.on('error', (err) => {
|
|
184
|
+
resolve({ success: false, exitCode: null });
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
}
|
|
@@ -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) };
|
|
@@ -64,6 +64,7 @@ createApp({
|
|
|
64
64
|
configs: [], selectedConfig: '',
|
|
65
65
|
configContent: '', configSaving: false, configMsg: '',
|
|
66
66
|
logs: [], logsLoading: false,
|
|
67
|
+
configDropdownOpen: false,
|
|
67
68
|
},
|
|
68
69
|
|
|
69
70
|
ssl: {
|
|
@@ -80,6 +81,7 @@ createApp({
|
|
|
80
81
|
domains: {
|
|
81
82
|
list: [], loading: false, error: '',
|
|
82
83
|
showForm: false,
|
|
84
|
+
upstreamTypeOpen: false,
|
|
83
85
|
editingName: null, // T017: null = adding, string = editing
|
|
84
86
|
saving: false,
|
|
85
87
|
dirty: false, // T019: Track unsaved changes
|
|
@@ -106,6 +108,10 @@ createApp({
|
|
|
106
108
|
password: '', loading: false, msg: '', error: '',
|
|
107
109
|
platform: 'linux', // T022: Platform from settings API
|
|
108
110
|
},
|
|
111
|
+
|
|
112
|
+
permissions: {
|
|
113
|
+
configured: false, loading: false, password: '', msg: '', error: '',
|
|
114
|
+
},
|
|
109
115
|
};
|
|
110
116
|
},
|
|
111
117
|
|
|
@@ -252,7 +258,7 @@ createApp({
|
|
|
252
258
|
await Promise.all([this.loadNginxStatus(), this.loadNginxConfigs(), this.loadNginxLogs()]);
|
|
253
259
|
} else if (p === 'ssl') { await this.loadSSL(); }
|
|
254
260
|
else if (p === 'domains') { await this.loadDomains(); }
|
|
255
|
-
else if (p === 'settings') { await this.loadSettings(); }
|
|
261
|
+
else if (p === 'settings') { await Promise.all([this.loadSettings(), this.loadPermissionsStatus()]); }
|
|
256
262
|
},
|
|
257
263
|
|
|
258
264
|
// ── Collapsible Sections ────────────────────────────────────────────
|
|
@@ -705,6 +711,25 @@ createApp({
|
|
|
705
711
|
}
|
|
706
712
|
},
|
|
707
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
|
+
|
|
708
733
|
async saveSettings() {
|
|
709
734
|
this.settings.loading = true; this.settings.msg = ''; this.settings.error = '';
|
|
710
735
|
const payload = {
|
|
@@ -720,4 +745,14 @@ createApp({
|
|
|
720
745
|
else { this.settings.error = r.data.error || 'Save failed'; }
|
|
721
746
|
},
|
|
722
747
|
},
|
|
723
|
-
})
|
|
748
|
+
})
|
|
749
|
+
.directive('click-outside', {
|
|
750
|
+
mounted(el, binding) {
|
|
751
|
+
el._clickOutside = (e) => { if (!el.contains(e.target)) binding.value(e); };
|
|
752
|
+
document.addEventListener('mousedown', el._clickOutside);
|
|
753
|
+
},
|
|
754
|
+
unmounted(el) {
|
|
755
|
+
document.removeEventListener('mousedown', el._clickOutside);
|
|
756
|
+
},
|
|
757
|
+
})
|
|
758
|
+
.mount('#app');
|
|
@@ -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' });
|