easy-devops 1.3.6 → 1.4.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.
Files changed (69) hide show
  1. package/README.md +1 -0
  2. package/dist/ui/assets/index-Bu7af-Kj.css +1 -0
  3. package/dist/ui/assets/index-gndgYe3K.js +532 -0
  4. package/dist/ui/assets/socket-Bv0wCEgi.js +65 -0
  5. package/dist/ui/index.html +2 -2
  6. package/package.json +2 -2
  7. package/src/cli/index.js +8 -0
  8. package/src/cli/managers/domain-manager.js +37 -6
  9. package/src/cli/managers/nginx-manager.js +14 -5
  10. package/src/cli/managers/node-manager.js +19 -13
  11. package/src/cli/managers/ssl-manager.js +89 -26
  12. package/src/cli/menu.js +8 -2
  13. package/src/cli/menus/cleanup.js +4 -2
  14. package/src/cli/menus/dashboard.js +22 -15
  15. package/src/cli/menus/hub.js +381 -0
  16. package/src/cli/menus/runtime.js +12 -0
  17. package/src/cli/menus/service.js +28 -10
  18. package/src/cli/menus/settings.js +46 -12
  19. package/src/cli/menus/uninstall.js +13 -5
  20. package/src/cli/menus/update.js +24 -14
  21. package/src/cli/ui/page.js +123 -0
  22. package/src/core/cert-operations.js +34 -4
  23. package/src/core/cert-reader.js +67 -22
  24. package/src/core/cert-renewal.js +65 -9
  25. package/src/core/cert-suggest.js +120 -0
  26. package/src/core/cleanup.js +221 -1
  27. package/src/core/cloudflare-ips.js +161 -0
  28. package/src/core/daemon/ipc.js +1 -1
  29. package/src/core/daemon/lock.js +296 -9
  30. package/src/core/dashboardProcess.js +134 -6
  31. package/src/core/deploy/apps.js +36 -62
  32. package/src/core/deploy/deployKey.js +331 -0
  33. package/src/core/deploy/domainLink.js +280 -23
  34. package/src/core/deploy/engine.js +382 -63
  35. package/src/core/deploy/ezfile.js +496 -29
  36. package/src/core/deploy/githubApi.js +100 -13
  37. package/src/core/deploy/hubCommands.js +158 -18
  38. package/src/core/deploy/status.js +28 -1
  39. package/src/core/domains-db.js +1 -0
  40. package/src/core/hub/agent.js +238 -32
  41. package/src/core/hub/deployProgress.js +411 -0
  42. package/src/core/hubConnect.js +205 -0
  43. package/src/core/hubPermissions.js +48 -10
  44. package/src/core/jobs/bus.js +1 -1
  45. package/src/core/jobs/owner.js +268 -6
  46. package/src/core/nginx-conf-generator.js +124 -19
  47. package/src/core/notifications/claim.js +26 -3
  48. package/src/core/permissions.js +277 -59
  49. package/src/core/platform.js +48 -2
  50. package/src/core/runner.js +96 -40
  51. package/src/core/ssl/preflight.js +548 -0
  52. package/src/core/ssl/progress.js +196 -0
  53. package/src/core/ssl-issuer.js +502 -148
  54. package/src/core/validators.js +24 -0
  55. package/src/dashboard/controllers/authController.js +12 -5
  56. package/src/dashboard/controllers/deploymentsController.js +76 -11
  57. package/src/dashboard/controllers/domainsController.js +35 -1
  58. package/src/dashboard/controllers/hubController.js +4 -3
  59. package/src/dashboard/controllers/settingsController.js +73 -68
  60. package/src/dashboard/controllers/sslController.js +135 -15
  61. package/src/dashboard/public/js/app.js +42 -7
  62. package/src/dashboard/routes/deployments.js +2 -0
  63. package/src/dashboard/routes/domains.js +1 -0
  64. package/src/dashboard/server.js +42 -7
  65. package/src/dashboard/socketManager.js +19 -25
  66. package/src/dashboard/views/partials/settings-panel.ejs +29 -10
  67. package/dist/ui/assets/index-BUpPxWmp.css +0 -1
  68. package/dist/ui/assets/index-DD0JjK0Q.js +0 -475
  69. package/dist/ui/assets/socket-4tfdap-e.js +0 -65
