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 8032f7f commit 2201376
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 13 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ Telegram交流群:[@CMLiussss](https://t.me/CMLiussss),**感谢[Alice Networ
| 变量名 | 示例 | 必填 | 备注 | YT |
|--------|---------|-|-----|-----|
| UUID | `90cd4a77-141a-43c9-991b-08263cfe9c10` || Powershell -NoExit -Command "[guid]::NewGuid()"| [Video](https://www.youtube.com/watch?v=s91zjpw3-P8&t=72s) |
| PROXYIP | `proxyip.fxxk.dedyn.io` || 备选作为访问CFCDN站点的代理节点(支持多ProxyIP, ProxyIP之间使用`,``换行`作间隔) | [Video](https://www.youtube.com/watch?v=s91zjpw3-P8&t=166s) |
| PROXYIP | `proxyip.fxxk.dedyn.io:443` || 备选作为访问CFCDN站点的代理节点(支持多ProxyIP, ProxyIP之间使用`,``换行`作间隔) | [Video](https://www.youtube.com/watch?v=s91zjpw3-P8&t=166s) |
| SOCKS5 | `user:[email protected]:1080` || 优先作为访问CFCDN站点的SOCKS5代理(支持多socks5, socks5之间使用`,``换行`作间隔) | [Video](https://www.youtube.com/watch?v=s91zjpw3-P8&t=826s) |
| GO2SOCKS5 | `blog.cmliussss.com`,`*ip111.cn` || 设置`SOCKS5`变量之后,可设置强制使用socks5访问名单(`*`可作为通配符,`换行`作多元素间隔) ||
| GO2SOCKS5 | `blog.cmliussss.com`,`*.ip111.cn`,`*google.com` || 设置`SOCKS5`变量之后,可设置强制使用socks5访问名单(`*`可作为通配符,`换行`作多元素间隔) ||
| ADD | `icook.tw:2053#官方优选域名` || 本地优选TLS域名/优选IP(支持多元素之间`,``换行`作间隔) ||
| ADDAPI | [https://raw.github.../addressesapi.txt](https://raw.githubusercontent.com/cmliu/WorkerVless2sub/main/addressesapi.txt) || 优选IP的API地址(支持多元素之间`,`或 换行 作间隔) ||
| ADDNOTLS | `icook.hk:8080#官方优选域名` || 本地优选noTLS域名/优选IP(支持多元素之间`,``换行`作间隔) ||
Expand All @@ -153,7 +153,7 @@ Telegram交流群:[@CMLiussss](https://t.me/CMLiussss),**感谢[Alice Networ
| SUBNAME | `edgetunnel` || 订阅名称 | |
| RPROXYIP | `false` || 设为 true 即可强制获取订阅器分配的ProxyIP(需订阅器支持)| [Video](https://www.youtube.com/watch?v=s91zjpw3-P8&t=1816s) |
| 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
66 changes: 56 additions & 10 deletions _worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { connect } from 'cloudflare:sockets';
// [Windows] Press "Win + R", input cmd and run: Powershell -NoExit -Command "[guid]::NewGuid()"
let userID = '90cd4a77-141a-43c9-991b-08263cfe9c10';

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

let sub = '';// 避免项目被滥用,现已取消内置订阅器
let subconverter = 'SUBAPI.fxxk.dedyn.io';// clash订阅转换后端,目前使用CM的订阅转换功能。自带虚假uuid和host订阅。
Expand Down Expand Up @@ -148,13 +148,9 @@ export default {
// const url = new URL(request.url);
switch (url.pathname.toLowerCase()) {
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 getVLESSConfig(userID, request.headers.get('Host'), sub, 'CF-Workers-SUB', RproxyIP, url);
return new Response(`${fakeConfig}`, { status: 200 });
Expand Down Expand Up @@ -208,7 +204,9 @@ export default {
}
}
default:
return new Response('Not found', { 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('不用怀疑!你UUID就是错的!!!', { status: 404 });
}
} else {
proxyIP = url.searchParams.get('proxyip') || proxyIP;
Expand Down Expand Up @@ -414,7 +412,15 @@ async function handleTCPOutBound(remoteSocket, addressType, addressRemote, portR
tcpSocket = await connectAndWrite(addressRemote, portRemote, true);
} else {
// 否则,尝试使用预设的代理 IP(如果有)或原始地址重试连接
if (!proxyIP || proxyIP == '') proxyIP = atob('cHJveHlpcC5meHhrLmRlZHluLmlv');
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);
}
// 无论重试是否成功,都要关闭 WebSocket(可能是为了重新建立连接)
Expand Down Expand Up @@ -1195,6 +1201,46 @@ 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 + addressesnotls.length + addressesnotlsapi.length + addressescsv.length) == 0){
addresses = [
Expand Down

0 comments on commit 2201376

Please sign in to comment.