diff --git a/src/authentication/auth.js b/src/authentication/auth.js index 521136806..b58b3bab0 100644 --- a/src/authentication/auth.js +++ b/src/authentication/auth.js @@ -1,8 +1,8 @@ import { SignJWT, jwtVerify } from 'jose'; import nacl from 'tweetnacl'; import { initializeParams, userID, origin } from "../helpers/init"; -import { renderLoginPage } from '../pages/loginPage'; -import { renderErrorPage } from '../pages/errorPage'; +import { renderLoginPage } from '../pages/login'; +import { renderErrorPage } from '../pages/error'; async function generateJWTToken (request, env) { await initializeParams(request, env); diff --git a/src/cores-configs/clash.js b/src/cores-configs/clash.js index 3de30a712..2afab084d 100644 --- a/src/cores-configs/clash.js +++ b/src/cores-configs/clash.js @@ -1,7 +1,7 @@ import { getConfigAddresses, extractWireguardParams, generateRemark, randomUpperCase, getRandomPath, isIPv6 } from './helpers'; import { initializeParams, userID, trojanPassword, hostName, defaultHttpsPorts } from "../helpers/init"; import { getDataset } from '../kv/handlers'; -import { renderErrorPage } from '../pages/errorPage'; +import { renderErrorPage } from '../pages/error'; import { isDomain } from '../helpers/helpers'; async function buildClashDNS (proxySettings, isChain, isWarp) { @@ -19,7 +19,7 @@ async function buildClashDNS (proxySettings, isChain, isWarp) { } = 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", "[2606:4700:4700::1111]", "[2606:4700:4700::1001]"] : ["1.1.1.1", "1.0.0.1"]; const isFakeDNS = (vlessTrojanFakeDNS && !isWarp) || (warpFakeDNS && isWarp); const isIPv6 = (enableIPv6 && !isWarp) || (warpEnableIPv6 && isWarp); @@ -30,33 +30,35 @@ async function buildClashDNS (proxySettings, isChain, isWarp) { { rule: bypassRussia, geosite: "category-ru" } ]; - let dns = { + const dns = { "enable": true, "listen": "0.0.0.0:1053", "ipv6": isIPv6, "respect-rules": true, "use-hosts": true, "use-system-hosts": false, - "nameserver": isWarp ? warpRemoteDNS : [remoteDNS], - "proxy-server-nameserver": [localDNS] + "nameserver": isWarp + ? warpRemoteDNS.map(dns => isChain ? `${dns}#💦 Warp - Best Ping 🚀` : dns) + : [isChain ? `${remoteDNS}#proxy-1` : remoteDNS], + "proxy-server-nameserver": [`${localDNS}#DIRECT`] }; if (isChain && !isWarp) { const chainOutboundServer = JSON.parse(outProxyParams).server; if (isDomain(chainOutboundServer)) dns["nameserver-policy"] = { - [chainOutboundServer]: remoteDNS + [chainOutboundServer]: `${remoteDNS}#proxy-1` }; } if (isBypass) { - let geosites = []; + const geosites = []; bypassRules.forEach(({ rule, geosite }) => { rule && geosites.push(geosite) }); dns["nameserver-policy"] = { ...dns["nameserver-policy"], - [`geosite:${geosites.join(',')}`]: [localDNS] + [`geosite:${geosites.join(',')}`]: [`${localDNS}#DIRECT`] }; } @@ -69,11 +71,8 @@ async function buildClashDNS (proxySettings, isChain, isWarp) { return dns; } -function buildClashRoutingRules (proxySettings, isChain, isWarp) { +function buildClashRoutingRules (proxySettings) { const { - remoteDNS, - localDNS, - warpEnableIPv6, bypassLAN, bypassIran, bypassChina, @@ -83,11 +82,9 @@ function buildClashRoutingRules (proxySettings, isChain, isWarp) { blockUDP443 } = proxySettings; - const url = new URL(remoteDNS); - const remoteDNSServer = url.hostname; const isBypass = bypassIran || bypassChina || bypassLAN || bypassRussia; const isBlock = blockAds || blockPorn; - let geositeDirectRules = [], geoipDirectRules = [], geositeBlockRules = []; + const geositeDirectRules = [], geoipDirectRules = [], geositeBlockRules = []; const geoRules = [ { rule: bypassLAN, type: 'direct', geosite: "private", geoip: "LAN" }, { rule: bypassIran, type: 'direct', geosite: "category-ir", geoip: "ir" }, @@ -111,19 +108,13 @@ function buildClashRoutingRules (proxySettings, isChain, isWarp) { }); } - let rules = [ - `AND,((IP-CIDR,${localDNS}/32),(NETWORK,udp),(DST-PORT,53)),DIRECT`, + const rules = [ ...geositeDirectRules, ...geoipDirectRules, ...geositeBlockRules ]; blockUDP443 && rules.push("AND,((NETWORK,udp),(DST-PORT,443)),REJECT"); - if (isChain) { - isWarp && !warpEnableIPv6 && rules.push("OR,((IP-CIDR,1.1.1.1/32),(IP-CIDR,1.0.0.1/32)),💦 Warp - Best Ping 🚀"); - isWarp && warpEnableIPv6 && rules.push("OR,((IP-CIDR,1.1.1.1/32),(IP-CIDR,1.0.0.1/32),(IP-CIDR6,2606:4700:4700::1111/128),(IP-CIDR6,2606:4700:4700::1001/128)),💦 Warp - Best Ping 🚀"); - !isWarp && rules.push(`AND,((${isDomain(remoteDNSServer) ? 'DOMAIN' : 'IP-CIDR'},${isDomain(remoteDNSServer) ? remoteDNSServer : `${remoteDNSServer}/32`}),(NETWORK,tcp)),proxy-1`); - } rules.push("MATCH,✅ Selector"); return rules; } @@ -131,7 +122,7 @@ function buildClashRoutingRules (proxySettings, isChain, isWarp) { function buildClashVLESSOutbound (remark, address, port, host, sni, path, allowInsecure) { const tls = defaultHttpsPorts.includes(port) ? true : false; const addr = isIPv6(address) ? address.replace(/\[|\]/g, '') : address; - let outbound = { + const outbound = { "name": remark, "type": "vless", "server": addr, @@ -228,7 +219,7 @@ function buildClashChainOutbound(chainProxyParams) { } const { server, port, uuid, flow, security, type, sni, fp, alpn, pbk, sid, headerType, host, path, serviceName } = chainProxyParams; - let chainOutbound = { + const chainOutbound = { "name": "💦 Chain Best Ping 💥", "type": "vless", "server": server, @@ -296,9 +287,9 @@ export async function getClashWarpConfig(request, env) { const { kvNotFound, proxySettings, warpConfigs } = await getDataset(request, env); if (kvNotFound) return await renderErrorPage(request, env, 'KV Dataset is not properly set!', null, true); const { warpEndpoints } = proxySettings; - let config = structuredClone(clashConfigTemp); - config.dns = await buildClashDNS(proxySettings, false, true); - config.rules = buildClashRoutingRules(proxySettings, true, true); + const config = structuredClone(clashConfigTemp); + config.dns = await buildClashDNS(proxySettings, true, true); + config.rules = buildClashRoutingRules(proxySettings); const selector = config['proxy-groups'][0]; const warpUrlTest = config['proxy-groups'][1]; selector.proxies = ['💦 Warp - Best Ping 🚀', '💦 WoW - Best Ping 🚀']; @@ -368,7 +359,7 @@ export async function getClashNormalConfig (request, env) { } } - let config = structuredClone(clashConfigTemp); + const config = structuredClone(clashConfigTemp); if (resolvedRemoteDNS.server) { config.hosts = { [resolvedRemoteDNS.server]: resolvedRemoteDNS.staticIPs @@ -376,16 +367,16 @@ export async function getClashNormalConfig (request, env) { } else { delete config.hosts; } - const Addresses = await getConfigAddresses(hostName, cleanIPs, enableIPv6); - const customCdnAddresses = customCdnAddrs ? customCdnAddrs.split(',') : []; - const totalAddresses = [...Addresses, ...customCdnAddresses]; config.dns = await buildClashDNS(proxySettings, chainProxy, false); - config.rules = buildClashRoutingRules(proxySettings, chainProxy, false); + config.rules = buildClashRoutingRules(proxySettings); const selector = config['proxy-groups'][0]; const urlTest = config['proxy-groups'][1]; selector.proxies = ['💦 Best Ping 💥']; urlTest.name = '💦 Best Ping 💥'; urlTest.interval = +bestVLESSTrojanInterval; + const Addresses = await getConfigAddresses(hostName, cleanIPs, enableIPv6); + const customCdnAddresses = customCdnAddrs ? customCdnAddrs.split(',') : []; + const totalAddresses = [...Addresses, ...customCdnAddresses]; let proxyIndex = 1, path; const protocols = [ ...(vlessConfigs ? ['VLESS'] : []), @@ -463,7 +454,9 @@ const clashConfigTemp = { "ipv6": true, "allow-lan": true, "mode": "rule", - "log-level": "info", + "log-level": "debug", + "disable-keep-alive": false, + "keep-alive-idle": 30, "keep-alive-interval": 30, "unified-delay": false, "geo-auto-update": true, diff --git a/src/cores-configs/normalConfigs.js b/src/cores-configs/normalConfigs.js index b21619dc7..1f1193219 100644 --- a/src/cores-configs/normalConfigs.js +++ b/src/cores-configs/normalConfigs.js @@ -1,7 +1,7 @@ import { getConfigAddresses, generateRemark, randomUpperCase, getRandomPath } from './helpers'; import { initializeParams, userID, trojanPassword, hostName, client, defaultHttpsPorts } from "../helpers/init"; import { getDataset } from '../kv/handlers'; -import { renderErrorPage } from '../pages/errorPage'; +import { renderErrorPage } from '../pages/error'; export async function getNormalConfigs(request, env) { await initializeParams(request, env); diff --git a/src/cores-configs/sing-box.js b/src/cores-configs/sing-box.js index b0c852d57..a0a597d7f 100644 --- a/src/cores-configs/sing-box.js +++ b/src/cores-configs/sing-box.js @@ -1,6 +1,6 @@ import { getConfigAddresses, extractWireguardParams, generateRemark, randomUpperCase, getRandomPath } from './helpers'; import { initializeParams, userID, trojanPassword, hostName, defaultHttpsPorts } from "../helpers/init"; -import { renderErrorPage } from '../pages/errorPage'; +import { renderErrorPage } from '../pages/error'; import { getDataset } from '../kv/handlers'; import { isDomain } from '../helpers/helpers'; @@ -22,16 +22,15 @@ function buildSingBoxDNS (proxySettings, outboundAddrs, isChain, isWarp) { let fakeip; const isFakeDNS = (vlessTrojanFakeDNS && !isWarp) || (warpFakeDNS && isWarp); const isIPv6 = (enableIPv6 && !isWarp) || (warpEnableIPv6 && isWarp); - const isBypass = bypassIran || bypassChina || bypassRussia; const geoRules = [ - { rule: bypassIran, type: 'direct', ruleSet: "geosite-ir" }, - { rule: bypassChina, type: 'direct', ruleSet: "geosite-cn" }, - { rule: bypassRussia, type: 'direct', ruleSet: "geosite-category-ru" }, - { rule: true, type: 'block', ruleSet: "geosite-malware" }, - { rule: true, type: 'block', ruleSet: "geosite-phishing" }, - { rule: true, type: 'block', ruleSet: "geosite-cryptominers" }, - { rule: blockAds, type: 'block', ruleSet: "geosite-category-ads-all" }, - { rule: blockPorn, type: 'block', ruleSet: "geosite-nsfw" } + { rule: bypassIran, type: 'direct', geosite: "geosite-ir", geoip: "geoip-ir" }, + { rule: bypassChina, type: 'direct', geosite: "geosite-cn", geoip: "geoip-cn" }, + { rule: bypassRussia, type: 'direct', geosite: "geosite-category-ru", geoip: "geoip-ru" }, + { rule: true, type: 'block', geosite: "geosite-malware" }, + { rule: true, type: 'block', geosite: "geosite-phishing" }, + { rule: true, type: 'block', geosite: "geosite-cryptominers" }, + { rule: blockAds, type: 'block', geosite: "geosite-category-ads-all" }, + { rule: blockPorn, type: 'block', geosite: "geosite-nsfw" } ]; const servers = [ { @@ -61,32 +60,24 @@ function buildSingBoxDNS (proxySettings, outboundAddrs, isChain, isWarp) { }; } else { const outboundDomains = outboundAddrs.filter(address => isDomain(address)); + const uniqueDomains = [...new Set(outboundDomains)]; outboundRule = { - domain: outboundDomains, + domain: uniqueDomains, server: "dns-direct" }; } - let rules = [ + const rules = [ outboundRule, { - clash_mode: "block", - server: "dns-block" - }, - { - clash_mode: "direct", + clash_mode: "Direct", server: "dns-direct" }, { - clash_mode: "global", + clash_mode: "Global", server: "dns-remote" } ]; - - let bypassRule = { - rule_set: [], - server: "dns-direct" - }; let blockRule = { disable_cache: true, @@ -94,12 +85,20 @@ function buildSingBoxDNS (proxySettings, outboundAddrs, isChain, isWarp) { server: "dns-block" }; - geoRules.forEach(({ rule, type, ruleSet }) => { - rule && type === 'direct' && bypassRule.rule_set.push(ruleSet); - rule && type === 'block' && blockRule.rule_set.push(ruleSet); + geoRules.forEach(({ rule, type, geosite, geoip }) => { + rule && type === 'direct' && rules.push({ + type: "logical", + mode: "and", + rules: [ + { rule_set: geosite }, + { rule_set: geoip } + ], + "server": "dns-direct" + }); + + rule && type === 'block' && blockRule.rule_set.push(geosite); }); - isBypass && rules.push(bypassRule); rules.push(blockRule); if (isFakeDNS) { servers.push({ @@ -140,26 +139,27 @@ function buildSingBoxRoutingRules (proxySettings) { } = proxySettings; const isBypass = bypassIran || bypassChina || bypassRussia; - let rules = [ - { - inbound: "dns-in", - outbound: "dns-out" - }, + const rules = [ { - network: "udp", - port: 53, + type: "logical", + mode: "or", + rules: [ + { + inbound: "dns-in", + }, + { + network: "udp", + port: 53 + } + ], outbound: "dns-out" }, { - clash_mode: "direct", + clash_mode: "Direct", outbound: "direct" }, { - clash_mode: "block", - outbound: "block" - }, - { - clash_mode: "global", + clash_mode: "Global", outbound: "proxy" } ]; @@ -259,9 +259,9 @@ function buildSingBoxRoutingRules (proxySettings) { download_detour: "direct" }; - let directRule = createRule('direct');; - let blockRule = createRule('block'); - let ruleSets = []; + const directRule = createRule('direct');; + const blockRule = createRule('block'); + const ruleSets = []; geoRules.forEach(({ rule, type, ruleSet }) => { const { geosite, geoip, geositeURL, geoipURL } = ruleSet; @@ -270,7 +270,7 @@ function buildSingBoxRoutingRules (proxySettings) { directRule.rule_set.unshift(geosite); directRule.rule_set.push(geoip); } else { - blockRule.rule_set.unshift(geosite); + blockRule.rule_set.unshift(geosite); geoip && blockRule.rule_set.push(geoip); } ruleSets.push({...routingRuleSet, tag: geosite, url: geositeURL}); @@ -295,7 +295,7 @@ function buildSingBoxVLESSOutbound (proxySettings, remark, address, port, host, const { enableIPv6, lengthMin, lengthMax, intervalMin, intervalMax, proxyIP } = proxySettings; const path = `/${getRandomPath(16)}${proxyIP ? `/${btoa(proxyIP)}` : ''}`; const tls = defaultHttpsPorts.includes(port) ? true : false; - let outbound = { + const outbound = { type: "vless", server: address, server_port: +port, @@ -337,7 +337,7 @@ function buildSingBoxTrojanOutbound (proxySettings, remark, address, port, host, const { enableIPv6, lengthMin, lengthMax, intervalMin, intervalMax, proxyIP } = proxySettings; const path = `/tr${getRandomPath(16)}${proxyIP ? `/${btoa(proxyIP)}` : ''}`; const tls = defaultHttpsPorts.includes(port) ? true : false; - let outbound = { + const outbound = { type: "trojan", password: trojanPassword, server: address, @@ -398,7 +398,7 @@ function buildSingBoxWarpOutbound (proxySettings, warpConfigs, remark, endpoint, privateKey } = extractWireguardParams(warpConfigs, chain); - let outbound = { + const outbound = { local_address: [ "172.16.0.2/32", warpIPv6 @@ -429,7 +429,7 @@ function buildSingBoxChainOutbound (chainProxyParams, enableIPv6) { if (["socks", "http"].includes(chainProxyParams.protocol)) { const { protocol, server, port, user, pass } = chainProxyParams; - let chainOutbound = { + const chainOutbound = { type: protocol, tag: "", server: server, @@ -444,7 +444,7 @@ function buildSingBoxChainOutbound (chainProxyParams, enableIPv6) { } const { server, port, uuid, flow, security, type, sni, fp, alpn, pbk, sid, headerType, host, path, serviceName } = chainProxyParams; - let chainOutbound = { + const chainOutbound = { type: "vless", tag: "", server: server, @@ -517,7 +517,7 @@ export async function getSingBoxWarpConfig (request, env, client) { const { kvNotFound, proxySettings, warpConfigs } = await getDataset(request, env); if (kvNotFound) return await renderErrorPage(request, env, 'KV Dataset is not properly set!', null, true); const { warpEndpoints } = proxySettings; - let config = structuredClone(singboxConfigTemp); + const config = structuredClone(singboxConfigTemp); const dnsObject = buildSingBoxDNS(proxySettings, undefined, false, true); const {rules, rule_set} = buildSingBoxRoutingRules(proxySettings); config.dns.servers = dnsObject.servers; @@ -535,7 +535,7 @@ export async function getSingBoxWarpConfig (request, env, client) { warpUrlTest.interval = `${proxySettings.bestWarpInterval}s`; WoWUrlTest.tag = `💦 WoW${proIndicator}- Best Ping 🚀`; WoWUrlTest.interval = `${proxySettings.bestWarpInterval}s`; - let warpRemarks = [], WoWRemarks = []; + const warpRemarks = [], WoWRemarks = []; warpEndpoints.split(',').forEach( (endpoint, index) => { const warpRemark = `💦 ${index + 1} - Warp 🇮🇷`; @@ -597,7 +597,7 @@ export async function getSingBoxCustomConfig(request, env, isFragment) { const Addresses = await getConfigAddresses(hostName, cleanIPs, enableIPv6); const customCdnAddresses = customCdnAddrs ? customCdnAddrs.split(',') : []; const totalAddresses = [...Addresses, ...customCdnAddresses]; - let config = structuredClone(singboxConfigTemp); + const config = structuredClone(singboxConfigTemp); const dnsObject = buildSingBoxDNS(proxySettings, totalAddresses, chainProxyOutbound, false); const {rules, rule_set} = buildSingBoxRoutingRules(proxySettings); config.dns.servers = dnsObject.servers; @@ -657,7 +657,7 @@ export async function getSingBoxCustomConfig(request, env, isFragment) { } if (chainProxyOutbound) { - let chain = structuredClone(chainProxyOutbound); + const chain = structuredClone(chainProxyOutbound); chain.tag = remark; chain.detour = `proxy-${proxyIndex}`; config.outbounds.push(chain); @@ -774,7 +774,7 @@ const singboxConfigTemp = { external_ui: "yacd", external_ui_download_url: "https://github.com/MetaCubeX/metacubexd/archive/refs/heads/gh-pages.zip", external_ui_download_detour: "direct", - default_mode: "rule" + default_mode: "Rule" } } }; \ No newline at end of file diff --git a/src/cores-configs/xray.js b/src/cores-configs/xray.js index 7d746bd23..7ffc2c533 100644 --- a/src/cores-configs/xray.js +++ b/src/cores-configs/xray.js @@ -1,8 +1,8 @@ -import { resolveDNS, isDomain } from '../helpers/helpers.js'; +import { resolveDNS, isDomain } from '../helpers/helpers'; import { getConfigAddresses, extractWireguardParams, base64ToDecimal, generateRemark, randomUpperCase, getRandomPath } from './helpers'; import { initializeParams, userID, trojanPassword, hostName, defaultHttpsPorts } from "../helpers/init"; -import { getDataset } from '../kv/handlers.js'; -import { renderErrorPage } from '../pages/errorPage.js'; +import { getDataset } from '../kv/handlers'; +import { renderErrorPage } from '../pages/error'; async function buildXrayDNS (proxySettings, outboundAddrs, domainToStaticIPs, isWorkerLess, isWarp) { const { @@ -29,16 +29,17 @@ async function buildXrayDNS (proxySettings, outboundAddrs, domainToStaticIPs, is ]; const blockRules = [ - { rule: blockAds, host: "geosite:category-ads-all", address: ["127.0.0.1"] }, - { rule: blockAds, host: "geosite:category-ads-ir", address: ["127.0.0.1"] }, - { rule: blockPorn, host: "geosite:category-porn", address: ["127.0.0.1"] } + { rule: blockAds, host: "geosite:category-ads-all" }, + { rule: blockAds, host: "geosite:category-ads-ir" }, + { rule: blockPorn, host: "geosite:category-porn" } ]; const isFakeDNS = (vlessTrojanFakeDNS && !isWarp) || (warpFakeDNS && isWarp); const isIPv6 = (enableIPv6 && !isWarp) || (warpEnableIPv6 && isWarp); const outboundDomains = outboundAddrs.filter(address => isDomain(address)); - const isOutboundRule = outboundDomains.length > 0; - const outboundRules = outboundDomains.map(domain => `full:${domain}`); + const uniqueDomains = [...new Set(outboundDomains)]; + const isOutboundRule = uniqueDomains.length > 0; + const outboundRules = uniqueDomains.map(domain => `full:${domain}`); const finalRemoteDNS = isWorkerLess ? ["https://cloudflare-dns.com/dns-query"] : isWarp @@ -48,8 +49,8 @@ async function buildXrayDNS (proxySettings, outboundAddrs, domainToStaticIPs, is : [remoteDNS]; const dnsHost = {}; - isBlock && blockRules.forEach( ({ rule, host, address}) => { - if (rule) dnsHost[host] = address; + isBlock && blockRules.forEach( ({ rule, host }) => { + if (rule) dnsHost[host] = ["127.0.0.1"]; }); const staticIPs = domainToStaticIPs ? await resolveDNS(domainToStaticIPs) : undefined; @@ -67,7 +68,7 @@ async function buildXrayDNS (proxySettings, outboundAddrs, domainToStaticIPs, is } const hosts = Object.keys(dnsHost).length ? { hosts: dnsHost } : {}; - let dnsObject = { + const dnsObject = { ...hosts, servers: finalRemoteDNS, queryStrategy: isIPv6 ? "UseIP" : "UseIPv4", @@ -80,7 +81,7 @@ async function buildXrayDNS (proxySettings, outboundAddrs, domainToStaticIPs, is skipFallback: true }); - let localDNSServer = { + const localDNSServer = { address: localDNS, domains: [], expectIPs: [], @@ -112,7 +113,6 @@ function buildXrayRoutingRules (proxySettings, outboundAddrs, isChain, isBalance const { remoteDNS, localDNS, - warpEnableIPv6, bypassLAN, bypassIran, bypassChina, @@ -122,13 +122,6 @@ function buildXrayRoutingRules (proxySettings, outboundAddrs, isChain, isBalance blockUDP443 } = proxySettings; - const url = new URL(remoteDNS); - const remoteDNSServer = url.hostname; - const finalRemoteDNSHosts = isWarp - ? 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"] - : [remoteDNSServer]; const isBlock = blockAds || blockPorn; const isBypass = bypassIran || bypassChina || bypassRussia; const geoRules = [ @@ -141,7 +134,7 @@ function buildXrayRoutingRules (proxySettings, outboundAddrs, isChain, isBalance ]; const outboundDomains = outboundAddrs.filter(address => isDomain(address)); const isOutboundRule = outboundDomains.length > 0; - let rules = [ + const rules = [ { inboundTag: [ "dns-in" @@ -204,12 +197,28 @@ function buildXrayRoutingRules (proxySettings, outboundAddrs, isChain, isBalance type: "field", }); - isChain && rules.push({ - [isDomain(remoteDNSServer) && !isWarp ? "domain" : "ip"]: finalRemoteDNSHosts, - [isBalancer ? "balancerTag" : "outboundTag"]: isBalancer ? "all-proxy" : "proxy", - network: isWarp ? "udp" : "tcp", - type: "field" - }); + if (isChain) { + const rule = { + [isBalancer ? "balancerTag" : "outboundTag"]: isBalancer ? "all-proxy" : "proxy", + type: "field" + }; + + if (!isWarp) { + const url = new URL(remoteDNS); + const remoteDNSServer = url.hostname; + rules.push({ + [isDomain(remoteDNSServer) ? "domain" : "ip"]: [remoteDNSServer], + network: "tcp", + ...rule + }); + } else { + rules.push({ + network: "udp", + port: "53", + ...rule + }); + } + } if (isBalancer) { rules.push({ @@ -229,7 +238,7 @@ function buildXrayRoutingRules (proxySettings, outboundAddrs, isChain, isBalance } function buildXrayVLESSOutbound (tag, address, port, host, sni, proxyIP, isFragment, allowInsecure, enableIPv6) { - let outbound = { + const outbound = { protocol: "vless", settings: { vnext: [ @@ -271,19 +280,20 @@ function buildXrayVLESSOutbound (tag, address, port, host, sni, proxyIP, isFragm }; } + const sockopt = outbound.streamSettings.sockopt; if (isFragment) { - outbound.streamSettings.sockopt.dialerProxy = "fragment"; + sockopt.dialerProxy = "fragment"; } else { - outbound.streamSettings.sockopt.tcpKeepAliveIdle = 60; - outbound.streamSettings.sockopt.tcpNoDelay = true; - outbound.streamSettings.sockopt.domainStrategy = enableIPv6 ? "UseIPv4v6" : "UseIPv4"; + sockopt.tcpKeepAliveIdle = 30; + sockopt.tcpNoDelay = true; + sockopt.domainStrategy = enableIPv6 ? "UseIPv4v6" : "UseIPv4"; } return outbound; } function buildXrayTrojanOutbound (tag, address, port, host, sni, proxyIP, isFragment, allowInsecure, enableIPv6) { - let outbound = { + const outbound = { protocol: "trojan", settings: { servers: [ @@ -319,12 +329,13 @@ function buildXrayTrojanOutbound (tag, address, port, host, sni, proxyIP, isFrag }; } + const sockopt = outbound.streamSettings.sockopt; if (isFragment) { - outbound.streamSettings.sockopt.dialerProxy = "fragment"; + sockopt.dialerProxy = "fragment"; } else { - outbound.streamSettings.sockopt.tcpKeepAliveIdle = 60; - outbound.streamSettings.sockopt.tcpNoDelay = true; - outbound.streamSettings.sockopt.domainStrategy = enableIPv6 ? "UseIPv4v6" : "UseIPv4"; + sockopt.tcpKeepAliveIdle = 30; + sockopt.tcpNoDelay = true; + sockopt.domainStrategy = enableIPv6 ? "UseIPv4v6" : "UseIPv4"; } return outbound; @@ -332,6 +343,7 @@ function buildXrayTrojanOutbound (tag, address, port, host, sni, proxyIP, isFrag function buildXrayWarpOutbound (proxySettings, warpConfigs, endpoint, isChain, client) { const { + warpEnableIPv6, nikaNGNoiseMode, noiseCountMin, noiseCountMax, @@ -348,7 +360,7 @@ function buildXrayWarpOutbound (proxySettings, warpConfigs, endpoint, isChain, c privateKey } = extractWireguardParams(warpConfigs, isChain); - let outbound = { + const outbound = { protocol: "wireguard", settings: { address: [ @@ -369,8 +381,7 @@ function buildXrayWarpOutbound (proxySettings, warpConfigs, endpoint, isChain, c streamSettings: { sockopt: { dialerProxy: "proxy", - tcpKeepAliveIdle: 100, - tcpNoDelay: true, + domainStrategy: warpEnableIPv6 ? "UseIPv4v6" : "UseIPv4", } }, tag: isChain ? "chain" : "proxy" @@ -387,7 +398,7 @@ function buildXrayWarpOutbound (proxySettings, warpConfigs, endpoint, isChain, c return outbound; } -function buildXrayChainOutbound(chainProxyParams) { +function buildXrayChainOutbound(chainProxyParams, enableIPv6) { if (['socks', 'http'].includes(chainProxyParams.protocol)) { const { protocol, server, port, user, pass } = chainProxyParams; return { @@ -411,6 +422,7 @@ function buildXrayChainOutbound(chainProxyParams) { network: "tcp", sockopt: { dialerProxy: "proxy", + domainStrategy: enableIPv6 ? "UseIPv4v6" : "UseIPv4", tcpNoDelay: true } }, @@ -445,7 +457,7 @@ function buildXrayChainOutbound(chainProxyParams) { mode } = chainProxyParams; - let proxyOutbound = { + const proxyOutbound = { mux: { concurrency: 8, enabled: true, @@ -475,6 +487,7 @@ function buildXrayChainOutbound(chainProxyParams) { security: security, sockopt: { dialerProxy: "proxy", + domainStrategy: enableIPv6 ? "UseIPv4v6" : "UseIPv4", tcpNoDelay: true } }, @@ -552,7 +565,6 @@ function buildXrayConfig (proxySettings, remark, isFragment, isBalancer, isChain vlessTrojanFakeDNS, enableIPv6, warpFakeDNS, - warpEnableIPv6, bestVLESSTrojanInterval, bestWarpInterval, lengthMin, @@ -563,8 +575,7 @@ function buildXrayConfig (proxySettings, remark, isFragment, isBalancer, isChain } = proxySettings; const isFakeDNS = (vlessTrojanFakeDNS && !isWarp) || (warpFakeDNS && isWarp); - const isIPv6 = (enableIPv6 && !isWarp) || (warpEnableIPv6 && isWarp); - let config = structuredClone(xrayConfigTemp); + const config = structuredClone(xrayConfigTemp); config.remarks = remark; if (isFakeDNS) { config.inbounds[0].sniffing.destOverride.push("fakedns"); @@ -602,7 +613,7 @@ function buildXrayConfig (proxySettings, remark, isFragment, isBalancer, isChain async function buildXrayBestPingConfig(proxySettings, totalAddresses, chainProxy, outbounds, isFragment) { const remark = isFragment ? '💦 BPB F - Best Ping 💥' : '💦 BPB - Best Ping 💥'; - let config = buildXrayConfig(proxySettings, remark, isFragment, true, chainProxy, true); + const config = buildXrayConfig(proxySettings, remark, isFragment, true, chainProxy, true); config.dns = await buildXrayDNS(proxySettings, totalAddresses, undefined, false, false); config.routing.rules = buildXrayRoutingRules(proxySettings, totalAddresses, chainProxy, true, false, false); config.outbounds.unshift(...outbounds); @@ -615,24 +626,24 @@ async function buildXrayBestFragmentConfig(proxySettings, hostName, chainProxy, '70-80', '80-90', '90-100', '10-30', '20-40', '30-50', '40-60', '50-70', '60-80', '70-90', '80-100', '100-200']; - let config = buildXrayConfig(proxySettings, '💦 BPB F - Best Fragment 😎', true, true, chainProxy, false, false); + const config = buildXrayConfig(proxySettings, '💦 BPB F - Best Fragment 😎', true, true, chainProxy, false, false); config.dns = await buildXrayDNS(proxySettings, [], hostName, false, false); config.routing.rules = buildXrayRoutingRules(proxySettings, [], chainProxy, true, false, false); const fragment = config.outbounds.shift(); - let bestFragOutbounds = []; + const bestFragOutbounds = []; bestFragValues.forEach( (fragLength, index) => { if (chainProxy) { - let chainOutbound = structuredClone(chainProxy); + const chainOutbound = structuredClone(chainProxy); chainOutbound.tag = `chain-${index + 1}`; chainOutbound.streamSettings.sockopt.dialerProxy = `prox-${index + 1}`; bestFragOutbounds.push(chainOutbound); } - let proxyOutbound = structuredClone(outbounds[chainProxy ? 1 : 0]); + const proxyOutbound = structuredClone(outbounds[chainProxy ? 1 : 0]); proxyOutbound.tag = `prox-${index + 1}`; proxyOutbound.streamSettings.sockopt.dialerProxy = `frag-${index + 1}`; - let fragmentOutbound = structuredClone(fragment); + const fragmentOutbound = structuredClone(fragment); fragmentOutbound.tag = `frag-${index + 1}`; fragmentOutbound.settings.fragment.length = fragLength; fragmentOutbound.settings.fragment.interval = '1-1'; @@ -644,10 +655,10 @@ async function buildXrayBestFragmentConfig(proxySettings, hostName, chainProxy, } async function buildXrayWorkerLessConfig(proxySettings) { - let config = buildXrayConfig(proxySettings, '💦 BPB F - WorkerLess ⭐', true, false, false, false, false); + 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); - let fakeOutbound = buildXrayVLESSOutbound('fake-outbound', 'google.com', '443', userID, 'google.com', 'google.com', '', true, false); + const fakeOutbound = buildXrayVLESSOutbound('fake-outbound', 'google.com', '443', userID, 'google.com', 'google.com', '', true, false); delete fakeOutbound.streamSettings.sockopt; fakeOutbound.streamSettings.wsSettings.path = '/'; config.outbounds.push(fakeOutbound); @@ -679,7 +690,7 @@ export async function getXrayCustomConfigs(request, env, isFragment) { if (outProxy) { const proxyParams = JSON.parse(outProxyParams); try { - chainProxy = buildXrayChainOutbound(proxyParams); + chainProxy = buildXrayChainOutbound(proxyParams, enableIPv6); } catch (error) { console.log('An error occured while parsing chain proxy: ', error); chainProxy = undefined; @@ -708,10 +719,10 @@ export async function getXrayCustomConfigs(request, env, isFragment) { const sni = isCustomAddr ? customCdnSni : randomUpperCase(hostName); const host = isCustomAddr ? customCdnHost : hostName; const remark = generateRemark(protocolIndex, port, addr, cleanIPs, protocol, configType); - let customConfig = buildXrayConfig(proxySettings, remark, isFragment, false, chainProxy, false, false); + const customConfig = buildXrayConfig(proxySettings, remark, isFragment, false, chainProxy, false, false); customConfig.dns = await buildXrayDNS(proxySettings, [addr], undefined); customConfig.routing.rules = buildXrayRoutingRules(proxySettings, [addr], chainProxy, false, false, false); - let outbound = protocol === 'VLESS' + const outbound = protocol === 'VLESS' ? buildXrayVLESSOutbound('proxy', addr, port, host, sni, proxyIP, isFragment, isCustomAddr, enableIPv6) : buildXrayTrojanOutbound('proxy', addr, port, host, sni, proxyIP, isFragment, isCustomAddr, enableIPv6); @@ -720,7 +731,7 @@ export async function getXrayCustomConfigs(request, env, isFragment) { if (chainProxy) { customConfig.outbounds.unshift(chainProxy); - let chainOutbound = structuredClone(chainProxy); + const chainOutbound = structuredClone(chainProxy); chainOutbound.tag = `chain-${proxyIndex}`; chainOutbound.streamSettings.sockopt.dialerProxy = `prox-${proxyIndex}`; outbounds.push(chainOutbound); @@ -735,7 +746,7 @@ export async function getXrayCustomConfigs(request, env, isFragment) { } const bestPing = await buildXrayBestPingConfig(proxySettings, totalAddresses, chainProxy, outbounds, isFragment); - let finalConfigs = [...configs, bestPing]; + const finalConfigs = [...configs, bestPing]; if (isFragment) { const bestFragment = await buildXrayBestFragmentConfig(proxySettings, hostName, chainProxy, outbounds); const workerLessConfig = await buildXrayWorkerLessConfig(proxySettings); @@ -754,25 +765,23 @@ export async function getXrayCustomConfigs(request, env, isFragment) { export async function getXrayWarpConfigs (request, env, client) { const { kvNotFound, proxySettings, warpConfigs } = await getDataset(request, env); if (kvNotFound) return await renderErrorPage(request, env, 'KV Dataset is not properly set!', null, true); - let xrayWarpConfigs = []; - let xrayWoWConfigs = []; - let xrayWarpOutbounds = []; - let xrayWoWOutbounds = []; + const xrayWarpConfigs = []; + const xrayWoWConfigs = []; + const xrayWarpOutbounds = []; + const xrayWoWOutbounds = []; const { warpEndpoints } = proxySettings; const outboundDomains = warpEndpoints.split(',').map(endpoint => endpoint.split(':')[0]).filter(address => isDomain(address)); const proIndicator = client === 'nikang' ? ' Pro ' : ' '; for (const [index, endpoint] of warpEndpoints.split(',').entries()) { const endpointHost = endpoint.split(':')[0]; - let warpConfig = buildXrayConfig(proxySettings, `💦 ${index + 1} - Warp${proIndicator}🇮🇷`, false, false, false, false, true); - let WoWConfig = buildXrayConfig(proxySettings, `💦 ${index + 1} - WoW${proIndicator}🌍`, false, false, true, false, true); + const warpConfig = buildXrayConfig(proxySettings, `💦 ${index + 1} - Warp${proIndicator}🇮🇷`, false, false, false, false, true); + const WoWConfig = buildXrayConfig(proxySettings, `💦 ${index + 1} - WoW${proIndicator}🌍`, false, false, true, false, true); warpConfig.dns = WoWConfig.dns = await buildXrayDNS(proxySettings, [endpointHost], undefined, false, true); warpConfig.routing.rules = buildXrayRoutingRules(proxySettings, [endpointHost], false, false, false, true); WoWConfig.routing.rules = buildXrayRoutingRules(proxySettings, [endpointHost], true, false, false, true); const warpOutbound = buildXrayWarpOutbound(proxySettings, warpConfigs, endpoint, false, client); const WoWOutbound = buildXrayWarpOutbound(proxySettings, warpConfigs, endpoint, true, client); - warpOutbound.settings.peers[0].endpoint = endpoint; - WoWOutbound.settings.peers[0].endpoint = endpoint; warpConfig.outbounds.unshift(warpOutbound); WoWConfig.outbounds.unshift(WoWOutbound, warpOutbound); xrayWarpConfigs.push(warpConfig); @@ -787,11 +796,11 @@ export async function getXrayWarpConfigs (request, env, client) { } const dnsObject = await buildXrayDNS(proxySettings, outboundDomains, undefined, false, true); - let xrayWarpBestPing = buildXrayConfig(proxySettings, `💦 Warp${proIndicator}- Best Ping 🚀`, false, true, false, false, true); + const xrayWarpBestPing = buildXrayConfig(proxySettings, `💦 Warp${proIndicator}- Best Ping 🚀`, false, true, false, false, true); xrayWarpBestPing.dns = dnsObject; xrayWarpBestPing.routing.rules = buildXrayRoutingRules(proxySettings, outboundDomains, false, true, false, true); xrayWarpBestPing.outbounds.unshift(...xrayWarpOutbounds); - let xrayWoWBestPing = buildXrayConfig(proxySettings, `💦 WoW${proIndicator}- Best Ping 🚀`, false, true, true, false, true); + const xrayWoWBestPing = buildXrayConfig(proxySettings, `💦 WoW${proIndicator}- Best Ping 🚀`, false, true, true, false, true); xrayWoWBestPing.dns = dnsObject; xrayWoWBestPing.routing.rules = buildXrayRoutingRules(proxySettings, outboundDomains, true, true, false, true); xrayWoWBestPing.outbounds.unshift(...xrayWoWOutbounds, ...xrayWarpOutbounds); @@ -869,7 +878,7 @@ const xrayConfigTemp = { }, streamSettings: { sockopt: { - tcpKeepAliveIdle: 100, + tcpKeepAliveIdle: 30, tcpNoDelay: true }, }, diff --git a/src/helpers/helpers.js b/src/helpers/helpers.js index ddf1be127..a1b17563d 100644 --- a/src/helpers/helpers.js +++ b/src/helpers/helpers.js @@ -1,7 +1,7 @@ import { Authenticate } from "../authentication/auth"; import { getDataset, updateDataset } from "../kv/handlers"; -import { renderErrorPage } from "../pages/errorPage"; -import { renderHomePage } from "../pages/homePage"; +import { renderErrorPage } from "../pages/error"; +import { renderHomePage } from "../pages/home"; import { initializeParams, origin } from "./init"; export function isValidUUID(uuid) { diff --git a/src/kv/handlers.js b/src/kv/handlers.js index 42551a860..793956a39 100644 --- a/src/kv/handlers.js +++ b/src/kv/handlers.js @@ -2,7 +2,7 @@ import { fetchWarpConfigs } from '../protocols/warp'; import { isDomain, resolveDNS } from '../helpers/helpers'; import { initializeParams, panelVersion } from '../helpers/init'; import { Authenticate } from '../authentication/auth'; -import { renderErrorPage } from '../pages/errorPage'; +import { renderErrorPage } from '../pages/error'; export async function getDataset(request, env) { await initializeParams(request, env); @@ -132,7 +132,7 @@ export async function updateDataset (request, env) { function extractChainProxyParams(chainProxy) { let configParams = {}; if (!chainProxy) return {}; - let url = new URL(chainProxy); + const url = new URL(chainProxy); const protocol = url.protocol.slice(0, -1); if (protocol === 'vless') { const params = new URLSearchParams(url.search); diff --git a/src/pages/errorPage.js b/src/pages/error.js similarity index 100% rename from src/pages/errorPage.js rename to src/pages/error.js diff --git a/src/pages/homePage.js b/src/pages/home.js similarity index 99% rename from src/pages/homePage.js rename to src/pages/home.js index 81b7ac15f..39fd5fd0a 100644 --- a/src/pages/homePage.js +++ b/src/pages/home.js @@ -45,10 +45,10 @@ export async function renderHomePage (request, env, proxySettings, isPassSet) { } = proxySettings; const isWarpPlus = warpPlusLicense ? true : false; - let activeProtocols = (vlessConfigs ? 1 : 0) + (trojanConfigs ? 1 : 0); + const activeProtocols = (vlessConfigs ? 1 : 0) + (trojanConfigs ? 1 : 0); let httpPortsBlock = '', httpsPortsBlock = ''; const allPorts = [...(hostName.includes('workers.dev') ? defaultHttpPorts : []), ...defaultHttpsPorts]; - let regionNames = new Intl.DisplayNames(['en'], {type: 'region'}); + const regionNames = new Intl.DisplayNames(['en'], {type: 'region'}); const countryCode = request.cf.country; const flag = String.fromCodePoint(...[...countryCode].map(c => 0x1F1E6 + c.charCodeAt(0) - 65)); const cfCountry = `${regionNames.of(countryCode)} ${flag}`; diff --git a/src/pages/loginPage.js b/src/pages/login.js similarity index 100% rename from src/pages/loginPage.js rename to src/pages/login.js diff --git a/src/worker.js b/src/worker.js index a04408884..570097126 100644 --- a/src/worker.js +++ b/src/worker.js @@ -3,7 +3,7 @@ import { vlessOverWSHandler } from './protocols/vless'; import { trojanOverWSHandler } from './protocols/trojan'; import { updateWarpConfigs } from './kv/handlers'; import { logout, resetPassword, login } from './authentication/auth'; -import { renderErrorPage } from './pages/errorPage'; +import { renderErrorPage } from './pages/error'; import { getXrayCustomConfigs, getXrayWarpConfigs } from './cores-configs/xray'; import { getSingBoxCustomConfig, getSingBoxWarpConfig } from './cores-configs/sing-box'; import { getClashNormalConfig, getClashWarpConfig } from './cores-configs/clash';