diff --git a/_worker.js b/_worker.js index 47f06a893a..f60e5714c2 100644 --- a/_worker.js +++ b/_worker.js @@ -25,8 +25,8 @@ let parsedSocks5Address = {}; let enableSocks = false; // 虚假uuid和hostname,用于发送给配置生成服务 -let fakeUserID = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"; -let fakeHostName = "EXAMPLE.COM"; +let fakeUserID = generateUUID(); +let fakeHostName = generateRandomString(); export default { /** @@ -67,10 +67,15 @@ export default { return new Response(JSON.stringify(request.cf), { status: 200 }); case `/${userID}`: { const vlessConfig = await getVLESSConfig(userID, request.headers.get('Host'), sub, userAgent, RproxyIP); + const now = Date.now(); + const timestamp = Math.floor(now / 1000); + const today = new Date(now); + today.setHours(0, 0, 0, 0); return new Response(`${vlessConfig}`, { status: 200, headers: { "Content-Type": "text/plain;charset=utf-8", + "Subscription-Userinfo": `upload=0; download=${Math.floor(((now - today.getTime())/86400000) * 24 * 1099511627776)}; total=${24 * 1099511627776}; expire=${timestamp}`, } }); } @@ -790,6 +795,37 @@ function revertFakeInfo(content, userID, hostName, isBase64) { return content; } +function generateRandomNumber() { + let minNum = 100000; + let maxNum = 999999; + return Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum; +} + +function generateRandomString() { + let minLength = 2; + let maxLength = 3; + let length = Math.floor(Math.random() * (maxLength - minLength + 1)) + minLength; + let characters = 'abcdefghijklmnopqrstuvwxyz'; + let result = ''; + for (let i = 0; i < length; i++) { + result += characters[Math.floor(Math.random() * characters.length)]; + } + return result; +} + +function generateUUID() { + let uuid = ''; + for (let i = 0; i < 32; i++) { + let num = Math.floor(Math.random() * 16); + if (num < 10) { + uuid += num; + } else { + uuid += String.fromCharCode(num + 55); + } + } + return uuid.replace(/(.{8})(.{4})(.{4})(.{4})(.{12})/, '$1-$2-$3-$4-$5').toLowerCase(); +} + /** * @param {string} userID * @param {string | null} hostName @@ -874,7 +910,11 @@ async function getVLESSConfig(userID, hostName, sub, userAgent, RproxyIP) { return 'Error: fetch is not available in this environment.'; } // 如果是使用默认域名,则改成一个workers的域名,订阅器会加上代理 - if (hostName.includes(".workers.dev") || hostName.includes(".pages.dev")) fakeHostName = "EXAMPLE.workers.dev"; + if (hostName.includes(".workers.dev") || hostName.includes(".pages.dev")){ + fakeHostName = `${fakeHostName}.${generateRandomString()}${generateRandomNumber()}.workers.dev`; + } else { + fakeHostName = `${fakeHostName}.${generateRandomNumber()}.xyz` + } let content = ""; let url = ""; let isBase64 = false;