Ejemplo n.º 1
0
        public UIViewController GetViewController()
        {
            var network = new BooleanElement("Enable", EnableNetwork);

            var host = new EntryElement("Host Name", "name", HostName);

            host.KeyboardType = UIKeyboardType.ASCIICapable;

            var port = new EntryElement("Port", "name", HostPort.ToString());

            port.KeyboardType = UIKeyboardType.NumberPad;

            var sort = new BooleanElement("Sort Names", SortNames);

            var root = new RootElement("Options")
            {
                new Section("Remote Server")
                {
                    network, host, port
                },
                new Section("Display")
                {
                    sort
                }
            };

            var dv = new DialogViewController(root, true)
            {
                Autorotate = true
            };

            dv.ViewDisappearing += delegate {
                EnableNetwork = network.Value;
                HostName      = host.Value;
                ushort p;
                if (UInt16.TryParse(port.Value, out p))
                {
                    HostPort = p;
                }
                else
                {
                    HostPort = -1;
                }
                SortNames = sort.Value;

                var defaults = NSUserDefaults.StandardUserDefaults;
                defaults.SetBool(EnableNetwork, "network.enabled");
                defaults.SetString(HostName ?? String.Empty, "network.host.name");
                defaults.SetInt(HostPort, "network.host.port");
                defaults.SetBool(SortNames, "display.sort");
            };

            return(dv);
        }
        /// <summary>
        /// Callback for transport selection change event
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="args">Selection Changed Event Arguments</param>
        public void OnTransportChanged(object sender, SelectionChangedEventArgs args)
        {
            // This prevent null exception
            if (App.CurrentAccount == null)
            {
                return;
            }

            var transportText = TransportComboBox.SelectedItem as TextBlock;

            App.CurrentAccount.Transport = transportText.Text;
            string transport = transportText.Text.ToLower();

            // Must check if HostPortBox exists before accessing it
            // When a users un-registers, this method is called before the HostPortBox is initialized
            if (transport == "tcp")
            {
                HostPort = App.CurrentAccount.HostPort = 5060;
                if (HostPortBox != null)
                {
                    HostPortBox.IsReadOnly = true;
                    HostPortBox.Background = Brushes.LightGray;
                    HostPortBox.Foreground = Brushes.Black;
                }
            }
            else if (transport == "tls")
            {
                HostPort = App.CurrentAccount.HostPort = 5061;
                if (HostPortBox != null)
                {
                    HostPortBox.IsReadOnly = true;
                    HostPortBox.Background = Brushes.LightGray;
                    HostPortBox.Foreground = Brushes.Black;
                }
            }
            else if (transport == "udp")
            {
                HostPort = App.CurrentAccount.HostPort = 5060;
                if (HostPortBox != null)
                {
                    HostPortBox.IsReadOnly = false;
                    HostPortBox.Background = Brushes.White;
                }
            }
            if (HostPortBox != null)
            {
                HostPortBox.Text = HostPort.ToString();
            }
        }
