From d04553034a9aece9b10f75827f63aa8f4208d2e0 Mon Sep 17 00:00:00 2001 From: next-autumn Date: Sun, 28 Feb 2021 14:19:26 +0800 Subject: [PATCH] add config files --- ProxySU_Core/ProxySU_Core.csproj | 14 +- .../Templates/xray/caddy/Http2Web.caddyfile | 18 -- .../xray/caddy/WebSocketTLSWeb.caddyfile | 18 -- .../Templates/xray/caddy/base.caddyfile | 5 + .../xray/caddy/vlessTcpTlsWeb.caddyfile | 10 -- .../Templates/xray/server/00_log/00_log.json | 5 - .../xray/server/05_inbounds/05_inbounds.json | 2 +- .../server/05_inbounds/Trojan_TCP_TLS.json | 26 +++ .../server/05_inbounds/VLESS_HTTP2_TLS.json | 27 --- .../server/05_inbounds/VLESS_TCP_TLS_WS.json | 24 --- .../server/05_inbounds/VLESS_TCP_XTLS.json | 31 ++++ .../xray/server/05_inbounds/VLESS_WS_TLS.json | 23 +++ .../server/05_inbounds/VMESS_TCP_TLS.json | 29 +++ .../xray/server/05_inbounds/VMESS_WS_TLS.json | 22 +++ .../ViewModels/Developers/ConfigBuilder.cs | 167 ++++++++++++++++++ .../ViewModels/Developers/Developer.cs | 15 -- ProxySU_Core/ViewModels/Developers/Project.cs | 26 +++ .../ViewModels/Developers/XrayParameters.cs | 56 +++--- .../ViewModels/Developers/XrayProject.cs | 150 ++++++---------- 19 files changed, 425 insertions(+), 243 deletions(-) delete mode 100644 ProxySU_Core/Templates/xray/caddy/Http2Web.caddyfile delete mode 100644 ProxySU_Core/Templates/xray/caddy/WebSocketTLSWeb.caddyfile create mode 100644 ProxySU_Core/Templates/xray/caddy/base.caddyfile delete mode 100644 ProxySU_Core/Templates/xray/caddy/vlessTcpTlsWeb.caddyfile delete mode 100644 ProxySU_Core/Templates/xray/server/00_log/00_log.json create mode 100644 ProxySU_Core/Templates/xray/server/05_inbounds/Trojan_TCP_TLS.json delete mode 100644 ProxySU_Core/Templates/xray/server/05_inbounds/VLESS_HTTP2_TLS.json delete mode 100644 ProxySU_Core/Templates/xray/server/05_inbounds/VLESS_TCP_TLS_WS.json create mode 100644 ProxySU_Core/Templates/xray/server/05_inbounds/VLESS_TCP_XTLS.json create mode 100644 ProxySU_Core/Templates/xray/server/05_inbounds/VLESS_WS_TLS.json create mode 100644 ProxySU_Core/Templates/xray/server/05_inbounds/VMESS_TCP_TLS.json create mode 100644 ProxySU_Core/Templates/xray/server/05_inbounds/VMESS_WS_TLS.json create mode 100644 ProxySU_Core/ViewModels/Developers/ConfigBuilder.cs delete mode 100644 ProxySU_Core/ViewModels/Developers/Developer.cs diff --git a/ProxySU_Core/ProxySU_Core.csproj b/ProxySU_Core/ProxySU_Core.csproj index d88a0b8..f54fa71 100644 --- a/ProxySU_Core/ProxySU_Core.csproj +++ b/ProxySU_Core/ProxySU_Core.csproj @@ -185,7 +185,7 @@ - + @@ -235,9 +235,7 @@ Settings.Designer.cs - - - + @@ -250,14 +248,16 @@ - - - + + + + + diff --git a/ProxySU_Core/Templates/xray/caddy/Http2Web.caddyfile b/ProxySU_Core/Templates/xray/caddy/Http2Web.caddyfile deleted file mode 100644 index 7e62dbc..0000000 --- a/ProxySU_Core/Templates/xray/caddy/Http2Web.caddyfile +++ /dev/null @@ -1,18 +0,0 @@ -##domain## { - root * /usr/share/caddy - file_server - tls { - protocols tls1.2 tls1.3 - ciphers TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 - curves x25519 - } - - reverse_proxy ##path## http://localhost:10000 { - transport http { - versions h2c 2 - } - } - ##reverse_Proxy1## - ##reverse_Proxy2## - ##reverse_Proxy3## -} \ No newline at end of file diff --git a/ProxySU_Core/Templates/xray/caddy/WebSocketTLSWeb.caddyfile b/ProxySU_Core/Templates/xray/caddy/WebSocketTLSWeb.caddyfile deleted file mode 100644 index bddb8f6..0000000 --- a/ProxySU_Core/Templates/xray/caddy/WebSocketTLSWeb.caddyfile +++ /dev/null @@ -1,18 +0,0 @@ -##domain## { - root * /usr/share/caddy - file_server - tls { - protocols tls1.2 tls1.3 - ciphers TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 - curves x25519 - } - @xray_websocket { - path ##path## - header Connection *Upgrade* - header Upgrade websocket - } - reverse_proxy @xray_websocket localhost:10000 - ##reverse_Proxy1## - ##reverse_Proxy2## - ##reverse_Proxy3## -} \ No newline at end of file diff --git a/ProxySU_Core/Templates/xray/caddy/base.caddyfile b/ProxySU_Core/Templates/xray/caddy/base.caddyfile new file mode 100644 index 0000000..537fbdc --- /dev/null +++ b/ProxySU_Core/Templates/xray/caddy/base.caddyfile @@ -0,0 +1,5 @@ +##domain##:80 { + root * /usr/share/caddy + file_server + ##reverse_proxy## +} \ No newline at end of file diff --git a/ProxySU_Core/Templates/xray/caddy/vlessTcpTlsWeb.caddyfile b/ProxySU_Core/Templates/xray/caddy/vlessTcpTlsWeb.caddyfile deleted file mode 100644 index 0e9f3d2..0000000 --- a/ProxySU_Core/Templates/xray/caddy/vlessTcpTlsWeb.caddyfile +++ /dev/null @@ -1,10 +0,0 @@ -:8800 { - root * /usr/share/caddy - file_server - ##reverse_Proxy1## - ##reverse_Proxy2## - ##reverse_Proxy3## -} -##domain##:80 { - redir https://##domain##{uri} -} \ No newline at end of file diff --git a/ProxySU_Core/Templates/xray/server/00_log/00_log.json b/ProxySU_Core/Templates/xray/server/00_log/00_log.json deleted file mode 100644 index 6a4cf00..0000000 --- a/ProxySU_Core/Templates/xray/server/00_log/00_log.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "log": { - "loglevel": "warning" - } -} \ No newline at end of file diff --git a/ProxySU_Core/Templates/xray/server/05_inbounds/05_inbounds.json b/ProxySU_Core/Templates/xray/server/05_inbounds/05_inbounds.json index 9a8d634..24465ae 100644 --- a/ProxySU_Core/Templates/xray/server/05_inbounds/05_inbounds.json +++ b/ProxySU_Core/Templates/xray/server/05_inbounds/05_inbounds.json @@ -1,3 +1,3 @@ { - "inbounds": [] + "inbounds": [] } diff --git a/ProxySU_Core/Templates/xray/server/05_inbounds/Trojan_TCP_TLS.json b/ProxySU_Core/Templates/xray/server/05_inbounds/Trojan_TCP_TLS.json new file mode 100644 index 0000000..0aca4d2 --- /dev/null +++ b/ProxySU_Core/Templates/xray/server/05_inbounds/Trojan_TCP_TLS.json @@ -0,0 +1,26 @@ +{ + "port": 1310, + "listen": "127.0.0.1", + "protocol": "trojan", + "settings": { + "clients": [ + { + "password": "", + "level": 0, + "email": "love@example.com" + } + ], + "fallbacks": [ + { + "dest": 80 + } + ] + }, + "streamSettings": { + "network": "tcp", + "security": "none", + "tcpSettings": { + "acceptProxyProtocol": true + } + } +} diff --git a/ProxySU_Core/Templates/xray/server/05_inbounds/VLESS_HTTP2_TLS.json b/ProxySU_Core/Templates/xray/server/05_inbounds/VLESS_HTTP2_TLS.json deleted file mode 100644 index a9e1b2f..0000000 --- a/ProxySU_Core/Templates/xray/server/05_inbounds/VLESS_HTTP2_TLS.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "inbounds": [ - { - "port": 10000, - "listen": "127.0.0.1", - "protocol": "vless", - "settings": { - "clients": [ - { - "id": "" - } - ], - "decryption": "none" - }, - "streamSettings": { - "security": "none", - "network": "h2", - "httpSettings": { - "path": "", - "host": [ - "" - ] - } - } - } - ] -} diff --git a/ProxySU_Core/Templates/xray/server/05_inbounds/VLESS_TCP_TLS_WS.json b/ProxySU_Core/Templates/xray/server/05_inbounds/VLESS_TCP_TLS_WS.json deleted file mode 100644 index fa16dbf..0000000 --- a/ProxySU_Core/Templates/xray/server/05_inbounds/VLESS_TCP_TLS_WS.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "inbounds": [ - { - "port": 443, - "listen": "127.0.0.1", - "protocol": "vless", - "settings": { - "clients": [ - { - "id": "" - } - ], - "decryption": "none" - }, - "streamSettings": { - "network": "ws", - "security": "none", - "wsSettings": { - "path": "" - } - } - } - ] -} \ No newline at end of file diff --git a/ProxySU_Core/Templates/xray/server/05_inbounds/VLESS_TCP_XTLS.json b/ProxySU_Core/Templates/xray/server/05_inbounds/VLESS_TCP_XTLS.json new file mode 100644 index 0000000..07a491a --- /dev/null +++ b/ProxySU_Core/Templates/xray/server/05_inbounds/VLESS_TCP_XTLS.json @@ -0,0 +1,31 @@ +{ + "port": 443, + "protocol": "vless", + "settings": { + "clients": [ + { + "id": "", + "flow": "xtls-rprx-direct", + "level": 0, + "email": "love@example.com" + } + ], + "decryption": "none", + "fallbacks": [] + }, + "streamSettings": { + "network": "tcp", + "security": "xtls", + "xtlsSettings": { + "alpn": [ + "http/1.1" + ], + "certificates": [ + { + "certificateFile": "/usr/local/etc/xray/ssl/xray_ssl.crt", + "keyFile": "/usr/local/etc/xray/ssl/xray_ssl.key" + } + ] + } + } +} \ No newline at end of file diff --git a/ProxySU_Core/Templates/xray/server/05_inbounds/VLESS_WS_TLS.json b/ProxySU_Core/Templates/xray/server/05_inbounds/VLESS_WS_TLS.json new file mode 100644 index 0000000..1b7d25c --- /dev/null +++ b/ProxySU_Core/Templates/xray/server/05_inbounds/VLESS_WS_TLS.json @@ -0,0 +1,23 @@ +{ + "port": 1234, + "listen": "127.0.0.1", + "protocol": "vless", + "settings": { + "clients": [ + { + "id": "", + "level": 0, + "email": "love@example.com" + } + ], + "decryption": "none" + }, + "streamSettings": { + "network": "ws", + "security": "none", + "wsSettings": { + "acceptProxyProtocol": true, + "path": "/websocket" + } + } +} diff --git a/ProxySU_Core/Templates/xray/server/05_inbounds/VMESS_TCP_TLS.json b/ProxySU_Core/Templates/xray/server/05_inbounds/VMESS_TCP_TLS.json new file mode 100644 index 0000000..015d566 --- /dev/null +++ b/ProxySU_Core/Templates/xray/server/05_inbounds/VMESS_TCP_TLS.json @@ -0,0 +1,29 @@ +{ + "port": 443, + "listen": "127.0.0.1", + "protocol": "vmess", + "settings": { + "clients": [ + { + "id": "", + "level": 0, + "email": "love@example.com" + } + ] + }, + "streamSettings": { + "network": "tcp", + "security": "none", + "tcpSettings": { + "acceptProxyProtocol": true, + "header": { + "type": "http", + "request": { + "path": [ + "/vmesstcp" + ] + } + } + } + } +}, diff --git a/ProxySU_Core/Templates/xray/server/05_inbounds/VMESS_WS_TLS.json b/ProxySU_Core/Templates/xray/server/05_inbounds/VMESS_WS_TLS.json new file mode 100644 index 0000000..bbf6dbb --- /dev/null +++ b/ProxySU_Core/Templates/xray/server/05_inbounds/VMESS_WS_TLS.json @@ -0,0 +1,22 @@ +{ + "port": 3456, + "listen": "127.0.0.1", + "protocol": "vmess", + "settings": { + "clients": [ + { + "id": "", + "level": 0, + "email": "love@example.com" + } + ] + }, + "streamSettings": { + "network": "ws", + "security": "none", + "wsSettings": { + "acceptProxyProtocol": true, + "path": "/vmessws" + } + } +} diff --git a/ProxySU_Core/ViewModels/Developers/ConfigBuilder.cs b/ProxySU_Core/ViewModels/Developers/ConfigBuilder.cs new file mode 100644 index 0000000..6bc02f8 --- /dev/null +++ b/ProxySU_Core/ViewModels/Developers/ConfigBuilder.cs @@ -0,0 +1,167 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; + +namespace ProxySU_Core.ViewModels.Developers +{ + public class ConfigBuilder + { + public dynamic xrayConfig { get; set; } + public string CaddyConfig { get; set; } + + private const string ServerLogDir = @"Templates\xray\server\00_log"; + private const string ServerApiDir = @"Templates\xray\server\01_api"; + private const string ServerDnsDir = @"Templates\xray\server\02_dns"; + private const string ServerRoutingDir = @"Templates\xray\server\03_routing"; + private const string ServerPolicyDir = @"Templates\xray\server\04_policy"; + private const string ServerInboundsDir = @"Templates\xray\server\05_inbounds"; + private const string ServerOutboundsDir = @"Templates\xray\server\06_outbounds"; + private const string ServerTransportDir = @"Templates\xray\server\07_transport"; + private const string ServerStatsDir = @"Templates\xray\server\08_stats"; + private const string ServerReverseDir = @"Templates\xray\server\09_reverse"; + private const string CaddyFileDir = @"Templates\xray\caddy"; + + public const int VLESS_TCP_Port = 1110; + public const int VLESS_WS_Port = 1111; + public const int VMESS_TCP_Port = 2110; + public const int VMESS_WS_Port = 2111; + public const int Trojan_TCP_Port = 3110; + + + public static dynamic LoadXrayConfig() + { + dynamic logObj = LoadJsonObj(Path.Combine(ServerLogDir, "00_log.json")); + dynamic apiObj = LoadJsonObj(Path.Combine(ServerApiDir, "01_api.json")); + dynamic dnsObj = LoadJsonObj(Path.Combine(ServerDnsDir, "02_dns.json")); + dynamic routingObj = LoadJsonObj(Path.Combine(ServerRoutingDir, "03_routing.json")); + dynamic policyObj = LoadJsonObj(Path.Combine(ServerPolicyDir, "04_policy.json")); + dynamic inboundsObj = LoadJsonObj(Path.Combine(ServerInboundsDir, "05_inbounds.json")); + dynamic outboundsObj = LoadJsonObj(Path.Combine(ServerOutboundsDir, "06_outbounds.json")); + dynamic transportObj = LoadJsonObj(Path.Combine(ServerTransportDir, "07_transport.json")); + dynamic statsObj = LoadJsonObj(Path.Combine(ServerStatsDir, "08_stats.json")); + dynamic reverseObj = LoadJsonObj(Path.Combine(ServerReverseDir, "09_reverse.json")); + + return new + { + log = logObj["log"], + api = apiObj["api"], + dns = dnsObj["dns"], + routing = routingObj["routing"], + policy = policyObj["policy"], + inbounds = inboundsObj["inbounds"], + outbounds = outboundsObj["outbounds"], + transport = transportObj["transport"], + stats = statsObj["stats"], + reverse = reverseObj["reverse"] + }; + + + } + + public static string BuildCaddyConfig(XrayParameters parameters) + { + var caddyStr = File.ReadAllText(Path.Combine(CaddyFileDir, "base.caddyfile")); + caddyStr.Replace("##domain##", parameters.Domain); + if (!string.IsNullOrEmpty(parameters.MaskDomain)) + { + caddyStr.Replace("##server_proxy##", $"reverse_proxy http://{parameters.MaskDomain} {{ header_up Host {parameters.MaskDomain} }}"); + } + else + { + caddyStr.Replace("##server_proxy##", ""); + } + + return caddyStr; + } + + public static string BuildXrayConfig(XrayParameters parameters) + { + var xrayConfig = LoadXrayConfig(); + var baseBound = LoadJsonObj(Path.Combine(ServerInboundsDir, "VLESS_TCP_XTLS.json")); + baseBound["port"] = VLESS_TCP_Port; + baseBound["settings"]["fallbacks"].Add(new + { + dest = 80, + xver = 1, + }); + xrayConfig["inbounds"].Add(baseBound); + + switch (parameters.Type) + { + case XrayType.VLESS_TCP_TLS: + case XrayType.VLESS_TCP_XTLS: + baseBound["settings"]["clients"][0]["id"] = parameters.UUID; + break; + case XrayType.VLESS_WS_TLS: + var wsInbound = LoadJsonObj(Path.Combine(ServerInboundsDir, "VLESS_WS_TLS.json")); + wsInbound["port"] = VLESS_WS_Port; + wsInbound["settings"]["clients"][0]["id"] = parameters.UUID; + wsInbound["streamSettings"]["wsSettings"]["path"] = parameters.VlessWsPath; + baseBound["settings"]["fallbacks"].Add(new + { + dest = VLESS_WS_Port, + path = parameters.VlessWsPath, + xver = 1, + }); + xrayConfig["inbounds"].Add(wsInbound); + break; + case XrayType.VMESS_TCP_TLS: + var mtcpBound = LoadJsonObj(Path.Combine(ServerInboundsDir, "VMESS_TCP_TLS.json")); + mtcpBound["port"] = VMESS_TCP_Port; + mtcpBound["settings"]["clients"][0]["id"] = parameters.UUID; + mtcpBound["streamSettings"]["tcpSettings"]["header"]["request"]["path"] = parameters.VmessTcpPath; + baseBound["settings"]["fallbacks"].Add(new + { + dest = VMESS_TCP_Port, + path = parameters.VmessTcpPath, + xver = 1, + }); + xrayConfig["inbounds"].Add(mtcpBound); + break; + case XrayType.VMESS_WS_TLS: + var mwsBound = LoadJsonObj(Path.Combine(ServerInboundsDir, "VMESS_WS_TLS.json")); + mwsBound["port"] = VMESS_WS_Port; + mwsBound["settings"]["clients"][0]["id"] = parameters.UUID; + mwsBound["streamSettings"]["wsSettings"]["path"] = parameters.VmessWsPath; + baseBound["settings"]["fallbacks"].Add(new + { + dest = VMESS_WS_Port, + path = parameters.VmessWsPath, + xver = 1, + }); + xrayConfig["inbounds"].Add(mwsBound); + break; + case XrayType.Trojan_TCP_TLS: + var trojanTcpBound = LoadJsonObj(Path.Combine(ServerInboundsDir, "Trojan_TCP_TLS.json")); + trojanTcpBound["port"] = Trojan_TCP_Port; + trojanTcpBound["settings"]["clients"][0]["password"] = parameters.TrojanPassword; + baseBound["settings"]["fallbacks"][0] = new + { + dest = Trojan_TCP_Port, + xver = 1, + }; + xrayConfig["inbounds"].Add(trojanTcpBound); + break; + default: + break; + } + + return JsonConvert.SerializeObject(xrayConfig, Formatting.Indented); + } + + private static dynamic LoadJsonObj(string path) + { + if (File.Exists(path)) + { + var jsonStr = File.ReadAllText(path, Encoding.UTF8); + return JsonConvert.DeserializeObject(jsonStr); + } + return null; + } + + } + +} diff --git a/ProxySU_Core/ViewModels/Developers/Developer.cs b/ProxySU_Core/ViewModels/Developers/Developer.cs deleted file mode 100644 index 9488632..0000000 --- a/ProxySU_Core/ViewModels/Developers/Developer.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace ProxySU_Core.ViewModels.Developers -{ - public class Developer - { - public string Name { get; set; } - - public string TemplateName { get; set; } - - public string Description { get; set; } - } -} diff --git a/ProxySU_Core/ViewModels/Developers/Project.cs b/ProxySU_Core/ViewModels/Developers/Project.cs index bef77c6..de90a6a 100644 --- a/ProxySU_Core/ViewModels/Developers/Project.cs +++ b/ProxySU_Core/ViewModels/Developers/Project.cs @@ -336,6 +336,32 @@ namespace ProxySU_Core.ViewModels.Developers return cmd.Trim() == "1"; } + /// + /// 安装 Caddy + /// + protected void InstallCaddy() + { + if (CmdType == CmdType.Apt) + { + RunCmd("sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https"); + RunCmd("curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo apt-key add -"); + RunCmd("curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee -a /etc/apt/sources.list.d/caddy-stable.list"); + RunCmd("sudo apt update"); + RunCmd("sudo apt install caddy"); + } + else if (CmdType == CmdType.Dnf) + { + RunCmd("dnf install 'dnf-command(copr)'"); + RunCmd("dnf copr enable @caddy/caddy"); + RunCmd("dnf install caddy"); + } + else if (CmdType == CmdType.Yum) + { + RunCmd("yum install yum-plugin-copr"); + RunCmd("yum copr enable @caddy/caddy"); + RunCmd("yum install caddy"); + } + } #region 检测系统环境 diff --git a/ProxySU_Core/ViewModels/Developers/XrayParameters.cs b/ProxySU_Core/ViewModels/Developers/XrayParameters.cs index cb612bb..4c47c32 100644 --- a/ProxySU_Core/ViewModels/Developers/XrayParameters.cs +++ b/ProxySU_Core/ViewModels/Developers/XrayParameters.cs @@ -25,11 +25,6 @@ namespace ProxySU_Core.ViewModels.Developers /// vless tcp路径 /// public string VlessTcpPath { get; set; } - - /// - /// vless http路径 - /// - public string VlessHttpPath { get; set; } /// /// vmess ws路径 @@ -42,9 +37,14 @@ namespace ProxySU_Core.ViewModels.Developers public string VmessTcpPath { get; set; } /// - /// vmess http路径 + /// trojan tcp路径 /// - public string VmessHttpPath { get; set; } + public string TrojanTcpPath { get; set; } + + /// + /// trojan密码 + /// + public string TrojanPassword { get; set; } /// /// 域名 @@ -60,25 +60,39 @@ namespace ProxySU_Core.ViewModels.Developers /// 安装类型 /// public XrayType Type { get; set; } + + + public string GetPath() + { + switch (Type) + { + case XrayType.VLESS_TCP_TLS: + return VlessTcpPath; + case XrayType.VLESS_TCP_XTLS: + return VlessTcpPath; + case XrayType.VLESS_WS_TLS: + return VlessWsPath; + case XrayType.VMESS_TCP_TLS: + return VmessTcpPath; + case XrayType.VMESS_WS_TLS: + return VmessWsPath; + case XrayType.Trojan_TCP_TLS: + return TrojanTcpPath; + default: + return string.Empty; + } + } } public enum XrayType { - Shadowsocks_AEAD, - Shadowsocks_TCP, - Sockets5_TLS, - Trojan_TCP_TLS, + VLESS_TCP_TLS, + VLESS_TCP_XTLS, + VLESS_WS_TLS, - // vless - VLESS_H2C_Caddy2, - VLESS_TCP_TLS_WS, - VLESS_TCP_XTLS_WHATEVER, - VLESS_mKCPSeed, + VMESS_TCP_TLS, + VMESS_WS_TLS, - // vmess - VMess_HTTP2, - VMess_TCP_TLS, - VMess_WebSocket_TLS, - VMess_mKCPSeed, + Trojan_TCP_TLS } } diff --git a/ProxySU_Core/ViewModels/Developers/XrayProject.cs b/ProxySU_Core/ViewModels/Developers/XrayProject.cs index 7ef84d3..70c2e7a 100644 --- a/ProxySU_Core/ViewModels/Developers/XrayProject.cs +++ b/ProxySU_Core/ViewModels/Developers/XrayProject.cs @@ -12,16 +12,19 @@ namespace ProxySU_Core.ViewModels.Developers public class XrayProject : Project { - private const string ServerLogPath = "/Templates/xray/server/00_log/00_log.json"; - private const string ServerApiPath = "/Templates/xray/server/01_api/01_api.json"; - private const string ServerDnsPath = "/Templates/xray/server/02_dns/02_dns.json"; - private const string ServerRoutingPath = "/Templates/xray/server/03_routing/03_routing.json"; - private const string ServerPolicyPath = "/Templates/xray/server/04_policy/04_policy.json"; - private const string ServerInboundsPath = "/Templates/xray/server/05_inbounds/05_inbounds.json"; - private const string ServerOutboundsPath = "/Templates/xray/server/06_outbounds/06_outbounds.json"; - private const string ServerTransportPath = "/Templates/xray/server/07_transport/07_transport.json"; - private const string ServerStatsPath = "/Templates/xray/server/08_stats/08_stats.json"; - private const string ServerReversePath = "/Templates/xray/server/09_reverse/09_reverse.json"; + private const string ServerLogDir = @"Templates\xray\server\00_log"; + private const string ServerApiDir = @"Templates\xray\server\01_api"; + private const string ServerDnsDir = @"Templates\xray\server\02_dns"; + private const string ServerRoutingDir = @"Templates\xray\server\03_routing"; + private const string ServerPolicyDir = @"Templates\xray\server\04_policy"; + private const string ServerInboundsDir = @"Templates\xray\server\05_inbounds"; + private const string ServerOutboundsDir = @"Templates\xray\server\06_outbounds"; + private const string ServerTransportDir = @"Templates\xray\server\07_transport"; + private const string ServerStatsDir = @"Templates\xray\server\08_stats"; + private const string ServerReverseDir = @"Templates\xray\server\09_reverse"; + private const string CaddyFileDir = @"Templates\xray\caddy"; + + private int randomCaddyListenPort = 8800; public XrayProject(SshClient sshClient, XrayParameters parameters, Action writeOutput) : base(sshClient, parameters, writeOutput) { @@ -55,7 +58,11 @@ namespace ProxySU_Core.ViewModels.Developers ValidateDomain(); - InstallXray(); + InstallXrayWithCert(); + + InstallCaddy(); + + UploadCaddyFile(); } catch (Exception ex) { @@ -63,7 +70,16 @@ namespace ProxySU_Core.ViewModels.Developers } } - private void InstallXray() + private void UploadCaddyFile() + { + var configJson = ConfigBuilder.BuildCaddyConfig(Parameters); + var stream = new MemoryStream(Encoding.UTF8.GetBytes(configJson)); + RunCmd("mv /etc/caddy/Caddyfile /etc/caddy/Caddyfile.back"); + UploadFile(stream, "/etc/caddy/Caddyfile"); + RunCmd("systemctl reload caddy"); + } + + private void InstallXrayWithCert() { RunCmd("bash -c \"$(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh)\" @ install"); @@ -82,88 +98,16 @@ namespace ProxySU_Core.ViewModels.Developers RunCmd(@"mv /usr/local/etc/xray/config.json /usr/local/etc/xray/config.json.1"); } - UploadXrayConfig(); + InstallCertToXray(); + + + var configJson = ConfigBuilder.BuildXrayConfig(Parameters); + var stream = new MemoryStream(Encoding.UTF8.GetBytes(configJson)); + RunCmd("rm -rf /usr/local/etc/xray/config.json"); + UploadFile(stream, "/usr/local/etc/xray/config.json"); } - private int GetRandomPort() - { - var random = new Random(); - return random.Next(10001, 60000); - } - - private void UploadXrayConfig() - { - dynamic logObj = JsonConvert.DeserializeObject(File.ReadAllText(ServerLogPath)); - dynamic apiObj = JsonConvert.DeserializeObject(File.ReadAllText(ServerApiPath)); - dynamic dnsObj = JsonConvert.DeserializeObject(File.ReadAllText(ServerDnsPath)); - dynamic routingObj = JsonConvert.DeserializeObject(File.ReadAllText(ServerRoutingPath)); - dynamic policyObj = JsonConvert.DeserializeObject(File.ReadAllText(ServerPolicyPath)); - dynamic inboundsObj = JsonConvert.DeserializeObject(File.ReadAllText(ServerInboundsPath)); - dynamic outboundsObj = JsonConvert.DeserializeObject(File.ReadAllText(ServerOutboundsPath)); - dynamic transportObj = JsonConvert.DeserializeObject(File.ReadAllText(ServerTransportPath)); - dynamic statsObj = JsonConvert.DeserializeObject(File.ReadAllText(ServerStatsPath)); - dynamic reverseObj = JsonConvert.DeserializeObject(File.ReadAllText(ServerReversePath)); - - switch (Parameters.Type) - { - case XrayType.Shadowsocks_AEAD: - break; - case XrayType.Shadowsocks_TCP: - break; - case XrayType.Sockets5_TLS: - break; - case XrayType.Trojan_TCP_TLS: - break; - case XrayType.VLESS_H2C_Caddy2: - inboundsObj = JsonConvert.DeserializeObject(File.ReadAllText("/Templates/xray/server/05_inbounds/VLESS_HTTP2_TLS.json")); - inboundsObj[0]["port"] = GetRandomPort(); - inboundsObj[0]["settings"]["clients"][0]["id"] = Parameters.UUID; - inboundsObj[0]["streamSettings"]["httpSettings"]["path"] = Parameters.VlessHttpPath; - inboundsObj[0]["streamSettings"]["httpSettings"]["host"][0] = Parameters.Domain; - break; - case XrayType.VLESS_TCP_TLS_WS: - inboundsObj = JsonConvert.DeserializeObject(File.ReadAllText("/Templates/xray/server/05_inbounds/VLESS_TCP_TLS_WS.json")); - inboundsObj[0]["port"] = GetRandomPort(); - inboundsObj[0]["settings"]["clients"][0]["id"] = Parameters.UUID; - inboundsObj[0]["streamSettings"]["httpSettings"]["path"] = Parameters.VlessWsPath; - break; - case XrayType.VLESS_TCP_XTLS_WHATEVER: - break; - case XrayType.VLESS_mKCPSeed: - break; - case XrayType.VMess_HTTP2: - break; - case XrayType.VMess_TCP_TLS: - break; - case XrayType.VMess_WebSocket_TLS: - break; - case XrayType.VMess_mKCPSeed: - break; - default: - break; - } - - var serverConfig = new - { - log = logObj["log"], - api = apiObj["api"], - dns = dnsObj["dns"], - routing = routingObj["routing"], - policy = policyObj["policy"], - inbounds = inboundsObj["inbounds"], - outbounds = outboundsObj["outbounds"], - transport = transportObj["transport"], - stats = statsObj["stats"], - reverse = reverseObj["reverse"] - }; - - var json = JsonConvert.SerializeObject(serverConfig); - var jsonStream = new MemoryStream(Encoding.UTF8.GetBytes(json)); - UploadFile(jsonStream, "/usr/local/etc/xray/config.json"); - jsonStream.Dispose(); - } - - private void InstallCert() + private void InstallCertToXray() { // 安装依赖 RunCmd(GetInstallCmd("socat")); @@ -223,16 +167,28 @@ namespace ProxySU_Core.ViewModels.Developers RunCmd(@"chmod 644 /usr/local/etc/xray/ssl/xray_ssl.key"); } - private void InstallCaddy() - { - - } - private string GetRandomEmail() { Random r = new Random(); var num = r.Next(200000000, 900000000); return $"{num}@qq.com"; } + + private int GetRandomPort() + { + var random = new Random(); + return random.Next(10001, 60000); + } + + private dynamic LoadJsonObj(string path) + { + if (File.Exists(path)) + { + var jsonStr = File.ReadAllText(path, Encoding.UTF8); + return JsonConvert.DeserializeObject(jsonStr); + } + return null; + } + } }