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.
- 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 +15 -4
- 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 +92 -1
- 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/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 +37 -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 +94 -28
- package/src/core/domains-db.js +234 -0
- package/src/core/events.js +94 -2
- 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 +31 -1
- 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 +70 -7
- 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 +302 -15
- package/src/dashboard/controllers/deploymentsController.js +479 -0
- package/src/dashboard/controllers/domainsController.js +39 -52
- package/src/dashboard/controllers/hubController.js +135 -0
- package/src/dashboard/controllers/nginxController.js +21 -3
- package/src/dashboard/controllers/processesController.js +368 -0
- package/src/dashboard/controllers/settingsController.js +180 -12
- package/src/dashboard/controllers/sslController.js +171 -10
- 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/js/app.js +489 -19
- package/src/dashboard/routes/auth.js +10 -10
- package/src/dashboard/routes/deployments.js +46 -0
- package/src/dashboard/routes/domains.js +9 -0
- package/src/dashboard/routes/hub.js +22 -0
- package/src/dashboard/routes/nginx.js +9 -0
- package/src/dashboard/routes/processes.js +29 -0
- package/src/dashboard/routes/settings.js +9 -0
- package/src/dashboard/routes/ssl.js +9 -0
- package/src/dashboard/server.js +288 -21
- package/src/dashboard/socketManager.js +171 -207
- package/src/dashboard/views/index.ejs +1 -0
- package/src/dashboard/views/partials/login.ejs +68 -7
- package/src/dashboard/views/partials/processes-panel.ejs +261 -0
- package/src/dashboard/views/partials/settings-panel.ejs +287 -0
- package/src/dashboard/views/partials/sidebar.ejs +2 -0
- package/src/dashboard/lib/domains-db.js +0 -51
|
@@ -2,23 +2,58 @@ import fs from 'fs/promises';
|
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import os from 'os';
|
|
4
4
|
import crypto from 'crypto';
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
loadConfig, saveConfig, BIND_ALL, BIND_LOOPBACK, BIND_LOOPBACK_V6,
|
|
7
|
+
AUTH_MODES, UI_MODES, isLoopbackBind, effectiveAuthMode,
|
|
8
|
+
} from '../../core/config.js';
|
|
9
|
+
import { isLoopbackAddress } from '../lib/localRequest.js';
|
|
10
|
+
import { hashPassword, validateNewPassword } from '../../core/passwords.js';
|
|
6
11
|
import { validatePort, validateEmail } from '../../core/validators.js';
|
|
12
|
+
import {
|
|
13
|
+
getAutoRenewSettings, normalizeAutoRenewDays, MIN_AUTO_RENEW_DAYS, MAX_AUTO_RENEW_DAYS,
|
|
14
|
+
} from '../../core/cert-renewal.js';
|
|
7
15
|
import { run, runWithStdin } from '../../core/shell.js';
|
|
8
16
|
import { checkPermissionsConfigured } from '../../core/permissions.js';
|
|
9
17
|
import { dbGet, dbSet } from '../../core/db.js';
|
|
18
|
+
import { deployRoot, defaultDeployRoot, validateDeployDir } from '../../core/deploy/store.js';
|
|
19
|
+
import { saveDomains } from '../../core/domains-db.js';
|
|
10
20
|
import { loadChannels, saveChannels, sendNotification } from '../../core/notifier.js';
|
|
11
21
|
|
|
12
22
|
class SettingsController {
|
|
13
23
|
get(req, res) {
|
|
14
24
|
try {
|
|
15
25
|
const config = loadConfig();
|
|
16
|
-
const { dashboardPort, nginxDir, sslDir, acmeEmail } = config;
|
|
26
|
+
const { dashboardPort, nginxDir, sslDir, acmeEmail, dashboardBindAddress } = config;
|
|
27
|
+
const hasPassword = Boolean(config.dashboardPasswordHash || config.dashboardPassword);
|
|
28
|
+
const autoRenew = getAutoRenewSettings(config);
|
|
29
|
+
// Neither the password nor its hash is ever returned.
|
|
17
30
|
res.json({
|
|
18
31
|
dashboardPort,
|
|
19
32
|
nginxDir,
|
|
20
33
|
sslDir,
|
|
21
34
|
acmeEmail,
|
|
35
|
+
// Background renewal of HTTP-01 certificates (core/cert-renewal.js).
|
|
36
|
+
// The limits are published so no client hard-codes them.
|
|
37
|
+
sslAutoRenew: autoRenew.enabled,
|
|
38
|
+
sslAutoRenewDays: autoRenew.days,
|
|
39
|
+
sslAutoRenewDaysMin: MIN_AUTO_RENEW_DAYS,
|
|
40
|
+
sslAutoRenewDaysMax: MAX_AUTO_RENEW_DAYS,
|
|
41
|
+
// Where NEW deployed apps are created. Existing apps stay where they
|
|
42
|
+
// were created; moving one is an action on the Deployments page.
|
|
43
|
+
deployDir: deployRoot(),
|
|
44
|
+
deployDirDefault: defaultDeployRoot(),
|
|
45
|
+
deployDirIsDefault: !config.deployDir,
|
|
46
|
+
dashboardBindAddress,
|
|
47
|
+
bindsToLoopbackOnly: isLoopbackBind(dashboardBindAddress),
|
|
48
|
+
dashboardAuth: effectiveAuthMode(config),
|
|
49
|
+
// Anything unrecognised reads as classic, which is also the
|
|
50
|
+
// default. The value only takes effect on restart.
|
|
51
|
+
dashboardUi: config.dashboardUi === UI_MODES.NEW ? UI_MODES.NEW : UI_MODES.CLASSIC,
|
|
52
|
+
// Whether the UI may offer 'none' at all: the bind must be loopback
|
|
53
|
+
// and the person asking must be on this machine.
|
|
54
|
+
canUseNoPassword: isLoopbackBind(dashboardBindAddress) &&
|
|
55
|
+
isLoopbackAddress(req.ip ?? req.socket?.remoteAddress),
|
|
56
|
+
hasPassword,
|
|
22
57
|
platform: process.platform === 'win32' ? 'win32' : 'linux',
|
|
23
58
|
});
|
|
24
59
|
} catch (err) {
|
|
@@ -26,17 +61,79 @@ class SettingsController {
|
|
|
26
61
|
}
|
|
27
62
|
}
|
|
28
63
|
|
|
29
|
-
update(req, res) {
|
|
64
|
+
async update(req, res) {
|
|
30
65
|
try {
|
|
31
|
-
const {
|
|
66
|
+
const {
|
|
67
|
+
dashboardPort, dashboardPassword, nginxDir, sslDir, acmeEmail, dashboardBindAddress,
|
|
68
|
+
dashboardAuth, dashboardUi, sslAutoRenew, sslAutoRenewDays, deployDir,
|
|
69
|
+
} = req.body;
|
|
70
|
+
|
|
71
|
+
const current = loadConfig();
|
|
32
72
|
|
|
33
73
|
if (dashboardPort !== undefined) {
|
|
34
74
|
const portError = validatePort(parseInt(dashboardPort, 10));
|
|
35
75
|
if (portError) return res.status(400).json({ error: portError });
|
|
36
76
|
}
|
|
37
77
|
|
|
38
|
-
|
|
39
|
-
|
|
78
|
+
// A password set from here is held to the same minimum as the
|
|
79
|
+
// first-run one, and is never stored in clear.
|
|
80
|
+
if (dashboardPassword !== undefined) {
|
|
81
|
+
const problem = validateNewPassword(dashboardPassword);
|
|
82
|
+
if (problem) return res.status(400).json({ error: problem });
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (dashboardBindAddress !== undefined &&
|
|
86
|
+
![BIND_ALL, BIND_LOOPBACK, BIND_LOOPBACK_V6].includes(dashboardBindAddress)) {
|
|
87
|
+
return res.status(400).json({
|
|
88
|
+
error: `Bind address must be ${BIND_LOOPBACK} (this machine only) or ${BIND_ALL} (all interfaces)`,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (dashboardAuth !== undefined &&
|
|
93
|
+
![AUTH_MODES.PASSWORD, AUTH_MODES.NONE].includes(dashboardAuth)) {
|
|
94
|
+
return res.status(400).json({
|
|
95
|
+
error: `Authentication must be '${AUTH_MODES.PASSWORD}' or '${AUTH_MODES.NONE}'`,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (dashboardUi !== undefined &&
|
|
100
|
+
![UI_MODES.CLASSIC, UI_MODES.NEW].includes(dashboardUi)) {
|
|
101
|
+
return res.status(400).json({
|
|
102
|
+
error: `Dashboard UI must be '${UI_MODES.CLASSIC}' or '${UI_MODES.NEW}'`,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// ── The auth/bind interlock ──────────────────────────────────────
|
|
107
|
+
//
|
|
108
|
+
// 'none' is only safe while nothing but this machine can reach the
|
|
109
|
+
// listener, so the two settings are validated TOGETHER against the
|
|
110
|
+
// state this request would produce — not against the current state.
|
|
111
|
+
// Otherwise a single request could set both and slip through by
|
|
112
|
+
// checking each against the old value.
|
|
113
|
+
const nextAuth = dashboardAuth ?? current.dashboardAuth;
|
|
114
|
+
const nextBind = dashboardBindAddress ?? current.dashboardBindAddress;
|
|
115
|
+
|
|
116
|
+
if (nextAuth === AUTH_MODES.NONE && !isLoopbackBind(nextBind)) {
|
|
117
|
+
// Which half the user is changing decides which message helps.
|
|
118
|
+
const changingBind = dashboardBindAddress !== undefined &&
|
|
119
|
+
dashboardBindAddress !== current.dashboardBindAddress;
|
|
120
|
+
|
|
121
|
+
return res.status(400).json({
|
|
122
|
+
error: changingBind
|
|
123
|
+
? 'This dashboard has no password, so it can only listen on this machine. Set a password first, then change where it listens.'
|
|
124
|
+
: `Running without a password requires the dashboard to listen on this machine only (currently ${nextBind}).`,
|
|
125
|
+
reason: changingBind ? 'bind_requires_password' : 'no_auth_requires_loopback',
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Turning auth OFF is only ever done from the machine itself.
|
|
130
|
+
if (dashboardAuth === AUTH_MODES.NONE &&
|
|
131
|
+
current.dashboardAuth !== AUTH_MODES.NONE &&
|
|
132
|
+
!isLoopbackAddress(req.ip ?? req.socket?.remoteAddress)) {
|
|
133
|
+
return res.status(403).json({
|
|
134
|
+
error: 'Removing the password can only be done from this machine.',
|
|
135
|
+
reason: 'no_auth_requires_local_request',
|
|
136
|
+
});
|
|
40
137
|
}
|
|
41
138
|
|
|
42
139
|
if (nginxDir !== undefined && (typeof nginxDir !== 'string' || nginxDir.trim() === '')) {
|
|
@@ -51,17 +148,68 @@ class SettingsController {
|
|
|
51
148
|
if (emailError) return res.status(400).json({ error: emailError });
|
|
52
149
|
}
|
|
53
150
|
|
|
54
|
-
|
|
151
|
+
if (sslAutoRenew !== undefined && typeof sslAutoRenew !== 'boolean') {
|
|
152
|
+
return res.status(400).json({ error: 'sslAutoRenew must be true or false' });
|
|
153
|
+
}
|
|
154
|
+
if (sslAutoRenewDays !== undefined && normalizeAutoRenewDays(sslAutoRenewDays) === null) {
|
|
155
|
+
return res.status(400).json({
|
|
156
|
+
error: `Auto-renew days must be a whole number from ${MIN_AUTO_RENEW_DAYS} to ${MAX_AUTO_RENEW_DAYS}`,
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// An empty value means "back to the default".
|
|
161
|
+
const resetDeployDir = deployDir === null || (typeof deployDir === 'string' && deployDir.trim() === '');
|
|
162
|
+
if (deployDir !== undefined && !resetDeployDir) {
|
|
163
|
+
const dirError = validateDeployDir(deployDir);
|
|
164
|
+
if (dirError) return res.status(400).json({ error: dirError });
|
|
165
|
+
try {
|
|
166
|
+
await fs.mkdir(path.resolve(deployDir.trim()), { recursive: true });
|
|
167
|
+
} catch (err) {
|
|
168
|
+
return res.status(400).json({ error: `That folder cannot be created or written to: ${err.message}` });
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const currentConfig = current;
|
|
55
173
|
const updates = {};
|
|
56
174
|
|
|
57
175
|
if (dashboardPort !== undefined) updates.dashboardPort = parseInt(dashboardPort, 10);
|
|
58
|
-
if (dashboardPassword !== undefined)
|
|
176
|
+
if (dashboardPassword !== undefined) {
|
|
177
|
+
updates.dashboardPasswordHash = await hashPassword(dashboardPassword);
|
|
178
|
+
// Drop any legacy plain-text copy at the same time.
|
|
179
|
+
updates.dashboardPassword = '';
|
|
180
|
+
}
|
|
181
|
+
if (dashboardBindAddress !== undefined) updates.dashboardBindAddress = dashboardBindAddress;
|
|
182
|
+
if (dashboardAuth !== undefined) updates.dashboardAuth = dashboardAuth;
|
|
183
|
+
if (dashboardUi !== undefined) updates.dashboardUi = dashboardUi;
|
|
184
|
+
|
|
185
|
+
// Setting a password implies wanting one; switching to 'password'
|
|
186
|
+
// without one leaves the first-run screen as the way back in, which
|
|
187
|
+
// is recoverable but not what anyone means by saving a password.
|
|
188
|
+
if (dashboardPassword !== undefined && dashboardAuth === undefined) {
|
|
189
|
+
updates.dashboardAuth = AUTH_MODES.PASSWORD;
|
|
190
|
+
}
|
|
59
191
|
if (nginxDir !== undefined) updates.nginxDir = nginxDir.trim();
|
|
60
192
|
if (sslDir !== undefined) updates.sslDir = sslDir.trim();
|
|
61
193
|
if (acmeEmail !== undefined) updates.acmeEmail = acmeEmail.trim();
|
|
194
|
+
if (deployDir !== undefined) updates.deployDir = resetDeployDir ? null : path.resolve(deployDir.trim());
|
|
195
|
+
if (sslAutoRenew !== undefined) updates.sslAutoRenew = sslAutoRenew;
|
|
196
|
+
if (sslAutoRenewDays !== undefined) updates.sslAutoRenewDays = normalizeAutoRenewDays(sslAutoRenewDays);
|
|
62
197
|
|
|
63
198
|
saveConfig({ ...currentConfig, ...updates });
|
|
64
|
-
|
|
199
|
+
|
|
200
|
+
// The port, the bind address and the UI choice only take effect on
|
|
201
|
+
// restart, so say so rather than letting the user think the change is
|
|
202
|
+
// already live.
|
|
203
|
+
const needsRestart = updates.dashboardPort !== undefined ||
|
|
204
|
+
updates.dashboardBindAddress !== undefined ||
|
|
205
|
+
updates.dashboardUi !== undefined;
|
|
206
|
+
|
|
207
|
+
res.json({
|
|
208
|
+
success: true,
|
|
209
|
+
needsRestart,
|
|
210
|
+
dashboardAuth: effectiveAuthMode({ ...currentConfig, ...updates }),
|
|
211
|
+
dashboardUi: updates.dashboardUi ?? currentConfig.dashboardUi,
|
|
212
|
+
});
|
|
65
213
|
} catch (err) {
|
|
66
214
|
res.status(500).json({ error: 'Internal server error' });
|
|
67
215
|
}
|
|
@@ -149,7 +297,14 @@ class SettingsController {
|
|
|
149
297
|
try {
|
|
150
298
|
const config = loadConfig();
|
|
151
299
|
const domains = dbGet('domains') || [];
|
|
152
|
-
|
|
300
|
+
// Strip BOTH the legacy plain-text password and the hash: a backup is
|
|
301
|
+
// a file the user downloads and may share, and a scrypt hash is still
|
|
302
|
+
// a credential worth cracking offline.
|
|
303
|
+
const {
|
|
304
|
+
dashboardPassword: _pw,
|
|
305
|
+
dashboardPasswordHash: _pwHash,
|
|
306
|
+
...safeConfig
|
|
307
|
+
} = config;
|
|
153
308
|
const backup = {
|
|
154
309
|
version: 1,
|
|
155
310
|
exportedAt: new Date().toISOString(),
|
|
@@ -171,10 +326,23 @@ class SettingsController {
|
|
|
171
326
|
return res.status(400).json({ error: 'Invalid backup: missing config' });
|
|
172
327
|
}
|
|
173
328
|
const current = loadConfig();
|
|
174
|
-
|
|
329
|
+
// A backup may predate hashed passwords and the bind setting. Never let
|
|
330
|
+
// one restore a plain-text password or silently re-open the listener.
|
|
331
|
+
const merged = {
|
|
332
|
+
...current,
|
|
333
|
+
...config,
|
|
334
|
+
dashboardPassword: current.dashboardPassword,
|
|
335
|
+
dashboardPasswordHash: current.dashboardPasswordHash,
|
|
336
|
+
dashboardBindAddress: current.dashboardBindAddress,
|
|
337
|
+
dashboardAuth: current.dashboardAuth,
|
|
338
|
+
};
|
|
175
339
|
saveConfig(merged);
|
|
340
|
+
// Through saveDomains(), not dbSet: restoring a backup replaces the
|
|
341
|
+
// whole domain set, which the Hub must learn about like any other
|
|
342
|
+
// domain write. A bare dbSet skipped the revision bump and left the
|
|
343
|
+
// Hub showing the pre-restore list until the next restart.
|
|
176
344
|
if (Array.isArray(domains)) {
|
|
177
|
-
|
|
345
|
+
saveDomains(domains);
|
|
178
346
|
}
|
|
179
347
|
res.json({ success: true });
|
|
180
348
|
} catch (err) {
|
|
@@ -1,5 +1,15 @@
|
|
|
1
|
-
import { listAllCerts } from '
|
|
2
|
-
import { issueCert
|
|
1
|
+
import { listAllCerts } from '../../core/cert-reader.js';
|
|
2
|
+
import { issueCert } from '../../cli/managers/ssl-manager.js';
|
|
3
|
+
import {
|
|
4
|
+
renewCertificate,
|
|
5
|
+
describeRenewal,
|
|
6
|
+
describeCertificate,
|
|
7
|
+
getAutoRenewSettings,
|
|
8
|
+
getAutoRenewState,
|
|
9
|
+
autoRenewPlan,
|
|
10
|
+
} from '../../core/cert-renewal.js';
|
|
11
|
+
import { describeIssuance, prepareDomainForHttpChallenge } from '../../core/ssl-issuer.js';
|
|
12
|
+
import { findDomain, getDomains } from '../../core/domains-db.js';
|
|
3
13
|
import { loadConfig } from '../../core/config.js';
|
|
4
14
|
import { promises as dns } from 'dns';
|
|
5
15
|
|
|
@@ -8,7 +18,7 @@ import { promises as dns } from 'dns';
|
|
|
8
18
|
// or when cancelled. Entries older than 10 minutes are forcibly removed.
|
|
9
19
|
const pendingDnsChallenges = new Map();
|
|
10
20
|
|
|
11
|
-
setInterval(() => {
|
|
21
|
+
const dnsSweepTimer = setInterval(() => {
|
|
12
22
|
const now = Date.now();
|
|
13
23
|
for (const [domain, state] of pendingDnsChallenges) {
|
|
14
24
|
if (now - state.createdAt > 10 * 60 * 1000) {
|
|
@@ -18,6 +28,24 @@ setInterval(() => {
|
|
|
18
28
|
}
|
|
19
29
|
}, 60000);
|
|
20
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Stops the DNS-challenge sweep and rejects anything still pending.
|
|
33
|
+
*
|
|
34
|
+
* Called by the dashboard's shutdown(): this interval is created at module
|
|
35
|
+
* load and would otherwise keep the event loop alive, so `ezz --dash` would
|
|
36
|
+
* never exit on Ctrl+C. Safe to call more than once.
|
|
37
|
+
*/
|
|
38
|
+
export function stopSslController() {
|
|
39
|
+
clearInterval(dnsSweepTimer);
|
|
40
|
+
|
|
41
|
+
for (const [domain, state] of pendingDnsChallenges) {
|
|
42
|
+
try {
|
|
43
|
+
state.confirmDeferred.reject(new Error('Dashboard is shutting down'));
|
|
44
|
+
} catch { /* already settled */ }
|
|
45
|
+
pendingDnsChallenges.delete(domain);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
21
49
|
class SslController {
|
|
22
50
|
async create(req, res, next) {
|
|
23
51
|
try {
|
|
@@ -110,11 +138,40 @@ class SslController {
|
|
|
110
138
|
return;
|
|
111
139
|
}
|
|
112
140
|
|
|
113
|
-
// HTTP validation path (synchronous — responds when complete)
|
|
141
|
+
// HTTP validation path (synchronous — responds when complete).
|
|
142
|
+
//
|
|
143
|
+
// Flow 2: make sure nginx can answer the challenge first. For a domain
|
|
144
|
+
// that is already configured this regenerates a stale config; for a new
|
|
145
|
+
// one it writes a temporary HTTP-only config. Either way nginx is only
|
|
146
|
+
// reloaded, never stopped.
|
|
147
|
+
const existing = findDomain(domainKey);
|
|
148
|
+
let prepared = null;
|
|
149
|
+
if (existing) {
|
|
150
|
+
prepared = await prepareDomainForHttpChallenge(existing);
|
|
151
|
+
if (!prepared.ok) {
|
|
152
|
+
return res.status(500).json({
|
|
153
|
+
error: 'challenge_setup_failed',
|
|
154
|
+
detail: prepared.error,
|
|
155
|
+
hint: 'nginx could not be prepared to answer the ACME challenge. Check the nginx config and try again.',
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
114
160
|
const result = await issueCert(domainKey, { www: !!www, validationMethod: 'http', email: acmeEmail });
|
|
115
161
|
|
|
116
162
|
if (result.success) {
|
|
117
|
-
|
|
163
|
+
// Tell the UI how the challenge ran: proxy (nginx stayed up), or a
|
|
164
|
+
// standalone fallback with how long nginx was stopped.
|
|
165
|
+
return res.json({
|
|
166
|
+
success: true,
|
|
167
|
+
certPath: result.certPath,
|
|
168
|
+
keyPath: result.keyPath,
|
|
169
|
+
mode: result.mode,
|
|
170
|
+
fellBack: result.fellBack,
|
|
171
|
+
nginxDownMs: result.nginxDownMs,
|
|
172
|
+
staging: result.staging,
|
|
173
|
+
summary: describeIssuance(result),
|
|
174
|
+
});
|
|
118
175
|
}
|
|
119
176
|
|
|
120
177
|
const { step } = result.error;
|
|
@@ -178,7 +235,18 @@ class SslController {
|
|
|
178
235
|
pendingDnsChallenges.delete(domainKey);
|
|
179
236
|
|
|
180
237
|
if (result.success) {
|
|
181
|
-
|
|
238
|
+
// Tell the UI how the challenge ran: proxy (nginx stayed up), or a
|
|
239
|
+
// standalone fallback with how long nginx was stopped.
|
|
240
|
+
return res.json({
|
|
241
|
+
success: true,
|
|
242
|
+
certPath: result.certPath,
|
|
243
|
+
keyPath: result.keyPath,
|
|
244
|
+
mode: result.mode,
|
|
245
|
+
fellBack: result.fellBack,
|
|
246
|
+
nginxDownMs: result.nginxDownMs,
|
|
247
|
+
staging: result.staging,
|
|
248
|
+
summary: describeIssuance(result),
|
|
249
|
+
});
|
|
182
250
|
}
|
|
183
251
|
return res.status(500).json({ success: false, error: result.error });
|
|
184
252
|
} catch (error) {
|
|
@@ -212,7 +280,38 @@ class SslController {
|
|
|
212
280
|
async list(req, res, next) {
|
|
213
281
|
try {
|
|
214
282
|
const certs = await listAllCerts();
|
|
215
|
-
|
|
283
|
+
|
|
284
|
+
// Additive: what the background job intends for each certificate, so the
|
|
285
|
+
// UI can show "auto-renews" / "manual renewal" instead of leaving the
|
|
286
|
+
// operator to guess. Computed by the same function the job uses.
|
|
287
|
+
const config = loadConfig();
|
|
288
|
+
const settings = getAutoRenewSettings(config);
|
|
289
|
+
const domains = getDomains();
|
|
290
|
+
const state = getAutoRenewState();
|
|
291
|
+
|
|
292
|
+
const withPlan = await Promise.all(certs.map(async (cert) => {
|
|
293
|
+
let plan = 'off';
|
|
294
|
+
try {
|
|
295
|
+
const info = await describeCertificate(cert.domain);
|
|
296
|
+
plan = autoRenewPlan({ certDomain: cert.domain, info, settings, domains, sslDir: config.sslDir });
|
|
297
|
+
} catch { /* unreadable certificate: report it as not handled */ }
|
|
298
|
+
|
|
299
|
+
const last = state[cert.domain] ?? null;
|
|
300
|
+
return {
|
|
301
|
+
...cert,
|
|
302
|
+
autoRenew: plan,
|
|
303
|
+
autoRenewDays: settings.days,
|
|
304
|
+
lastAutoRenew: last
|
|
305
|
+
? {
|
|
306
|
+
at: last.lastAttemptAt ?? null,
|
|
307
|
+
result: last.lastResult ?? null,
|
|
308
|
+
error: last.lastError ?? null,
|
|
309
|
+
}
|
|
310
|
+
: null,
|
|
311
|
+
};
|
|
312
|
+
}));
|
|
313
|
+
|
|
314
|
+
res.json(withPlan);
|
|
216
315
|
} catch (error) {
|
|
217
316
|
next(error);
|
|
218
317
|
}
|
|
@@ -236,13 +335,44 @@ class SslController {
|
|
|
236
335
|
return res.status(404).json({ error: `Domain '${domain}' not found` });
|
|
237
336
|
}
|
|
238
337
|
|
|
239
|
-
|
|
338
|
+
// renewCertificate() is the one renewal path (core/cert-renewal.js): it
|
|
339
|
+
// regenerates a config that predates the ACME challenge location, keeps
|
|
340
|
+
// the names the certificate already covers, and reloads nginx so the new
|
|
341
|
+
// certificate is the one being served.
|
|
342
|
+
const result = await renewCertificate(domain, { email: config.acmeEmail });
|
|
240
343
|
|
|
241
344
|
if (result.success) {
|
|
242
|
-
|
|
345
|
+
// Tell the UI how the challenge ran: proxy (nginx stayed up), or a
|
|
346
|
+
// standalone fallback with how long nginx was stopped.
|
|
347
|
+
return res.json({
|
|
348
|
+
success: true,
|
|
349
|
+
certPath: result.certPath,
|
|
350
|
+
keyPath: result.keyPath,
|
|
351
|
+
mode: result.mode,
|
|
352
|
+
fellBack: result.fellBack,
|
|
353
|
+
nginxDownMs: result.nginxDownMs,
|
|
354
|
+
staging: result.staging,
|
|
355
|
+
nginxReloaded: result.nginxReloaded,
|
|
356
|
+
summary: describeRenewal(result),
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
if (result.skipped === 'manual') {
|
|
361
|
+
return res.status(409).json({
|
|
362
|
+
error: 'manual_renewal_required',
|
|
363
|
+
detail: result.error.cause,
|
|
364
|
+
hint: 'Create the certificate again from the SSL page using the DNS method.',
|
|
365
|
+
});
|
|
243
366
|
}
|
|
244
367
|
|
|
245
368
|
const { step } = result.error;
|
|
369
|
+
if (step === 'challenge setup') {
|
|
370
|
+
return res.status(500).json({
|
|
371
|
+
error: 'challenge_setup_failed',
|
|
372
|
+
detail: result.error.cause,
|
|
373
|
+
hint: 'nginx could not be prepared to answer the ACME challenge.',
|
|
374
|
+
});
|
|
375
|
+
}
|
|
246
376
|
if (step === 'port 80 check') {
|
|
247
377
|
return res.status(409).json({
|
|
248
378
|
error: 'port_busy',
|
|
@@ -272,12 +402,43 @@ class SslController {
|
|
|
272
402
|
const results = [];
|
|
273
403
|
|
|
274
404
|
for (const cert of expiring) {
|
|
275
|
-
const result = await
|
|
405
|
+
const result = await renewCertificate(cert.domain, { email: config.acmeEmail });
|
|
406
|
+
|
|
407
|
+
if (!result.success && result.error?.step === 'challenge setup') {
|
|
408
|
+
results.push({
|
|
409
|
+
domain: cert.domain,
|
|
410
|
+
success: false,
|
|
411
|
+
certPath: null,
|
|
412
|
+
keyPath: null,
|
|
413
|
+
error: 'challenge_setup_failed',
|
|
414
|
+
detail: result.error.cause,
|
|
415
|
+
});
|
|
416
|
+
continue;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
if (result.skipped === 'manual') {
|
|
420
|
+
results.push({
|
|
421
|
+
domain: cert.domain,
|
|
422
|
+
success: false,
|
|
423
|
+
certPath: null,
|
|
424
|
+
keyPath: null,
|
|
425
|
+
error: 'manual_renewal_required',
|
|
426
|
+
detail: result.error.cause,
|
|
427
|
+
});
|
|
428
|
+
continue;
|
|
429
|
+
}
|
|
430
|
+
|
|
276
431
|
results.push({
|
|
277
432
|
domain: cert.domain,
|
|
278
433
|
success: result.success,
|
|
279
434
|
certPath: result.certPath,
|
|
280
435
|
keyPath: result.keyPath,
|
|
436
|
+
mode: result.mode,
|
|
437
|
+
fellBack: result.fellBack,
|
|
438
|
+
nginxDownMs: result.nginxDownMs,
|
|
439
|
+
configRegenerated: Boolean(result.configRegenerated),
|
|
440
|
+
nginxReloaded: result.nginxReloaded,
|
|
441
|
+
summary: describeRenewal(result),
|
|
281
442
|
});
|
|
282
443
|
}
|
|
283
444
|
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dashboard/lib/daemonBridge.js
|
|
3
|
+
*
|
|
4
|
+
* The dashboard's end of the daemon's event channel.
|
|
5
|
+
*
|
|
6
|
+
* It connects to the daemon's IPC socket and REPUBLISHES every frame onto this
|
|
7
|
+
* process's job bus. That one decision is what keeps the rest of the dashboard
|
|
8
|
+
* simple: dashboard/socketManager.js subscribes to the bus and nothing else,
|
|
9
|
+
* so it does not care whether an event came from monitors running here or from
|
|
10
|
+
* a daemon in another process. There is exactly one path to the browser.
|
|
11
|
+
*
|
|
12
|
+
* The two cases never overlap. When a daemon is running, core/jobs/index.js
|
|
13
|
+
* stops this process's monitors, so the only events on the bus are the ones
|
|
14
|
+
* arriving over IPC. When no daemon is running, there is nothing to connect to
|
|
15
|
+
* and the bus carries local events only.
|
|
16
|
+
*
|
|
17
|
+
* It also answers "is the service running?" for the banner — from the lock
|
|
18
|
+
* file, not from whether the socket happens to be connected. A daemon that is
|
|
19
|
+
* up but whose IPC failed to bind is still running the jobs, and telling the
|
|
20
|
+
* user to install a service they already have would be worse than saying
|
|
21
|
+
* nothing.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import { connectToDaemon } from '../../core/daemon/ipc.js';
|
|
25
|
+
import { publish } from '../../core/jobs/bus.js';
|
|
26
|
+
import { inspect, watchLock } from '../../core/daemon/lock.js';
|
|
27
|
+
import { getDataDir } from '../../core/platform.js';
|
|
28
|
+
import { backgroundServiceState, invalidateProbes } from '../../core/service/index.js';
|
|
29
|
+
|
|
30
|
+
let bridge = null;
|
|
31
|
+
let hello = null;
|
|
32
|
+
let lockWatch = null;
|
|
33
|
+
let lastAnnounced = null;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Starts the bridge. Safe to call when no daemon exists: the client retries
|
|
37
|
+
* quietly with backoff and connects if one appears later.
|
|
38
|
+
*
|
|
39
|
+
* @param {Object} [opts]
|
|
40
|
+
* @param {string} [opts.dataDir]
|
|
41
|
+
* @returns {{ stop: () => void, status: () => DaemonStatus }}
|
|
42
|
+
*
|
|
43
|
+
* @typedef {Object} DaemonStatus
|
|
44
|
+
* @property {boolean} running A daemon holds the lock
|
|
45
|
+
* @property {boolean} connected We have a live event channel to it
|
|
46
|
+
* @property {number|null} pid
|
|
47
|
+
* @property {string|null} version
|
|
48
|
+
* @property {number|null} startedAt
|
|
49
|
+
*/
|
|
50
|
+
export function startDaemonBridge({ dataDir = getDataDir() } = {}) {
|
|
51
|
+
stopDaemonBridge();
|
|
52
|
+
|
|
53
|
+
bridge = connectToDaemon({
|
|
54
|
+
dataDir,
|
|
55
|
+
onEvent(event, payload) {
|
|
56
|
+
if (event === 'daemon:hello') {
|
|
57
|
+
// Identity, not an event the browser needs: the banner reads it from
|
|
58
|
+
// status() instead.
|
|
59
|
+
hello = payload;
|
|
60
|
+
announce(dataDir);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
publish(event, payload);
|
|
64
|
+
},
|
|
65
|
+
onStatus(connected, detail) {
|
|
66
|
+
if (connected) {
|
|
67
|
+
console.log('[daemonBridge] connected to the background service');
|
|
68
|
+
} else {
|
|
69
|
+
hello = null;
|
|
70
|
+
// A daemon that stopped is not the same as one we cannot reach, and
|
|
71
|
+
// saying "no event channel" for both was misleading during an ordinary
|
|
72
|
+
// restart. The lock tells us which this is.
|
|
73
|
+
const stillThere = inspect({ dataDir }).running;
|
|
74
|
+
console.log(stillThere
|
|
75
|
+
? `[daemonBridge] lost the event channel to the running service (${detail ?? 'disconnected'}) — retrying`
|
|
76
|
+
: '[daemonBridge] the background service is not running');
|
|
77
|
+
}
|
|
78
|
+
announce(dataDir);
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
// The lock is the authority on whether a daemon exists, and it changes the
|
|
83
|
+
// instant one starts. Watching it does two things the backoff cannot:
|
|
84
|
+
// reconnect the event channel immediately instead of waiting out a delay
|
|
85
|
+
// computed from earlier failures, and tell the browser about the new state
|
|
86
|
+
// at once.
|
|
87
|
+
lockWatch = watchLock({
|
|
88
|
+
dataDir,
|
|
89
|
+
onChange() {
|
|
90
|
+
if (inspect({ dataDir }).running) bridge?.reconnectNow();
|
|
91
|
+
announce(dataDir);
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
announce(dataDir);
|
|
96
|
+
|
|
97
|
+
return { stop: stopDaemonBridge, status: daemonStatus, announce: () => announce(dataDir) };
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Publishes the background-service state to the browser, when it changes.
|
|
102
|
+
*
|
|
103
|
+
* Only on a real change: this is called from a lock watcher and from every
|
|
104
|
+
* connect and disconnect, and a browser that re-rendered on each of those
|
|
105
|
+
* would flicker during an ordinary restart.
|
|
106
|
+
*/
|
|
107
|
+
function announce(dataDir) {
|
|
108
|
+
try {
|
|
109
|
+
const next = daemonStatus({ dataDir });
|
|
110
|
+
const signature = JSON.stringify(next);
|
|
111
|
+
if (signature === lastAnnounced) return;
|
|
112
|
+
lastAnnounced = signature;
|
|
113
|
+
|
|
114
|
+
// The service state changed, so the cached probes in GET /api/service no
|
|
115
|
+
// longer describe it. Dropped here rather than only on a TTL, because this
|
|
116
|
+
// fires the moment a daemon appears or goes away - including when a change
|
|
117
|
+
// was made by `ezz service start` in another process, which nothing in
|
|
118
|
+
// THIS process would otherwise know about.
|
|
119
|
+
invalidateProbes();
|
|
120
|
+
|
|
121
|
+
publish('service:changed', next);
|
|
122
|
+
} catch (err) {
|
|
123
|
+
console.error('[daemonBridge] could not publish the service state:', err.message);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** Stops the bridge if one is running. Idempotent. */
|
|
128
|
+
export function stopDaemonBridge() {
|
|
129
|
+
if (bridge) {
|
|
130
|
+
bridge.close();
|
|
131
|
+
bridge = null;
|
|
132
|
+
}
|
|
133
|
+
lockWatch?.close();
|
|
134
|
+
lockWatch = null;
|
|
135
|
+
hello = null;
|
|
136
|
+
lastAnnounced = null;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* What the dashboard should tell the user about the background service.
|
|
141
|
+
*
|
|
142
|
+
* `running` comes from the lock file — the authority on whether a daemon
|
|
143
|
+
* exists. `connected` is about this process's event channel to it, which is a
|
|
144
|
+
* separate question and only affects how fresh the live view is.
|
|
145
|
+
*
|
|
146
|
+
* @param {Object} [opts]
|
|
147
|
+
* @returns {DaemonStatus}
|
|
148
|
+
*/
|
|
149
|
+
export function daemonStatus({ dataDir = getDataDir() } = {}) {
|
|
150
|
+
// Everything about the service itself comes from core, so the HTTP response
|
|
151
|
+
// and the `service:changed` socket event carry the identical shape and the
|
|
152
|
+
// UI has one type to render. Only `connected` is the bridge's own business —
|
|
153
|
+
// it describes THIS process's event channel, not the service.
|
|
154
|
+
const state = backgroundServiceState({ dataDir });
|
|
155
|
+
|
|
156
|
+
return {
|
|
157
|
+
...state,
|
|
158
|
+
connected: Boolean(bridge?.connected()),
|
|
159
|
+
// The hello frame is the daemon's own word for its version; the lock is a
|
|
160
|
+
// fallback for a daemon whose IPC never came up.
|
|
161
|
+
version: hello?.version ?? state.version,
|
|
162
|
+
};
|
|
163
|
+
}
|