easy-devops 1.2.0 → 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 +17 -5
- 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 +93 -2
- 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/channels/discord.js +77 -0
- package/src/core/channels/telegram.js +120 -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 +44 -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 +364 -0
- package/src/core/domains-db.js +234 -0
- package/src/core/events.js +222 -0
- 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 +103 -0
- 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 +128 -13
- 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 +316 -0
- package/src/dashboard/controllers/deploymentsController.js +479 -0
- package/src/dashboard/controllers/domainsController.js +403 -0
- package/src/dashboard/controllers/hubController.js +135 -0
- package/src/dashboard/controllers/nginxController.js +146 -0
- package/src/dashboard/controllers/processesController.js +368 -0
- package/src/dashboard/controllers/settingsController.js +503 -0
- package/src/dashboard/controllers/sslController.js +452 -0
- 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/img/icon.png +0 -0
- package/src/dashboard/public/img/icon_b.png +0 -0
- package/src/dashboard/public/js/app.js +595 -19
- package/src/dashboard/routes/auth.js +14 -33
- package/src/dashboard/routes/deployments.js +46 -0
- package/src/dashboard/routes/domains.js +20 -363
- package/src/dashboard/routes/hub.js +22 -0
- package/src/dashboard/routes/nginx.js +22 -146
- package/src/dashboard/routes/processes.js +29 -0
- package/src/dashboard/routes/settings.js +25 -232
- package/src/dashboard/routes/ssl.js +18 -276
- package/src/dashboard/server.js +279 -165
- package/src/dashboard/socketManager.js +246 -0
- package/src/dashboard/views/index.ejs +1 -0
- package/src/dashboard/views/partials/domain-form.ejs +64 -1
- package/src/dashboard/views/partials/login.ejs +69 -8
- package/src/dashboard/views/partials/processes-panel.ejs +261 -0
- package/src/dashboard/views/partials/settings-panel.ejs +549 -118
- package/src/dashboard/views/partials/sidebar.ejs +3 -1
- package/src/dashboard/lib/domains-db.js +0 -51
- /package/src/{dashboard/routes → core/channels}/.gitkeep +0 -0
|
@@ -37,6 +37,11 @@ const DEFAULT_FORM = {
|
|
|
37
37
|
accessLog: true,
|
|
38
38
|
customLocations: '',
|
|
39
39
|
},
|
|
40
|
+
notifications: {
|
|
41
|
+
domain_health: { enabled: true, channelIds: [] },
|
|
42
|
+
cert_expiry: { enabled: true, channelIds: [] },
|
|
43
|
+
nginx_down: { enabled: true, channelIds: [] },
|
|
44
|
+
},
|
|
40
45
|
};
|
|
41
46
|
|
|
42
47
|
createApp({
|
|
@@ -48,17 +53,38 @@ createApp({
|
|
|
48
53
|
authenticated: false,
|
|
49
54
|
page: 'overview',
|
|
50
55
|
|
|
51
|
-
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
|
+
},
|
|
52
66
|
|
|
53
67
|
navItems: [
|
|
54
68
|
{ id: 'overview', label: 'Overview', icon: '⚡' },
|
|
55
69
|
{ id: 'nginx', label: 'Nginx', icon: '🌐' },
|
|
56
70
|
{ id: 'ssl', label: 'SSL Certs', icon: '🔒' },
|
|
57
71
|
{ id: 'domains', label: 'Domains', icon: '🔗' },
|
|
72
|
+
{ id: 'processes', label: 'Processes', icon: '🧩' },
|
|
58
73
|
{ id: 'logs', label: 'Logs', icon: '📋' },
|
|
59
74
|
{ id: 'settings', label: 'Settings', icon: '⚙️' },
|
|
60
75
|
],
|
|
61
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
|
+
|
|
62
88
|
nginx: {
|
|
63
89
|
status: null, loading: false,
|
|
64
90
|
actionMsg: '', actionError: '',
|
|
@@ -104,6 +130,7 @@ createApp({
|
|
|
104
130
|
performance: false,
|
|
105
131
|
security: false,
|
|
106
132
|
advanced: false,
|
|
133
|
+
notifications: false,
|
|
107
134
|
},
|
|
108
135
|
|
|
109
136
|
logs: {
|
|
@@ -117,6 +144,23 @@ createApp({
|
|
|
117
144
|
dashboardPort: '', nginxDir: '', sslDir: '', acmeEmail: '',
|
|
118
145
|
password: '', loading: false, msg: '', error: '',
|
|
119
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,
|
|
120
164
|
},
|
|
121
165
|
|
|
122
166
|
permissions: {
|
|
@@ -127,6 +171,20 @@ createApp({
|
|
|
127
171
|
restoring: false, msg: '', error: '',
|
|
128
172
|
},
|
|
129
173
|
|
|
174
|
+
channels: {
|
|
175
|
+
list: [],
|
|
176
|
+
loading: false,
|
|
177
|
+
testingId: null,
|
|
178
|
+
testResults: {},
|
|
179
|
+
},
|
|
180
|
+
channelModal: {
|
|
181
|
+
open: false,
|
|
182
|
+
editing: null, // null = add new, string = channel id being edited
|
|
183
|
+
form: { name: '', type: 'discord', webhookUrl: '', botToken: '', chatId: '', message: '' },
|
|
184
|
+
saving: false,
|
|
185
|
+
error: '',
|
|
186
|
+
},
|
|
187
|
+
|
|
130
188
|
notifications: {
|
|
131
189
|
items: [], // { id, type, severity, message, domain?, timestamp }
|
|
132
190
|
panelOpen: false,
|
|
@@ -216,18 +274,26 @@ createApp({
|
|
|
216
274
|
document.documentElement.classList.toggle('dark', this.theme === 'dark');
|
|
217
275
|
document.documentElement.setAttribute('data-accent', this.accent);
|
|
218
276
|
|
|
219
|
-
// Check if already authenticated
|
|
277
|
+
// Check if already authenticated, and whether this is a first run.
|
|
220
278
|
try {
|
|
221
279
|
const r = await fetch('/api/auth');
|
|
222
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;
|
|
223
285
|
if (d.authenticated) { this.authenticated = true; this.loadPage('overview'); }
|
|
224
286
|
} catch { /* server may not be up yet */ }
|
|
225
287
|
|
|
226
|
-
//
|
|
227
|
-
await this.loadSettings();
|
|
288
|
+
// Settings are behind the session now, so only load them once signed in.
|
|
289
|
+
if (this.authenticated) await this.loadSettings();
|
|
228
290
|
|
|
229
291
|
// Real-time nginx status via Socket.io
|
|
230
|
-
|
|
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' } });
|
|
231
297
|
socket.on('nginx:status', (status) => {
|
|
232
298
|
this.nginx.status = status;
|
|
233
299
|
});
|
|
@@ -239,6 +305,22 @@ createApp({
|
|
|
239
305
|
for (const r of results) map[r.name] = r.up;
|
|
240
306
|
this.domainHealth = map;
|
|
241
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
|
+
|
|
242
324
|
socket.on('logs:line', ({ line, logFile }) => {
|
|
243
325
|
if (!this.logs.paused && logFile === this.logs.activeLog) {
|
|
244
326
|
this.logs.lines.push(line);
|
|
@@ -251,13 +333,41 @@ createApp({
|
|
|
251
333
|
methods: {
|
|
252
334
|
// ── Core API helper ────────────────────────────────────────────────────────
|
|
253
335
|
async api(method, path, body) {
|
|
254
|
-
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
|
+
};
|
|
255
348
|
if (body !== undefined) opts.body = JSON.stringify(body);
|
|
256
349
|
const r = await fetch(path, opts);
|
|
257
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
|
+
|
|
258
359
|
return { ok: r.ok, status: r.status, data };
|
|
259
360
|
},
|
|
260
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
|
+
|
|
261
371
|
// ── Theme ─────────────────────────────────────────────────────────────────
|
|
262
372
|
toggleTheme() { this.theme = this.theme === 'dark' ? 'light' : 'dark'; },
|
|
263
373
|
setAccent(color) { this.accent = color; },
|
|
@@ -267,13 +377,83 @@ createApp({
|
|
|
267
377
|
this.login.loading = true; this.login.error = '';
|
|
268
378
|
const r = await this.api('POST', '/api/login', { password: this.login.password });
|
|
269
379
|
this.login.loading = false;
|
|
270
|
-
|
|
271
|
-
|
|
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';
|
|
272
449
|
},
|
|
273
450
|
|
|
274
451
|
async doLogout() {
|
|
275
452
|
await this.api('POST', '/api/logout');
|
|
276
453
|
this.authenticated = false;
|
|
454
|
+
this.login.password = '';
|
|
455
|
+
this.login.confirm = '';
|
|
456
|
+
this.login.error = '';
|
|
277
457
|
},
|
|
278
458
|
|
|
279
459
|
// ── Navigation (T021: Nav click guard) ────────────────────────────────────
|
|
@@ -296,6 +476,9 @@ createApp({
|
|
|
296
476
|
|
|
297
477
|
async loadPage(p) {
|
|
298
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();
|
|
299
482
|
this.page = p;
|
|
300
483
|
if (p === 'overview') {
|
|
301
484
|
await Promise.all([this.loadNginxStatus(), this.loadSSL(), this.loadDomains()]);
|
|
@@ -304,7 +487,8 @@ createApp({
|
|
|
304
487
|
} else if (p === 'ssl') { await this.loadSSL(); }
|
|
305
488
|
else if (p === 'domains') { await this.loadDomains(); }
|
|
306
489
|
else if (p === 'logs') { this.subscribeToLogs(this.logs.activeLog); }
|
|
307
|
-
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()]); }
|
|
308
492
|
},
|
|
309
493
|
|
|
310
494
|
// ── Collapsible Sections ────────────────────────────────────────────
|
|
@@ -312,6 +496,133 @@ createApp({
|
|
|
312
496
|
this.sections[sectionId] = !this.sections[sectionId];
|
|
313
497
|
},
|
|
314
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
|
+
|
|
315
626
|
// ── Nginx ─────────────────────────────────────────────────────────────────
|
|
316
627
|
async loadNginxStatus() {
|
|
317
628
|
this.nginx.loading = true;
|
|
@@ -482,7 +793,9 @@ createApp({
|
|
|
482
793
|
if (!isConfirmed) return;
|
|
483
794
|
}
|
|
484
795
|
this.domains.showForm = !this.domains.showForm;
|
|
485
|
-
if (
|
|
796
|
+
if (this.domains.showForm) {
|
|
797
|
+
await this.loadChannels();
|
|
798
|
+
} else {
|
|
486
799
|
this.resetDomainForm();
|
|
487
800
|
}
|
|
488
801
|
},
|
|
@@ -504,6 +817,7 @@ createApp({
|
|
|
504
817
|
performance: false,
|
|
505
818
|
security: false,
|
|
506
819
|
advanced: false,
|
|
820
|
+
notifications: false,
|
|
507
821
|
};
|
|
508
822
|
},
|
|
509
823
|
|
|
@@ -521,6 +835,9 @@ createApp({
|
|
|
521
835
|
if (!isConfirmed) return;
|
|
522
836
|
}
|
|
523
837
|
|
|
838
|
+
// Ensure channels are loaded for the notifications section
|
|
839
|
+
await this.loadChannels();
|
|
840
|
+
|
|
524
841
|
// Fetch domain data
|
|
525
842
|
const r = await this.api('GET', `/api/domains`);
|
|
526
843
|
if (!r.ok) {
|
|
@@ -570,6 +887,11 @@ createApp({
|
|
|
570
887
|
accessLog: domain.advanced?.accessLog ?? true,
|
|
571
888
|
customLocations: domain.advanced?.customLocations || '',
|
|
572
889
|
},
|
|
890
|
+
notifications: {
|
|
891
|
+
domain_health: domain.notifications?.domain_health ?? { enabled: true, channelIds: [] },
|
|
892
|
+
cert_expiry: domain.notifications?.cert_expiry ?? { enabled: true, channelIds: [] },
|
|
893
|
+
nginx_down: domain.notifications?.nginx_down ?? { enabled: true, channelIds: [] },
|
|
894
|
+
},
|
|
573
895
|
};
|
|
574
896
|
|
|
575
897
|
this.domains.editingName = name;
|
|
@@ -583,6 +905,7 @@ createApp({
|
|
|
583
905
|
performance: true,
|
|
584
906
|
security: true,
|
|
585
907
|
advanced: true,
|
|
908
|
+
notifications: true,
|
|
586
909
|
};
|
|
587
910
|
},
|
|
588
911
|
|
|
@@ -731,13 +1054,17 @@ createApp({
|
|
|
731
1054
|
const domain = this.domains.form.name;
|
|
732
1055
|
if (domain) {
|
|
733
1056
|
const platform = this.settings.platform;
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
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`;
|
|
741
1068
|
}
|
|
742
1069
|
}
|
|
743
1070
|
}
|
|
@@ -754,6 +1081,11 @@ createApp({
|
|
|
754
1081
|
this.settings.sslDir = r.data.sslDir;
|
|
755
1082
|
this.settings.acmeEmail = r.data.acmeEmail || '';
|
|
756
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;
|
|
757
1089
|
}
|
|
758
1090
|
},
|
|
759
1091
|
|
|
@@ -763,6 +1095,173 @@ createApp({
|
|
|
763
1095
|
if (r.ok) this.permissions.configured = r.data.configured;
|
|
764
1096
|
},
|
|
765
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
|
+
|
|
1258
|
+
async loadChannels() {
|
|
1259
|
+
this.channels.loading = true;
|
|
1260
|
+
const r = await this.api('GET', '/api/settings/channels');
|
|
1261
|
+
this.channels.loading = false;
|
|
1262
|
+
if (r.ok) this.channels.list = Array.isArray(r.data) ? r.data : [];
|
|
1263
|
+
},
|
|
1264
|
+
|
|
766
1265
|
async setupPermissions() {
|
|
767
1266
|
this.permissions.loading = true; this.permissions.msg = ''; this.permissions.error = '';
|
|
768
1267
|
const r = await this.api('POST', '/api/settings/permissions/setup', { password: this.permissions.password });
|
|
@@ -865,10 +1364,87 @@ createApp({
|
|
|
865
1364
|
acmeEmail: this.settings.acmeEmail,
|
|
866
1365
|
};
|
|
867
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;
|
|
868
1371
|
const r = await this.api('POST', '/api/settings', payload);
|
|
869
1372
|
this.settings.loading = false;
|
|
870
|
-
if (r.ok) {
|
|
871
|
-
|
|
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'; }
|
|
1382
|
+
},
|
|
1383
|
+
|
|
1384
|
+
openAddChannel() {
|
|
1385
|
+
this.channelModal.editing = null;
|
|
1386
|
+
this.channelModal.form = { name: '', type: 'discord', webhookUrl: '', botToken: '', chatId: '', message: '' };
|
|
1387
|
+
this.channelModal.error = '';
|
|
1388
|
+
this.channelModal.open = true;
|
|
1389
|
+
},
|
|
1390
|
+
|
|
1391
|
+
openEditChannel(channel) {
|
|
1392
|
+
this.channelModal.editing = channel.id;
|
|
1393
|
+
this.channelModal.form = {
|
|
1394
|
+
name: channel.name,
|
|
1395
|
+
type: channel.type,
|
|
1396
|
+
webhookUrl: channel.webhookUrl || '',
|
|
1397
|
+
botToken: channel.botToken || '',
|
|
1398
|
+
chatId: channel.chatId || '',
|
|
1399
|
+
message: channel.message || '',
|
|
1400
|
+
};
|
|
1401
|
+
this.channelModal.error = '';
|
|
1402
|
+
this.channelModal.open = true;
|
|
1403
|
+
},
|
|
1404
|
+
|
|
1405
|
+
async saveChannel() {
|
|
1406
|
+
this.channelModal.saving = true;
|
|
1407
|
+
this.channelModal.error = '';
|
|
1408
|
+
const { name, type, webhookUrl, botToken, chatId, message } = this.channelModal.form;
|
|
1409
|
+
const payload = { name, type, webhookUrl, botToken, chatId, message };
|
|
1410
|
+
const r = this.channelModal.editing
|
|
1411
|
+
? await this.api('PUT', `/api/settings/channels/${this.channelModal.editing}`, payload)
|
|
1412
|
+
: await this.api('POST', '/api/settings/channels', payload);
|
|
1413
|
+
this.channelModal.saving = false;
|
|
1414
|
+
if (r.ok) {
|
|
1415
|
+
this.channelModal.open = false;
|
|
1416
|
+
await this.loadChannels();
|
|
1417
|
+
} else {
|
|
1418
|
+
this.channelModal.error = r.data.error || 'Save failed';
|
|
1419
|
+
}
|
|
1420
|
+
},
|
|
1421
|
+
|
|
1422
|
+
async deleteChannel(id) {
|
|
1423
|
+
const { isConfirmed } = await Swal.fire({
|
|
1424
|
+
title: 'Delete channel?',
|
|
1425
|
+
text: 'This cannot be undone.',
|
|
1426
|
+
icon: 'warning',
|
|
1427
|
+
showCancelButton: true,
|
|
1428
|
+
confirmButtonText: 'Delete',
|
|
1429
|
+
cancelButtonText: 'Cancel',
|
|
1430
|
+
...this.swalTheme,
|
|
1431
|
+
});
|
|
1432
|
+
if (!isConfirmed) return;
|
|
1433
|
+
await this.api('DELETE', `/api/settings/channels/${id}`);
|
|
1434
|
+
await this.loadChannels();
|
|
1435
|
+
},
|
|
1436
|
+
|
|
1437
|
+
async testChannelById(id) {
|
|
1438
|
+
this.channels.testingId = id;
|
|
1439
|
+
this.channels.testResults = { ...this.channels.testResults, [id]: { msg: '', error: '' } };
|
|
1440
|
+
const r = await this.api('POST', `/api/settings/channels/${id}/test`);
|
|
1441
|
+
this.channels.testingId = null;
|
|
1442
|
+
this.channels.testResults = {
|
|
1443
|
+
...this.channels.testResults,
|
|
1444
|
+
[id]: r.ok
|
|
1445
|
+
? { msg: 'Test sent ✓', error: '' }
|
|
1446
|
+
: { msg: '', error: r.data.error || 'Test failed' },
|
|
1447
|
+
};
|
|
872
1448
|
},
|
|
873
1449
|
},
|
|
874
1450
|
})
|