Exemple #1
0
        private static void inbound(Server server, ref V2rayConfig v2rayConfig)
        {
            try
            {
                var inbound = new Inbounds
                {
                    port     = Global.Settings.Socks5LocalPort,
                    protocol = "socks",
                    listen   = Global.Settings.LocalAddress,
                    settings = new Inboundsettings
                    {
                        udp = true
                    }
                };

                v2rayConfig.inbounds = new List <Inbounds>
                {
                    inbound
                };
            }
            catch
            {
                // ignored
            }
        }
        private static void routing(Server server, Mode mode, ref V2rayConfig v2rayConfig)
        {
            try
            {
                var directRuleObject = new RulesItem
                {
                    type        = "field",
                    ip          = new List <string>(),
                    domain      = new List <string>(),
                    outboundTag = "direct"
                };

                var blockRuleObject = new RulesItem
                {
                    type        = "field",
                    ip          = new List <string>(),
                    domain      = new List <string>(),
                    outboundTag = "block"
                };

                if (mode.BypassChina)
                {
                    switch (mode.Type)
                    {
                    case 0:
                        directRuleObject.ip.Add("geoip:cn");
                        break;

                    case 1:
                    case 2:
                        if (Global.Flags.SupportFakeDns && Global.Settings.TUNTAP.UseFakeDNS)
                        {
                            directRuleObject.domain.Add("geosite:cn");
                        }
                        else
                        {
                            directRuleObject.ip.Add("geoip:cn");
                        }
                        break;

                    default:
                        directRuleObject.domain.Add("geosite:cn");
                        break;
                    }
                }

                if (mode.Type is 0 or 1 or 2)
                {
                    blockRuleObject.ip.Add("geoip:private");
                }

                v2rayConfig.routing = new Routing
                {
                    rules = new List <RulesItem>()
                };
Exemple #3
0
        private static void routing(Server server, Mode mode, ref V2rayConfig v2rayConfig)
        {
            try
            {
                RulesItem rulesItem;
                if (mode.BypassChina)
                {
                    rulesItem = new RulesItem
                    {
                        type = "field",
                        ip   = new List <string>
                        {
                            "geoip:cn",
                            "geoip:private"
                        },
                        domain = new List <string>
                        {
                            "geosite:cn"
                        },
                        outboundTag = "direct"
                    };
                }
                else
                {
                    rulesItem = new RulesItem
                    {
                        type = "field",
                        ip   = new List <string>
                        {
                            "geoip:private"
                        },
                        outboundTag = "direct"
                    };
                }

                v2rayConfig.routing = new Routing
                {
                    rules = new List <RulesItem>
                    {
                        rulesItem
                    }
                };
            }
            catch
            {
                // ignored
            }
        }
Exemple #4
0
        public static string GenerateClientConfig(Server server, Mode mode)
        {
            try
            {
                var v2rayConfig = new V2rayConfig();

                inbound(server, ref v2rayConfig);

                routing(server, mode, ref v2rayConfig);

                outbound(server, mode, ref v2rayConfig);

                return(JsonConvert.SerializeObject(v2rayConfig));
            }
            catch
            {
                return("");
            }
        }
Exemple #5
0
        public static string GenerateClientConfig(Server server, Mode mode)
        {
            try
            {
                var v2rayConfig = new V2rayConfig();

                inbound(server, ref v2rayConfig);

                routing(server, mode, ref v2rayConfig);

                outbound(server, mode, ref v2rayConfig);

                return(JsonConvert.SerializeObject(v2rayConfig, Formatting.Indented, new JsonSerializerSettings {
                    NullValueHandling = NullValueHandling.Ignore
                }));
            }
            catch
            {
                return("");
            }
        }
Exemple #6
0
        private static void outbound(Server server, Mode mode, ref V2rayConfig v2rayConfig)
        {
            try
            {
                var outbound = new Outbounds
                {
                    settings       = new Outboundsettings(),
                    mux            = new Mux(),
                    streamSettings = new StreamSettings
                    {
                        network = "tcp"
                    }
                };

                switch (server)
                {
                case Socks5.Socks5 socks5:
                {
                    var serversItem = new ServersItem
                    {
                        users = new List <SocksUsersItem>()
                    };
                    outbound.settings.servers = new List <ServersItem>
                    {
                        serversItem
                    };

                    serversItem.address  = server.AutoResolveHostname();
                    serversItem.port     = server.Port;
                    serversItem.method   = null;
                    serversItem.password = null;

                    if (socks5.Auth())
                    {
                        var socksUsersItem = new SocksUsersItem
                        {
                            user  = socks5.Username,
                            pass  = socks5.Password,
                            level = 1
                        };

                        serversItem.users.Add(socksUsersItem);
                    }

                    outbound.mux.enabled     = false;
                    outbound.mux.concurrency = -1;
                    outbound.protocol        = "socks";
                    break;
                }

                case VLESS.VLESS vless:
                {
                    var vnextItem = new VnextItem
                    {
                        users = new List <UsersItem>()
                    };
                    outbound.settings.vnext = new List <VnextItem>
                    {
                        vnextItem
                    };

                    vnextItem.address = server.AutoResolveHostname();
                    vnextItem.port    = server.Port;

                    var usersItem = new UsersItem();
                    vnextItem.users.Add(usersItem);

                    usersItem.id         = vless.UserID;
                    usersItem.alterId    = 0;
                    usersItem.flow       = string.Empty;
                    usersItem.encryption = vless.EncryptMethod;

                    outbound.mux.enabled     = vless.UseMux ?? Global.Settings.V2RayConfig.UseMux;
                    outbound.mux.concurrency = vless.UseMux ?? Global.Settings.V2RayConfig.UseMux ? 8 : -1;

                    var streamSettings = outbound.streamSettings;
                    boundStreamSettings(vless, ref streamSettings);

                    if (vless.TransferProtocol == "xtls")
                    {
                        usersItem.flow = string.IsNullOrEmpty(vless.Flow) ? "xtls-rprx-origin" : vless.Flow;

                        outbound.mux.enabled     = false;
                        outbound.mux.concurrency = -1;
                    }

                    outbound.protocol         = "vless";
                    outbound.settings.servers = null;
                    break;
                }

                case VMess vmess:
                {
                    var vnextItem = new VnextItem
                    {
                        users = new List <UsersItem>()
                    };
                    outbound.settings.vnext = new List <VnextItem>
                    {
                        vnextItem
                    };

                    vnextItem.address = server.AutoResolveHostname();
                    vnextItem.port    = server.Port;

                    var usersItem = new UsersItem();
                    vnextItem.users.Add(usersItem);

                    usersItem.id       = vmess.UserID;
                    usersItem.alterId  = vmess.AlterID;
                    usersItem.security = vmess.EncryptMethod;

                    outbound.mux.enabled     = vmess.UseMux ?? Global.Settings.V2RayConfig.UseMux;
                    outbound.mux.concurrency = vmess.UseMux ?? Global.Settings.V2RayConfig.UseMux ? 8 : -1;

                    var streamSettings = outbound.streamSettings;
                    boundStreamSettings(vmess, ref streamSettings);

                    outbound.protocol = "vmess";
                    break;
                }
                }

                v2rayConfig.outbounds = new List <Outbounds>
                {
                    outbound,
                    new Outbounds
                    {
                        tag      = "direct",
                        protocol = "freedom"
                    }
                };
            }
            catch
            {
                // ignored
            }
        }