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.
Files changed (126) hide show
  1. package/README.md +97 -6
  2. package/dist/ui/assets/index-B6zdwEnG.css +1 -0
  3. package/dist/ui/assets/index-Cy0oNmul.js +442 -0
  4. package/dist/ui/assets/socket-DwLPrgsr.js +1 -0
  5. package/dist/ui/assets/socket-K5ttLD2q.js +65 -0
  6. package/dist/ui/brand/apple-touch-icon.png +0 -0
  7. package/dist/ui/brand/favicon-16.png +0 -0
  8. package/dist/ui/brand/favicon-32.png +0 -0
  9. package/dist/ui/brand/favicon-light-16.png +0 -0
  10. package/dist/ui/brand/favicon-light-32.png +0 -0
  11. package/dist/ui/brand/favicon.ico +0 -0
  12. package/dist/ui/brand/icon-192.png +0 -0
  13. package/dist/ui/brand/icon-48.png +0 -0
  14. package/dist/ui/brand/icon-512.png +0 -0
  15. package/dist/ui/brand/icon-64-light.png +0 -0
  16. package/dist/ui/brand/icon-64.png +0 -0
  17. package/dist/ui/brand/logo-dark.png +0 -0
  18. package/dist/ui/brand/logo-light.png +0 -0
  19. package/dist/ui/brand/mark-dark.png +0 -0
  20. package/dist/ui/brand/mark-light.png +0 -0
  21. package/dist/ui/index.html +71 -0
  22. package/install.ps1 +188 -1
  23. package/install.sh +254 -29
  24. package/package.json +15 -4
  25. package/src/cli/dash.js +110 -0
  26. package/src/cli/index.js +237 -106
  27. package/src/cli/managers/domain-manager.js +60 -40
  28. package/src/cli/managers/ssl-manager.js +47 -330
  29. package/src/cli/menu.js +156 -0
  30. package/src/cli/menus/cleanup.js +205 -0
  31. package/src/cli/menus/dashboard.js +92 -1
  32. package/src/cli/menus/runtime.js +236 -0
  33. package/src/cli/menus/service.js +764 -0
  34. package/src/cli/menus/settings.js +176 -8
  35. package/src/cli/menus/uninstall.js +167 -0
  36. package/src/cli/menus/update.js +221 -65
  37. package/src/core/acme-challenge.js +273 -0
  38. package/src/core/cert-operations.js +189 -0
  39. package/src/{dashboard/lib → core}/cert-reader.js +2 -2
  40. package/src/core/cert-renewal.js +494 -0
  41. package/src/core/cleanup.js +600 -0
  42. package/src/core/config.js +169 -2
  43. package/src/core/daemon/ipc.js +292 -0
  44. package/src/core/daemon/lock.js +294 -0
  45. package/src/core/daemon/run.js +241 -0
  46. package/src/core/daemon/stopRequest.js +162 -0
  47. package/src/core/db.js +37 -8
  48. package/src/core/deploy/apps.js +491 -0
  49. package/src/core/deploy/domainLink.js +200 -0
  50. package/src/core/deploy/engine.js +973 -0
  51. package/src/core/deploy/ezfile.js +361 -0
  52. package/src/core/deploy/github.js +239 -0
  53. package/src/core/deploy/githubApi.js +261 -0
  54. package/src/core/deploy/hookServer.js +325 -0
  55. package/src/core/deploy/hubCommands.js +267 -0
  56. package/src/core/deploy/launcher.js +57 -0
  57. package/src/core/deploy/status.js +91 -0
  58. package/src/core/deploy/store.js +398 -0
  59. package/src/core/domainNotifier.js +94 -28
  60. package/src/core/domains-db.js +234 -0
  61. package/src/core/events.js +94 -2
  62. package/src/core/hub/agent.js +842 -0
  63. package/src/core/hubLink.js +306 -0
  64. package/src/core/hubPermissions.js +430 -0
  65. package/src/core/installSource.js +162 -0
  66. package/src/core/jobs/bus.js +120 -0
  67. package/src/core/jobs/index.js +371 -0
  68. package/src/core/jobs/monitors.js +368 -0
  69. package/src/core/jobs/owner.js +217 -0
  70. package/src/core/jobs/revisionWatcher.js +106 -0
  71. package/src/core/nginx-apply.js +213 -0
  72. package/src/core/nginx-conf-generator.js +253 -17
  73. package/src/{dashboard/lib → core}/nginx-service.js +18 -9
  74. package/src/core/notifications/claim.js +214 -0
  75. package/src/core/notifications/dispatch.js +154 -0
  76. package/src/core/notifier.js +31 -1
  77. package/src/core/passwords.js +172 -0
  78. package/src/core/permissions.js +8 -4
  79. package/src/core/platform.js +709 -2
  80. package/src/core/probeCache.js +258 -0
  81. package/src/core/purge.js +372 -0
  82. package/src/core/runner.js +488 -0
  83. package/src/core/service/acl.js +226 -0
  84. package/src/core/service/dataDir.js +345 -0
  85. package/src/core/service/index.js +1128 -0
  86. package/src/core/service/legacy.js +218 -0
  87. package/src/core/service/runtime.js +446 -0
  88. package/src/core/service/runtimeUpdate.js +800 -0
  89. package/src/core/service/systemd.js +458 -0
  90. package/src/core/service/windowsPersonal.js +530 -0
  91. package/src/core/service/windowsService.js +576 -0
  92. package/src/core/service/winsw.js +260 -0
  93. package/src/core/setupCode.js +331 -0
  94. package/src/core/shell.js +70 -7
  95. package/src/core/ssl-issuer.js +627 -0
  96. package/src/core/updater.js +295 -0
  97. package/src/core/validators.js +99 -0
  98. package/src/dashboard/controllers/authController.js +302 -15
  99. package/src/dashboard/controllers/deploymentsController.js +479 -0
  100. package/src/dashboard/controllers/domainsController.js +39 -52
  101. package/src/dashboard/controllers/hubController.js +135 -0
  102. package/src/dashboard/controllers/nginxController.js +21 -3
  103. package/src/dashboard/controllers/processesController.js +368 -0
  104. package/src/dashboard/controllers/settingsController.js +180 -12
  105. package/src/dashboard/controllers/sslController.js +171 -10
  106. package/src/dashboard/lib/daemonBridge.js +163 -0
  107. package/src/dashboard/lib/localRequest.js +235 -0
  108. package/src/dashboard/lib/loginRateLimit.js +119 -0
  109. package/src/dashboard/lib/requireAuth.js +80 -0
  110. package/src/dashboard/public/js/app.js +489 -19
  111. package/src/dashboard/routes/auth.js +10 -10
  112. package/src/dashboard/routes/deployments.js +46 -0
  113. package/src/dashboard/routes/domains.js +9 -0
  114. package/src/dashboard/routes/hub.js +22 -0
  115. package/src/dashboard/routes/nginx.js +9 -0
  116. package/src/dashboard/routes/processes.js +29 -0
  117. package/src/dashboard/routes/settings.js +9 -0
  118. package/src/dashboard/routes/ssl.js +9 -0
  119. package/src/dashboard/server.js +288 -21
  120. package/src/dashboard/socketManager.js +171 -207
  121. package/src/dashboard/views/index.ejs +1 -0
  122. package/src/dashboard/views/partials/login.ejs +68 -7
  123. package/src/dashboard/views/partials/processes-panel.ejs +261 -0
  124. package/src/dashboard/views/partials/settings-panel.ejs +287 -0
  125. package/src/dashboard/views/partials/sidebar.ejs +2 -0
  126. package/src/dashboard/lib/domains-db.js +0 -51
