easy-devops 1.3.6 → 1.4.1
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 +1 -0
- package/dist/ui/assets/index-Bu7af-Kj.css +1 -0
- package/dist/ui/assets/index-gndgYe3K.js +532 -0
- package/dist/ui/assets/socket-Bv0wCEgi.js +65 -0
- package/dist/ui/index.html +2 -2
- package/install.bat +14 -7
- package/package.json +2 -2
- package/src/cli/index.js +8 -0
- package/src/cli/managers/domain-manager.js +37 -6
- package/src/cli/managers/nginx-manager.js +14 -5
- package/src/cli/managers/node-manager.js +19 -13
- package/src/cli/managers/ssl-manager.js +89 -26
- package/src/cli/menu.js +8 -2
- package/src/cli/menus/cleanup.js +4 -2
- package/src/cli/menus/dashboard.js +22 -15
- package/src/cli/menus/hub.js +402 -0
- package/src/cli/menus/runtime.js +12 -0
- package/src/cli/menus/service.js +80 -13
- package/src/cli/menus/settings.js +46 -12
- package/src/cli/menus/uninstall.js +13 -5
- package/src/cli/menus/update.js +24 -14
- package/src/cli/ui/page.js +123 -0
- package/src/core/cert-operations.js +34 -4
- package/src/core/cert-reader.js +67 -22
- package/src/core/cert-renewal.js +65 -9
- package/src/core/cert-suggest.js +120 -0
- package/src/core/cleanup.js +221 -1
- package/src/core/cloudflare-ips.js +161 -0
- package/src/core/daemon/ipc.js +1 -1
- package/src/core/daemon/lock.js +296 -9
- package/src/core/daemon/run.js +12 -0
- package/src/core/daemon/stateFile.js +128 -0
- package/src/core/dashboardProcess.js +134 -6
- package/src/core/db.js +26 -1
- package/src/core/deploy/apps.js +36 -62
- package/src/core/deploy/deployKey.js +331 -0
- package/src/core/deploy/domainLink.js +280 -23
- package/src/core/deploy/engine.js +382 -63
- package/src/core/deploy/ezfile.js +496 -29
- package/src/core/deploy/githubApi.js +100 -13
- package/src/core/deploy/hubCommands.js +158 -18
- package/src/core/deploy/status.js +28 -1
- package/src/core/domains-db.js +1 -0
- package/src/core/hub/agent.js +238 -32
- package/src/core/hub/deployProgress.js +411 -0
- package/src/core/hubConnect.js +205 -0
- package/src/core/hubPermissions.js +48 -10
- package/src/core/jobs/bus.js +1 -1
- package/src/core/jobs/owner.js +268 -6
- package/src/core/nginx-conf-generator.js +124 -19
- package/src/core/notifications/claim.js +26 -3
- package/src/core/permissions.js +277 -59
- package/src/core/platform.js +73 -2
- package/src/core/runner.js +96 -40
- package/src/core/service/dataDir.js +34 -9
- package/src/core/service/index.js +203 -24
- package/src/core/service/runtime.js +40 -3
- package/src/core/service/windowsService.js +452 -107
- package/src/core/service/winsw.js +44 -3
- package/src/core/ssl/preflight.js +548 -0
- package/src/core/ssl/progress.js +196 -0
- package/src/core/ssl-issuer.js +502 -148
- package/src/core/validators.js +24 -0
- package/src/dashboard/controllers/authController.js +12 -5
- package/src/dashboard/controllers/deploymentsController.js +76 -11
- package/src/dashboard/controllers/domainsController.js +35 -1
- package/src/dashboard/controllers/hubController.js +4 -3
- package/src/dashboard/controllers/settingsController.js +73 -68
- package/src/dashboard/controllers/sslController.js +135 -15
- package/src/dashboard/public/js/app.js +42 -7
- package/src/dashboard/routes/deployments.js +2 -0
- package/src/dashboard/routes/domains.js +1 -0
- package/src/dashboard/server.js +42 -7
- package/src/dashboard/socketManager.js +19 -25
- package/src/dashboard/views/partials/settings-panel.ejs +29 -10
- package/dist/ui/assets/index-BUpPxWmp.css +0 -1
- package/dist/ui/assets/index-DD0JjK0Q.js +0 -475
- package/dist/ui/assets/socket-4tfdap-e.js +0 -65
|
@@ -54,6 +54,25 @@ export const WINSW_BYTES = 18_243_033;
|
|
|
54
54
|
/** Service identity. The display name is what appears in services.msc. */
|
|
55
55
|
export const SERVICE_ID = 'EasyDevOps';
|
|
56
56
|
export const SERVICE_DISPLAY_NAME = 'Easy DevOps';
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The names the wrapper and its definition are stored under.
|
|
60
|
+
*
|
|
61
|
+
* WinSW v2 finds its configuration ONLY as `<its own base name>.xml` in its
|
|
62
|
+
* own directory; a path passed on the command line is ignored. Storing the
|
|
63
|
+
* downloaded `WinSW-x64.exe` under its release name beside `EasyDevOps.xml`
|
|
64
|
+
* is exactly what made 1.4.0's Server-mode install fail with "Unable to
|
|
65
|
+
* locate WinSW-x64.[xml|yml]". Both names are derived from SERVICE_ID here,
|
|
66
|
+
* and nowhere else, so they cannot drift apart again.
|
|
67
|
+
*
|
|
68
|
+
* WINSW_ASSET stays the RELEASE asset name: it is what is downloaded and what
|
|
69
|
+
* the hash pins, not what the file is called once it is installed.
|
|
70
|
+
*/
|
|
71
|
+
export const WINSW_EXE_NAME = `${SERVICE_ID}.exe`;
|
|
72
|
+
export const WINSW_XML_NAME = `${SERVICE_ID}.xml`;
|
|
73
|
+
|
|
74
|
+
/** The name 1.4.0 stored the wrapper under. Found and removed on install. */
|
|
75
|
+
export const LEGACY_WINSW_NAME = WINSW_ASSET;
|
|
57
76
|
export const SERVICE_DESCRIPTION =
|
|
58
77
|
'Monitors nginx, domains and certificates, sends notifications, and runs the Easy DevOps Hub agent.';
|
|
59
78
|
|
|
@@ -125,10 +144,10 @@ export async function verifyWinsw(file) {
|
|
|
125
144
|
* @param {typeof fetch} [opts.fetchImpl] Injectable, for tests
|
|
126
145
|
* @returns {Promise<{ ok: boolean, path?: string, reason?: string, sha256?: string }>}
|
|
127
146
|
*/
|
|
128
|
-
export async function downloadWinsw({ dest, log = () => {}, fetchImpl = fetch } = {}) {
|
|
147
|
+
export async function downloadWinsw({ dest, log = () => {}, fetchImpl = fetch, verify = verifyWinsw } = {}) {
|
|
129
148
|
// Already there and correct: do not download 18MB again.
|
|
130
149
|
if (fs.existsSync(dest)) {
|
|
131
|
-
const existing = await
|
|
150
|
+
const existing = await verify(dest);
|
|
132
151
|
if (existing.ok) {
|
|
133
152
|
log(`${WINSW_ASSET} ${WINSW_VERSION} already present and verified.`);
|
|
134
153
|
return { ok: true, path: dest, sha256: existing.sha256 };
|
|
@@ -136,6 +155,28 @@ export async function downloadWinsw({ dest, log = () => {}, fetchImpl = fetch }
|
|
|
136
155
|
log(`An existing ${path.basename(dest)} did not verify (${existing.reason.split('\n')[0]}); re-downloading.`);
|
|
137
156
|
}
|
|
138
157
|
|
|
158
|
+
// 1.4.0 left the wrapper beside `dest` under its release name. A copy that
|
|
159
|
+
// still verifies is the same pinned binary, so it is moved into place
|
|
160
|
+
// instead of downloading 18MB again; one that does not verify is removed.
|
|
161
|
+
// Either way the old name does not survive, because a second WinSW binary
|
|
162
|
+
// in the directory is only ever a source of confusion.
|
|
163
|
+
const legacy = path.join(path.dirname(dest), LEGACY_WINSW_NAME);
|
|
164
|
+
if (legacy !== dest && fs.existsSync(legacy)) {
|
|
165
|
+
const old = await verify(legacy);
|
|
166
|
+
try {
|
|
167
|
+
if (old.ok) {
|
|
168
|
+
fs.rmSync(dest, { force: true });
|
|
169
|
+
fs.renameSync(legacy, dest);
|
|
170
|
+
log(`Renamed the verified ${LEGACY_WINSW_NAME} to ${path.basename(dest)}.`);
|
|
171
|
+
return { ok: true, path: dest, sha256: old.sha256 };
|
|
172
|
+
}
|
|
173
|
+
fs.rmSync(legacy, { force: true });
|
|
174
|
+
log(`Removed an unverified ${LEGACY_WINSW_NAME} left by an earlier install.`);
|
|
175
|
+
} catch (err) {
|
|
176
|
+
log(`Could not tidy up ${legacy}: ${err.message}. Downloading a fresh copy instead.`);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
139
180
|
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
140
181
|
|
|
141
182
|
// Downloaded to a temporary name and renamed only after verification, so an
|
|
@@ -157,7 +198,7 @@ export async function downloadWinsw({ dest, log = () => {}, fetchImpl = fetch }
|
|
|
157
198
|
return { ok: false, reason: `download failed: ${err.message}` };
|
|
158
199
|
}
|
|
159
200
|
|
|
160
|
-
const verified = await
|
|
201
|
+
const verified = await verify(temp);
|
|
161
202
|
if (!verified.ok) {
|
|
162
203
|
try { fs.rmSync(temp, { force: true }); } catch { /* nothing to clean */ }
|
|
163
204
|
return { ok: false, reason: verified.reason };
|
|
@@ -0,0 +1,548 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* core/ssl/preflight.js
|
|
3
|
+
*
|
|
4
|
+
* Everything that can be known BEFORE a Let's Encrypt request is made.
|
|
5
|
+
*
|
|
6
|
+
* A failed check stops the operation here: no account is created, no order is
|
|
7
|
+
* placed and no failed-validation budget is spent. The module is pure with
|
|
8
|
+
* respect to I/O — DNS, HTTP, local interfaces, the challenge listener and the
|
|
9
|
+
* clock are all injectable — which is what lets the e2e suite prove every
|
|
10
|
+
* branch without touching the network.
|
|
11
|
+
*
|
|
12
|
+
* Each check returns { id, status: 'ok'|'warn'|'fail'|'skipped', message, fix }.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import http from 'node:http';
|
|
16
|
+
import https from 'node:https';
|
|
17
|
+
import net from 'node:net';
|
|
18
|
+
import os from 'node:os';
|
|
19
|
+
import { promises as dnsPromises } from 'node:dns';
|
|
20
|
+
import { ACME_CHALLENGE_PATH } from '../nginx-conf-generator.js';
|
|
21
|
+
|
|
22
|
+
/** Cloudflare's published edge ranges. Source: https://www.cloudflare.com/ips/ (2026-11-19). */
|
|
23
|
+
export const CLOUDFLARE_IPV4 = Object.freeze([
|
|
24
|
+
'173.245.48.0/20',
|
|
25
|
+
'103.21.244.0/22',
|
|
26
|
+
'103.22.200.0/22',
|
|
27
|
+
'103.31.4.0/22',
|
|
28
|
+
'141.101.64.0/18',
|
|
29
|
+
'108.162.192.0/18',
|
|
30
|
+
'190.93.240.0/20',
|
|
31
|
+
'188.114.96.0/20',
|
|
32
|
+
'197.234.240.0/22',
|
|
33
|
+
'198.41.128.0/17',
|
|
34
|
+
'162.158.0.0/15',
|
|
35
|
+
'104.16.0.0/13',
|
|
36
|
+
'104.24.0.0/14',
|
|
37
|
+
'172.64.0.0/13',
|
|
38
|
+
'131.0.72.0/22',
|
|
39
|
+
]);
|
|
40
|
+
|
|
41
|
+
/** Cloudflare's published IPv6 ranges. Same source and date as above. */
|
|
42
|
+
export const CLOUDFLARE_IPV6 = Object.freeze([
|
|
43
|
+
'2400:cb00::/32',
|
|
44
|
+
'2606:4700::/32',
|
|
45
|
+
'2803:f800::/32',
|
|
46
|
+
'2405:b500::/32',
|
|
47
|
+
'2405:8100::/32',
|
|
48
|
+
'2a06:98c0::/29',
|
|
49
|
+
'2c0f:f248::/32',
|
|
50
|
+
]);
|
|
51
|
+
|
|
52
|
+
export const DEFAULT_HTTP_PROBE_TIMEOUT_MS = 5000;
|
|
53
|
+
|
|
54
|
+
const cloudflare = new net.BlockList();
|
|
55
|
+
for (const range of CLOUDFLARE_IPV4) {
|
|
56
|
+
const [base, bits] = range.split('/');
|
|
57
|
+
cloudflare.addSubnet(base, Number(bits), 'ipv4');
|
|
58
|
+
}
|
|
59
|
+
for (const range of CLOUDFLARE_IPV6) {
|
|
60
|
+
const [base, bits] = range.split('/');
|
|
61
|
+
cloudflare.addSubnet(base, Number(bits), 'ipv6');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** True when an address is in Cloudflare's published edge ranges. */
|
|
65
|
+
export function isCloudflareAddress(address) {
|
|
66
|
+
const ip = String(address ?? '').trim();
|
|
67
|
+
if (!ip) return false;
|
|
68
|
+
const family = net.isIP(ip);
|
|
69
|
+
if (family === 4) return cloudflare.check(ip, 'ipv4');
|
|
70
|
+
if (family === 6) return cloudflare.check(ip, 'ipv6');
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Local interface addresses, including loopback, normalised for comparison. */
|
|
75
|
+
export function defaultLocalAddresses() {
|
|
76
|
+
const found = new Set(['127.0.0.1', '::1']);
|
|
77
|
+
try {
|
|
78
|
+
for (const entries of Object.values(os.networkInterfaces())) {
|
|
79
|
+
for (const entry of entries ?? []) {
|
|
80
|
+
if (!entry?.address) continue;
|
|
81
|
+
found.add(entry.address.split('%')[0]);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
} catch { /* an unreadable interface table is not fatal */ }
|
|
85
|
+
return [...found];
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function normaliseIp(value) {
|
|
89
|
+
return String(value ?? '').trim().replace(/^\[|\]$/g, '').split('%')[0];
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** True when `address` is one of this machine's addresses. */
|
|
93
|
+
export function isLocalAddress(address, localAddresses = defaultLocalAddresses()) {
|
|
94
|
+
const ip = normaliseIp(address);
|
|
95
|
+
if (!ip) return false;
|
|
96
|
+
const locals = localAddresses.map(normaliseIp);
|
|
97
|
+
if (locals.includes(ip)) return true;
|
|
98
|
+
// An IPv4-mapped IPv6 address still names the same local interface.
|
|
99
|
+
if (ip.startsWith('::ffff:')) return locals.includes(ip.slice(7));
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function isMissingRecord(error) {
|
|
104
|
+
return ['ENOTFOUND', 'ENODATA', 'NXDOMAIN'].includes(error?.code);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function errorText(error) {
|
|
108
|
+
if (!error) return '';
|
|
109
|
+
return error.code ? `${error.code}: ${error.message}` : error.message;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* A tiny HTTP GET that never follows a redirect and never throws.
|
|
114
|
+
*
|
|
115
|
+
* `address` connects to a specific IP while sending `Host: <hostHeader>`,
|
|
116
|
+
* which is how an AAAA record is tested without adding a second name to DNS.
|
|
117
|
+
*
|
|
118
|
+
* @returns {Promise<{ ok: boolean, status: number|null, body: string,
|
|
119
|
+
* headers: Object, error: string|null }>}
|
|
120
|
+
*/
|
|
121
|
+
export function defaultHttpGet(url, {
|
|
122
|
+
address = null,
|
|
123
|
+
hostHeader = null,
|
|
124
|
+
timeoutMs = DEFAULT_HTTP_PROBE_TIMEOUT_MS,
|
|
125
|
+
} = {}) {
|
|
126
|
+
return new Promise((resolve) => {
|
|
127
|
+
let target;
|
|
128
|
+
try {
|
|
129
|
+
target = new URL(url);
|
|
130
|
+
} catch (err) {
|
|
131
|
+
resolve({ ok: false, status: null, body: '', headers: {}, error: err.message });
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const secure = target.protocol === 'https:';
|
|
136
|
+
const transport = secure ? https : http;
|
|
137
|
+
const port = Number(target.port) || (secure ? 443 : 80);
|
|
138
|
+
const host = address ? normaliseIp(address) : target.hostname;
|
|
139
|
+
|
|
140
|
+
const req = transport.request({
|
|
141
|
+
host,
|
|
142
|
+
port,
|
|
143
|
+
path: `${target.pathname || '/'}${target.search || ''}`,
|
|
144
|
+
method: 'GET',
|
|
145
|
+
headers: { Host: hostHeader || target.host },
|
|
146
|
+
timeout: timeoutMs,
|
|
147
|
+
// A redirect is data here, not something to follow.
|
|
148
|
+
maxRedirects: 0,
|
|
149
|
+
}, (res) => {
|
|
150
|
+
let body = '';
|
|
151
|
+
res.setEncoding('utf8');
|
|
152
|
+
res.on('data', (chunk) => {
|
|
153
|
+
if (body.length < 64 * 1024) body += chunk;
|
|
154
|
+
});
|
|
155
|
+
res.on('end', () => resolve({
|
|
156
|
+
ok: true,
|
|
157
|
+
status: res.statusCode ?? null,
|
|
158
|
+
body,
|
|
159
|
+
headers: res.headers ?? {},
|
|
160
|
+
error: null,
|
|
161
|
+
}));
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
req.on('timeout', () => {
|
|
165
|
+
req.destroy();
|
|
166
|
+
resolve({ ok: false, status: null, body: '', headers: {}, error: 'timed out' });
|
|
167
|
+
});
|
|
168
|
+
req.on('error', (err) => resolve({
|
|
169
|
+
ok: false,
|
|
170
|
+
status: null,
|
|
171
|
+
body: '',
|
|
172
|
+
headers: {},
|
|
173
|
+
error: err.code || err.message,
|
|
174
|
+
}));
|
|
175
|
+
req.end();
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** Starts the loopback challenge listener for the probe token. */
|
|
180
|
+
async function defaultServeChallenge(challengePort, token, expected, fn) {
|
|
181
|
+
const { withChallengeServer } = await import('../acme-challenge.js');
|
|
182
|
+
return withChallengeServer(challengePort, async ({ setToken }) => {
|
|
183
|
+
setToken(token, expected);
|
|
184
|
+
return fn();
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function result(id, status, message, fix = '') {
|
|
189
|
+
return { id, status, message, fix };
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function readinessFix(name) {
|
|
193
|
+
return `Check the spelling of ${name}, then add an A record pointing at this server (and an AAAA record only if this server has a working IPv6 address).`;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
async function lookupName(name, { resolve4, resolve6, resolveAny }) {
|
|
197
|
+
const settle = (fn) => Promise.resolve()
|
|
198
|
+
.then(() => fn(name))
|
|
199
|
+
.then((value) => ({ value: Array.isArray(value) ? value : [], error: null }))
|
|
200
|
+
.catch((error) => ({ value: [], error }));
|
|
201
|
+
|
|
202
|
+
const [a, aaaa, any] = await Promise.all([
|
|
203
|
+
settle(resolve4),
|
|
204
|
+
settle(resolve6),
|
|
205
|
+
settle(resolveAny),
|
|
206
|
+
]);
|
|
207
|
+
return { a, aaaa, any };
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Runs every preflight check for one certificate request.
|
|
212
|
+
*
|
|
213
|
+
* @param {string} domainName
|
|
214
|
+
* @param {Object} [options]
|
|
215
|
+
* @param {boolean} [options.www]
|
|
216
|
+
* @param {'http'|'dns'} [options.validationMethod]
|
|
217
|
+
* @param {'proxy'|'standalone'|'dns'} [options.mode] How the challenge will be served
|
|
218
|
+
* @param {number} [options.challengePort] Loopback port of the challenge listener
|
|
219
|
+
* @param {number} [options.httpPort] Public HTTP port (80, except tests)
|
|
220
|
+
* @param {number} [options.httpTimeoutMs]
|
|
221
|
+
* @param {Object} [options.deps] Injected collaborators (testing only)
|
|
222
|
+
* @returns {Promise<{
|
|
223
|
+
* ok: boolean,
|
|
224
|
+
* results: Array<{id:string,status:string,message:string,fix:string}>,
|
|
225
|
+
* proxied: boolean,
|
|
226
|
+
* reachesUs: boolean,
|
|
227
|
+
* }>}
|
|
228
|
+
*/
|
|
229
|
+
export async function runPreflight(domainName, options = {}) {
|
|
230
|
+
const {
|
|
231
|
+
www = false,
|
|
232
|
+
validationMethod = 'http',
|
|
233
|
+
mode = 'proxy',
|
|
234
|
+
challengePort = 8089,
|
|
235
|
+
httpPort = 80,
|
|
236
|
+
httpTimeoutMs = DEFAULT_HTTP_PROBE_TIMEOUT_MS,
|
|
237
|
+
deps = {},
|
|
238
|
+
} = options;
|
|
239
|
+
|
|
240
|
+
const {
|
|
241
|
+
resolve4 = dnsPromises.resolve4,
|
|
242
|
+
resolve6 = dnsPromises.resolve6,
|
|
243
|
+
resolveAny = dnsPromises.resolveAny,
|
|
244
|
+
httpGet = defaultHttpGet,
|
|
245
|
+
localAddresses: localAddressesDep = defaultLocalAddresses,
|
|
246
|
+
serveChallenge = defaultServeChallenge,
|
|
247
|
+
} = deps;
|
|
248
|
+
|
|
249
|
+
// The injected value may be a function (the default) or a ready array.
|
|
250
|
+
const localAddresses = typeof localAddressesDep === 'function'
|
|
251
|
+
? localAddressesDep()
|
|
252
|
+
: localAddressesDep;
|
|
253
|
+
|
|
254
|
+
const name = String(domainName ?? '').trim().toLowerCase();
|
|
255
|
+
const names = www && name && !name.startsWith('*.') ? [name, `www.${name}`] : [name];
|
|
256
|
+
const results = [];
|
|
257
|
+
let proxied = false;
|
|
258
|
+
let reachesUs = false;
|
|
259
|
+
|
|
260
|
+
const lookups = new Map();
|
|
261
|
+
for (const candidate of names) {
|
|
262
|
+
const lookup = candidate.startsWith('*.') ? candidate.slice(2) : candidate;
|
|
263
|
+
lookups.set(candidate, await lookupName(lookup, { resolve4, resolve6, resolveAny }));
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// ── a. The name resolves at all ───────────────────────────────────────────
|
|
267
|
+
for (const candidate of names) {
|
|
268
|
+
const { a, aaaa, any } = lookups.get(candidate);
|
|
269
|
+
const noAddress = a.value.length === 0 && aaaa.value.length === 0;
|
|
270
|
+
|
|
271
|
+
if (noAddress) {
|
|
272
|
+
const allMissing = [a, aaaa, any].every((r) => r.error && isMissingRecord(r.error));
|
|
273
|
+
const unexpected = [a, aaaa, any].find((r) => r.error && !isMissingRecord(r.error));
|
|
274
|
+
if (allMissing) {
|
|
275
|
+
results.push(result(
|
|
276
|
+
`dns:${candidate}`,
|
|
277
|
+
'fail',
|
|
278
|
+
`${candidate} has no DNS record`,
|
|
279
|
+
readinessFix(candidate),
|
|
280
|
+
));
|
|
281
|
+
} else if (unexpected) {
|
|
282
|
+
results.push(result(
|
|
283
|
+
`dns:${candidate}`,
|
|
284
|
+
'fail',
|
|
285
|
+
`DNS lookup for ${candidate} failed: ${errorText(unexpected.error)}`,
|
|
286
|
+
readinessFix(candidate),
|
|
287
|
+
));
|
|
288
|
+
} else {
|
|
289
|
+
results.push(result(
|
|
290
|
+
`dns:${candidate}`,
|
|
291
|
+
'fail',
|
|
292
|
+
`${candidate} has DNS records but no A or AAAA address`,
|
|
293
|
+
readinessFix(candidate),
|
|
294
|
+
));
|
|
295
|
+
}
|
|
296
|
+
continue;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
results.push(result(
|
|
300
|
+
`dns:${candidate}`,
|
|
301
|
+
'ok',
|
|
302
|
+
`${candidate} resolves to ${[...a.value, ...aaaa.value].join(', ')}`,
|
|
303
|
+
));
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// ── b. Classify every address ─────────────────────────────────────────────
|
|
307
|
+
for (const candidate of names) {
|
|
308
|
+
const { a, aaaa } = lookups.get(candidate);
|
|
309
|
+
|
|
310
|
+
for (const ip of a.value) {
|
|
311
|
+
if (isLocalAddress(ip, localAddresses)) {
|
|
312
|
+
results.push(result(
|
|
313
|
+
`a:${candidate}:${ip}`, 'ok',
|
|
314
|
+
`${candidate} points at this server (${ip})`,
|
|
315
|
+
));
|
|
316
|
+
} else if (isCloudflareAddress(ip)) {
|
|
317
|
+
proxied = true;
|
|
318
|
+
results.push(result(
|
|
319
|
+
`a:${candidate}:${ip}`, 'ok',
|
|
320
|
+
`${candidate} is proxied by Cloudflare (${ip})`,
|
|
321
|
+
));
|
|
322
|
+
} else {
|
|
323
|
+
results.push(result(
|
|
324
|
+
`a:${candidate}:${ip}`, 'warn',
|
|
325
|
+
`${candidate} points to ${ip}, which is not this server`,
|
|
326
|
+
`Point the A record at this server, or put Cloudflare in front of ${candidate}.`,
|
|
327
|
+
));
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
for (const ip of aaaa.value) {
|
|
332
|
+
if (isLocalAddress(ip, localAddresses)) {
|
|
333
|
+
results.push(result(
|
|
334
|
+
`aaaa:${candidate}:${ip}`, 'ok',
|
|
335
|
+
`${candidate} points at this server over IPv6 (${ip})`,
|
|
336
|
+
));
|
|
337
|
+
} else if (isCloudflareAddress(ip)) {
|
|
338
|
+
proxied = true;
|
|
339
|
+
results.push(result(
|
|
340
|
+
`aaaa:${candidate}:${ip}`, 'ok',
|
|
341
|
+
`${candidate} is proxied by Cloudflare over IPv6 (${ip})`,
|
|
342
|
+
));
|
|
343
|
+
} else {
|
|
344
|
+
// Filled in by check c once the probe has run.
|
|
345
|
+
results.push(result(
|
|
346
|
+
`aaaa:${candidate}:${ip}`, 'warn',
|
|
347
|
+
`${candidate} has an AAAA record (${ip}) that has not been probed yet`,
|
|
348
|
+
`Remove the AAAA record, or point it at this server. Let's Encrypt prefers IPv6.`,
|
|
349
|
+
));
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// ── c/d. Port 80 and the IPv6 address, through the real public path ───────
|
|
355
|
+
const httpChecks = [];
|
|
356
|
+
if (validationMethod === 'dns') {
|
|
357
|
+
httpChecks.push(result(
|
|
358
|
+
'aaaa', 'skipped',
|
|
359
|
+
'DNS-01 validation does not use port 80, so IPv6 reachability is not checked',
|
|
360
|
+
));
|
|
361
|
+
httpChecks.push(result(
|
|
362
|
+
'http', 'skipped',
|
|
363
|
+
'DNS-01 validation does not use the HTTP challenge',
|
|
364
|
+
));
|
|
365
|
+
} else if (mode === 'standalone') {
|
|
366
|
+
httpChecks.push(result(
|
|
367
|
+
'aaaa', 'skipped',
|
|
368
|
+
'Standalone mode binds port 80 directly; the public HTTP probe runs during the challenge',
|
|
369
|
+
));
|
|
370
|
+
httpChecks.push(result(
|
|
371
|
+
'http', 'skipped',
|
|
372
|
+
'Standalone mode binds port 80 directly; nginx is not in the path',
|
|
373
|
+
));
|
|
374
|
+
} else {
|
|
375
|
+
const probeToken = `easy-devops-preflight-${Date.now()}-${Math.random().toString(36).slice(2, 12)}`;
|
|
376
|
+
const expected = `${probeToken}.preflight`;
|
|
377
|
+
const challengePath = `${ACME_CHALLENGE_PATH}${probeToken}`;
|
|
378
|
+
const publicResults = [];
|
|
379
|
+
const aaaaReachable = new Set();
|
|
380
|
+
|
|
381
|
+
const probe = async (candidate) => {
|
|
382
|
+
// c. An AAAA that is not one of ours must actually answer on this host.
|
|
383
|
+
const { aaaa } = lookups.get(candidate);
|
|
384
|
+
for (const ip of aaaa.value) {
|
|
385
|
+
if (isLocalAddress(ip, localAddresses) || isCloudflareAddress(ip)) continue;
|
|
386
|
+
const res = await httpGet(`http://${candidate}:${httpPort}${challengePath}`, {
|
|
387
|
+
address: ip,
|
|
388
|
+
hostHeader: candidate,
|
|
389
|
+
timeoutMs: httpTimeoutMs,
|
|
390
|
+
});
|
|
391
|
+
if (res.ok && res.status === 200 && res.body === expected) {
|
|
392
|
+
aaaaReachable.add(`${candidate}:${ip}`);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
// d. The ordinary public path, exactly as Let's Encrypt will use it.
|
|
397
|
+
return httpGet(`http://${candidate}:${httpPort}${challengePath}`, {
|
|
398
|
+
hostHeader: candidate,
|
|
399
|
+
timeoutMs: httpTimeoutMs,
|
|
400
|
+
});
|
|
401
|
+
};
|
|
402
|
+
|
|
403
|
+
let responses = new Map();
|
|
404
|
+
try {
|
|
405
|
+
responses = await serveChallenge(challengePort, probeToken, expected, async () => {
|
|
406
|
+
const out = new Map();
|
|
407
|
+
for (const candidate of names) out.set(candidate, await probe(candidate));
|
|
408
|
+
return out;
|
|
409
|
+
});
|
|
410
|
+
} catch (err) {
|
|
411
|
+
httpChecks.push(result(
|
|
412
|
+
'http', 'fail',
|
|
413
|
+
`The challenge listener could not start: ${errorText(err)}`,
|
|
414
|
+
`Stop whatever is using port ${challengePort}, or change acmeChallengePort in Settings.`,
|
|
415
|
+
));
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
// Rewrite the AAAA warnings that the probe resolved.
|
|
419
|
+
for (let i = 0; i < results.length; i += 1) {
|
|
420
|
+
const entry = results[i];
|
|
421
|
+
if (!entry.id.startsWith('aaaa:') || entry.status !== 'warn') continue;
|
|
422
|
+
const candidate = entry.id.split(':')[1];
|
|
423
|
+
const ip = entry.id.slice(`aaaa:${candidate}:`.length);
|
|
424
|
+
if (aaaaReachable.has(`${candidate}:${ip}`)) {
|
|
425
|
+
results[i] = result(
|
|
426
|
+
entry.id, 'ok',
|
|
427
|
+
`${candidate} reaches this server over IPv6 (${ip})`,
|
|
428
|
+
);
|
|
429
|
+
} else {
|
|
430
|
+
results[i] = result(
|
|
431
|
+
entry.id, 'fail',
|
|
432
|
+
`${candidate} has an AAAA record (${ip}) that does not reach this server; Let's Encrypt prefers IPv6`,
|
|
433
|
+
`Remove the AAAA record for ${candidate}, or point it at this server.`,
|
|
434
|
+
);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
for (const candidate of names) {
|
|
439
|
+
const res = responses.get(candidate);
|
|
440
|
+
if (!res) continue;
|
|
441
|
+
const label = `http:${candidate}`;
|
|
442
|
+
|
|
443
|
+
if (res.ok && res.status === 200 && res.body === expected) {
|
|
444
|
+
reachesUs = true;
|
|
445
|
+
publicResults.push(result(label, 'ok', `http://${candidate}/ answers this server on port 80`));
|
|
446
|
+
continue;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
if (res.ok && res.status >= 300 && res.status < 400) {
|
|
450
|
+
publicResults.push(result(
|
|
451
|
+
label, 'fail',
|
|
452
|
+
`Cloudflare 'Always Use HTTPS' or a redirect sends Let's Encrypt to https for ${candidate}`,
|
|
453
|
+
`Turn off Cloudflare 'Always Use HTTPS' (or the port-80 redirect) for ${candidate} so /.well-known/acme-challenge/ stays on HTTP.`,
|
|
454
|
+
));
|
|
455
|
+
continue;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
if (res.error === 'ECONNREFUSED' || res.error === 'timed out' || /ECONNREFUSED|EHOSTUNREACH|ETIMEDOUT|timeout/i.test(res.error ?? '')) {
|
|
459
|
+
publicResults.push(result(
|
|
460
|
+
label, 'fail',
|
|
461
|
+
`port 80 is closed or blocked for ${candidate}`,
|
|
462
|
+
`Open port 80 in the firewall or security group and make sure nginx is running for ${candidate}.`,
|
|
463
|
+
));
|
|
464
|
+
continue;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
if (!res.ok) {
|
|
468
|
+
publicResults.push(result(
|
|
469
|
+
label, 'fail',
|
|
470
|
+
`could not reach ${candidate} on port 80: ${res.error}`,
|
|
471
|
+
`Check that the DNS record points at this server and that port 80 is open.`,
|
|
472
|
+
));
|
|
473
|
+
continue;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
publicResults.push(result(
|
|
477
|
+
label, 'fail',
|
|
478
|
+
`another server answers for ${candidate} (HTTP ${res.status})`,
|
|
479
|
+
`Point the DNS A/AAAA record at this server, and check that nothing else is listening on port 80.`,
|
|
480
|
+
));
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
httpChecks.push(...publicResults);
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
results.push(...httpChecks);
|
|
487
|
+
|
|
488
|
+
const ok = !results.some((entry) => entry.status === 'fail');
|
|
489
|
+
return { ok, results, proxied, reachesUs };
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
/** One-line summary for a failed preflight, without exposing secrets. */
|
|
493
|
+
export function summarizePreflight(preflightResult) {
|
|
494
|
+
if (!preflightResult) return '';
|
|
495
|
+
const failed = (preflightResult.results ?? []).filter((entry) => entry.status === 'fail');
|
|
496
|
+
if (failed.length === 0) return '';
|
|
497
|
+
return failed.map((entry) => `${entry.message}${entry.fix ? ` — ${entry.fix}` : ''}`).join(' ');
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
/**
|
|
501
|
+
* A one-line fix for the common ACME failures. Kept next to the preflight so
|
|
502
|
+
* every caller reports the same next step, and so a rate limit names how long
|
|
503
|
+
* to wait rather than only that it happened.
|
|
504
|
+
*
|
|
505
|
+
* @param {string} message
|
|
506
|
+
* @param {string} [domain]
|
|
507
|
+
* @returns {string}
|
|
508
|
+
*/
|
|
509
|
+
export function fixForAcmeError(message, domain = '') {
|
|
510
|
+
const text = String(message ?? '');
|
|
511
|
+
const target = domain || 'the domain';
|
|
512
|
+
|
|
513
|
+
const retry = text.match(/retry[\s-]*after\s*:?\s*(\d+)/i);
|
|
514
|
+
if (retry) {
|
|
515
|
+
const seconds = Number(retry[1]);
|
|
516
|
+
const hours = Math.floor(seconds / 3600);
|
|
517
|
+
const minutes = Math.floor((seconds % 3600) / 60);
|
|
518
|
+
const human = hours > 0 ? `${hours}h ${minutes}m` : `${minutes}m`;
|
|
519
|
+
return `Let's Encrypt is rate limiting this name. Wait ${seconds}s (${human}) before trying again.`;
|
|
520
|
+
}
|
|
521
|
+
const retryDate = text.match(/retry[\s-]*after\s*:?\s*(\d{4}-\d\d-\d\dT[^\s,;]+)/i);
|
|
522
|
+
if (retryDate) {
|
|
523
|
+
const when = new Date(retryDate[1]);
|
|
524
|
+
if (!Number.isNaN(when.getTime())) {
|
|
525
|
+
const seconds = Math.max(1, Math.round((when.getTime() - Date.now()) / 1000));
|
|
526
|
+
return `Let's Encrypt is rate limiting this name. Wait about ${seconds}s (until ${when.toISOString()}) before trying again.`;
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
if (/too many certificates|rate.?limit|urn:ietf:params:acme:error:rateLimited/i.test(text)) {
|
|
530
|
+
return "Let's Encrypt is rate limiting this name. Wait before trying again — the limit is per registered domain and per account.";
|
|
531
|
+
}
|
|
532
|
+
if (/NXDOMAIN|no DNS record|ENOTFOUND|ENODATA/i.test(text)) {
|
|
533
|
+
return `Add an A record for ${target} pointing at this server, then try again.`;
|
|
534
|
+
}
|
|
535
|
+
if (/AAAA|IPv6/i.test(text)) {
|
|
536
|
+
return `Remove the AAAA record for ${target}, or point it at this server. Let's Encrypt prefers IPv6.`;
|
|
537
|
+
}
|
|
538
|
+
if (/always use https|redirect/i.test(text)) {
|
|
539
|
+
return `Turn off Cloudflare 'Always Use HTTPS' (or the port-80 redirect) for ${target}.`;
|
|
540
|
+
}
|
|
541
|
+
if (/ECONNREFUSED|port 80|timeout|timed out/i.test(text)) {
|
|
542
|
+
return `Open port 80 in the firewall or security group and make sure nginx is running for ${target}.`;
|
|
543
|
+
}
|
|
544
|
+
if (/unauthorized|incorrect response|wrong server/i.test(text)) {
|
|
545
|
+
return `Check that ${target} points at this server and that nothing else answers on port 80.`;
|
|
546
|
+
}
|
|
547
|
+
return `Check the DNS records for ${target} and that port 80 reaches this server, then try again.`;
|
|
548
|
+
}
|