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.
Files changed (132) 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 +17 -5
  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 +93 -2
  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/channels/discord.js +77 -0
  42. package/src/core/channels/telegram.js +120 -0
  43. package/src/core/cleanup.js +600 -0
  44. package/src/core/config.js +169 -2
  45. package/src/core/daemon/ipc.js +292 -0
  46. package/src/core/daemon/lock.js +294 -0
  47. package/src/core/daemon/run.js +241 -0
  48. package/src/core/daemon/stopRequest.js +162 -0
  49. package/src/core/db.js +44 -8
  50. package/src/core/deploy/apps.js +491 -0
  51. package/src/core/deploy/domainLink.js +200 -0
  52. package/src/core/deploy/engine.js +973 -0
  53. package/src/core/deploy/ezfile.js +361 -0
  54. package/src/core/deploy/github.js +239 -0
  55. package/src/core/deploy/githubApi.js +261 -0
  56. package/src/core/deploy/hookServer.js +325 -0
  57. package/src/core/deploy/hubCommands.js +267 -0
  58. package/src/core/deploy/launcher.js +57 -0
  59. package/src/core/deploy/status.js +91 -0
  60. package/src/core/deploy/store.js +398 -0
  61. package/src/core/domainNotifier.js +364 -0
  62. package/src/core/domains-db.js +234 -0
  63. package/src/core/events.js +222 -0
  64. package/src/core/hub/agent.js +842 -0
  65. package/src/core/hubLink.js +306 -0
  66. package/src/core/hubPermissions.js +430 -0
  67. package/src/core/installSource.js +162 -0
  68. package/src/core/jobs/bus.js +120 -0
  69. package/src/core/jobs/index.js +371 -0
  70. package/src/core/jobs/monitors.js +368 -0
  71. package/src/core/jobs/owner.js +217 -0
  72. package/src/core/jobs/revisionWatcher.js +106 -0
  73. package/src/core/nginx-apply.js +213 -0
  74. package/src/core/nginx-conf-generator.js +253 -17
  75. package/src/{dashboard/lib → core}/nginx-service.js +18 -9
  76. package/src/core/notifications/claim.js +214 -0
  77. package/src/core/notifications/dispatch.js +154 -0
  78. package/src/core/notifier.js +103 -0
  79. package/src/core/passwords.js +172 -0
  80. package/src/core/permissions.js +8 -4
  81. package/src/core/platform.js +709 -2
  82. package/src/core/probeCache.js +258 -0
  83. package/src/core/purge.js +372 -0
  84. package/src/core/runner.js +488 -0
  85. package/src/core/service/acl.js +226 -0
  86. package/src/core/service/dataDir.js +345 -0
  87. package/src/core/service/index.js +1128 -0
  88. package/src/core/service/legacy.js +218 -0
  89. package/src/core/service/runtime.js +446 -0
  90. package/src/core/service/runtimeUpdate.js +800 -0
  91. package/src/core/service/systemd.js +458 -0
  92. package/src/core/service/windowsPersonal.js +530 -0
  93. package/src/core/service/windowsService.js +576 -0
  94. package/src/core/service/winsw.js +260 -0
  95. package/src/core/setupCode.js +331 -0
  96. package/src/core/shell.js +128 -13
  97. package/src/core/ssl-issuer.js +627 -0
  98. package/src/core/updater.js +295 -0
  99. package/src/core/validators.js +99 -0
  100. package/src/dashboard/controllers/authController.js +316 -0
  101. package/src/dashboard/controllers/deploymentsController.js +479 -0
  102. package/src/dashboard/controllers/domainsController.js +403 -0
  103. package/src/dashboard/controllers/hubController.js +135 -0
  104. package/src/dashboard/controllers/nginxController.js +146 -0
  105. package/src/dashboard/controllers/processesController.js +368 -0
  106. package/src/dashboard/controllers/settingsController.js +503 -0
  107. package/src/dashboard/controllers/sslController.js +452 -0
  108. package/src/dashboard/lib/daemonBridge.js +163 -0
  109. package/src/dashboard/lib/localRequest.js +235 -0
  110. package/src/dashboard/lib/loginRateLimit.js +119 -0
  111. package/src/dashboard/lib/requireAuth.js +80 -0
  112. package/src/dashboard/public/img/icon.png +0 -0
  113. package/src/dashboard/public/img/icon_b.png +0 -0
  114. package/src/dashboard/public/js/app.js +595 -19
  115. package/src/dashboard/routes/auth.js +14 -33
  116. package/src/dashboard/routes/deployments.js +46 -0
  117. package/src/dashboard/routes/domains.js +20 -363
  118. package/src/dashboard/routes/hub.js +22 -0
  119. package/src/dashboard/routes/nginx.js +22 -146
  120. package/src/dashboard/routes/processes.js +29 -0
  121. package/src/dashboard/routes/settings.js +25 -232
  122. package/src/dashboard/routes/ssl.js +18 -276
  123. package/src/dashboard/server.js +279 -165
  124. package/src/dashboard/socketManager.js +246 -0
  125. package/src/dashboard/views/index.ejs +1 -0
  126. package/src/dashboard/views/partials/domain-form.ejs +64 -1
  127. package/src/dashboard/views/partials/login.ejs +69 -8
  128. package/src/dashboard/views/partials/processes-panel.ejs +261 -0
  129. package/src/dashboard/views/partials/settings-panel.ejs +549 -118
  130. package/src/dashboard/views/partials/sidebar.ejs +3 -1
  131. package/src/dashboard/lib/domains-db.js +0 -51
  132. /package/src/{dashboard/routes → core/channels}/.gitkeep +0 -0
