示例#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));
            }
        }
        public override NSObject GetObjectValue(NSTableView tableView,
                                                NSTableColumn tableColumn,
                                                nint row)
        {
            TableProtocolsControllerItem i = Items[(int)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 == "IP")
            {
                return(new NSString(Conversions.ToString(i.IP + 1)));
            }
            else if (tableColumn.Identifier == "Description")
            {
                return(new NSString(i.Description));
            }
            else if (tableColumn.Identifier == "Specs")
            {
                return(new NSString(i.Specs));
            }
            else
            {
                throw new NotImplementedException(string.Format("{0} is not recognized", tableColumn.Identifier));
            }
        }
        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;
        }
示例#4
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;
        }
        public TableProtocolsController(NSTableView tableView)
        {
            this.tableView = tableView;

            if ((Engine.Instance.AirVPN != null) && (Engine.Instance.AirVPN.Manifest != null))
            {
                foreach (ConnectionMode mode in Engine.Instance.AirVPN.Modes)
                {
                    if (mode.Available == false)
                    {
                        continue;
                    }
                    TableProtocolsControllerItem item = new TableProtocolsControllerItem();
                    item.Protocol    = mode.Protocol;
                    item.Port        = mode.Port;
                    item.IP          = mode.EntryIndex;
                    item.Description = mode.Title;
                    item.Specs       = mode.Specs;
                    Items.Add(item);
                }
            }

            this.tableView.DataSource = this;
        }
        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);
            s.SetBool("ui.iec", GuiUtils.GetCheck(ChkUiIEC));

            // 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[(int)TableProtocols.SelectedRow];
                s.Set("mode.protocol", itemProtocol.Protocol);
                s.SetInt("mode.port", itemProtocol.Port);
                s.SetInt("mode.alt", itemProtocol.IP);
            }
            else
            {
                s.Set("mode.protocol", "AUTO");
                s.SetInt("mode.port", 443);
                s.SetInt("mode.alt", 0);
            }


            // Proxy

            s.Set("proxy.mode", GuiUtils.GetSelected(CboProxyType));

            if (GuiUtils.GetSelected(CboProxyWhen) == Messages.WindowsSettingsProxyWhenAlways)
            {
                s.Set("proxy.when", "always");
            }
            else if (GuiUtils.GetSelected(CboProxyWhen) == Messages.WindowsSettingsProxyWhenWeb)
            {
                s.Set("proxy.when", "web");
            }
            else if (GuiUtils.GetSelected(CboProxyWhen) == Messages.WindowsSettingsProxyWhenOpenVPN)
            {
                s.Set("proxy.when", "openvpn");
            }
            else if (GuiUtils.GetSelected(CboProxyWhen) == Messages.WindowsSettingsProxyWhenNone)
            {
                s.Set("proxy.when", "none");
            }
            else
            {
                s.Set("proxy.when", "always");
            }

            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("tools.openvpn.path", TxtAdvancedOpenVpnPath.StringValue);
            s.SetBool("advanced.skip_alreadyrun", GuiUtils.GetCheck(ChkAdvancedSkipAlreadyRun));
            s.SetBool("advanced.providers", GuiUtils.GetCheck(ChkAdvancedProviders));

            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.SetBool("netlock.allow_dns", GuiUtils.GetCheck(ChkLockAllowDNS));
            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);
            s.Set("openvpn.directives.path", TxtOpenVpnDirectivesCustomPath.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();
        }