diff --git a/dist/worker.js b/dist/worker.js index 5968adda..dfdba7bb 100644 --- a/dist/worker.js +++ b/dist/worker.js @@ -1,3 +1,9 @@ +/*! + * v2ray Subscription Worker v2.3 + * Copyright 2024 Vahid Farid (https://twitter.com/vahidfarid) + * Licensed under GPLv3 (https://github.com/vfarid/v2ray-worker/blob/main/Licence.md) + */ + var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; @@ -238,7 +244,7 @@ var require_bcrypt = __commonJS({ return hash2.substring(0, 29); }; var nextTick = typeof process !== "undefined" && process && typeof process.nextTick === "function" ? typeof setImmediate === "function" ? setImmediate : process.nextTick : setTimeout; - function stringToBytes(str2) { + function stringToBytes2(str2) { var out = [], i = 0; utfx.encodeUTF16toUTF8(function() { if (i >= str2.length) @@ -1830,7 +1836,7 @@ var require_bcrypt = __commonJS({ } var r1 = parseInt(salt.substring(offset, offset + 1), 10) * 10, r2 = parseInt(salt.substring(offset + 1, offset + 2), 10), rounds = r1 + r2, real_salt = salt.substring(offset + 3, offset + 25); s += minor >= "a" ? "\0" : ""; - var passwordb = stringToBytes(s), saltb = base64_decode(real_salt, BCRYPT_SALT_LEN); + var passwordb = stringToBytes2(s), saltb = base64_decode(real_salt, BCRYPT_SALT_LEN); function finish(bytes) { var res = []; res.push("$2"); @@ -3755,117 +3761,210 @@ import { connect } from "cloudflare:sockets"; // src/helpers.ts init_modules_watch_stub(); -function GetMultipleRandomElements(arr, num) { - let shuffled = arr.sort(() => 0.5 - Math.random()); - return shuffled.slice(0, num); + +// node_modules/uuid/dist/esm-browser/index.js +init_modules_watch_stub(); + +// node_modules/uuid/dist/esm-browser/stringify.js +init_modules_watch_stub(); + +// node_modules/uuid/dist/esm-browser/validate.js +init_modules_watch_stub(); + +// node_modules/uuid/dist/esm-browser/regex.js +init_modules_watch_stub(); +var regex_default = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i; + +// node_modules/uuid/dist/esm-browser/validate.js +function validate(uuid2) { + return typeof uuid2 === "string" && regex_default.test(uuid2); } -function IsIp(str2) { - try { - if (str2 == "" || str2 == void 0) - return false; - if (!/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])(\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])){2}\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-4])$/.test(str2)) { - return false; - } - let ls = str2.split("."); - if (ls == null || ls.length != 4 || ls[3] == "0" || parseInt(ls[3]) === 0) { - return false; - } - return true; - } catch (e) { - } - return false; +var validate_default = validate; + +// node_modules/uuid/dist/esm-browser/stringify.js +var byteToHex = []; +for (let i = 0; i < 256; ++i) { + byteToHex.push((i + 256).toString(16).slice(1)); } -function IsValidUUID(uuid2) { - return /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(uuid2); +function unsafeStringify(arr, offset = 0) { + return byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]; } -function GetVlessConfig(no, uuid2, sni, address, port) { - if (address.toLowerCase() == sni.toLowerCase()) { - address = sni; - } - return { - name: `${no}-vless-worker-${address}`, - type: "vless", - tls: true, - network: "ws", - port, - servername: sni, - uuid: uuid2, - fp: "randomized", - alpn: "h2,http/1.1", - host: sni, - "ws-opts": { - path: "vless-ws/?ed=2048", - headers: { - Host: sni + +// node_modules/uuid/dist/esm-browser/v35.js +init_modules_watch_stub(); + +// node_modules/uuid/dist/esm-browser/parse.js +init_modules_watch_stub(); +function parse(uuid2) { + if (!validate_default(uuid2)) { + throw TypeError("Invalid UUID"); + } + let v; + const arr = new Uint8Array(16); + arr[0] = (v = parseInt(uuid2.slice(0, 8), 16)) >>> 24; + arr[1] = v >>> 16 & 255; + arr[2] = v >>> 8 & 255; + arr[3] = v & 255; + arr[4] = (v = parseInt(uuid2.slice(9, 13), 16)) >>> 8; + arr[5] = v & 255; + arr[6] = (v = parseInt(uuid2.slice(14, 18), 16)) >>> 8; + arr[7] = v & 255; + arr[8] = (v = parseInt(uuid2.slice(19, 23), 16)) >>> 8; + arr[9] = v & 255; + arr[10] = (v = parseInt(uuid2.slice(24, 36), 16)) / 1099511627776 & 255; + arr[11] = v / 4294967296 & 255; + arr[12] = v >>> 24 & 255; + arr[13] = v >>> 16 & 255; + arr[14] = v >>> 8 & 255; + arr[15] = v & 255; + return arr; +} +var parse_default = parse; + +// node_modules/uuid/dist/esm-browser/v35.js +function stringToBytes(str2) { + str2 = unescape(encodeURIComponent(str2)); + const bytes = []; + for (let i = 0; i < str2.length; ++i) { + bytes.push(str2.charCodeAt(i)); + } + return bytes; +} +var DNS = "6ba7b810-9dad-11d1-80b4-00c04fd430c8"; +var URL2 = "6ba7b811-9dad-11d1-80b4-00c04fd430c8"; +function v35(name, version2, hashfunc) { + function generateUUID(value, namespace, buf, offset) { + var _namespace; + if (typeof value === "string") { + value = stringToBytes(value); + } + if (typeof namespace === "string") { + namespace = parse_default(namespace); + } + if (((_namespace = namespace) === null || _namespace === void 0 ? void 0 : _namespace.length) !== 16) { + throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)"); + } + let bytes = new Uint8Array(16 + value.length); + bytes.set(namespace); + bytes.set(value, namespace.length); + bytes = hashfunc(bytes); + bytes[6] = bytes[6] & 15 | version2; + bytes[8] = bytes[8] & 63 | 128; + if (buf) { + offset = offset || 0; + for (let i = 0; i < 16; ++i) { + buf[offset + i] = bytes[i]; } - }, - server: address, - path: "vless-ws/?ed=2048" - }; -} -function IsBase64(str2) { - return /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{4})$/.test(str2); -} -function RemoveDuplicateConfigs(configList) { - const seen = {}; - return configList.filter((conf) => { - const key = conf.name + conf.port + conf.server + (conf.uuid || conf.password); - if (!seen[key]) { - seen[key] = true; - return true; + return buf; } - return false; - }); -} -function AddNumberToConfigs(configList, start) { - const seen = {}; - return configList.map((conf, index) => { - conf.name = index + start + "-" + conf.name; - return conf; - }); -} -function GenerateToken(length = 32) { - const buffer = new Uint8Array(length); - for (let i = 0; i < length; i++) { - buffer[i] = Math.floor(Math.random() * 256); + return unsafeStringify(bytes); } - return Array.from(buffer).map((byte) => byte.toString(16).padStart(2, "0")).join(""); -} -function Delay(ms) { - return new Promise((resolve) => setTimeout(resolve, ms)); -} -function MuddleDomain(hostname) { - const parts = hostname.split("."); - const subdomain = parts.slice(0, parts.length - 2).join("."); - const domain = parts.slice(-2).join("."); - const muddledDomain = domain.split("").map( - (char) => Math.random() < 0.5 ? char.toLowerCase() : char.toUpperCase() - ).join(""); - return subdomain + "." + muddledDomain; + try { + generateUUID.name = name; + } catch (err) { + } + generateUUID.DNS = DNS; + generateUUID.URL = URL2; + return generateUUID; } +// node_modules/uuid/dist/esm-browser/v5.js +init_modules_watch_stub(); + +// node_modules/uuid/dist/esm-browser/sha1.js +init_modules_watch_stub(); +function f(s, x, y, z) { + switch (s) { + case 0: + return x & y ^ ~x & z; + case 1: + return x ^ y ^ z; + case 2: + return x & y ^ x & z ^ y & z; + case 3: + return x ^ y ^ z; + } +} +function ROTL(x, n) { + return x << n | x >>> 32 - n; +} +function sha1(bytes) { + const K = [1518500249, 1859775393, 2400959708, 3395469782]; + const H = [1732584193, 4023233417, 2562383102, 271733878, 3285377520]; + if (typeof bytes === "string") { + const msg = unescape(encodeURIComponent(bytes)); + bytes = []; + for (let i = 0; i < msg.length; ++i) { + bytes.push(msg.charCodeAt(i)); + } + } else if (!Array.isArray(bytes)) { + bytes = Array.prototype.slice.call(bytes); + } + bytes.push(128); + const l = bytes.length / 4 + 2; + const N = Math.ceil(l / 16); + const M = new Array(N); + for (let i = 0; i < N; ++i) { + const arr = new Uint32Array(16); + for (let j = 0; j < 16; ++j) { + arr[j] = bytes[i * 64 + j * 4] << 24 | bytes[i * 64 + j * 4 + 1] << 16 | bytes[i * 64 + j * 4 + 2] << 8 | bytes[i * 64 + j * 4 + 3]; + } + M[i] = arr; + } + M[N - 1][14] = (bytes.length - 1) * 8 / Math.pow(2, 32); + M[N - 1][14] = Math.floor(M[N - 1][14]); + M[N - 1][15] = (bytes.length - 1) * 8 & 4294967295; + for (let i = 0; i < N; ++i) { + const W = new Uint32Array(80); + for (let t = 0; t < 16; ++t) { + W[t] = M[i][t]; + } + for (let t = 16; t < 80; ++t) { + W[t] = ROTL(W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16], 1); + } + let a = H[0]; + let b = H[1]; + let c = H[2]; + let d = H[3]; + let e = H[4]; + for (let t = 0; t < 80; ++t) { + const s = Math.floor(t / 20); + const T = ROTL(a, 5) + f(s, b, c, d) + e + K[s] + W[t] >>> 0; + e = d; + d = c; + c = ROTL(b, 30) >>> 0; + b = a; + a = T; + } + H[0] = H[0] + a >>> 0; + H[1] = H[1] + b >>> 0; + H[2] = H[2] + c >>> 0; + H[3] = H[3] + d >>> 0; + H[4] = H[4] + e >>> 0; + } + return [H[0] >> 24 & 255, H[0] >> 16 & 255, H[0] >> 8 & 255, H[0] & 255, H[1] >> 24 & 255, H[1] >> 16 & 255, H[1] >> 8 & 255, H[1] & 255, H[2] >> 24 & 255, H[2] >> 16 & 255, H[2] >> 8 & 255, H[2] & 255, H[3] >> 24 & 255, H[3] >> 16 & 255, H[3] >> 8 & 255, H[3] & 255, H[4] >> 24 & 255, H[4] >> 16 & 255, H[4] >> 8 & 255, H[4] & 255]; +} +var sha1_default = sha1; + +// node_modules/uuid/dist/esm-browser/v5.js +var v5 = v35("v5", 80, sha1_default); +var v5_default = v5; + // src/variables.ts init_modules_watch_stub(); -var defaultProviders = [ - "https://raw.githubusercontent.com/mahdibland/V2RayAggregator/master/sub/list/00.txt", - "https://raw.githubusercontent.com/sashalsk/V2Ray/main/V2Config_64base", - "https://raw.githubusercontent.com/Leon406/SubCrawler/master/sub/share/vless", - "https://raw.githubusercontent.com/mfuu/v2ray/master/clash.yaml", - "https://raw.githubusercontent.com/peasoft/NoMoreWalls/master/list.yml", - "https://raw.githubusercontent.com/a2470982985/getNode/main/clash.yaml", - "https://raw.githubusercontent.com/mlabalabala/v2ray-node/main/nodefree4clash.txt", - "https://raw.githubusercontent.com/mahdibland/V2RayAggregator/master/sub/sub_merge.txt", - "https://raw.githubusercontent.com/mfuu/v2ray/master/v2ray" -]; +var version = "2.3"; var defaultProtocols = [ "vmess", - "vless" + "built-in-vless" ]; var defaultALPNList = [ + "h3,h2,http/1.1", + "h3,h2,http/1.1", + "h3,h2,http/1.1", + "h3,h2", "h2,http/1.1", "h2", - "http/1.1", - "h2,http/1.1" + "http/1.1" ]; var defaultPFList = [ "chrome", @@ -3888,17 +3987,17 @@ var cfPorts = [ 2096, 8443 ]; -var supportedCiphers = [ - "none", - "auto", - "plain", - "aes-128-cfb", - "aes-192-cfb", - "aes-256-cfb", - "rc4-md5", - "chacha20-ietf", - "xchacha20", - "chacha20-ietf-poly1305" +var fragmentsLengthList = [ + "10-20", + "10-50", + "20-50", + "30-80", + "50-100" +]; +var fragmentsIntervalList = [ + "10-20", + "10-50", + "20-50" ]; var defaultClashConfig = { port: 7890, @@ -3934,35 +4033,113 @@ var defaultClashConfig = { ] }; +// src/helpers.ts +function GetMultipleRandomElements(arr, num) { + let shuffled = arr.sort(() => 0.5 - Math.random()); + return shuffled.slice(0, num); +} +function IsIp(str2) { + try { + if (str2 == "" || str2 == void 0) + return false; + if (!/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])(\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])){2}\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-4])$/.test(str2)) { + return false; + } + let ls = str2.split("."); + if (ls == null || ls.length != 4 || ls[3] == "0" || parseInt(ls[3]) === 0) { + return false; + } + return true; + } catch (e) { + } + return false; +} +function IsValidUUID(uuid2) { + return /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(uuid2); +} +function GetVlessConfig(no, uuid2, sni, address, port) { + if (address.toLowerCase() == sni.toLowerCase()) { + address = sni; + } + return { + remarks: `${no}-vless-worker-${address}`, + configType: "vless", + security: "tls", + tls: "tls", + network: "ws", + port, + sni, + uuid: uuid2, + host: sni, + path: "vless-ws/?ed=2048", + address + }; +} +function IsBase64(str2) { + return /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{4})$/.test(str2); +} +function RemoveDuplicateConfigs(configList) { + const seen = {}; + return configList.filter((conf) => { + const key = conf.remarks + conf.port + conf.address + conf.uuid; + if (!seen[key]) { + seen[key] = true; + return true; + } + return false; + }); +} +function AddNumberToConfigs(configList, start) { + const seen = {}; + return configList.map((conf, index) => { + conf.remarks = index + start + "-" + conf.remarks; + return conf; + }); +} +function GenerateToken(length = 32) { + const buffer = new Uint8Array(length); + for (let i = 0; i < length; i++) { + buffer[i] = Math.floor(Math.random() * 256); + } + return Array.from(buffer).map((byte) => byte.toString(16).padStart(2, "0")).join(""); +} +function Delay(ms) { + return new Promise((resolve) => setTimeout(resolve, ms)); +} +function MuddleDomain(hostname) { + const parts = hostname.split("."); + const subdomain = parts.slice(0, parts.length - 2).join("."); + const domain = parts.slice(-2).join("."); + const muddledDomain = domain.split("").map( + (char) => Math.random() < 0.5 ? char.toLowerCase() : char.toUpperCase() + ).join(""); + return subdomain + "." + muddledDomain; +} +function getUUID(sni) { + return v5_default(sni.toLowerCase(), "ebc4a168-a6fe-47ce-bc25-6183c6212dcc"); +} + // src/vless.ts var WS_READY_STATE_OPEN = 1; var WS_READY_STATE_CLOSING = 2; var uuid = ""; var proxyIP = ""; async function GetVlessConfigList(sni, addressList, max, env) { - let uuid2 = await env.settings.get("UUID"); + uuid = getUUID(sni); let configList = []; - if (uuid2) { - for (let i = 0; i < max; i++) { - configList.push(GetVlessConfig( - i + 1, - uuid2, - MuddleDomain(sni), - addressList[Math.floor(Math.random() * addressList.length)], - cfPorts[Math.floor(Math.random() * cfPorts.length)] - )); - } + for (let i = 0; i < max; i++) { + configList.push(GetVlessConfig( + i + 1, + uuid, + MuddleDomain(sni), + addressList[Math.floor(Math.random() * addressList.length)], + cfPorts[Math.floor(Math.random() * cfPorts.length)] + )); } return configList; } -async function VlessOverWSHandler(request, env) { - uuid = uuid || await env.settings.get("UUID") || ""; - if (!proxyIP) { - let proxyIPList = (await env.settings.get("ProxyIPs"))?.split("\n") || []; - if (proxyIPList.length) { - proxyIP = proxyIPList[Math.floor(Math.random() * proxyIPList.length)]; - } - } +async function VlessOverWSHandler(request, sni, env) { + uuid = getUUID(sni); const [client, webSocket] = Object.values(new WebSocketPair()); webSocket.accept(); let address = ""; @@ -4008,12 +4185,12 @@ async function VlessOverWSHandler(request, env) { const vlessResponseHeader = new Uint8Array([vlessVersion[0], 0]); const rawClientData = chunk.slice(rawDataIndex); if (isDns) { - const { write } = await HandleUDPOutbound(webSocket, vlessResponseHeader); + const { write } = await HandleUDPOutbound(webSocket, vlessResponseHeader, env); udpStreamWrite = write; udpStreamWrite(rawClientData); return; } - HandleTCPOutbound(remoteSocketWapper, addressRemote, portRemote, rawClientData, webSocket, vlessResponseHeader); + HandleTCPOutbound(remoteSocketWapper, addressRemote, portRemote, rawClientData, webSocket, vlessResponseHeader, env); } })).catch((err) => { }); @@ -4067,7 +4244,7 @@ function ProcessVlessHeader(vlessBuffer, uuid2) { message: "Invalid data" }; } - const version = new Uint8Array(vlessBuffer.slice(0, 1)); + const version2 = new Uint8Array(vlessBuffer.slice(0, 1)); let isValidUser = false; let isUDP = false; if (Stringify(new Uint8Array(vlessBuffer.slice(1, 17))) === uuid2) { @@ -4148,11 +4325,11 @@ function ProcessVlessHeader(vlessBuffer, uuid2) { addressType, portRemote, rawDataIndex: addressValueIndex + addressLength, - vlessVersion: version, + vlessVersion: version2, isUDP }; } -async function HandleUDPOutbound(webSocket, vlessResponseHeader) { +async function HandleUDPOutbound(webSocket, vlessResponseHeader, env) { let isVlessHeaderSent = false; const transformStream = new TransformStream({ transform(chunk, controller) { @@ -4167,9 +4344,10 @@ async function HandleUDPOutbound(webSocket, vlessResponseHeader) { } } }); + const blockPorn = await env.settings.get("BlockPorn"); transformStream.readable.pipeTo(new WritableStream({ async write(chunk) { - const resp = await fetch("https://1.1.1.1/dns-query", { + const resp = await fetch(blockPorn == "yes" ? "https://1.1.1.3/dns-query" : "https://1.1.1.1/dns-query", { method: "POST", headers: { "content-type": "application/dns-message" @@ -4197,7 +4375,8 @@ async function HandleUDPOutbound(webSocket, vlessResponseHeader) { } }; } -async function HandleTCPOutbound(remoteSocket, addressRemote, portRemote, rawClientData, webSocket, vlessResponseHeader) { +async function HandleTCPOutbound(remoteSocket, addressRemote, portRemote, rawClientData, webSocket, vlessResponseHeader, env) { + let retryCount = 2; async function connectAndWrite(address, port) { const socketAddress = { hostname: address, @@ -4215,6 +4394,10 @@ async function HandleTCPOutbound(remoteSocket, addressRemote, portRemote, rawCli return tcpSocket2; } async function retry() { + const proxyList = (await env.settings.get("Proxies"))?.split("\n").filter((t) => t.trim().length > 0) || []; + if (proxyList.length) { + proxyIP = proxyList[Math.floor(Math.random() * proxyList.length)]; + } const tcpSocket2 = await connectAndWrite(proxyIP || addressRemote, portRemote); tcpSocket2.closed.catch((error) => { }).finally(() => { @@ -4283,7 +4466,7 @@ function Base64ToArrayBuffer(base64Str) { } } function IsValidVlessUUID(uuid2) { - return /^[0-9a-f]{8}-[0-9a-f]{4}-[4][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(uuid2); + return /^[0-9a-f]{8}-[0-9a-f]{4}-[5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(uuid2); } function Stringify(arr, offset = 0) { const uuid2 = UnsafeStringify(arr, offset); @@ -4292,76 +4475,17 @@ function Stringify(arr, offset = 0) { } return uuid2; } -var byteToHex = []; +var byteToHex2 = []; for (let i = 0; i < 256; ++i) { - byteToHex.push((i + 256).toString(16).slice(1)); + byteToHex2.push((i + 256).toString(16).slice(1)); } function UnsafeStringify(arr, offset = 0) { - return `${byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]]}-${byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]]}-${byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]]}-${byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]]}-${byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]}`.toLowerCase(); + return `${byteToHex2[arr[offset + 0]] + byteToHex2[arr[offset + 1]] + byteToHex2[arr[offset + 2]] + byteToHex2[arr[offset + 3]]}-${byteToHex2[arr[offset + 4]] + byteToHex2[arr[offset + 5]]}-${byteToHex2[arr[offset + 6]] + byteToHex2[arr[offset + 7]]}-${byteToHex2[arr[offset + 8]] + byteToHex2[arr[offset + 9]]}-${byteToHex2[arr[offset + 10]] + byteToHex2[arr[offset + 11]] + byteToHex2[arr[offset + 12]] + byteToHex2[arr[offset + 13]] + byteToHex2[arr[offset + 14]] + byteToHex2[arr[offset + 15]]}`.toLowerCase(); } // src/panel.ts init_modules_watch_stub(); var bcrypt = __toESM(require_bcrypt()); - -// node_modules/uuid/dist/esm-browser/index.js -init_modules_watch_stub(); - -// node_modules/uuid/dist/esm-browser/rng.js -init_modules_watch_stub(); -var getRandomValues; -var rnds8 = new Uint8Array(16); -function rng() { - if (!getRandomValues) { - getRandomValues = typeof crypto !== "undefined" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto); - if (!getRandomValues) { - throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported"); - } - } - return getRandomValues(rnds8); -} - -// node_modules/uuid/dist/esm-browser/stringify.js -init_modules_watch_stub(); -var byteToHex2 = []; -for (let i = 0; i < 256; ++i) { - byteToHex2.push((i + 256).toString(16).slice(1)); -} -function unsafeStringify(arr, offset = 0) { - return byteToHex2[arr[offset + 0]] + byteToHex2[arr[offset + 1]] + byteToHex2[arr[offset + 2]] + byteToHex2[arr[offset + 3]] + "-" + byteToHex2[arr[offset + 4]] + byteToHex2[arr[offset + 5]] + "-" + byteToHex2[arr[offset + 6]] + byteToHex2[arr[offset + 7]] + "-" + byteToHex2[arr[offset + 8]] + byteToHex2[arr[offset + 9]] + "-" + byteToHex2[arr[offset + 10]] + byteToHex2[arr[offset + 11]] + byteToHex2[arr[offset + 12]] + byteToHex2[arr[offset + 13]] + byteToHex2[arr[offset + 14]] + byteToHex2[arr[offset + 15]]; -} - -// node_modules/uuid/dist/esm-browser/v4.js -init_modules_watch_stub(); - -// node_modules/uuid/dist/esm-browser/native.js -init_modules_watch_stub(); -var randomUUID = typeof crypto !== "undefined" && crypto.randomUUID && crypto.randomUUID.bind(crypto); -var native_default = { - randomUUID -}; - -// node_modules/uuid/dist/esm-browser/v4.js -function v4(options, buf, offset) { - if (native_default.randomUUID && !buf && !options) { - return native_default.randomUUID(); - } - options = options || {}; - const rnds = options.random || (options.rng || rng)(); - rnds[6] = rnds[6] & 15 | 64; - rnds[8] = rnds[8] & 63 | 128; - if (buf) { - offset = offset || 0; - for (let i = 0; i < 16; ++i) { - buf[offset + i] = rnds[i]; - } - return buf; - } - return unsafeStringify(rnds); -} -var v4_default = v4; - -// src/panel.ts async function GetPanel(request, env) { const url = new URL(request.url); try { @@ -4370,26 +4494,29 @@ async function GetPanel(request, env) { if (hash2 && url.searchParams.get("token") != token) { return Response.redirect(`${url.protocol}//${url.hostname}${url.port != "443" ? ":" + url.port : ""}/login`, 302); } + const settingsVersion = await env.settings.get("Version") || "2.0"; + if (settingsVersion != version) { + await env.settings.delete("Providers"); + await env.settings.delete("Protocols"); + } const maxConfigs = parseInt(await env.settings.get("MaxConfigs") || "200"); - const protocols = (await env.settings.get("Protocols"))?.split("\n") || defaultProtocols; - const alpnList = (await env.settings.get("ALPNs"))?.split("\n") || defaultALPNList; - const fingerPrints = (await env.settings.get("FingerPrints"))?.split("\n") || defaultPFList; - const providers = (await env.settings.get("Providers"))?.split("\n") || defaultProviders; - const cleanDomainIPs = (await env.settings.get("CleanDomainIPs"))?.split("\n") || []; - const configs = (await env.settings.get("Configs"))?.split("\n") || []; + const protocols = (await env.settings.get("Protocols"))?.split("\n").filter((t) => t.trim().length > 0) || defaultProtocols; + const alpnList = (await env.settings.get("ALPNs"))?.split("\n").filter((t) => t.trim().length > 0) || []; + const fingerPrints = (await env.settings.get("FingerPrints"))?.split("\n").filter((t) => t.trim().length > 0) || []; + const cleanDomainIPs = (await env.settings.get("CleanDomainIPs"))?.split("\n").filter((t) => t.trim().length > 0) || []; + const configs = (await env.settings.get("Configs"))?.split("\n").filter((t) => t.trim().length > 0) || []; const includeOriginalConfigs = await env.settings.get("IncludeOriginalConfigs") || "yes"; const includeMergedConfigs = await env.settings.get("IncludeMergedConfigs") || "yes"; - var uuid2 = await env.settings.get("UUID") || ""; - if (!IsValidUUID(uuid2)) { - uuid2 = v4_default(); - await env.settings.put("UUID", uuid2); - } + const enableFragments = await env.settings.get("EnableFragments") || "yes"; + const blockPorn = await env.settings.get("BlockPorn") || "no"; + const providers = (await env.settings.get("Providers"))?.split("\n").filter((t) => t.trim().length > 0) || []; + const proxies = (await env.settings.get("ManualProxies"))?.split("\n").filter((t) => t.trim().length > 0) || []; var htmlMessage = ""; const message = url.searchParams.get("message"); if (message == "success") { - htmlMessage = `
Settings saved successfully. / \u062A\u0646\u0638\u06CC\u0645\u0627\u062A \u0628\u0627 \u0645\u0648\u0641\u0642\u06CC\u062A \u0630\u062E\u06CC\u0631\u0647 \u0634\u062F.
`; + htmlMessage = `
Settings saved successfully.
\u062A\u0646\u0638\u06CC\u0645\u0627\u062A \u0628\u0627 \u0645\u0648\u0641\u0642\u06CC\u062A \u0630\u062E\u06CC\u0631\u0647 \u0634\u062F.
`; } else if (message == "error") { - htmlMessage = `
Failed to save settings! / \u062E\u0637\u0627 \u062F\u0631 \u0630\u062E\u06CC\u0631\u0647\u200C\u06CC \u062A\u0646\u0638\u06CC\u0645\u0627\u062A!
`; + htmlMessage = `
Failed to save settings!
\u062E\u0637\u0627 \u062F\u0631 \u0630\u062E\u06CC\u0631\u0647\u200C\u06CC \u062A\u0646\u0638\u06CC\u0645\u0627\u062A!
`; } var passwordSection = ""; if (hash2) { @@ -4400,7 +4527,10 @@ async function GetPanel(request, env) { `; } else { passwordSection = ` -
+
+ +
+
@@ -4421,100 +4551,275 @@ async function GetPanel(request, env) { +