mirror of
https://github.com/proxysu/ProxySU.git
synced 2024-11-25 06:36:08 +03:00
add config files
This commit is contained in:
parent
bdac51e8ea
commit
d04553034a
@ -185,7 +185,7 @@
|
||||
<Compile Include="Tools\DateTimeUtils.cs" />
|
||||
<Compile Include="ViewModels\BaseCommand.cs" />
|
||||
<Compile Include="ViewModels\BaseModel.cs" />
|
||||
<Compile Include="ViewModels\Developers\Developer.cs" />
|
||||
<Compile Include="ViewModels\Developers\ConfigBuilder.cs" />
|
||||
<Compile Include="ViewModels\Developers\IParameters.cs" />
|
||||
<Compile Include="ViewModels\Developers\Project.cs" />
|
||||
<Compile Include="ViewModels\Developers\XrayParameters.cs" />
|
||||
@ -235,9 +235,7 @@
|
||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||
</None>
|
||||
<None Include="Templates\xray\base.json" />
|
||||
<None Include="Templates\xray\caddy\Http2Web.caddyfile" />
|
||||
<None Include="Templates\xray\caddy\vlessTcpTlsWeb.caddyfile" />
|
||||
<None Include="Templates\xray\caddy\WebSocketTLSWeb.caddyfile" />
|
||||
<None Include="Templates\xray\caddy\base.caddyfile" />
|
||||
<None Include="Templates\xray\client\00_log\00_log.json" />
|
||||
<None Include="Templates\xray\client\01_api\01_api.json" />
|
||||
<None Include="Templates\xray\client\02_dns\02_dns.json" />
|
||||
@ -250,14 +248,16 @@
|
||||
<None Include="Templates\xray\client\07_transport\07_transport.json" />
|
||||
<None Include="Templates\xray\client\08_stats\08_stats.json" />
|
||||
<None Include="Templates\xray\client\09_reverse\09_reverse.json" />
|
||||
<None Include="Templates\xray\server\00_log\00_log.json" />
|
||||
<None Include="Templates\xray\server\01_api\01_api.json" />
|
||||
<None Include="Templates\xray\server\02_dns\02_dns.json" />
|
||||
<None Include="Templates\xray\server\03_routing\03_routing.json" />
|
||||
<None Include="Templates\xray\server\04_policy\04_policy.json" />
|
||||
<None Include="Templates\xray\server\05_inbounds\05_inbounds.json" />
|
||||
<None Include="Templates\xray\server\05_inbounds\VLESS_HTTP2_TLS.json" />
|
||||
<None Include="Templates\xray\server\05_inbounds\VLESS_TCP_TLS_WS.json" />
|
||||
<None Include="Templates\xray\server\05_inbounds\Trojan_TCP_TLS.json" />
|
||||
<None Include="Templates\xray\server\05_inbounds\VLESS_TCP_XTLS.json" />
|
||||
<None Include="Templates\xray\server\05_inbounds\VLESS_WS_TLS.json" />
|
||||
<None Include="Templates\xray\server\05_inbounds\VMESS_TCP_TLS.json" />
|
||||
<None Include="Templates\xray\server\05_inbounds\VMESS_WS_TLS.json" />
|
||||
<None Include="Templates\xray\server\06_outbounds\06_outbounds.json" />
|
||||
<None Include="Templates\xray\server\07_transport\07_transport.json" />
|
||||
<None Include="Templates\xray\server\08_stats\08_stats.json" />
|
||||
|
@ -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##
|
||||
}
|
@ -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##
|
||||
}
|
5
ProxySU_Core/Templates/xray/caddy/base.caddyfile
Normal file
5
ProxySU_Core/Templates/xray/caddy/base.caddyfile
Normal file
@ -0,0 +1,5 @@
|
||||
##domain##:80 {
|
||||
root * /usr/share/caddy
|
||||
file_server
|
||||
##reverse_proxy##
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
:8800 {
|
||||
root * /usr/share/caddy
|
||||
file_server
|
||||
##reverse_Proxy1##
|
||||
##reverse_Proxy2##
|
||||
##reverse_Proxy3##
|
||||
}
|
||||
##domain##:80 {
|
||||
redir https://##domain##{uri}
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
{
|
||||
"log": {
|
||||
"loglevel": "warning"
|
||||
}
|
||||
}
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
@ -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": [
|
||||
""
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
@ -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": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
@ -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"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
@ -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"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
167
ProxySU_Core/ViewModels/Developers/ConfigBuilder.cs
Normal file
167
ProxySU_Core/ViewModels/Developers/ConfigBuilder.cs
Normal file
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -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; }
|
||||
}
|
||||
}
|
@ -336,6 +336,32 @@ namespace ProxySU_Core.ViewModels.Developers
|
||||
return cmd.Trim() == "1";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 安装 Caddy
|
||||
/// </summary>
|
||||
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 检测系统环境
|
||||
|
@ -26,11 +26,6 @@ namespace ProxySU_Core.ViewModels.Developers
|
||||
/// </summary>
|
||||
public string VlessTcpPath { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// vless http路径
|
||||
/// </summary>
|
||||
public string VlessHttpPath { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// vmess ws路径
|
||||
/// </summary>
|
||||
@ -42,9 +37,14 @@ namespace ProxySU_Core.ViewModels.Developers
|
||||
public string VmessTcpPath { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// vmess http路径
|
||||
/// trojan tcp路径
|
||||
/// </summary>
|
||||
public string VmessHttpPath { get; set; }
|
||||
public string TrojanTcpPath { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// trojan密码
|
||||
/// </summary>
|
||||
public string TrojanPassword { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 域名
|
||||
@ -60,25 +60,39 @@ namespace ProxySU_Core.ViewModels.Developers
|
||||
/// 安装类型
|
||||
/// </summary>
|
||||
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
|
||||
}
|
||||
}
|
||||
|
@ -12,16 +12,19 @@ namespace ProxySU_Core.ViewModels.Developers
|
||||
public class XrayProject : Project<XrayParameters>
|
||||
{
|
||||
|
||||
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<string> 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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user