@@ -0,0 +1,200 @@
1
+ /**
2
+ * core/deploy/domainLink.js
3
+ *
4
+ * Ties a deployed app to a domain: nginx proxies the domain to the port the
5
+ * app listens on, and the two stay in step.
6
+ *
7
+ * Nothing new is invented for nginx here. A link is an ordinary domain record,
8
+ * created or updated through handleHubDomainCommand() — the same path the
9
+ * dashboard, the CLI and the Hub use, with the same "test, and restore the
10
+ * previous config if nginx rejects it" guarantee. What this module adds is the
11
+ * bookkeeping: the app remembers its domain, and a deployment that changes the
12
+ * app's port moves the domain with it.
13
+ */
14
+
15
+ import fs from 'fs';
16
+ import path from 'path';
17
+
18
+ import { loadConfig } from '../config.js';
19
+ import { findDomain, handleHubDomainCommand } from '../domains-db.js';
20
+ import { validateDomainName } from '../validators.js';
21
+ import { issueCertificate, prepareDomainForHttpChallenge, reloadNginx, describeIssuance } from '../ssl-issuer.js';
22
+
23
+ import { getApp, setAppDomain } from './apps.js';
24
+ import { readState, releaseDir } from './store.js';
25
+
26
+ /**
27
+ * The port an app listens on: what is set on the app, else what its live
28
+ * release was started with (from ez.json or PORT).
29
+ *
30
+ * @returns {number|null}
31
+ */
32
+ export function appPort(app) {
33
+ const own = Number(app?.settings?.port);
34
+ if (Number.isInteger(own) && own > 0) return own;
35
+
36
+ try {
37
+ const current = readState(app.id).current;
38
+ if (!current) return null;
39
+ const meta = JSON.parse(fs.readFileSync(path.join(releaseDir(app.id, current), 'ez.release.json'), 'utf8'));
40
+ return Number.isInteger(meta.port) && meta.port > 0 ? meta.port : null;
41
+ } catch {
42
+ return null;
43
+ }
44
+ }
45
+
46
+ /**
47
+ * Links an app to a domain.
48
+ *
49
+ * `domain` may name an existing domain — it is re-pointed at the app — or a
50
+ * new one, which is created. With `ssl: true` a certificate is requested over
51
+ * HTTP-01 once the domain answers; if that fails the link still stands, over
52
+ * plain HTTP, and the answer says why.
53
+ *
54
+ * @param {string} appId
55
+ * @param {{ domain: string, ssl?: boolean }} input
56
+ * @param {Object} [deps] Injected collaborators (testing only)
57
+ * @returns {Promise<{ ok: boolean, status: number, error: string|null,
58
+ * domain?: string, created?: boolean, port?: number, ssl?: Object|null, nginxReloaded?: boolean }>}
59
+ */
60
+ export async function linkDomain(appId, { domain, ssl = false } = {}, deps = {}) {
61
+ const {
62
+ domainCommand = handleHubDomainCommand,
63
+ reload = reloadNginx,
64
+ issue = issueCertificate,
65
+ prepare = prepareDomainForHttpChallenge,
66
+ } = deps;
67
+
68
+ const app = getApp(appId);
69
+ if (!app) return { ok: false, status: 404, error: `No app named "${appId}".` };
70
+
71
+ const name = String(domain ?? '').trim().toLowerCase();
72
+ const nameError = validateDomainName(name);
73
+ if (nameError) return { ok: false, status: 400, error: nameError };
74
+
75
+ const port = appPort(app);
76
+ if (!port) {
77
+ return {
78
+ ok: false,
79
+ status: 409,
80
+ error: 'This app has no port yet. Set its port (or put "port" in ez.json and deploy once), then link the domain.',
81
+ };
82
+ }
83
+
84
+ const existing = findDomain(name);
85
+ const result = existing
86
+ ? await domainCommand({ action: 'update', name, domain: { port, backendHost: '127.0.0.1' } })
87
+ : await domainCommand({ action: 'create', domain: { name, port } });
88
+
89
+ if (!result?.ok) return { ok: false, status: 500, error: result?.error ?? 'nginx rejected the configuration.' };
90
+
91
+ setAppDomain(appId, name);
92
+
93
+ let reloaded = await reload();
94
+ let sslResult = null;
95
+
96
+ if (ssl && !findDomain(name)?.ssl?.enabled) {
97
+ sslResult = await requestCertificate(name, { domainCommand, issue, prepare });
98
+ if (sslResult.ok) reloaded = await reload();
99
+ }
100
+
101
+ return {
102
+ ok: true,
103
+ status: 200,
104
+ error: null,
105
+ domain: name,
106
+ created: !existing,
107
+ port,
108
+ ssl: sslResult,
109
+ nginxReloaded: Boolean(reloaded?.ok),
110
+ };
111
+ }
112
+
113
+ /** Requests a certificate for a freshly linked domain and switches the domain to HTTPS. */
114
+ async function requestCertificate(name, { domainCommand, issue, prepare }) {
115
+ const config = loadConfig();
116
+ if (!config.acmeEmail) {
117
+ return { ok: false, detail: 'No certificate was requested: set an ACME email in Settings first.' };
118
+ }
119
+
120
+ try {
121
+ const record = findDomain(name);
122
+ const prepared = await prepare(record);
123
+ if (!prepared.ok) return { ok: false, detail: `Could not prepare nginx for the challenge: ${prepared.error}` };
124
+
125
+ const issued = await issue(name, { validationMethod: 'http', email: config.acmeEmail });
126
+ if (!issued.success) {
127
+ const cause = String(issued.error?.cause ?? 'The certificate could not be issued.').split('\n')[0];
128
+ return { ok: false, detail: `${cause} The domain works over HTTP; issue the certificate from the SSL page once its DNS points here.` };
129
+ }
130
+
131
+ const updated = await domainCommand({
132
+ action: 'update',
133
+ name,
134
+ domain: { ssl: { enabled: true, certPath: issued.certPath, keyPath: issued.keyPath } },
135
+ });
136
+ if (!updated?.ok) {
137
+ return { ok: false, detail: `The certificate was issued, but nginx rejected the HTTPS config: ${updated?.error ?? 'unknown error'}` };
138
+ }
139
+ return { ok: true, detail: describeIssuance(issued) || 'Certificate issued.' };
140
+ } catch (err) {
141
+ return { ok: false, detail: `The certificate could not be issued: ${err.message}` };
142
+ }
143
+ }
144
+
145
+ /**
146
+ * Forgets the link. The domain itself is left exactly as it is — it may be
147
+ * serving traffic, and removing a domain is its own decision.
148
+ *
149
+ * @returns {{ ok: boolean, status: number, error: string|null }}
150
+ */
151
+ export function unlinkDomain(appId) {
152
+ const app = getApp(appId);
153
+ if (!app) return { ok: false, status: 404, error: `No app named "${appId}".` };
154
+ setAppDomain(appId, null);
155
+ return { ok: true, status: 200, error: null };
156
+ }
157
+
158
+ /**
159
+ * Deletes the domain an app is linked to. Used when an app is removed and the
160
+ * person removing it asked for the domain to go too.
161
+ *
162
+ * @returns {Promise<{ ok: boolean, error: string|null }>}
163
+ */
164
+ export async function deleteLinkedDomain(app, deps = {}) {
165
+ const { domainCommand = handleHubDomainCommand } = deps;
166
+ if (!app?.domain || !findDomain(app.domain)) return { ok: true, error: null };
167
+ const result = await domainCommand({ action: 'delete', name: app.domain });
168
+ return { ok: Boolean(result?.ok), error: result?.ok ? null : (result?.error ?? 'The domain could not be removed.') };
169
+ }
170
+
171
+ /**
172
+ * After a deployment: if the app's port changed, move the linked domain to it.
173
+ *
174
+ * Without this, changing `port` in ez.json and deploying would leave nginx
175
+ * proxying to a port nothing listens on any more — the app healthy, the site
176
+ * down. Never throws; a failure is returned as a warning for the run.
177
+ *
178
+ * @param {Object} app
179
+ * @param {number|null} port The port the release that just went live listens on
180
+ * @returns {Promise<string|null>} A line for the deployment log, or null when nothing changed
181
+ */
182
+ export async function syncLinkedDomain(app, port, deps = {}) {
183
+ const { domainCommand = handleHubDomainCommand, reload = reloadNginx } = deps;
184
+ try {
185
+ if (!app?.domain || !port) return null;
186
+ const record = findDomain(app.domain);
187
+ if (!record) return `warning: the linked domain ${app.domain} no longer exists.`;
188
+ if (Number(record.port) === Number(port) && (record.backendHost ?? '127.0.0.1') === '127.0.0.1') return null;
189
+
190
+ const result = await domainCommand({ action: 'update', name: app.domain, domain: { port, backendHost: '127.0.0.1' } });
191
+ if (!result?.ok) return `warning: ${app.domain} could not be pointed at port ${port}: ${result?.error ?? 'nginx rejected the config'}`;
192
+
193
+ const reloaded = await reload();
194
+ return reloaded?.ok
195
+ ? `${app.domain} now proxies to port ${port}.`
196
+ : `warning: ${app.domain} was pointed at port ${port}, but nginx was not reloaded.`;
197
+ } catch (err) {
198
+ return `warning: the linked domain could not be updated: ${err.message}`;
199
+ }
200
+ }