Skip to content

Commit

Permalink
更新README.md,增加访客订阅说明和注意事项;修改_worker.js,添加访客订阅功能及相关逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
cmliu committed Jan 21, 2025
1 parent b1217f6 commit e404e65
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 15 deletions.
32 changes: 21 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@

![自建汇聚订阅 CF-Workers-SUB](./sub.png)

> 这是一个将多个节点和订阅合并为单一链接的工具,支持自动适配与自定义分流,简化了订阅管理。
这是一个将多个节点和订阅合并为单一链接的工具,支持自动适配与自定义分流,简化了订阅管理。

> [!CAUTION]
> **汇聚订阅非base64订阅时**,会自动生成一个**有效期为24小时的临时订阅**,并提交给**订阅转换后端**来完成订阅转换,可避免您的汇聚订阅地址泄露。
> [!WARNING]
> **汇聚订阅非base64订阅时**,如果您的节点数量**十分庞大**,订阅转换后端将需要较长时间才能完成订阅转换,这会导致部分梯子客户端在订阅时提示超时而无法完成订阅(说直白一点就是**汇聚节点池的节点时容易导致Clash订阅超时**)!
>
> 可自行删减订阅节点数量,提高订阅转换效率!
## 🛠 功能特点
1. **节点链接自动转换成base64订阅链接:** 这是最基础的功能,可以将您的节点自动转换为base64格式的订阅链接;
Expand All @@ -12,7 +20,7 @@
5. **更多功能等待发掘...**