@@ -9,6 +9,8 @@ import {
9
9
  autoRenewPlan,
10
10
  } from '../../core/cert-renewal.js';
11
11
  import { describeIssuance, prepareDomainForHttpChallenge } from '../../core/ssl-issuer.js';
12
+ import { resolveOpId } from '../../core/ssl/progress.js';
13
+ import { publish } from '../../core/jobs/bus.js';
12
14
  import { findDomain, getDomains } from '../../core/domains-db.js';
13
15
  import { loadConfig } from '../../core/config.js';
14
16
  import { isWindows } from '../../core/platform.js';
@@ -37,6 +39,35 @@ const dnsSweepTimer = setInterval(() => {
37
39
  }
38
40
  }, 60000);
39
41
 
42
+ /**
43
+ * Validates or generates the operation id for a request and wires the live
44
+ * `ssl:progress` event onto the bus. The socket manager forwards it; it is
45
+ * deliberately not cached, because a stage is a moment, not a state.
46
+ *
47
+ * @returns {{ opId: string, onEvent: Function } | { error: string }}
48
+ */
49
+ function progressForRequest(req) {
50
+ const { opId, error } = resolveOpId(req.body?.opId);
51
+ if (error) return { error };
52
+ return {
53
+ opId,
54
+ onEvent: (event) => publish('ssl:progress', event),
55
+ };
56
+ }
57
+
58
+ /**
59
+ * The per-check preflight results for an API body.
60
+ *
61
+ * `issueCertificate()` keeps them as `preflight.results`; clients render them
62
+ * as the PreflightResult list, so a failure body must carry the checks rather
63
+ * than only the one-line cause. A request that stopped before preflight ran
64
+ * (missing email, wildcard over HTTP) has no array and answers `null`.
65
+ */
66
+ export function preflightChecks(result) {
67
+ const checks = result?.preflight?.results;
68
+ return Array.isArray(checks) ? checks : null;
69
+ }
70
+
40
71
  /**
41
72
  * Stops the DNS-challenge sweep and rejects anything still pending.
42
73
  *
@@ -131,6 +162,10 @@ class SslController {
131
162
  }
132
163
 
133
164
  const domainKey = domain.trim();
165
+ const progress = progressForRequest(req);
166
+ if (progress.error) {
167
+ return res.status(400).json({ error: 'invalid_opId', detail: progress.error });
168
+ }
134
169
  const config = loadConfig();
135
170
  const acmeEmail = email || config.acmeEmail;
136
171
 
@@ -152,6 +187,7 @@ class SslController {
152
187
  responseSent = true;
153
188
  pendingDnsChallenges.set(domainKey, {
154
189
  domain: domainKey,
190
+ opId: progress.opId,
155
191
  txtName,
156
192
  txtValue,
157
193
  confirmDeferred: { resolve: confirmResolve, reject: confirmReject },
@@ -161,6 +197,7 @@ class SslController {
161
197
 
162
198
  res.status(202).json({
163
199
  status: 'waiting_dns',
200
+ opId: progress.opId,
164
201
  domain: domainKey,
165
202
  txtName,
166
203
  txtValue,
@@ -172,20 +209,38 @@ class SslController {
172
209
  };
173
210
 
174
211
  // Run issueCert in the background — it will call onDnsChallenge which sends 202 and pauses.
175
- issueCert(domainKey, { www: !!www, validationMethod: 'dns', email: acmeEmail, onDnsChallenge })
212
+ issueCert(domainKey, {
213
+ www: !!www,
214
+ validationMethod: 'dns',
215
+ email: acmeEmail,
216
+ onDnsChallenge,
217
+ opId: progress.opId,
218
+ onEvent: progress.onEvent,
219
+ })
176
220
  .then(result => {
177
221
  resultResolve(result);
178
222
  pendingDnsChallenges.delete(domainKey);
179
223
  if (!responseSent) {
180
224
  responseSent = true;
181
225
  if (result.success) {
182
- return res.json({ success: true, certPath: result.certPath, keyPath: result.keyPath });
226
+ return res.json({
227
+ success: true,
228
+ opId: progress.opId,
229
+ certPath: result.certPath,
230
+ keyPath: result.keyPath,
231
+ preflight: preflightChecks(result),
232
+ });
183
233
  }
184
234
  const { step } = result.error ?? {};
185
235
  if (step === 'email configuration') {
186
- return res.status(400).json({ error: 'email_required', hint: 'Configure acmeEmail in settings or provide email parameter.' });
236
+ return res.status(400).json({ error: 'email_required', opId: progress.opId, preflight: preflightChecks(result), hint: 'Configure acmeEmail in settings or provide email parameter.' });
187
237
  }
188
- return res.status(500).json({ success: false, error: result.error });
238
+ return res.status(500).json({
239
+ success: false,
240
+ opId: progress.opId,
241
+ error: result.error,
242
+ preflight: preflightChecks(result),
243
+ });
189
244
  }
190
245
  })
191
246
  .catch(err => {
@@ -205,7 +260,7 @@ class SslController {
205
260
  pendingDnsChallenges.delete(domainKey);
206
261
  if (!responseSent) {
207
262
  responseSent = true;
208
- return res.status(500).json({ success: false, error: errResult.error });
263
+ return res.status(500).json({ success: false, opId: progress.opId, error: errResult.error, preflight: null });
209
264
  }
210
265
  });
211
266
 
@@ -226,25 +281,35 @@ class SslController {
226
281
  if (!prepared.ok) {
227
282
  return res.status(500).json({
228
283
  error: 'challenge_setup_failed',
284
+ opId: progress.opId,
285
+ preflight: null,
229
286
  detail: prepared.error,
230
287
  hint: 'nginx could not be prepared to answer the ACME challenge. Check the nginx config and try again.',
231
288
  });
232
289
  }
233
290
  }
234
291
 
235
- const result = await issueCert(domainKey, { www: !!www, validationMethod: 'http', email: acmeEmail });
292
+ const result = await issueCert(domainKey, {
293
+ www: !!www,
294
+ validationMethod: 'http',
295
+ email: acmeEmail,
296
+ opId: progress.opId,
297
+ onEvent: progress.onEvent,
298
+ });
236
299
 
237
300
  if (result.success) {
238
301
  // Tell the UI how the challenge ran: proxy (nginx stayed up), or a
239
302
  // standalone fallback with how long nginx was stopped.
240
303
  return res.json({
241
304
  success: true,
305
+ opId: progress.opId,
242
306
  certPath: result.certPath,
243
307
  keyPath: result.keyPath,
244
308
  mode: result.mode,
245
309
  fellBack: result.fellBack,
246
310
  nginxDownMs: result.nginxDownMs,
247
311
  staging: result.staging,
312
+ preflight: preflightChecks(result),
248
313
  summary: describeIssuance(result),
249
314
  });
250
315
  }
@@ -253,17 +318,26 @@ class SslController {
253
318
  if (step === 'email configuration') {
254
319
  return res.status(400).json({
255
320
  error: 'email_required',
321
+ opId: progress.opId,
322
+ preflight: preflightChecks(result),
256
323
  hint: 'Configure acmeEmail in settings or provide email parameter.',
257
324
  });
258
325
  }
259
326
  if (step === 'port 80 check') {
260
327
  return res.status(409).json({
261
328
  error: 'port_busy',
329
+ opId: progress.opId,
330
+ preflight: preflightChecks(result),
262
331
  detail: result.error.cause,
263
332
  hint: 'Stop the process using port 80 and try again.',
264
333
  });
265
334
  }
266
- return res.status(500).json({ success: false, error: result.error });
335
+ return res.status(500).json({
336
+ success: false,
337
+ opId: progress.opId,
338
+ error: result.error,
339
+ preflight: preflightChecks(result),
340
+ });
267
341
  } catch (error) {
268
342
  next(error);
269
343
  }
@@ -314,16 +388,23 @@ class SslController {
314
388
  // standalone fallback with how long nginx was stopped.
315
389
  return res.json({
316
390
  success: true,
391
+ opId: state.opId ?? null,
317
392
  certPath: result.certPath,
318
393
  keyPath: result.keyPath,
319
394
  mode: result.mode,
320
395
  fellBack: result.fellBack,
321
396
  nginxDownMs: result.nginxDownMs,
322
397
  staging: result.staging,
398
+ preflight: preflightChecks(result),
323
399
  summary: describeIssuance(result),
324
400
  });
325
401
  }
326
- return res.status(500).json({ success: false, error: result.error });
402
+ return res.status(500).json({
403
+ success: false,
404
+ opId: state.opId ?? null,
405
+ error: result.error,
406
+ preflight: preflightChecks(result),
407
+ });
327
408
  } catch (error) {
328
409
  next(error);
329
410
  }
@@ -354,7 +435,7 @@ class SslController {
354
435
 
355
436
  async list(req, res, next) {
356
437
  try {
357
- const certs = await listAllCerts();
438
+ const certs = await listAllCerts({ includeUnusable: true });
358
439
 
359
440
  // Additive: what the background job intends for each certificate, so the
360
441
  // UI can show "auto-renews" / "manual renewal" instead of leaving the
@@ -367,8 +448,10 @@ class SslController {
367
448
  const withPlan = await Promise.all(certs.map(async (cert) => {
368
449
  let plan = 'off';
369
450
  try {
370
- const info = await describeCertificate(cert.domain);
371
- plan = autoRenewPlan({ certDomain: cert.domain, info, settings, domains, sslDir: config.sslDir });
451
+ if (cert.status !== 'not_issued' && cert.status !== 'unreadable') {
452
+ const info = await describeCertificate(cert.domain);
453
+ plan = autoRenewPlan({ certDomain: cert.domain, info, settings, domains, sslDir: config.sslDir });
454
+ }
372
455
  } catch { /* unreadable certificate: report it as not handled */ }
