mirror of
https://github.com/lush2020/CF-Workers-SUB.git
synced 2026-03-21 02:24:02 +08:00
Update _worker.js
This commit is contained in:
72
_worker.js
72
_worker.js
@@ -8,25 +8,25 @@ let TG = 0; //1 为推送所有的访问信息,0 为不推送订阅转换后
|
||||
let SUBUpdateTime = 6; //自定义订阅更新时间,单位小时
|
||||
|
||||
//自建节点
|
||||
const MainData = `
|
||||
let MainData = `
|
||||
vless://b7a392e2-4ef0-4496-90bc-1c37bb234904@cf.090227.xyz:443?encryption=none&security=tls&sni=edgetunnel-2z2.pages.dev&fp=random&type=ws&host=edgetunnel-2z2.pages.dev&path=%2F%3Fed%3D2048#%E5%8A%A0%E5%85%A5%E6%88%91%E7%9A%84%E9%A2%91%E9%81%93t.me%2FCMLiussss%E8%A7%A3%E9%94%81%E6%9B%B4%E5%A4%9A%E4%BC%98%E9%80%89%E8%8A%82%E7%82%B9
|
||||
vmess://ew0KICAidiI6ICIyIiwNCiAgInBzIjogIuWKoOWFpeaIkeeahOmikemBk3QubWUvQ01MaXVzc3Nz6Kej6ZSB5pu05aSa5LyY6YCJ6IqC54K5PuiLseWbvSDlgKvmlabph5Hono3ln44iLA0KICAiYWRkIjogImNmLjA5MDIyNy54eXoiLA0KICAicG9ydCI6ICI4NDQzIiwNCiAgImlkIjogIjAzZmNjNjE4LWI5M2QtNjc5Ni02YWVkLThhMzhjOTc1ZDU4MSIsDQogICJhaWQiOiAiMCIsDQogICJzY3kiOiAiYXV0byIsDQogICJuZXQiOiAid3MiLA0KICAidHlwZSI6ICJub25lIiwNCiAgImhvc3QiOiAicHBmdjJ0bDl2ZW9qZC1tYWlsbGF6eS5wYWdlcy5kZXYiLA0KICAicGF0aCI6ICIvamFkZXIuZnVuOjQ0My9saW5rdndzIiwNCiAgInRscyI6ICJ0bHMiLA0KICAic25pIjogInBwZnYydGw5dmVvamQtbWFpbGxhenkucGFnZXMuZGV2IiwNCiAgImFscG4iOiAiIiwNCiAgImZwIjogIiINCn0=
|
||||
`
|
||||
|
||||
//机场信息,可多个,也可为0
|
||||
const urls = [
|
||||
let urls = [
|
||||
'https://sub.xf.free.hr/auto',
|
||||
'https://hy2sub.pages.dev',
|
||||
// 添加更多订阅,支持base64
|
||||
];
|
||||
|
||||
let subconverter = "api.v1.mk"; //在线订阅转换后端,目前使用肥羊的订阅转换功能。支持自建psub 可自行搭建https://github.com/bulianglin/psub
|
||||
let subconverter = "apiurl.v1.mk"; //在线订阅转换后端,目前使用肥羊的订阅转换功能。支持自建psub 可自行搭建https://github.com/bulianglin/psub
|
||||
let subconfig = "https://raw.githubusercontent.com/cmliu/ACL4SSR/main/Clash/config/ACL4SSR_Online_Full.ini"; //订阅配置文件
|
||||
|
||||
export default {
|
||||
async fetch (request,env) {
|
||||
const userAgentHeader = request.headers.get('User-Agent');
|
||||
const userAgent = userAgentHeader ? userAgentHeader.toLowerCase() : "null";
|
||||
const userAgent = userAgentHeader ? userAgentHeader : "null";
|
||||
const url = new URL(request.url);
|
||||
const token = url.searchParams.get('token');
|
||||
mytoken = env.TOKEN || mytoken;
|
||||
@@ -36,15 +36,60 @@ export default {
|
||||
subconverter = env.SUBAPI || subconverter;
|
||||
subconfig = env.SUBCONFIG || subconfig;
|
||||
|
||||
MainData = env.LINK || MainData;
|
||||
const link = await ADD(MainData);
|
||||
MainData = link.join('\n');
|
||||
//console.log(MainData);
|
||||
|
||||
let links = MainData;
|
||||
if(env.SUBLINK) urls = await ADD(env.SUBLINK);
|
||||
links += '|' + urls.join('|'); // 将 urls 数组的元素作为字符串添加到 links 的末尾
|
||||
links = links.replace(/[ "'\r\n]+/g, '|').replace(/\|\|+/g, '|');
|
||||
if (links.charAt(0) == '|') links = links.slice(1);
|
||||
if (links.charAt(links.length -1) == '|') links = links.slice(0, links.length - 1);
|
||||
//console.log(links);
|
||||
|
||||
if ( !(token == mytoken || url.pathname == ("/"+ mytoken) || url.pathname.includes("/"+ mytoken + "?")) ) {
|
||||
if ( TG == 1 && url.pathname !== "/" && url.pathname !== "/favicon.ico" ) await sendMessage("#异常访问", request.headers.get('CF-Connecting-IP'), `UA: ${userAgent}</tg-spoiler>\n域名: ${url.hostname}\n<tg-spoiler>入口: ${url.pathname + url.search}</tg-spoiler>`);
|
||||
return new Response('Hello World!', { status: 403 });
|
||||
//首页改成一个nginx伪装页
|
||||
return new Response(`
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Welcome to nginx!</title>
|
||||
<style>
|
||||
body {
|
||||
width: 35em;
|
||||
margin: 0 auto;
|
||||
font-family: Tahoma, Verdana, Arial, sans-serif;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Welcome to nginx!</h1>
|
||||
<p>If you see this page, the nginx web server is successfully installed and
|
||||
working. Further configuration is required.</p>
|
||||
|
||||
<p>For online documentation and support please refer to
|
||||
<a href="http://nginx.org/">nginx.org</a>.<br/>
|
||||
Commercial support is available at
|
||||
<a href="http://nginx.com/">nginx.com</a>.</p>
|
||||
|
||||
<p><em>Thank you for using nginx.</em></p>
|
||||
</body>
|
||||
</html>
|
||||
`, {
|
||||
headers: {
|
||||
'Content-Type': 'text/html; charset=UTF-8',
|
||||
},
|
||||
});
|
||||
} else if ( TG == 1 || !userAgent.includes('subconverter') || !userAgent.includes('null')){
|
||||
await sendMessage("#获取订阅", request.headers.get('CF-Connecting-IP'), `UA: ${userAgent}</tg-spoiler>\n域名: ${url.hostname}\n<tg-spoiler>入口: ${url.pathname + url.search}</tg-spoiler>`);
|
||||
}
|
||||
|
||||
if (userAgent.includes('clash')) {
|
||||
const subconverterUrl = `https://${subconverter}/sub?target=clash&url=${encodeURIComponent(request.url)}&insert=false&config=${encodeURIComponent(subconfig)}&emoji=true&list=false&tfo=false&scv=false&fdn=false&sort=false&new_name=true`;
|
||||
const subconverterUrl = `https://${subconverter}/sub?target=clash&url=${encodeURIComponent(links)}&insert=false&config=${encodeURIComponent(subconfig)}&emoji=true&list=false&tfo=false&scv=false&fdn=false&sort=false&new_name=true`;
|
||||
//const subconverterUrl = `https://${subconverter}/sub?target=clash&url=${encodeURIComponent(request.url)}&insert=false&config=${encodeURIComponent(subconfig)}&emoji=true&list=false&tfo=false&scv=false&fdn=false&sort=false&new_name=true`;
|
||||
|
||||
try {
|
||||
const subconverterResponse = await fetch(subconverterUrl);
|
||||
@@ -68,7 +113,8 @@ export default {
|
||||
});
|
||||
}
|
||||
} else if (userAgent.includes('sing-box') || userAgent.includes('singbox')) {
|
||||
const subconverterUrl = `https://${subconverter}/sub?target=singbox&url=${encodeURIComponent(request.url)}&insert=false&config=${encodeURIComponent(subconfig)}&emoji=true&list=false&tfo=false&scv=false&fdn=false&sort=false&new_name=true`;
|
||||
const subconverterUrl = `https://${subconverter}/sub?target=singbox&url=${encodeURIComponent(links)}&insert=false&config=${encodeURIComponent(subconfig)}&emoji=true&list=false&tfo=false&scv=false&fdn=false&sort=false&new_name=true`;
|
||||
//const subconverterUrl = `https://${subconverter}/sub?target=singbox&url=${encodeURIComponent(request.url)}&insert=false&config=${encodeURIComponent(subconfig)}&emoji=true&list=false&tfo=false&scv=false&fdn=false&sort=false&new_name=true`;
|
||||
|
||||
try {
|
||||
const subconverterResponse = await fetch(subconverterUrl);
|
||||
@@ -100,7 +146,7 @@ export default {
|
||||
method: 'get',
|
||||
headers: {
|
||||
'Accept': 'text/html,application/xhtml+xml,application/xml;',
|
||||
'User-Agent': 'CF-Workers-SUB/cmliu'
|
||||
'User-Agent': 'v2rayN/6.39 CF-Workers-SUB/cmliu'
|
||||
}
|
||||
})));
|
||||
|
||||
@@ -166,3 +212,13 @@ function base64Decode(str) {
|
||||
const decoder = new TextDecoder('utf-8');
|
||||
return decoder.decode(bytes);
|
||||
}
|
||||
|
||||
async function ADD(envadd) {
|
||||
var addtext = envadd.replace(/[ "'\r\n]+/g, ',').replace(/,+/g, ','); // 将空格、双引号、单引号和换行符替换为逗号
|
||||
//console.log(addtext);
|
||||
if (addtext.charAt(0) == ',') addtext = addtext.slice(1);
|
||||
if (addtext.charAt(addtext.length -1) == ',') addtext = addtext.slice(0, addtext.length - 1);
|
||||
const add = addtext.split(',');
|
||||
//console.log(add);
|
||||
return add ;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user