示例#1
0
        public override NSObject GetObjectValue(NSTableView tableView,
                                                NSTableColumn tableColumn,
                                                int row)
        {
            TableProtocolsControllerItem i = Items [row];

            if (tableColumn.Identifier == "Protocol")
            {
                return(new NSString(i.Protocol.ToUpperInvariant()));
            }
            else if (tableColumn.Identifier == "Port")
            {
                return(new NSString(i.Port.ToString()));
            }
            else if (tableColumn.Identifier == "Entry")
            {
                return(new NSString((i.Entry == 0) ? "Primary":"Alternative"));
            }
            else if (tableColumn.Identifier == "Cipher")
            {
                return(new NSString(i.Cipher));
            }
            else if (tableColumn.Identifier == "Description")
            {
                return(new NSString(i.Description));
            }
            else
            {
                throw new NotImplementedException(string.Format("{0} is not recognized", tableColumn.Identifier));
            }
        }
示例#2
0
        public TableProtocolsController(NSTableView tableView)
        {
            this.tableView = tableView;

            XmlNodeList xmlModes = Engine.Instance.AirVPN.Manifest.SelectNodes("//modes/mode");

            foreach (XmlElement xmlMode in xmlModes)
            {
                TableProtocolsControllerItem item = new TableProtocolsControllerItem();
                item.Protocol    = xmlMode.GetAttribute("protocol").ToUpper();
                item.Port        = Conversions.ToInt32(xmlMode.GetAttribute("port"), 443);
                item.Entry       = Conversions.ToInt32(xmlMode.GetAttribute("entry_index"), 0);
                item.Cipher      = xmlMode.GetAttribute("cipher");
                item.Description = xmlMode.GetAttribute("title");
                Items.Add(item);
            }

            this.tableView.DataSource = this;
        }
