예제 #1
0
        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);
        }
예제 #2
0
        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));
        }