Esempio n. 1
0
        /// <summary>
        ///		启动
        /// </summary>
        /// <param name="server">服务器</param>
        /// <param name="mode">模式</param>
        /// <returns>是否启动成功</returns>
        public bool Start(Objects.Server server, Objects.Mode mode)
        {
            var result = false;

            switch (server.Type)
            {
            case "Socks5":
                result = true;
                break;

            case "Shadowsocks":
                result = pSSController.Start(server, mode);
                break;

            case "ShadowsocksR":
                result = pSSRController.Start(server, mode);
                break;

            case "VMess":
                result = pVMessController.Start(server, mode);
                break;

            default:
                break;
            }

            if (result)
            {
                if (mode.Type == 0)
                {
                    result = pNFController.Start(server, mode);
                }
                else if (mode.Type == 1)
                {
                    result = pTUNTAPController.Start(server, mode);
                }
                else if (mode.Type == 2)
                {
                    result = pTUNTAPController.Start(server, mode);
                }
                else if (mode.Type == 3)
                {
                    result = pHTTPController.Start(server, mode);
                }
            }

            if (!result)
            {
                Stop();
            }

            return(result);
        }
Esempio n. 2
0
        /// <summary>
        ///		启动
        /// </summary>
        /// <param name="server">服务器</param>
        /// <param name="mode">模式</param>
        /// <returns>是否启动成功</returns>
        public bool Start(Objects.Server server, Objects.Mode mode)
        {
            var result = false;

            switch (server.Type)
            {
            //case "Socks5":
            //    result = true;
            //    System.Windows.Forms.MessageBox.Show("Socks5");
            //    break;
            //case "Shadowsocks":
            //    result = pSSController.Start(server, mode);
            //    System.Windows.Forms.MessageBox.Show("Shadowsocks");
            //    break;
            case "ShadowsocksR":
                result = pSSRController.Start(server, mode);
                //System.Windows.Forms.MessageBox.Show("ShadowsocksR");
                break;

            //case "VMess":
            //    result = pVMessController.Start(server, mode);
            //    System.Windows.Forms.MessageBox.Show("VMess");
            //    break;
            default:
                break;
            }

            if (result)
            {
                if (mode.Type == 1)
                {
                    // TUN/TAP 全局代理模式,启动 TUN/TAP 控制器
                    result = pTUNTAPController.Start(server, mode);
                }
                else if (mode.Type == 2)
                {
                    // TUN/TAP 全局代理模式,启动 TUN/TAP 控制器
                    result = pTUNTAPController.Start(server, mode);
                }
                else
                {
                    result = false;
                }
            }

            if (!result)
            {
                Stop();
            }

            return(result);
        }
Esempio n. 3
0
        /// <summary>
        ///     启动
        /// </summary>
        /// <param name="server">服务器</param>
        /// <param name="mode">模式</param>
        /// <returns>是否启动成功</returns>
        public bool Start(Server server, Mode mode)
        {
            FlushDNSResolverCache();

            var result = false;

            if (server.Type == "Socks5")
            {
                result = mode.Type != 4;
            }
            else
            {
                switch (server.Type)
                {
                case "SS":
                    pServerClientController = new SSController();
                    break;

                case "SSR":
                    pServerClientController = new SSRController();
                    break;

                case "VMess":
                    pServerClientController = new VMessController();
                    break;

                case "Trojan":
                    pServerClientController = new TrojanController();
                    break;
                }

                MainForm.Instance.StatusText(i18N.Translate("Starting ", pServerClientController.MainName));
                if (pServerClientController.ready)
                {
                    result = pServerClientController.Start(server, mode);
                }
            }

            if (result) // If server runs,then run mode
            {
                switch (mode.Type)
                {
                case 0:     // 进程代理模式
                    pNFController ??= new NFController();
                    pNTTController ??= new NTTController();
                    if (pNFController.ready)
                    {
                        result = pNFController.Start(server, mode, false);
                    }

                    if (!result && pNFController.ready)
                    {
                        MainForm.Instance.StatusText(i18N.Translate("Restarting Redirector"));
                        Logging.Info("正常启动失败后尝试停止驱动服务再重新启动");
                        //正常启动失败后尝试停止驱动服务再重新启动
                        result = pNFController.Start(server, mode, true);
                    }

                    if (result)
                    {
                        Task.Run(() => pNTTController.Start());
                    }
                    break;

                case 1:     // TUN/TAP 黑名单代理模式
                case 2:     // TUN/TAP 白名单代理模式
                    pTUNTAPController ??= new TUNTAPController();
                    pNTTController ??= new NTTController();
                    result = pTUNTAPController.Start(server, mode);
                    if (result)
                    {
                        Task.Run(() => pNTTController.Start());
                    }
                    break;

                case 3:     // HTTP 系统代理和 Socks5 和 HTTP 代理模式
                case 5:
                    pHTTPController ??= new HTTPController();
                    result = pHTTPController.Start(server, mode);
                    break;

                case 4:     // Socks5 代理模式,不需要启动额外的Server
                    break;

                default:
                    result = false;
                    break;
                }
            }

            if (!result)
            {
                Stop();
            }

            return(result);
        }
