easy-devops 1.0.1 → 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/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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "easy-devops",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "A unified DevOps management tool with CLI and web dashboard for managing Nginx, SSL certificates, and Node.js on Linux and Windows servers.",
5
5
  "keywords": [
6
6
  "devops",
@@ -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 testResult = await run(nginxTestCmd(nginxDir), { cwd: nginxDir });
303
+ const testCmd = isWindows ? nginxTestCmd(nginxDir) : 'nginx -t';
304
+ const testResult = await run(testCmd, { cwd: nginxDir });
304
305
 
305
- if (!testResult.success) {
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 testResult = await run(nginxTestCmd(nginxDir), { cwd: nginxDir });
380
+ const testCmd = isWindows ? nginxTestCmd(nginxDir) : 'nginx -t';
381
+ const testResult = await run(testCmd, { cwd: nginxDir });
380
382
 
381
- if (!testResult.success) {
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 testResult = await run(nginxTestCmd(nginxDir), { cwd: nginxDir });
455
- if (!testResult.success) {
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 testResult = await run(nginxTestCmd(nginxDir), { cwd: nginxDir });
530
- if (!testResult.success) {
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
- if (!PathDomain) {
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
- await import('fs/promises').then(fs => fs.mkdir(`${nginxDir}\\conf\\conf.d`, { recursive: true }));
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 (!willKnown) {
78
- console.warn(chalk.yellow(`Warning: .well-known/acme-challenge directory not found in ${nginxDir} — creating it now...`));
79
- await import('fs/promises').then(fs => fs.mkdir(`${nginxDir}\\html\\.well-known\\`, { recursive: true }));
80
- await import('fs/promises').then(fs => fs.mkdir(`${nginxDir}\\html\\.well-known\\acme-challenge`, { recursive: true }));
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.success,
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
- const cmd = isWindows ? `& "${nginxExe}" -s reload` : 'systemctl reload nginx';
103
- const result = await run(cmd, { cwd: nginxDir });
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 run('systemctl restart nginx');
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 run('systemctl start nginx', { timeout: 15000 });
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
- const cmd = isWindows ? 'taskkill /f /IM nginx.exe' : 'systemctl stop nginx';
240
- const result = await run(cmd, { cwd: nginxDir });
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
- console.log(chalk.red('\n' + (result.stderr || result.stdout)));
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
- console.log(chalk.yellow('\n sudo password required to install nginx.\n'));
255
-
256
- const auth = await runInteractive('sudo -v');
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
- if (!auth.success) {
259
- console.log(chalk.red(' sudo authentication failed.'));
260
- return { success: false, message: 'sudo authentication failed', output: auth.stderr };
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
- const spinner = ora('Installing nginx…').start();
264
- const result = await run('sudo apt-get install -y nginx', { timeout: 120000 });
265
- if (result.success) {
266
- spinner.succeed('nginx installed successfully');
267
- return { success: true, message: 'nginx installed successfully', output: result.stdout };
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
- spinner.fail('Installation failed');
270
- console.log(chalk.red(result.stderr || result.stdout));
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(`${nginxDir}\\conf\\conf.d`, { recursive: true }));
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.writeFile(`${nginxDir}\\html\\.well-known\\acme-challenge`, '', (err) => {
356
- if (err) {
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
- await fs.mkdir(path.dirname(keyPath), { recursive: true });
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
- await fs.mkdir(certDir, { recursive: true });
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([{
@@ -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
+ }
@@ -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('nginx -s reload');
99
- return { success: result.success, output: combineOutput(result) };
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
- const stopResult = isWindows
108
- ? await run('taskkill /f /IM nginx.exe')
109
- : await run('nginx -s stop');
110
-
111
- await new Promise(resolve => setTimeout(resolve, 2000));
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 startResult = await run(nginxExe, { cwd: nginxDir, timeout: 15000 });
114
- const output = [combineOutput(stopResult), combineOutput(startResult)]
115
- .filter(Boolean)
116
- .join('\n')
117
- .trim();
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 testResult = await run(nginxTestCmd(nginxDir), { cwd: nginxDir });
135
- if (!testResult.success) {
136
- return { success: false, output: combineOutput(testResult) };
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('nginx', { cwd: nginxDir, timeout: 15000 });
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('pgrep -x nginx');
160
- running = check.exitCode === 0;
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('nginx -s stop');
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 result = await run(nginxTestCmd(nginxDir), { cwd: nginxDir });
203
- return { success: result.success, output: combineOutput(result) };
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 result = await run(nginxTestCmd(nginxDir), { cwd: nginxDir });
250
- if (!result.success) {
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
- throw new NginxConfigError(combineOutput(result));
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 testResult = await run(nginxTestCmd(nginxDir), { cwd: nginxDir });
128
- if (!testResult.success) {
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
- return res.status(500).json({ error: 'nginx config test failed', output: testResult.stderr || testResult.stdout });
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 testResult = await run(nginxTestCmd(nginxDir), { cwd: nginxDir });
204
- if (!testResult.success) {
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
- return res.status(500).json({ error: 'nginx config test failed', output: testResult.stderr || testResult.stdout });
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 testResult = await run(nginxTestCmd(nginxDir), { cwd: nginxDir });
303
- if (!testResult.success) {
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
- return res.status(500).json({ error: 'nginx config test failed', output: testResult.stderr || testResult.stdout });
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 testResult = await run(nginxTestCmd(nginxDir), { cwd: nginxDir });
331
- if (!testResult.success) {
332
- return res.status(500).json({ error: 'nginx config test failed', output: testResult.stderr || testResult.stdout });
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 reloadResult = await run(nginxReloadCmd(nginxDir), { cwd: nginxDir });
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
- return res.status(500).json({ error: 'nginx reload failed', output: reloadResult.stderr || reloadResult.stdout });
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>