## 🎬 视频教程
- **CF-Workers-SUB 视频教程**: https://www.youtube.com/watch?v=w6rRY4FDd58
- **[自建订阅!CF-Workers-SUB 教你如何将多节点多订阅汇聚合并为一个订阅!](https://youtu.be/w6rRY4FDd58)**

## 🤝 社区支持
- Telegram 交流群: [@CMLiussss](https://t.me/CMLiussss)
Expand Down Expand Up @@ -89,14 +97,16 @@
</details>
## 📋 变量说明
| 变量名 | 示例 | 备注 |
|--------|---------|-----|
| TOKEN | `auto` | 快速订阅内置节点的订阅路径地址 /auto |
| TGTOKEN | `6894123456:XXXXXXXXXX0qExVsBPUhHDAbXXXXXqWXgBA` | 发送TG通知的机器人token |
| TGID | `6946912345` | 接收TG通知的账户数字ID |
| SUBNAME | `CF-Workers-SUB` | 订阅名称 |
| SUBAPI | `subapi.fxxk.dedyn.io` | clash、singbox等 订阅转换后端 |
| SUBCONFIG | [https://raw.github.../ACL4SSR_Online_MultiCountry.ini](https://raw.githubusercontent.com/cmliu/ACL4SSR/main/Clash/config/ACL4SSR_Online_MultiCountry.ini) | clash、singbox等 订阅转换配置文件 |
| 变量名 | 示例 | 必填 | 备注 |
|-|-|-|-|
| TOKEN | `auto` | ✅ | 汇聚订阅的订阅配置路径地址,例如:`/auto` |
| GUEST | `test` | ❌ | 汇聚订阅的访客订阅TOKEN,例如:`/sub?token=test` |
| LINK | `vless://b7a39...`,`vmess://ew0K...`,`https://sub...` | ❌ | 可同时放入多个节点链接与多个订阅链接,链接之间用换行做间隔(添加**KV命名空间**后,变量将不会使用)|
| TGTOKEN | `6894123456:XXXXXXXXXX0qExVsBPUhHDAbXXXXXqWXgBA` | ❌ | 发送TG通知的机器人token |
| TGID | `6946912345` | ❌ | 接收TG通知的账户数字ID |
| SUBNAME | `CF-Workers-SUB` | ❌ | 订阅名称 |
| SUBAPI | `subapi.fxxk.dedyn.io` | ❌ | clash、singbox等 订阅转换后端 |
| SUBCONFIG | [https://raw.github.../ACL4SSR_Online_MultiCountry.ini](https://raw.githubusercontent.com/cmliu/ACL4SSR/main/Clash/config/ACL4SSR_Online_MultiCountry.ini) | ❌ | clash、singbox等 订阅转换配置文件 |
## ⚠️ 注意事项
Expand All @@ -108,4 +118,4 @@
# 🙏 致谢
[Alice Networks LTD](https://alicenetworks.net/),[mianayang](https://github.com/mianayang/myself/blob/main/cf-workers/sub/sub.js)、[ACL4SSR](https://github.com/ACL4SSR/ACL4SSR/tree/master/Clash/config)、[肥羊](https://github.com/youshandefeiyang/sub-web-modify)
[Alice Networks LTD](https://alicenetworks.net/),[mianayang](https://github.com/mianayang/myself/blob/main/cf-workers/sub/sub.js)、[ACL4SSR](https://github.com/ACL4SSR/ACL4SSR/tree/master/Clash/config)、[肥羊](https://sub.v1.mk/)
54 changes: 50 additions & 4 deletions _worker.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

// 部署完成后在网址后面加上这个,获取自建节点和机场聚合节点,/?token=auto或/auto或

let mytoken = 'auto'; //可以随便取,或者uuid生成,https://1024tools.com/uuid
let mytoken = 'auto';
let guestToken = ''; //可以随便取,或者uuid生成,https://1024tools.com/uuid
let BotToken = ''; //可以为空,或者@BotFather中输入/start,/newbot,并关注机器人
let ChatID = ''; //可以为空,或者@userinfobot中获取,/start
let TG = 0; //小白勿动, 开发者专用,1 为推送所有的访问信息,0 为不推送订阅转换后端的访问信息与异常访问
Expand Down Expand Up @@ -50,14 +51,17 @@ export default {
currentDate.setHours(0, 0, 0, 0);
const timeTemp = Math.ceil(currentDate.getTime() / 1000);
const fakeToken = await MD5MD5(`${mytoken}${timeTemp}`);
guestToken = env.GUESTTOKEN || env.GUEST || guestToken;
if (!guestToken) guestToken = await MD5MD5(mytoken);
const 访客订阅 = guestToken;
//console.log(`${fakeUserID}\n${fakeHostName}`); // 打印fakeID

let UD = Math.floor(((timestamp - Date.now()) / timestamp * total * 1099511627776) / 2);
total = total * 1099511627776;
let expire = Math.floor(timestamp / 1000);
SUBUpdateTime = env.SUBUPTIME || SUBUpdateTime;

if (!(token == mytoken || token == fakeToken || url.pathname == ("/" + mytoken) || url.pathname.includes("/" + mytoken + "?"))) {
if (!([mytoken, fakeToken, 访客订阅].includes(token) || url.pathname == ("/" + mytoken) || url.pathname.includes("/" + mytoken + "?"))) {
if (TG == 1 && url.pathname !== "/" && url.pathname !== "/favicon.ico") await sendMessage(`#异常访问 ${FileName}`, request.headers.get('CF-Connecting-IP'), `UA: ${userAgent}</tg-spoiler>\n域名: ${url.hostname}\n<tg-spoiler>入口: ${url.pathname + url.search}</tg-spoiler>`);
if (env.URL302) return Response.redirect(env.URL302, 302);
else if (env.URL) return await proxyURL(env.URL, url);
Expand All @@ -72,7 +76,7 @@ export default {
await 迁移地址列表(env, 'LINK.txt');
if (userAgent.includes('mozilla') && !url.search) {
await sendMessage(`#编辑订阅 ${FileName}`, request.headers.get('CF-Connecting-IP'), `UA: ${userAgentHeader}</tg-spoiler>\n域名: ${url.hostname}\n<tg-spoiler>入口: ${url.pathname + url.search}</tg-spoiler>`);
return await KV(request, env, 'LINK.txt');
return await KV(request, env, 'LINK.txt', 访客订阅);
} else {
MainData = await env.KV.get('LINK.txt') || MainData;
}
Expand Down Expand Up @@ -488,7 +492,7 @@ async function 迁移地址列表(env, txt = 'ADD.txt') {
return false;
}

async function KV(request, env, txt = 'ADD.txt') {
async function KV(request, env, txt = 'ADD.txt', guest) {
const url = new URL(request.url);
try {
// POST请求处理
Expand Down Expand Up @@ -602,6 +606,31 @@ async function KV(request, env, txt = 'ADD.txt') {
loon订阅地址:<br>
<a href="javascript:void(0)" onclick="copyToClipboard('https://${url.hostname}/${mytoken}?loon','qrcode_5')" style="color:blue;text-decoration:underline;cursor:pointer;">https://${url.hostname}/${mytoken}?loon</a><br>
<div id="qrcode_5" style="margin: 10px 10px 10px 10px;"></div>
&nbsp;&nbsp;<strong><a href="javascript:void(0);" id="noticeToggle" onclick="toggleNotice()">查看访客订阅∨</a></strong><br>
<div id="noticeContent" class="notice-content" style="display: none;">
---------------------------------------------------------------<br>
访客订阅只能使用订阅功能,无法查看配置页!<br>
GUEST(访客订阅TOKEN): <strong>${guest}</strong><br>
---------------------------------------------------------------<br>
自适应订阅地址:<br>
<a href="javascript:void(0)" onclick="copyToClipboard('https://${url.hostname}/sub?token=${guest}','guest_0')" style="color:blue;text-decoration:underline;cursor:pointer;">https://${url.hostname}/sub?token=${guest}</a><br>
<div id="guest_0" style="margin: 10px 10px 10px 10px;"></div>
Base64订阅地址:<br>
<a href="javascript:void(0)" onclick="copyToClipboard('https://${url.hostname}/sub?token=${guest}&b64','guest_1')" style="color:blue;text-decoration:underline;cursor:pointer;">https://${url.hostname}/sub?token=${guest}&b64</a><br>
<div id="guest_1" style="margin: 10px 10px 10px 10px;"></div>
clash订阅地址:<br>
<a href="javascript:void(0)" onclick="copyToClipboard('https://${url.hostname}/sub?token=${guest}&clash','guest_2')" style="color:blue;text-decoration:underline;cursor:pointer;">https://${url.hostname}/sub?token=${guest}&clash</a><br>
<div id="guest_2" style="margin: 10px 10px 10px 10px;"></div>
singbox订阅地址:<br>
<a href="javascript:void(0)" onclick="copyToClipboard('https://${url.hostname}/sub?token=${guest}&sb','guest_3')" style="color:blue;text-decoration:underline;cursor:pointer;">https://${url.hostname}/sub?token=${guest}&sb</a><br>
<div id="guest_3" style="margin: 10px 10px 10px 10px;"></div>
surge订阅地址:<br>
<a href="javascript:void(0)" onclick="copyToClipboard('https://${url.hostname}/sub?token=${guest}&surge','guest_4')" style="color:blue;text-decoration:underline;cursor:pointer;">https://${url.hostname}/sub?token=${guest}&surge</a><br>
<div id="guest_4" style="margin: 10px 10px 10px 10px;"></div>
loon订阅地址:<br>
<a href="javascript:void(0)" onclick="copyToClipboard('https://${url.hostname}/sub?token=${guest}&loon','guest_5')" style="color:blue;text-decoration:underline;cursor:pointer;">https://${url.hostname}/sub?token=${guest}&loon</a><br>
<div id="guest_5" style="margin: 10px 10px 10px 10px;"></div>
</div>
---------------------------------------------------------------<br>
################################################################<br>
订阅转换配置<br>
Expand Down Expand Up @@ -760,6 +789,23 @@ async function KV(request, env, txt = 'ADD.txt') {
timer = setTimeout(saveContent, 5000);
});
}
function toggleNotice() {
const noticeContent = document.getElementById('noticeContent');
const noticeToggle = document.getElementById('noticeToggle');
if (noticeContent.style.display === 'none' || noticeContent.style.display === '') {
noticeContent.style.display = 'block';
noticeToggle.textContent = '隐藏访客订阅∧';
} else {
noticeContent.style.display = 'none';
noticeToggle.textContent = '查看访客订阅∨';
}
}
// 初始化 noticeContent 的 display 属性
document.addEventListener('DOMContentLoaded', () => {
document.getElementById('noticeContent').style.display = 'none';
});
</script>
</body>
</html>
Expand Down

0 comments on commit e404e65

Please sign in to comment.