示例#3
0
        void SaveOptions()
        {
            Storage s = Engine.Instance.Storage;

            // General

            s.SetBool("connect", GuiUtils.GetCheck(ChkConnect));
            s.SetBool("netlock", GuiUtils.GetCheck(ChkNetLock));


            s.SetBool("servers.startlast", GuiUtils.GetCheck(ChkGeneralStartLast));
            s.SetBool("gui.osx.visible", GuiUtils.GetCheck(ChkGeneralOsxVisible));
            // s.SetBool ("gui.osx.dock", GuiUtils.GetCheck (ChkGeneralOsxDock)); // See this FAQ: https://airvpn.org/topic/13331-its-possible-to-hide-the-icon-in-dock-bar-under-os-x/
            s.SetBool("gui.osx.notifications", GuiUtils.GetCheck(ChkGeneralOsxNotifications));
            s.SetBool("gui.osx.sysbar.show_info", GuiUtils.GetCheck(ChkUiSystemBarShowInfo));
            s.SetBool("gui.osx.sysbar.show_speed", GuiUtils.GetCheck(ChkUiSystemBarShowSpeed));
            s.SetBool("gui.osx.sysbar.show_server", GuiUtils.GetCheck(ChkUiSystemBarShowServer));
            s.SetBool("gui.exit_confirm", GuiUtils.GetCheck(ChkExitConfirm));

            // UI
            string uiUnit = "";

            if (GuiUtils.GetSelected(CboUiUnit) == Messages.WindowsSettingsUiUnit1)
            {
                uiUnit = "bytes";
            }
            else if (GuiUtils.GetSelected(CboUiUnit) == Messages.WindowsSettingsUiUnit2)
            {
                uiUnit = "bits";
            }
            s.Set("ui.unit", uiUnit);

            /*
             * string interfaceStyle = GuiUtils.GetSelected (CboGeneralOsxInterfaceStyle);
             * //string currentInterfaceStyle = GuiUtils.InterfaceColorMode ();
             * if(interfaceStyle == "Dark")
             *      Platform.Instance.ShellCmd ("defaults write -g AppleInterfaceStyle Dark");
             * else
             *      Platform.Instance.ShellCmd ("defaults remove -g AppleInterfaceStyle");
             */

            // Protocols
            if (GuiUtils.GetCheck(ChkProtocolsAutomatic))
            {
                s.Set("mode.protocol", "AUTO");
                s.SetInt("mode.port", 443);
                s.SetInt("mode.alt", 0);
            }
            else if (TableProtocols.SelectedRowCount == 1)
            {
                TableProtocolsControllerItem itemProtocol = TableProtocolsController.Items [TableProtocols.SelectedRow];
                s.Set("mode.protocol", itemProtocol.Protocol);
                s.SetInt("mode.port", itemProtocol.Port);
                s.SetInt("mode.alt", itemProtocol.Entry);
            }
            else
            {
                s.Set("mode.protocol", "AUTO");
                s.SetInt("mode.port", 443);
                s.SetInt("mode.alt", 0);
            }


            // Proxy

            s.Set("proxy.mode", GuiUtils.GetSelected(CboProxyType));
            s.Set("proxy.host", TxtProxyHost.StringValue);
            s.SetInt("proxy.port", Conversions.ToInt32(TxtProxyPort.StringValue));
            s.Set("proxy.auth", GuiUtils.GetSelected(CboProxyAuthentication));
            s.Set("proxy.login", TxtProxyLogin.StringValue);
            s.Set("proxy.password", TxtProxyPassword.StringValue);
            s.SetInt("proxy.tor.control.port", Conversions.ToInt32(TxtProxyTorControlPort.StringValue));
            s.Set("proxy.tor.control.password", TxtProxyTorControlPassword.StringValue);

            // Routes
            s.Set("routes.default", RouteDescriptionToDirection(GuiUtils.GetSelected(CboRoutesOtherwise)));

            string routes = "";

            foreach (TableRoutingControllerItem item in TableRoutingController.Items)
            {
                if (routes != "")
                {
                    routes += ";";
                }
                routes += item.Ip + "," + item.Action + "," + item.Notes;
            }
            s.Set("routes.custom", routes);

            // Advanced - General
            s.SetBool("advanced.expert", GuiUtils.GetCheck(ChkAdvancedExpertMode));

            s.SetBool("advanced.check.route", GuiUtils.GetCheck(ChkAdvancedCheckRoute));
            string ipV6Mode = GuiUtils.GetSelected(CboIpV6);

            if (ipV6Mode == "None")
            {
                s.Set("ipv6.mode", "none");
            }
            else if (ipV6Mode == "Disable")
            {
                s.Set("ipv6.mode", "disable");
            }
            else
            {
                s.Set("ipv6.mode", "disable");
            }
            s.SetBool("pinger.enabled", GuiUtils.GetCheck(ChkAdvancedPingerEnabled));
            s.SetBool("routes.remove_default", GuiUtils.GetCheck(ChkRouteRemoveDefaultGateway));

            s.Set("executables.openvpn", TxtAdvancedOpenVpnPath.StringValue);

            string manifestRefresh = GuiUtils.GetSelected(CboAdvancedManifestRefresh);

            if (manifestRefresh == "Automatic")             // Auto
            {
                s.SetInt("advanced.manifest.refresh", -1);
            }
            else if (manifestRefresh == "Never")             // Never
            {
                s.SetInt("advanced.manifest.refresh", 0);
            }
            else if (manifestRefresh == "Every minute")             // One minute
            {
                s.SetInt("advanced.manifest.refresh", 1);
            }
            else if (manifestRefresh == "Every ten minute")             // Ten minute
            {
                s.SetInt("advanced.manifest.refresh", 10);
            }
            else if (manifestRefresh == "Every one hour")             // One hour
            {
                s.SetInt("advanced.manifest.refresh", 60);
            }

            string openVpnSndBuf = GuiUtils.GetSelected(CboOpenVpnSndBuf);

            if (openVpnSndBuf == Messages.Automatic)
            {
                s.SetInt("openvpn.sndbuf", -2);
            }
            else if (openVpnSndBuf == Messages.WindowsSettingsOpenVpnDefault)
            {
                s.SetInt("openvpn.sndbuf", -1);
            }
            else if (openVpnSndBuf == "8 KB")
            {
                s.SetInt("openvpn.sndbuf", 1024 * 8);
            }
            else if (openVpnSndBuf == "16 KB")
            {
                s.SetInt("openvpn.sndbuf", 1024 * 16);
            }
            else if (openVpnSndBuf == "32 KB")
            {
                s.SetInt("openvpn.sndbuf", 1024 * 32);
            }
            else if (openVpnSndBuf == "64 KB")
            {
                s.SetInt("openvpn.sndbuf", 1024 * 64);
            }
            else if (openVpnSndBuf == "128 KB")
            {
                s.SetInt("openvpn.sndbuf", 1024 * 128);
            }
            else if (openVpnSndBuf == "256 KB")
            {
                s.SetInt("openvpn.sndbuf", 1024 * 256);
            }
            else if (openVpnSndBuf == "512 KB")
            {
                s.SetInt("openvpn.sndbuf", 1024 * 512);
            }

            string openVpnRcvBuf = GuiUtils.GetSelected(CboOpenVpnRcvBuf);

            if (openVpnRcvBuf == Messages.Automatic)
            {
                s.SetInt("openvpn.rcvbuf", -2);
            }
            else if (openVpnRcvBuf == Messages.WindowsSettingsOpenVpnDefault)
            {
                s.SetInt("openvpn.rcvbuf", -1);
            }
            else if (openVpnRcvBuf == "8 KB")
            {
                s.SetInt("openvpn.rcvbuf", 1024 * 8);
            }
            else if (openVpnRcvBuf == "16 KB")
            {
                s.SetInt("openvpn.rcvbuf", 1024 * 16);
            }
            else if (openVpnRcvBuf == "32 KB")
            {
                s.SetInt("openvpn.rcvbuf", 1024 * 32);
            }
            else if (openVpnRcvBuf == "64 KB")
            {
                s.SetInt("openvpn.rcvbuf", 1024 * 64);
            }
            else if (openVpnRcvBuf == "128 KB")
            {
                s.SetInt("openvpn.rcvbuf", 1024 * 128);
            }
            else if (openVpnRcvBuf == "256 KB")
            {
                s.SetInt("openvpn.rcvbuf", 1024 * 256);
            }
            else if (openVpnRcvBuf == "512 KB")
            {
                s.SetInt("openvpn.rcvbuf", 1024 * 512);
            }

            // Advanced - DNS
            string dnsMode = GuiUtils.GetSelected(CboDnsSwitchMode);

            if (dnsMode == "Disabled")
            {
                s.Set("dns.mode", "none");
            }
            else
            {
                s.Set("dns.mode", "auto");
            }
            s.SetBool("dns.check", GuiUtils.GetCheck(ChkDnsCheck));

            string dnsServers = "";

            for (int i = 0; i < TableDnsServersController.GetCount(); i++)
            {
                if (dnsServers != "")
                {
                    dnsServers += ",";
                }
                dnsServers += TableDnsServersController.Get(i);
            }
            s.Set("dns.servers", dnsServers);

            // Advanced - Lock
            string lockMode = GuiUtils.GetSelected(CboLockMode);

            s.Set("netlock.mode", "none");
            if (lockMode == "Automatic")
            {
                s.Set("netlock.mode", "auto");
            }
            else
            {
                foreach (NetworkLockPlugin lockPlugin in Engine.Instance.NetworkLockManager.Modes)
                {
                    if (lockPlugin.GetName() == lockMode)
                    {
                        s.Set("netlock.mode", lockPlugin.GetCode());
                    }
                }
            }
            s.SetBool("netlock.allow_private", GuiUtils.GetCheck(ChkLockAllowPrivate));
            s.SetBool("netlock.allow_ping", GuiUtils.GetCheck(ChkLockAllowPing));
            s.Set("netlock.allowed_ips", TxtLockAllowedIPS.StringValue);

            // Advanced - Logging
            s.SetBool("log.file.enabled", GuiUtils.GetCheck(ChkLoggingEnabled));
            s.SetBool("log.level.debug", GuiUtils.GetCheck(ChkLogLevelDebug));
            s.Set("log.file.path", TxtLoggingPath.StringValue);

            // Advanced - OVPN Directives
            s.SetBool("openvpn.skip_defaults", GuiUtils.GetSelected(CboOpenVpnDirectivesSkipDefault) == Messages.WindowsSettingsOpenVpnDirectivesDefaultSkip2);
            s.Set("openvpn.directives", TxtAdvancedOpenVpnDirectivesDefault.StringValue);
            s.Set("openvpn.custom", TxtAdvancedOpenVpnDirectivesCustom.StringValue);

            // Advanced - Events
            SaveOptionsEvent("app.start", 0);
            SaveOptionsEvent("app.stop", 1);
            SaveOptionsEvent("session.start", 2);
            SaveOptionsEvent("session.stop", 3);
            SaveOptionsEvent("vpn.pre", 4);
            SaveOptionsEvent("vpn.up", 5);
            SaveOptionsEvent("vpn.down", 6);

            Engine.Instance.OnSettingsChanged();
        }