easy-devops 1.2.1 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +97 -6
- package/dist/ui/assets/index-B6zdwEnG.css +1 -0
- package/dist/ui/assets/index-Cy0oNmul.js +442 -0
- package/dist/ui/assets/socket-DwLPrgsr.js +1 -0
- package/dist/ui/assets/socket-K5ttLD2q.js +65 -0
- package/dist/ui/brand/apple-touch-icon.png +0 -0
- package/dist/ui/brand/favicon-16.png +0 -0
- package/dist/ui/brand/favicon-32.png +0 -0
- package/dist/ui/brand/favicon-light-16.png +0 -0
- package/dist/ui/brand/favicon-light-32.png +0 -0
- package/dist/ui/brand/favicon.ico +0 -0
- package/dist/ui/brand/icon-192.png +0 -0
- package/dist/ui/brand/icon-48.png +0 -0
- package/dist/ui/brand/icon-512.png +0 -0
- package/dist/ui/brand/icon-64-light.png +0 -0
- package/dist/ui/brand/icon-64.png +0 -0
- package/dist/ui/brand/logo-dark.png +0 -0
- package/dist/ui/brand/logo-light.png +0 -0
- package/dist/ui/brand/mark-dark.png +0 -0
- package/dist/ui/brand/mark-light.png +0 -0
- package/dist/ui/index.html +71 -0
- package/install.ps1 +188 -1
- package/install.sh +254 -29
- package/package.json +15 -4
- package/src/cli/dash.js +110 -0
- package/src/cli/index.js +237 -106
- package/src/cli/managers/domain-manager.js +60 -40
- package/src/cli/managers/ssl-manager.js +47 -330
- package/src/cli/menu.js +156 -0
- package/src/cli/menus/cleanup.js +205 -0
- package/src/cli/menus/dashboard.js +92 -1
- package/src/cli/menus/runtime.js +236 -0
- package/src/cli/menus/service.js +764 -0
- package/src/cli/menus/settings.js +176 -8
- package/src/cli/menus/uninstall.js +167 -0
- package/src/cli/menus/update.js +221 -65
- package/src/core/acme-challenge.js +273 -0
- package/src/core/cert-operations.js +189 -0
- package/src/{dashboard/lib → core}/cert-reader.js +2 -2
- package/src/core/cert-renewal.js +494 -0
- package/src/core/cleanup.js +600 -0
- package/src/core/config.js +169 -2
- package/src/core/daemon/ipc.js +292 -0
- package/src/core/daemon/lock.js +294 -0
- package/src/core/daemon/run.js +241 -0
- package/src/core/daemon/stopRequest.js +162 -0
- package/src/core/db.js +37 -8
- package/src/core/deploy/apps.js +491 -0
- package/src/core/deploy/domainLink.js +200 -0
- package/src/core/deploy/engine.js +973 -0
- package/src/core/deploy/ezfile.js +361 -0
- package/src/core/deploy/github.js +239 -0
- package/src/core/deploy/githubApi.js +261 -0
- package/src/core/deploy/hookServer.js +325 -0
- package/src/core/deploy/hubCommands.js +267 -0
- package/src/core/deploy/launcher.js +57 -0
- package/src/core/deploy/status.js +91 -0
- package/src/core/deploy/store.js +398 -0
- package/src/core/domainNotifier.js +94 -28
- package/src/core/domains-db.js +234 -0
- package/src/core/events.js +94 -2
- package/src/core/hub/agent.js +842 -0
- package/src/core/hubLink.js +306 -0
- package/src/core/hubPermissions.js +430 -0
- package/src/core/installSource.js +162 -0
- package/src/core/jobs/bus.js +120 -0
- package/src/core/jobs/index.js +371 -0
- package/src/core/jobs/monitors.js +368 -0
- package/src/core/jobs/owner.js +217 -0
- package/src/core/jobs/revisionWatcher.js +106 -0
- package/src/core/nginx-apply.js +213 -0
- package/src/core/nginx-conf-generator.js +253 -17
- package/src/{dashboard/lib → core}/nginx-service.js +18 -9
- package/src/core/notifications/claim.js +214 -0
- package/src/core/notifications/dispatch.js +154 -0
- package/src/core/notifier.js +31 -1
- package/src/core/passwords.js +172 -0
- package/src/core/permissions.js +8 -4
- package/src/core/platform.js +709 -2
- package/src/core/probeCache.js +258 -0
- package/src/core/purge.js +372 -0
- package/src/core/runner.js +488 -0
- package/src/core/service/acl.js +226 -0
- package/src/core/service/dataDir.js +345 -0
- package/src/core/service/index.js +1128 -0
- package/src/core/service/legacy.js +218 -0
- package/src/core/service/runtime.js +446 -0
- package/src/core/service/runtimeUpdate.js +800 -0
- package/src/core/service/systemd.js +458 -0
- package/src/core/service/windowsPersonal.js +530 -0
- package/src/core/service/windowsService.js +576 -0
- package/src/core/service/winsw.js +260 -0
- package/src/core/setupCode.js +331 -0
- package/src/core/shell.js +70 -7
- package/src/core/ssl-issuer.js +627 -0
- package/src/core/updater.js +295 -0
- package/src/core/validators.js +99 -0
- package/src/dashboard/controllers/authController.js +302 -15
- package/src/dashboard/controllers/deploymentsController.js +479 -0
- package/src/dashboard/controllers/domainsController.js +39 -52
- package/src/dashboard/controllers/hubController.js +135 -0
- package/src/dashboard/controllers/nginxController.js +21 -3
- package/src/dashboard/controllers/processesController.js +368 -0
- package/src/dashboard/controllers/settingsController.js +180 -12
- package/src/dashboard/controllers/sslController.js +171 -10
- package/src/dashboard/lib/daemonBridge.js +163 -0
- package/src/dashboard/lib/localRequest.js +235 -0
- package/src/dashboard/lib/loginRateLimit.js +119 -0
- package/src/dashboard/lib/requireAuth.js +80 -0
- package/src/dashboard/public/js/app.js +489 -19
- package/src/dashboard/routes/auth.js +10 -10
- package/src/dashboard/routes/deployments.js +46 -0
- package/src/dashboard/routes/domains.js +9 -0
- package/src/dashboard/routes/hub.js +22 -0
- package/src/dashboard/routes/nginx.js +9 -0
- package/src/dashboard/routes/processes.js +29 -0
- package/src/dashboard/routes/settings.js +9 -0
- package/src/dashboard/routes/ssl.js +9 -0
- package/src/dashboard/server.js +288 -21
- package/src/dashboard/socketManager.js +171 -207
- package/src/dashboard/views/index.ejs +1 -0
- package/src/dashboard/views/partials/login.ejs +68 -7
- package/src/dashboard/views/partials/processes-panel.ejs +261 -0
- package/src/dashboard/views/partials/settings-panel.ejs +287 -0
- package/src/dashboard/views/partials/sidebar.ejs +2 -0
- package/src/dashboard/lib/domains-db.js +0 -51
|
@@ -53,17 +53,38 @@ createApp({
|
|
|
53
53
|
authenticated: false,
|
|
54
54
|
page: 'overview',
|
|
55
55
|
|
|
56
|
-
login: {
|
|
56
|
+
login: {
|
|
57
|
+
password: '', confirm: '', error: '', loading: false,
|
|
58
|
+
// Replaced by minPasswordLength from GET /api/auth as soon as it
|
|
59
|
+
// answers; this is only the value used before that first response.
|
|
60
|
+
needsSetup: false, minLength: 6,
|
|
61
|
+
// Offered only when the server says this request is local and the
|
|
62
|
+
// dashboard listens on this machine only.
|
|
63
|
+
canUseNoPassword: false,
|
|
64
|
+
authMode: 'password',
|
|
65
|
+
},
|
|
57
66
|
|
|
58
67
|
navItems: [
|
|
59
68
|
{ id: 'overview', label: 'Overview', icon: '⚡' },
|
|
60
69
|
{ id: 'nginx', label: 'Nginx', icon: '🌐' },
|
|
61
70
|
{ id: 'ssl', label: 'SSL Certs', icon: '🔒' },
|
|
62
71
|
{ id: 'domains', label: 'Domains', icon: '🔗' },
|
|
72
|
+
{ id: 'processes', label: 'Processes', icon: '🧩' },
|
|
63
73
|
{ id: 'logs', label: 'Logs', icon: '📋' },
|
|
64
74
|
{ id: 'settings', label: 'Settings', icon: '⚙️' },
|
|
65
75
|
],
|
|
66
76
|
|
|
77
|
+
// Background service (PM2) and the process list.
|
|
78
|
+
svc: {
|
|
79
|
+
status: null, loading: false, restarting: false, message: '', error: false,
|
|
80
|
+
},
|
|
81
|
+
processes: {
|
|
82
|
+
apps: [], loading: false, pm2Installed: false, currentUser: '',
|
|
83
|
+
busy: null, message: '', error: false,
|
|
84
|
+
logsFor: null, logLines: [],
|
|
85
|
+
confirm: null,
|
|
86
|
+
},
|
|
87
|
+
|
|
67
88
|
nginx: {
|
|
68
89
|
status: null, loading: false,
|
|
69
90
|
actionMsg: '', actionError: '',
|
|
@@ -123,8 +144,24 @@ createApp({
|
|
|
123
144
|
dashboardPort: '', nginxDir: '', sslDir: '', acmeEmail: '',
|
|
124
145
|
password: '', loading: false, msg: '', error: '',
|
|
125
146
|
platform: 'linux', // T022: Platform from settings API
|
|
147
|
+
dashboardBindAddress: '', bindsToLoopbackOnly: false,
|
|
148
|
+
dashboardAuth: 'password', canUseNoPassword: false, hasPassword: false,
|
|
149
|
+
},
|
|
150
|
+
settingsTab: 'general', // 'general' | 'notifications' | 'hub'
|
|
151
|
+
|
|
152
|
+
hub: {
|
|
153
|
+
loading: false,
|
|
154
|
+
status: {
|
|
155
|
+
linked: false, connected: false, status: 'not_linked',
|
|
156
|
+
hubUrl: null, serverId: null, permissions: {},
|
|
157
|
+
tree: [], comingSoon: [],
|
|
158
|
+
lastError: null, attempts: 0,
|
|
159
|
+
},
|
|
160
|
+
form: { connectionString: '' },
|
|
161
|
+
msg: '',
|
|
162
|
+
error: '',
|
|
163
|
+
pollTimer: null,
|
|
126
164
|
},
|
|
127
|
-
settingsTab: 'general', // 'general' | 'notifications'
|
|
128
165
|
|
|
129
166
|
permissions: {
|
|
130
167
|
configured: false, loading: false, password: '', msg: '', error: '',
|
|
@@ -237,18 +274,26 @@ createApp({
|
|
|
237
274
|
document.documentElement.classList.toggle('dark', this.theme === 'dark');
|
|
238
275
|
document.documentElement.setAttribute('data-accent', this.accent);
|
|
239
276
|
|
|
240
|
-
// Check if already authenticated
|
|
277
|
+
// Check if already authenticated, and whether this is a first run.
|
|
241
278
|
try {
|
|
242
279
|
const r = await fetch('/api/auth');
|
|
243
280
|
const d = await r.json();
|
|
281
|
+
this.login.needsSetup = d.needsSetup === true;
|
|
282
|
+
this.login.canUseNoPassword = d.canUseNoPassword === true;
|
|
283
|
+
this.login.authMode = d.authMode || 'password';
|
|
284
|
+
if (typeof d.minPasswordLength === 'number') this.login.minLength = d.minPasswordLength;
|
|
244
285
|
if (d.authenticated) { this.authenticated = true; this.loadPage('overview'); }
|
|
245
286
|
} catch { /* server may not be up yet */ }
|
|
246
287
|
|
|
247
|
-
//
|
|
248
|
-
await this.loadSettings();
|
|
288
|
+
// Settings are behind the session now, so only load them once signed in.
|
|
289
|
+
if (this.authenticated) await this.loadSettings();
|
|
249
290
|
|
|
250
291
|
// Real-time nginx status via Socket.io
|
|
251
|
-
|
|
292
|
+
// extraHeaders reaches the server because socket.io's default transport
|
|
293
|
+
// order starts with HTTP polling, where headers can be set. Do NOT add
|
|
294
|
+
// transports: ['websocket'] here — browsers cannot set headers on a
|
|
295
|
+
// WebSocket upgrade, and the handshake would be refused.
|
|
296
|
+
const socket = io({ extraHeaders: { 'X-EZ-Request': '1' } });
|
|
252
297
|
socket.on('nginx:status', (status) => {
|
|
253
298
|
this.nginx.status = status;
|
|
254
299
|
});
|
|
@@ -260,6 +305,22 @@ createApp({
|
|
|
260
305
|
for (const r of results) map[r.name] = r.up;
|
|
261
306
|
this.domainHealth = map;
|
|
262
307
|
});
|
|
308
|
+
// A change applied by the Hub (or any other process) — refresh just the
|
|
309
|
+
// affected section so the open tab does not show stale data.
|
|
310
|
+
socket.on('local:changed', ({ section }) => {
|
|
311
|
+
if (section === 'domains') {
|
|
312
|
+
this.loadDomains();
|
|
313
|
+
if (this.page === 'ssl') this.loadCerts();
|
|
314
|
+
} else if (section === 'ssl') {
|
|
315
|
+
this.loadCerts();
|
|
316
|
+
this.loadDomains();
|
|
317
|
+
} else if (section === 'nginx') {
|
|
318
|
+
this.loadNginxStatus();
|
|
319
|
+
if (this.page === 'nginx') this.loadNginxConfigs();
|
|
320
|
+
}
|
|
321
|
+
if (this.settingsTab === 'hub') this.loadHubStatus();
|
|
322
|
+
});
|
|
323
|
+
|
|
263
324
|
socket.on('logs:line', ({ line, logFile }) => {
|
|
264
325
|
if (!this.logs.paused && logFile === this.logs.activeLog) {
|
|
265
326
|
this.logs.lines.push(line);
|
|
@@ -272,13 +333,41 @@ createApp({
|
|
|
272
333
|
methods: {
|
|
273
334
|
// ── Core API helper ────────────────────────────────────────────────────────
|
|
274
335
|
async api(method, path, body) {
|
|
275
|
-
const opts = {
|
|
336
|
+
const opts = {
|
|
337
|
+
method,
|
|
338
|
+
headers: {
|
|
339
|
+
'Content-Type': 'application/json',
|
|
340
|
+
// Proves the request came from the dashboard's own page rather than
|
|
341
|
+
// another website in this browser: a cross-site form cannot set a
|
|
342
|
+
// custom header, and a cross-site fetch that tries triggers a CORS
|
|
343
|
+
// preflight the server never approves. Required on every
|
|
344
|
+
// state-changing request — see dashboard/lib/localRequest.js.
|
|
345
|
+
'X-EZ-Request': '1',
|
|
346
|
+
},
|
|
347
|
+
};
|
|
276
348
|
if (body !== undefined) opts.body = JSON.stringify(body);
|
|
277
349
|
const r = await fetch(path, opts);
|
|
278
350
|
const data = await r.json().catch(() => ({}));
|
|
351
|
+
|
|
352
|
+
// Any 401 means the session is gone — expired, or the server restarted
|
|
353
|
+
// with a new session secret. Drop straight back to the login screen
|
|
354
|
+
// instead of leaving a half-dead page showing stale data.
|
|
355
|
+
if (r.status === 401 && path !== '/api/login' && path !== '/api/setup') {
|
|
356
|
+
this.handleUnauthorized(data);
|
|
357
|
+
}
|
|
358
|
+
|
|
279
359
|
return { ok: r.ok, status: r.status, data };
|
|
280
360
|
},
|
|
281
361
|
|
|
362
|
+
/** Returns the UI to the login screen after the session was refused. */
|
|
363
|
+
handleUnauthorized(data) {
|
|
364
|
+
if (this.authenticated) this.login.error = 'Your session ended. Please sign in again.';
|
|
365
|
+
this.authenticated = false;
|
|
366
|
+
this.login.password = '';
|
|
367
|
+
this.login.confirm = '';
|
|
368
|
+
if (data && data.needsSetup === true) this.login.needsSetup = true;
|
|
369
|
+
},
|
|
370
|
+
|
|
282
371
|
// ── Theme ─────────────────────────────────────────────────────────────────
|
|
283
372
|
toggleTheme() { this.theme = this.theme === 'dark' ? 'light' : 'dark'; },
|
|
284
373
|
setAccent(color) { this.accent = color; },
|
|
@@ -288,13 +377,83 @@ createApp({
|
|
|
288
377
|
this.login.loading = true; this.login.error = '';
|
|
289
378
|
const r = await this.api('POST', '/api/login', { password: this.login.password });
|
|
290
379
|
this.login.loading = false;
|
|
291
|
-
|
|
292
|
-
|
|
380
|
+
|
|
381
|
+
if (r.ok) {
|
|
382
|
+
this.authenticated = true;
|
|
383
|
+
this.login.password = '';
|
|
384
|
+
this.login.confirm = '';
|
|
385
|
+
this.login.needsSetup = false;
|
|
386
|
+
await this.loadSettings();
|
|
387
|
+
this.loadPage('overview');
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
// The server decides when setup is needed; the page follows it.
|
|
392
|
+
if (r.data && r.data.needsSetup === true) this.login.needsSetup = true;
|
|
393
|
+
this.login.error = r.data.error || 'Invalid password';
|
|
394
|
+
},
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* First run: run without a password.
|
|
398
|
+
*
|
|
399
|
+
* Only reachable when the server reported canUseNoPassword, which means
|
|
400
|
+
* the dashboard listens on this machine only AND this request came from
|
|
401
|
+
* this machine. The server re-checks both; this is just the button.
|
|
402
|
+
*/
|
|
403
|
+
async doSetupNoPassword() {
|
|
404
|
+
this.login.error = '';
|
|
405
|
+
this.login.loading = true;
|
|
406
|
+
const r = await this.api('POST', '/api/setup', { mode: 'none' });
|
|
407
|
+
this.login.loading = false;
|
|
408
|
+
|
|
409
|
+
if (r.ok) {
|
|
410
|
+
this.authenticated = true;
|
|
411
|
+
this.login.needsSetup = false;
|
|
412
|
+
this.login.authMode = 'none';
|
|
413
|
+
await this.loadSettings();
|
|
414
|
+
this.loadPage('overview');
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
this.login.error = r.data.error || 'Could not save that choice';
|
|
419
|
+
},
|
|
420
|
+
|
|
421
|
+
/** First run: set the initial password, which also signs the user in. */
|
|
422
|
+
async doSetup() {
|
|
423
|
+
this.login.error = '';
|
|
424
|
+
|
|
425
|
+
if (this.login.password.length < this.login.minLength) {
|
|
426
|
+
this.login.error = 'The password must be at least ' + this.login.minLength + ' characters.';
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
if (this.login.password !== this.login.confirm) {
|
|
430
|
+
this.login.error = 'The two passwords do not match.';
|
|
431
|
+
return;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
this.login.loading = true;
|
|
435
|
+
const r = await this.api('POST', '/api/setup', { password: this.login.password });
|
|
436
|
+
this.login.loading = false;
|
|
437
|
+
|
|
438
|
+
if (r.ok) {
|
|
439
|
+
this.authenticated = true;
|
|
440
|
+
this.login.password = '';
|
|
441
|
+
this.login.confirm = '';
|
|
442
|
+
this.login.needsSetup = false;
|
|
443
|
+
await this.loadSettings();
|
|
444
|
+
this.loadPage('overview');
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
this.login.error = r.data.error || 'Could not set the password';
|
|
293
449
|
},
|
|
294
450
|
|
|
295
451
|
async doLogout() {
|
|
296
452
|
await this.api('POST', '/api/logout');
|
|
297
453
|
this.authenticated = false;
|
|
454
|
+
this.login.password = '';
|
|
455
|
+
this.login.confirm = '';
|
|
456
|
+
this.login.error = '';
|
|
298
457
|
},
|
|
299
458
|
|
|
300
459
|
// ── Navigation (T021: Nav click guard) ────────────────────────────────────
|
|
@@ -317,6 +476,9 @@ createApp({
|
|
|
317
476
|
|
|
318
477
|
async loadPage(p) {
|
|
319
478
|
if (this.page === 'logs' && p !== 'logs') this.unsubscribeLogs();
|
|
479
|
+
// The hub status poll only exists for the settings page; leaving it must
|
|
480
|
+
// not leave a timer re-polling in the background.
|
|
481
|
+
if (p !== 'settings') this.stopHubPoll();
|
|
320
482
|
this.page = p;
|
|
321
483
|
if (p === 'overview') {
|
|
322
484
|
await Promise.all([this.loadNginxStatus(), this.loadSSL(), this.loadDomains()]);
|
|
@@ -325,7 +487,8 @@ createApp({
|
|
|
325
487
|
} else if (p === 'ssl') { await this.loadSSL(); }
|
|
326
488
|
else if (p === 'domains') { await this.loadDomains(); }
|
|
327
489
|
else if (p === 'logs') { this.subscribeToLogs(this.logs.activeLog); }
|
|
328
|
-
else if (p === '
|
|
490
|
+
else if (p === 'processes') { await this.loadProcessesPage(); }
|
|
491
|
+
else if (p === 'settings') { await Promise.all([this.loadSettings(), this.loadPermissionsStatus(), this.loadChannels(), this.loadHubStatus(), this.loadServiceStatus()]); }
|
|
329
492
|
},
|
|
330
493
|
|
|
331
494
|
// ── Collapsible Sections ────────────────────────────────────────────
|
|
@@ -333,6 +496,133 @@ createApp({
|
|
|
333
496
|
this.sections[sectionId] = !this.sections[sectionId];
|
|
334
497
|
},
|
|
335
498
|
|
|
499
|
+
// ── Background service + processes ────────────────────────────────────────
|
|
500
|
+
|
|
501
|
+
/** Both panels on the Processes page come from two independent reads. */
|
|
502
|
+
async loadProcessesPage() {
|
|
503
|
+
await Promise.all([this.loadServiceStatus(), this.loadProcesses()]);
|
|
504
|
+
},
|
|
505
|
+
|
|
506
|
+
async loadServiceStatus() {
|
|
507
|
+
this.svc.loading = true;
|
|
508
|
+
const r = await this.api('GET', '/api/service');
|
|
509
|
+
this.svc.loading = false;
|
|
510
|
+
if (r.ok) this.svc.status = r.data;
|
|
511
|
+
},
|
|
512
|
+
|
|
513
|
+
async loadProcesses() {
|
|
514
|
+
this.processes.loading = true;
|
|
515
|
+
const r = await this.api('GET', '/api/processes');
|
|
516
|
+
this.processes.loading = false;
|
|
517
|
+
if (!r.ok) {
|
|
518
|
+
this.processes.error = true;
|
|
519
|
+
this.processes.message = r.data?.error || 'Could not read the process list';
|
|
520
|
+
return;
|
|
521
|
+
}
|
|
522
|
+
this.processes.apps = r.data.apps || [];
|
|
523
|
+
this.processes.pm2Installed = Boolean(r.data.pm2?.installed);
|
|
524
|
+
this.processes.currentUser = r.data.currentUser || '';
|
|
525
|
+
this.processes.error = false;
|
|
526
|
+
this.processes.message = '';
|
|
527
|
+
},
|
|
528
|
+
|
|
529
|
+
describeBoot(status) {
|
|
530
|
+
if (!status) return 'No';
|
|
531
|
+
// null means the init system could not be inspected (non-systemd Linux);
|
|
532
|
+
// showing "No" there would be a confident lie.
|
|
533
|
+
if (status.enabledOnBoot === null) return 'Unknown';
|
|
534
|
+
if (!status.enabledOnBoot) return 'No';
|
|
535
|
+
if (status.bootMode === 'logon') return 'At logon';
|
|
536
|
+
if (status.bootMode === 'boot') return 'At startup';
|
|
537
|
+
return 'Yes';
|
|
538
|
+
},
|
|
539
|
+
|
|
540
|
+
formatBytes(bytes) {
|
|
541
|
+
if (bytes === null || bytes === undefined) return '—';
|
|
542
|
+
if (bytes < 1024 * 1024) return Math.round(bytes / 1024) + ' KB';
|
|
543
|
+
return Math.round(bytes / (1024 * 1024)) + ' MB';
|
|
544
|
+
},
|
|
545
|
+
|
|
546
|
+
formatDuration(ms) {
|
|
547
|
+
if (ms === null || ms === undefined || ms < 0) return '—';
|
|
548
|
+
const s = Math.floor(ms / 1000);
|
|
549
|
+
if (s < 60) return s + 's';
|
|
550
|
+
const m = Math.floor(s / 60);
|
|
551
|
+
if (m < 60) return m + 'm';
|
|
552
|
+
const h = Math.floor(m / 60);
|
|
553
|
+
if (h < 24) return h + 'h ' + (m % 60) + 'm';
|
|
554
|
+
return Math.floor(h / 24) + 'd ' + (h % 24) + 'h';
|
|
555
|
+
},
|
|
556
|
+
|
|
557
|
+
/**
|
|
558
|
+
* Acts on one PM2 process.
|
|
559
|
+
*
|
|
560
|
+
* Anything Easy DevOps did not create asks first: the user may be looking
|
|
561
|
+
* at an unrelated production app that happens to share this PM2.
|
|
562
|
+
*/
|
|
563
|
+
async processAction(app, action) {
|
|
564
|
+
if (!app.managed && (action === 'stop' || action === 'restart')) {
|
|
565
|
+
this.processes.confirm = { name: app.name, action };
|
|
566
|
+
return;
|
|
567
|
+
}
|
|
568
|
+
await this.runProcessAction(app.name, action);
|
|
569
|
+
},
|
|
570
|
+
|
|
571
|
+
async runConfirmedProcessAction() {
|
|
572
|
+
const pending = this.processes.confirm;
|
|
573
|
+
this.processes.confirm = null;
|
|
574
|
+
if (pending) await this.runProcessAction(pending.name, pending.action);
|
|
575
|
+
},
|
|
576
|
+
|
|
577
|
+
async runProcessAction(name, action) {
|
|
578
|
+
this.processes.busy = name;
|
|
579
|
+
this.processes.message = '';
|
|
580
|
+
const r = await this.api('POST', `/api/processes/${encodeURIComponent(name)}/${action}`);
|
|
581
|
+
this.processes.busy = null;
|
|
582
|
+
|
|
583
|
+
if (r.ok) {
|
|
584
|
+
this.processes.error = false;
|
|
585
|
+
this.processes.message = `${name}: ${action} done`;
|
|
586
|
+
} else {
|
|
587
|
+
this.processes.error = true;
|
|
588
|
+
this.processes.message = r.data?.error || `Could not ${action} ${name}`;
|
|
589
|
+
}
|
|
590
|
+
await this.loadProcessesPage();
|
|
591
|
+
},
|
|
592
|
+
|
|
593
|
+
async showProcessLogs(app) {
|
|
594
|
+
this.processes.busy = app.name;
|
|
595
|
+
const r = await this.api('GET', `/api/processes/${encodeURIComponent(app.name)}/logs?lines=200`);
|
|
596
|
+
this.processes.busy = null;
|
|
597
|
+
if (r.ok) {
|
|
598
|
+
this.processes.logsFor = app.name;
|
|
599
|
+
this.processes.logLines = r.data.lines || [];
|
|
600
|
+
} else {
|
|
601
|
+
this.processes.error = true;
|
|
602
|
+
this.processes.message = r.data?.error || 'Could not read the logs';
|
|
603
|
+
}
|
|
604
|
+
},
|
|
605
|
+
|
|
606
|
+
/**
|
|
607
|
+
* Restarts the service. Safe from the dashboard on both platforms: it needs
|
|
608
|
+
* no elevation and no password prompt, unlike installing the boot task.
|
|
609
|
+
*/
|
|
610
|
+
async restartService() {
|
|
611
|
+
this.svc.restarting = true;
|
|
612
|
+
this.svc.message = '';
|
|
613
|
+
const r = await this.api('POST', '/api/service/restart');
|
|
614
|
+
this.svc.restarting = false;
|
|
615
|
+
|
|
616
|
+
if (r.ok) {
|
|
617
|
+
this.svc.error = false;
|
|
618
|
+
this.svc.message = 'Service restarted. The dashboard may take a moment to come back.';
|
|
619
|
+
} else {
|
|
620
|
+
this.svc.error = true;
|
|
621
|
+
this.svc.message = r.data?.error || 'Could not restart the service';
|
|
622
|
+
}
|
|
623
|
+
await this.loadServiceStatus();
|
|
624
|
+
},
|
|
625
|
+
|
|
336
626
|
// ── Nginx ─────────────────────────────────────────────────────────────────
|
|
337
627
|
async loadNginxStatus() {
|
|
338
628
|
this.nginx.loading = true;
|
|
@@ -764,13 +1054,17 @@ createApp({
|
|
|
764
1054
|
const domain = this.domains.form.name;
|
|
765
1055
|
if (domain) {
|
|
766
1056
|
const platform = this.settings.platform;
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
1057
|
+
// Always forward slashes, including on Windows: nginx reads a
|
|
1058
|
+
// backslash as an escape character, so C:\nginx\test\... would
|
|
1059
|
+
// have its \n and \t turned into a newline and a tab.
|
|
1060
|
+
// Use the configured sslDir — that is where certs are issued.
|
|
1061
|
+
const fallback = platform === 'win32' ? 'C:/easy-devops/ssl' : '/etc/easy-devops/ssl';
|
|
1062
|
+
const base = String(this.settings.sslDir || fallback)
|
|
1063
|
+
.replace(/\\/g, '/')
|
|
1064
|
+
.replace(/\/{2,}/g, '/')
|
|
1065
|
+
.replace(/\/+$/, '');
|
|
1066
|
+
this.domains.form.ssl.certPath = `${base}/${domain}/fullchain.pem`;
|
|
1067
|
+
this.domains.form.ssl.keyPath = `${base}/${domain}/privkey.pem`;
|
|
774
1068
|
}
|
|
775
1069
|
}
|
|
776
1070
|
}
|
|
@@ -787,6 +1081,11 @@ createApp({
|
|
|
787
1081
|
this.settings.sslDir = r.data.sslDir;
|
|
788
1082
|
this.settings.acmeEmail = r.data.acmeEmail || '';
|
|
789
1083
|
this.settings.platform = r.data.platform || 'linux'; // T022
|
|
1084
|
+
this.settings.dashboardBindAddress = r.data.dashboardBindAddress || '';
|
|
1085
|
+
this.settings.bindsToLoopbackOnly = r.data.bindsToLoopbackOnly === true;
|
|
1086
|
+
this.settings.dashboardAuth = r.data.dashboardAuth || 'password';
|
|
1087
|
+
this.settings.canUseNoPassword = r.data.canUseNoPassword === true;
|
|
1088
|
+
this.settings.hasPassword = r.data.hasPassword === true;
|
|
790
1089
|
}
|
|
791
1090
|
},
|
|
792
1091
|
|
|
@@ -796,6 +1095,166 @@ createApp({
|
|
|
796
1095
|
if (r.ok) this.permissions.configured = r.data.configured;
|
|
797
1096
|
},
|
|
798
1097
|
|
|
1098
|
+
// ── Hub ──────────────────────────────────────────────────────────────────────
|
|
1099
|
+
hubStatusLabel() {
|
|
1100
|
+
const map = {
|
|
1101
|
+
not_linked: 'Not linked',
|
|
1102
|
+
connecting: 'Connecting…',
|
|
1103
|
+
connected: 'Online',
|
|
1104
|
+
rejected: 'Rejected by hub',
|
|
1105
|
+
unreachable: 'Hub unreachable',
|
|
1106
|
+
};
|
|
1107
|
+
return map[this.hub.status.status] || 'Unknown';
|
|
1108
|
+
},
|
|
1109
|
+
|
|
1110
|
+
hubStatusDotClass() {
|
|
1111
|
+
const map = {
|
|
1112
|
+
connected: 'bg-green-500',
|
|
1113
|
+
connecting: 'bg-yellow-500',
|
|
1114
|
+
unreachable: 'bg-yellow-500',
|
|
1115
|
+
rejected: 'bg-red-500',
|
|
1116
|
+
not_linked: 'bg-slate-500',
|
|
1117
|
+
};
|
|
1118
|
+
return map[this.hub.status.status] || 'bg-slate-500';
|
|
1119
|
+
},
|
|
1120
|
+
|
|
1121
|
+
async loadHubStatus() {
|
|
1122
|
+
const r = await this.api('GET', '/api/hub/status');
|
|
1123
|
+
if (r.ok) {
|
|
1124
|
+
this.hub.status = {
|
|
1125
|
+
linked: r.data.linked,
|
|
1126
|
+
connected: r.data.connected,
|
|
1127
|
+
status: r.data.status || 'not_linked',
|
|
1128
|
+
hubUrl: r.data.hubUrl,
|
|
1129
|
+
serverId: r.data.serverId,
|
|
1130
|
+
permissions: r.data.permissions || {},
|
|
1131
|
+
tree: Array.isArray(r.data.tree) ? r.data.tree : [],
|
|
1132
|
+
comingSoon: Array.isArray(r.data.comingSoon) ? r.data.comingSoon : [],
|
|
1133
|
+
lastError: r.data.lastError || null,
|
|
1134
|
+
attempts: r.data.attempts || 0,
|
|
1135
|
+
};
|
|
1136
|
+
// Keep polling only while the outcome is still undecided.
|
|
1137
|
+
// Keep polling while the outcome can still change on its own.
|
|
1138
|
+
// 'unreachable' is included because the agent retries in the
|
|
1139
|
+
// background and can recover without any user action — without this
|
|
1140
|
+
// the tab would keep showing "Hub unreachable" after it reconnected.
|
|
1141
|
+
// 'rejected' and 'not_linked' need the user, so polling stops there.
|
|
1142
|
+
if (this.hub.status.status === 'connecting') this.scheduleHubPoll(2000);
|
|
1143
|
+
else if (this.hub.status.status === 'unreachable') this.scheduleHubPoll(15000);
|
|
1144
|
+
else this.stopHubPoll();
|
|
1145
|
+
}
|
|
1146
|
+
},
|
|
1147
|
+
|
|
1148
|
+
scheduleHubPoll(delayMs = 2000) {
|
|
1149
|
+
this.stopHubPoll();
|
|
1150
|
+
this.hub.pollTimer = setTimeout(() => this.loadHubStatus(), delayMs);
|
|
1151
|
+
},
|
|
1152
|
+
|
|
1153
|
+
stopHubPoll() {
|
|
1154
|
+
if (this.hub.pollTimer) {
|
|
1155
|
+
clearTimeout(this.hub.pollTimer);
|
|
1156
|
+
this.hub.pollTimer = null;
|
|
1157
|
+
}
|
|
1158
|
+
},
|
|
1159
|
+
|
|
1160
|
+
async connectHubAgent() {
|
|
1161
|
+
this.hub.loading = true;
|
|
1162
|
+
this.hub.msg = '';
|
|
1163
|
+
this.hub.error = '';
|
|
1164
|
+
try {
|
|
1165
|
+
const r = await this.api('POST', '/api/hub/connect', {
|
|
1166
|
+
connectionString: this.hub.form.connectionString,
|
|
1167
|
+
});
|
|
1168
|
+
if (r.ok) {
|
|
1169
|
+
this.hub.form.connectionString = '';
|
|
1170
|
+
this.hub.msg = 'Connection string saved. Connecting to the hub…';
|
|
1171
|
+
await this.loadHubStatus();
|
|
1172
|
+
} else {
|
|
1173
|
+
this.hub.error = r.data?.error || 'Failed to connect to the hub';
|
|
1174
|
+
}
|
|
1175
|
+
} catch (e) {
|
|
1176
|
+
// fetch() rejects when the dashboard is unreachable; without this the
|
|
1177
|
+
// button would stay disabled forever.
|
|
1178
|
+
this.hub.error = 'Could not reach the dashboard. Please try again.';
|
|
1179
|
+
} finally {
|
|
1180
|
+
this.hub.loading = false;
|
|
1181
|
+
}
|
|
1182
|
+
},
|
|
1183
|
+
|
|
1184
|
+
async unlinkHub() {
|
|
1185
|
+
if (!confirm('Unlink this server from the hub? The hub will stop receiving data from this server.')) return;
|
|
1186
|
+
this.hub.loading = true;
|
|
1187
|
+
this.hub.msg = '';
|
|
1188
|
+
this.hub.error = '';
|
|
1189
|
+
try {
|
|
1190
|
+
const r = await this.api('DELETE', '/api/hub/link');
|
|
1191
|
+
if (r.ok) {
|
|
1192
|
+
this.stopHubPoll();
|
|
1193
|
+
this.hub.status = {
|
|
1194
|
+
linked: false, connected: false, status: 'not_linked',
|
|
1195
|
+
hubUrl: null, serverId: null, permissions: {},
|
|
1196
|
+
lastError: null, attempts: 0,
|
|
1197
|
+
};
|
|
1198
|
+
this.hub.form.connectionString = '';
|
|
1199
|
+
this.hub.msg = 'Unlinked from hub.';
|
|
1200
|
+
} else {
|
|
1201
|
+
this.hub.error = r.data?.error || 'Failed to unlink from the hub';
|
|
1202
|
+
}
|
|
1203
|
+
} catch (e) {
|
|
1204
|
+
this.hub.error = 'Could not reach the dashboard. Please try again.';
|
|
1205
|
+
} finally {
|
|
1206
|
+
this.hub.loading = false;
|
|
1207
|
+
}
|
|
1208
|
+
},
|
|
1209
|
+
|
|
1210
|
+
// ── Permission tree ───────────────────────────────────────────────────────
|
|
1211
|
+
|
|
1212
|
+
/** 'on' | 'off' | 'partial' for a group's checkbox. */
|
|
1213
|
+
hubGroupState(group) {
|
|
1214
|
+
const grantable = (group.children || []).filter(c => !c.comingSoon);
|
|
1215
|
+
if (grantable.length === 0) return 'off';
|
|
1216
|
+
const on = grantable.filter(c => this.hub.status.permissions[c.id] === true).length;
|
|
1217
|
+
if (on === 0) return 'off';
|
|
1218
|
+
if (on === grantable.length) return 'on';
|
|
1219
|
+
return 'partial';
|
|
1220
|
+
},
|
|
1221
|
+
|
|
1222
|
+
hubGroupChecked(group) { return this.hubGroupState(group) === 'on'; },
|
|
1223
|
+
hubGroupIndeterminate(group) { return this.hubGroupState(group) === 'partial'; },
|
|
1224
|
+
|
|
1225
|
+
/** Toggling a group sets every grantable child the same way. */
|
|
1226
|
+
async toggleHubGroup(group) {
|
|
1227
|
+
const turnOn = this.hubGroupState(group) !== 'on';
|
|
1228
|
+
for (const child of group.children || []) {
|
|
1229
|
+
if (child.comingSoon) continue;
|
|
1230
|
+
this.hub.status.permissions[child.id] = turnOn;
|
|
1231
|
+
}
|
|
1232
|
+
await this.persistHubPermissions({ groups: { [group.id]: turnOn } });
|
|
1233
|
+
},
|
|
1234
|
+
|
|
1235
|
+
async toggleHubPermission(child) {
|
|
1236
|
+
if (child.comingSoon) return;
|
|
1237
|
+
const next = !this.hub.status.permissions[child.id];
|
|
1238
|
+
this.hub.status.permissions[child.id] = next;
|
|
1239
|
+
await this.persistHubPermissions({ [child.id]: next });
|
|
1240
|
+
},
|
|
1241
|
+
|
|
1242
|
+
async persistHubPermissions(payload) {
|
|
1243
|
+
this.hub.error = '';
|
|
1244
|
+
const r = await this.api('PUT', '/api/hub/permissions', payload);
|
|
1245
|
+
if (r.ok) {
|
|
1246
|
+
// Trust the server's normalised answer over local optimism.
|
|
1247
|
+
this.hub.status.permissions = r.data.permissions || {};
|
|
1248
|
+
} else {
|
|
1249
|
+
this.hub.error = r.data?.error || 'Failed to save permissions';
|
|
1250
|
+
await this.loadHubStatus();
|
|
1251
|
+
}
|
|
1252
|
+
},
|
|
1253
|
+
|
|
1254
|
+
hubGrantedCount() {
|
|
1255
|
+
return Object.values(this.hub.status.permissions || {}).filter(Boolean).length;
|
|
1256
|
+
},
|
|
1257
|
+
|
|
799
1258
|
async loadChannels() {
|
|
800
1259
|
this.channels.loading = true;
|
|
801
1260
|
const r = await this.api('GET', '/api/settings/channels');
|
|
@@ -905,10 +1364,21 @@ createApp({
|
|
|
905
1364
|
acmeEmail: this.settings.acmeEmail,
|
|
906
1365
|
};
|
|
907
1366
|
if (this.settings.password) payload.dashboardPassword = this.settings.password;
|
|
1367
|
+
if (this.settings.dashboardBindAddress) {
|
|
1368
|
+
payload.dashboardBindAddress = this.settings.dashboardBindAddress;
|
|
1369
|
+
}
|
|
1370
|
+
if (this.settings.dashboardAuth) payload.dashboardAuth = this.settings.dashboardAuth;
|
|
908
1371
|
const r = await this.api('POST', '/api/settings', payload);
|
|
909
1372
|
this.settings.loading = false;
|
|
910
|
-
if (r.ok) {
|
|
911
|
-
|
|
1373
|
+
if (r.ok) {
|
|
1374
|
+
// The port and the bind address only apply on restart; saying "saved"
|
|
1375
|
+
// alone would imply the change is already in force.
|
|
1376
|
+
this.settings.msg = r.data.needsRestart
|
|
1377
|
+
? 'Settings saved ✓ — restart the dashboard for the port and bind address to take effect'
|
|
1378
|
+
: 'Settings saved ✓';
|
|
1379
|
+
this.settings.password = '';
|
|
1380
|
+
await this.loadSettings();
|
|
1381
|
+
} else { this.settings.error = r.data.error || 'Save failed'; }
|
|
912
1382
|
},
|
|
913
1383
|
|
|
914
1384
|
openAddChannel() {
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The only public router.
|
|
3
|
+
*
|
|
4
|
+
* Everything here exists so a client can obtain a session in the first place,
|
|
5
|
+
* so it cannot sit behind requireAuth. Each endpoint carries its own guard
|
|
6
|
+
* instead: login is rate limited and refuses an unset password, and setup is
|
|
7
|
+
* refused once a password exists.
|
|
8
|
+
*/
|
|
1
9
|
import { Router } from 'express';
|
|
2
|
-
import rateLimit from 'express-rate-limit';
|
|
3
10
|
import AuthController from '../controllers/authController.js';
|
|
4
11
|
|
|
5
12
|
const router = Router();
|
|
6
13
|
const controller = new AuthController();
|
|
7
14
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
max: 10,
|
|
11
|
-
standardHeaders: true,
|
|
12
|
-
legacyHeaders: false,
|
|
13
|
-
message: { ok: false, error: 'Too many login attempts. Try again in 15 minutes.' },
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
router.post('/login', loginLimiter, (req, res, next) => controller.login(req, res, next));
|
|
15
|
+
router.post('/login', (req, res, next) => controller.login(req, res, next));
|
|
16
|
+
router.post('/setup', (req, res, next) => controller.setup(req, res, next));
|
|
17
17
|
router.get('/auth', (req, res, next) => controller.check(req, res, next));
|
|
18
18
|
router.post('/logout', (req, res, next) => controller.logout(req, res, next));
|
|
19
19
|
|