Esempio n. 4
0
        /// <summary>
        ///		启动
        /// </summary>
        /// <param name="server">服务器</param>
        /// <param name="mode">模式</param>
        /// <returns>是否启动成功</returns>
        public bool Start(Objects.Server server, Objects.Mode mode)
        {
            var result = false;

            switch (server.Type)
            {
            case "Socks5":
                result = true;
                break;

            case "Shadowsocks":
                KillProcess("Shadowsocks");
                result = pSSController.Start(server, mode);
                break;

            case "ShadowsocksR":
                KillProcess("ShadowsocksR");
                result = pSSRController.Start(server, mode);
                break;

            case "VMess":
                KillProcess("v2ray");
                result = pVMessController.Start(server, mode);
                break;

            default:
                break;
            }

            if (result)
            {
                if (mode.Type == 0)
                {
                    // 进程代理模式,启动 NF 控制器
                    result = pNFController.Start(server, mode);
                }
                else if (mode.Type == 1)
                {
                    // TUN/TAP 全局代理模式,启动 TUN/TAP 控制器
                    result = pTUNTAPController.Start(server, mode);
                }
                else if (mode.Type == 2)
                {
                    // TUN/TAP 全局代理模式,启动 TUN/TAP 控制器
                    result = pTUNTAPController.Start(server, mode);
                }
                else if (mode.Type == 3 || mode.Type == 5)
                {
                    // HTTP 系统代理和 Socks5 和 HTTP 代理模式,启动 HTTP 控制器
                    result = pHTTPController.Start(server, mode);
                }
                else if (mode.Type == 4)
                {
                    // Socks5 代理模式,不需要启动额外的控制器
                }
                else
                {
                    result = false;
                }
            }

            if (!result)
            {
                Stop();
            }

            return(result);
        }
