diff --git a/README.md b/README.md index 2b69e07..6b48b66 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,15 @@ ask question and cloudflare ips: [https://t.me/edtunnel](https://t.me/edtunnel) 3. Noneed add `nodejs_compat` at setting Compatibility flags +## How to use non 443 port as proxyIP + +1. got to `https://proxyip.edtunnel.best/` paste your `ProxyIP:proxyport` and click `Check` button. +2. if `Proxy IP` is `true`, you can use this `ProxyIP:proxyport` as `ProxyIP` +3. if `Proxy IP` is `false`, you can see `Origin` is `443` this means the port can be accessed website. +4. edit worker `PROXYIP` variable example `211.230.110.231:50008` + +Note: the proxyIP with port may not vaild some cloudflare site that use http only. + ## How to change UUID 1. edit `wrangler.toml` file `UUID` variable(not recommended at public repo) @@ -53,12 +62,12 @@ ask question and cloudflare ips: [https://t.me/edtunnel](https://t.me/edtunnel) ## Support Environment Variables -| Variable | Required | Example | Description | -| -------------- | -------- | --------------------------------------- | ---------------------------------- | -| `UUID` | No | `12345678-1234-1234-1234-123456789012` | Unique identifier | -| `PROXYIP` | No | `1.1.1.1` or `cdn.xn--b6gac.eu.org` | Redirct cloudflare ips to ProxyIP | -| `SOCKS5` | No | `1.1.1.1:1080` or `user:pass@host:port` | SOCKS5 proxy cloudflare ips | -| `SOCKS5_RELAY` | No | `true` or `false` | Enable SOCKS5 relaying all traffic | +| Variable | Required | Example | Description | +| -------------- | -------- | ----------------------------------------------------------------------------------------------------------- | ---------------------------------- | +| `UUID` | No | `12345678-1234-1234-1234-123456789012` | Unique identifier | +| `PROXYIP` | No | `1.1.1.1` or `cdn.xn--b6gac.eu.org` or with port `1.1.1.1:9443` or `[2a01:4f8:c2c:123f:64:5:6810:c55a]:443` | Redirct cloudflare ips to ProxyIP | +| `SOCKS5` | No | `1.1.1.1:1080` or `user:pass@host:port` | SOCKS5 proxy cloudflare ips | +| `SOCKS5_RELAY` | No | `true` or `false` | Enable SOCKS5 relaying all traffic | ### Enviroment variable setting workers diff --git a/index.js b/index.js index c92c0c1..d2ef6d3 100644 --- a/index.js +++ b/index.js @@ -5,10 +5,15 @@ import { connect } from 'cloudflare:sockets'; // [Windows] Press "Win + R", input cmd and run: Powershell -NoExit -Command "[guid]::NewGuid()" let userID = 'd342d11e-d424-4583-b36e-524ab1f0afa4'; -const proxyIPs = ['cdn.xn--b6gac.eu.org', 'cdn-all.xn--b6gac.eu.org', 'workers.cloudflare.cyou']; +const proxyIPs = ['cdn.xn--b6gac.eu.org:443', 'cdn-all.xn--b6gac.eu.org:443', 'workers.cloudflare.cyou:443']; // if you want to use ipv6 or single proxyIP, please add comment at this line and remove comment at the next line let proxyIP = proxyIPs[Math.floor(Math.random() * proxyIPs.length)]; +// how to make sure the proxyIP with port is valid? +// go to https://proxyip.edtunnel.best/ , input your proxyIP:proxyPort, and click "Check" button +// if the port is valid, value "Proxy IP" is true, otherwise false and the value "Origin" must be 443 +let proxyPort = proxyIP.includes(':') ? proxyIP.split(':')[1] : '443'; + // use single proxyip instead of random // let proxyIP = 'cdn.xn--b6gac.eu.org'; // ipv6 proxyIP example remove comment to use @@ -38,10 +43,16 @@ export default { try { const { UUID, PROXYIP, SOCKS5, SOCKS5_RELAY } = env; userID = UUID || userID; - proxyIP = PROXYIP || proxyIP; socks5Address = SOCKS5 || socks5Address; socks5Relay = SOCKS5_RELAY || socks5Relay; - + if (PROXYIP) { + [proxyIP, proxyPort = '443'] = PROXYIP.split(':'); + } else { + proxyPort = proxyIP.includes(':') ? proxyIP.split(':')[1] : '443'; + proxyIP = proxyIP.split(':')[0]; + } + console.log('ProxyIP:', proxyIP); + console.log('ProxyPort:', proxyPort); if (socks5Address) { try { parsedSocks5Address = socks5AddressParser(socks5Address); @@ -171,18 +182,15 @@ async function ProtocolOverWSHandler(request) { if (hasError) { // controller.error(message); throw new Error(message); // cf seems has bug, controller.error will not end stream - // webSocket.close(1000, message); - return; } - // if UDP but port not DNS port, close it + // Handle UDP connections for DNS (port 53) only if (isUDP) { if (portRemote === 53) { isDns = true; } else { - // controller.error('UDP proxy only enable for DNS which is port 53'); - throw new Error('UDP proxy only enable for DNS which is port 53'); // cf seems has bug, controller.error will not end stream - return; + throw new Error('UDP proxy is only enabled for DNS (port 53)'); } + return; // Early return after setting isDns or throwing error } // ["version", "附加信息长度 N"] const ProtocolResponseHeader = new Uint8Array([ProtocolVersion[0], 0]); @@ -248,7 +256,6 @@ async function trojanOverWSHandler(request) { portWithRandomLog = `${portRemote}--${Math.random()} tcp`; if (hasError) { throw new Error(message); - return; } handleTCPOutBound(remoteSocketWapper, addressRemote, portRemote, rawClientData, webSocket, log, addressType); }, @@ -306,7 +313,7 @@ async function handleTCPOutBound(remoteSocket, addressType, addressRemote, portR if (enableSocks) { tcpSocket = await connectAndWrite(addressRemote, portRemote, true); } else { - tcpSocket = await connectAndWrite(proxyIP || addressRemote, portRemote); + tcpSocket = await connectAndWrite(proxyIP || addressRemote, proxyPort || portRemote); } // no matter retry success or not, close websocket tcpSocket.closed.catch(error => { diff --git a/package.json b/package.json index c76e3fd..58f08f1 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "deploy": "wrangler deploy", "build": "wrangler deploy --dry-run", "dev": "wrangler dev --remote", + "dev-local": "wrangler dev index.js --remote", "obfuscate": "javascript-obfuscator _worker.js" }, "author": "", diff --git a/wrangler.toml b/wrangler.toml index 7a3008d..51c3b31 100644 --- a/wrangler.toml +++ b/wrangler.toml @@ -9,9 +9,5 @@ workers_dev = true [vars] # UUID = "d342d11e-d424-4583-b36e-524ab1f0afa4" -# PROXYIP = "1.2.3.4" -# DNS_RESOLVER_URL = "https://cloudflare-dns.com/dns-query" -# NODE_ID = "1" -# API_TOKEN = "example_dev_token" -# API_HOST = "api.v2board.com" -UUID = "1b6c1745-992e-4aac-8685-266c090e50ea,89b64978-6244-4bf3-bf64-67ade4ce5c8f,d342d11e-d424-4583-b36e-524ab1f0afa4" +PROXYIP = "211.230.110.231:50008" +UUID = "1b6c1745-992e-4aac-8685-266c090e50ea"