cfpilot 0.9.8 → 0.11.2

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/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.9.8";
90
+ VERSION = "0.11.2";
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((resolve2) => {
196
+ return await new Promise((resolve3) => {
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
- resolve2(value);
204
+ resolve3(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((resolve2) => {
294
+ return await new Promise((resolve3) => {
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
- resolve2(value);
301
+ resolve3(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((resolve2) => {
393
+ return await new Promise((resolve3) => {
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
- resolve2([...selected].sort((a, b) => a - b).map((i) => choices[i].value));
400
+ resolve3([...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") {
@@ -452,7 +452,7 @@ var init_prompt = __esm({
452
452
  // src/menu/store.ts
453
453
  import { homedir } from "node:os";
454
454
  import { join } from "node:path";
455
- import { mkdirSync, readFileSync, writeFileSync, existsSync } from "node:fs";
455
+ import { chmodSync, mkdirSync, readFileSync, writeFileSync, existsSync } from "node:fs";
456
456
  function configDir() {
457
457
  const override = process.env.CFPILOT_CONFIG_DIR?.trim();
458
458
  return override ? override : join(homedir(), ".cfpilot");
@@ -472,14 +472,28 @@ function loadConfig() {
472
472
  return {};
473
473
  }
474
474
  }
475
+ function ensureConfigDir() {
476
+ const dir = configDir();
477
+ mkdirSync(dir, { recursive: true, mode: DIR_MODE });
478
+ try {
479
+ chmodSync(dir, DIR_MODE);
480
+ } catch {
481
+ }
482
+ return dir;
483
+ }
475
484
  function saveConfig(patch) {
476
485
  const current = loadConfig();
477
486
  const next = { ...current, ...patch };
478
487
  for (const k of Object.keys(next)) {
479
488
  if (next[k] === "" || next[k] === void 0) delete next[k];
480
489
  }
481
- mkdirSync(configDir(), { recursive: true });
482
- writeFileSync(configFile(), JSON.stringify(next, null, 2) + "\n", "utf8");
490
+ ensureConfigDir();
491
+ const file = configFile();
492
+ writeFileSync(file, JSON.stringify(next, null, 2) + "\n", { encoding: "utf8", mode: FILE_MODE });
493
+ try {
494
+ chmodSync(file, FILE_MODE);
495
+ } catch {
496
+ }
483
497
  }
484
498
  function saveToken(token, keep = {}) {
485
499
  const trimmed = token.trim();
@@ -500,7 +514,12 @@ function saveToken(token, keep = {}) {
500
514
  }
501
515
  function clearConfig() {
502
516
  const file = configFile();
503
- if (existsSync(file)) writeFileSync(file, "{}\n", "utf8");
517
+ if (!existsSync(file)) return;
518
+ writeFileSync(file, "{}\n", { encoding: "utf8", mode: FILE_MODE });
519
+ try {
520
+ chmodSync(file, FILE_MODE);
521
+ } catch {
522
+ }
504
523
  }
505
524
  function resolveToken(fromArgs) {
506
525
  return (fromArgs || "").trim() || (process.env.CLOUDFLARE_API_TOKEN || "").trim() || loadConfig().token || "";
@@ -508,10 +527,12 @@ function resolveToken(fromArgs) {
508
527
  function isConfigured(cfg = loadConfig()) {
509
528
  return Boolean(cfg.token);
510
529
  }
511
- var ACCOUNT_SCOPED_FIELDS;
530
+ var DIR_MODE, FILE_MODE, ACCOUNT_SCOPED_FIELDS;
512
531
  var init_store = __esm({
513
532
  "src/menu/store.ts"() {
514
533
  "use strict";
534
+ DIR_MODE = 448;
535
+ FILE_MODE = 384;
515
536
  ACCOUNT_SCOPED_FIELDS = [
516
537
  "accountId",
517
538
  "accountName",
@@ -1567,7 +1588,8 @@ var init_github_mirrors = __esm({
1567
1588
  });
1568
1589
 
1569
1590
  // src/deploy/kernel-remote.ts
1570
- import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
1591
+ import { createHash } from "node:crypto";
1592
+ import { mkdir, readFile, rename, unlink, writeFile } from "node:fs/promises";
1571
1593
  import { homedir as homedir2 } from "node:os";
1572
1594
  import { dirname, join as join2, resolve } from "node:path";
1573
1595
  import { fileURLToPath } from "node:url";
@@ -1591,10 +1613,11 @@ async function fetchRemoteKernelInfo(options = {}) {
1591
1613
  for (const item of sorted) {
1592
1614
  const controlUrl = findAssetUrl(item.release.assets ?? [], CONTROL_ASSET_NAME);
1593
1615
  const dataUrl = findAssetUrl(item.release.assets ?? [], DATA_ASSET_NAME);
1616
+ const checksumsUrl = findAssetUrl(item.release.assets ?? [], CHECKSUMS_ASSET_NAME);
1594
1617
  if (!controlUrl || !dataUrl) {
1595
1618
  continue;
1596
1619
  }
1597
- return { version: item.version, controlUrl, dataUrl };
1620
+ return { version: item.version, controlUrl, dataUrl, checksumsUrl };
1598
1621
  }
1599
1622
  return null;
1600
1623
  }
@@ -1627,14 +1650,19 @@ async function fetchReleasesWithFallback(timeoutMs) {
1627
1650
  prerelease: false,
1628
1651
  assets: [
1629
1652
  { name: CONTROL_ASSET_NAME, browser_download_url: controlUrl },
1630
- { name: DATA_ASSET_NAME, browser_download_url: dataUrl }
1653
+ { name: DATA_ASSET_NAME, browser_download_url: dataUrl },
1654
+ {
1655
+ name: CHECKSUMS_ASSET_NAME,
1656
+ browser_download_url: `${RELEASES_WEB}/latest/download/${CHECKSUMS_ASSET_NAME}`
1657
+ }
1631
1658
  ]
1632
1659
  };
1633
1660
  return [pseudo];
1634
1661
  }
1635
1662
  function findAssetUrl(assets, name) {
1663
+ const want = name.trim().toLowerCase();
1636
1664
  for (const asset of assets) {
1637
- if (asset.name.trim().toLowerCase() === name) return asset.browser_download_url;
1665
+ if (asset.name.trim().toLowerCase() === want) return asset.browser_download_url;
1638
1666
  }
1639
1667
  return "";
1640
1668
  }
@@ -1650,10 +1678,11 @@ function isGitHubRelease(value) {
1650
1678
  if (item.assets !== void 0 && !Array.isArray(item.assets)) return false;
1651
1679
  return true;
1652
1680
  }
1653
- async function downloadAsset(url, timeoutMs) {
1681
+ async function downloadAsset(url, timeoutMs, options = {}) {
1654
1682
  if (!url.trim()) throw new Error("\u4E0B\u8F7D\u5730\u5740\u4E3A\u7A7A");
1683
+ const sources = options.allowMirrors === false ? [{ name: "GitHub", url }] : downloadSources(url);
1655
1684
  const errors = [];
1656
- for (const source of downloadSources(url)) {
1685
+ for (const source of sources) {
1657
1686
  try {
1658
1687
  const response = await fetch(source.url, {
1659
1688
  headers: { "User-Agent": "CFPilot-CLI" },
@@ -1710,6 +1739,47 @@ async function readBodyWithLimit(response) {
1710
1739
  out += decoder.decode();
1711
1740
  return out;
1712
1741
  }
1742
+ function sha256Hex(content) {
1743
+ return createHash("sha256").update(content, "utf8").digest("hex");
1744
+ }
1745
+ function parseChecksums(text) {
1746
+ const out = /* @__PURE__ */ new Map();
1747
+ for (const raw of text.split("\n")) {
1748
+ const line = raw.trim();
1749
+ if (!line || line.startsWith("#")) continue;
1750
+ const match = /^([0-9a-fA-F]{64})\s+\*?(.+)$/.exec(line);
1751
+ if (!match) continue;
1752
+ out.set(match[2].trim().toLowerCase(), match[1].toLowerCase());
1753
+ }
1754
+ return out;
1755
+ }
1756
+ async function downloadChecksums(info, timeoutMs) {
1757
+ if (!info.checksumsUrl.trim()) {
1758
+ throw new Error(
1759
+ `Release ${info.version} \u672A\u53D1\u5E03 ${CHECKSUMS_ASSET_NAME}\uFF0C\u65E0\u6CD5\u6821\u9A8C\u5185\u6838\u5B8C\u6574\u6027`
1760
+ );
1761
+ }
1762
+ const text = await downloadAsset(info.checksumsUrl, timeoutMs, { allowMirrors: false });
1763
+ const map = parseChecksums(text);
1764
+ for (const name of [CONTROL_ASSET_NAME, DATA_ASSET_NAME]) {
1765
+ if (!map.has(name.toLowerCase())) {
1766
+ throw new Error(`\u5185\u6838\u6821\u9A8C\u6E05\u5355\u7F3A\u5C11 ${name} \u7684\u6458\u8981`);
1767
+ }
1768
+ }
1769
+ return { text, map };
1770
+ }
1771
+ function verifyAsset(shortName, content, map) {
1772
+ const assetName = ASSET_BY_SHORT_NAME[shortName];
1773
+ if (!assetName) throw new Error(`\u672A\u77E5\u5185\u6838\u4EA7\u7269\uFF1A${shortName}`);
1774
+ const expected = map.get(assetName.toLowerCase());
1775
+ if (!expected) throw new Error(`\u6821\u9A8C\u6E05\u5355\u7F3A\u5C11 ${assetName} \u7684\u6458\u8981`);
1776
+ const actual = sha256Hex(content);
1777
+ if (actual !== expected) {
1778
+ throw new Error(
1779
+ `\u5185\u6838\u4EA7\u7269 ${assetName} \u6458\u8981\u4E0D\u5339\u914D\uFF08\u671F\u671B ${expected.slice(0, 12)}\u2026\uFF0C\u5B9E\u9645 ${actual.slice(0, 12)}\u2026\uFF09\u2014\u2014 \u5DF2\u62D2\u7EDD\u4F7F\u7528`
1780
+ );
1781
+ }
1782
+ }
1713
1783
  function cacheRoot() {
1714
1784
  const override = process.env[CACHE_DIR_ENV]?.trim();
1715
1785
  if (override) return override;
@@ -1783,7 +1853,7 @@ async function loadKernelBundle(currentVersion, options = {}) {
1783
1853
  control: bundle.control,
1784
1854
  data: bundle.data,
1785
1855
  version: remote.version,
1786
- source: `\u8FDC\u7A0B ${remote.version}`
1856
+ source: `\u8FDC\u7A0B ${remote.version}\uFF08\u5DF2\u6821\u9A8C\uFF09`
1787
1857
  };
1788
1858
  } catch (err) {
1789
1859
  log(
@@ -1804,20 +1874,46 @@ async function fetchRemoteKernel(info, timeoutMs) {
1804
1874
  const dir = cacheDir(info.version);
1805
1875
  const controlPath = join2(dir, "control.js");
1806
1876
  const dataPath = join2(dir, "dataplane.js");
1807
- const cachedControl = await readCached(controlPath);
1808
- const cachedData = await readCached(dataPath);
1809
- if (cachedControl && cachedData) {
1810
- return { control: cachedControl, data: cachedData };
1877
+ const sumsPath = join2(dir, "SHA256SUMS");
1878
+ let sumsText = await readCached(sumsPath);
1879
+ let sums = sumsText ? parseChecksums(sumsText) : null;
1880
+ const sumsComplete = sums !== null && sums.has(CONTROL_ASSET_NAME.toLowerCase()) && sums.has(DATA_ASSET_NAME.toLowerCase());
1881
+ if (!sums || !sumsComplete) {
1882
+ const fetched = await downloadChecksums(info, timeoutMs);
1883
+ sumsText = fetched.text;
1884
+ sums = fetched.map;
1885
+ }
1886
+ let control = await readCached(controlPath);
1887
+ let data = await readCached(dataPath);
1888
+ if (control) {
1889
+ try {
1890
+ verifyAsset("control.js", control, sums);
1891
+ } catch {
1892
+ control = null;
1893
+ await unlink(controlPath).catch(() => void 0);
1894
+ }
1895
+ }
1896
+ if (data) {
1897
+ try {
1898
+ verifyAsset("dataplane.js", data, sums);
1899
+ } catch {
1900
+ data = null;
1901
+ await unlink(dataPath).catch(() => void 0);
1902
+ }
1811
1903
  }
1812
- const control = cachedControl ?? await downloadAsset(info.controlUrl, timeoutMs);
1813
- const data = cachedData ?? await downloadAsset(info.dataUrl, timeoutMs);
1904
+ if (control && data) return { control, data };
1905
+ control ??= await downloadAsset(info.controlUrl, timeoutMs);
1906
+ verifyAsset("control.js", control, sums);
1907
+ data ??= await downloadAsset(info.dataUrl, timeoutMs);
1908
+ verifyAsset("dataplane.js", data, sums);
1814
1909
  if (!control.trim()) throw new Error("\u4E0B\u8F7D\u5230\u7684\u63A7\u5236\u9762\u4EA7\u7269\u4E3A\u7A7A");
1815
1910
  if (!data.trim()) throw new Error("\u4E0B\u8F7D\u5230\u7684\u6570\u636E\u9762\u4EA7\u7269\u4E3A\u7A7A");
1911
+ await writeCached(sumsPath, sumsText).catch(() => void 0);
1816
1912
  await writeCached(controlPath, control).catch(() => void 0);
1817
1913
  await writeCached(dataPath, data).catch(() => void 0);
1818
1914
  return { control, data };
1819
1915
  }
1820
- var CONTROL_ASSET_NAME, DATA_ASSET_NAME, REPO, RELEASES_API2, DEFAULT_TIMEOUT_MS, MAX_ASSET_BYTES, CACHE_DIR_ENV, LOCAL_DIR_ENV, REMOTE_OFF_ENV, BUILD_RE, BUILD_NUMERIC_RE;
1916
+ var CONTROL_ASSET_NAME, DATA_ASSET_NAME, CHECKSUMS_ASSET_NAME, REPO, RELEASES_API2, DEFAULT_TIMEOUT_MS, MAX_ASSET_BYTES, CACHE_DIR_ENV, LOCAL_DIR_ENV, REMOTE_OFF_ENV, BUILD_RE, BUILD_NUMERIC_RE, ASSET_BY_SHORT_NAME;
1821
1917
  var init_kernel_remote = __esm({
1822
1918
  "src/deploy/kernel-remote.ts"() {
1823
1919
  "use strict";
@@ -1825,6 +1921,7 @@ var init_kernel_remote = __esm({
1825
1921
  init_github_mirrors();
1826
1922
  CONTROL_ASSET_NAME = "cfpilot-kernel-control.js";
1827
1923
  DATA_ASSET_NAME = "cfpilot-kernel-dataplane.js";
1924
+ CHECKSUMS_ASSET_NAME = "cfpilot-kernel-SHA256SUMS";
1828
1925
  REPO = "xmwengxing/CFPilot";
1829
1926
  RELEASES_API2 = process.env.CFPILOT_KERNEL_API_BASE ?? `https://api.github.com/repos/${REPO}/releases`;
1830
1927
  DEFAULT_TIMEOUT_MS = 2e4;
@@ -1834,6 +1931,10 @@ var init_kernel_remote = __esm({
1834
1931
  REMOTE_OFF_ENV = "CFPILOT_KERNEL_REMOTE";
1835
1932
  BUILD_RE = /["']([0-9a-f]{7,10}-(?:[0-9a-f]{4,16}|[0-9]{12}))["']/;
1836
1933
  BUILD_NUMERIC_RE = /["'](\d{10,14})["']/;
1934
+ ASSET_BY_SHORT_NAME = {
1935
+ "control.js": CONTROL_ASSET_NAME,
1936
+ "dataplane.js": DATA_ASSET_NAME
1937
+ };
1837
1938
  }
1838
1939
  });
1839
1940
 
@@ -3160,6 +3261,11 @@ var init_status = __esm({
3160
3261
  });
3161
3262
 
3162
3263
  // src/scan/countries.ts
3264
+ function isRegionGroup(code) {
3265
+ const key = String(code ?? "").trim().toUpperCase();
3266
+ if (!Object.prototype.hasOwnProperty.call(REGION_GROUPS, key)) return false;
3267
+ return true;
3268
+ }
3163
3269
  function countryOfColo(colo) {
3164
3270
  return coloToCountry.get(colo.toUpperCase()) ?? "";
3165
3271
  }
@@ -3169,14 +3275,29 @@ function isKnownCountry(code) {
3169
3275
  function normalizeCountryFilter(input) {
3170
3276
  if (!Array.isArray(input)) return [];
3171
3277
  const out = [];
3278
+ const push = (code) => {
3279
+ if (code && !out.includes(code)) out.push(code);
3280
+ };
3172
3281
  for (const raw of input) {
3173
3282
  const code = String(raw ?? "").trim().toUpperCase();
3174
- if (!code || out.includes(code)) continue;
3175
- if (isKnownCountry(code)) out.push(code);
3283
+ if (!code) continue;
3284
+ if (isRegionGroup(code)) {
3285
+ for (const member of REGION_GROUPS[code] ?? []) push(String(member).toUpperCase());
3286
+ continue;
3287
+ }
3288
+ if (isKnownCountry(code)) {
3289
+ push(code);
3290
+ continue;
3291
+ }
3292
+ const country = countryOfColo(code);
3293
+ if (country) push(country);
3176
3294
  }
3177
3295
  return out;
3178
3296
  }
3179
- var COUNTRY_COLOS, coloToCountry, SUPPORTED_COUNTRIES;
3297
+ function coloCity(colo) {
3298
+ return COLO_CITIES[colo.toUpperCase()] ?? "";
3299
+ }
3300
+ var COUNTRY_COLOS, REGION_GROUPS, REGION_GROUP_NAMES, coloToCountry, SUPPORTED_COUNTRIES, COLO_CITIES;
3180
3301
  var init_countries = __esm({
3181
3302
  "src/scan/countries.ts"() {
3182
3303
  "use strict";
@@ -3216,11 +3337,88 @@ var init_countries = __esm({
3216
3337
  CL: ["SCL"],
3217
3338
  MX: ["MEX"]
3218
3339
  };
3340
+ REGION_GROUPS = {
3341
+ ASIA: ["HK", "TW", "JP", "KR", "SG", "MY", "TH", "VN", "ID", "PH", "IN", "AE", "IL"],
3342
+ US: ["US"]
3343
+ };
3344
+ REGION_GROUP_NAMES = {
3345
+ ASIA: "\u4E9A\u6D32\u7EC4",
3346
+ US: "\u7F8E\u56FD\u7EC4"
3347
+ };
3219
3348
  coloToCountry = /* @__PURE__ */ new Map();
3220
3349
  for (const [country, colos] of Object.entries(COUNTRY_COLOS)) {
3221
3350
  for (const colo of colos) coloToCountry.set(colo, country);
3222
3351
  }
3223
3352
  SUPPORTED_COUNTRIES = Object.keys(COUNTRY_COLOS);
3353
+ COLO_CITIES = {
3354
+ HKG: "\u9999\u6E2F",
3355
+ TPE: "\u53F0\u5317",
3356
+ KHH: "\u9AD8\u96C4",
3357
+ NRT: "\u4E1C\u4EAC",
3358
+ KIX: "\u5927\u962A",
3359
+ CTS: "\u672D\u5E4C",
3360
+ FUK: "\u798F\u5188",
3361
+ ICN: "\u9996\u5C14",
3362
+ PUS: "\u91DC\u5C71",
3363
+ SIN: "\u65B0\u52A0\u5761",
3364
+ KUL: "\u5409\u9686\u5761",
3365
+ BKK: "\u66FC\u8C37",
3366
+ SGN: "\u80E1\u5FD7\u660E\u5E02",
3367
+ HAN: "\u6CB3\u5185",
3368
+ CGK: "\u96C5\u52A0\u8FBE",
3369
+ DPS: "\u767B\u5DF4\u8428",
3370
+ MNL: "\u9A6C\u5C3C\u62C9",
3371
+ BOM: "\u5B5F\u4E70",
3372
+ MAA: "\u91D1\u5948",
3373
+ DEL: "\u65B0\u5FB7\u91CC",
3374
+ SYD: "\u6089\u5C3C",
3375
+ MEL: "\u58A8\u5C14\u672C",
3376
+ BNE: "\u5E03\u91CC\u65AF\u73ED",
3377
+ PER: "\u73C0\u65AF",
3378
+ AKL: "\u5965\u514B\u5170",
3379
+ LAX: "\u6D1B\u6749\u77F6",
3380
+ SJC: "\u5723\u4F55\u585E",
3381
+ SEA: "\u897F\u96C5\u56FE",
3382
+ ORD: "\u829D\u52A0\u54E5",
3383
+ DFW: "\u8FBE\u62C9\u65AF",
3384
+ IAD: "\u534E\u76DB\u987F",
3385
+ EWR: "\u7EBD\u74E6\u514B",
3386
+ ATL: "\u4E9A\u7279\u5170\u5927",
3387
+ MIA: "\u8FC8\u963F\u5BC6",
3388
+ DEN: "\u4E39\u4F5B",
3389
+ PHX: "\u51E4\u51F0\u57CE",
3390
+ BOS: "\u6CE2\u58EB\u987F",
3391
+ YYZ: "\u591A\u4F26\u591A",
3392
+ YVR: "\u6E29\u54E5\u534E",
3393
+ YYC: "\u5361\u5C14\u52A0\u91CC",
3394
+ LHR: "\u4F26\u6566",
3395
+ MAN: "\u66FC\u5F7B\u65AF\u7279",
3396
+ FRA: "\u6CD5\u5170\u514B\u798F",
3397
+ MUC: "\u6155\u5C3C\u9ED1",
3398
+ BER: "\u67CF\u6797",
3399
+ CDG: "\u5DF4\u9ECE",
3400
+ MRS: "\u9A6C\u8D5B",
3401
+ AMS: "\u963F\u59C6\u65AF\u7279\u4E39",
3402
+ MXP: "\u7C73\u5170",
3403
+ FCO: "\u7F57\u9A6C",
3404
+ MAD: "\u9A6C\u5FB7\u91CC",
3405
+ BCN: "\u5DF4\u585E\u7F57\u90A3",
3406
+ ARN: "\u65AF\u5FB7\u54E5\u5C14\u6469",
3407
+ ZRH: "\u82CF\u9ECE\u4E16",
3408
+ VIE: "\u7EF4\u4E5F\u7EB3",
3409
+ WAW: "\u534E\u6C99",
3410
+ DME: "\u83AB\u65AF\u79D1",
3411
+ SVO: "\u83AB\u65AF\u79D1",
3412
+ IST: "\u4F0A\u65AF\u5766\u5E03\u5C14",
3413
+ DXB: "\u8FEA\u62DC",
3414
+ TLV: "\u7279\u62C9\u7EF4\u592B",
3415
+ JNB: "\u7EA6\u7FF0\u5185\u65AF\u5821",
3416
+ GRU: "\u5723\u4FDD\u7F57",
3417
+ GIG: "\u91CC\u7EA6\u70ED\u5185\u5362",
3418
+ EZE: "\u5E03\u5B9C\u8BFA\u65AF\u827E\u5229\u65AF",
3419
+ SCL: "\u5723\u5730\u4E9A\u54E5",
3420
+ MEX: "\u58A8\u897F\u54E5\u57CE"
3421
+ };
3224
3422
  }
3225
3423
  });
3226
3424
 
@@ -3232,7 +3430,7 @@ function extractColo(text) {
3232
3430
  return match ? match[1].toUpperCase() : "";
3233
3431
  }
3234
3432
  function probeWs101(ip, port, host, timeoutMs = 3e3, path = "/__edge_probe") {
3235
- return new Promise((resolve2) => {
3433
+ return new Promise((resolve3) => {
3236
3434
  const started = Date.now();
3237
3435
  const key = crypto.randomBytes(16).toString("base64");
3238
3436
  let settled = false;
@@ -3245,7 +3443,7 @@ function probeWs101(ip, port, host, timeoutMs = 3e3, path = "/__edge_probe") {
3245
3443
  socket.destroy();
3246
3444
  } catch {
3247
3445
  }
3248
- resolve2({ ...result, latencyMs: Date.now() - started });
3446
+ resolve3({ ...result, latencyMs: Date.now() - started });
3249
3447
  };
3250
3448
  const request = [
3251
3449
  `GET ${path} HTTP/1.1`,
@@ -3348,7 +3546,7 @@ function decodeWsFrame(buf) {
3348
3546
  return { frame, rest };
3349
3547
  }
3350
3548
  function probeWsPing(ip, port, host, timeoutMs = 5e3, path = "/__edge_probe") {
3351
- return new Promise((resolve2) => {
3549
+ return new Promise((resolve3) => {
3352
3550
  const started = Date.now();
3353
3551
  const key = crypto.randomBytes(16).toString("base64");
3354
3552
  let settled = false;
@@ -3363,7 +3561,7 @@ function probeWsPing(ip, port, host, timeoutMs = 5e3, path = "/__edge_probe") {
3363
3561
  socket.destroy();
3364
3562
  } catch {
3365
3563
  }
3366
- resolve2({ ...result, latencyMs: Date.now() - started });
3564
+ resolve3({ ...result, latencyMs: Date.now() - started });
3367
3565
  };
3368
3566
  const request = [
3369
3567
  `GET ${path} HTTP/1.1`,
@@ -3474,7 +3672,7 @@ function probeWsPing(ip, port, host, timeoutMs = 5e3, path = "/__edge_probe") {
3474
3672
  });
3475
3673
  }
3476
3674
  function probeTlsHandshake(ip, port, host, timeoutMs = 4e3) {
3477
- return new Promise((resolve2) => {
3675
+ return new Promise((resolve3) => {
3478
3676
  const started = Date.now();
3479
3677
  let settled = false;
3480
3678
  const finish = (result) => {
@@ -3485,7 +3683,7 @@ function probeTlsHandshake(ip, port, host, timeoutMs = 4e3) {
3485
3683
  socket.destroy();
3486
3684
  } catch {
3487
3685
  }
3488
- resolve2({ ip, tlsMs: result.tlsMs ?? Date.now() - started, ...result });
3686
+ resolve3({ ip, tlsMs: result.tlsMs ?? Date.now() - started, ...result });
3489
3687
  };
3490
3688
  const socket = tls.connect(
3491
3689
  {
@@ -3525,7 +3723,7 @@ function measureThroughput(options) {
3525
3723
  minBytes = 32 * 1024
3526
3724
  } = options;
3527
3725
  const connCount = Math.max(1, Math.min(8, connections));
3528
- return new Promise((resolve2) => {
3726
+ return new Promise((resolve3) => {
3529
3727
  const started = Date.now();
3530
3728
  let settled = false;
3531
3729
  const meter = new WindowMeter({ startedAt: started, warmupMs, windowMs });
@@ -3555,7 +3753,7 @@ function measureThroughput(options) {
3555
3753
  else if (totalBytes === 0) error = lastError || "\u672A\u6536\u5230\u6570\u636E";
3556
3754
  else error = lastError || `\u8F7D\u8377\u4E0D\u8DB3\uFF08${totalBytes}/${minBytes} \u5B57\u8282\uFF09`;
3557
3755
  }
3558
- resolve2({
3756
+ resolve3({
3559
3757
  ok,
3560
3758
  bytes: totalBytes,
3561
3759
  ms: now - started,
@@ -3705,7 +3903,7 @@ function verifyTunnel(options) {
3705
3903
  const { ip, port, host, wsPath, uuid, trojanPassword, targetHost = "baidu.com", targetPort = 80, timeoutMs = 8e3 } = options;
3706
3904
  const payload = uuid ? buildVlessTunnelPayload(uuid, targetHost, targetPort, tunnelTargetRequest(targetHost)) : trojanPassword ? buildTrojanTunnelPayload(trojanPassword, targetHost, targetPort, tunnelTargetRequest(targetHost)) : null;
3707
3905
  if (!payload) return Promise.resolve({ ok: false, stage: "protocol", latencyMs: 0, error: "\u7F3A\u5C11 uuid / trojanPassword" });
3708
- return new Promise((resolve2) => {
3906
+ return new Promise((resolve3) => {
3709
3907
  const started = Date.now();
3710
3908
  const key = crypto.randomBytes(16).toString("base64");
3711
3909
  let settled = false;
@@ -3719,7 +3917,7 @@ function verifyTunnel(options) {
3719
3917
  socket.destroy();
3720
3918
  } catch {
3721
3919
  }
3722
- resolve2({ ...r, latencyMs: Date.now() - started });
3920
+ resolve3({ ...r, latencyMs: Date.now() - started });
3723
3921
  };
3724
3922
  const socket = tls.connect({ host: ip, port, servername: host, rejectUnauthorized: false, ALPNProtocols: ["http/1.1"] }, () => {
3725
3923
  socket.write(tunnelUpgradeRequest(host, wsPath, key));
@@ -3889,7 +4087,7 @@ function schemeForPort(port) {
3889
4087
  return port === 443 || port === 2053 || port === 2083 || port === 2087 || port === 2096 || port === 8443 ? "https" : "http";
3890
4088
  }
3891
4089
  function checkSpeedUrlAvailable(parsed, timeoutMs = 6e3) {
3892
- return new Promise((resolve2) => {
4090
+ return new Promise((resolve3) => {
3893
4091
  let settled = false;
3894
4092
  let received = "";
3895
4093
  const finish = (available, status2, error) => {
@@ -3900,7 +4098,7 @@ function checkSpeedUrlAvailable(parsed, timeoutMs = 6e3) {
3900
4098
  socket.destroy();
3901
4099
  } catch {
3902
4100
  }
3903
- resolve2({ available, status: status2, error });
4101
+ resolve3({ available, status: status2, error });
3904
4102
  };
3905
4103
  const path = parsed.path.includes("bytes=") ? parsed.path.replace(/bytes=\d+/, "bytes=1024") : parsed.path;
3906
4104
  const request = [
@@ -3977,10 +4175,99 @@ var init_speed_url = __esm({
3977
4175
  }
3978
4176
  });
3979
4177
 
4178
+ // src/scan/unlock.ts
4179
+ import * as tls3 from "node:tls";
4180
+ function probeUnlock(options) {
4181
+ const { ip, port = 443, host, token, timeoutMs = 12e3 } = options;
4182
+ return new Promise((resolve3) => {
4183
+ let settled = false;
4184
+ let raw = Buffer.alloc(0);
4185
+ const finish = (result) => {
4186
+ if (settled) return;
4187
+ settled = true;
4188
+ try {
4189
+ socket.destroy();
4190
+ } catch {
4191
+ }
4192
+ resolve3(result);
4193
+ };
4194
+ const socket = tls3.connect(
4195
+ {
4196
+ host: ip,
4197
+ port,
4198
+ servername: host,
4199
+ // 证书是给域名签的,我们连的是 IP;这里只验证「能不能通」,不校验证书链
4200
+ rejectUnauthorized: false,
4201
+ ALPNProtocols: ["http/1.1"]
4202
+ },
4203
+ () => {
4204
+ socket.write(
4205
+ [
4206
+ "GET /__unlock_probe HTTP/1.1",
4207
+ `Host: ${host}`,
4208
+ `x-cfpilot-token: ${token}`,
4209
+ "Accept: application/json",
4210
+ "Connection: close",
4211
+ "",
4212
+ ""
4213
+ ].join("\r\n")
4214
+ );
4215
+ }
4216
+ );
4217
+ socket.setTimeout(timeoutMs, () => finish({ ok: false, colo: "", region: "", targets: [], error: "\u8D85\u65F6" }));
4218
+ socket.on("error", (err) => finish({ ok: false, colo: "", region: "", targets: [], error: err.message }));
4219
+ socket.on("data", (chunk) => {
4220
+ raw = raw.length === 0 ? chunk : Buffer.concat([raw, chunk]);
4221
+ const idx = raw.indexOf("\r\n\r\n");
4222
+ if (idx < 0) {
4223
+ if (raw.length > 16384) finish({ ok: false, colo: "", region: "", targets: [], error: "\u54CD\u5E94\u5934\u5F02\u5E38" });
4224
+ return;
4225
+ }
4226
+ const head = raw.subarray(0, idx).toString("latin1");
4227
+ const status2 = /^HTTP\/1\.[01]\s+(\d{3})/.exec(head)?.[1];
4228
+ const body = raw.subarray(idx + 4).toString("utf8");
4229
+ if (status2 !== "200") {
4230
+ finish({
4231
+ ok: false,
4232
+ colo: "",
4233
+ region: "",
4234
+ targets: [],
4235
+ error: status2 === "404" ? "\u7AEF\u70B9\u672A\u5F00\u542F\uFF08\u9762\u677F\u300C\u51FA\u7AD9\u4E0E\u9AD8\u7EA7\u300D\u91CC\u6253\u5F00\u300C\u51FA\u53E3\u4F53\u68C0\u300D\uFF09" : status2 === "403" ? "\u4EE4\u724C\u65E0\u6548\uFF08\u9700\u4F20\u5B8C\u6574 UUID\uFF09" : `HTTP ${status2 ?? "?"}`
4236
+ });
4237
+ return;
4238
+ }
4239
+ try {
4240
+ const parsed = JSON.parse(body);
4241
+ finish({
4242
+ ok: true,
4243
+ colo: parsed.colo ?? "",
4244
+ region: parsed.region ?? "",
4245
+ targets: Array.isArray(parsed.targets) ? parsed.targets : []
4246
+ });
4247
+ } catch {
4248
+ finish({ ok: false, colo: "", region: "", targets: [], error: "\u54CD\u5E94\u4E0D\u662F\u5408\u6CD5 JSON" });
4249
+ }
4250
+ });
4251
+ socket.on("end", () => {
4252
+ if (!settled) finish({ ok: false, colo: "", region: "", targets: [], error: "\u8FDE\u63A5\u63D0\u524D\u7ED3\u675F" });
4253
+ });
4254
+ });
4255
+ }
4256
+ function describeUnlock(result) {
4257
+ if (!result.ok) return `\u4F53\u68C0\u5931\u8D25\uFF1A${result.error ?? "\u672A\u77E5\u539F\u56E0"}`;
4258
+ const parts = result.targets.map((t) => `${t.id}:${t.verdict}`);
4259
+ return `${result.colo || "UNK"} ${parts.join(" ")}`;
4260
+ }
4261
+ var init_unlock = __esm({
4262
+ "src/scan/unlock.ts"() {
4263
+ "use strict";
4264
+ }
4265
+ });
4266
+
3980
4267
  // src/scan/scan.ts
3981
4268
  import * as net2 from "node:net";
3982
4269
  async function tcpPing(ip, port, timeoutMs) {
3983
- return new Promise((resolve2) => {
4270
+ return new Promise((resolve3) => {
3984
4271
  const started = Date.now();
3985
4272
  let settled = false;
3986
4273
  const socket = new net2.Socket();
@@ -3991,7 +4278,7 @@ async function tcpPing(ip, port, timeoutMs) {
3991
4278
  socket.destroy();
3992
4279
  } catch {
3993
4280
  }
3994
- resolve2({ ip, ok, latency: Date.now() - started });
4281
+ resolve3({ ip, ok, latency: Date.now() - started });
3995
4282
  };
3996
4283
  socket.setTimeout(timeoutMs, () => done(false));
3997
4284
  socket.once("connect", () => done(true));
@@ -4016,6 +4303,7 @@ async function pool(items, concurrency, worker, shouldStop) {
4016
4303
  async function poolAdaptive(items, concurrency, worker, batchSize = 200) {
4017
4304
  const out = [];
4018
4305
  const maxConcurrency = Math.max(1, concurrency);
4306
+ const minConcurrency = Math.min(8, maxConcurrency);
4019
4307
  let current = maxConcurrency;
4020
4308
  for (let start = 0; start < items.length; start += batchSize) {
4021
4309
  const batch = items.slice(start, start + batchSize);
@@ -4024,7 +4312,7 @@ async function poolAdaptive(items, concurrency, worker, batchSize = 200) {
4024
4312
  const okCount = results.reduce((n, r) => n + (r.ok ? 1 : 0), 0);
4025
4313
  const rate = results.length > 0 ? okCount / results.length : 1;
4026
4314
  if (rate < 0.4) {
4027
- current = Math.max(8, Math.floor(current / 2));
4315
+ current = Math.max(minConcurrency, Math.min(maxConcurrency, Math.floor(current / 2)));
4028
4316
  } else if (rate > 0.85) {
4029
4317
  current = Math.min(maxConcurrency, current * 2);
4030
4318
  }
@@ -4311,6 +4599,33 @@ async function runScan(options) {
4311
4599
  (a, b) => options.skipSpeed ? a.tlsMs - b.tlsMs || a.latency - b.latency : b.speed - a.speed || a.tlsMs - b.tlsMs || a.latency - b.latency
4312
4600
  );
4313
4601
  const entries = pickWithDiversity(ranked, top);
4602
+ if (options.unlock && options.uuid && entries.length > 0) {
4603
+ const byColo = /* @__PURE__ */ new Map();
4604
+ for (const entry of entries) {
4605
+ const key = entry.colo || "UNK";
4606
+ if (!byColo.has(key)) byColo.set(key, entry);
4607
+ }
4608
+ const reps = [...byColo.values()];
4609
+ report({ type: "stage", stage: 4, name: "\u51FA\u53E3\u4F53\u68C0\uFF08\u6309\u673A\u623F\u53BB\u91CD\uFF09", total: reps.length });
4610
+ let done2 = 0;
4611
+ await pool(reps, 2, async (rep) => {
4612
+ const result = await probeUnlock({
4613
+ ip: rep.ip,
4614
+ port: options.port,
4615
+ host: options.host,
4616
+ token: options.uuid
4617
+ });
4618
+ done2++;
4619
+ report({
4620
+ type: "progress",
4621
+ stage: 4,
4622
+ done: done2,
4623
+ total: reps.length,
4624
+ message: `${rep.colo || "UNK"} ${describeUnlock(result)}`
4625
+ });
4626
+ return result;
4627
+ });
4628
+ }
4314
4629
  for (const entry of entries) {
4315
4630
  report({ type: "result", entry });
4316
4631
  }
@@ -4379,6 +4694,7 @@ var init_scan = __esm({
4379
4694
  init_true_probe();
4380
4695
  init_speed_url();
4381
4696
  init_countries();
4697
+ init_unlock();
4382
4698
  }
4383
4699
  });
4384
4700
 
@@ -4628,6 +4944,7 @@ function splitByWeight(cidr) {
4628
4944
  return out.sort((a, b) => a.base < b.base ? -1 : a.base > b.base ? 1 : 0);
4629
4945
  }
4630
4946
  function expandCidrs(cidrs, options = {}) {
4947
+ const neutral = options.neutral === true;
4631
4948
  const sample = options.sample ?? 2e4;
4632
4949
  const random = makeRandom(options.seed ?? 24301);
4633
4950
  const parsedRaw = cidrs.map(parseCidr).filter((c2) => c2 !== null);
@@ -4653,7 +4970,8 @@ function expandCidrs(cidrs, options = {}) {
4653
4970
  const familyBudget = Math.max(1, Math.round(hasOtherFamily ? sample / 2 : sample));
4654
4971
  const effectiveSize = (c2) => {
4655
4972
  if (c2.family !== 4) return c2.size;
4656
- const weight = cidrWeight(c2.cidr);
4973
+ const raw = cidrWeight(c2.cidr);
4974
+ const weight = neutral ? raw > 0 ? 1 : 0 : raw;
4657
4975
  if (weight <= 0) return 0n;
4658
4976
  const scaled = Number(c2.size) * weight;
4659
4977
  return scaled >= 1 ? BigInt(Math.floor(scaled)) : 0n;
@@ -4668,7 +4986,7 @@ function expandCidrs(cidrs, options = {}) {
4668
4986
  }
4669
4987
  if (familyTotal === 0n) continue;
4670
4988
  const minForCidr = (c2) => {
4671
- if (c2.family !== 4) return minPerCidr;
4989
+ if (c2.family !== 4 || neutral) return minPerCidr;
4672
4990
  const w = cidrWeight(c2.cidr);
4673
4991
  if (w >= 1) return minPerCidr;
4674
4992
  return Math.max(1, Math.round(minPerCidr * w));
@@ -4773,8 +5091,8 @@ var init_ip_ranges = __esm({
4773
5091
  // 复测 11/12,最好的一段(旧表 0.9)
4774
5092
  "188.114.96.0/20": 0.75,
4775
5093
  // 复测 9/12(旧表 0.3 —— 被低估 3 倍)
4776
- "172.64.0.0/13": 0.4,
4777
- // 复测 5/12(旧表 0.1 —— 被低估 5 倍)
5094
+ "172.64.0.0/13": 0.55,
5095
+ // 复测 5/12;2026-10-29 用户侧实测该段出过 9.3 MB/s(NRT),不宜压太低
4778
5096
  "103.21.244.0/22": 0.35,
4779
5097
  // 复测 4/12
4780
5098
  "103.31.4.0/22": 0.3,
@@ -4831,7 +5149,7 @@ var init_ip_ranges = __esm({
4831
5149
  import * as net3 from "node:net";
4832
5150
  import { execFile } from "node:child_process";
4833
5151
  function isPortListening(port, timeoutMs = 400) {
4834
- return new Promise((resolve2) => {
5152
+ return new Promise((resolve3) => {
4835
5153
  const socket = new net3.Socket();
4836
5154
  let settled = false;
4837
5155
  const done = (open) => {
@@ -4841,7 +5159,7 @@ function isPortListening(port, timeoutMs = 400) {
4841
5159
  socket.destroy();
4842
5160
  } catch {
4843
5161
  }
4844
- resolve2(open);
5162
+ resolve3(open);
4845
5163
  };
4846
5164
  socket.setTimeout(timeoutMs, () => done(false));
4847
5165
  socket.once("connect", () => done(true));
@@ -4855,12 +5173,12 @@ function isPortListening(port, timeoutMs = 400) {
4855
5173
  }
4856
5174
  async function readSystemProxy() {
4857
5175
  if (process.platform !== "win32") return "";
4858
- const query = (key) => new Promise((resolve2) => {
5176
+ const query = (key) => new Promise((resolve3) => {
4859
5177
  execFile(
4860
5178
  "reg",
4861
5179
  ["query", "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", "/v", key],
4862
5180
  { timeout: 3e3, windowsHide: true },
4863
- (err, stdout2) => resolve2(err ? "" : String(stdout2))
5181
+ (err, stdout2) => resolve3(err ? "" : String(stdout2))
4864
5182
  );
4865
5183
  });
4866
5184
  try {
@@ -5015,12 +5333,13 @@ async function resolveCandidates(opts = {}) {
5015
5333
  const sample = opts.sample ?? DEFAULT_CANDIDATE_SAMPLE;
5016
5334
  const seed = opts.seed ?? randomSeed();
5017
5335
  const family = opts.family ?? "both";
5336
+ const neutral = opts.neutral === true;
5018
5337
  const customCidrs = normalizeCidrInput(opts.cidr);
5019
5338
  if (customCidrs.length > 0) {
5020
- return expandCidrs(filterByFamily(customCidrs, family), { sample, seed });
5339
+ return expandCidrs(filterByFamily(customCidrs, family), { sample, seed, neutral });
5021
5340
  }
5022
5341
  const cidrs = await loadCloudflareCidrs(family);
5023
- return expandCidrs(cidrs, { sample, seed });
5342
+ return expandCidrs(cidrs, { sample, seed, neutral });
5024
5343
  }
5025
5344
  function randomSeed() {
5026
5345
  return (Date.now() ^ Math.floor(Math.random() * 4294967296)) >>> 0;
@@ -5218,12 +5537,12 @@ function startBridge(options = {}) {
5218
5537
  sendJson(res, 500, { ok: false, error: err instanceof Error ? err.message : String(err) });
5219
5538
  });
5220
5539
  });
5221
- return new Promise((resolve2, reject) => {
5540
+ return new Promise((resolve3, reject) => {
5222
5541
  server.once("error", reject);
5223
5542
  server.listen(port, host, () => {
5224
5543
  const address = server.address();
5225
5544
  const boundPort = typeof address === "object" && address !== null ? address.port : port;
5226
- resolve2({
5545
+ resolve3({
5227
5546
  server,
5228
5547
  port: boundPort,
5229
5548
  close: () => new Promise((done) => {
@@ -5475,7 +5794,9 @@ scan \u9009\u9879:
5475
5794
  \u4E0E TCP \u5EF6\u8FDF\u51E0\u4E4E\u65E0\u5173\uFF08\u5B9E\u6D4B TCP 9ms \u7684 IP \u53EF\u80FD\u8981 3.5 \u79D2\uFF09\uFF0C
5476
5795
  \u91C7\u6837\u5C0F\u4E86\u6839\u672C\u78B0\u4E0D\u5230\u63E1\u624B\u5FEB\u7684 IP
5477
5796
  --countries <a,b> \u56FD\u5BB6 / \u5730\u533A\u8FC7\u6EE4\uFF08\u53EF\u591A\u9009\uFF0C\u9017\u53F7\u5206\u9694\uFF0C\u5982 US,JP,SG\uFF09
5478
- \u4E0D\u9009 = \u5168\u91CF\u3002\u673A\u623F\u6765\u81EA 101 \u63E1\u624B\u54CD\u5E94\u3002
5797
+ \u4E5F\u63A5\u53D7\u5206\u7EC4\u5173\u952E\u5B57\uFF1AASIA = \u4E9A\u6D32\u7EC4\u3001US = \u7F8E\u56FD\u7EC4\uFF0C
5798
+ \u53EF\u4E0E\u56FD\u5BB6\u7801\u6DF7\u5199\uFF08\u5982 ASIA,US\uFF09\uFF1B\u4E0D\u586B = \u5168\u91CF\u3002
5799
+ \u673A\u623F\u6765\u81EA 101 \u63E1\u624B\u54CD\u5E94\u3002
5479
5800
  \u5E26\u6B64\u53C2\u6570\u4F1A\u81EA\u52A8\u6269\u5927 101 \u6821\u9A8C\u7684\u5019\u9009\u6C60\uFF08120 \u2192 \u6700\u591A 500\uFF09\uFF0C
5480
5801
  \u5426\u5219\u76EE\u6807\u5730\u533A\u53EF\u80FD\u56E0\u5EF6\u8FDF\u6392\u5E8F\u88AB\u63D0\u524D\u622A\u65AD\uFF1B
5481
5802
  \u7B5B\u4E0D\u5230\u65F6\u4F1A\u660E\u786E\u63D0\u793A\u300C\u5DF2\u653E\u5BBD\u4E3A\u5168\u91CF\u300D\u800C\u4E0D\u662F\u9759\u9ED8\u5FFD\u7565
@@ -5489,10 +5810,15 @@ scan \u9009\u9879:
5489
5810
  --speed-limit <n> \u8FDB\u5165\u6D4B\u901F\u7684\u5019\u9009\u6570\uFF0C\u9ED8\u8BA4 30
5490
5811
  --speed-bytes <n> \u6D4B\u901F\u5B57\u8282\u6570\uFF0C\u9ED8\u8BA4 5242880
5491
5812
  --timeout <ms> \u9636\u6BB5\u4E00\u8D85\u65F6\uFF0C\u9ED8\u8BA4 1200
5813
+ --neutral-sampling \u4E2D\u6027\u91C7\u6837\uFF1A\u5FFD\u7565\u7F51\u6BB5\u6743\u91CD\u3001\u6309\u7F51\u6BB5\u5927\u5C0F\u7B49\u6BD4\u62BD\u53D6
5814
+ \uFF08\u9009\u56FD\u5BB6\u7B5B\u9009\u65F6\u4F1A\u81EA\u52A8\u542F\u7528\uFF1B\u53EA\u4FDD\u7559 TCP \u5C42\u4E0D\u53EF\u8FBE\u7684\u7F51\u6BB5\uFF09
5492
5815
  --speed-repeat <n> \u6BCF\u4E2A\u5019\u9009\u91CD\u590D\u6D4B\u901F\u6B21\u6570\uFF0C\u9ED8\u8BA4 1\uFF08>1 \u65F6\u53D6\u4E2D\u4F4D\u6570\u5E76\u663E\u793A \xB1\u6296\u52A8\uFF09
5493
5816
  --uuid <uuid> \u771F\u5B9E\u96A7\u9053\u6821\u9A8C\u7528\u7684 VLESS UUID\uFF08\u7ED9\u4E86\u624D\u4F1A\u8DD1\u9636\u6BB5\u4E8C\u70B9\u4E94\uFF09
5494
5817
  --trojan-password <pw> \u771F\u5B9E\u96A7\u9053\u6821\u9A8C\u7528\u7684 Trojan \u53E3\u4EE4\uFF08\u4E0E --uuid \u4E8C\u9009\u4E00\uFF09
5495
5818
  --verify-target <host> \u96A7\u9053\u6821\u9A8C\u8BBF\u95EE\u7684\u76EE\u6807\u57DF\u540D\uFF0C\u9ED8\u8BA4 baidu.com
5819
+ --unlock \u51FA\u53E3\u4F53\u68C0\uFF1A\u6309\u673A\u623F\u53BB\u91CD\uFF0C\u6807\u6CE8 [AI] / [NF]
5820
+ \u9700\u8981 --uuid\uFF08\u7AEF\u70B9\u9274\u6743\uFF09\u4E0E\u9762\u677F\u5F00\u542F\u300C\u51FA\u53E3\u4F53\u68C0\u300D\u5F00\u5173
5821
+ \u7ED3\u679C\u6309\u673A\u623F\u7F13\u5B58 10 \u5206\u949F\uFF0C\u540C\u4E00\u673A\u623F\u53EA\u6253\u4E00\u6B21\u5916\u90E8\u8BF7\u6C42
5496
5822
  --no-verify-ws-path \u8DF3\u8FC7\u300C\u771F\u5B9E WS \u8DEF\u5F84 101\u300D\u8FD9\u9879\u989D\u5916\u6821\u9A8C
5497
5823
  --seed <n> \u91C7\u6837\u968F\u673A\u79CD\u5B50\u3002\u9ED8\u8BA4\u6BCF\u6B21\u968F\u673A \u2014\u2014 \u4FDD\u8BC1\u6BCF\u6B21\u63A2\u7D22\u4E0D\u540C\u7684 IP \u5B50\u96C6
5498
5824
  \uFF08\u5199\u6B7B\u79CD\u5B50\u4F1A\u8BA9\u6BCF\u6B21\u8DD1\u90FD\u6D4B\u540C\u4E00\u6279 IP\uFF0C\u62BD\u5230\u52A3\u8D28\u6BB5\u5C31\u6C38\u8FDC\u6D4B\u4E0D\u51FA\u597D IP\uFF09
@@ -5553,6 +5879,9 @@ async function resolveCandidatesFromArgs(args) {
5553
5879
  return readIpFile(text);
5554
5880
  }
5555
5881
  return resolveCandidates({
5882
+ // 选国家时**自动中性采样**:采样发生在阶段一之前、那时还不知道机房,
5883
+ // 若某国家的 IP 集中在低权重网段,候选会被压少 → 可能「扫了几千个还是找不到 HKG/NRT」。
5884
+ neutral: args.flags["neutral-sampling"] !== void 0 || flagList(args, "countries").length > 0,
5556
5885
  sample: flagNumber(args, "sample", 6556),
5557
5886
  cidr: flagList(args, "cidr"),
5558
5887
  // ⚠️ 不传 seed = 每次随机(默认)。只有用户显式给了 --seed 才固定,
@@ -5596,12 +5925,23 @@ function printTable(entries) {
5596
5925
  const rank = String(index + 1).padStart(2, " ");
5597
5926
  const address = `${formatHost(entry.ip)}:${entry.port}`.padEnd(24, " ");
5598
5927
  const colo = (entry.colo || "UNK").padEnd(6, " ");
5599
- const tls3 = String(entry.tlsMs).padStart(7, " ");
5928
+ const tls4 = String(entry.tlsMs).padStart(7, " ");
5600
5929
  const latency = String(entry.latency).padStart(7, " ");
5601
5930
  const speed = entry.speed.toFixed(1).padStart(9, " ");
5602
- process.stdout.write(`${rank} ${address} ${colo} ${tls3} ${latency} ${speed}
5931
+ process.stdout.write(`${rank} ${address} ${colo} ${tls4} ${latency} ${speed}
5603
5932
  `);
5604
5933
  });
5934
+ const seen = [];
5935
+ for (const entry of entries) {
5936
+ const colo = entry.colo || "UNK";
5937
+ if (!seen.includes(colo)) seen.push(colo);
5938
+ }
5939
+ const named = seen.filter((c2) => coloCity(c2));
5940
+ if (named.length > 0) {
5941
+ process.stdout.write(
5942
+ "\n\u673A\u623F\u5BF9\u7167\uFF1A" + named.map((c2) => `${c2}=${coloCity(c2)}`).join(" ") + "\n"
5943
+ );
5944
+ }
5605
5945
  }
5606
5946
  function printCopyable(entries) {
5607
5947
  if (entries.length === 0) return;
@@ -5817,6 +6157,8 @@ ${NAME} v${VERSION}
5817
6157
  verifyTargetHost: flagString(args, "verify-target"),
5818
6158
  verifyTargetPort: flagNumber(args, "verify-target-port", 80),
5819
6159
  speedRepeat: flagNumber(args, "speed-repeat", 1),
6160
+ // 出口体检(可选):需要 --uuid 做端点鉴权,按机房去重调用
6161
+ unlock: flagBool(args, "unlock"),
5820
6162
  verifyWsPath: args.flags["no-verify-ws-path"] === void 0,
5821
6163
  top,
5822
6164
  onProgress: (event) => printProgress(event, quiet)
@@ -6020,11 +6362,21 @@ async function menuScan() {
6020
6362
  const wantFilter = await confirm("\u8981\u6309\u673A\u623F\u5730\u533A\u7B5B\u9009\u5417\uFF1F\uFF08\u4E0D\u7B5B\u9009\u8DD1\u5168\u91CF\uFF09", false);
6021
6363
  let countries = [];
6022
6364
  if (wantFilter) {
6365
+ const CLEAR = "__CLEAR__";
6366
+ const GROUP = "GROUP:";
6023
6367
  const picked = await multiSelect(
6024
6368
  "\u9009\u62E9\u5730\u533A\uFF08\u7A7A\u683C\u5207\u6362\uFF0CEnter \u786E\u8BA4\uFF09",
6025
- SUPPORTED_COUNTRIES.map((code) => ({ label: code, value: code }))
6369
+ [
6370
+ { label: "\u53D6\u6D88\u9009\u62E9\uFF08\u4E0D\u9009 = \u5168\u90E8\uFF09", value: CLEAR },
6371
+ ...Object.entries(REGION_GROUP_NAMES).map(([key, name]) => ({
6372
+ label: name,
6373
+ hint: `\u5C55\u5F00\u4E3A ${REGION_GROUPS[key]?.length ?? 0} \u4E2A\u56FD\u5BB6`,
6374
+ value: GROUP + key
6375
+ })),
6376
+ ...SUPPORTED_COUNTRIES.map((code) => ({ label: code, value: code }))
6377
+ ]
6026
6378
  );
6027
- countries = picked;
6379
+ countries = picked.includes(CLEAR) ? [] : picked.map((v) => v.startsWith(GROUP) ? v.slice(GROUP.length) : v);
6028
6380
  }
6029
6381
  const sampleStr = await ask("\u91C7\u6837\u6570\u91CF", { fallback: "6556" });
6030
6382
  const sample = Number(sampleStr) || 6556;
@@ -6606,10 +6958,141 @@ var init_token_command = __esm({
6606
6958
  }
6607
6959
  });
6608
6960
 
6961
+ // src/vps/command.ts
6962
+ var command_exports3 = {};
6963
+ __export(command_exports3, {
6964
+ runVpsCommand: () => runVpsCommand
6965
+ });
6966
+ import { spawn } from "node:child_process";
6967
+ import { existsSync as existsSync2, readFileSync as readFileSync3, writeFileSync as writeFileSync2 } from "node:fs";
6968
+ import { dirname as dirname2, resolve as resolve2 } from "node:path";
6969
+ import { fileURLToPath as fileURLToPath2 } from "node:url";
6970
+ function loadScript() {
6971
+ const here = dirname2(fileURLToPath2(import.meta.url));
6972
+ const candidates = [
6973
+ resolve2(here, "../assets/vps-socks5.sh"),
6974
+ resolve2(here, "../../assets/vps-socks5.sh")
6975
+ ];
6976
+ for (const path of candidates) {
6977
+ if (existsSync2(path)) return readFileSync3(path, "utf8");
6978
+ }
6979
+ throw new Error("\u5185\u7F6E\u811A\u672C\u7F3A\u5931\uFF08assets/vps-socks5.sh\uFF09\uFF0C\u8BF7\u91CD\u65B0\u5B89\u88C5\u6216\u5347\u7EA7 cfpilot");
6980
+ }
6981
+ function withPort(script, port) {
6982
+ if (!port || !Number.isInteger(port) || port <= 0 || port > 65535) return script;
6983
+ return script.replace(/^PORT=1080$/m, `PORT=${port}`);
6984
+ }
6985
+ function runSsh(host, script) {
6986
+ return new Promise((resolvePromise) => {
6987
+ const child = spawn("ssh", ["-t", "-o", "StrictHostKeyChecking=accept-new", host, "bash -s"], {
6988
+ stdio: ["pipe", "inherit", "inherit"]
6989
+ });
6990
+ child.on("error", (err) => {
6991
+ if (err.code === "ENOENT") {
6992
+ process.stderr.write(
6993
+ "\n\u672C\u673A\u6CA1\u6709\u627E\u5230 ssh \u5BA2\u6237\u7AEF\u3002\n\xB7 Windows\uFF1A\u8BBE\u7F6E \u2192 \u5E94\u7528 \u2192 \u53EF\u9009\u529F\u80FD \u2192 \u6DFB\u52A0\u300COpenSSH \u5BA2\u6237\u7AEF\u300D\n\xB7 \u6216\u8005\u6539\u7528\uFF1Acfpilot vps\uFF08\u751F\u6210\u811A\u672C\u540E\u624B\u52A8 scp \u5230 VPS \u6267\u884C\uFF09\n\n"
6994
+ );
6995
+ } else {
6996
+ process.stderr.write(`
6997
+ ssh \u542F\u52A8\u5931\u8D25\uFF1A${err.message}
6998
+ `);
6999
+ }
7000
+ resolvePromise(1);
7001
+ });
7002
+ child.on("close", (code) => resolvePromise(code ?? 1));
7003
+ child.stdin.write(script);
7004
+ child.stdin.end();
7005
+ });
7006
+ }
7007
+ async function runVpsCommand(args) {
7008
+ if (flagBool(args, "h") || flagBool(args, "help")) {
7009
+ process.stdout.write(HELP);
7010
+ return;
7011
+ }
7012
+ const port = flagNumber(args, "port", 0);
7013
+ const script = withPort(loadScript(), port > 0 ? port : void 0);
7014
+ if (flagBool(args, "print")) {
7015
+ process.stdout.write(script);
7016
+ return;
7017
+ }
7018
+ const sshHost = flagString(args, "ssh").trim();
7019
+ if (sshHost) {
7020
+ process.stdout.write(`
7021
+ \u6B63\u5728\u901A\u8FC7 ssh \u5728 ${sshHost} \u4E0A\u6267\u884C\u90E8\u7F72\u811A\u672C\u2026
7022
+ `);
7023
+ process.stdout.write("\uFF08\u9996\u6B21\u8FDE\u63A5\u4F1A\u63D0\u793A\u786E\u8BA4\u4E3B\u673A\u6307\u7EB9\uFF1B\u811A\u672C\u9700\u8981 root\uFF0C\u5FC5\u8981\u65F6\u4F1A\u8981\u6C42\u8F93\u5165 sudo \u5BC6\u7801\uFF09\n\n");
7024
+ const code = await runSsh(sshHost, script);
7025
+ if (code !== 0) {
7026
+ process.stderr.write(`
7027
+ \u8FDC\u7A0B\u6267\u884C\u5931\u8D25\uFF08\u9000\u51FA\u7801 ${code}\uFF09\u3002\u53EF\u6539\u7528 cfpilot vps \u751F\u6210\u811A\u672C\u540E\u624B\u52A8\u6267\u884C\u3002
7028
+ `);
7029
+ process.exitCode = code;
7030
+ }
7031
+ return;
7032
+ }
7033
+ const out = resolve2(process.cwd(), flagString(args, "out") ?? "cfpilot-vps-socks5.sh");
7034
+ writeFileSync2(out, script, { mode: 493 });
7035
+ process.stdout.write(
7036
+ `
7037
+ \u5DF2\u751F\u6210\u811A\u672C\uFF1A${out}
7038
+
7039
+ \u63A5\u4E0B\u6765\u4E8C\u9009\u4E00\uFF1A
7040
+
7041
+ \u2460 \u6709 ssh \u5BA2\u6237\u7AEF\uFF08\u63A8\u8350\uFF09
7042
+ scp cfpilot-vps-socks5.sh root@\u4F60\u7684VPS_IP:/tmp/
7043
+ ssh -t root@\u4F60\u7684VPS_IP "bash /tmp/cfpilot-vps-socks5.sh"
7044
+
7045
+ \u2461 \u5728 VPS \u4E0A\u624B\u52A8\u6267\u884C
7046
+ \u628A\u811A\u672C\u4F20\u4E0A\u53BB\uFF0C\u7136\u540E\uFF1Asudo bash /tmp/cfpilot-vps-socks5.sh
7047
+
7048
+ \u8DD1\u5B8C\u4F1A\u6253\u5370\u4E00\u884C socks5://\u7528\u6237\u540D:\u53E3\u4EE4@IP:\u7AEF\u53E3\uFF0C
7049
+ \u7C98\u8FDB CFPilot \u9762\u677F\u300C\u51FA\u7AD9\u4E0E\u9AD8\u7EA7\u300D\u2192 SOCKS5 \u5373\u53EF\u3002
7050
+
7051
+ \u63D0\u793A\uFF1A\u4E5F\u53EF\u4EE5\u76F4\u63A5 ${NAME} vps --ssh root@\u4F60\u7684VPS_IP\uFF0C\u7531\u672C\u5DE5\u5177\u4EE3\u8DD1\u3002
7052
+
7053
+ `
7054
+ );
7055
+ }
7056
+ var HELP;
7057
+ var init_command3 = __esm({
7058
+ "src/vps/command.ts"() {
7059
+ "use strict";
7060
+ init_args();
7061
+ init_version();
7062
+ HELP = `
7063
+ ${NAME} vps \u2014\u2014 \u5728\u81EA\u5DF1\u7684 VPS \u4E0A\u90E8\u7F72 SOCKS5 \u843D\u5730\u4EE3\u7406
7064
+
7065
+ \u7528\u6CD5:
7066
+ ${NAME} vps [\u9009\u9879]
7067
+
7068
+ \u9009\u9879:
7069
+ --ssh <user@host> \u76F4\u63A5\u901A\u8FC7\u7CFB\u7EDF ssh \u8FDC\u7A0B\u6267\u884C\uFF08\u9700\u672C\u673A\u6709 ssh \u5BA2\u6237\u7AEF\uFF09
7070
+ --port <\u7AEF\u53E3> SOCKS5 \u76D1\u542C\u7AEF\u53E3\uFF0C\u9ED8\u8BA4 1080
7071
+ --out <\u8DEF\u5F84> \u811A\u672C\u843D\u5730\u8DEF\u5F84\uFF0C\u9ED8\u8BA4 ./cfpilot-vps-socks5.sh
7072
+ --print \u53EA\u628A\u811A\u672C\u8F93\u51FA\u5230\u6807\u51C6\u8F93\u51FA\uFF08\u81EA\u5DF1\u5BA1\u8BA1 / \u624B\u5DE5\u6267\u884C\uFF09
7073
+ -h, --help \u663E\u793A\u672C\u5E2E\u52A9
7074
+
7075
+ \u8BF4\u660E:
7076
+ \u90E8\u7F72\u5B8C\u6210\u540E\u4F1A\u6253\u5370\u4E00\u884C socks5://\u7528\u6237\u540D:\u53E3\u4EE4@IP:\u7AEF\u53E3\uFF0C
7077
+ \u7C98\u8FDB CFPilot \u9762\u677F\u300C\u51FA\u7AD9\u4E0E\u9AD8\u7EA7\u300D\u7684 SOCKS5 \u8F93\u5165\u6846\u5373\u53EF\u3002
7078
+
7079
+ \u811A\u672C\u505A\u7684\u4E8B\uFF1A\u88C5 sing-box \u2192 \u751F\u6210\u968F\u673A\u7528\u6237\u540D/\u53E3\u4EE4 \u2192 \u8D77\u5E26\u8BA4\u8BC1\u7684 SOCKS5
7080
+ \u2192 \u6CE8\u518C systemd \u670D\u52A1 \u2192 \u6253\u5370\u8FDE\u63A5\u4E32\u3002\u4EC5\u652F\u6301 Debian/Ubuntu/CentOS \u7CFB\u3002
7081
+
7082
+ \u4E3A\u4EC0\u4E48\u9700\u8981\u5B83\uFF1AWorker \u7684\u51FA\u53E3\u662F\u673A\u623F IP\uFF0C\u6D41\u5A92\u4F53\u4E0E\u90E8\u5206\u7AD9\u70B9\u5BF9\u673A\u623F IP
7083
+ \u6709\u7ED3\u6784\u6027\u98CE\u63A7\uFF1B\u6362\u4E00\u4E2A\u81EA\u5DF1\u7684\u51FA\u53E3\u6BD4\u4EFB\u4F55\u300C\u89E3\u9501\u68C0\u6D4B\u300D\u90FD\u6709\u6548\u3002
7084
+
7085
+ \u793A\u4F8B:
7086
+ ${NAME} vps --ssh root@203.0.113.10
7087
+ ${NAME} vps --print > deploy.sh
7088
+ `;
7089
+ }
7090
+ });
7091
+
6609
7092
  // src/cli.ts
6610
7093
  init_args();
6611
7094
  init_version();
6612
- var HELP = `
7095
+ var HELP2 = `
6613
7096
  ${NAME} v${VERSION}
6614
7097
  Cloudflare Pages \u4EE3\u7406\u90E8\u7F72\u4E0E\u4F18\u9009\u5DE5\u5177
6615
7098
 
@@ -6619,6 +7102,7 @@ Cloudflare Pages \u4EE3\u7406\u90E8\u7F72\u4E0E\u4F18\u9009\u5DE5\u5177
6619
7102
  ${NAME} scan [\u9009\u9879] \u672C\u5730\u771F\u8FDE\u63A5\u4F18\u9009
6620
7103
  ${NAME} status \u67E5\u770B\u5F53\u524D\u5B9E\u4F8B\u72B6\u6001
6621
7104
  ${NAME} token [\u9009\u9879] \u68C0\u67E5 API Token \u6743\u9650
7105
+ ${NAME} vps [\u9009\u9879] \u5728\u81EA\u5DF1\u7684 VPS \u4E0A\u90E8\u7F72 SOCKS5 \u843D\u5730\u4EE3\u7406
6622
7106
  ${NAME} config [\u9009\u9879] \u67E5\u770B/\u4FEE\u6539\u672C\u5730\u914D\u7F6E
6623
7107
  ${NAME} --help \u663E\u793A\u5E2E\u52A9
6624
7108
  ${NAME} --version \u663E\u793A\u7248\u672C
@@ -6640,11 +7124,11 @@ async function main() {
6640
7124
  return;
6641
7125
  }
6642
7126
  if (!command && (flagBool(args, "h") || flagBool(args, "help"))) {
6643
- process.stdout.write(HELP);
7127
+ process.stdout.write(HELP2);
6644
7128
  return;
6645
7129
  }
6646
7130
  if (command === "help") {
6647
- process.stdout.write(HELP);
7131
+ process.stdout.write(HELP2);
6648
7132
  return;
6649
7133
  }
6650
7134
  switch (command) {
@@ -6679,11 +7163,16 @@ async function main() {
6679
7163
  await runConfig2(args);
6680
7164
  return;
6681
7165
  }
7166
+ case "vps": {
7167
+ const { runVpsCommand: runVpsCommand2 } = await Promise.resolve().then(() => (init_command3(), command_exports3));
7168
+ await runVpsCommand2(args);
7169
+ return;
7170
+ }
6682
7171
  default: {
6683
7172
  process.stderr.write(`\u672A\u77E5\u547D\u4EE4\uFF1A${command}
6684
7173
 
6685
7174
  `);
6686
- process.stderr.write(HELP);
7175
+ process.stderr.write(HELP2);
6687
7176
  process.exitCode = 1;
6688
7177
  }
6689
7178
  }