Esempio n. 5
0
        /// <summary>
        ///		启动
        /// </summary>
        /// <param name="server">服务器</param>
        /// <param name="mode">模式</param>
        /// <returns>是否启动成功</returns>
        public bool Start(Server server, Mode mode)
        {
            FlushDNSResolverCache();

            var result = false;

            switch (server.Type)
            {
            case "Socks5":
                if (mode.Type == 4)
                {
                    result = false;
                }
                else
                {
                    result = true;
                }
                break;

            case "SS":
                KillProcess("Shadowsocks");
                if (pSSController == null)
                {
                    pSSController = new SSController();
                }
                result = pSSController.Start(server, mode);
                break;

            case "SSR":
                KillProcess("ShadowsocksR");
                if (pSSRController == null)
                {
                    pSSRController = new SSRController();
                }
                result = pSSRController.Start(server, mode);
                break;

            case "VMess":
                KillProcess("v2ray");
                if (pVMessController == null)
                {
                    pVMessController = new VMessController();
                }
                result = pVMessController.Start(server, mode);
                break;

            case "Trojan":
                KillProcess("Trojan");
                if (pTrojanController == null)
                {
                    pTrojanController = new TrojanController();
                }
                result = pTrojanController.Start(server, mode);
                break;
            }

            if (result)
            {
                if (mode.Type == 0)
                {
                    if (pNFController == null)
                    {
                        pNFController = new NFController();
                    }
                    if (pNTTController == null)
                    {
                        pNTTController = new NTTController();
                    }
                    // 进程代理模式,启动 NF 控制器
                    result = pNFController.Start(server, mode, false);
                    if (!result)
                    {
                        MainForm.Instance.StatusText($"{i18N.Translate("Status")}{i18N.Translate(": ")}{i18N.Translate("Restarting Redirector")}");
                        Logging.Info("正常启动失败后尝试停止驱动服务再重新启动");
                        //正常启动失败后尝试停止驱动服务再重新启动
                        result = pNFController.Start(server, mode, true);
                    }
                    else
                    {
                        Task.Run(() => pNTTController.Start());
                    }
                }
                else if (mode.Type == 1)
                {
                    if (pTUNTAPController == null)
                    {
                        pTUNTAPController = new TUNTAPController();
                    }
                    if (pNTTController == null)
                    {
                        pNTTController = new NTTController();
                    }
                    // TUN/TAP 黑名单代理模式,启动 TUN/TAP 控制器
                    result = pTUNTAPController.Start(server, mode);
                    if (result)
                    {
                        Task.Run(() => pNTTController.Start());
                    }
                }
                else if (mode.Type == 2)
                {
                    if (pTUNTAPController == null)
                    {
                        pTUNTAPController = new TUNTAPController();
                    }
                    if (pNTTController == null)
                    {
                        pNTTController = new NTTController();
                    }
                    // TUN/TAP 白名单代理模式,启动 TUN/TAP 控制器
                    result = pTUNTAPController.Start(server, mode);
                    if (result)
                    {
                        Task.Run(() => pNTTController.Start());
                    }
                }
                else if (mode.Type == 3 || mode.Type == 5)
                {
                    if (pHTTPController == null)
                    {
                        pHTTPController = new HTTPController();
                    }
                    // HTTP 系统代理和 Socks5 和 HTTP 代理模式,启动 HTTP 控制器
                    result = pHTTPController.Start(server, mode);
                }
                else if (mode.Type == 4)
                {
                    // Socks5 代理模式,不需要启动额外的控制器
                }
                else
                {
                    result = false;
                }
            }

            if (!result)
            {
                Stop();
            }

            return(result);
        }
Esempio n. 6
0
        /// <summary>
        ///		启动
        /// </summary>
        /// <param name="server">服务器</param>
        /// <param name="mode">模式</param>
        /// <returns>是否启动成功</returns>
        public bool Start(Models.Server server, Models.Mode mode)
        {
            FlushDNSResolverCache();

            var result = false;

            switch (server.Type)
            {
            case "Socks5":
                if (mode.Type == 4)
                {
                    result = false;
                }
                else
                {
                    result = true;
                }
                break;

            case "SS":
                KillProcess("Shadowsocks");
                if (pSSController == null)
                {
                    pSSController = new SSController();
                }
                result = pSSController.Start(server, mode);
                break;

            case "SSR":
                KillProcess("ShadowsocksR");
                if (pSSRController == null)
                {
                    pSSRController = new SSRController();
                }
                result = pSSRController.Start(server, mode);
                break;

            case "VMess":
                KillProcess("v2ray");
                if (pVMessController == null)
                {
                    pVMessController = new VMessController();
                }
                result = pVMessController.Start(server, mode);
                break;
            }

            if (result)
            {
                if (mode.Type == 0)
                {
                    if (pNFController == null)
                    {
                        pNFController = new NFController();
                    }
                    if (pNTTController == null)
                    {
                        pNTTController = new NTTController();
                    }
                    // 进程代理模式,启动 NF 控制器
                    result = pNFController.Start(server, mode);
                    if (result)
                    {
                        Task.Run(() =>
                        {
                            pNTTController.Start();
                        });
                    }
                }
                else if (mode.Type == 1)
                {
                    if (pTUNTAPController == null)
                    {
                        pTUNTAPController = new TUNTAPController();
                    }
                    if (pNTTController == null)
                    {
                        pNTTController = new NTTController();
                    }
                    // TUN/TAP 黑名单代理模式,启动 TUN/TAP 控制器
                    result = pTUNTAPController.Start(server, mode);
                    if (result)
                    {
                        Task.Run(() =>
                        {
                            pNTTController.Start();
                        });
                    }
                }
                else if (mode.Type == 2)
                {
                    if (pTUNTAPController == null)
                    {
                        pTUNTAPController = new TUNTAPController();
                    }
                    if (pNTTController == null)
                    {
                        pNTTController = new NTTController();
                    }
                    // TUN/TAP 白名单代理模式,启动 TUN/TAP 控制器
                    result = pTUNTAPController.Start(server, mode);
                    if (result)
                    {
                        Task.Run(() =>
                        {
                            pNTTController.Start();
                        });
                    }
                }
                else if (mode.Type == 3 || mode.Type == 5)
                {
                    if (pHTTPController == null)
                    {
                        pHTTPController = new HTTPController();
                    }
                    // HTTP 系统代理和 Socks5 和 HTTP 代理模式,启动 HTTP 控制器
                    result = pHTTPController.Start(server, mode);
                }
                else if (mode.Type == 4)
                {
                    // Socks5 代理模式,不需要启动额外的控制器
                }
                else
                {
                    result = false;
                }
            }

            if (!result)
            {
                Stop();
            }

            return(result);
        }
