Skip to content

Commit 2201376

Browse files
committed
可自定义PROXYIP端口
1 parent 8032f7f commit 2201376

File tree

2 files changed

+59
-13
lines changed

2 files changed

+59
-13
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,9 @@ Telegram交流群:[@CMLiussss](https://t.me/CMLiussss),**感谢[Alice Networ
136136
| 变量名 | 示例 | 必填 | 备注 | YT |
137137
|--------|---------|-|-----|-----|
138138
| UUID | `90cd4a77-141a-43c9-991b-08263cfe9c10` || Powershell -NoExit -Command "[guid]::NewGuid()"| [Video](https://www.youtube.com/watch?v=s91zjpw3-P8&t=72s) |
139-
| PROXYIP | `proxyip.fxxk.dedyn.io` || 备选作为访问CFCDN站点的代理节点(支持多ProxyIP, ProxyIP之间使用`,``换行`作间隔) | [Video](https://www.youtube.com/watch?v=s91zjpw3-P8&t=166s) |
139+
| PROXYIP | `proxyip.fxxk.dedyn.io:443` || 备选作为访问CFCDN站点的代理节点(支持多ProxyIP, ProxyIP之间使用`,``换行`作间隔) | [Video](https://www.youtube.com/watch?v=s91zjpw3-P8&t=166s) |
140140
| SOCKS5 | `user:[email protected]:1080` || 优先作为访问CFCDN站点的SOCKS5代理(支持多socks5, socks5之间使用`,``换行`作间隔) | [Video](https://www.youtube.com/watch?v=s91zjpw3-P8&t=826s) |
141-
| GO2SOCKS5 | `blog.cmliussss.com`,`*ip111.cn` || 设置`SOCKS5`变量之后,可设置强制使用socks5访问名单(`*`可作为通配符,`换行`作多元素间隔) ||
141+
| GO2SOCKS5 | `blog.cmliussss.com`,`*.ip111.cn`,`*google.com` || 设置`SOCKS5`变量之后,可设置强制使用socks5访问名单(`*`可作为通配符,`换行`作多元素间隔) ||
142142
| ADD | `icook.tw:2053#官方优选域名` || 本地优选TLS域名/优选IP(支持多元素之间`,``换行`作间隔) ||
143143
| ADDAPI | [https://raw.github.../addressesapi.txt](https://raw.githubusercontent.com/cmliu/WorkerVless2sub/main/addressesapi.txt) || 优选IP的API地址(支持多元素之间`,`或 换行 作间隔) ||
144144
| ADDNOTLS | `icook.hk:8080#官方优选域名` || 本地优选noTLS域名/优选IP(支持多元素之间`,``换行`作间隔) ||
@@ -153,7 +153,7 @@ Telegram交流群:[@CMLiussss](https://t.me/CMLiussss),**感谢[Alice Networ
153153
| SUBNAME | `edgetunnel` || 订阅名称 | |
154154
| RPROXYIP | `false` || 设为 true 即可强制获取订阅器分配的ProxyIP(需订阅器支持)| [Video](https://www.youtube.com/watch?v=s91zjpw3-P8&t=1816s) |
155155
| URL302 | `https://t.me/CMLiussss` || 主页302跳转(支持多url, url之间使用`,``换行`作间隔, 小白别用) | |
156-
| URL | `https://t.me/CMLiussss` || 主页伪装(支持多url, url之间使用`,``换行`作间隔, 乱设容易触发反诈) | |
156+
| URL | `https://blog.cmliussss.com` || 主页反代伪装(支持多url, url之间使用`,``换行`作间隔, 乱设容易触发反诈) | |
157157
| CFEMAIL | `[email protected]` || CF账户邮箱(与`CFKEY`都填上后, 订阅信息将显示请求使用量, 小白别用) | |
158158
| CFKEY | `c6a944b5c956b6c18c2352880952bced8b85e` || CF账户Global API Key(与`CFEMAIL`都填上后, 订阅信息将显示请求使用量, 小白别用) | |
159159

_worker.js

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { connect } from 'cloudflare:sockets';
66
// [Windows] Press "Win + R", input cmd and run: Powershell -NoExit -Command "[guid]::NewGuid()"
77
let userID = '90cd4a77-141a-43c9-991b-08263cfe9c10';
88

9-
let proxyIP = '';// 小白勿动,该地址并不影响你的网速,这是给CF代理使用的。'cdn.xn--b6gac.eu.org, cdn-all.xn--b6gac.eu.org, workers.cloudflare.cyou'
9+
let proxyIP = '';// 小白勿动,该地址并不影响你的网速,这是给CF代理使用的。'cdn.xn--b6gac.eu.org, cdn-all.xn--b6gac.eu.org'
1010

1111
let sub = '';// 避免项目被滥用,现已取消内置订阅器
1212
let subconverter = 'SUBAPI.fxxk.dedyn.io';// clash订阅转换后端,目前使用CM的订阅转换功能。自带虚假uuid和host订阅。
@@ -148,13 +148,9 @@ export default {
148148
// const url = new URL(request.url);
149149
switch (url.pathname.toLowerCase()) {
150150
case '/':
151-
const envKey = env.URL302 ? 'URL302' : (env.URL ? 'URL' : null);
152-
if (envKey) {
153-
const URLs = await ADD(env[envKey]);
154-
const URL = URLs[Math.floor(Math.random() * URLs.length)];
155-
return envKey === 'URL302' ? Response.redirect(URL, 302) : fetch(new Request(URL, request));
156-
}
157-
return new Response(JSON.stringify(request.cf, null, 4), { status: 200 });
151+
if (env.URL302) return Response.redirect(env.URL302, 302);
152+
else if (env.URL) return await proxyURL(env.URL, url);
153+
else return new Response(JSON.stringify(request.cf, null, 4), { status: 200 });
158154
case `/${fakeUserID}`:
159155
const fakeConfig = await getVLESSConfig(userID, request.headers.get('Host'), sub, 'CF-Workers-SUB', RproxyIP, url);
160156
return new Response(`${fakeConfig}`, { status: 200 });
@@ -208,7 +204,9 @@ export default {
208204
}
209205
}
210206
default:
211-
return new Response('Not found', { status: 404 });
207+
if (env.URL302) return Response.redirect(env.URL302, 302);
208+
else if (env.URL) return await proxyURL(env.URL, url);
209+
else return new Response('不用怀疑!你UUID就是错的!!!', { status: 404 });
212210
}
213211
} else {
214212
proxyIP = url.searchParams.get('proxyip') || proxyIP;
@@ -414,7 +412,15 @@ async function handleTCPOutBound(remoteSocket, addressType, addressRemote, portR
414412
tcpSocket = await connectAndWrite(addressRemote, portRemote, true);
415413
} else {
416414
// 否则,尝试使用预设的代理 IP(如果有)或原始地址重试连接
417-
if (!proxyIP || proxyIP == '') proxyIP = atob('cHJveHlpcC5meHhrLmRlZHluLmlv');
415+
if (!proxyIP || proxyIP == '') {
416+
proxyIP = atob('cHJveHlpcC5meHhrLmRlZHluLmlv');
417+
} else if (proxyIP.includes(']:')) {
418+
portRemote = proxyIP.split(']:')[1] || portRemote;
419+
proxyIP = proxyIP.split(']:')[0] || proxyIP;
420+
} else if (proxyIP.split(':').length === 2) {
421+
portRemote = proxyIP.split(':')[1] || portRemote;
422+
proxyIP = proxyIP.split(':')[0] || proxyIP;
423+
}
418424
tcpSocket = await connectAndWrite(proxyIP || addressRemote, portRemote);
419425
}
420426
// 无论重试是否成功,都要关闭 WebSocket(可能是为了重新建立连接)
@@ -1195,6 +1201,46 @@ async function ADD(envadd) {
11951201
return add;
11961202
}
11971203

1204+
async function proxyURL(proxyURL, url) {
1205+
const URLs = await ADD(proxyURL);
1206+
const fullURL = URLs[Math.floor(Math.random() * URLs.length)];
1207+
1208+
// 解析目标 URL
1209+
let parsedURL = new URL(fullURL);
1210+
console.log(parsedURL);
1211+
// 提取并可能修改 URL 组件
1212+
let URLProtocol = parsedURL.protocol.slice(0, -1) || 'https';
1213+
let URLHostname = parsedURL.hostname;
1214+
let URLPathname = parsedURL.pathname;
1215+
let URLSearch = parsedURL.search;
1216+
1217+
// 处理 pathname
1218+
if (URLPathname.charAt(URLPathname.length - 1) == '/') {
1219+
URLPathname = URLPathname.slice(0, -1);
1220+
}
1221+
URLPathname += url.pathname;
1222+
1223+
// 构建新的 URL
1224+
let newURL = `${URLProtocol}://${URLHostname}${URLPathname}${URLSearch}`;
1225+
1226+
// 反向代理请求
1227+
let response = await fetch(newURL);
1228+
1229+
// 创建新的响应
1230+
let newResponse = new Response(response.body, {
1231+
status: response.status,
1232+
statusText: response.statusText,
1233+
headers: response.headers
1234+
});
1235+
1236+
// 添加自定义头部,包含 URL 信息
1237+
//newResponse.headers.set('X-Proxied-By', 'Cloudflare Worker');
1238+
//newResponse.headers.set('X-Original-URL', fullURL);
1239+
newResponse.headers.set('X-New-URL', newURL);
1240+
1241+
return newResponse;
1242+
}
1243+
11981244
function checkSUB(host) {
11991245
if ((!sub || sub == '') && (addresses.length + addressesapi.length + addressesnotls.length + addressesnotlsapi.length + addressescsv.length) == 0){
12001246
addresses = [

0 commit comments

Comments
 (0)