Ejemplo n.º 3
0
        public override void SetBasicPropertyValues()
        {
            base.SetBasicPropertyValues();

            //默认ModuleNumber由ID决定
            ModuleNumber = ID;
            ResourceProperty propertyValue;

            for (int i = 0; i < ListProperties.Count; i++)
            {
                propertyValue = ListProperties[i];
                switch (propertyValue.PropertyID)
                {
                case S1110Consts.PROPERTYID_HOSTADDRESS:
                    propertyValue.Value = HostAddress;
                    break;

                case S1110Consts.PROPERTYID_HOSTNAME:
                    propertyValue.Value = HostName;
                    break;

                case S1110Consts.PROPERTYID_HOSTPORT:
                    propertyValue.Value = HostPort.ToString();
                    break;

                case S1110Consts.PROPERTYID_CONTINENT:
                    propertyValue.Value = Continent;
                    break;

                case S1110Consts.PROPERTYID_COUNTRY:
                    propertyValue.Value = Country;
                    break;

                case S1110Consts.PROPERTYID_MODULENUMBER:
                    propertyValue.Value = ModuleNumber.ToString();
                    break;

                case S1110Consts.PROPERTYID_ENABLEDISABLE:
                    propertyValue.Value = IsEnabled ? "1" : "0";
                    break;

                case S1110Consts.PROPERTYID_MACHINE:
                    propertyValue.Value = MachineObjID.ToString();
                    break;
                }
            }
        }
        public override async Task <IDictionary <string, string> > SaveSetting()
        {
            var uiWorkflow   = IoC.Resolve <IUiWorkflow>();
            var textService  = IoC.Resolve <ITextService>();
            var savePassword = false;

            if (string.IsNullOrWhiteSpace(AuthPassword))
            {
                savePassword = (await DialogCoordinator.Instance.ShowMessageAsync(uiWorkflow,
                                                                                  textService.Compile("MailDistributor.Strategy.Smtp.Save.EncryptPassword.Title", CultureInfo.CurrentUICulture, out _).ToString(),
                                                                                  textService.Compile("MailDistributor.Strategy.Smtp.Save.EncryptPassword.Message", CultureInfo.CurrentUICulture, out _).ToString()
                                                                                  )) == MessageDialogResult.Affirmative;
            }

            return(new Dictionary <string, string>()
            {
                { nameof(Host), Host },
                { nameof(HostPort), HostPort.ToString() },
                { nameof(AuthUserName), AuthUserName },
                { nameof(AuthPassword), savePassword ? AuthPassword : null },
            });
        }
Ejemplo n.º 5
0
        public override void SetBasicPropertyValues()
        {
            base.SetBasicPropertyValues();

            ResourceProperty propertyValue;

            for (int i = 0; i < ListProperties.Count; i++)
            {
                propertyValue = ListProperties[i];
                switch (propertyValue.PropertyID)
                {
                case S1110Consts.PROPERTYID_HOSTADDRESS:
                    propertyValue.Value = HostAddress;
                    break;

                case S1110Consts.PROPERTYID_HOSTNAME:
                    propertyValue.Value = HostName;
                    break;

                case S1110Consts.PROPERTYID_HOSTPORT:
                    propertyValue.Value = HostPort.ToString();
                    break;

                case S1110Consts.PROPERTYID_CONTINENT:
                    propertyValue.Value = Continent;
                    break;

                case S1110Consts.PROPERTYID_COUNTRY:
                    propertyValue.Value = Country;
                    break;

                case 11:
                    propertyValue.Value = LogPath;
                    break;
                }
            }
        }
Ejemplo n.º 6
0
        public string GetField(int field)
        {
            switch (field)
            {
            case 0: return(HostName);

            case 1: return(GameName);

            case 2: return(GameVersion);

            case 3: return(MapName);

            case 4: return(GameType);

            case 5: return(GameVariant);

            case 6: return(NumPlayers.ToString());

            case 7: return(MaxPlayers.ToString());

            case 8: return(GameMode);

            case 9: return((Password ? 1 : 0).ToString());

            case 10: return(TimeLimit.ToString());

            case 11: return(RoundTime.ToString());

            case 12: return(HostPort.ToString());

            case 13: return((Dedicated ? 1 : 0).ToString());

            case 14: return((Ranked ? 1 : 0).ToString());

            case 15: return((AntiCheat ? 1 : 0).ToString());

            case 16: return(OS);

            case 17: return((BattleRecorder ? 1 : 0).ToString());

            case 18: return(BRIndex);

            case 19: return(BRDownload);

            case 20: return((Voip ? 1 : 0).ToString());

            case 21: return((AutoBalance ? 1 : 0).ToString());

            case 22: return((FriendlyFire ? 1 : 0).ToString());

            case 23: return(TKMode);

            case 24: return(StartDelay.ToString());

            case 25: return(SpawnTime.ToString("0.000000", CultureInfo.InvariantCulture));

            case 26: return(ServerText);

            case 27: return(ServerLogo);

            case 28: return(CommunityWebsite);

            case 29: return(ScoreLimit.ToString());

            case 30: return(TicketRatio.ToString());

            case 31: return(TeamRatio.ToString("0.000000", CultureInfo.InvariantCulture));

            case 32: return(Team1Name);

            case 33: return(Team2Name);

            case 34: return((CoopEnabled ? 1 : 0).ToString());

            case 35: return((Pure ? 1 : 0).ToString());

            case 36: return(MapSize.ToString());

            case 37: return((Unlocks ? 1 : 0).ToString());

            case 38: return(Fps.ToString());

            case 39: return((Plasma ? 1 : 0).ToString());

            case 40: return(ReservedSlots.ToString());

            case 41: return(CoopBotRatio.ToString());

            case 42: return(CoopBotCount.ToString());

            case 43: return(CoopBotDifficulty.ToString());

            case 44: return((NoVehicles ? 1 : 0).ToString());

            default:
                return("");
            }
        }
