diff --git a/Cargo.lock b/Cargo.lock index 5764cce..d3412a5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -93,6 +93,12 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + [[package]] name = "block-buffer" version = "0.10.4" @@ -752,12 +758,14 @@ version = "0.1.0" dependencies = [ "aes", "aes-gcm", + "base64", "bytes", "futures-util", "getrandom", "md-5", "pin-project-lite", "serde", + "serde_json", "sha2", "tokio", "uuid", diff --git a/Cargo.toml b/Cargo.toml index c69a6d8..1201215 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,8 @@ crate-type = ["cdylib"] [dependencies] tokio = { version = "1.28", features = ["io-util", "rt"] } serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0" +base64 = "0.22" getrandom = { version = "0.2", features = ["js"] } worker = "0.0.18" futures-util = "0.3.28" diff --git a/README.md b/README.md index 8f9c353..dedfe76 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ and visit https://{YOUR-WORKERS-SUBDOMAIN}.workers.dev/link to get the config li $ make deploy ``` -4. Modify the [xray config](./config/xray.json) and run: +4. Modify the [xray config](./config/vmess.json) and run: ```sh $ xray -c ./config/xray.json ``` diff --git a/config/vless.json b/config/vless.json deleted file mode 100644 index 5800f4d..0000000 --- a/config/vless.json +++ /dev/null @@ -1,43 +0,0 @@ -{ - "log": { - "loglevel": "info" - }, - "inbounds": [ - { - "port": 1085, - "listen": "127.0.0.1", - "protocol": "socks", - "settings": { - "udp": true - } - } - ], - "outbounds": [ - { - "protocol": "vless", - "settings": { - "vnext": [ - { - "address": "CLOUDFLARE_CLEAN_IP", - "port": 80, - "users": [ - { - "id": "0fbf4f81-2598-4b6a-a623-0ead4cb9efa8", - "level": 0, - "encryption": "none" - } - ] - } - ] - }, - "streamSettings": { - "network": "ws", - "wsSettings" : { - "headers": { - "Host": "CF_WORKERS_SUBDOMAIN" - } - } - } - } - ] -} diff --git a/config/vmess.json b/config/vmess.json index 05a743b..c8251d7 100644 --- a/config/vmess.json +++ b/config/vmess.json @@ -18,8 +18,8 @@ "settings": { "vnext": [ { - "address": "CLOUDFLARE_CLEAN_IP", - "port": 80, + "address": "localhost", + "port": 8787, "users": [ { "id": "0fbf4f81-2598-4b6a-a623-0ead4cb9efa8", @@ -32,9 +32,6 @@ "streamSettings": { "network": "ws", "wsSettings" : { - "headers": { - "Host": "CF_WORKERS_SUBDOMAIN" - } } } } diff --git a/src/lib.rs b/src/lib.rs index fc0fae4..f8ab4e8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,7 +5,9 @@ mod proxy; use crate::config::Config; use crate::proxy::*; +use base64::{engine::general_purpose::URL_SAFE, Engine as _}; use serde::Serialize; +use serde_json::json; use uuid::Uuid; use worker::*; @@ -45,13 +47,31 @@ fn link(_: Request, cx: RouteContext) -> Result { link: String, } - let link = format!( - "vmess://{}@104.24.30.167:80?encryption=zero&type=ws&security=none&host={}#tunl", - cx.data.uuid, cx.data.host - ); + let link = { + let host = cx.data.host.to_string(); + let uuid = cx.data.uuid.to_string(); + let config = json!({ + "ps": "tunl", + "v": "2", + "add": "162.159.16.149", + "port": "80", + "id": uuid, + "aid": "0", + "scy": "zero", + "net": "ws", + "type": "none", + "host": host, + "path": "", + "tls": "", + "sni": "", + "alpn": ""} + ); + format!("vmess://{}", URL_SAFE.encode(config.to_string())) + }; Response::from_json(&Link { link, - description: "visit https://scanner.github1.cloud/ and replace the IP address in the configuration with a clean one".to_string() + description: + "visit https://scanner.github1.cloud/ and replace the IP address in the configuration with a clean one".to_string() }) }