diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a146edd03..0cca4cc5d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -28,8 +28,7 @@ jobs: run: | npx wrangler deploy src/worker.js --name bpb-worker-panel --compatibility-flag [nodejs_compat] --compatibility-date 2024-10-26 --dry-run --outdir=dist cp -f dist/worker.js unobfuscated/worker.js - touch cache.json - npx javascript-obfuscator --split-strings true --split-strings-chunk-length 2 --transform-object-keys true --rename-globals true --rename-properties true --rename-properties-mode unsafe --identifier-names-cache-path cache.json dist/worker.js --output _worker.js + npx javascript-obfuscator --split-strings true --split-strings-chunk-length 2 dist/worker.js --output _worker.js - name: Commit and push built worker run: | diff --git a/src/cores-configs/clash.js b/src/cores-configs/clash.js index c3b8803d0..dc42f0815 100644 --- a/src/cores-configs/clash.js +++ b/src/cores-configs/clash.js @@ -6,7 +6,7 @@ async function buildClashDNS (proxySettings, isChain, isWarp) { const { remoteDNS, localDNS, - vlessTrojanFakeDNS, + VLTRFakeDNS, outProxyParams, enableIPv6, warpFakeDNS, @@ -14,14 +14,13 @@ async function buildClashDNS (proxySettings, isChain, isWarp) { bypassIran, bypassChina, bypassRussia, - customBypassRules, - customBlockRules + customBypassRules } = proxySettings; const warpRemoteDNS = warpEnableIPv6 ? ["1.1.1.1", "1.0.0.1", "[2606:4700:4700::1111]", "[2606:4700:4700::1001]"] : ["1.1.1.1", "1.0.0.1"]; - const isFakeDNS = (vlessTrojanFakeDNS && !isWarp) || (warpFakeDNS && isWarp); + const isFakeDNS = (VLTRFakeDNS && !isWarp) || (warpFakeDNS && isWarp); const isIPv6 = (enableIPv6 && !isWarp) || (warpEnableIPv6 && isWarp); const customBypassRulesDomains = customBypassRules.split(',').filter(address => isDomain(address)); const isBypass = bypassIran || bypassChina || bypassRussia; @@ -248,7 +247,7 @@ function buildClashRoutingRules (proxySettings) { return { rules, ruleProviders }; } -function buildClashVLESSOutbound (remark, address, port, host, sni, path, allowInsecure) { +function buildClashVLOutbound (remark, address, port, host, sni, path, allowInsecure) { const tls = globalThis.defaultHttpsPorts.includes(port) ? true : false; const addr = isIPv6(address) ? address.replace(/\[|\]/g, '') : address; const outbound = { @@ -280,7 +279,7 @@ function buildClashVLESSOutbound (remark, address, port, host, sni, path, allowI return outbound; } -function buildClashTrojanOutbound (remark, address, port, host, sni, path, allowInsecure) { +function buildClashTROutbound (remark, address, port, host, sni, path, allowInsecure) { const addr = isIPv6(address) ? address.replace(/\[|\]/g, '') : address; return { "name": remark, @@ -461,14 +460,14 @@ export async function getClashNormalConfig (request, env) { cleanIPs, proxyIP, ports, - vlessConfigs, - trojanConfigs, + VLConfigs, + TRConfigs, outProxy, outProxyParams, customCdnAddrs, customCdnHost, customCdnSni, - bestVLESSTrojanInterval, + bestVLTRInterval, enableIPv6 } = proxySettings; @@ -503,21 +502,21 @@ export async function getClashNormalConfig (request, env) { const urlTest = config['proxy-groups'][1]; selector.proxies = ['πŸ’¦ Best Ping πŸ’₯']; urlTest.name = 'πŸ’¦ Best Ping πŸ’₯'; - urlTest.interval = +bestVLESSTrojanInterval; + urlTest.interval = +bestVLTRInterval; const Addresses = await getConfigAddresses(cleanIPs, enableIPv6); const customCdnAddresses = customCdnAddrs ? customCdnAddrs.split(',') : []; const totalAddresses = [...Addresses, ...customCdnAddresses]; let proxyIndex = 1, path; const protocols = [ - ...(vlessConfigs ? ['VLESS'] : []), - ...(trojanConfigs ? ['Trojan'] : []) + ...(VLConfigs ? ['VLESS'] : []), + ...(TRConfigs ? ['Trojan'] : []) ]; protocols.forEach ( protocol => { let protocolIndex = 1; ports.forEach ( port => { totalAddresses.forEach( addr => { - let VLESSOutbound, TrojanOutbound; + let VLOutbound, TROutbound; const isCustomAddr = customCdnAddresses.includes(addr); const configType = isCustomAddr ? 'C' : ''; const sni = isCustomAddr ? customCdnSni : randomUpperCase(globalThis.hostName); @@ -526,7 +525,7 @@ export async function getClashNormalConfig (request, env) { if (protocol === 'VLESS') { path = `/${getRandomPath(16)}${proxyIP ? `/${btoa(proxyIP)}` : ''}`; - VLESSOutbound = buildClashVLESSOutbound( + VLOutbound = buildClashVLOutbound( chainProxy ? `proxy-${proxyIndex}` : remark, addr, port, @@ -535,14 +534,14 @@ export async function getClashNormalConfig (request, env) { path, isCustomAddr ); - config.proxies.push(VLESSOutbound); + config.proxies.push(VLOutbound); selector.proxies.push(remark); urlTest.proxies.push(remark); } if (protocol === 'Trojan' && globalThis.defaultHttpsPorts.includes(port)) { path = `/tr${getRandomPath(16)}${proxyIP ? `/${btoa(proxyIP)}` : ''}`; - TrojanOutbound = buildClashTrojanOutbound( + TROutbound = buildClashTROutbound( chainProxy ? `proxy-${proxyIndex}` : remark, addr, port, @@ -551,7 +550,7 @@ export async function getClashNormalConfig (request, env) { path, isCustomAddr ); - config.proxies.push(TrojanOutbound); + config.proxies.push(TROutbound); selector.proxies.push(remark); urlTest.proxies.push(remark); } diff --git a/src/cores-configs/normalConfigs.js b/src/cores-configs/normalConfigs.js index 5bb47589b..0d2e6b297 100644 --- a/src/cores-configs/normalConfigs.js +++ b/src/cores-configs/normalConfigs.js @@ -7,8 +7,8 @@ export async function getNormalConfigs(request, env) { cleanIPs, proxyIP, ports, - vlessConfigs, - trojanConfigs , + VLConfigs, + TRConfigs , outProxy, customCdnAddrs, customCdnHost, @@ -16,13 +16,13 @@ export async function getNormalConfigs(request, env) { enableIPv6 } = proxySettings; - let vlessConfs = '', trojanConfs = '', chainProxy = ''; + let VLConfs = '', TRConfs = '', chainProxy = ''; let proxyIndex = 1; const Addresses = await getConfigAddresses(cleanIPs, enableIPv6); const customCdnAddresses = customCdnAddrs ? customCdnAddrs.split(',') : []; const totalAddresses = [...Addresses, ...customCdnAddresses]; const alpn = globalThis.client === 'singbox' ? 'http/1.1' : 'h2,http/1.1'; - const trojanPass = encodeURIComponent(globalThis.trojanPassword); + const TRPass = encodeURIComponent(globalThis.TRPassword); const earlyData = globalThis.client === 'singbox' ? '&eh=Sec-WebSocket-Protocol&ed=2560' : encodeURIComponent('?ed=2560'); @@ -34,18 +34,18 @@ export async function getNormalConfigs(request, env) { const sni = isCustomAddr ? customCdnSni : randomUpperCase(globalThis.hostName); const host = isCustomAddr ? customCdnHost : globalThis.hostName; const path = `${getRandomPath(16)}${proxyIP ? `/${encodeURIComponent(btoa(proxyIP))}` : ''}${earlyData}`; - const vlessRemark = encodeURIComponent(generateRemark(proxyIndex, port, addr, cleanIPs, 'VLESS', configType)); - const trojanRemark = encodeURIComponent(generateRemark(proxyIndex, port, addr, cleanIPs, 'Trojan', configType)); + const VLRemark = encodeURIComponent(generateRemark(proxyIndex, port, addr, cleanIPs, 'VLESS', configType)); + const TRRemark = encodeURIComponent(generateRemark(proxyIndex, port, addr, cleanIPs, 'Trojan', configType)); const tlsFields = globalThis.defaultHttpsPorts.includes(port) ? `&security=tls&sni=${sni}&fp=randomized&alpn=${alpn}` : '&security=none'; - if (vlessConfigs) { - vlessConfs += `${atob('dmxlc3M6Ly8=')}${globalThis.userID}@${addr}:${port}?path=/${path}&encryption=none&host=${host}&type=ws${tlsFields}#${vlessRemark}\n`; + if (VLConfigs) { + VLConfs += `${atob('dmxlc3M6Ly8=')}${globalThis.userID}@${addr}:${port}?path=/${path}&encryption=none&host=${host}&type=ws${tlsFields}#${VLRemark}\n`; } - if (trojanConfigs) { - trojanConfs += `${atob('dHJvamFuOi8v')}${trojanPass}@${addr}:${port}?path=/tr${path}&host=${host}&type=ws${tlsFields}#${trojanRemark}\n`; + if (TRConfigs) { + TRConfs += `${atob('dHJvamFuOi8v')}${TRPass}@${addr}:${port}?path=/tr${path}&host=${host}&type=ws${tlsFields}#${TRRemark}\n`; } proxyIndex++; @@ -66,7 +66,7 @@ export async function getNormalConfigs(request, env) { } } - const configs = btoa(vlessConfs + trojanConfs + chainProxy); + const configs = btoa(VLConfs + TRConfs + chainProxy); return new Response(configs, { status: 200, headers: { diff --git a/src/cores-configs/sing-box.js b/src/cores-configs/sing-box.js index 21dc17f8c..bfcb8df1f 100644 --- a/src/cores-configs/sing-box.js +++ b/src/cores-configs/sing-box.js @@ -6,7 +6,7 @@ function buildSingBoxDNS (proxySettings, outboundAddrs, isWarp, remoteDNSDetour) const { remoteDNS, localDNS, - vlessTrojanFakeDNS, + VLTRFakeDNS, enableIPv6, warpFakeDNS, warpEnableIPv6, @@ -20,7 +20,7 @@ function buildSingBoxDNS (proxySettings, outboundAddrs, isWarp, remoteDNSDetour) } = proxySettings; let fakeip; - const isFakeDNS = (vlessTrojanFakeDNS && !isWarp) || (warpFakeDNS && isWarp); + const isFakeDNS = (VLTRFakeDNS && !isWarp) || (warpFakeDNS && isWarp); const isIPv6 = (enableIPv6 && !isWarp) || (warpEnableIPv6 && isWarp); const customBypassRulesDomains = customBypassRules.split(',').filter(address => isDomain(address)); const customBlockRulesDomains = customBlockRules.split(',').filter(address => isDomain(address)); @@ -349,7 +349,7 @@ function buildSingBoxRoutingRules (proxySettings) { return {rules, rule_set: ruleSets}; } -function buildSingBoxVLESSOutbound (proxySettings, remark, address, port, host, sni, allowInsecure, isFragment) { +function buildSingBoxVLOutbound (proxySettings, remark, address, port, host, sni, allowInsecure, isFragment) { const { enableIPv6, lengthMin, lengthMax, intervalMin, intervalMax, proxyIP } = proxySettings; const path = `/${getRandomPath(16)}${proxyIP ? `/${btoa(proxyIP)}` : ''}`; const tls = globalThis.defaultHttpsPorts.includes(port) ? true : false; @@ -391,13 +391,13 @@ function buildSingBoxVLESSOutbound (proxySettings, remark, address, port, host, return outbound; } -function buildSingBoxTrojanOutbound (proxySettings, remark, address, port, host, sni, allowInsecure, isFragment) { +function buildSingBoxTROutbound (proxySettings, remark, address, port, host, sni, allowInsecure, isFragment) { const { enableIPv6, lengthMin, lengthMax, intervalMin, intervalMax, proxyIP } = proxySettings; const path = `/tr${getRandomPath(16)}${proxyIP ? `/${btoa(proxyIP)}` : ''}`; const tls = globalThis.defaultHttpsPorts.includes(port) ? true : false; const outbound = { type: "trojan", - password: globalThis.trojanPassword, + password: globalThis.TRPassword, server: address, server_port: +port, domain_strategy: enableIPv6 ? "prefer_ipv4" : "ipv4_only", @@ -623,14 +623,14 @@ export async function getSingBoxCustomConfig(request, env, isFragment) { const { cleanIPs, ports, - vlessConfigs, - trojanConfigs, + VLConfigs, + TRConfigs, outProxy, outProxyParams, customCdnAddrs, customCdnHost, customCdnSni, - bestVLESSTrojanInterval, + bestVLTRInterval, enableIPv6 } = proxySettings; @@ -663,20 +663,20 @@ export async function getSingBoxCustomConfig(request, env, isFragment) { const selector = config.outbounds[0]; const urlTest = config.outbounds[1]; selector.outbounds = ['πŸ’¦ Best Ping πŸ’₯']; - urlTest.interval = `${bestVLESSTrojanInterval}s`; + urlTest.interval = `${bestVLTRInterval}s`; urlTest.tag = 'πŸ’¦ Best Ping πŸ’₯'; const totalPorts = ports.filter(port => isFragment ? globalThis.defaultHttpsPorts.includes(port) : true); let proxyIndex = 1; const protocols = [ - ...(vlessConfigs ? ['VLESS'] : []), - ...(trojanConfigs ? ['Trojan'] : []) + ...(VLConfigs ? ['VLESS'] : []), + ...(TRConfigs ? ['Trojan'] : []) ]; protocols.forEach ( protocol => { let protocolIndex = 1; totalPorts.forEach ( port => { totalAddresses.forEach ( addr => { - let VLESSOutbound, TrojanOutbound; + let VLOutbound, TROutbound; const isCustomAddr = customCdnAddresses.includes(addr); const configType = isCustomAddr ? 'C' : isFragment ? 'F' : ''; const sni = isCustomAddr ? customCdnSni : randomUpperCase(globalThis.hostName); @@ -684,7 +684,7 @@ export async function getSingBoxCustomConfig(request, env, isFragment) { const remark = generateRemark(protocolIndex, port, addr, cleanIPs, protocol, configType); if (protocol === 'VLESS') { - VLESSOutbound = buildSingBoxVLESSOutbound ( + VLOutbound = buildSingBoxVLOutbound ( proxySettings, chainProxy ? `proxy-${proxyIndex}` : remark, addr, @@ -694,11 +694,11 @@ export async function getSingBoxCustomConfig(request, env, isFragment) { isCustomAddr, isFragment ); - config.outbounds.push(VLESSOutbound); + config.outbounds.push(VLOutbound); } if (protocol === 'Trojan') { - TrojanOutbound = buildSingBoxTrojanOutbound ( + TROutbound = buildSingBoxTROutbound ( proxySettings, chainProxy ? `proxy-${proxyIndex}` : remark, addr, @@ -708,7 +708,7 @@ export async function getSingBoxCustomConfig(request, env, isFragment) { isCustomAddr, isFragment ); - config.outbounds.push(TrojanOutbound); + config.outbounds.push(TROutbound); } if (chainProxy) { diff --git a/src/cores-configs/xray.js b/src/cores-configs/xray.js index df01c4c3e..44b014734 100644 --- a/src/cores-configs/xray.js +++ b/src/cores-configs/xray.js @@ -7,7 +7,7 @@ async function buildXrayDNS (proxySettings, outboundAddrs, domainToStaticIPs, is remoteDNS, resolvedRemoteDNS, localDNS, - vlessTrojanFakeDNS, + VLTRFakeDNS, enableIPv6, warpFakeDNS, warpEnableIPv6, @@ -32,7 +32,7 @@ async function buildXrayDNS (proxySettings, outboundAddrs, domainToStaticIPs, is { rule: blockPorn, host: "geosite:category-porn" } ]; - const isFakeDNS = (vlessTrojanFakeDNS && !isWarp) || (warpFakeDNS && isWarp); + const isFakeDNS = (VLTRFakeDNS && !isWarp) || (warpFakeDNS && isWarp); const isIPv6 = (enableIPv6 && !isWarp) || (warpEnableIPv6 && isWarp); const outboundDomains = outboundAddrs.filter(address => isDomain(address)); const customBypassRulesDomains = customBypassRules.split(',').filter(address => isDomain(address)); @@ -274,7 +274,7 @@ function buildXrayRoutingRules (proxySettings, outboundAddrs, isChain, isBalance return rules; } -function buildXrayVLESSOutbound (tag, address, port, host, sni, proxyIP, isFragment, allowInsecure, enableIPv6) { +function buildXrayVLOutbound (tag, address, port, host, sni, proxyIP, isFragment, allowInsecure, enableIPv6) { const outbound = { protocol: "vless", settings: { @@ -329,7 +329,7 @@ function buildXrayVLESSOutbound (tag, address, port, host, sni, proxyIP, isFragm return outbound; } -function buildXrayTrojanOutbound (tag, address, port, host, sni, proxyIP, isFragment, allowInsecure, enableIPv6) { +function buildXrayTROutbound (tag, address, port, host, sni, proxyIP, isFragment, allowInsecure, enableIPv6) { const outbound = { protocol: "trojan", settings: { @@ -337,7 +337,7 @@ function buildXrayTrojanOutbound (tag, address, port, host, sni, proxyIP, isFrag { address: address, port: +port, - password: globalThis.trojanPassword, + password: globalThis.TRPassword, level: 8 } ] @@ -599,10 +599,10 @@ function buildXrayChainOutbound(chainProxyParams, enableIPv6) { function buildXrayConfig (proxySettings, remark, isFragment, isBalancer, isChain, balancerFallback, isWarp) { const { - vlessTrojanFakeDNS, + VLTRFakeDNS, enableIPv6, warpFakeDNS, - bestVLESSTrojanInterval, + bestVLTRInterval, bestWarpInterval, lengthMin, lengthMax, @@ -611,7 +611,7 @@ function buildXrayConfig (proxySettings, remark, isFragment, isBalancer, isChain fragmentPackets } = proxySettings; - const isFakeDNS = (vlessTrojanFakeDNS && !isWarp) || (warpFakeDNS && isWarp); + const isFakeDNS = (VLTRFakeDNS && !isWarp) || (warpFakeDNS && isWarp); const config = structuredClone(xrayConfigTemp); config.remarks = remark; if (isFakeDNS) { @@ -630,7 +630,7 @@ function buildXrayConfig (proxySettings, remark, isFragment, isBalancer, isChain } if (isBalancer) { - const interval = isWarp ? bestWarpInterval : bestVLESSTrojanInterval; + const interval = isWarp ? bestWarpInterval : bestVLTRInterval; config.observatory.probeInterval = `${interval}s`; if (balancerFallback) config.routing.balancers[0].fallbackTag = "prox-2"; if (isChain) { @@ -695,7 +695,7 @@ async function buildXrayWorkerLessConfig(proxySettings) { const config = buildXrayConfig(proxySettings, 'πŸ’¦ BPB F - WorkerLess ⭐', true, false, false, false, false); config.dns = await buildXrayDNS(proxySettings, [], undefined, true); config.routing.rules = buildXrayRoutingRules(proxySettings, [], false, false, true, false); - const fakeOutbound = buildXrayVLESSOutbound('fake-outbound', 'google.com', '443', globalThis.userID, 'google.com', 'google.com', '', true, false); + const fakeOutbound = buildXrayVLOutbound('fake-outbound', 'google.com', '443', globalThis.userID, 'google.com', 'google.com', '', true, false); delete fakeOutbound.streamSettings.sockopt; fakeOutbound.streamSettings.wsSettings.path = '/'; config.outbounds.push(fakeOutbound); @@ -717,8 +717,8 @@ export async function getXrayCustomConfigs(request, env, isFragment) { customCdnAddrs, customCdnHost, customCdnSni, - vlessConfigs, - trojanConfigs, + VLConfigs, + TRConfigs, ports } = proxySettings; @@ -741,8 +741,8 @@ export async function getXrayCustomConfigs(request, env, isFragment) { const customCdnAddresses = customCdnAddrs ? customCdnAddrs.split(',') : []; const totalAddresses = isFragment ? [...Addresses] : [...Addresses, ...customCdnAddresses]; const totalPorts = ports.filter(port => isFragment ? globalThis.defaultHttpsPorts.includes(port): true); - vlessConfigs && protocols.push('VLESS'); - trojanConfigs && protocols.push('Trojan'); + VLConfigs && protocols.push('VLESS'); + TRConfigs && protocols.push('Trojan'); let proxyIndex = 1; for (const protocol of protocols) { @@ -758,8 +758,8 @@ export async function getXrayCustomConfigs(request, env, isFragment) { customConfig.dns = await buildXrayDNS(proxySettings, [addr], undefined); customConfig.routing.rules = buildXrayRoutingRules(proxySettings, [addr], chainProxy, false, false, false); const outbound = protocol === 'VLESS' - ? buildXrayVLESSOutbound('proxy', addr, port, host, sni, proxyIP, isFragment, isCustomAddr, enableIPv6) - : buildXrayTrojanOutbound('proxy', addr, port, host, sni, proxyIP, isFragment, isCustomAddr, enableIPv6); + ? buildXrayVLOutbound('proxy', addr, port, host, sni, proxyIP, isFragment, isCustomAddr, enableIPv6) + : buildXrayTROutbound('proxy', addr, port, host, sni, proxyIP, isFragment, isCustomAddr, enableIPv6); customConfig.outbounds.unshift({...outbound}); outbound.tag = `prox-${proxyIndex}`; diff --git a/src/helpers/init.js b/src/helpers/init.js index 10dbccfce..e975b98a3 100644 --- a/src/helpers/init.js +++ b/src/helpers/init.js @@ -4,11 +4,11 @@ export function initializeParams(request, env) { const proxyIPs = env.PROXYIP?.split(',').map(proxyIP => proxyIP.trim()); const url = new URL(request.url); const searchParams = new URLSearchParams(url.search); - globalThis.panelVersion = '2.8.1'; + globalThis.panelVersion = '2.8.2'; globalThis.defaultHttpPorts = ['80', '8080', '2052', '2082', '2086', '2095', '8880']; globalThis.defaultHttpsPorts = ['443', '8443', '2053', '2083', '2087', '2096']; globalThis.userID = env.UUID; - globalThis.trojanPassword = env.TROJAN_PASS; + globalThis.TRPassword = env.TR_PASS; globalThis.proxyIP = proxyIPs ? proxyIPs[Math.floor(Math.random() * proxyIPs.length)] : atob('YnBiLnlvdXNlZi5pc2VnYXJvLmNvbQ=='); globalThis.hostName = request.headers.get('Host'); globalThis.pathName = url.pathname; @@ -16,7 +16,7 @@ export function initializeParams(request, env) { globalThis.urlOrigin = url.origin; globalThis.dohURL = env.DOH_URL || 'https://cloudflare-dns.com/dns-query'; if (pathName !== '/secrets') { - if (!userID || !globalThis.trojanPassword) throw new Error(`Please set UUID and Trojan password first. Please visit here to generate them.`, { cause: "init"}); + if (!userID || !globalThis.TRPassword) throw new Error(`Please set UUID and Trojan password first. Please visit here to generate them.`, { cause: "init"}); if (userID && !isValidUUID(userID)) throw new Error(`Invalid UUID: ${userID}`, { cause: "init"}); if (typeof env.bpb !== 'object') throw new Error('KV Dataset is not properly set! Please refer to tutorials.', { cause: "init"}); } diff --git a/src/kv/handlers.js b/src/kv/handlers.js index 3cb4b8f61..b2758dc04 100644 --- a/src/kv/handlers.js +++ b/src/kv/handlers.js @@ -70,7 +70,7 @@ export async function updateDataset (request, env) { remoteDNS: remoteDNS, resolvedRemoteDNS: resolvedRemoteDNS, localDNS: validateField('localDNS') ?? currentSettings?.localDNS ?? '8.8.8.8', - vlessTrojanFakeDNS: validateField('vlessTrojanFakeDNS') ?? currentSettings?.vlessTrojanFakeDNS ?? false, + VLTRFakeDNS: validateField('VLTRFakeDNS') ?? currentSettings?.VLTRFakeDNS ?? false, proxyIP: validateField('proxyIP')?.replaceAll(' ', '') ?? currentSettings?.proxyIP ?? '', outProxy: validateField('outProxy') ?? currentSettings?.outProxy ?? '', outProxyParams: extractChainProxyParams(validateField('outProxy')) ?? currentSettings?.outProxyParams ?? {}, @@ -79,9 +79,9 @@ export async function updateDataset (request, env) { customCdnAddrs: validateField('customCdnAddrs')?.replaceAll(' ', '') ?? currentSettings?.customCdnAddrs ?? '', customCdnHost: validateField('customCdnHost')?.trim() ?? currentSettings?.customCdnHost ?? '', customCdnSni: validateField('customCdnSni')?.trim() ?? currentSettings?.customCdnSni ?? '', - bestVLESSTrojanInterval: validateField('bestVLESSTrojanInterval') ?? currentSettings?.bestVLESSTrojanInterval ?? '30', - vlessConfigs: validateField('vlessConfigs') ?? currentSettings?.vlessConfigs ?? true, - trojanConfigs: validateField('trojanConfigs') ?? currentSettings?.trojanConfigs ?? false, + bestVLTRInterval: validateField('bestVLTRInterval') ?? currentSettings?.bestVLTRInterval ?? '30', + VLConfigs: validateField('VLConfigs') ?? currentSettings?.VLConfigs ?? true, + TRConfigs: validateField('TRConfigs') ?? currentSettings?.TRConfigs ?? false, ports: validateField('ports')?.split(',') ?? currentSettings?.ports ?? ['443'], lengthMin: validateField('fragmentLengthMin') ?? currentSettings?.lengthMin ?? '100', lengthMax: validateField('fragmentLengthMax') ?? currentSettings?.lengthMax ?? '200', diff --git a/src/pages/home.js b/src/pages/home.js index 1aa39c51a..cc2c1f854 100644 --- a/src/pages/home.js +++ b/src/pages/home.js @@ -2,7 +2,7 @@ export async function renderHomePage (proxySettings, isPassSet) { const { remoteDNS, localDNS, - vlessTrojanFakeDNS, + VLTRFakeDNS, proxyIP, outProxy, cleanIPs, @@ -10,9 +10,9 @@ export async function renderHomePage (proxySettings, isPassSet) { customCdnAddrs, customCdnHost, customCdnSni, - bestVLESSTrojanInterval, - vlessConfigs, - trojanConfigs, + bestVLTRInterval, + VLConfigs, + TRConfigs, ports, lengthMin, lengthMax, @@ -44,7 +44,7 @@ export async function renderHomePage (proxySettings, isPassSet) { } = proxySettings; const isWarpPlus = warpPlusLicense ? true : false; - const activeProtocols = (vlessConfigs ? 1 : 0) + (trojanConfigs ? 1 : 0); + const activeProtocols = (VLConfigs ? 1 : 0) + (TRConfigs ? 1 : 0); let httpPortsBlock = '', httpsPortsBlock = ''; const allPorts = [...(globalThis.hostName.includes('workers.dev') ? globalThis.defaultHttpPorts : []), ...globalThis.defaultHttpsPorts]; @@ -405,8 +405,8 @@ export async function renderHomePage (proxySettings, isPassSet) {
@@ -454,17 +454,17 @@ export async function renderHomePage (proxySettings, isPassSet) {
- +
- +
- +
diff --git a/src/protocols/trojan.js b/src/protocols/trojan.js index 64dc633c9..749b9a42d 100644 --- a/src/protocols/trojan.js +++ b/src/protocols/trojan.js @@ -1,7 +1,7 @@ import { connect } from 'cloudflare:sockets'; import sha256 from 'js-sha256'; -export async function trojanOverWSHandler(request) { +export async function TROverWSHandler(request) { const webSocketPair = new WebSocketPair(); const [client, webSocket] = Object.values(webSocketPair); webSocket.accept(); @@ -38,7 +38,7 @@ export async function trojanOverWSHandler(request) { portRemote = 443, addressRemote = "", rawClientData, - } = await parseTrojanHeader(chunk); + } = await parseTRHeader(chunk); address = addressRemote; portWithRandomLog = `${portRemote}--${Math.random()} tcp`; @@ -69,7 +69,7 @@ export async function trojanOverWSHandler(request) { }); } -async function parseTrojanHeader(buffer) { +async function parseTRHeader(buffer) { if (buffer.byteLength < 56) { return { hasError: true, @@ -86,7 +86,7 @@ async function parseTrojanHeader(buffer) { } const password = new TextDecoder().decode(buffer.slice(0, crLfIndex)); - if (password !== sha256.sha224(globalThis.trojanPassword)) { + if (password !== sha256.sha224(globalThis.TRPassword)) { return { hasError: true, message: "invalid password", @@ -210,14 +210,14 @@ async function handleTCPOutBound( safeCloseWebSocket(webSocket); }); - trojanRemoteSocketToWS(tcpSocket, webSocket, null, log); + TRRemoteSocketToWS(tcpSocket, webSocket, null, log); } const tcpSocket = await connectAndWrite(addressRemote, portRemote); // when remoteSocket is ready, pass to websocket // remote--> ws - trojanRemoteSocketToWS(tcpSocket, webSocket, retry, log); + TRRemoteSocketToWS(tcpSocket, webSocket, retry, log); } /** @@ -283,7 +283,7 @@ function makeReadableWebSocketStream(webSocketServer, earlyDataHeader, log) { return stream; } -async function trojanRemoteSocketToWS(remoteSocket, webSocket, retry, log) { +async function TRRemoteSocketToWS(remoteSocket, webSocket, retry, log) { let hasIncomingData = false; await remoteSocket.readable .pipeTo( diff --git a/src/protocols/vless.js b/src/protocols/vless.js index dbc5f9523..089b18b5c 100644 --- a/src/protocols/vless.js +++ b/src/protocols/vless.js @@ -6,7 +6,7 @@ import { isValidUUID } from '../helpers/helpers'; * @param {import("@cloudflare/workers-types").Request} request The incoming request object. * @returns {Promise} A Promise that resolves to a WebSocket response object. */ -export async function vlessOverWSHandler(request) { +export async function VLOverWSHandler(request) { /** @type {import("@cloudflare/workers-types").WebSocket[]} */ // @ts-ignore const webSocketPair = new WebSocketPair(); @@ -51,9 +51,9 @@ export async function vlessOverWSHandler(request) { portRemote = 443, addressRemote = "", rawDataIndex, - vlessVersion = new Uint8Array([0, 0]), + VLVersion = new Uint8Array([0, 0]), isUDP, - } = await processVlessHeader(chunk, globalThis.userID); + } = await processVLHeader(chunk, globalThis.userID); address = addressRemote; portWithRandomLog = `${portRemote}--${Math.random()} ${isUDP ? "udp " : "tcp "} `; if (hasError) { @@ -73,12 +73,12 @@ export async function vlessOverWSHandler(request) { } } // ["version", "ι™„εŠ δΏ‘ζ―ι•ΏεΊ¦ N"] - const vlessResponseHeader = new Uint8Array([vlessVersion[0], 0]); + const VLResponseHeader = new Uint8Array([VLVersion[0], 0]); const rawClientData = chunk.slice(rawDataIndex); // TODO: support udp here when cf runtime has udp support if (isDns) { - const { write } = await handleUDPOutBound(webSocket, vlessResponseHeader, log); + const { write } = await handleUDPOutBound(webSocket, VLResponseHeader, log); udpStreamWrite = write; udpStreamWrite(rawClientData); return; @@ -90,7 +90,7 @@ export async function vlessOverWSHandler(request) { portRemote, rawClientData, webSocket, - vlessResponseHeader, + VLResponseHeader, log ); }, @@ -142,7 +142,7 @@ async function checkUuidInApiResponse(targetUuid) { * @param {number} portRemote The remote port to connect to. * @param {Uint8Array} rawClientData The raw client data to write. * @param {import("@cloudflare/workers-types").WebSocket} webSocket The WebSocket to pass the remote socket to. - * @param {Uint8Array} vlessResponseHeader The VLESS response header. + * @param {Uint8Array} VLResponseHeader The VLESS response header. * @param {function} log The logging function. * @returns {Promise} The remote socket. */ @@ -152,7 +152,7 @@ async function handleTCPOutBound( portRemote, rawClientData, webSocket, - vlessResponseHeader, + VLResponseHeader, log ) { async function connectAndWrite(address, port) { @@ -185,14 +185,14 @@ async function handleTCPOutBound( safeCloseWebSocket(webSocket); }); - vlessRemoteSocketToWS(tcpSocket, webSocket, vlessResponseHeader, null, log); + VLRemoteSocketToWS(tcpSocket, webSocket, VLResponseHeader, null, log); } const tcpSocket = await connectAndWrite(addressRemote, portRemote); // when remoteSocket is ready, pass to websocket // remote--> ws - vlessRemoteSocketToWS(tcpSocket, webSocket, vlessResponseHeader, retry, log); + VLRemoteSocketToWS(tcpSocket, webSocket, VLResponseHeader, retry, log); } /** @@ -263,7 +263,7 @@ function makeReadableWebSocketStream(webSocketServer, earlyDataHeader, log) { /** * Processes the VLESS header buffer and returns an object with the relevant information. - * @param {ArrayBuffer} vlessBuffer The VLESS header buffer to process. + * @param {ArrayBuffer} VLBuffer The VLESS header buffer to process. * @param {string} userID The user ID to validate against the UUID in the VLESS header. * @returns {{ * hasError: boolean, @@ -272,21 +272,21 @@ function makeReadableWebSocketStream(webSocketServer, earlyDataHeader, log) { * addressType?: number, * portRemote?: number, * rawDataIndex?: number, - * vlessVersion?: Uint8Array, + * VLVersion?: Uint8Array, * isUDP?: boolean * }} An object with the relevant information extracted from the VLESS header buffer. */ -async function processVlessHeader(vlessBuffer, userID) { - if (vlessBuffer.byteLength < 24) { +async function processVLHeader(VLBuffer, userID) { + if (VLBuffer.byteLength < 24) { return { hasError: true, message: "invalid data", }; } - const version = new Uint8Array(vlessBuffer.slice(0, 1)); + const version = new Uint8Array(VLBuffer.slice(0, 1)); let isValidUser = false; let isUDP = false; - const slicedBuffer = new Uint8Array(vlessBuffer.slice(1, 17)); + const slicedBuffer = new Uint8Array(VLBuffer.slice(1, 17)); const slicedBufferString = stringify(slicedBuffer); const uuids = userID.includes(",") ? userID.split(",") : [userID]; @@ -303,10 +303,10 @@ async function processVlessHeader(vlessBuffer, userID) { }; } - const optLength = new Uint8Array(vlessBuffer.slice(17, 18))[0]; + const optLength = new Uint8Array(VLBuffer.slice(17, 18))[0]; //skip opt for now - const command = new Uint8Array(vlessBuffer.slice(18 + optLength, 18 + optLength + 1))[0]; + const command = new Uint8Array(VLBuffer.slice(18 + optLength, 18 + optLength + 1))[0]; // 0x01 TCP // 0x02 UDP @@ -321,12 +321,12 @@ async function processVlessHeader(vlessBuffer, userID) { }; } const portIndex = 18 + optLength + 1; - const portBuffer = vlessBuffer.slice(portIndex, portIndex + 2); + const portBuffer = VLBuffer.slice(portIndex, portIndex + 2); // port is big-Endian in raw data etc 80 == 0x005d const portRemote = new DataView(portBuffer).getUint16(0); let addressIndex = portIndex + 2; - const addressBuffer = new Uint8Array(vlessBuffer.slice(addressIndex, addressIndex + 1)); + const addressBuffer = new Uint8Array(VLBuffer.slice(addressIndex, addressIndex + 1)); // 1--> ipv4 addressLength =4 // 2--> domain name addressLength=addressBuffer[1] @@ -338,16 +338,16 @@ async function processVlessHeader(vlessBuffer, userID) { switch (addressType) { case 1: addressLength = 4; - addressValue = new Uint8Array(vlessBuffer.slice(addressValueIndex, addressValueIndex + addressLength)).join("."); + addressValue = new Uint8Array(VLBuffer.slice(addressValueIndex, addressValueIndex + addressLength)).join("."); break; case 2: - addressLength = new Uint8Array(vlessBuffer.slice(addressValueIndex, addressValueIndex + 1))[0]; + addressLength = new Uint8Array(VLBuffer.slice(addressValueIndex, addressValueIndex + 1))[0]; addressValueIndex += 1; - addressValue = new TextDecoder().decode(vlessBuffer.slice(addressValueIndex, addressValueIndex + addressLength)); + addressValue = new TextDecoder().decode(VLBuffer.slice(addressValueIndex, addressValueIndex + addressLength)); break; case 3: addressLength = 16; - const dataView = new DataView(vlessBuffer.slice(addressValueIndex, addressValueIndex + addressLength)); + const dataView = new DataView(VLBuffer.slice(addressValueIndex, addressValueIndex + addressLength)); // 2001:0db8:85a3:0000:0000:8a2e:0370:7334 const ipv6 = []; for (let i = 0; i < 8; i++) { @@ -375,7 +375,7 @@ async function processVlessHeader(vlessBuffer, userID) { addressType, portRemote, rawDataIndex: addressValueIndex + addressLength, - vlessVersion: version, + VLVersion: version, isUDP, }; } @@ -384,17 +384,17 @@ async function processVlessHeader(vlessBuffer, userID) { * Converts a remote socket to a WebSocket connection. * @param {import("@cloudflare/workers-types").Socket} remoteSocket The remote socket to convert. * @param {import("@cloudflare/workers-types").WebSocket} webSocket The WebSocket to connect to. - * @param {ArrayBuffer | null} vlessResponseHeader The VLESS response header. + * @param {ArrayBuffer | null} VLResponseHeader The VL response header. * @param {(() => Promise) | null} retry The function to retry the connection if it fails. * @param {(info: string) => void} log The logging function. * @returns {Promise} A Promise that resolves when the conversion is complete. */ -async function vlessRemoteSocketToWS(remoteSocket, webSocket, vlessResponseHeader, retry, log) { +async function VLRemoteSocketToWS(remoteSocket, webSocket, VLResponseHeader, retry, log) { // remote--> ws let remoteChunkCount = 0; let chunks = []; /** @type {ArrayBuffer | null} */ - let vlessHeader = vlessResponseHeader; + let VLHeader = VLResponseHeader; let hasIncomingData = false; // check if remoteSocket has incoming data await remoteSocket.readable .pipeTo( @@ -411,9 +411,9 @@ async function vlessRemoteSocketToWS(remoteSocket, webSocket, vlessResponseHeade if (webSocket.readyState !== WS_READY_STATE_OPEN) { controller.error("webSocket.readyState is not open, maybe close"); } - if (vlessHeader) { - webSocket.send(await new Blob([vlessHeader, chunk]).arrayBuffer()); - vlessHeader = null; + if (VLHeader) { + webSocket.send(await new Blob([VLHeader, chunk]).arrayBuffer()); + VLHeader = null; } else { // seems no need rate limit this, CF seems fix this??.. // if (remoteChunkCount > 20000) { @@ -524,12 +524,12 @@ function stringify(arr, offset = 0) { /** * Handles outbound UDP traffic by transforming the data into DNS queries and sending them over a WebSocket connection. * @param {import("@cloudflare/workers-types").WebSocket} webSocket The WebSocket connection to send the DNS queries over. - * @param {ArrayBuffer} vlessResponseHeader The VLESS response header. + * @param {ArrayBuffer} VLResponseHeader The VL response header. * @param {(string) => void} log The logging function. * @returns {{write: (chunk: Uint8Array) => void}} An object with a write method that accepts a Uint8Array chunk to write to the transform stream. */ -async function handleUDPOutBound(webSocket, vlessResponseHeader, log) { - let isVlessHeaderSent = false; +async function handleUDPOutBound(webSocket, VLResponseHeader, log) { + let isVLHeaderSent = false; const transformStream = new TransformStream({ start(controller) {}, transform(chunk, controller) { @@ -567,11 +567,11 @@ async function handleUDPOutBound(webSocket, vlessResponseHeader, log) { const udpSizeBuffer = new Uint8Array([(udpSize >> 8) & 0xff, udpSize & 0xff]); if (webSocket.readyState === WS_READY_STATE_OPEN) { log(`doh success and dns message length is ${udpSize}`); - if (isVlessHeaderSent) { + if (isVLHeaderSent) { webSocket.send(await new Blob([udpSizeBuffer, dnsQueryResult]).arrayBuffer()); } else { - webSocket.send(await new Blob([vlessResponseHeader, udpSizeBuffer, dnsQueryResult]).arrayBuffer()); - isVlessHeaderSent = true; + webSocket.send(await new Blob([VLResponseHeader, udpSizeBuffer, dnsQueryResult]).arrayBuffer()); + isVLHeaderSent = true; } } }, diff --git a/src/worker.js b/src/worker.js index faed5d188..2d7c72823 100644 --- a/src/worker.js +++ b/src/worker.js @@ -1,6 +1,6 @@ import { initializeParams } from './helpers/init'; -import { vlessOverWSHandler } from './protocols/vless'; -import { trojanOverWSHandler } from './protocols/trojan'; +import { VLOverWSHandler } from './protocols/vless'; +import { TROverWSHandler } from './protocols/trojan'; import { updateWarpConfigs } from './kv/handlers'; import { logout, resetPassword, login } from './authentication/auth'; import { renderErrorPage } from './pages/error'; @@ -60,8 +60,8 @@ export default { } } else { return globalThis.pathName.startsWith('/tr') - ? await trojanOverWSHandler(request) - : await vlessOverWSHandler(request); + ? await TROverWSHandler(request) + : await VLOverWSHandler(request); } } catch (err) { return await renderErrorPage(err);