cfpilot 0.33.7 → 0.40.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/assets/control.js +17 -17
- package/assets/dataplane.js +5 -5
- package/assets/worker.js +21 -21
- package/dist/cli.js +76 -37
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -87,7 +87,7 @@ var VERSION, NAME;
|
|
|
87
87
|
var init_version = __esm({
|
|
88
88
|
"src/shared/version.ts"() {
|
|
89
89
|
"use strict";
|
|
90
|
-
VERSION = "0.
|
|
90
|
+
VERSION = "0.40.0";
|
|
91
91
|
NAME = "cfpilot";
|
|
92
92
|
}
|
|
93
93
|
});
|
|
@@ -1836,11 +1836,18 @@ function versionFromTag(tag) {
|
|
|
1836
1836
|
for (const prefix of ["desktop-v", "gui-v", "v"]) {
|
|
1837
1837
|
if (text2.startsWith(prefix)) {
|
|
1838
1838
|
const rest = text2.slice(prefix.length);
|
|
1839
|
-
|
|
1839
|
+
const m = /^(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?)$/.exec(rest);
|
|
1840
|
+
return m ? m[1] : "";
|
|
1840
1841
|
}
|
|
1841
1842
|
}
|
|
1842
1843
|
return "";
|
|
1843
1844
|
}
|
|
1845
|
+
function isSafeReleaseTag(tag) {
|
|
1846
|
+
return /^(?:desktop-v|gui-v|v)\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/.test(tag);
|
|
1847
|
+
}
|
|
1848
|
+
function officialAssetUrl(tag, assetName) {
|
|
1849
|
+
return `${RELEASES_WEB}/download/${tag}/${assetName}`;
|
|
1850
|
+
}
|
|
1844
1851
|
async function fetchRemoteKernelInfo(options = {}) {
|
|
1845
1852
|
if (isRemoteDisabled()) return null;
|
|
1846
1853
|
const releases = await fetchReleasesWithFallback(options.timeoutMs ?? DEFAULT_TIMEOUT_MS);
|
|
@@ -1849,13 +1856,18 @@ async function fetchRemoteKernelInfo(options = {}) {
|
|
|
1849
1856
|
}
|
|
1850
1857
|
const sorted = releases.filter((release) => !release.draft && !release.prerelease).map((release) => ({ release, version: versionFromTag(release.tag_name) })).filter((item) => item.version !== "").sort((a, b) => compareSemver(b.version, a.version));
|
|
1851
1858
|
for (const item of sorted) {
|
|
1852
|
-
const
|
|
1853
|
-
|
|
1854
|
-
const checksumsUrl = findAssetUrl(item.release.assets ?? [], CHECKSUMS_ASSET_NAME);
|
|
1855
|
-
if (!controlUrl || !dataUrl) {
|
|
1859
|
+
const assets = item.release.assets ?? [];
|
|
1860
|
+
if (!hasAsset(assets, CONTROL_ASSET_NAME) || !hasAsset(assets, DATA_ASSET_NAME)) {
|
|
1856
1861
|
continue;
|
|
1857
1862
|
}
|
|
1858
|
-
|
|
1863
|
+
const tag = item.release.tag_name.trim();
|
|
1864
|
+
if (!isSafeReleaseTag(tag)) continue;
|
|
1865
|
+
return {
|
|
1866
|
+
version: item.version,
|
|
1867
|
+
controlUrl: officialAssetUrl(tag, CONTROL_ASSET_NAME),
|
|
1868
|
+
dataUrl: officialAssetUrl(tag, DATA_ASSET_NAME),
|
|
1869
|
+
checksumsUrl: officialAssetUrl(tag, CHECKSUMS_ASSET_NAME)
|
|
1870
|
+
};
|
|
1859
1871
|
}
|
|
1860
1872
|
return null;
|
|
1861
1873
|
}
|
|
@@ -1897,12 +1909,9 @@ async function fetchReleasesWithFallback(timeoutMs) {
|
|
|
1897
1909
|
};
|
|
1898
1910
|
return [pseudo];
|
|
1899
1911
|
}
|
|
1900
|
-
function
|
|
1912
|
+
function hasAsset(assets, name) {
|
|
1901
1913
|
const want = name.trim().toLowerCase();
|
|
1902
|
-
|
|
1903
|
-
if (asset.name.trim().toLowerCase() === want) return asset.browser_download_url;
|
|
1904
|
-
}
|
|
1905
|
-
return "";
|
|
1914
|
+
return assets.some((asset) => asset.name.trim().toLowerCase() === want);
|
|
1906
1915
|
}
|
|
1907
1916
|
function isRemoteDisabled() {
|
|
1908
1917
|
const raw = process.env[REMOTE_OFF_ENV]?.trim().toLowerCase();
|
|
@@ -2114,15 +2123,7 @@ async function fetchRemoteKernel(info, timeoutMs) {
|
|
|
2114
2123
|
const dir = cacheDir(info.version);
|
|
2115
2124
|
const controlPath = join2(dir, "control.js");
|
|
2116
2125
|
const dataPath = join2(dir, "dataplane.js");
|
|
2117
|
-
const
|
|
2118
|
-
let sumsText = await readCached(sumsPath);
|
|
2119
|
-
let sums = sumsText ? parseChecksums(sumsText) : null;
|
|
2120
|
-
const sumsComplete = sums !== null && sums.has(CONTROL_ASSET_NAME.toLowerCase()) && sums.has(DATA_ASSET_NAME.toLowerCase());
|
|
2121
|
-
if (!sums || !sumsComplete) {
|
|
2122
|
-
const fetched = await downloadChecksums(info, timeoutMs);
|
|
2123
|
-
sumsText = fetched.text;
|
|
2124
|
-
sums = fetched.map;
|
|
2125
|
-
}
|
|
2126
|
+
const { map: sums } = await downloadChecksums(info, timeoutMs);
|
|
2126
2127
|
let control = await readCached(controlPath);
|
|
2127
2128
|
let data = await readCached(dataPath);
|
|
2128
2129
|
if (control) {
|
|
@@ -2148,7 +2149,6 @@ async function fetchRemoteKernel(info, timeoutMs) {
|
|
|
2148
2149
|
verifyAsset("dataplane.js", data, sums);
|
|
2149
2150
|
if (!control.trim()) throw new Error("\u4E0B\u8F7D\u5230\u7684\u63A7\u5236\u9762\u4EA7\u7269\u4E3A\u7A7A");
|
|
2150
2151
|
if (!data.trim()) throw new Error("\u4E0B\u8F7D\u5230\u7684\u6570\u636E\u9762\u4EA7\u7269\u4E3A\u7A7A");
|
|
2151
|
-
await writeCached(sumsPath, sumsText).catch(() => void 0);
|
|
2152
2152
|
await writeCached(controlPath, control).catch(() => void 0);
|
|
2153
2153
|
await writeCached(dataPath, data).catch(() => void 0);
|
|
2154
2154
|
return { control, data };
|
|
@@ -2535,7 +2535,8 @@ async function deployPagesSplit(options) {
|
|
|
2535
2535
|
const result = {
|
|
2536
2536
|
control: { name: options.controlProject, subdomain: "" },
|
|
2537
2537
|
data: { name: options.dataProject, subdomain: "" },
|
|
2538
|
-
warnings
|
|
2538
|
+
warnings,
|
|
2539
|
+
success: true
|
|
2539
2540
|
};
|
|
2540
2541
|
const kv = { KV: { namespace_id: options.kvNamespaceId } };
|
|
2541
2542
|
const kernel = await resolveKernel(options, log, warnings);
|
|
@@ -2785,6 +2786,7 @@ async function deployPagesSplit(options) {
|
|
|
2785
2786
|
});
|
|
2786
2787
|
if (!dataAttempt) {
|
|
2787
2788
|
warnings.push("\u6570\u636E\u9762\u90E8\u7F72\u5931\u8D25\uFF0C\u5DF2\u4E2D\u6B62\u672C\u6B21\u90E8\u7F72\uFF08\u63A7\u5236\u9762\u4E0D\u518D\u90E8\u7F72\uFF09\u3002");
|
|
2789
|
+
result.success = false;
|
|
2788
2790
|
return result;
|
|
2789
2791
|
}
|
|
2790
2792
|
{
|
|
@@ -2847,8 +2849,10 @@ async function deployPagesSplit(options) {
|
|
|
2847
2849
|
if (controlAttempt) {
|
|
2848
2850
|
result.control.name = controlAttempt.project ?? controlName;
|
|
2849
2851
|
result.control.subdomain = controlAttempt.subdomain;
|
|
2852
|
+
} else {
|
|
2853
|
+
result.success = false;
|
|
2850
2854
|
}
|
|
2851
|
-
if (result.control.subdomain && result.data.subdomain) {
|
|
2855
|
+
if (result.success !== false && result.control.subdomain && result.data.subdomain) {
|
|
2852
2856
|
const build = effectiveBuild;
|
|
2853
2857
|
const kernelVersion = kernel.version.trim();
|
|
2854
2858
|
await writeManifest(client, options.accountId, options.kvNamespaceId, {
|
|
@@ -2968,7 +2972,7 @@ async function deployOnce(params) {
|
|
|
2968
2972
|
return { project: name, subdomain: slot.subdomain, deploymentId: deployment.id };
|
|
2969
2973
|
}
|
|
2970
2974
|
warnings.push(`${label}\u90E8\u7F72\u672A\u786E\u8BA4\u6210\u529F\uFF08\u9879\u76EE ${name}\uFF0C\u72B6\u6001\uFF1A${final?.latest_stage?.status ?? "\u672A\u77E5"}\uFF09`);
|
|
2971
|
-
return
|
|
2975
|
+
return null;
|
|
2972
2976
|
} catch (err) {
|
|
2973
2977
|
const message = err instanceof Error ? err.message : String(err);
|
|
2974
2978
|
const blocked = /8000119|has been blocked/i.test(message);
|
|
@@ -3350,9 +3354,11 @@ async function runDeployCommand(args) {
|
|
|
3350
3354
|
process.stdout.write(`
|
|
3351
3355
|
${"\u2500".repeat(52)}
|
|
3352
3356
|
`);
|
|
3353
|
-
|
|
3357
|
+
if (result.control.subdomain) {
|
|
3358
|
+
process.stdout.write(`\u63A7\u5236\u9762\uFF1Ahttps://${result.control.subdomain}${result.panelPath ?? ""}
|
|
3354
3359
|
`);
|
|
3355
|
-
|
|
3360
|
+
}
|
|
3361
|
+
if (result.data.subdomain) process.stdout.write(`\u6570\u636E\u9762\uFF1Ahttps://${result.data.subdomain}
|
|
3356
3362
|
`);
|
|
3357
3363
|
if (result.uuid) process.stdout.write(`UUID\uFF1A${result.uuid}
|
|
3358
3364
|
`);
|
|
@@ -3360,8 +3366,15 @@ ${"\u2500".repeat(52)}
|
|
|
3360
3366
|
`);
|
|
3361
3367
|
if (result.panelPassword) process.stdout.write(`\u9762\u677F\u5BC6\u7801\uFF1A${result.panelPassword}
|
|
3362
3368
|
`);
|
|
3363
|
-
|
|
3369
|
+
const deploySucceeded = result.success !== false;
|
|
3370
|
+
if (deploySucceeded) {
|
|
3371
|
+
process.stdout.write(`\u2705 \u90E8\u7F72\u6210\u529F
|
|
3372
|
+
`);
|
|
3373
|
+
} else {
|
|
3374
|
+
process.exitCode = 1;
|
|
3375
|
+
process.stdout.write(`\u274C \u90E8\u7F72\u672A\u5B8C\u6210
|
|
3364
3376
|
`);
|
|
3377
|
+
}
|
|
3365
3378
|
if (result.warnings.length > 0) {
|
|
3366
3379
|
process.stdout.write(`
|
|
3367
3380
|
\u544A\u8B66\uFF08${result.warnings.length} \u6761\uFF09\uFF1A
|
|
@@ -4132,11 +4145,13 @@ function measureThroughput(options) {
|
|
|
4132
4145
|
let lastError = "";
|
|
4133
4146
|
let headerMismatch = false;
|
|
4134
4147
|
const sockets = [];
|
|
4148
|
+
const staggerTimers = [];
|
|
4135
4149
|
const finish = () => {
|
|
4136
4150
|
if (settled) return;
|
|
4137
4151
|
settled = true;
|
|
4138
4152
|
clearInterval(ticker);
|
|
4139
4153
|
clearTimeout(timer);
|
|
4154
|
+
for (const handle of staggerTimers) clearTimeout(handle);
|
|
4140
4155
|
for (const s of sockets) {
|
|
4141
4156
|
try {
|
|
4142
4157
|
s.destroy();
|
|
@@ -4176,6 +4191,7 @@ function measureThroughput(options) {
|
|
|
4176
4191
|
""
|
|
4177
4192
|
].join("\r\n");
|
|
4178
4193
|
const openOne = () => {
|
|
4194
|
+
if (settled) return;
|
|
4179
4195
|
let headerDone = false;
|
|
4180
4196
|
let headerBuffer = Buffer.alloc(0);
|
|
4181
4197
|
const socket = tls.connect(
|
|
@@ -4247,7 +4263,8 @@ function measureThroughput(options) {
|
|
|
4247
4263
|
}, windowMs);
|
|
4248
4264
|
const timer = setTimeout(finish, durationMs + 4e3);
|
|
4249
4265
|
for (let i = 0; i < connCount; i++) {
|
|
4250
|
-
setTimeout(openOne, i * 60);
|
|
4266
|
+
const handle = setTimeout(openOne, i * 60);
|
|
4267
|
+
staggerTimers.push(handle);
|
|
4251
4268
|
}
|
|
4252
4269
|
});
|
|
4253
4270
|
}
|
|
@@ -6205,11 +6222,13 @@ async function postResults(callbackUrl, token, entries, mode = "replace", timeou
|
|
|
6205
6222
|
"User-Agent": "CFPilot-Scanner/1.0"
|
|
6206
6223
|
},
|
|
6207
6224
|
body: JSON.stringify({ ips: entries, mode }),
|
|
6208
|
-
signal: AbortSignal.timeout(timeoutMs)
|
|
6225
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
6226
|
+
// callback 来自本地桥接请求,禁止自动跟随到内网或其它主机,
|
|
6227
|
+
// 避免把 Bearer 令牌转发给重定向目标。
|
|
6228
|
+
redirect: "manual"
|
|
6209
6229
|
});
|
|
6210
6230
|
if (!response.ok) {
|
|
6211
|
-
|
|
6212
|
-
return { ok: false, status: response.status, error: `\u56DE\u4F20\u5931\u8D25 HTTP ${response.status} ${text2}`.trim() };
|
|
6231
|
+
return { ok: false, status: response.status, error: `\u56DE\u4F20\u5931\u8D25 HTTP ${response.status}` };
|
|
6213
6232
|
}
|
|
6214
6233
|
return { ok: true, status: response.status };
|
|
6215
6234
|
} catch (err) {
|
|
@@ -7395,6 +7414,7 @@ __export(server_exports, {
|
|
|
7395
7414
|
validateCallbackUrl: () => validateCallbackUrl
|
|
7396
7415
|
});
|
|
7397
7416
|
import { createServer } from "node:http";
|
|
7417
|
+
import { randomBytes as randomBytes4 } from "node:crypto";
|
|
7398
7418
|
function normalizeSample(value) {
|
|
7399
7419
|
if (typeof value === "number" && Number.isFinite(value) && value > 0) {
|
|
7400
7420
|
return Math.min(Math.floor(value), DEFAULT_CANDIDATE_SAMPLE);
|
|
@@ -7484,8 +7504,18 @@ function sendJson(res, status2, data) {
|
|
|
7484
7504
|
res.end(body);
|
|
7485
7505
|
}
|
|
7486
7506
|
async function readBody(req) {
|
|
7507
|
+
const declared = Number(req.headers["content-length"] ?? 0);
|
|
7508
|
+
if (Number.isFinite(declared) && declared > MAX_BRIDGE_BODY_BYTES) {
|
|
7509
|
+
throw new Error("\u8BF7\u6C42\u4F53\u8D85\u8FC7 2MiB \u4E0A\u9650");
|
|
7510
|
+
}
|
|
7487
7511
|
const chunks = [];
|
|
7488
|
-
|
|
7512
|
+
let total = 0;
|
|
7513
|
+
for await (const chunk of req) {
|
|
7514
|
+
const part = chunk;
|
|
7515
|
+
total += part.byteLength;
|
|
7516
|
+
if (total > MAX_BRIDGE_BODY_BYTES) throw new Error("\u8BF7\u6C42\u4F53\u8D85\u8FC7 2MiB \u4E0A\u9650");
|
|
7517
|
+
chunks.push(part);
|
|
7518
|
+
}
|
|
7489
7519
|
return Buffer.concat(chunks).toString("utf8");
|
|
7490
7520
|
}
|
|
7491
7521
|
function parseStartScanRequest(text2) {
|
|
@@ -7547,8 +7577,9 @@ function broadcast(job, event) {
|
|
|
7547
7577
|
function startBridge(options = {}) {
|
|
7548
7578
|
const host = options.host ?? "127.0.0.1";
|
|
7549
7579
|
const port = options.port ?? DEFAULT_BRIDGE_PORT;
|
|
7580
|
+
const token = randomBytes4(24).toString("hex");
|
|
7550
7581
|
const server = createServer((req, res) => {
|
|
7551
|
-
void handleRequest(req, res).catch((err) => {
|
|
7582
|
+
void handleRequest(req, res, token).catch((err) => {
|
|
7552
7583
|
sendJson(res, 500, { ok: false, error: err instanceof Error ? err.message : String(err) });
|
|
7553
7584
|
});
|
|
7554
7585
|
});
|
|
@@ -7560,6 +7591,7 @@ function startBridge(options = {}) {
|
|
|
7560
7591
|
resolve4({
|
|
7561
7592
|
server,
|
|
7562
7593
|
port: boundPort,
|
|
7594
|
+
token,
|
|
7563
7595
|
close: () => new Promise((done) => {
|
|
7564
7596
|
for (const job of jobs.values()) {
|
|
7565
7597
|
for (const subscriber of job.subscribers) subscriber.end();
|
|
@@ -7571,8 +7603,12 @@ function startBridge(options = {}) {
|
|
|
7571
7603
|
});
|
|
7572
7604
|
});
|
|
7573
7605
|
}
|
|
7574
|
-
async function handleRequest(req, res) {
|
|
7606
|
+
async function handleRequest(req, res, bridgeToken) {
|
|
7575
7607
|
const url = new URL(req.url ?? "/", `http://${req.headers.host ?? "127.0.0.1"}`);
|
|
7608
|
+
if (req.headers[BRIDGE_TOKEN_HEADER] !== bridgeToken) {
|
|
7609
|
+
sendJson(res, 401, { ok: false, error: "\u6865\u63A5\u670D\u52A1\u672A\u6388\u6743" });
|
|
7610
|
+
return;
|
|
7611
|
+
}
|
|
7576
7612
|
if (req.method === "OPTIONS") {
|
|
7577
7613
|
res.writeHead(204, corsHeaders());
|
|
7578
7614
|
res.end();
|
|
@@ -7726,7 +7762,7 @@ async function handleRequest(req, res) {
|
|
|
7726
7762
|
}
|
|
7727
7763
|
sendJson(res, 404, { ok: false, error: "\u63A5\u53E3\u4E0D\u5B58\u5728" });
|
|
7728
7764
|
}
|
|
7729
|
-
var BRIDGE_VERSION, DEFAULT_BRIDGE_PORT, jobs, jobCounter, JOB_TTL_MS, MAX_JOBS;
|
|
7765
|
+
var BRIDGE_VERSION, DEFAULT_BRIDGE_PORT, jobs, jobCounter, JOB_TTL_MS, MAX_JOBS, MAX_BRIDGE_BODY_BYTES, BRIDGE_TOKEN_HEADER;
|
|
7730
7766
|
var init_server = __esm({
|
|
7731
7767
|
"src/scan/server.ts"() {
|
|
7732
7768
|
"use strict";
|
|
@@ -7739,6 +7775,8 @@ var init_server = __esm({
|
|
|
7739
7775
|
jobCounter = 0;
|
|
7740
7776
|
JOB_TTL_MS = 10 * 60 * 1e3;
|
|
7741
7777
|
MAX_JOBS = 5;
|
|
7778
|
+
MAX_BRIDGE_BODY_BYTES = 2 * 1024 * 1024;
|
|
7779
|
+
BRIDGE_TOKEN_HEADER = "x-cfpilot-bridge-token";
|
|
7742
7780
|
}
|
|
7743
7781
|
});
|
|
7744
7782
|
|
|
@@ -9508,7 +9546,8 @@ async function runScanCommand(args) {
|
|
|
9508
9546
|
` ${NAME} \u672C\u5730\u6865\u63A5\u670D\u52A1\u5DF2\u542F\u52A8`,
|
|
9509
9547
|
` \u76D1\u542C\u5730\u5740\uFF1Ahttp://${host2}:${handle.port}`,
|
|
9510
9548
|
` \u7248\u672C\uFF1Av${BRIDGE_VERSION2}`,
|
|
9511
|
-
|
|
9549
|
+
` \u6865\u63A5\u4EE4\u724C\uFF1A${handle.token}`,
|
|
9550
|
+
" \u53EF\u7528 HTTP \u63A5\u53E3\uFF1AGET /status\u3001POST /start-scan\u3001GET /events\u3001GET /results\uFF08\u8BF7\u6C42\u5934 x-cfpilot-bridge-token\uFF09",
|
|
9512
9551
|
" \u6309 Ctrl+C \u9000\u51FA\u3002",
|
|
9513
9552
|
""
|
|
9514
9553
|
].join("\n")
|