Skip to content

Commit

Permalink
可自定义PROXYIP端口
Browse files Browse the repository at this point in the history
  • Loading branch information
cmliu committed Sep 29, 2024
1 parent 8f337c8 commit 23daa0e
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 23 deletions.
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ Telegram交流群:[@CMLiussss](https://t.me/CMLiussss),**感谢[Alice Networ
| 变量名 | 示例 | 备注 |
|--------|---------|-----|
| PASSWORD | `auto` | 可以取任意值 |
| PROXYIP | `proxyip.fxxk.dedyn.io` | 备选作为访问CFCDN站点的代理节点(支持多ProxyIP, ProxyIP之间使用`,``换行`作间隔) |
| PROXYIP | `proxyip.fxxk.dedyn.io:443` | 备选作为访问CFCDN站点的代理节点(支持多ProxyIP, ProxyIP之间使用`,``换行`作间隔) |
| SOCKS5 | `user:[email protected]:1080` | 优先作为访问CFCDN站点的SOCKS5代理(支持多socks5, socks5之间使用`,``换行`作间隔) |
| GO2SOCKS5 | `blog.cmliussss.com`,`*ip111.cn` | 设置`SOCKS5`变量之后,可设置强制使用socks5访问名单(`*`可作为通配符,`换行`作多元素间隔) |
| GO2SOCKS5 | `blog.cmliussss.com`,`*.ip111.cn`,`*google.com` | 设置`SOCKS5`变量之后,可设置强制使用socks5访问名单(`*`可作为通配符,`换行`作多元素间隔) |
| ADD | `www.csgo.com:2087,icook.hk` | 本地优选域名/优选IP(支持多元素之间`,``换行`作间隔) |
| ADDAPI | [https://raw.github.../addressesapi.txt](https://raw.githubusercontent.com/cmliu/WorkerVless2sub/main/addressesapi.txt) | 不解释, 懂得都懂 |
| ADDCSV | [https://raw.github.../addressescsv.csv](https://raw.githubusercontent.com/cmliu/WorkerVless2sub/main/addressescsv.csv) | 不解释, 懂得都懂 |
Expand All @@ -155,7 +155,7 @@ Telegram交流群:[@CMLiussss](https://t.me/CMLiussss),**感谢[Alice Networ
| SUBNAME | `epeius` | 订阅名称 |
| RPROXYIP | `false` | 设为 true 即可强制获取订阅器分配的ProxyIP(需订阅器支持)|
| URL302 | `https://t.me/CMLiussss` | 主页302跳转(支持多url, url之间使用`,``换行`作间隔, 小白别用) |
| URL | `https://t.me/CMLiussss` | 主页伪装(支持多url, url之间使用`,``换行`作间隔, 乱设容易触发反诈) |
| URL | `https://blog.cmliussss.com` | 主页反代伪装(支持多url, url之间使用`,``换行`作间隔, 乱设容易触发反诈) |
| CFEMAIL | `[email protected]` | CF账户邮箱(与`CFKEY`都填上后, 订阅信息将显示请求使用量, 小白别用) |
| CFKEY | `c6a944b5c956b6c18c2352880952bced8b85e` | CF账户Global API Key(与`CFEMAIL`都填上后, 订阅信息将显示请求使用量, 小白别用) |

Expand Down Expand Up @@ -195,5 +195,19 @@ Telegram交流群:[@CMLiussss](https://t.me/CMLiussss),**感谢[Alice Networ
## Star 星星走起
[![Stargazers over time](https://starchart.cc/cmliu/epeius.svg?variant=adaptive)](https://starchart.cc/cmliu/epeius)

## 已适配客户端
### Windows
- [v2rayN](https://github.com/2dust/v2rayN)
- clash.meta([FlClash](https://github.com/chen08209/FlClash),[clash-verge-rev
](https://github.com/clash-verge-rev/clash-verge-rev),[Clash Nyanpasu](https://github.com/keiko233/clash-nyanpasu))
### IOS
- Surge,小火箭
- sing-box([SFI](https://sing-box.sagernet.org/zh/clients/apple/))
### 安卓
- clash.meta([ClashMetaForAndroid](https://github.com/MetaCubeX/ClashMetaForAndroid),[FlClash](https://github.com/chen08209/FlClash))
- sing-box([SFA](https://github.com/SagerNet/sing-box))
### MacOS
- clash.meta([FlClash](https://github.com/chen08209/FlClash))

# 感谢
[ca110us](https://github.com/ca110us/epeius)、[xream](https://github.com/xream)、[3Kmfi6HP](https://github.com/3Kmfi6HP/EDtunnel/tree/trojan)、[zizifn](https://github.com/zizifn/edgetunnel)、[emn178](https://github.com/emn178/js-sha256)、[ACL4SSR](https://github.com/ACL4SSR/ACL4SSR/tree/master/Clash/config)、[SHIJS1999](https://github.com/SHIJS1999/cloudflare-worker-vless-ip)、<a href="https://url.cmliussss.com/alice"><img src="https://alicenetworks.net/templates/lagom2/assets/img/logo/logo_big.194980063.png" width="150" height="75" alt="Alice Networks LTD"/></a>、
4 changes: 2 additions & 2 deletions _worker.js

Large diffs are not rendered by default.

74 changes: 56 additions & 18 deletions _worker.src.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,9 @@ export default {
//const url = new URL(request.url);
switch (url.pathname) {
case '/':
const envKey = env.URL302 ? 'URL302' : (env.URL ? 'URL' : null);
if (envKey) {
const URLs = await ADD(env[envKey]);
const URL = URLs[Math.floor(Math.random() * URLs.length)];
return envKey === 'URL302' ? Response.redirect(URL, 302) : fetch(new Request(URL, request));
}
return new Response(JSON.stringify(request.cf, null, 4), { status: 200 });
if (env.URL302) return Response.redirect(env.URL302, 302);
else if (env.URL) return await proxyURL(env.URL, url);
else return new Response(JSON.stringify(request.cf, null, 4), { status: 200 });
case `/${fakeUserID}`:
const fakeConfig = await getTrojanConfig(password, request.headers.get('Host'), sub, 'CF-Workers-SUB', RproxyIP, url);
return new Response(`${fakeConfig}`, { status: 200 });
Expand Down Expand Up @@ -187,7 +183,9 @@ export default {
});
}
default:
return new Response("Incorrect password!!!", { status: 404 });
if (env.URL302) return Response.redirect(env.URL302, 302);
else if (env.URL) return await proxyURL(env.URL, url);
else return new Response('不用怀疑!你PASSWORD就是错的!!!', { status: 404 });
}
} else {
proxyIP = url.searchParams.get('proxyip') || proxyIP;
Expand Down Expand Up @@ -394,32 +392,39 @@ async function handleTCPOutBound(remoteSocket, addressRemote, portRemote, rawCli
async function connectAndWrite(address, port, socks = false) {
log(`connected to ${address}:${port}`);
//if (/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(address)) address = `${atob('d3d3Lg==')}${address}${atob('LmlwLjA5MDIyNy54eXo=')}`;
const tcpSocket2 = socks ? await socks5Connect(addressType, address, port, log)
const tcpSocket = socks ? await socks5Connect(addressType, address, port, log)
: connect({
hostname: address,
port
});
remoteSocket.value = tcpSocket2;
remoteSocket.value = tcpSocket;
//log(`connected to ${address}:${port}`);
const writer = tcpSocket2.writable.getWriter();
const writer = tcpSocket.writable.getWriter();
await writer.write(rawClientData);
writer.releaseLock();
return tcpSocket2;
return tcpSocket;
}
async function retry() {
let tcpSocket2
if (enableSocks) {
tcpSocket2 = await connectAndWrite(addressRemote, portRemote, true);
tcpSocket = await connectAndWrite(addressRemote, portRemote, true);
} else {
if (!proxyIP || proxyIP == '') proxyIP = atob('cHJveHlpcC5meHhrLmRlZHluLmlv');
tcpSocket2 = await connectAndWrite(proxyIP || addressRemote, portRemote);
if (!proxyIP || proxyIP == '') {
proxyIP = atob('cHJveHlpcC5meHhrLmRlZHluLmlv');
} else if (proxyIP.includes(']:')) {
portRemote = proxyIP.split(']:')[1] || portRemote;
proxyIP = proxyIP.split(']:')[0] || proxyIP;
} else if (proxyIP.split(':').length === 2) {
portRemote = proxyIP.split(':')[1] || portRemote;
proxyIP = proxyIP.split(':')[0] || proxyIP;
}
tcpSocket = await connectAndWrite(proxyIP || addressRemote, portRemote);
}
tcpSocket2.closed.catch((error) => {
tcpSocket.closed.catch((error) => {
console.log("retry tcpSocket closed error", error);
}).finally(() => {
safeCloseWebSocket(webSocket);
});
remoteSocketToWS(tcpSocket2, webSocket, null, log);
remoteSocketToWS(tcpSocket, webSocket, null, log);
}
let useSocks = false;
if( go2Socks5s.length > 0 && enableSocks ) useSocks = await useSocks5Pattern(addressRemote);
Expand Down Expand Up @@ -581,6 +586,39 @@ async function ADD(envadd) {
return add ;
}

async function proxyURL(proxyURL, url) {
const URLs = await ADD(proxyURL);
const fullURL = URLs[Math.floor(Math.random() * URLs.length)];
// 解析目标 URL
let parsedURL = new URL(fullURL);
console.log(parsedURL);
// 提取并可能修改 URL 组件
let URLProtocol = parsedURL.protocol.slice(0, -1) || 'https';
let URLHostname = parsedURL.hostname;
let URLPathname = parsedURL.pathname;
let URLSearch = parsedURL.search;
// 处理 pathname
if (URLPathname.charAt(URLPathname.length - 1) == '/') {
URLPathname = URLPathname.slice(0, -1);
}
URLPathname += url.pathname;
// 构建新的 URL
let newURL = `${URLProtocol}://${URLHostname}${URLPathname}${URLSearch}`;
// 反向代理请求
let response = await fetch(newURL);
// 创建新的响应
let newResponse = new Response(response.body, {
status: response.status,
statusText: response.statusText,
headers: response.headers
});
// 添加自定义头部,包含 URL 信息
//newResponse.headers.set('X-Proxied-By', 'Cloudflare Worker');
//newResponse.headers.set('X-Original-URL', fullURL);
newResponse.headers.set('X-New-URL', newURL);
return newResponse;
}

function checkSUB(host) {
if ((!sub || sub == '') && (addresses.length + addressesapi.length + addressescsv.length) == 0){
addresses = [
Expand Down

0 comments on commit 23daa0e

Please sign in to comment.