easy-devops 1.3.5 → 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 +73 -8
  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
@@ -0,0 +1,196 @@
1
+ /**
2
+ * core/ssl/progress.js
3
+ *
4
+ * Live progress for a certificate operation, in one small place so the
5
+ * dashboard, the CLI and the Hub all describe the same stages the same way.
6
+ *
7
+ * The payload is deliberately boring and secret-free:
8
+ *
9
+ * { opId, domain, stage, status: 'running'|'ok'|'failed'|'skipped',
10
+ * detail?, elapsedMs, at }
11
+ *
12
+ * Throttling is part of the contract: at most five events per opId per second.
13
+ * When the budget is spent the LAST event of each stage is kept and sent when
14
+ * the window reopens, so a stage's running -> ok/failed pair cannot be lost to
15
+ * the throttle. A listener that throws never breaks the issuance that is doing
16
+ * the real work.
17
+ */
18
+
19
+ import crypto from 'node:crypto';
20
+
21
+ export const OP_ID_PATTERN = /^[A-Za-z0-9_-]{8,64}$/;
22
+ export const PROGRESS_WINDOW_MS = 1000;
23
+ export const PROGRESS_MAX_PER_WINDOW = 5;
24
+ export const PROGRESS_DETAIL_MAX = 300;
25
+
26
+ /** True for a caller-supplied operation id that is safe to echo back. */
27
+ export function isValidOpId(value) {
28
+ return typeof value === 'string' && OP_ID_PATTERN.test(value);
29
+ }
30
+
31
+ /** A server-generated id, used when the client did not send one. */
32
+ export function newOpId() {
33
+ return `ssl_${crypto.randomBytes(16).toString('hex')}`;
34
+ }
35
+
36
+ /**
37
+ * Validates an optional client opId.
38
+ *
39
+ * @param {*} value
40
+ * @param {() => string} [generate]
41
+ * @returns {{ opId: string, error: string|null }}
42
+ */
43
+ export function resolveOpId(value, generate = newOpId) {
44
+ if (value === undefined || value === null || value === '') {
45
+ return { opId: generate(), error: null };
46
+ }
47
+ if (!isValidOpId(value)) {
48
+ return {
49
+ opId: null,
50
+ error: 'opId must be 8-64 characters of A-Z, a-z, 0-9, "_" or "-".',
51
+ };
52
+ }
53
+ return { opId: value, error: null };
54
+ }
55
+
56
+ /**
57
+ * Removes anything that must never leave the process in a progress detail.
58
+ * ACME errors are text from a remote server; a key block in one would be a
59
+ * surprise, and the cost of checking is trivial.
60
+ */
61
+ export function sanitizeDetail(value) {
62
+ if (typeof value !== 'string' || value === '') return '';
63
+ const redacted = value
64
+ .replace(/-----BEGIN [^-]*PRIVATE KEY-----[\s\S]*?(?:-----END [^-]*PRIVATE KEY-----|$)/g,
65
+ '[redacted private key]')
66
+ .replace(/-----BEGIN [^-]*-----[\s\S]*?-----END [^-]*-----/g, '[redacted]');
67
+ return redacted.length > PROGRESS_DETAIL_MAX
68
+ ? redacted.slice(0, PROGRESS_DETAIL_MAX)
69
+ : redacted;
70
+ }
71
+
72
+ /**
73
+ * Creates the per-operation reporter.
74
+ *
75
+ * @param {Object} [options]
76
+ * @param {string|null} [options.opId]
77
+ * @param {string|null} [options.domain]
78
+ * @param {(event: Object) => void} [options.onEvent] Full event payload
79
+ * @param {(stage: string, status: string, detail?: string) => void} [options.onProgress]
80
+ * The Hub/agent signature: step = stage.
81
+ * @param {() => number} [options.now] Injected clock (testing)
82
+ * @param {Function} [options.schedule] Injected setTimeout (testing)
83
+ * @param {Function} [options.cancel] Injected clearTimeout (testing)
84
+ * @returns {{
85
+ * opId: string|null, domain: string|null,
86
+ * report: (stage: string, status: string, detail?: string) => void,
87
+ * elapsedMs: () => number,
88
+ * flush: () => void,
89
+ * pendingCount: () => number,
90
+ * stop: () => void,
91
+ * }}
92
+ */
93
+ export function createSslProgress({
94
+ opId = null,
95
+ domain = null,
96
+ onEvent = null,
97
+ onProgress = null,
98
+ now = Date.now,
99
+ schedule = setTimeout,
100
+ cancel = clearTimeout,
101
+ windowMs = PROGRESS_WINDOW_MS,
102
+ maxPerWindow = PROGRESS_MAX_PER_WINDOW,
103
+ } = {}) {
104
+ const startedAt = now();
105
+ let windowStartedAt = startedAt;
106
+ let sentInWindow = 0;
107
+ let timer = null;
108
+ const deferred = new Map();
109
+
110
+ const safeEmit = (payload) => {
111
+ try { if (onEvent) onEvent(payload); } catch { /* never break the work */ }
112
+ try {
113
+ if (onProgress) onProgress(payload.stage, payload.status, payload.detail);
114
+ } catch { /* never break the work */ }
115
+ };
116
+
117
+ const arm = () => {
118
+ if (timer) return;
119
+ const wait = Math.max(1, windowStartedAt + windowMs - now());
120
+ try {
121
+ timer = schedule(() => {
122
+ timer = null;
123
+ flush();
124
+ }, wait);
125
+ if (timer && typeof timer.unref === 'function') timer.unref();
126
+ } catch { timer = null; }
127
+ };
128
+
129
+ const flush = () => {
130
+ try {
131
+ if (deferred.size === 0) return;
132
+ const t = now();
133
+ if (t - windowStartedAt >= windowMs) {
134
+ windowStartedAt = t;
135
+ sentInWindow = 0;
136
+ }
137
+ for (const [stage, payload] of [...deferred]) {
138
+ if (sentInWindow >= maxPerWindow) break;
139
+ deferred.delete(stage);
140
+ sentInWindow += 1;
141
+ safeEmit(payload);
142
+ }
143
+ if (deferred.size) arm();
144
+ } catch { /* never throw from a timer */ }
145
+ };
146
+
147
+ const report = (stage, status, detail) => {
148
+ try {
149
+ const statusName = String(status);
150
+ if (!['running', 'ok', 'failed', 'skipped'].includes(statusName)) return;
151
+
152
+ const elapsedMs = Math.max(0, now() - startedAt);
153
+ const payload = {
154
+ opId,
155
+ domain,
156
+ stage: String(stage),
157
+ status: statusName,
158
+ elapsedMs,
159
+ at: new Date().toISOString(),
160
+ };
161
+ const clean = sanitizeDetail(detail);
162
+ if (clean) payload.detail = clean;
163
+
164
+ const t = now();
165
+ if (t - windowStartedAt >= windowMs) {
166
+ windowStartedAt = t;
167
+ sentInWindow = 0;
168
+ }
169
+
170
+ if (sentInWindow < maxPerWindow) {
171
+ sentInWindow += 1;
172
+ safeEmit(payload);
173
+ return;
174
+ }
175
+
176
+ // Over the budget: remember only the newest event for this stage.
177
+ deferred.set(payload.stage, payload);
178
+ arm();
179
+ } catch { /* never throw */ }
180
+ };
181
+
182
+ return {
183
+ opId,
184
+ domain,
185
+ report,
186
+ elapsedMs: () => Math.max(0, now() - startedAt),
187
+ flush,
188
+ pendingCount: () => deferred.size,
189
+ stop() {
190
+ if (timer) {
191
+ try { cancel(timer); } catch { /* ignore */ }
192
+ timer = null;
193
+ }
194
+ },
195
+ };
196
+ }