@@ -0,0 +1,306 @@
1
+ /**
2
+ * core/hubLink.js
3
+ *
4
+ * Single source of truth for this server's link to an Easy DevOps Hub.
5
+ *
6
+ * Owns the whole lifecycle: parsing the `ezops://` connection string the hub
7
+ * issues, persisting / reading / clearing the link, the per-hub permission
8
+ * flags, and the classification of agent handshake failures.
9
+ *
10
+ * Consumers (dashboard controller, hub agent, and a future CLI menu) MUST go
11
+ * through this module rather than touching the database keys directly.
12
+ *
13
+ * Storage (via core/db.js only):
14
+ * 'hub-link' → { hubUrl, serverId, secret }
15
+ * 'hub-permissions' → { reloadNginx, manageDomains, manageSSL }
16
+ *
17
+ * The stored shapes are unchanged from the previous server-generated flow, so
18
+ * servers that were already linked keep working without re-pairing.
19
+ *
20
+ * The secret is a credential: it is persisted so the agent can authenticate,
21
+ * but it MUST NOT be logged or returned by any read API.
22
+ */
23
+
24
+ import { dbGet, dbSet, dbDelete } from './db.js';
25
+ import { validateConnectionString } from './validators.js';
26
+ import {
27
+ defaultPermissions,
28
+ normalizePermissions,
29
+ setPermission,
30
+ setGroup,
31
+ isLegacyPermissions,
32
+ migrateLegacyPermissions,
33
+ } from './hubPermissions.js';
34
+
35
+ const HUB_LINK_KEY = 'hub-link';
36
+ const HUB_PERMISSIONS_KEY = 'hub-permissions';
37
+ const HUB_REVISION_KEY = 'hub-revision';
38
+ const PREFIX = 'ezops://';
39
+
40
+ /**
41
+ * Permissions start fully denied — the hub cannot act until the user opts in.
42
+ * The shape comes from the catalog in core/hubPermissions.js.
43
+ */
44
+ export const DEFAULT_HUB_PERMISSIONS = defaultPermissions();
45
+
46
+ /**
47
+ * Agent statuses surfaced to the UI.
48
+ * not_linked — no connection string saved yet
49
+ * connecting — socket opened, handshake not completed
50
+ * connected — authenticated and streaming
51
+ * rejected — the hub refused our credentials; retrying cannot help
52
+ * unreachable — network/transport failure; retrying with backoff
53
+ */
54
+ export const HUB_AGENT_STATUS = {
55
+ NOT_LINKED: 'not_linked',
56
+ CONNECTING: 'connecting',
57
+ CONNECTED: 'connected',
58
+ REJECTED: 'rejected',
59
+ UNREACHABLE: 'unreachable',
60
+ };
61
+
62
+ /**
63
+ * Handshake rejection messages emitted by the hub's /agent-socket middleware.
64
+ * Anything not in this set is treated as a transport problem, so an unfamiliar
65
+ * error keeps retrying rather than silently giving up.
66
+ *
67
+ * Mirrors hub_backend/src/lib/agentServer.ts:
68
+ * AUTH_REQUIRED — we sent no serverId/secret
69
+ * UNKNOWN_SERVER — the hub has no such server (e.g. deleted from the hub)
70
+ * INVALID_SECRET — the secret does not match the stored hash
71
+ */
72
+ export const AGENT_REJECTION_ERRORS = Object.freeze([
73
+ 'AUTH_REQUIRED',
74
+ 'UNKNOWN_SERVER',
75
+ 'INVALID_SECRET',
76
+ ]);
77
+
78
+ /** Human-readable explanation per rejection reason. */
79
+ const REJECTION_MESSAGES = {
80
+ AUTH_REQUIRED: 'The hub rejected the handshake: no credentials were sent.',
81
+ UNKNOWN_SERVER:
82
+ 'The hub does not recognise this server. It may have been deleted from the hub — add it again and paste the new connection string.',
83
+ INVALID_SECRET:
84
+ 'The hub rejected this secret. If it was regenerated, paste the new connection string.',
85
+ };
86
+
87
+ /**
88
+ * True when a connection error means the hub refused our credentials.
89
+ * Such failures are permanent until the user pastes a new string, so the agent
90
+ * must stop retrying instead of looping.
91
+ * @param {string} message
92
+ * @returns {boolean}
93
+ */
94
+ export function isAuthRejection(message) {
95
+ if (!message || typeof message !== 'string') return false;
96
+ return AGENT_REJECTION_ERRORS.includes(message.trim());
97
+ }
98
+
99
+ /**
100
+ * Explain a rejection message for display.
101
+ * @param {string} message
102
+ * @returns {string}
103
+ */
104
+ export function describeRejection(message) {
105
+ const key = typeof message === 'string' ? message.trim() : '';
106
+ return REJECTION_MESSAGES[key] ?? 'The hub rejected this server’s credentials.';
107
+ }
108
+
109
+ /**
110
+ * Normalise a stored hub URL into an origin the Socket.io client can dial.
111
+ * Bare hosts default to https; existing schemes are preserved.
112
+ * @param {string} hubUrl
113
+ * @returns {string}
114
+ */
115
+ export function resolveHubOrigin(hubUrl) {
116
+ const raw = String(hubUrl ?? '').trim().replace(/\/+$/, '');
117
+ return /^https?:\/\//i.test(raw) ? raw : `https://${raw}`;
118
+ }
119
+
120
+ /**
121
+ * Parse and validate a connection string issued by the hub.
122
+ * Does not persist anything — pass the result to saveHubLink().
123
+ *
124
+ * @param {string} str
125
+ * @returns {{ ok: true, link: { hubUrl: string, serverId: string, secret: string } }
126
+ * | { ok: false, error: string }}
127
+ */
128
+ export function parseConnectionString(str) {
129
+ const error = validateConnectionString(str);
130
+ if (error) return { ok: false, error };
131
+
132
+ const [hubUrl, serverId, secret] = String(str)
133
+ .trim()
134
+ .slice(PREFIX.length)
135
+ .split('|')
136
+ .map((part) => part.trim());
137
+
138
+ return { ok: true, link: { hubUrl, serverId, secret } };
139
+ }
140
+
141
+ /**
142
+ * Read the saved hub link.
143
+ * @returns {{ hubUrl: string, serverId: string, secret: string }|null}
144
+ */
145
+ export function getHubLink() {
146
+ const link = dbGet(HUB_LINK_KEY);
147
+ if (!link || typeof link !== 'object') return null;
148
+ if (!link.hubUrl || !link.serverId || !link.secret) return null;
149
+ return { hubUrl: link.hubUrl, serverId: link.serverId, secret: link.secret };
150
+ }
151
+
152
+ /** @returns {boolean} True when a usable link is stored. */
153
+ export function isLinked() {
154
+ return getHubLink() !== null;
155
+ }
156
+
157
+ /**
158
+ * Persist a parsed link.
159
+ *
160
+ * Existing permissions are preserved on re-pairing: rotating a secret or
161
+ * re-pasting a string must not silently re-grant or revoke what the user
162
+ * already decided. Permissions are seeded fully-denied only on a first link.
163
+ *
164
+ * @param {{ hubUrl: string, serverId: string, secret: string }} link
165
+ * @returns {{ ok: true, link: object } | { ok: false, error: string }}
166
+ */
167
+ export function saveHubLink(link) {
168
+ if (!link || typeof link !== 'object') {
169
+ return { ok: false, error: 'Invalid hub link' };
170
+ }
171
+
172
+ const { hubUrl, serverId, secret } = link;
173
+ if (!hubUrl || !serverId || !secret) {
174
+ return { ok: false, error: 'Hub link requires hubUrl, serverId and secret' };
175
+ }
176
+
177
+ dbSet(HUB_LINK_KEY, { hubUrl, serverId, secret });
178
+
179
+ if (!dbGet(HUB_PERMISSIONS_KEY)) {
180
+ dbSet(HUB_PERMISSIONS_KEY, { ...DEFAULT_HUB_PERMISSIONS });
181
+ }
182
+
183
+ // Pairing is exactly the kind of change another process must learn about
184
+ // promptly, and it was the one change that did NOT bump the counter. The
185
+ // consequence was concrete: pairing from the dashboard while the daemon owns
186
+ // the jobs left the daemon unaware, so it never connected its agent, while
187
+ // the dashboard started one of its own — which is how two sockets with the
188
+ // same serverId ended up evicting each other.
189
+ bumpHubRevision();
190
+
191
+ return { ok: true, link: { hubUrl, serverId, secret } };
192
+ }
193
+
194
+ /**
195
+ * Parse, validate and persist in one step.
196
+ * @param {string} str
197
+ * @returns {{ ok: true, link: object } | { ok: false, error: string }}
198
+ */
199
+ export function saveConnectionString(str) {
200
+ const parsed = parseConnectionString(str);
201
+ if (!parsed.ok) return parsed;
202
+ return saveHubLink(parsed.link);
203
+ }
204
+
205
+ /**
206
+ * Remove the link and its permission flags.
207
+ *
208
+ * Bumps the revision for the same reason saveHubLink() does: another process
209
+ * may be holding an agent open against credentials that no longer exist.
210
+ */
211
+ export function clearHubLink() {
212
+ dbDelete(HUB_LINK_KEY);
213
+ dbDelete(HUB_PERMISSIONS_KEY);
214
+ bumpHubRevision();
215
+ }
216
+
217
+ /**
218
+ * Read the permission map, normalised against the catalog.
219
+ *
220
+ * Migrates the pre-tree {reloadNginx, manageDomains, manageSSL} shape on first
221
+ * read and persists the result, so the migration happens once and is
222
+ * idempotent — a second call sees catalog ids and skips it.
223
+ *
224
+ * @returns {Object<string, boolean>}
225
+ */
226
+ export function getHubPermissions() {
227
+ const stored = dbGet(HUB_PERMISSIONS_KEY);
228
+
229
+ if (isLegacyPermissions(stored)) {
230
+ const migrated = migrateLegacyPermissions(stored);
231
+ dbSet(HUB_PERMISSIONS_KEY, migrated);
232
+ bumpHubRevision();
233
+ return migrated;
234
+ }
235
+
236
+ return normalizePermissions(stored);
237
+ }
238
+
239
+ /**
240
+ * Apply permission changes.
241
+ *
242
+ * Accepts either individual leaf ids ({ 'nginx.stop': true }) or whole groups
243
+ * ({ groups: { nginx: true } }), which sets every grantable child. Unknown and
244
+ * comingSoon ids are ignored, so a malformed request cannot widen access.
245
+ *
246
+ * @param {Object} updates
247
+ * @returns {Object<string, boolean>} The persisted permissions
248
+ */
249
+ export function saveHubPermissions(updates) {
250
+ let next = getHubPermissions();
251
+
252
+ if (updates && typeof updates.groups === 'object' && updates.groups !== null) {
253
+ for (const [groupId, enabled] of Object.entries(updates.groups)) {
254
+ if (typeof enabled === 'boolean') next = setGroup(next, groupId, enabled);
255
+ }
256
+ }
257
+
258
+ for (const [id, enabled] of Object.entries(updates ?? {})) {
259
+ if (id === 'groups') continue;
260
+ if (typeof enabled === 'boolean') next = setPermission(next, id, enabled);
261
+ }
262
+
263
+ dbSet(HUB_PERMISSIONS_KEY, next);
264
+ bumpHubRevision();
265
+ return next;
266
+ }
267
+
268
+ // ─── Change revision ──────────────────────────────────────────────────────────
269
+ //
270
+ // The CLI and the dashboard are separate processes, so the agent (which lives
271
+ // in the dashboard) cannot be notified in-process when the CLI changes
272
+ // something. A counter in SQLite is the cheapest shared signal: the agent polls
273
+ // it every few seconds and pushes only when it actually moved.
274
+
275
+ /** @returns {number} Current revision. */
276
+ export function getHubRevision() {
277
+ const n = dbGet(HUB_REVISION_KEY);
278
+ return typeof n === 'number' ? n : 0;
279
+ }
280
+
281
+ /**
282
+ * Increment the revision. Call after any change the Hub should learn about
283
+ * promptly: domains, certificates, permissions.
284
+ * @returns {number} The new revision
285
+ */
286
+ export function bumpHubRevision() {
287
+ const next = getHubRevision() + 1;
288
+ dbSet(HUB_REVISION_KEY, next);
289
+ return next;
290
+ }
291
+
292
+ /**
293
+ * Non-secret view of the current link, for status APIs and UI.
294
+ * Deliberately omits the secret.
295
+ * @returns {{ linked: boolean, hubUrl: string|null, serverId: string|null,
296
+ * permissions: object }}
297
+ */
298
+ export function getLinkStatus() {
299
+ const link = getHubLink();
300
+ return {
301
+ linked: link !== null,
302
+ hubUrl: link?.hubUrl ?? null,
303
+ serverId: link?.serverId ?? null,
304
+ permissions: getHubPermissions(),
305
+ };
306
+ }