mirror of
https://github.com/lush2020/edgetunnel.git
synced 2026-03-21 17:12:33 +08:00
配置页添加动态UUID到期时间
This commit is contained in:
51
_worker.js
51
_worker.js
@@ -80,6 +80,7 @@ let httpsPorts = ["2053","2083","2087","2096","8443"];
|
||||
let effectiveTime = 7;//有效时间 单位:天
|
||||
let updateTime = 3;//更新时间
|
||||
let userIDLow;
|
||||
let userIDTime = "";
|
||||
export default {
|
||||
/**
|
||||
* @param {import("@cloudflare/workers-types").Request} request
|
||||
@@ -104,6 +105,7 @@ export default {
|
||||
const userIDs = await generateDynamicUUID(env.KEY);
|
||||
userID = userIDs[0];
|
||||
userIDLow = userIDs[1];
|
||||
userIDTime = userIDs[2];
|
||||
//console.log(`启用动态UUID\n秘钥KEY: ${env.KEY}\nUUIDNow: ${userID}\nUUIDLow: ${userIDLow}`);
|
||||
effectiveTime = env.TIME || effectiveTime;
|
||||
updateTime = env.UPTIME || updateTime;
|
||||
@@ -1412,7 +1414,7 @@ async function getVLESSConfig(userID, hostName, sub, UA, RproxyIP, _url, env) {
|
||||
|
||||
if (env.KEY && _url.pathname !== `/${env.KEY}`) 订阅器 = '';
|
||||
else 订阅器 += `\nSUBAPI(订阅转换后端): ${subProtocol}://${subconverter}\nSUBCONFIG(订阅转换配置文件): ${subconfig}`;
|
||||
const 动态UUID = (uuid != userID) ? `TOKEN: ${uuid}\nUUIDNow: ${userID}\nUUIDLow: ${userIDLow}\nTIME(动态UUID有效时间): ${effectiveTime} 天\nUPTIME(动态UUID更新时间): ${updateTime} 时(北京时间)\n\n` : "";
|
||||
const 动态UUID = (uuid != userID) ? `TOKEN: ${uuid}\nUUIDNow: ${userID}\nUUIDLow: ${userIDLow}\n${userIDTime}TIME(动态UUID有效时间): ${effectiveTime} 天\nUPTIME(动态UUID更新时间): ${updateTime} 时(北京时间)\n\n` : `${userIDTime}`;
|
||||
return `
|
||||
################################################################
|
||||
Subscribe / sub 订阅地址, 支持 Base64、clash-meta、sing-box 订阅格式
|
||||
@@ -1924,26 +1926,19 @@ function isValidIPv4(address) {
|
||||
}
|
||||
|
||||
function generateDynamicUUID(key) {
|
||||
// 获取当前时间是当年的第几周(以北京时间凌晨3点为界)
|
||||
function getWeekOfYear() {
|
||||
const now = new Date();
|
||||
const timezoneOffset = 8; // 北京时间相对于UTC的时区偏移+8小时
|
||||
const adjustedNow = new Date(now.getTime() + timezoneOffset * 60 * 60 * 1000);
|
||||
const start = new Date(2007, 6, 7, 3, 0, 0); // 固定起始日期为2007年7月7日的凌晨3点
|
||||
|
||||
// 计算当前时间与今年1月1日凌晨3点的差距
|
||||
const diff = adjustedNow - start;
|
||||
|
||||
// 一周的毫秒数(7天)
|
||||
const oneWeek = 1000 * 60 * 60 * 24 * effectiveTime;
|
||||
|
||||
// 返回当前是第几周,向上取整
|
||||
return [Math.ceil(diff / oneWeek), Math.ceil((diff / oneWeek)- 1)];
|
||||
}
|
||||
|
||||
const passwdTimes = getWeekOfYear(); // 获取当前周数并存储
|
||||
const passwdTime = passwdTimes[0];
|
||||
const passwdTimeLow = passwdTimes[1];
|
||||
function getWeekOfYear() {
|
||||
const now = new Date();
|
||||
const timezoneOffset = 8; // 北京时间相对于UTC的时区偏移+8小时
|
||||
const adjustedNow = new Date(now.getTime() + timezoneOffset * 60 * 60 * 1000);
|
||||
const start = new Date(2007, 6, 7, updateTime, 0, 0); // 固定起始日期为2007年7月7日的凌晨3点
|
||||
const diff = adjustedNow - start;
|
||||
const oneWeek = 1000 * 60 * 60 * 24 * effectiveTime;
|
||||
return Math.ceil(diff / oneWeek);
|
||||
}
|
||||
|
||||
const passwdTime = getWeekOfYear(); // 获取当前周数
|
||||
const endTime = new Date(2007, 6, 7, updateTime, 0, 0); // 固定起始日期
|
||||
endTime.setMilliseconds(endTime.getMilliseconds() + passwdTime * 1000 * 60 * 60 * 24 * effectiveTime);
|
||||
|
||||
// 生成 UUID 的辅助函数
|
||||
function generateUUID(baseString) {
|
||||
@@ -1955,10 +1950,14 @@ function generateDynamicUUID(key) {
|
||||
return uuid;
|
||||
});
|
||||
}
|
||||
|
||||
// 生成两个 UUID
|
||||
const currentUUIDPromise = generateUUID(key + passwdTime);
|
||||
const previousUUIDPromise = generateUUID(key + (passwdTime - 1));
|
||||
|
||||
// 生成两个 UUID
|
||||
const currentUUIDPromise = generateUUID(key + passwdTime);
|
||||
const previousUUIDPromise = generateUUID(key + passwdTimeLow);
|
||||
|
||||
return Promise.all([currentUUIDPromise, previousUUIDPromise]);
|
||||
// 格式化到期时间
|
||||
const expirationDateUTC = new Date(endTime.getTime() - 8 * 60 * 60 * 1000); // UTC时间
|
||||
const expirationDateString = `到期时间(UTC): ${expirationDateUTC.toISOString().slice(0, 19).replace('T', ' ')} (UTC+8): ${endTime.toISOString().slice(0, 19).replace('T', ' ')}\n`;
|
||||
|
||||
return Promise.all([currentUUIDPromise, previousUUIDPromise, expirationDateString]);
|
||||
}
|
||||
Reference in New Issue
Block a user