Ejemplo n.º 7
0
        public string PrepareConfig(HostsViewModel hosts, bool isLoadBalancePrepare = false)
        {
            string config     = ConfigTemplate;
            string appVersion = VersionTracking.CurrentVersion;

            string version_path = Path.Combine(
                App.Instance.DataPathParent,
                "version_" + appVersion);

            string gfwlist_path = Path.Combine(App.Instance.DataPathParent, "gfw_list");
            string cn_ips_path  = Path.Combine(App.Instance.DataPathParent, "cn_ips_list");
            string cert_path    = Path.Combine(App.Instance.DataPathParent, "cacert");

            if (!File.Exists(version_path))
            {
                File.WriteAllText(version_path, "TrojanPlus App Version: " + appVersion);

                File.WriteAllText(gfwlist_path, Resx.TextResource.gfwlist);
                File.WriteAllText(cn_ips_path, Resx.TextResource.cn_mainland_ips);
                File.WriteAllText(cert_path, Resx.TextResource.cacert);
            }

            config = config.Replace("${run_type}", "client_tun");
            config = config.Replace("${remote_addr}", HostAddress);
            config = config.Replace("${remote_port}", HostPort.ToString());
            config = config.Replace("${password}", Password);

            config = config.Replace("${udp_timeout}", "10");
            config = config.Replace("${udp_socket_buf}", "16384");
            config = config.Replace("${udp_recv_buf}", "4096");

            config = config.Replace("${log_level}", EnableDebugLog ? "0" : "5");

            config = config.Replace("${ssl.verify}", SSLVerify.ToLowerString());
            config = config.Replace("${ssl.verify_hostname}", SSLVerify.ToLowerString());
            config = config.Replace("${ssl.ssl_shutdown_wait_time}", "3");
            config = config.Replace("${ssl.sni}", HostAddress);
            config = config.Replace("${ssl.cert}", cert_path);

            config = config.Replace("${tcp.fast_open}", EnableTCPFastOpen ? "true" : "false");
            config = config.Replace("${tcp.connect_time_out}", "5");

            config = config.Replace("${experimental.pipeline_num}", EnablePipeline ? "5" : "0");
            config = config.Replace("${experimental.pipeline_ack_window}", "100");

            if (!isLoadBalancePrepare && LoadBalance.Count > 0)
            {
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < LoadBalance.Count; i++)
                {
                    var h = hosts.FindHostByName(LoadBalance[i]);
                    if (h != null && h.EnablePipeline)
                    {
                        string loadConfig = h.PrepareConfig(hosts, true);
                        string path       = Path.Combine(App.Instance.DataPathParent, "balance_config" + i);
                        File.WriteAllText(path, loadConfig);

                        if (sb.Length > 0)
                        {
                            sb.Append(",");
                        }

                        sb.Append($"\"{path}\"");
                    }
                }

                config = config.Replace("${experimental.pipeline_loadbalance_configs}", sb.ToString());
            }
            else
            {
                config = config.Replace("${experimental.pipeline_loadbalance_configs}", string.Empty);
                if (isLoadBalancePrepare)
                {
                    config = config.Replace("${tun.tun_fd}", "-1");
                }
            }

            config = config.Replace("${tun.net_ip}", TunNetIP);
            config = config.Replace("${tun.mtu}", TunMtu.ToString());

            config = config.Replace("${dns.udp_socket_buf}", "8192");
            config = config.Replace("${dns.udp_recv_buf}", "1024");

            config = config.Replace("${dns.up_dns_server}", UpStreamNS);
            config = config.Replace("${dns.up_gfw_dns_server}", GFWUpStreamNS);

            config = config.Replace("${dns.gfwlist}", gfwlist_path);
            config = config.Replace("${route.cn_mainland_ips_file}", cn_ips_path);
            config = config.Replace("${route.proxy_type}", ((int)Route).ToString());

            string proxy_ips_path = Path.Combine(App.Instance.DataPathParent, "proxy_ips");
            string white_ips_path = Path.Combine(App.Instance.DataPathParent, "white_ips");

            File.WriteAllText(proxy_ips_path, string.Empty);
            File.WriteAllText(white_ips_path, string.Empty);

            config = config.Replace("${route.proxy_ips}", proxy_ips_path);
            config = config.Replace("${route.white_ips}", white_ips_path);

            return(config);
        }