373
456
 
374
457
  const last = state[cert.domain] ?? null;
@@ -438,10 +521,15 @@ class SslController {
438
521
  try {
439
522
  const domain = req.params.domain;
440
523
  const config = loadConfig();
524
+ const progress = progressForRequest(req);
525
+ if (progress.error) {
526
+ return res.status(400).json({ error: 'invalid_opId', detail: progress.error });
527
+ }
441
528
 
442
529
  if (!config.acmeEmail) {
443
530
  return res.status(400).json({
444
531
  error: 'email_required',
532
+ opId: progress.opId,
445
533
  hint: 'Configure acmeEmail in settings first.',
446
534
  });
447
535
  }
@@ -449,20 +537,25 @@ class SslController {
449
537
  const certs = await listAllCerts();
450
538
  const found = certs.find(cert => cert.domain === domain);
451
539
  if (!found) {
452
- return res.status(404).json({ error: `Domain '${domain}' not found` });
540
+ return res.status(404).json({ error: `Domain '${domain}' not found`, opId: progress.opId });
453
541
  }
454
542
 
455
543
  // renewCertificate() is the one renewal path (core/cert-renewal.js): it
456
544
  // regenerates a config that predates the ACME challenge location, keeps
457
545
  // the names the certificate already covers, and reloads nginx so the new
458
546
  // certificate is the one being served.
459
- const result = await renewCertificate(domain, { email: config.acmeEmail });
547
+ const result = await renewCertificate(domain, {
548
+ email: config.acmeEmail,
549
+ opId: progress.opId,
550
+ onEvent: progress.onEvent,
551
+ });
460
552
 
461
553
  if (result.success) {
462
554
  // Tell the UI how the challenge ran: proxy (nginx stayed up), or a
463
555
  // standalone fallback with how long nginx was stopped.
464
556
  return res.json({
465
557
  success: true,
558
+ opId: progress.opId,
466
559
  certPath: result.certPath,
467
560
  keyPath: result.keyPath,
468
561
  mode: result.mode,
@@ -470,6 +563,7 @@ class SslController {
470
563
  nginxDownMs: result.nginxDownMs,
471
564
  staging: result.staging,
472
565
  nginxReloaded: result.nginxReloaded,
566
+ preflight: preflightChecks(result),
473
567
  summary: describeRenewal(result),
474
568
  });
475
569
  }
@@ -477,6 +571,8 @@ class SslController {
477
571
  if (result.skipped === 'manual') {
478
572
  return res.status(409).json({
479
573
  error: 'manual_renewal_required',
574
+ opId: progress.opId,
575
+ preflight: preflightChecks(result),
480
576
  detail: result.error.cause,
481
577
  hint: 'Create the certificate again from the SSL page using the DNS method.',
482
578
  });
@@ -486,6 +582,8 @@ class SslController {
486
582
  if (step === 'challenge setup') {
487
583
  return res.status(500).json({
488
584
  error: 'challenge_setup_failed',
585
+ opId: progress.opId,
586
+ preflight: preflightChecks(result),
489
587
  detail: result.error.cause,
490
588
  hint: 'nginx could not be prepared to answer the ACME challenge.',
491
589
  });
@@ -493,11 +591,18 @@ class SslController {
493
591
  if (step === 'port 80 check') {
494
592
  return res.status(409).json({
495
593
  error: 'port_busy',
594
+ opId: progress.opId,
595
+ preflight: preflightChecks(result),
496
596
  detail: result.error.cause,
497
597
  hint: 'Stop the process using port 80 and try again.',
498
598
  });
499
599
  }
500
- return res.status(500).json({ success: false, error: result.error });
600
+ return res.status(500).json({
601
+ success: false,
602
+ opId: progress.opId,
603
+ error: result.error,
604
+ preflight: preflightChecks(result),
605
+ });
501
606
  } catch (error) {
502
607
  next(error);
503
608
  }
@@ -506,10 +611,15 @@ class SslController {
506
611
  async renewAll(req, res, next) {
507
612
  try {
508
613
  const config = loadConfig();
614
+ const progress = progressForRequest(req);
615
+ if (progress.error) {
616
+ return res.status(400).json({ error: 'invalid_opId', detail: progress.error });
617
+ }
509
618
 
510
619
  if (!config.acmeEmail) {
511
620
  return res.status(400).json({
512
621
  error: 'email_required',
622
+ opId: progress.opId,
513
623
  hint: 'Configure acmeEmail in settings first.',
514
624
  });
515
625
  }
@@ -519,16 +629,22 @@ class SslController {
519
629
  const results = [];
520
630
 
521
631
  for (const cert of expiring) {
522
- const result = await renewCertificate(cert.domain, { email: config.acmeEmail });
632
+ const result = await renewCertificate(cert.domain, {
633
+ email: config.acmeEmail,
634
+ opId: progress.opId,
635
+ onEvent: progress.onEvent,
636
+ });
523
637
 
524
638
  if (!result.success && result.error?.step === 'challenge setup') {
525
639
  results.push({
526
640
  domain: cert.domain,
641
+ opId: progress.opId,
527
642
  success: false,
528
643
  certPath: null,
529
644
  keyPath: null,
530
645
  error: 'challenge_setup_failed',
531
646
  detail: result.error.cause,
647
+ preflight: preflightChecks(result),
532
648
  });
533
649
  continue;
534
650
  }
@@ -536,17 +652,20 @@ class SslController {
536
652
  if (result.skipped === 'manual') {
537
653
  results.push({
538
654
  domain: cert.domain,
655
+ opId: progress.opId,
539
656
  success: false,
540
657
  certPath: null,
541
658
  keyPath: null,
542
659
  error: 'manual_renewal_required',
543
660
  detail: result.error.cause,
661
+ preflight: preflightChecks(result),
544
662
  });
545
663
  continue;
546
664
  }
547
665
 
548
666
  results.push({
549
667
  domain: cert.domain,
668
+ opId: progress.opId,
550
669
  success: result.success,
551
670
  certPath: result.certPath,
552
671
  keyPath: result.keyPath,
@@ -555,6 +674,7 @@ class SslController {
555
674
  nginxDownMs: result.nginxDownMs,
556
675
  configRegenerated: Boolean(result.configRegenerated),
557
676
  nginxReloaded: result.nginxReloaded,
677
+ preflight: preflightChecks(result),
558
678
  summary: describeRenewal(result),
559
679
  });
560
680
  }
@@ -164,7 +164,8 @@ createApp({
164
164
  },
165
165
 
166
166
  permissions: {
167
- configured: false, loading: false, password: '', msg: '', error: '',
167
+ configured: false, loading: false, checking: false,
168
+ commands: [], refusedDirs: [], msg: '', error: '',
168
169
  },
169
170
 
170
171
  backup: {
@@ -1092,7 +1093,7 @@ createApp({
1092
1093
  async loadPermissionsStatus() {
1093
1094
  if (this.settings.platform === 'win32') { this.permissions.configured = true; return; }
1094
1095
  const r = await this.api('GET', '/api/settings/permissions');
1095
- if (r.ok) this.permissions.configured = r.data.configured;
1096
+ if (r.ok) this.permissions.configured = r.data.configured === true;
1096
1097
  },
1097
1098
 
1098
1099
  // ── Hub ──────────────────────────────────────────────────────────────────────
@@ -1264,14 +1265,48 @@ createApp({
1264
1265
 
1265
1266
  async setupPermissions() {
1266
1267
  this.permissions.loading = true; this.permissions.msg = ''; this.permissions.error = '';
1267
- const r = await this.api('POST', '/api/settings/permissions/setup', { password: this.permissions.password });
1268
+ // The dashboard never receives a sudo password: the endpoint takes no
1269
+ // body and answers with the commands the operator runs themselves.
1270
+ const r = await this.api('POST', '/api/settings/permissions/setup');
1268
1271
  this.permissions.loading = false;
1269
- if (r.ok) {
1270
- this.permissions.configured = true;
1272
+ const d = r.data || {};
1273
+ this.permissions.commands = Array.isArray(d.commands) ? d.commands : [];
1274
+ this.permissions.refusedDirs = Array.isArray(d.refusedDirs) ? d.refusedDirs : [];
1275
+ if (typeof d.configured === 'boolean') this.permissions.configured = d.configured;
1276
+
1277
+ if (!r.ok) {
1278
+ this.permissions.error = d.error || 'Could not prepare the setup commands';
1279
+ } else if (this.permissions.configured) {
1271
1280
  this.permissions.msg = 'Permissions configured ✓';
1272
- this.permissions.password = '';
1281
+ } else if (this.permissions.commands.length) {
1282
+ this.permissions.msg = '';
1273
1283
  } else {
1274
- this.permissions.error = r.data?.error || 'Setup failed';
1284
+ this.permissions.error = 'No setup commands were returned';
1285
+ }
1286
+ },
1287
+
1288
+ async checkPermissionsAgain() {
1289
+ this.permissions.checking = true; this.permissions.msg = ''; this.permissions.error = '';
1290
+ const r = await this.api('GET', '/api/settings/permissions');
1291
+ this.permissions.checking = false;
1292
+ if (!r.ok) {
1293
+ this.permissions.error = r.data?.error || 'Could not read the permissions status';
1294
+ return;
1295
+ }
1296
+ this.permissions.configured = r.data.configured === true;
1297
+ this.permissions.msg = this.permissions.configured
1298
+ ? 'Permissions configured ✓'
1299
+ : 'Still not configured — run the commands above in a terminal on the server.';
1300
+ },
1301
+
1302
+ async copyPermissionCommands() {
1303
+ const text = this.permissions.commands.join('\n');
1304
+ if (!text) return;
1305
+ try {
1306
+ await navigator.clipboard.writeText(text);
1307
+ this.permissions.msg = 'Commands copied to the clipboard';
1308
+ } catch {
1309
+ this.permissions.error = 'Copy failed — select the commands and copy them manually.';
1275
1310
  }
1276
1311
  },
1277
1312
 
@@ -41,6 +41,8 @@ router.get('/:id/runs/:runId', (req, res, next) => controller.run(req, res, next
41
41
  router.post('/:id/hook-token', (req, res, next) => controller.hookToken(req, res, next));
42
42
  router.delete('/:id/hook-token', (req, res, next) => controller.revokeHookToken(req, res, next));
43
43
  router.post('/:id/deploy-key', (req, res, next) => controller.deployKey(req, res, next));
44
+ router.post('/:id/deploy-key/test', (req, res, next) => controller.deployKeyTest(req, res, next));
45
+ router.post('/:id/deploy-key/github', (req, res, next) => controller.deployKeyGithub(req, res, next));
44
46
  router.get('/:id/github', (req, res, next) => controller.github(req, res, next));
45
47
  router.post('/:id/github/apply', (req, res, next) => controller.githubApply(req, res, next));
46
48
 
@@ -19,6 +19,7 @@ router.put('/:name', (req, res, next) => controller.update(req, res, next));
19
19
  router.delete('/:name', (req, res, next) => controller.delete(req, res, next));
20
20
  router.put('/:name/toggle', (req, res, next) => controller.toggle(req, res, next));
21
21
  router.post('/:name/reload', (req, res, next) => controller.reload(req, res, next));
22
+ router.get('/:name/ssl-suggestion', (req, res, next) => controller.sslSuggestion(req, res, next));
22
23
  router.get('/:name/notifications', (req, res, next) => controller.getNotifications(req, res, next));
23
24
  router.put('/:name/notifications', (req, res, next) => controller.updateNotifications(req, res, next));
24
25
 
@@ -113,7 +113,7 @@ function currentBinding() {
113
113
  // override.
114
114
  //
115
115
  // This reverses the earlier default. It changed because the new UI is now the
116
- // one being developed against docs/api-contract.md, and leaving the old page
116
+ // one being developed against API-CONTRACT.md, and leaving the old page
117
117
  // as the default meant every new install started on the implementation that is
118
118
  // no longer maintained. The EJS files stay in the tree: an operator who hits a
119
119
  // regression in the new UI needs a working dashboard in the same minute, not
@@ -148,8 +148,13 @@ if (classicRequested) {
148
148
  );
149
149
  }
150
150
 
151
- // Static files - disable index serving so the classic EJS page handles root.
152
- // Kept in both modes: the React build reuses /img assets from here.
151
+ // Static files for the classic page (its Vue bundle, /img assets). Index
152
+ // serving is off in both modes so the route that serves root decides which UI
153
+ // answers. The React build reuses /img assets from here.
154
+ //
155
+ // No maxAge: the default is `public, max-age=0`, which makes a browser
156
+ // revalidate on every use. These files carry no content hash, so a long cache
157
+ // would keep serving an old bundle after an upgrade.
153
158
  app.use(express.static(path.join(__dirname, 'public'), { index: false }));
154
159
 
155
160
  /**
@@ -177,10 +182,39 @@ app.use('/api', processesRouter);
177
182
  app.use('/api/deployments', deploymentsRouter);
178
183
  app.use('/api', updateRouter);
179
184
 
185
+ /**
186
+ * True for a build asset whose NAME carries a content hash.
187
+ *
188
+ * Vite writes `assets/index-4f3a9c2b.js`, and the hash changes when the bytes
189
+ * do — which is the only thing that makes a one-year cache safe. Everything
190
+ * else in the build keeps its name across releases (a favicon copied into
191
+ * assets/, and index.html itself) and must be revalidated instead.
192
+ *
193
+ * @param {string} filePath Absolute path the static middleware is serving
194
+ * @returns {boolean}
195
+ */
196
+ function isHashedAsset(filePath) {
197
+ const rel = path.relative(uiDistDir, filePath);
198
+ if (!rel.startsWith(`assets${path.sep}`)) return false;
199
+ return /-[A-Za-z0-9_-]{8,}\.[A-Za-z0-9]+$/.test(path.basename(rel));
200
+ }
201
+
180
202
  if (servingNewUi) {
181
- // Hashed Vite assets are immutable; index.html is served with no-cache
182
- // below, so a rebuilt bundle is picked up on the next page load.
183
- app.use(express.static(uiDistDir, { index: false, maxAge: '1y', immutable: true }));
203
+ // Only hashed assets are immutable; every other file in the build (including
204
+ // index.html, requested directly) gets `no-cache`, so a rebuilt bundle is
205
+ // picked up on the next page load. The route below serves index.html for the
206
+ // SPA with the same policy.
207
+ app.use(express.static(uiDistDir, {
208
+ index: false,
209
+ setHeaders(res, filePath) {
210
+ res.setHeader(
211
+ 'Cache-Control',
212
+ isHashedAsset(filePath)
213
+ ? 'public, max-age=31536000, immutable'
214
+ : 'no-cache',
215
+ );
216
+ },
217
+ }));
184
218
 
185
219
  // Client-side routes such as /#/domains arrive here as GET / and are
186
220
  // handled by the static index. A real path (/domains/example.com) gets the
@@ -332,7 +366,8 @@ let shutdownPromise = null;
332
366
 
333
367
  /**
334
368
  * Releases everything this module started: the HTTP server, the Socket.io
335
- * polling intervals and log tails, the hub agent, and the SQLite handle.
369
+ * server and its log tails, the daemon bridge, the background jobs, and the
370
+ * SQLite handle.
336
371
  *
337
372
  * Idempotent — concurrent or repeated calls (a second Ctrl+C during shutdown)
338
373
  * return the same promise and never double-close.
@@ -6,14 +6,14 @@
6
6
  * It used to: nginx polling, domain health probes, certificate checks and the
7
7
  * notification decisions all lived here, driven by intervals that only ran
8
8
  * while a browser was connected. That is why none of it worked without an open
9
- * dashboard, and why it could not move into a service.
9
+ * dashboard.
10
10
  *
11
11
  * All of it now lives in core/jobs/, runs in whichever process owns the jobs,
12
12
  * and arrives here as events on core/jobs/bus.js — published either by the
13
13
  * monitors in this process, or by the daemon over IPC and republished onto the
14
14
  * bus by dashboard/lib/daemonBridge.js. This module's whole job is to forward
15
15
  * them to connected browsers unchanged, which is why the bus uses the names
16
- * and payloads from docs/api-contract.md.
16
+ * and payloads from API-CONTRACT.md.
17
17
  *
18
18
  * What is still genuinely socket work and stays here: the session and
19
19
  * local-request guards on the handshake, and the live log tails — a tail exists
@@ -27,13 +27,14 @@ import { socketRequireAuth } from './lib/requireAuth.js';
27
27
  import { socketRequireLocalRequest } from './lib/localRequest.js';
28
28
  import { loadConfig } from '../core/config.js';
29
29
  import { nginxLogPath } from '../core/platform.js';
30
- import { publish, subscribeAll } from '../core/jobs/bus.js';
30
+ import { subscribe, subscribeAll } from '../core/jobs/bus.js';
31
31
 
32
32
  let connectedClients = 0;
33
33
  const activeTails = new Map();
34
34
 
35
35
  let ioServer = null;
36
36
  let unsubscribeBus = null;
37
+ let unsubscribeSslProgress = null;
37
38
 
38
39
  /**
39
40
  * The most recent payload for each replayable event.
@@ -109,6 +110,15 @@ function initSocket(httpServer, sessionMiddleware, getBinding) {
109
110
  if (connectedClients > 0) io.emit(event, payload);
110
111
  });
111
112
 
113
+ // `ssl:progress` is a moment in one certificate operation, never state, so
114
+ // it is forwarded but deliberately not replayed. It is subscribed here
115
+ // rather than added to JOB_EVENTS until API-CONTRACT.md documents it: the
116
+ // contract check compares that list with the document, and the contract is
117
+ // updated in its own change.
118
+ unsubscribeSslProgress = subscribe('ssl:progress', (payload) => {
119
+ if (connectedClients > 0) io.emit('ssl:progress', payload);
120
+ });
121
+
112
122
  io.on('connection', (socket) => {
113
123
  connectedClients++;
114
124
 
@@ -185,27 +195,6 @@ function stopTail(socketId) {
185
195
  }
186
196
  }
187
197
 
188
- // ─── Outbound helper ──────────────────────────────────────────────────────────
189
-
190
- /**
191
- * Tells every open dashboard tab that a section changed, so the UI can refresh
192
- * just that part instead of reloading the page.
193
- *
194
- * Used when a change did NOT originate in this browser — most importantly when
195
- * the Hub applies a command through core/hub/agent.js, or when another process
196
- * moves the revision counter.
197
- *
198
- * It publishes to the job bus rather than emitting at the socket server
199
- * directly, so the same call works in the daemon, which has no socket server,
200
- * and still reaches browsers through IPC. Safe to call before initSocket().
201
- *
202
- * @param {'domains'|'ssl'|'nginx'|'settings'} section
203
- * @param {Object} [detail] Optional extra context for the client
204
- */
205
- function emitLocalChange(section, detail = {}) {
206
- publish('local:changed', { section, source: 'hub', at: Date.now(), ...detail });
207
- }
208
-
209
198
  /**
210
199
  * Stops everything initSocket() started: the bus subscription, every active
211
200
  * log tail (each is a spawned child process), and the Socket.io server itself.
@@ -222,6 +211,11 @@ async function stopSocket() {
222
211
  unsubscribeBus = null;
223
212
  }
224
213
 
214
+ if (unsubscribeSslProgress) {
215
+ unsubscribeSslProgress();
216
+ unsubscribeSslProgress = null;
217
+ }
218
+
225
219
  // Kill the tail/Get-Content children; stopTail() removes each map entry.
226
220
  for (const socketId of [...activeTails.keys()]) stopTail(socketId);
227
221
 
@@ -243,4 +237,4 @@ async function stopSocket() {
243
237
  });
244
238
  }
245
239
 
246
- export { initSocket, stopSocket, emitLocalChange };
240
+ export { initSocket, stopSocket };