Esempio n. 7
0
        /// <summary>
        ///		启动
        /// </summary>
        /// <param name="server">服务器</param>
        /// <param name="mode">模式</param>
        /// <returns>是否启动成功</returns>
        public (bool, string) Start(Models.Server server, Models.Mode mode)
        {
            var result = (false, "");

            switch (server.Type)
            {
            case "Socks5":
                if (mode.Type == 4)
                {
                    result = (false, null);
                }
                else
                {
                    result = (true, null);
                }
                break;

            case "SS":
                KillProcess("Shadowsocks");
                if (pSSController == null)
                {
                    pSSController = new SSController();
                }
                result = (pSSController.Start(server, mode), null);
                break;

            case "SSR":
                KillProcess("ShadowsocksR");
                if (pSSRController == null)
                {
                    pSSRController = new SSRController();
                }
                result = (pSSRController.Start(server, mode), null);
                break;

            case "VMess":
                KillProcess("v2ray");
                if (pVMessController == null)
                {
                    pVMessController = new VMessController();
                }
                result = (pVMessController.Start(server, mode), null);
                break;
            }

            if (result.Item1)
            {
                if (mode.Type == 0)
                {
                    if (pNFController == null)
                    {
                        pNFController = new NFController();
                    }
                    if (pNTTController == null)
                    {
                        pNTTController = new NTTController();
                    }
                    // 进程代理模式,启动 NF 控制器
                    result = (pNFController.Start(server, mode), pNTTController.Start().Item2);
                }
                else if (mode.Type == 1)
                {
                    if (pTUNTAPController == null)
                    {
                        pTUNTAPController = new TUNTAPController();
                    }
                    if (pNTTController == null)
                    {
                        pNTTController = new NTTController();
                    }
                    // TUN/TAP 黑名单代理模式,启动 TUN/TAP 控制器
                    result = (pTUNTAPController.Start(server, mode), pNTTController.Start().Item2);
                }
                else if (mode.Type == 2)
                {
                    if (pTUNTAPController == null)
                    {
                        pTUNTAPController = new TUNTAPController();
                    }
                    if (pNTTController == null)
                    {
                        pNTTController = new NTTController();
                    }
                    // TUN/TAP 白名单代理模式,启动 TUN/TAP 控制器
                    result = (pTUNTAPController.Start(server, mode), pNTTController.Start().Item2);
                }
                else if (mode.Type == 3 || mode.Type == 5)
                {
                    if (pHTTPController == null)
                    {
                        pHTTPController = new HTTPController();
                    }
                    // HTTP 系统代理和 Socks5 和 HTTP 代理模式,启动 HTTP 控制器
                    result = (pHTTPController.Start(server, mode), null);
                }
                else if (mode.Type == 4)
                {
                    // Socks5 代理模式,不需要启动额外的控制器
                }
                else
                {
                    result = (false, null);
                }
            }

            if (!result.Item1)
            {
                Stop();
            }

            return(result);
        }