Ejemplo n.º 8
0
        public UIViewController GetViewController()
        {
            var network = new BooleanElement("Enable", EnableNetwork);

            var host = new EntryElement("Host Name", "name", HostName);

            host.KeyboardType = UIKeyboardType.ASCIICapable;

            var port = new EntryElement("Port", "name", HostPort.ToString());

            port.KeyboardType = UIKeyboardType.NumberPad;

            var sort = new BooleanElement("Sort Names", SortNames);

            var repeat      = new BooleanElement("Repeat", Repeat);
            var repeatCount = new EntryElement("Repeat Count", "repeat", RepeatCount.ToString());

            var autoStart = new BooleanElement("Auto Start", AutoStart);
            var autoExit  = new BooleanElement("Auto Exit", TerminateAfterExecution);

            var root = new RootElement("Options")
            {
                new Section("Remote Server")
                {
                    network, host, port
                },
                new Section("Display")
                {
                    sort
                },
                new Section("Repeat")
                {
                    repeat, repeatCount
                },
                new Section("Misc")
                {
                    autoStart, autoExit
                }
            };

            var dv = new DialogViewController(root, true)
            {
                Autorotate = true
            };

            dv.ViewDisappearing += delegate {
                EnableNetwork = network.Value;
                HostName      = host.Value;
                ushort p;
                if (UInt16.TryParse(port.Value, out p))
                {
                    HostPort = p;
                }
                else
                {
                    HostPort = -1;
                }
                SortNames = sort.Value;

                int r;
                if (Int32.TryParse(repeatCount.Value, out r))
                {
                    RepeatCount = r;
                }
                else
                {
                    RepeatCount = 0;
                }
                Repeat = repeat.Value;

                AutoStart = autoStart.Value;
                TerminateAfterExecution = autoExit.Value;

                var defaults = NSUserDefaults.StandardUserDefaults;
                defaults.SetBool(EnableNetwork, "network.enabled");
                defaults.SetString(HostName ?? String.Empty, "network.host.name");
                defaults.SetInt(HostPort, "network.host.port");
                defaults.SetBool(SortNames, "display.sort");
                defaults.SetBool(Repeat, "repeat.enabled");
                defaults.SetInt(RepeatCount, "repeat.count");
                defaults.SetBool(AutoStart, "misc.autostart");
                defaults.SetBool(TerminateAfterExecution, "misc.autoexit");
            };

            return(dv);
        }