cfpilot 0.15.0 → 0.15.3
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 +2 -2
- package/assets/dataplane.js +5 -5
- package/assets/relay-ip-builtin.txt +200 -0
- package/assets/worker.js +17 -17
- package/dist/cli.js +367 -75
- 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.15.
|
|
90
|
+
VERSION = "0.15.3";
|
|
91
91
|
NAME = "cfpilot";
|
|
92
92
|
}
|
|
93
93
|
});
|
|
@@ -193,7 +193,7 @@ async function ask(question, options = {}) {
|
|
|
193
193
|
}
|
|
194
194
|
const suffix = fallback ? c.gray(` [${fallback}]`) : "";
|
|
195
195
|
stdout.write(`${c.cyan("?")} ${question}${suffix}${c.gray(": ")}`);
|
|
196
|
-
return await new Promise((
|
|
196
|
+
return await new Promise((resolve4) => {
|
|
197
197
|
let buf = "";
|
|
198
198
|
const wasRaw = stdin.isRaw;
|
|
199
199
|
const finish = (value) => {
|
|
@@ -201,7 +201,7 @@ async function ask(question, options = {}) {
|
|
|
201
201
|
stdin.setRawMode(wasRaw ?? false);
|
|
202
202
|
stdin.pause();
|
|
203
203
|
stdout.write("\n");
|
|
204
|
-
|
|
204
|
+
resolve4(value);
|
|
205
205
|
};
|
|
206
206
|
const onKey = (str, key) => {
|
|
207
207
|
if (key?.ctrl && key.name === "c") {
|
|
@@ -291,14 +291,14 @@ async function select(question, choices, options = {}) {
|
|
|
291
291
|
`);
|
|
292
292
|
hideCursor();
|
|
293
293
|
render(true);
|
|
294
|
-
return await new Promise((
|
|
294
|
+
return await new Promise((resolve4) => {
|
|
295
295
|
const wasRaw = stdin.isRaw;
|
|
296
296
|
const finish = (value) => {
|
|
297
297
|
stdin.removeListener("keypress", onKey);
|
|
298
298
|
stdin.setRawMode(wasRaw ?? false);
|
|
299
299
|
stdin.pause();
|
|
300
300
|
showCursor();
|
|
301
|
-
|
|
301
|
+
resolve4(value);
|
|
302
302
|
};
|
|
303
303
|
const move = (delta) => {
|
|
304
304
|
let next = cursor;
|
|
@@ -390,14 +390,14 @@ async function multiSelect(question, choices, options = {}) {
|
|
|
390
390
|
`);
|
|
391
391
|
hideCursor();
|
|
392
392
|
render(true);
|
|
393
|
-
return await new Promise((
|
|
393
|
+
return await new Promise((resolve4) => {
|
|
394
394
|
const wasRaw = stdin.isRaw;
|
|
395
395
|
const finish = () => {
|
|
396
396
|
stdin.removeListener("keypress", onKey);
|
|
397
397
|
stdin.setRawMode(wasRaw ?? false);
|
|
398
398
|
stdin.pause();
|
|
399
399
|
showCursor();
|
|
400
|
-
|
|
400
|
+
resolve4([...selected].sort((a, b) => a - b).map((i) => choices[i].value));
|
|
401
401
|
};
|
|
402
402
|
const onKey = (str, key) => {
|
|
403
403
|
if (key?.ctrl && key.name === "c") {
|
|
@@ -3823,7 +3823,7 @@ function extractColo(text2) {
|
|
|
3823
3823
|
return match ? match[1].toUpperCase() : "";
|
|
3824
3824
|
}
|
|
3825
3825
|
function probeWs101(ip, port, host, timeoutMs = 3e3, path = "/__edge_probe") {
|
|
3826
|
-
return new Promise((
|
|
3826
|
+
return new Promise((resolve4) => {
|
|
3827
3827
|
const started = Date.now();
|
|
3828
3828
|
const key = crypto.randomBytes(16).toString("base64");
|
|
3829
3829
|
let settled = false;
|
|
@@ -3836,7 +3836,7 @@ function probeWs101(ip, port, host, timeoutMs = 3e3, path = "/__edge_probe") {
|
|
|
3836
3836
|
socket.destroy();
|
|
3837
3837
|
} catch {
|
|
3838
3838
|
}
|
|
3839
|
-
|
|
3839
|
+
resolve4({ ...result, latencyMs: Date.now() - started });
|
|
3840
3840
|
};
|
|
3841
3841
|
const request3 = [
|
|
3842
3842
|
`GET ${path} HTTP/1.1`,
|
|
@@ -3939,7 +3939,7 @@ function decodeWsFrame(buf) {
|
|
|
3939
3939
|
return { frame, rest };
|
|
3940
3940
|
}
|
|
3941
3941
|
function probeWsPing(ip, port, host, timeoutMs = 5e3, path = "/__edge_probe") {
|
|
3942
|
-
return new Promise((
|
|
3942
|
+
return new Promise((resolve4) => {
|
|
3943
3943
|
const started = Date.now();
|
|
3944
3944
|
const key = crypto.randomBytes(16).toString("base64");
|
|
3945
3945
|
let settled = false;
|
|
@@ -3954,7 +3954,7 @@ function probeWsPing(ip, port, host, timeoutMs = 5e3, path = "/__edge_probe") {
|
|
|
3954
3954
|
socket.destroy();
|
|
3955
3955
|
} catch {
|
|
3956
3956
|
}
|
|
3957
|
-
|
|
3957
|
+
resolve4({ ...result, latencyMs: Date.now() - started });
|
|
3958
3958
|
};
|
|
3959
3959
|
const request3 = [
|
|
3960
3960
|
`GET ${path} HTTP/1.1`,
|
|
@@ -4065,7 +4065,7 @@ function probeWsPing(ip, port, host, timeoutMs = 5e3, path = "/__edge_probe") {
|
|
|
4065
4065
|
});
|
|
4066
4066
|
}
|
|
4067
4067
|
function probeTlsHandshake(ip, port, host, timeoutMs = 4e3) {
|
|
4068
|
-
return new Promise((
|
|
4068
|
+
return new Promise((resolve4) => {
|
|
4069
4069
|
const started = Date.now();
|
|
4070
4070
|
let settled = false;
|
|
4071
4071
|
const finish = (result) => {
|
|
@@ -4076,7 +4076,7 @@ function probeTlsHandshake(ip, port, host, timeoutMs = 4e3) {
|
|
|
4076
4076
|
socket.destroy();
|
|
4077
4077
|
} catch {
|
|
4078
4078
|
}
|
|
4079
|
-
|
|
4079
|
+
resolve4({ ip, tlsMs: result.tlsMs ?? Date.now() - started, ...result });
|
|
4080
4080
|
};
|
|
4081
4081
|
const socket = tls.connect(
|
|
4082
4082
|
{
|
|
@@ -4116,7 +4116,7 @@ function measureThroughput(options) {
|
|
|
4116
4116
|
minBytes = 32 * 1024
|
|
4117
4117
|
} = options;
|
|
4118
4118
|
const connCount = Math.max(1, Math.min(16, connections));
|
|
4119
|
-
return new Promise((
|
|
4119
|
+
return new Promise((resolve4) => {
|
|
4120
4120
|
const started = Date.now();
|
|
4121
4121
|
let settled = false;
|
|
4122
4122
|
const meter = new WindowMeter({ startedAt: started, warmupMs, windowMs });
|
|
@@ -4146,7 +4146,7 @@ function measureThroughput(options) {
|
|
|
4146
4146
|
else if (totalBytes === 0) error = lastError || "\u672A\u6536\u5230\u6570\u636E";
|
|
4147
4147
|
else error = lastError || `\u8F7D\u8377\u4E0D\u8DB3\uFF08${totalBytes}/${minBytes} \u5B57\u8282\uFF09`;
|
|
4148
4148
|
}
|
|
4149
|
-
|
|
4149
|
+
resolve4({
|
|
4150
4150
|
ok,
|
|
4151
4151
|
bytes: totalBytes,
|
|
4152
4152
|
ms: now - started,
|
|
@@ -4296,7 +4296,7 @@ function verifyTunnel(options) {
|
|
|
4296
4296
|
const { ip, port, host, wsPath, uuid, trojanPassword, targetHost = "baidu.com", targetPort = 80, timeoutMs = 8e3 } = options;
|
|
4297
4297
|
const payload = uuid ? buildVlessTunnelPayload(uuid, targetHost, targetPort, tunnelTargetRequest(targetHost)) : trojanPassword ? buildTrojanTunnelPayload(trojanPassword, targetHost, targetPort, tunnelTargetRequest(targetHost)) : null;
|
|
4298
4298
|
if (!payload) return Promise.resolve({ ok: false, stage: "protocol", latencyMs: 0, error: "\u7F3A\u5C11 uuid / trojanPassword" });
|
|
4299
|
-
return new Promise((
|
|
4299
|
+
return new Promise((resolve4) => {
|
|
4300
4300
|
const started = Date.now();
|
|
4301
4301
|
const key = crypto.randomBytes(16).toString("base64");
|
|
4302
4302
|
let settled = false;
|
|
@@ -4310,7 +4310,7 @@ function verifyTunnel(options) {
|
|
|
4310
4310
|
socket.destroy();
|
|
4311
4311
|
} catch {
|
|
4312
4312
|
}
|
|
4313
|
-
|
|
4313
|
+
resolve4({ ...r, latencyMs: Date.now() - started });
|
|
4314
4314
|
};
|
|
4315
4315
|
const socket = tls.connect({ host: ip, port, servername: host, rejectUnauthorized: false, ALPNProtocols: ["http/1.1"] }, () => {
|
|
4316
4316
|
socket.write(tunnelUpgradeRequest(host, wsPath, key));
|
|
@@ -4496,7 +4496,7 @@ function schemeForPort(port) {
|
|
|
4496
4496
|
return port === 443 || port === 2053 || port === 2083 || port === 2087 || port === 2096 || port === 8443 ? "https" : "http";
|
|
4497
4497
|
}
|
|
4498
4498
|
function checkSpeedUrlAvailable(parsed, timeoutMs = 6e3) {
|
|
4499
|
-
return new Promise((
|
|
4499
|
+
return new Promise((resolve4) => {
|
|
4500
4500
|
let settled = false;
|
|
4501
4501
|
let received = "";
|
|
4502
4502
|
const finish = (available, status2, error) => {
|
|
@@ -4507,7 +4507,7 @@ function checkSpeedUrlAvailable(parsed, timeoutMs = 6e3) {
|
|
|
4507
4507
|
socket.destroy();
|
|
4508
4508
|
} catch {
|
|
4509
4509
|
}
|
|
4510
|
-
|
|
4510
|
+
resolve4({ available, status: status2, error });
|
|
4511
4511
|
};
|
|
4512
4512
|
const path = parsed.path.includes("bytes=") ? parsed.path.replace(/bytes=\d+/, "bytes=1024") : parsed.path;
|
|
4513
4513
|
const request3 = [
|
|
@@ -4588,7 +4588,7 @@ var init_speed_url = __esm({
|
|
|
4588
4588
|
import * as tls3 from "node:tls";
|
|
4589
4589
|
function probeUnlock(options) {
|
|
4590
4590
|
const { ip, port = 443, host, token, timeoutMs = 12e3 } = options;
|
|
4591
|
-
return new Promise((
|
|
4591
|
+
return new Promise((resolve4) => {
|
|
4592
4592
|
let settled = false;
|
|
4593
4593
|
let raw = Buffer.alloc(0);
|
|
4594
4594
|
const finish = (result) => {
|
|
@@ -4598,7 +4598,7 @@ function probeUnlock(options) {
|
|
|
4598
4598
|
socket.destroy();
|
|
4599
4599
|
} catch {
|
|
4600
4600
|
}
|
|
4601
|
-
|
|
4601
|
+
resolve4(result);
|
|
4602
4602
|
};
|
|
4603
4603
|
const socket = tls3.connect(
|
|
4604
4604
|
{
|
|
@@ -4983,7 +4983,9 @@ function expandCidrs(cidrs, options = {}) {
|
|
|
4983
4983
|
}
|
|
4984
4984
|
return out;
|
|
4985
4985
|
}
|
|
4986
|
-
function looksLikeIpLiteral(
|
|
4986
|
+
function looksLikeIpLiteral(rawValue) {
|
|
4987
|
+
if (!rawValue) return false;
|
|
4988
|
+
const value = (rawValue.split("#")[0] ?? "").trim();
|
|
4987
4989
|
if (!value) return false;
|
|
4988
4990
|
if (value.startsWith("[")) return /^\[[0-9a-fA-F:.]+\](?::\d{1,5})?$/.test(value);
|
|
4989
4991
|
if (/^\d{1,3}(?:\.\d{1,3}){3}(?::\d{1,5})?$/.test(value)) {
|
|
@@ -5031,7 +5033,59 @@ function readIpFile(text2) {
|
|
|
5031
5033
|
}
|
|
5032
5034
|
return out;
|
|
5033
5035
|
}
|
|
5034
|
-
|
|
5036
|
+
async function readIpUrl(rawUrl, timeoutMs = IP_URL_TIMEOUT_MS, maxBytes = IP_URL_MAX_BYTES) {
|
|
5037
|
+
const trimmed = rawUrl.trim();
|
|
5038
|
+
let url;
|
|
5039
|
+
try {
|
|
5040
|
+
url = new URL(trimmed);
|
|
5041
|
+
} catch {
|
|
5042
|
+
throw new Error(`\u4E0D\u662F\u5408\u6CD5\u7684\u94FE\u63A5\uFF1A${trimmed}`);
|
|
5043
|
+
}
|
|
5044
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
5045
|
+
throw new Error(`\u53EA\u652F\u6301 http/https \u94FE\u63A5\uFF0C\u5B9E\u9645\u662F ${url.protocol}`);
|
|
5046
|
+
}
|
|
5047
|
+
let res;
|
|
5048
|
+
try {
|
|
5049
|
+
res = await fetch(url, { redirect: "follow", signal: AbortSignal.timeout(timeoutMs) });
|
|
5050
|
+
} catch (err) {
|
|
5051
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
5052
|
+
throw new Error(`\u62C9\u53D6\u5931\u8D25\uFF1A${msg}`);
|
|
5053
|
+
}
|
|
5054
|
+
if (!res.ok) throw new Error(`\u62C9\u53D6\u5931\u8D25 HTTP ${res.status} ${res.statusText}`.trim());
|
|
5055
|
+
const declared = Number(res.headers.get("content-length") ?? "");
|
|
5056
|
+
if (Number.isFinite(declared) && declared > maxBytes) {
|
|
5057
|
+
throw new Error(
|
|
5058
|
+
`\u6E05\u5355\u8FC7\u5927\uFF1A\u58F0\u660E ${(declared / 1024 / 1024).toFixed(1)} MB\uFF0C\u4E0A\u9650 ${(maxBytes / 1024 / 1024).toFixed(1)} MB`
|
|
5059
|
+
);
|
|
5060
|
+
}
|
|
5061
|
+
const decoder = new TextDecoder();
|
|
5062
|
+
let text2 = "";
|
|
5063
|
+
let total = 0;
|
|
5064
|
+
const reader = res.body?.getReader();
|
|
5065
|
+
if (reader) {
|
|
5066
|
+
for (; ; ) {
|
|
5067
|
+
const { done, value } = await reader.read();
|
|
5068
|
+
if (done) break;
|
|
5069
|
+
if (!value || value.byteLength === 0) continue;
|
|
5070
|
+
total += value.byteLength;
|
|
5071
|
+
if (total > maxBytes) {
|
|
5072
|
+
try {
|
|
5073
|
+
await reader.cancel();
|
|
5074
|
+
} catch {
|
|
5075
|
+
}
|
|
5076
|
+
throw new Error(`\u6E05\u5355\u8FC7\u5927\uFF1A\u8D85\u8FC7 ${(maxBytes / 1024 / 1024).toFixed(1)} MB \u4E0A\u9650`);
|
|
5077
|
+
}
|
|
5078
|
+
text2 += decoder.decode(value, { stream: true });
|
|
5079
|
+
}
|
|
5080
|
+
}
|
|
5081
|
+
text2 += decoder.decode();
|
|
5082
|
+
const list = readIpFile(text2);
|
|
5083
|
+
if (list.length === 0) {
|
|
5084
|
+
throw new Error(`\u94FE\u63A5\u5185\u5BB9\u91CC\u6CA1\u6709\u53EF\u8BC6\u522B\u7684 IP\uFF1A${trimmed}`);
|
|
5085
|
+
}
|
|
5086
|
+
return list;
|
|
5087
|
+
}
|
|
5088
|
+
var BUILTIN_IPV4_CIDRS, IPV4_CIDR_WEIGHTS, DEFAULT_CIDR_WEIGHT, IPV6_PREFIX_WEIGHTS, DEFAULT_IPV6_CIDR_WEIGHT, IPV6_ACTIVE_PREFIXES, IPV6_DEAD_PREFIXES, WEIGHT_TABLE_V4, WEIGHT_TABLE_V6, BUILTIN_IPV6_CIDRS, IP_URL_MAX_BYTES, IP_URL_TIMEOUT_MS;
|
|
5035
5089
|
var init_ip_ranges = __esm({
|
|
5036
5090
|
"src/scan/ip-ranges.ts"() {
|
|
5037
5091
|
"use strict";
|
|
@@ -5137,6 +5191,8 @@ var init_ip_ranges = __esm({
|
|
|
5137
5191
|
"2a06:98c0::/29",
|
|
5138
5192
|
"2c0f:f248::/32"
|
|
5139
5193
|
];
|
|
5194
|
+
IP_URL_MAX_BYTES = 2 * 1024 * 1024;
|
|
5195
|
+
IP_URL_TIMEOUT_MS = 15e3;
|
|
5140
5196
|
}
|
|
5141
5197
|
});
|
|
5142
5198
|
|
|
@@ -5165,7 +5221,7 @@ function countFailure(into, stage, error) {
|
|
|
5165
5221
|
bucket[key] = (bucket[key] ?? 0) + 1;
|
|
5166
5222
|
}
|
|
5167
5223
|
async function tcpPing(ip, port, timeoutMs) {
|
|
5168
|
-
return new Promise((
|
|
5224
|
+
return new Promise((resolve4) => {
|
|
5169
5225
|
const started = Date.now();
|
|
5170
5226
|
let settled = false;
|
|
5171
5227
|
const socket = new net2.Socket();
|
|
@@ -5176,7 +5232,7 @@ async function tcpPing(ip, port, timeoutMs) {
|
|
|
5176
5232
|
socket.destroy();
|
|
5177
5233
|
} catch {
|
|
5178
5234
|
}
|
|
5179
|
-
|
|
5235
|
+
resolve4({ ip, ok, latency: Date.now() - started });
|
|
5180
5236
|
};
|
|
5181
5237
|
socket.setTimeout(timeoutMs, () => done(false));
|
|
5182
5238
|
socket.once("connect", () => done(true));
|
|
@@ -5681,6 +5737,14 @@ var init_scan = __esm({
|
|
|
5681
5737
|
});
|
|
5682
5738
|
|
|
5683
5739
|
// src/scan/callback.ts
|
|
5740
|
+
var callback_exports = {};
|
|
5741
|
+
__export(callback_exports, {
|
|
5742
|
+
fetchScannerToken: () => fetchScannerToken,
|
|
5743
|
+
getPanelConfig: () => getPanelConfig,
|
|
5744
|
+
loginPanel: () => loginPanel,
|
|
5745
|
+
patchPanelConfig: () => patchPanelConfig,
|
|
5746
|
+
postResults: () => postResults
|
|
5747
|
+
});
|
|
5684
5748
|
async function postResults(callbackUrl, token, entries, mode = "replace", timeoutMs = 15e3) {
|
|
5685
5749
|
try {
|
|
5686
5750
|
const response = await fetch(callbackUrl, {
|
|
@@ -5734,6 +5798,48 @@ async function loginPanel(panelHost, password, timeoutMs = 25e3) {
|
|
|
5734
5798
|
return { ok: false, base, cookie: "", error: err instanceof Error ? err.message : String(err) };
|
|
5735
5799
|
}
|
|
5736
5800
|
}
|
|
5801
|
+
async function getPanelConfig(panelHost, password, timeoutMs = 25e3) {
|
|
5802
|
+
const session = await loginPanel(panelHost, password, timeoutMs);
|
|
5803
|
+
if (!session.ok) return { ok: false, error: session.error };
|
|
5804
|
+
try {
|
|
5805
|
+
const res = await fetch(session.base + "/api/v1/config", {
|
|
5806
|
+
headers: { Cookie: session.cookie },
|
|
5807
|
+
signal: AbortSignal.timeout(timeoutMs)
|
|
5808
|
+
});
|
|
5809
|
+
const text2 = await res.text().catch(() => "");
|
|
5810
|
+
if (!res.ok) return { ok: false, error: `\u8BFB\u53D6\u914D\u7F6E\u5931\u8D25 HTTP ${res.status} ${text2.slice(0, 160)}` };
|
|
5811
|
+
try {
|
|
5812
|
+
const parsed = JSON.parse(text2);
|
|
5813
|
+
return { ok: true, config: parsed.config };
|
|
5814
|
+
} catch {
|
|
5815
|
+
return { ok: false, error: "\u914D\u7F6E\u63A5\u53E3\u8FD4\u56DE\u7684\u4E0D\u662F JSON" };
|
|
5816
|
+
}
|
|
5817
|
+
} catch (err) {
|
|
5818
|
+
return { ok: false, error: err instanceof Error ? err.message : String(err) };
|
|
5819
|
+
}
|
|
5820
|
+
}
|
|
5821
|
+
async function patchPanelConfig(panelHost, password, patch, timeoutMs = 25e3) {
|
|
5822
|
+
const session = await loginPanel(panelHost, password, timeoutMs);
|
|
5823
|
+
if (!session.ok) return { ok: false, error: session.error };
|
|
5824
|
+
try {
|
|
5825
|
+
const res = await fetch(session.base + "/api/v1/config", {
|
|
5826
|
+
method: "PUT",
|
|
5827
|
+
headers: { "Content-Type": "application/json", Cookie: session.cookie },
|
|
5828
|
+
body: JSON.stringify({ config: patch }),
|
|
5829
|
+
signal: AbortSignal.timeout(timeoutMs)
|
|
5830
|
+
});
|
|
5831
|
+
const text2 = await res.text().catch(() => "");
|
|
5832
|
+
if (!res.ok) return { ok: false, error: `\u66F4\u65B0\u914D\u7F6E\u5931\u8D25 HTTP ${res.status} ${text2.slice(0, 160)}` };
|
|
5833
|
+
try {
|
|
5834
|
+
const parsed = JSON.parse(text2);
|
|
5835
|
+
return { ok: true, config: parsed.config };
|
|
5836
|
+
} catch {
|
|
5837
|
+
return { ok: true };
|
|
5838
|
+
}
|
|
5839
|
+
} catch (err) {
|
|
5840
|
+
return { ok: false, error: err instanceof Error ? err.message : String(err) };
|
|
5841
|
+
}
|
|
5842
|
+
}
|
|
5737
5843
|
async function fetchScannerToken(panelHost, password, timeoutMs = 25e3) {
|
|
5738
5844
|
const session = await loginPanel(panelHost, password, timeoutMs);
|
|
5739
5845
|
if (!session.ok) return { ok: false, error: session.error };
|
|
@@ -5778,7 +5884,7 @@ var init_callback = __esm({
|
|
|
5778
5884
|
import * as net3 from "node:net";
|
|
5779
5885
|
import { execFile } from "node:child_process";
|
|
5780
5886
|
function isPortListening(port, timeoutMs = 400) {
|
|
5781
|
-
return new Promise((
|
|
5887
|
+
return new Promise((resolve4) => {
|
|
5782
5888
|
const socket = new net3.Socket();
|
|
5783
5889
|
let settled = false;
|
|
5784
5890
|
const done = (open2) => {
|
|
@@ -5788,7 +5894,7 @@ function isPortListening(port, timeoutMs = 400) {
|
|
|
5788
5894
|
socket.destroy();
|
|
5789
5895
|
} catch {
|
|
5790
5896
|
}
|
|
5791
|
-
|
|
5897
|
+
resolve4(open2);
|
|
5792
5898
|
};
|
|
5793
5899
|
socket.setTimeout(timeoutMs, () => done(false));
|
|
5794
5900
|
socket.once("connect", () => done(true));
|
|
@@ -5802,12 +5908,12 @@ function isPortListening(port, timeoutMs = 400) {
|
|
|
5802
5908
|
}
|
|
5803
5909
|
async function readSystemProxy() {
|
|
5804
5910
|
if (process.platform !== "win32") return "";
|
|
5805
|
-
const query = (key) => new Promise((
|
|
5911
|
+
const query = (key) => new Promise((resolve4) => {
|
|
5806
5912
|
execFile(
|
|
5807
5913
|
"reg",
|
|
5808
5914
|
["query", "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", "/v", key],
|
|
5809
5915
|
{ timeout: 3e3, windowsHide: true },
|
|
5810
|
-
(err, stdout2) =>
|
|
5916
|
+
(err, stdout2) => resolve4(err ? "" : String(stdout2))
|
|
5811
5917
|
);
|
|
5812
5918
|
});
|
|
5813
5919
|
try {
|
|
@@ -6450,10 +6556,10 @@ function findGlobalIPv6() {
|
|
|
6450
6556
|
}
|
|
6451
6557
|
async function probeDefaultRoute(timeoutMs = 800) {
|
|
6452
6558
|
const platform = process.platform;
|
|
6453
|
-
const run = (cmd, args) => new Promise((
|
|
6559
|
+
const run = (cmd, args) => new Promise((resolve4, reject) => {
|
|
6454
6560
|
const child = execFile2(cmd, args, { timeout: timeoutMs, windowsHide: true, maxBuffer: 1 << 20 }, (err, stdout2) => {
|
|
6455
6561
|
if (err && !stdout2) reject(err);
|
|
6456
|
-
else
|
|
6562
|
+
else resolve4(String(stdout2 ?? ""));
|
|
6457
6563
|
});
|
|
6458
6564
|
child.on("error", reject);
|
|
6459
6565
|
});
|
|
@@ -6473,7 +6579,7 @@ async function probeDefaultRoute(timeoutMs = 800) {
|
|
|
6473
6579
|
}
|
|
6474
6580
|
}
|
|
6475
6581
|
function tcpReachable(address, port, timeoutMs) {
|
|
6476
|
-
return new Promise((
|
|
6582
|
+
return new Promise((resolve4) => {
|
|
6477
6583
|
let settled = false;
|
|
6478
6584
|
const done = (ok) => {
|
|
6479
6585
|
if (settled) return;
|
|
@@ -6482,7 +6588,7 @@ function tcpReachable(address, port, timeoutMs) {
|
|
|
6482
6588
|
socket.destroy();
|
|
6483
6589
|
} catch {
|
|
6484
6590
|
}
|
|
6485
|
-
|
|
6591
|
+
resolve4(ok);
|
|
6486
6592
|
};
|
|
6487
6593
|
const socket = new net4.Socket();
|
|
6488
6594
|
socket.setTimeout(timeoutMs, () => done(false));
|
|
@@ -6671,12 +6777,12 @@ async function discoverIPv6Prefixes(hosts, timeoutMs = 6e3) {
|
|
|
6671
6777
|
return [...out].sort();
|
|
6672
6778
|
}
|
|
6673
6779
|
function withTimeout(promise, ms) {
|
|
6674
|
-
return new Promise((
|
|
6780
|
+
return new Promise((resolve4, reject) => {
|
|
6675
6781
|
const timer = setTimeout(() => reject(new Error("timeout")), ms);
|
|
6676
6782
|
promise.then(
|
|
6677
6783
|
(value) => {
|
|
6678
6784
|
clearTimeout(timer);
|
|
6679
|
-
|
|
6785
|
+
resolve4(value);
|
|
6680
6786
|
},
|
|
6681
6787
|
(error) => {
|
|
6682
6788
|
clearTimeout(timer);
|
|
@@ -6996,12 +7102,12 @@ function startBridge(options = {}) {
|
|
|
6996
7102
|
sendJson(res, 500, { ok: false, error: err instanceof Error ? err.message : String(err) });
|
|
6997
7103
|
});
|
|
6998
7104
|
});
|
|
6999
|
-
return new Promise((
|
|
7105
|
+
return new Promise((resolve4, reject) => {
|
|
7000
7106
|
server.once("error", reject);
|
|
7001
7107
|
server.listen(port, host, () => {
|
|
7002
7108
|
const address = server.address();
|
|
7003
7109
|
const boundPort = typeof address === "object" && address !== null ? address.port : port;
|
|
7004
|
-
|
|
7110
|
+
resolve4({
|
|
7005
7111
|
server,
|
|
7006
7112
|
port: boundPort,
|
|
7007
7113
|
close: () => new Promise((done) => {
|
|
@@ -7276,6 +7382,7 @@ scan \u9009\u9879:
|
|
|
7276
7382
|
\u7B5B\u4E0D\u5230\u65F6\u4F1A\u660E\u786E\u63D0\u793A\u300C\u5DF2\u653E\u5BBD\u4E3A\u5168\u91CF\u300D\u800C\u4E0D\u662F\u9759\u9ED8\u5FFD\u7565
|
|
7277
7383
|
--cidr <a,b> \u81EA\u5B9A\u4E49\u7F51\u6BB5\uFF08\u53EF\u91CD\u590D\uFF0C\u7528\u9017\u53F7\u5206\u9694\uFF09
|
|
7278
7384
|
--ip-file <path> \u4F7F\u7528\u672C\u5730 IP \u5217\u8868\u6587\u4EF6
|
|
7385
|
+
--ip-url <\u94FE\u63A5> \u4F7F\u7528\u8FDC\u7A0B IP \u5217\u8868\uFF08http/https\uFF0C\u4E0A\u9650 2MB\uFF0C\u4E0E --ip-file \u4E8C\u9009\u4E00\uFF09
|
|
7279
7386
|
--max-latency <ms> \u9636\u6BB5\u4E00 TCP \u5EF6\u8FDF\u4E0A\u9650\uFF0C\u9ED8\u8BA4 0\uFF08\u4E0D\u9650\uFF09
|
|
7280
7387
|
--tls-timeout <ms> \u9636\u6BB5\u4E00 TLS \u63E1\u624B\u8D85\u65F6\uFF0C\u9ED8\u8BA4 2000
|
|
7281
7388
|
\u8D85\u65F6\u4E0D\u518D\u91CD\u8BD5\uFF08\u8BE5 IP \u5728\u5F53\u524D\u7F51\u7EDC\u4E0B\u5C31\u662F\u4E0D\u53EF\u7528\uFF09
|
|
@@ -7373,16 +7480,24 @@ ${NAME} scan relay \u2014\u2014 \u53CD\u4EE3\u5165\u53E3\uFF08ProxyIP \u6C60\uFF
|
|
|
7373
7480
|
\u7528\u6CD5:
|
|
7374
7481
|
${NAME} scan relay --file <\u5019\u9009\u6587\u4EF6> --host <\u6570\u636E\u9762\u57DF\u540D> \\
|
|
7375
7482
|
--ws-path <WS \u8DEF\u5F84> --uuid <UUID> [\u9009\u9879]
|
|
7483
|
+
${NAME} scan relay --url <\u6E05\u5355\u94FE\u63A5> --host <\u6570\u636E\u9762\u57DF\u540D> \\
|
|
7484
|
+
--ws-path <WS \u8DEF\u5F84> --uuid <UUID> \\
|
|
7485
|
+
--push incremental --panel <\u63A7\u5236\u9762> --panel-password ***
|
|
7376
7486
|
|
|
7377
7487
|
\u9009\u9879:
|
|
7378
7488
|
--file <path> \u5019\u9009 IP \u6587\u4EF6\uFF08\u6BCF\u884C\u4E00\u4E2A\uFF0C\u652F\u6301 CSV \u4E0E # \u6CE8\u91CA\uFF09
|
|
7489
|
+
--url <\u94FE\u63A5> \u8FDC\u7A0B\u5019\u9009\u6E05\u5355\uFF08http/https\uFF0C\u4E0A\u9650 2MB\uFF09\uFF0C\u4E0E --file \u4E8C\u9009\u4E00
|
|
7379
7490
|
--host <domain> \u6570\u636E\u9762\u57DF\u540D\uFF08\u96A7\u9053\u4E0E SNI \u90FD\u7528\u5B83\uFF09
|
|
7380
7491
|
--ws-path <path> \u6570\u636E\u9762\u7684 WebSocket \u8DEF\u5F84
|
|
7381
|
-
--uuid <uuid> VLESS UUID
|
|
7492
|
+
--uuid <uuid> VLESS UUID\uFF08\u96A7\u9053\u9274\u6743\uFF0C\u5FC5\u9700\uFF09
|
|
7382
7493
|
--rounds <n> \u8F6E\u6570\uFF0C\u9ED8\u8BA4 2
|
|
7383
7494
|
--timeout <ms> \u5355\u76EE\u6807\u8D85\u65F6\uFF0C\u9ED8\u8BA4 12000
|
|
7384
7495
|
--out <path> \u5199\u51FA\u53EF**\u76F4\u63A5\u7C98\u8D34**\u8FDB ProxyIP \u6C60\u7684\u6E05\u5355\uFF08\u53EA\u542B\u5168\u901A\u9879\uFF0C\u6309\u8D28\u91CF\u6392\u5E8F\uFF09
|
|
7385
|
-
--top <n> \u4E0E --out \u914D\u5408\uFF1A\u6700\u591A\
|
|
7496
|
+
--top <n> \u4E0E --out / --push \u914D\u5408\uFF1A\u6700\u591A\u53D6\u51E0\u6761\uFF0C\u9ED8\u8BA4 10
|
|
7497
|
+
--push <mode> \u76F4\u63A5\u5199\u5165\u9762\u677F ProxyIP \u6C60\uFF1Aincremental \u589E\u91CF / overwrite \u8986\u76D6
|
|
7498
|
+
\u9700\u8981\u540C\u65F6\u7ED9 --panel \u4E0E --panel-password
|
|
7499
|
+
--panel <domain> \u63A7\u5236\u9762\u57DF\u540D\uFF08--push \u65F6\u5FC5\u586B\uFF09
|
|
7500
|
+
--panel-password <pw> \u9762\u677F\u767B\u5F55\u5BC6\u7801\uFF08--push \u65F6\u5FC5\u586B\uFF09
|
|
7386
7501
|
--json \u8F93\u51FA\u673A\u5668\u53EF\u8BFB JSON
|
|
7387
7502
|
--quiet \u53EA\u8F93\u51FA\u7ED3\u679C
|
|
7388
7503
|
-h, --help \u663E\u793A\u672C\u5E2E\u52A9
|
|
@@ -7693,12 +7808,53 @@ var init_compare = __esm({
|
|
|
7693
7808
|
}
|
|
7694
7809
|
});
|
|
7695
7810
|
|
|
7811
|
+
// src/scan/relay-builtin.ts
|
|
7812
|
+
import { readFileSync as readFileSync2 } from "node:fs";
|
|
7813
|
+
import { dirname as dirname3, resolve as resolve2 } from "node:path";
|
|
7814
|
+
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
7815
|
+
function moduleDir2() {
|
|
7816
|
+
try {
|
|
7817
|
+
const meta = import.meta;
|
|
7818
|
+
if (meta && typeof meta.url === "string") return dirname3(fileURLToPath2(meta.url));
|
|
7819
|
+
} catch {
|
|
7820
|
+
}
|
|
7821
|
+
return typeof __dirname === "string" ? __dirname : process.cwd();
|
|
7822
|
+
}
|
|
7823
|
+
function readBuiltinRelayCandidates() {
|
|
7824
|
+
const paths = [
|
|
7825
|
+
resolve2(moduleDir2(), `../assets/${BUILTIN_RELAY_FILE}`),
|
|
7826
|
+
resolve2(moduleDir2(), `../../assets/${BUILTIN_RELAY_FILE}`),
|
|
7827
|
+
resolve2(process.cwd(), `packages/cli/assets/${BUILTIN_RELAY_FILE}`)
|
|
7828
|
+
];
|
|
7829
|
+
for (const path of paths) {
|
|
7830
|
+
try {
|
|
7831
|
+
const list = readIpFile(readFileSync2(path, "utf8")).filter(
|
|
7832
|
+
(ip) => /^\d{1,3}(\.\d{1,3}){3}$/.test(ip)
|
|
7833
|
+
);
|
|
7834
|
+
if (list.length > 0) return list;
|
|
7835
|
+
} catch {
|
|
7836
|
+
}
|
|
7837
|
+
}
|
|
7838
|
+
throw new Error(
|
|
7839
|
+
`\u5185\u7F6E\u53CD\u4EE3\u5019\u9009\u7F3A\u5931\uFF08assets/${BUILTIN_RELAY_FILE}\uFF09\uFF0C\u8BF7\u91CD\u65B0\u5B89\u88C5\u6216\u5347\u7EA7 cfpilot\uFF1B
|
|
7840
|
+
\u4E5F\u53EF\u4EE5\u7528\u81EA\u5DF1\u7684\u6E05\u5355\uFF1A--file <\u8DEF\u5F84> \u6216 --url <\u94FE\u63A5>`
|
|
7841
|
+
);
|
|
7842
|
+
}
|
|
7843
|
+
var BUILTIN_RELAY_FILE;
|
|
7844
|
+
var init_relay_builtin = __esm({
|
|
7845
|
+
"src/scan/relay-builtin.ts"() {
|
|
7846
|
+
"use strict";
|
|
7847
|
+
init_ip_ranges();
|
|
7848
|
+
BUILTIN_RELAY_FILE = "relay-ip-builtin.txt";
|
|
7849
|
+
}
|
|
7850
|
+
});
|
|
7851
|
+
|
|
7696
7852
|
// src/scan/relay.ts
|
|
7697
7853
|
var relay_exports = {};
|
|
7698
7854
|
__export(relay_exports, {
|
|
7699
7855
|
runRelayCommand: () => runRelayCommand
|
|
7700
7856
|
});
|
|
7701
|
-
import { readFileSync as
|
|
7857
|
+
import { readFileSync as readFileSync3, writeFileSync as writeFileSync2 } from "node:fs";
|
|
7702
7858
|
import { Duplex } from "node:stream";
|
|
7703
7859
|
import * as tls4 from "node:tls";
|
|
7704
7860
|
function uuidToBytes(uuid) {
|
|
@@ -7743,6 +7899,8 @@ function createDuplex(ws) {
|
|
|
7743
7899
|
read() {
|
|
7744
7900
|
}
|
|
7745
7901
|
});
|
|
7902
|
+
duplex.on("error", () => {
|
|
7903
|
+
});
|
|
7746
7904
|
return {
|
|
7747
7905
|
duplex,
|
|
7748
7906
|
push: (buf) => {
|
|
@@ -7757,7 +7915,7 @@ function withTimeout2(promise, ms, label) {
|
|
|
7757
7915
|
]);
|
|
7758
7916
|
}
|
|
7759
7917
|
function openTunnel(wsUrl, uuid, ip, port, timeoutMs) {
|
|
7760
|
-
return new Promise((
|
|
7918
|
+
return new Promise((resolve4, reject) => {
|
|
7761
7919
|
const started = Date.now();
|
|
7762
7920
|
const ws = new WebSocket(wsUrl);
|
|
7763
7921
|
ws.binaryType = "arraybuffer";
|
|
@@ -7785,7 +7943,7 @@ function openTunnel(wsUrl, uuid, ip, port, timeoutMs) {
|
|
|
7785
7943
|
clearTimeout(timer);
|
|
7786
7944
|
const rest = bytes.subarray(Math.min(headerLen, bytes.byteLength));
|
|
7787
7945
|
if (rest.byteLength > 0) push(rest);
|
|
7788
|
-
|
|
7946
|
+
resolve4({ ws, duplex, tunnelMs: Date.now() - started, first: sniff });
|
|
7789
7947
|
return;
|
|
7790
7948
|
}
|
|
7791
7949
|
if (sniff.first.length === 0) sniff.first = Buffer.from(bytes);
|
|
@@ -7810,7 +7968,7 @@ function openTunnel(wsUrl, uuid, ip, port, timeoutMs) {
|
|
|
7810
7968
|
});
|
|
7811
7969
|
}
|
|
7812
7970
|
function readHttp(socket, timeoutMs) {
|
|
7813
|
-
return new Promise((
|
|
7971
|
+
return new Promise((resolve4, reject) => {
|
|
7814
7972
|
let text2 = "";
|
|
7815
7973
|
let done = false;
|
|
7816
7974
|
const finish = () => {
|
|
@@ -7822,7 +7980,7 @@ function readHttp(socket, timeoutMs) {
|
|
|
7822
7980
|
const head = sep >= 0 ? text2.slice(0, sep) : text2;
|
|
7823
7981
|
const body = sep >= 0 ? text2.slice(sep + 4) : "";
|
|
7824
7982
|
const matched = /^HTTP\/1\.[01] (\d{3})/.exec(head);
|
|
7825
|
-
|
|
7983
|
+
resolve4({ status: matched ? Number(matched[1]) : 0, body, raw: text2 });
|
|
7826
7984
|
};
|
|
7827
7985
|
const timer = setTimeout(finish, timeoutMs);
|
|
7828
7986
|
const onData = (chunk) => {
|
|
@@ -7872,7 +8030,7 @@ async function probeOne(opts, ip, timeoutMs) {
|
|
|
7872
8030
|
out.tunnelMs = tunnel.tunnelMs;
|
|
7873
8031
|
const tlsStarted = Date.now();
|
|
7874
8032
|
socket = await withTimeout2(
|
|
7875
|
-
new Promise((
|
|
8033
|
+
new Promise((resolve4, reject) => {
|
|
7876
8034
|
const s = tls4.connect(
|
|
7877
8035
|
{
|
|
7878
8036
|
socket: tunnel.duplex,
|
|
@@ -7881,7 +8039,7 @@ async function probeOne(opts, ip, timeoutMs) {
|
|
|
7881
8039
|
// 这一条通过,就等于证明「这个候选确实把 SNI=我们的域名 转到了 CF」。
|
|
7882
8040
|
rejectUnauthorized: true
|
|
7883
8041
|
},
|
|
7884
|
-
() =>
|
|
8042
|
+
() => resolve4(s)
|
|
7885
8043
|
);
|
|
7886
8044
|
s.once("error", reject);
|
|
7887
8045
|
}),
|
|
@@ -7951,35 +8109,58 @@ async function runRelayCommand(args) {
|
|
|
7951
8109
|
return;
|
|
7952
8110
|
}
|
|
7953
8111
|
const file = flagString(args, "file");
|
|
8112
|
+
const url = flagString(args, "url");
|
|
7954
8113
|
const host = flagString(args, "host").trim().replace(/^https?:\/\//i, "").replace(/\/$/, "");
|
|
7955
8114
|
const wsPath = flagString(args, "ws-path");
|
|
7956
8115
|
const uuid = flagString(args, "uuid");
|
|
7957
8116
|
const rounds = Math.max(1, flagNumber(args, "rounds", 2));
|
|
7958
8117
|
const timeoutMs = Math.max(1e3, flagNumber(args, "timeout", DEFAULT_TIMEOUT_MS2));
|
|
8118
|
+
const concurrency = Math.max(1, flagNumber(args, "concurrency", CONCURRENCY));
|
|
7959
8119
|
const asJson = flagBool(args, "json");
|
|
7960
8120
|
const quiet = flagBool(args, "quiet");
|
|
7961
8121
|
const outPath = flagString(args, "out");
|
|
7962
8122
|
const topN = Math.max(1, flagNumber(args, "top", 10));
|
|
7963
|
-
|
|
7964
|
-
|
|
8123
|
+
const pushRaw = flagString(args, "push").trim().toLowerCase();
|
|
8124
|
+
const pushKind = pushRaw === "append" ? "incremental" : pushRaw === "replace" ? "overwrite" : pushRaw;
|
|
8125
|
+
const panel = flagString(args, "panel");
|
|
8126
|
+
const panelPassword = flagString(args, "panel-password");
|
|
8127
|
+
if (!host || !wsPath || !uuid) {
|
|
8128
|
+
process.stderr.write("\u7F3A\u5C11\u53C2\u6570\uFF1A--host\u3001--ws-path\u3001--uuid \u90FD\u662F\u5FC5\u586B\n");
|
|
8129
|
+
process.stderr.write("\u5019\u9009\u9ED8\u8BA4\u7528\u5185\u7F6E\u6E05\u5355\uFF1B\u4E5F\u53EF\u7528 --file / --url \u6307\u5B9A\n");
|
|
7965
8130
|
process.stderr.write("\u7528\u6CD5\u89C1\uFF1Acfpilot scan relay --help\n");
|
|
7966
8131
|
process.exit(1);
|
|
7967
8132
|
}
|
|
8133
|
+
if (pushKind && pushKind !== "incremental" && pushKind !== "overwrite") {
|
|
8134
|
+
process.stderr.write("\u2717 --push \u53EA\u63A5\u53D7 incremental\uFF08\u589E\u91CF\uFF09/ overwrite\uFF08\u8986\u76D6\uFF09\n");
|
|
8135
|
+
process.exit(1);
|
|
8136
|
+
}
|
|
8137
|
+
if (pushKind && (!panel || !panelPassword)) {
|
|
8138
|
+
process.stderr.write("\u2717 --push \u9700\u8981\u540C\u65F6\u63D0\u4F9B --panel\uFF08\u63A7\u5236\u9762\uFF09\u4E0E --panel-password\n");
|
|
8139
|
+
process.exit(1);
|
|
8140
|
+
}
|
|
7968
8141
|
let ips;
|
|
8142
|
+
let rawCount = 0;
|
|
8143
|
+
const sourceLabel = file ? `\u6587\u4EF6 ${file}` : url ? `\u94FE\u63A5 ${url}` : "\u5185\u7F6E\u6E05\u5355";
|
|
7969
8144
|
try {
|
|
7970
|
-
|
|
8145
|
+
const raw = file ? readIpFile(readFileSync3(file, "utf8")) : url ? await readIpUrl(url) : readBuiltinRelayCandidates();
|
|
8146
|
+
rawCount = raw.length;
|
|
8147
|
+
ips = raw.filter((ip) => /^\d{1,3}(\.\d{1,3}){3}$/.test(ip));
|
|
7971
8148
|
} catch (err) {
|
|
7972
|
-
process.stderr.write(`\u2717 \u8BFB\u53D6\u5019\u9009\
|
|
8149
|
+
process.stderr.write(`\u2717 \u8BFB\u53D6\u5019\u9009\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}
|
|
7973
8150
|
`);
|
|
7974
8151
|
process.exit(1);
|
|
7975
8152
|
return;
|
|
7976
8153
|
}
|
|
7977
8154
|
if (ips.length === 0) {
|
|
7978
|
-
process.stderr.write(`\u2717 ${
|
|
8155
|
+
process.stderr.write(`\u2717 ${sourceLabel} \u91CC\u6CA1\u6709\u53EF\u8BFB\u7684 IPv4 \u5019\u9009
|
|
7979
8156
|
`);
|
|
7980
8157
|
process.exit(1);
|
|
7981
8158
|
return;
|
|
7982
8159
|
}
|
|
8160
|
+
if (rawCount > ips.length && !quiet) {
|
|
8161
|
+
process.stderr.write(`\u5DF2\u5FFD\u7565 ${rawCount - ips.length} \u6761\u975E IPv4 \u6761\u76EE
|
|
8162
|
+
`);
|
|
8163
|
+
}
|
|
7983
8164
|
const wsUrl = `wss://${host}${wsPath.startsWith("/") ? wsPath : "/" + wsPath}`;
|
|
7984
8165
|
let expectedBuild = "";
|
|
7985
8166
|
try {
|
|
@@ -8026,7 +8207,7 @@ async function runRelayCommand(args) {
|
|
|
8026
8207
|
}
|
|
8027
8208
|
}
|
|
8028
8209
|
};
|
|
8029
|
-
await Promise.all(Array.from({ length: Math.min(
|
|
8210
|
+
await Promise.all(Array.from({ length: Math.min(concurrency, jobs2.length) }, () => worker()));
|
|
8030
8211
|
if (!quiet) process.stderr.write("\n");
|
|
8031
8212
|
const aggregates = [];
|
|
8032
8213
|
for (const [ip, list] of perIp) {
|
|
@@ -8051,12 +8232,40 @@ async function runRelayCommand(args) {
|
|
|
8051
8232
|
});
|
|
8052
8233
|
const alwaysOk = aggregates.filter((a) => a.successPct === 100).length;
|
|
8053
8234
|
const neverOk = aggregates.filter((a) => a.successPct === 0).length;
|
|
8235
|
+
const picked = aggregates.filter((a) => a.successPct === 100).slice(0, topN).map((a) => a.ip);
|
|
8054
8236
|
if (outPath) {
|
|
8055
|
-
const picked = aggregates.filter((a) => a.successPct === 100).slice(0, topN).map((a) => a.ip);
|
|
8056
8237
|
writeFileSync2(outPath, picked.join("\n") + (picked.length > 0 ? "\n" : ""), "utf8");
|
|
8057
8238
|
if (!quiet) process.stderr.write(`\u5DF2\u5199\u51FA ${picked.length} \u6761\u5230 ${outPath}
|
|
8058
8239
|
`);
|
|
8059
8240
|
}
|
|
8241
|
+
if (pushKind) {
|
|
8242
|
+
if (picked.length === 0) {
|
|
8243
|
+
if (!quiet) process.stderr.write("\u6CA1\u6709\u5168\u901A\u9879\uFF0C\u8DF3\u8FC7\u5199\u5165\u9762\u677F\n");
|
|
8244
|
+
} else {
|
|
8245
|
+
const current = await getPanelConfig(panel, panelPassword);
|
|
8246
|
+
if (!current.ok) {
|
|
8247
|
+
process.stderr.write(`\u2717 \u8BFB\u53D6\u9762\u677F\u914D\u7F6E\u5931\u8D25\uFF1A${current.error}
|
|
8248
|
+
`);
|
|
8249
|
+
process.exitCode = 1;
|
|
8250
|
+
} else {
|
|
8251
|
+
const existing = String(current.config?.proxyIp ?? "").split(/[\n,;]+/).map((s) => s.trim()).filter(Boolean);
|
|
8252
|
+
const next2 = pushKind === "overwrite" ? picked : [.../* @__PURE__ */ new Set([...existing, ...picked])];
|
|
8253
|
+
const written = await patchPanelConfig(panel, panelPassword, { proxyIp: next2.join("\n") });
|
|
8254
|
+
if (!written.ok) {
|
|
8255
|
+
process.stderr.write(`\u2717 \u5199\u5165\u9762\u677F\u5931\u8D25\uFF1A${written.error}
|
|
8256
|
+
`);
|
|
8257
|
+
process.exitCode = 1;
|
|
8258
|
+
} else if (!quiet) {
|
|
8259
|
+
const verb = pushKind === "overwrite" ? "\u8986\u76D6\u5199\u5165" : "\u589E\u91CF\u5199\u5165";
|
|
8260
|
+
const added = next2.length - existing.length;
|
|
8261
|
+
process.stderr.write(
|
|
8262
|
+
`\u5DF2${verb}\u9762\u677F ProxyIP \u6C60\uFF1A\u672C\u6B21 ${picked.length} \u6761` + (pushKind === "overwrite" ? "" : `\uFF08\u65B0\u589E ${Math.max(0, added)} \u6761\uFF09`) + `\uFF0C\u6C60\u5185\u5171 ${next2.length} \u6761
|
|
8263
|
+
`
|
|
8264
|
+
);
|
|
8265
|
+
}
|
|
8266
|
+
}
|
|
8267
|
+
}
|
|
8268
|
+
}
|
|
8060
8269
|
if (asJson) {
|
|
8061
8270
|
process.stdout.write(
|
|
8062
8271
|
`${JSON.stringify(
|
|
@@ -8065,7 +8274,7 @@ async function runRelayCommand(args) {
|
|
|
8065
8274
|
tool: "cfpilot",
|
|
8066
8275
|
version: VERSION,
|
|
8067
8276
|
command: "scan relay",
|
|
8068
|
-
params: {
|
|
8277
|
+
params: { source: sourceLabel, host, wsPath, rounds, targets: ips.length },
|
|
8069
8278
|
expectedBuild,
|
|
8070
8279
|
summary: { alwaysOk, neverOk, flaky: aggregates.length - alwaysOk - neverOk },
|
|
8071
8280
|
results: aggregates
|
|
@@ -8114,6 +8323,8 @@ var init_relay = __esm({
|
|
|
8114
8323
|
init_version();
|
|
8115
8324
|
init_help2();
|
|
8116
8325
|
init_ip_ranges();
|
|
8326
|
+
init_relay_builtin();
|
|
8327
|
+
init_callback();
|
|
8117
8328
|
CONCURRENCY = 8;
|
|
8118
8329
|
DEFAULT_TIMEOUT_MS2 = 12e3;
|
|
8119
8330
|
}
|
|
@@ -8125,7 +8336,7 @@ __export(command_exports2, {
|
|
|
8125
8336
|
normalizeWsPath: () => normalizeWsPath,
|
|
8126
8337
|
runScanCommand: () => runScanCommand
|
|
8127
8338
|
});
|
|
8128
|
-
import { readFileSync as
|
|
8339
|
+
import { readFileSync as readFileSync4 } from "node:fs";
|
|
8129
8340
|
import { join as join4 } from "node:path";
|
|
8130
8341
|
function normalizeWsPath(raw, fallback) {
|
|
8131
8342
|
const value = (raw ?? fallback).trim();
|
|
@@ -8215,9 +8426,9 @@ function familyFromArgs(args) {
|
|
|
8215
8426
|
}
|
|
8216
8427
|
async function resolveCandidatesFromArgs(args, extraHosts = []) {
|
|
8217
8428
|
const ipFile = flagString(args, "ip-file");
|
|
8218
|
-
|
|
8219
|
-
|
|
8220
|
-
const candidates = readIpFile(
|
|
8429
|
+
const ipUrl = flagString(args, "ip-url");
|
|
8430
|
+
if (ipFile || ipUrl) {
|
|
8431
|
+
const candidates = ipFile ? readIpFile(readFileSync4(ipFile, "utf8")) : await readIpUrl(ipUrl);
|
|
8221
8432
|
return {
|
|
8222
8433
|
candidates,
|
|
8223
8434
|
family: "both",
|
|
@@ -8228,7 +8439,7 @@ async function resolveCandidatesFromArgs(args, extraHosts = []) {
|
|
|
8228
8439
|
v4: candidates.filter((ip) => !ip.includes(":")).length,
|
|
8229
8440
|
v6: candidates.filter((ip) => ip.includes(":")).length
|
|
8230
8441
|
},
|
|
8231
|
-
note: `\u5019\u9009\u6765\u81EA\u6587\u4EF6 ${ipFile}\uFF08\u672A\u505A\u7F51\u6BB5\u91C7\u6837\uFF0C\u4E5F\u672A\u505A IPv6 \u9884\u68C0\uFF09`
|
|
8442
|
+
note: ipFile ? `\u5019\u9009\u6765\u81EA\u6587\u4EF6 ${ipFile}\uFF08\u672A\u505A\u7F51\u6BB5\u91C7\u6837\uFF0C\u4E5F\u672A\u505A IPv6 \u9884\u68C0\uFF09` : `\u5019\u9009\u6765\u81EA\u94FE\u63A5 ${ipUrl}\uFF08\u672A\u505A\u7F51\u6BB5\u91C7\u6837\uFF0C\u4E5F\u672A\u505A IPv6 \u9884\u68C0\uFF09`
|
|
8232
8443
|
};
|
|
8233
8444
|
}
|
|
8234
8445
|
const base = {
|
|
@@ -8747,6 +8958,7 @@ var init_command2 = __esm({
|
|
|
8747
8958
|
// src/menu/scan.ts
|
|
8748
8959
|
var scan_exports = {};
|
|
8749
8960
|
__export(scan_exports, {
|
|
8961
|
+
menuRelayScan: () => menuRelayScan,
|
|
8750
8962
|
menuScan: () => menuScan,
|
|
8751
8963
|
menuScanPush: () => menuScanPush
|
|
8752
8964
|
});
|
|
@@ -8915,6 +9127,80 @@ async function menuScanPush() {
|
|
|
8915
9127
|
const { runScanCommand: runScanCommand2 } = await Promise.resolve().then(() => (init_command2(), command_exports2));
|
|
8916
9128
|
await runScanCommand2(makeArgs2(flags));
|
|
8917
9129
|
}
|
|
9130
|
+
async function menuRelayScan() {
|
|
9131
|
+
const cfg = loadConfig();
|
|
9132
|
+
if (!cfg.dataHost || !cfg.panelHost) {
|
|
9133
|
+
status("warn", "\u9700\u8981\u5148\u6709\u5DF2\u90E8\u7F72\u7684\u5B9E\u4F8B\uFF08\u7F3A\u6570\u636E\u9762\u6216\u63A7\u5236\u9762\u57DF\u540D\uFF09");
|
|
9134
|
+
return;
|
|
9135
|
+
}
|
|
9136
|
+
process.stdout.write("\n");
|
|
9137
|
+
box("\u53CD\u4EE3\u4F18\u9009\uFF08\u51FA\u7AD9\u94FE\u8DEF\u4F53\u68C0\uFF09", [
|
|
9138
|
+
`${c.gray("\u6570\u636E\u9762")} ${cfg.dataHost}`,
|
|
9139
|
+
`${c.gray("\u63A7\u5236\u9762")} ${cfg.panelHost}`,
|
|
9140
|
+
"\u9A8C\u8BC1\u5019\u9009\u4EE3\u7406\u80FD\u5426\u628A SNI \u8F6C\u53D1\u5230\u4F60\u7684\u6570\u636E\u9762"
|
|
9141
|
+
]);
|
|
9142
|
+
process.stdout.write("\n");
|
|
9143
|
+
const source = await select("\u5019\u9009\u6765\u6E90", [
|
|
9144
|
+
{ label: "\u672C\u5730\u6587\u4EF6\uFF08csv / txt\uFF09", value: "file" },
|
|
9145
|
+
{ label: "\u8FDC\u7A0B\u94FE\u63A5", value: "url" }
|
|
9146
|
+
]);
|
|
9147
|
+
if (source === null) return;
|
|
9148
|
+
const sourceValue = await ask(source === "file" ? "\u6587\u4EF6\u8DEF\u5F84" : "\u6E05\u5355\u94FE\u63A5", { fallback: "" });
|
|
9149
|
+
if (!sourceValue.trim()) {
|
|
9150
|
+
status("warn", "\u9700\u8981\u5019\u9009\u6E05\u5355");
|
|
9151
|
+
return;
|
|
9152
|
+
}
|
|
9153
|
+
const password = await ask("\u9762\u677F\u5BC6\u7801\uFF08\u7528\u4E8E\u8BFB\u53D6 UUID \u4E0E\u5199\u5165 ProxyIP \u6C60\uFF09", {
|
|
9154
|
+
password: true,
|
|
9155
|
+
allowEmpty: true
|
|
9156
|
+
});
|
|
9157
|
+
if (!password) {
|
|
9158
|
+
status("warn", "\u9700\u8981\u9762\u677F\u5BC6\u7801");
|
|
9159
|
+
return;
|
|
9160
|
+
}
|
|
9161
|
+
const { getPanelConfig: getPanelConfig2 } = await Promise.resolve().then(() => (init_callback(), callback_exports));
|
|
9162
|
+
const cfgRes = await getPanelConfig2(cfg.panelHost, password);
|
|
9163
|
+
if (!cfgRes.ok) {
|
|
9164
|
+
status("fail", `\u8BFB\u53D6\u9762\u677F\u914D\u7F6E\u5931\u8D25\uFF1A${cfgRes.error}`);
|
|
9165
|
+
return;
|
|
9166
|
+
}
|
|
9167
|
+
const uuid = String(cfgRes.config?.uuid ?? "");
|
|
9168
|
+
const wsPath = cfg.wsPath || String(cfgRes.config?.wsPath ?? "");
|
|
9169
|
+
if (!uuid || !wsPath) {
|
|
9170
|
+
status("warn", "\u9762\u677F\u914D\u7F6E\u91CC\u7F3A uuid \u6216 wsPath\uFF0C\u5148\u5728\u9762\u677F\u91CC\u786E\u8BA4\u5B9E\u4F8B\u914D\u7F6E");
|
|
9171
|
+
return;
|
|
9172
|
+
}
|
|
9173
|
+
const topStr = await ask("\u4FDD\u7559\u6761\u6570\uFF08\u5199\u5165/\u8F93\u51FA\uFF09", { fallback: "10" });
|
|
9174
|
+
const roundsStr = await ask("\u8F6E\u6570\uFF08\u6BCF\u8F6E\u91CD\u6D4B\u4E00\u6B21\uFF0C\u6297\u6296\u52A8\uFF09", { fallback: "2" });
|
|
9175
|
+
const push = await confirm("\u6D4B\u5B8C\u76F4\u63A5\u5199\u5165\u9762\u677F ProxyIP \u6C60\uFF1F", true);
|
|
9176
|
+
let pushMode = "incremental";
|
|
9177
|
+
if (push) {
|
|
9178
|
+
const picked = await select("\u5199\u5165\u65B9\u5F0F", [
|
|
9179
|
+
{ label: "\u589E\u91CF\uFF08\u4FDD\u7559\u6C60\u91CC\u5DF2\u6709\u7684\uFF09", value: "incremental" },
|
|
9180
|
+
{ label: "\u8986\u76D6\uFF08\u6E05\u7A7A\u540E\u5199\u5165\uFF09", value: "overwrite" }
|
|
9181
|
+
]);
|
|
9182
|
+
if (picked === null) return;
|
|
9183
|
+
pushMode = picked;
|
|
9184
|
+
}
|
|
9185
|
+
process.stdout.write("\n");
|
|
9186
|
+
status("info", "\u5F00\u59CB\u51FA\u7AD9\u4F53\u68C0\u2026");
|
|
9187
|
+
status("info", "\u6BCF\u4E2A\u5019\u9009\u90FD\u8981\u8D70\u4E00\u6761\u96A7\u9053\uFF0C260 \u4E2A\u7EA6 3~4 \u5206\u949F");
|
|
9188
|
+
process.stdout.write("\n");
|
|
9189
|
+
const flags = {
|
|
9190
|
+
host: cfg.dataHost,
|
|
9191
|
+
"ws-path": wsPath,
|
|
9192
|
+
uuid,
|
|
9193
|
+
rounds: roundsStr || "2",
|
|
9194
|
+
top: topStr || "10",
|
|
9195
|
+
panel: cfg.panelHost,
|
|
9196
|
+
"panel-password": password
|
|
9197
|
+
};
|
|
9198
|
+
if (source === "file") flags.file = sourceValue.trim();
|
|
9199
|
+
else flags.url = sourceValue.trim();
|
|
9200
|
+
if (push) flags.push = pushMode;
|
|
9201
|
+
const { runRelayCommand: runRelayCommand2 } = await Promise.resolve().then(() => (init_relay(), relay_exports));
|
|
9202
|
+
await runRelayCommand2(makeArgs2(flags));
|
|
9203
|
+
}
|
|
8918
9204
|
var init_scan2 = __esm({
|
|
8919
9205
|
"src/menu/scan.ts"() {
|
|
8920
9206
|
"use strict";
|
|
@@ -9303,6 +9589,7 @@ async function runMenu() {
|
|
|
9303
9589
|
{ label: "\u66F4\u65B0\u73B0\u6709\u5B9E\u4F8B", value: "deploy-update", hint: "\u6CBF\u7528\u51ED\u636E\uFF0C\u53EA\u66F4\u65B0\u5185\u6838" },
|
|
9304
9590
|
{ label: "\u67E5\u770B\u5B9E\u4F8B\u72B6\u6001", value: "status", hint: "\u8BFB\u53D6\u7EBF\u4E0A\u90E8\u7F72\u4FE1\u606F" },
|
|
9305
9591
|
{ label: "\u672C\u5730\u4F18\u9009\uFF08\u771F\u8FDE\u63A5\u6D4B\u901F\uFF09", value: "scan", hint: "\u626B\u63CF\u53EF\u7528 IP" },
|
|
9592
|
+
{ label: "\u53CD\u4EE3\u4F18\u9009\uFF08\u51FA\u7AD9\u94FE\u8DEF\u4F53\u68C0\uFF09", value: "relay", hint: "\u6D4B\u5019\u9009\u4EE3\u7406\u80FD\u5426\u8F6C\u53D1\u5230\u4F60" },
|
|
9306
9593
|
{ label: "\u4FEE\u6539\u9762\u677F\u5BC6\u7801", value: "change-password" },
|
|
9307
9594
|
{ label: "\u68C0\u67E5 Token \u6743\u9650", value: "token-check" },
|
|
9308
9595
|
{ label: "\u914D\u7F6E\uFF08Token / \u8D26\u53F7 / KV\uFF09", value: "config" },
|
|
@@ -9338,6 +9625,11 @@ async function runMenu() {
|
|
|
9338
9625
|
await menuScan2();
|
|
9339
9626
|
break;
|
|
9340
9627
|
}
|
|
9628
|
+
case "relay": {
|
|
9629
|
+
const { menuRelayScan: menuRelayScan2 } = await Promise.resolve().then(() => (init_scan2(), scan_exports));
|
|
9630
|
+
await menuRelayScan2();
|
|
9631
|
+
break;
|
|
9632
|
+
}
|
|
9341
9633
|
case "change-password": {
|
|
9342
9634
|
const { menuChangePassword: menuChangePassword2 } = await Promise.resolve().then(() => (init_deploy(), deploy_exports));
|
|
9343
9635
|
await menuChangePassword2();
|
|
@@ -9380,7 +9672,7 @@ var init_main = __esm({
|
|
|
9380
9672
|
// src/scan/single.ts
|
|
9381
9673
|
import * as net6 from "node:net";
|
|
9382
9674
|
function probeTcp(ip, port, timeoutMs) {
|
|
9383
|
-
return new Promise((
|
|
9675
|
+
return new Promise((resolve4) => {
|
|
9384
9676
|
const started = Date.now();
|
|
9385
9677
|
let settled = false;
|
|
9386
9678
|
const finish = (result) => {
|
|
@@ -9390,7 +9682,7 @@ function probeTcp(ip, port, timeoutMs) {
|
|
|
9390
9682
|
socket.destroy();
|
|
9391
9683
|
} catch {
|
|
9392
9684
|
}
|
|
9393
|
-
|
|
9685
|
+
resolve4({ stage: "TCP \u5EFA\u8FDE", ms: Date.now() - started, ...result });
|
|
9394
9686
|
};
|
|
9395
9687
|
const socket = net6.connect({ host: ip, port });
|
|
9396
9688
|
socket.setTimeout(timeoutMs, () => finish({ ok: false, error: "\u8D85\u65F6" }));
|
|
@@ -9665,7 +9957,7 @@ function validateIdentityResponse(value, now) {
|
|
|
9665
9957
|
};
|
|
9666
9958
|
}
|
|
9667
9959
|
function readExactly(socket, length) {
|
|
9668
|
-
return new Promise((
|
|
9960
|
+
return new Promise((resolve4, reject) => {
|
|
9669
9961
|
let data = Buffer.alloc(0);
|
|
9670
9962
|
const cleanup = () => {
|
|
9671
9963
|
socket.off("data", onData);
|
|
@@ -9686,7 +9978,7 @@ function readExactly(socket, length) {
|
|
|
9686
9978
|
socket.pause();
|
|
9687
9979
|
cleanup();
|
|
9688
9980
|
if (data.length > length) socket.unshift(data.subarray(length));
|
|
9689
|
-
|
|
9981
|
+
resolve4(data.subarray(0, length));
|
|
9690
9982
|
};
|
|
9691
9983
|
socket.on("data", onData);
|
|
9692
9984
|
socket.once("error", onError);
|
|
@@ -9758,7 +10050,7 @@ function identifyEgress(options) {
|
|
|
9758
10050
|
} catch {
|
|
9759
10051
|
return Promise.resolve(fail("config", "\u8BC6\u522B\u914D\u7F6E\u65E0\u6548\uFF1A\u9700\u8981 HTTPS\u3001\u6709\u6548\u77ED\u671F\u4EE4\u724C\u548C\u53EF\u9009 SOCKS5 \u5730\u5740"));
|
|
9760
10052
|
}
|
|
9761
|
-
return new Promise((
|
|
10053
|
+
return new Promise((resolve4) => {
|
|
9762
10054
|
let settled = false;
|
|
9763
10055
|
let request3;
|
|
9764
10056
|
let socket;
|
|
@@ -9770,7 +10062,7 @@ function identifyEgress(options) {
|
|
|
9770
10062
|
request3?.destroy();
|
|
9771
10063
|
socket?.destroy();
|
|
9772
10064
|
agent.destroy();
|
|
9773
|
-
|
|
10065
|
+
resolve4(result);
|
|
9774
10066
|
};
|
|
9775
10067
|
const timer = setTimeout(() => finish(fail("timeout", "\u51FA\u53E3\u8BC6\u522B\u8D85\u8FC7\u603B\u8D85\u65F6\u9884\u7B97")), timeoutMs);
|
|
9776
10068
|
if (proxy) {
|
|
@@ -9956,7 +10248,7 @@ function probeWebsite(target, options = {}) {
|
|
|
9956
10248
|
} catch {
|
|
9957
10249
|
return Promise.resolve({ ...base, error: "\u7F51\u7AD9\u68C0\u6D4B\u914D\u7F6E\u65E0\u6548" });
|
|
9958
10250
|
}
|
|
9959
|
-
return new Promise((
|
|
10251
|
+
return new Promise((resolve4) => {
|
|
9960
10252
|
let settled = false;
|
|
9961
10253
|
let socket;
|
|
9962
10254
|
let request3;
|
|
@@ -9968,7 +10260,7 @@ function probeWebsite(target, options = {}) {
|
|
|
9968
10260
|
request3?.destroy();
|
|
9969
10261
|
socket?.destroy();
|
|
9970
10262
|
agent.destroy();
|
|
9971
|
-
|
|
10263
|
+
resolve4({ ...base, ...patch, ms: Date.now() - started });
|
|
9972
10264
|
};
|
|
9973
10265
|
const onError = (error) => finish({ status: tlsFailure(error) ? "tls_error" : "http_error", error: tlsFailure(error) ? "\u7F51\u7AD9 TLS \u6821\u9A8C\u5931\u8D25" : "\u6307\u5B9A\u8DEF\u5F84\u8FDE\u63A5\u5931\u8D25" });
|
|
9974
10266
|
const timer = setTimeout(() => finish({ status: "timeout", error: "\u7F51\u7AD9\u68C0\u6D4B\u8D85\u8FC7\u603B\u8D85\u65F6\u9884\u7B97" }), timeout);
|
|
@@ -10199,17 +10491,17 @@ __export(command_exports3, {
|
|
|
10199
10491
|
runVpsCommand: () => runVpsCommand
|
|
10200
10492
|
});
|
|
10201
10493
|
import { spawn } from "node:child_process";
|
|
10202
|
-
import { existsSync as existsSync2, readFileSync as
|
|
10203
|
-
import { dirname as
|
|
10204
|
-
import { fileURLToPath as
|
|
10494
|
+
import { existsSync as existsSync2, readFileSync as readFileSync5, writeFileSync as writeFileSync3 } from "node:fs";
|
|
10495
|
+
import { dirname as dirname4, resolve as resolve3 } from "node:path";
|
|
10496
|
+
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
10205
10497
|
function loadScript() {
|
|
10206
|
-
const here =
|
|
10498
|
+
const here = dirname4(fileURLToPath3(import.meta.url));
|
|
10207
10499
|
const candidates = [
|
|
10208
|
-
|
|
10209
|
-
|
|
10500
|
+
resolve3(here, "../assets/vps-socks5.sh"),
|
|
10501
|
+
resolve3(here, "../../assets/vps-socks5.sh")
|
|
10210
10502
|
];
|
|
10211
10503
|
for (const path of candidates) {
|
|
10212
|
-
if (existsSync2(path)) return
|
|
10504
|
+
if (existsSync2(path)) return readFileSync5(path, "utf8");
|
|
10213
10505
|
}
|
|
10214
10506
|
throw new Error("\u5185\u7F6E\u811A\u672C\u7F3A\u5931\uFF08assets/vps-socks5.sh\uFF09\uFF0C\u8BF7\u91CD\u65B0\u5B89\u88C5\u6216\u5347\u7EA7 cfpilot");
|
|
10215
10507
|
}
|
|
@@ -10265,7 +10557,7 @@ async function runVpsCommand(args) {
|
|
|
10265
10557
|
}
|
|
10266
10558
|
return;
|
|
10267
10559
|
}
|
|
10268
|
-
const out =
|
|
10560
|
+
const out = resolve3(process.cwd(), flagString(args, "out") ?? "cfpilot-vps-socks5.sh");
|
|
10269
10561
|
writeFileSync3(out, script, { mode: 493 });
|
|
10270
10562
|
process.stdout.write(
|
|
10271
10563
|
`
|