Merge pull request #872 from cmliu/beta2.0

Beta2.0
This commit is contained in:
CMLiussss
2025-12-12 17:56:27 +08:00
committed by GitHub
2 changed files with 72 additions and 49 deletions

View File

@@ -118,11 +118,11 @@
|--------|---------|-|-----|
| ADMIN | `123456` |✅| 面板登录密码 |
| KEY | `CMLiussss` |❌| 快速订阅密钥,访问`/CMLiussss`即可快读订阅。 |
| HOST | `edt-pages.github.io` |❌| 强制固定伪装域名 |
| HOST | `edt-pages.github.io` |❌| 强制固定伪装域名(支持多元素,使用`换行符``,`做间隔) |
| UUID | `90cd4a77-141a-43c9-991b-08263cfe9c10` |❌| 强制固定UUID |
| PATH | `/` |❌| 强制固定路径 |
| PROXYIP | `proxyip.cmliussss.net:443` |❌| 更换默认内置PROXYIP |
| URL | `https://blog.cmliussss.com` |❌| 主页反代伪装(乱设容易触发反诈,反代被墙的网站会加速域名被墙) |
| URL | `https://cloudflare-error-page-3th.pages.dev` |❌| 主页反代伪装(乱设容易触发反诈,反代被墙的网站会加速域名被墙) |
| GO2SOCKS5 | `blog.cmliussss.com`,`*.ip111.cn`,`*google.com` |❌| 设置`SOCKS5``HTTP`变量之后可设置强制使用socks5访问名单(设置为`*`可作为全局代理) |
## 🔧 实用技巧
@@ -184,4 +184,5 @@
- [白嫖哥](https://t.me/bestcfipas)
- [Mingyu](https://github.com/ymyuuu/workers-vless)
- [Alexandre Kojève](https://t.me/Enkelte_notif/784)stallTCP v1.3
- [eooce](https://github.com/eooce/Cloudflare-proxy)
- [eooce](https://github.com/eooce/Cloudflare-proxy)
- [Sukka](https://ip.skk.moe/)

View File

@@ -8,13 +8,14 @@ export default {
const url = new URL(request.url);
const UA = request.headers.get('User-Agent') || 'null';
const upgradeHeader = request.headers.get('Upgrade');
const 管理员密码 = env.ADMIN || env.admin || env.PASSWORD || env.password || env.pswd || env.TOKEN || env.KEY;
const 管理员密码 = env.ADMIN || env.admin || env.PASSWORD || env.password || env.pswd || env.TOKEN || env.KEY || env.UUID || env.uuid;
const 加密秘钥 = env.KEY || '勿动此默认密钥有需求请自行通过添加变量KEY进行修改';
const userIDMD5 = await MD5MD5(管理员密码 + 加密秘钥);
const uuidRegex = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/;
const envUUID = env.UUID || env.uuid;
const userID = (envUUID && uuidRegex.test(envUUID)) ? envUUID.toLowerCase() : [userIDMD5.slice(0, 8), userIDMD5.slice(8, 12), '4' + userIDMD5.slice(13, 16), '8' + userIDMD5.slice(17, 20), userIDMD5.slice(20)].join('-');
const host = env.HOST ? env.HOST.toLowerCase().replace(/^https?:\/\//, '').split('/')[0].split(':')[0] : url.hostname;
const hosts = env.HOST ? (await 整理成数组(env.HOST)).map(h => h.toLowerCase().replace(/^https?:\/\//, '').split('/')[0].split(':')[0]) : [url.hostname];
const host = hosts[0];
if (env.PROXYIP) {
const proxyIPs = await 整理成数组(env.PROXYIP);
反代IP = proxyIPs[Math.floor(Math.random() * proxyIPs.length)];
@@ -229,53 +230,68 @@ export default {
if (订阅类型 === 'mixed') {
const 节点路径 = config_JSON.启用0RTT ? config_JSON.PATH + '?ed=2560' : config_JSON.PATH;
const TLS分片参数 = config_JSON.TLS分片 == 'Shadowrocket' ? `&fragment=${encodeURIComponent('1,40-60,30-50,tlshello')}` : config_JSON.TLS分片 == 'Happ' ? `&fragment=${encodeURIComponent('3,1,tlshello')}` : '';
const 完整优选列表 = config_JSON.优选订阅生成.本地IP库.随机IP ? (await 生成随机IP(request, config_JSON.优选订阅生成.本地IP库.随机数量, config_JSON.优选订阅生成.本地IP库.指定端口))[0] : await env.KV.get('ADD.txt') ? await 整理成数组(await env.KV.get('ADD.txt')) : (await 生成随机IP(request, config_JSON.优选订阅生成.本地IP库.随机数量, config_JSON.优选订阅生成.本地IP库.指定端口))[0];
const 优选API = [], 优选IP = [], 其他节点 = [];
for (const 元素 of 完整优选列表) {
if (元素.toLowerCase().startsWith('https://')) 优选API.push(元素);
else if (元素.toLowerCase().includes('://')) 其他节点.push(元素);
else 优选IP.push(元素);
}
const 其他节点LINK = 其他节点.join('\n') + '\n';
let 完整优选IP = [], 其他节点LINK = '';
if (!url.searchParams.has('sub') && config_JSON.优选订阅生成.local) { // 本地生成订阅
const 完整优选列表 = config_JSON.优选订阅生成.本地IP库.随机IP ? (await 生成随机IP(request, config_JSON.优选订阅生成.本地IP库.随机数量, config_JSON.优选订阅生成.本地IP库.指定端口))[0] : await env.KV.get('ADD.txt') ? await 整理成数组(await env.KV.get('ADD.txt')) : (await 生成随机IP(request, config_JSON.优选订阅生成.本地IP库.随机数量, config_JSON.优选订阅生成.本地IP库.指定端口))[0];
const 优选API = [], 优选IP = [], 其他节点 = [];
for (const 元素 of 完整优选列表) {
if (元素.toLowerCase().startsWith('https://')) 优选API.push(元素);
else if (元素.toLowerCase().includes('://')) 其他节点.push(元素);
else 优选IP.push(元素);
}
其他节点LINK = 其他节点.join('\n') + '\n';
const 优选API的IP = await 请求优选API(优选API);
const 完整优选IP = [...new Set(优选IP.concat(优选API的IP))];
订阅内容 = 完整优选IP.map(原始地址 => {
// 统一正则: 匹配 域名/IPv4/IPv6地址 + 可选端口 + 可选备注
// 示例:
// - 域名: hj.xmm1993.top:2096#备注 或 example.com
// - IPv4: 166.0.188.128:443#Los Angeles 或 166.0.188.128
// - IPv6: [2606:4700::]:443#CMCC 或 [2606:4700::]
const regex = /^(\[[\da-fA-F:]+\]|[\d.]+|[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?)*)(?::(\d+))?(?:#(.+))?$/;
const match = 原始地址.match(regex);
let 节点地址, 节点端口 = "443", 节点备注;
if (match) {
节点地址 = match[1]; // IP地址或域名(可能带方括号)
节点端口 = match[2] || "443"; // 端口,默认443
节点备注 = match[3] || 节点地址; // 备注,默认为地址本身
} else {
// 不规范的格式跳过处理返回null
console.warn(`[订阅内容] 不规范的IP格式已忽略: ${原始地址}`);
return null;
}
const 节点HOST = 随机替换通配符(host);
return `${协议类型}://${config_JSON.UUID}@${节点地址}:${节点端口}?security=tls&type=${config_JSON.传输协议}&host=${节点HOST}&sni=${节点HOST}&path=${encodeURIComponent(config_JSON.随机路径 ? 随机路径() + 节点路径 : 节点路径) + TLS分片参数}&encryption=none${config_JSON.跳过证书验证 ? '&allowInsecure=1' : ''}#${encodeURIComponent(节点备注)}`;
}).filter(item => item !== null).join('\n');
订阅内容 = btoa(其他节点LINK + 订阅内容);
完整优选IP = [...new Set(优选IP.concat(优选API的IP))];
} else { // 优选订阅生成器
let 优选订阅生成器HOST = url.searchParams.get('sub') || config_JSON.优选订阅生成.SUB;
优选订阅生成器HOST = 优选订阅生成器HOST && !/^https?:\/\//i.test(优选订阅生成器HOST) ? `https://${优选订阅生成器HOST}` : 优选订阅生成器HOST;
const 优选订阅生成器URL = `${优选订阅生成器HOST}/sub?host=example.com&${协议类型 === ('v' + 'le' + 'ss') ? 'uuid' : 'pw'}=00000000-0000-4000-8000-000000000000&path=${encodeURIComponent(config_JSON.随机路径 ? 随机路径() + 节点路径 : 节点路径) + TLS分片参数}&type=${config_JSON.传输协议}`;
const 优选订阅生成器URL = `${优选订阅生成器HOST}/sub?host=example.com&uuid=00000000-0000-4000-8000-000000000000`;
try {
const response = await fetch(优选订阅生成器URL, { headers: { 'User-Agent': 'v2rayN/edge' + 'tunnel (https://github.com/cmliu/edge' + 'tunnel)' } });
if (response.ok) 订阅内容 = btoa(其他节点LINK + atob(await response.text()));
else return new Response('优选订阅生成器异常:' + response.statusText, { status: response.status });
if (!response.ok) return new Response('优选订阅生成器异常:' + response.statusText, { status: response.status });
const 优选订阅生成器返回订阅内容 = atob(await response.text());
const 订阅行列表 = 优选订阅生成器返回订阅内容.includes('\r\n') ? 优选订阅生成器返回订阅内容.split('\r\n') : 优选订阅生成器返回订阅内容.split('\n');
for (const 行内容 of 订阅行列表) {
if (!行内容.trim()) continue; // 跳过空行
if (行内容.includes('00000000-0000-4000-8000-000000000000') && 行内容.includes('example.com')) { // 这是优选IP行提取 域名:端口#备注
const 地址匹配 = 行内容.match(/:\/\/[^@]+@([^?]+)/);
if (地址匹配) {
let 地址端口 = 地址匹配[1], 备注 = ''; // 域名:端口 或 IP:端口
const 备注匹配 = 行内容.match(/#(.+)$/);
if (备注匹配) 备注 = '#' + decodeURIComponent(备注匹配[1]);
完整优选IP.push(地址端口 + 备注);
}
} else 其他节点LINK += 行内容 + '\n';
}
} catch (error) {
return new Response('优选订阅生成器异常:' + error.message, { status: 403 });
}
}
订阅内容 = 完整优选IP.map(原始地址 => {
// 统一正则: 匹配 域名/IPv4/IPv6地址 + 可选端口 + 可选备注
// 示例:
// - 域名: hj.xmm1993.top:2096#备注 或 example.com
// - IPv4: 166.0.188.128:443#Los Angeles 或 166.0.188.128
// - IPv6: [2606:4700::]:443#CMCC 或 [2606:4700::]
const regex = /^(\[[\da-fA-F:]+\]|[\d.]+|[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?)*)(?::(\d+))?(?:#(.+))?$/;
const match = 原始地址.match(regex);
let 节点地址, 节点端口 = "443", 节点备注;
if (match) {
节点地址 = match[1]; // IP地址或域名(可能带方括号)
节点端口 = match[2] || "443"; // 端口,默认443
节点备注 = match[3] || 节点地址; // 备注,默认为地址本身
} else {
// 不规范的格式跳过处理返回null
console.warn(`[订阅内容] 不规范的IP格式已忽略: ${原始地址}`);
return null;
}
return `${协议类型}://00000000-0000-4000-8000-000000000000@${节点地址}:${节点端口}?security=tls&type=${config_JSON.传输协议}&host=example.com&sni=example.com&path=${encodeURIComponent(config_JSON.随机路径 ? 随机路径() + 节点路径 : 节点路径) + TLS分片参数}&encryption=none${config_JSON.跳过证书验证 ? '&allowInsecure=1' : ''}#${encodeURIComponent(节点备注)}`;
}).filter(item => item !== null).join('\n');
} else { // 订阅转换
const 订阅转换URL = `${config_JSON.订阅转换配置.SUBAPI}/sub?target=${订阅类型}&url=${encodeURIComponent(url.protocol + '//' + url.host + '/sub?target=mixed&token=' + 订阅TOKEN + (url.searchParams.has('sub') && url.searchParams.get('sub') != '' ? `&sub=${url.searchParams.get('sub')}` : ''))}&config=${encodeURIComponent(config_JSON.订阅转换配置.SUBCONFIG)}&emoji=${config_JSON.订阅转换配置.SUBEMOJI}&scv=${config_JSON.跳过证书验证}`;
try {
@@ -288,10 +304,11 @@ export default {
return new Response('订阅转换后端异常:' + error.message, { status: 403 });
}
}
if (订阅类型 === 'mixed') {
订阅内容 = 批量替换域名(atob(订阅内容).replace(/00000000-0000-4000-8000-000000000000/g, config_JSON.UUID), host);
if (!ua.includes('mozilla')) 订阅内容 = btoa(订阅内容);
} else 订阅内容 = 批量替换域名(订阅内容.replace(/00000000-0000-4000-8000-000000000000/g, config_JSON.UUID), host);
if (!ua.includes('subconverter')) 订阅内容 = 批量替换域名(订阅内容.replace(/00000000-0000-4000-8000-000000000000/g, config_JSON.UUID), config_JSON.HOSTS)
if (!ua.includes('mozilla') && 订阅类型 === 'mixed') 订阅内容 = btoa(订阅内容);
if (订阅类型 === 'singbox') {
订阅内容 = JSON.stringify(JSON.parse(订阅内容), null, 2);
responseHeaders["content-type"] = 'application/json; charset=utf-8';
@@ -502,7 +519,8 @@ async function forwardataTCP(host, portNum, rawData, ws, respHeader, remoteConnW
connectStreams(newSocket, ws, respHeader, null);
}
if (启用SOCKS5反代 && 启用SOCKS5全局反代) {
const 验证SOCKS5白名单 = (addr) => SOCKS5白名单.some(p => new RegExp(`^${p.replace(/\*/g, '.*')}$`, 'i').test(addr));
if (启用SOCKS5反代 && (启用SOCKS5全局反代 || 验证SOCKS5白名单(host))) {
try {
await connecttoPry();
} catch (err) {
@@ -831,21 +849,23 @@ function 随机替换通配符(h) {
});
}
function 批量替换域名(内容, host, 每组数量 = 2) {
function 批量替换域名(内容, hosts, 每组数量 = 2) {
let count = 0, currentRandomHost = null;
return 内容.replace(/example\.com/g, () => {
if (count % 每组数量 === 0) currentRandomHost = 随机替换通配符(host);
if (count % 每组数量 === 0) currentRandomHost = 随机替换通配符(hosts[Math.floor(Math.random() * hosts.length)]);
count++;
return currentRandomHost;
});
}
async function 读取config_JSON(env, hostname, userID, path, 重置配置 = false) {
const host = 随机替换通配符(hostname);
//const host = 随机替换通配符(hostname);
const host = hostname;
const 初始化开始时间 = performance.now();
const 默认配置JSON = {
TIME: new Date().toISOString(),
HOST: host,
HOSTS: [hostname],
UUID: userID,
协议类型: "v" + "le" + "ss",
传输协议: "ws",
@@ -912,6 +932,8 @@ async function 读取config_JSON(env, hostname, userID, path, 重置配置 = fal
}
config_JSON.HOST = host;
if (!config_JSON.HOSTS) config_JSON.HOSTS = [hostname];
if (env.HOST) config_JSON.HOSTS = (await 整理成数组(env.HOST)).map(h => h.toLowerCase().replace(/^https?:\/\//, '').split('/')[0].split(':')[0]);
config_JSON.UUID = userID;
config_JSON.PATH = path ? (path.startsWith('/') ? path : '/' + path) : (config_JSON.反代.SOCKS5.启用 ? ('/' + config_JSON.反代.SOCKS5.启用 + (config_JSON.反代.SOCKS5.全局 ? '://' : '=') + config_JSON.反代.SOCKS5.账号) : (config_JSON.反代.PROXYIP === 'auto' ? '/' : `/proxyip=${config_JSON.反代.PROXYIP}`));
const TLS分片参数 = config_JSON.TLS分片 == 'Shadowrocket' ? `&fragment=${encodeURIComponent('1,40-60,30-50,tlshello')}` : config_JSON.TLS分片 == 'Happ' ? `&fragment=${encodeURIComponent('3,1,tlshello')}` : '';