Skip to content

Commit

Permalink
Update _worker.js
Browse files Browse the repository at this point in the history
  • Loading branch information
cmliu authored Mar 7, 2024
1 parent 02e4939 commit daa9a51
Showing 1 changed file with 43 additions and 3 deletions.
46 changes: 43 additions & 3 deletions _worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand Down Expand Up @@ -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}`,
}
});
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit daa9a51

Please sign in to comment.