protected override void OnLoad(EventArgs e) { base.OnLoad(e); CommonInit("Settings"); BuildTreeTabs(); lblLoggingHelp.Text = Messages.WindowsSettingsLoggingHelp; pnlGeneralWindowsOnly.Visible = Platform.Instance.IsWindowsSystem(); pnlAdvancedGeneralWindowsOnly.Visible = Platform.Instance.IsWindowsSystem(); chkWindowsWfp.Visible = Platform.Instance.IsWindowsSystem(); if ((Engine.Instance.AirVPN != null) && (Engine.Instance.AirVPN.Manifest != null)) { XmlNodeList xmlModes = Engine.Instance.AirVPN.Manifest.SelectNodes("//modes/mode"); foreach (XmlElement xmlMode in xmlModes) { Controls.ListViewItemProtocol itemMode = new Controls.ListViewItemProtocol(); itemMode.Protocol = xmlMode.GetAttribute("protocol").ToUpperInvariant(); itemMode.Port = Conversions.ToInt32(xmlMode.GetAttribute("port"), 443); itemMode.Entry = Conversions.ToInt32(xmlMode.GetAttribute("entry_index"), 0); while (itemMode.SubItems.Count < 5) { itemMode.SubItems.Add(""); } itemMode.SubItems[0].Text = itemMode.Protocol; itemMode.SubItems[1].Text = itemMode.Port.ToString(); if (itemMode.Entry == 0) { itemMode.SubItems[2].Text = "Primary"; } else if (itemMode.Entry == 1) { itemMode.SubItems[2].Text = "Alternative"; } else { itemMode.SubItems[2].Text = "Alternative " + xmlMode.GetAttribute("entry_index"); } itemMode.SubItems[3].Text = xmlMode.GetAttribute("title"); lstProtocols.Items.Add(itemMode); } lstProtocols.ResizeColumnsAuto(); } // UI cboUiUnit.Items.Clear(); cboUiUnit.Items.Add(Messages.WindowsSettingsUiUnit0); cboUiUnit.Items.Add(Messages.WindowsSettingsUiUnit1); cboUiUnit.Items.Add(Messages.WindowsSettingsUiUnit2); // Proxy cboProxyMode.Items.Clear(); cboProxyMode.Items.Add("None"); cboProxyMode.Items.Add("Detect"); cboProxyMode.Items.Add("Http"); cboProxyMode.Items.Add("Socks"); cboProxyMode.Items.Add("Tor"); // Routes lstRoutes.ResizeColumnString(0, "255.255.255.255/255.255.255.255"); lstRoutes.ResizeColumnString(1, "Outside the VPN tunnel"); lstRoutes.ResizeColumnMax(2); cboRoutesOtherwise.Items.Add(Settings.RouteDirectionToDescription("in")); cboRoutesOtherwise.Items.Add(Settings.RouteDirectionToDescription("out")); cboLockMode.Items.Clear(); cboLockMode.Items.Add("None"); cboLockMode.Items.Add("Automatic"); foreach (NetworkLockPlugin lockPlugin in Engine.Instance.NetworkLockManager.Modes) { cboLockMode.Items.Add(lockPlugin.GetName()); } lblRoutesNetworkLockWarning.Text = Messages.WindowsSettingsRouteLockHelp; lblLockRoutingOutWarning.Text = Messages.NetworkLockNotAvailableWithRouteOut; lstAdvancedEvents.Items.Add(new ListViewItem("App Start")); lstAdvancedEvents.Items.Add(new ListViewItem("App End")); lstAdvancedEvents.Items.Add(new ListViewItem("Session Start")); lstAdvancedEvents.Items.Add(new ListViewItem("Session End")); lstAdvancedEvents.Items.Add(new ListViewItem("VPN Pre")); lstAdvancedEvents.Items.Add(new ListViewItem("VPN Up")); lstAdvancedEvents.Items.Add(new ListViewItem("VPN Down")); lstAdvancedEvents.ResizeColumnsAuto(); lblOpenVpnRcvbuf.Text = Messages.WindowsSettingsOpenVpnRcvBuf + ":"; lblOpenVpnSndbuf.Text = Messages.WindowsSettingsOpenVpnSndBuf + ":"; cboOpenVpnRcvbuf.Items.Clear(); cboOpenVpnRcvbuf.Items.Add(Messages.Automatic); cboOpenVpnRcvbuf.Items.Add(Messages.WindowsSettingsOpenVpnDefault); cboOpenVpnRcvbuf.Items.Add("8 KB"); cboOpenVpnRcvbuf.Items.Add("16 KB"); cboOpenVpnRcvbuf.Items.Add("32 KB"); cboOpenVpnRcvbuf.Items.Add("64 KB"); cboOpenVpnRcvbuf.Items.Add("128 KB"); cboOpenVpnRcvbuf.Items.Add("256 KB"); cboOpenVpnRcvbuf.Items.Add("512 KB"); cboOpenVpnSndbuf.Items.Clear(); cboOpenVpnSndbuf.Items.Add(Messages.Automatic); cboOpenVpnSndbuf.Items.Add(Messages.WindowsSettingsOpenVpnDefault); cboOpenVpnSndbuf.Items.Add("8 KB"); cboOpenVpnSndbuf.Items.Add("16 KB"); cboOpenVpnSndbuf.Items.Add("32 KB"); cboOpenVpnSndbuf.Items.Add("64 KB"); cboOpenVpnSndbuf.Items.Add("128 KB"); cboOpenVpnSndbuf.Items.Add("256 KB"); cboOpenVpnSndbuf.Items.Add("512 KB"); cmdAdvancedUninstallDriver.Visible = Platform.Instance.CanUnInstallDriver(); cmdAdvancedUninstallDriver.Enabled = (Platform.Instance.GetDriverAvailable() != ""); // OVPN directives cboOpenVpnDirectivesDefaultSkip.Items.Clear(); cboOpenVpnDirectivesDefaultSkip.Items.Add(Messages.WindowsSettingsOpenVpnDirectivesDefaultSkip1); cboOpenVpnDirectivesDefaultSkip.Items.Add(Messages.WindowsSettingsOpenVpnDirectivesDefaultSkip2); ReadOptions(); RefreshLogPreview(); EnableIde(); m_onLoadCompleted = true; }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); CommonInit("Settings"); BuildTreeTabs(); lblLoggingHelp.Text = Messages.WindowsSettingsLoggingHelp; pnlGeneralWindowsOnly.Visible = Platform.Instance.IsWindowsSystem(); pnlAdvancedGeneralWindowsOnly.Visible = Platform.Instance.IsWindowsSystem(); chkWindowsDebugWorkaround.Visible = Platform.Instance.IsWindowsSystem(); if( (Engine.Instance.AirVPN != null) && (Engine.Instance.AirVPN.Manifest != null) ) { XmlNodeList xmlModes = Engine.Instance.AirVPN.Manifest.SelectNodes("//modes/mode"); foreach (XmlElement xmlMode in xmlModes) { Controls.ListViewItemProtocol itemMode = new Controls.ListViewItemProtocol(); itemMode.Protocol = xmlMode.GetAttribute("protocol").ToUpperInvariant(); itemMode.Port = Conversions.ToInt32(xmlMode.GetAttribute("port"), 443); itemMode.Entry = Conversions.ToInt32(xmlMode.GetAttribute("entry_index"),0); while (itemMode.SubItems.Count < 5) itemMode.SubItems.Add(""); itemMode.SubItems[0].Text = itemMode.Protocol; itemMode.SubItems[1].Text = itemMode.Port.ToString(); if (itemMode.Entry == 0) itemMode.SubItems[2].Text = "Primary"; else if (itemMode.Entry == 1) itemMode.SubItems[2].Text = "Alternative"; else itemMode.SubItems[2].Text = "Alternative " + xmlMode.GetAttribute("entry_index"); itemMode.SubItems[3].Text = xmlMode.GetAttribute("title"); lstProtocols.Items.Add(itemMode); } lstProtocols.ResizeColumnsAuto(); } // UI cboUiUnit.Items.Clear(); cboUiUnit.Items.Add(Messages.WindowsSettingsUiUnit0); cboUiUnit.Items.Add(Messages.WindowsSettingsUiUnit1); cboUiUnit.Items.Add(Messages.WindowsSettingsUiUnit2); // Proxy cboProxyMode.Items.Clear(); cboProxyMode.Items.Add("None"); cboProxyMode.Items.Add("Detect"); cboProxyMode.Items.Add("Http"); cboProxyMode.Items.Add("Socks"); cboProxyMode.Items.Add("Tor"); // Routes lstRoutes.ResizeColumnString(0, "255.255.255.255/255.255.255.255"); lstRoutes.ResizeColumnString(1, "Outside the VPN tunnel"); lstRoutes.ResizeColumnMax(2); cboRoutesOtherwise.Items.Add(Settings.RouteDirectionToDescription("in")); cboRoutesOtherwise.Items.Add(Settings.RouteDirectionToDescription("out")); cboLockMode.Items.Clear(); cboLockMode.Items.Add("None"); cboLockMode.Items.Add("Automatic"); foreach (NetworkLockPlugin lockPlugin in Engine.Instance.NetworkLockManager.Modes) cboLockMode.Items.Add(lockPlugin.GetName()); lblRoutesNetworkLockWarning.Text = Messages.WindowsSettingsRouteLockHelp; lblLockRoutingOutWarning.Text = Messages.NetworkLockNotAvailableWithRouteOut; lstAdvancedEvents.Items.Add(new ListViewItem("App Start")); lstAdvancedEvents.Items.Add(new ListViewItem("App End")); lstAdvancedEvents.Items.Add(new ListViewItem("Session Start")); lstAdvancedEvents.Items.Add(new ListViewItem("Session End")); lstAdvancedEvents.Items.Add(new ListViewItem("VPN Pre")); lstAdvancedEvents.Items.Add(new ListViewItem("VPN Up")); lstAdvancedEvents.Items.Add(new ListViewItem("VPN Down")); lstAdvancedEvents.ResizeColumnsAuto(); lblOpenVpnRcvbuf.Text = Messages.WindowsSettingsOpenVpnRcvBuf + ":"; lblOpenVpnSndbuf.Text = Messages.WindowsSettingsOpenVpnSndBuf + ":"; cboOpenVpnRcvbuf.Items.Clear(); cboOpenVpnRcvbuf.Items.Add(Messages.Automatic); cboOpenVpnRcvbuf.Items.Add(Messages.WindowsSettingsOpenVpnDefault); cboOpenVpnRcvbuf.Items.Add("8 KB"); cboOpenVpnRcvbuf.Items.Add("16 KB"); cboOpenVpnRcvbuf.Items.Add("32 KB"); cboOpenVpnRcvbuf.Items.Add("64 KB"); cboOpenVpnRcvbuf.Items.Add("128 KB"); cboOpenVpnRcvbuf.Items.Add("256 KB"); cboOpenVpnRcvbuf.Items.Add("512 KB"); cboOpenVpnSndbuf.Items.Clear(); cboOpenVpnSndbuf.Items.Add(Messages.Automatic); cboOpenVpnSndbuf.Items.Add(Messages.WindowsSettingsOpenVpnDefault); cboOpenVpnSndbuf.Items.Add("8 KB"); cboOpenVpnSndbuf.Items.Add("16 KB"); cboOpenVpnSndbuf.Items.Add("32 KB"); cboOpenVpnSndbuf.Items.Add("64 KB"); cboOpenVpnSndbuf.Items.Add("128 KB"); cboOpenVpnSndbuf.Items.Add("256 KB"); cboOpenVpnSndbuf.Items.Add("512 KB"); cmdAdvancedUninstallDriver.Visible = Platform.Instance.CanUnInstallDriver(); cmdAdvancedUninstallDriver.Enabled = (Platform.Instance.GetDriverAvailable() != ""); // OVPN directives cboOpenVpnDirectivesDefaultSkip.Items.Clear(); cboOpenVpnDirectivesDefaultSkip.Items.Add(Messages.WindowsSettingsOpenVpnDirectivesDefaultSkip1); cboOpenVpnDirectivesDefaultSkip.Items.Add(Messages.WindowsSettingsOpenVpnDirectivesDefaultSkip2); ReadOptions(); RefreshLogPreview(); EnableIde(); m_onLoadCompleted = true; }
public void SaveOptions() { Storage s = Engine.Instance.Storage; // General s.SetBool("connect", chkConnect.Checked); s.SetBool("netlock", chkNetLock.Checked); s.SetBool("gui.windows.start_minimized", chkUiMinimizeStart.Checked); s.SetBool("gui.windows.tray", chkUiMinimizeTray.Checked); s.SetBool("gui.windows.notifications", chkSystemNotifications.Checked); s.SetBool("servers.startlast", chkGeneralStartLast.Checked); s.SetBool("gui.exit_confirm", chkExitConfirm.Checked); s.SetBool("os.single_instance", chkOsSingleInstance.Checked); // Ui string uiUnit = ""; if (cboUiUnit.SelectedIndex == 1) { uiUnit = "bytes"; } else if (cboUiUnit.SelectedIndex == 2) { uiUnit = "bits"; } s.Set("ui.unit", uiUnit); if (chkUiFontGeneral.Checked) { int posComma = lblUiFontGeneral.Text.IndexOf(","); s.Set("gui.font.normal.name", lblUiFontGeneral.Text.Substring(0, posComma)); s.Set("gui.font.normal.size", lblUiFontGeneral.Text.Substring(posComma + 1)); } else { s.Set("gui.font.normal.name", ""); s.SetFloat("gui.font.normal.size", 0); } // Protocols if (lstProtocols.Items.Count == 0) // Occur if AirVPN provider is disabled { chkProtocolsAutomatic.Checked = true; } if (chkProtocolsAutomatic.Checked) { s.Set("mode.protocol", "AUTO"); s.SetInt("mode.port", 443); s.SetInt("mode.alt", 0); } else if (lstProtocols.SelectedItems.Count == 1) { Controls.ListViewItemProtocol item = lstProtocols.SelectedItems[0] as Controls.ListViewItemProtocol; s.Set("mode.protocol", item.Protocol); s.SetInt("mode.port", item.Port); s.SetInt("mode.alt", item.Entry); } else { s.Set("mode.protocol", "AUTO"); s.SetInt("mode.port", 443); s.SetInt("mode.alt", 0); } // Proxy s.Set("proxy.mode", cboProxyMode.Text); s.Set("proxy.host", txtProxyHost.Text); s.Set("proxy.port", txtProxyPort.Text); s.Set("proxy.auth", cboProxyAuthentication.Text); s.Set("proxy.login", txtProxyLogin.Text); s.Set("proxy.password", txtProxyPassword.Text); s.SetInt("proxy.tor.control.port", Conversions.ToInt32(txtProxyTorControlPort.Text)); s.Set("proxy.tor.control.password", txtProxyTorControlPassword.Text); // Routes s.Set("routes.default", RouteDescriptionToDirection(cboRoutesOtherwise.Text)); String routes = ""; foreach (ListViewItem item in lstRoutes.Items) { if (routes != "") { routes += ";"; } routes += item.Text + "," + RouteDescriptionToDirection(item.SubItems[1].Text) + "," + item.SubItems[2].Text; } s.Set("routes.custom", routes); // Advanced - General s.SetBool("advanced.expert", chkExpert.Checked); s.SetBool("advanced.check.route", chkAdvancedCheckRoute.Checked); string ipV6 = cboIpV6.Text; if (ipV6 == "None") { s.Set("ipv6.mode", "none"); } else if (ipV6 == "Disable") { s.Set("ipv6.mode", "disable"); } else { s.Set("ipv6.mode", "none"); } s.SetBool("pinger.enabled", chkAdvancedPingerEnabled.Checked); s.SetBool("routes.remove_default", chkRouteRemoveDefault.Checked); s.SetBool("windows.tap_up", chkWindowsTapUp.Checked); s.SetBool("windows.dhcp_disable", chkWindowsDhcpSwitch.Checked); s.SetBool("windows.disable_driver_upgrade", chkWindowsDisableDriverUpgrade.Checked); s.SetBool("windows.ipv6.os_disable", chkWindowsIPv6DisableAtOs.Checked); s.SetBool("windows.dns.force_all_interfaces", chkWindowsDnsForceAllInterfaces.Checked); s.SetBool("windows.dns.lock", chkWindowsDnsLock.Checked); s.SetBool("windows.wfp", chkWindowsWfp.Checked); s.Set("executables.openvpn", txtExePath.Text); int manifestRefreshIndex = cboAdvancedManifestRefresh.SelectedIndex; if (manifestRefreshIndex == 0) // Auto { s.SetInt("advanced.manifest.refresh", -1); } else if (manifestRefreshIndex == 1) // Never { s.SetInt("advanced.manifest.refresh", 0); } else if (manifestRefreshIndex == 2) // One minute { s.SetInt("advanced.manifest.refresh", 1); } else if (manifestRefreshIndex == 3) // Ten minute { s.SetInt("advanced.manifest.refresh", 10); } else if (manifestRefreshIndex == 4) // One hour { s.SetInt("advanced.manifest.refresh", 60); } int openVpnSndBufIndex = cboOpenVpnSndbuf.SelectedIndex; if (openVpnSndBufIndex == 0) { s.SetInt("openvpn.sndbuf", -2); } else if (openVpnSndBufIndex == 1) { s.SetInt("openvpn.sndbuf", -1); } else if (openVpnSndBufIndex == 2) { s.SetInt("openvpn.sndbuf", 1024 * 8); } else if (openVpnSndBufIndex == 3) { s.SetInt("openvpn.sndbuf", 1024 * 16); } else if (openVpnSndBufIndex == 4) { s.SetInt("openvpn.sndbuf", 1024 * 32); } else if (openVpnSndBufIndex == 5) { s.SetInt("openvpn.sndbuf", 1024 * 64); } else if (openVpnSndBufIndex == 6) { s.SetInt("openvpn.sndbuf", 1024 * 128); } else if (openVpnSndBufIndex == 7) { s.SetInt("openvpn.sndbuf", 1024 * 256); } else if (openVpnSndBufIndex == 8) { s.SetInt("openvpn.sndbuf", 1024 * 512); } int openVpnRcvBufIndex = cboOpenVpnRcvbuf.SelectedIndex; if (openVpnRcvBufIndex == 0) { s.SetInt("openvpn.rcvbuf", -2); } else if (openVpnRcvBufIndex == 1) { s.SetInt("openvpn.rcvbuf", -1); } else if (openVpnRcvBufIndex == 2) { s.SetInt("openvpn.rcvbuf", 1024 * 8); } else if (openVpnRcvBufIndex == 3) { s.SetInt("openvpn.rcvbuf", 1024 * 16); } else if (openVpnRcvBufIndex == 4) { s.SetInt("openvpn.rcvbuf", 1024 * 32); } else if (openVpnRcvBufIndex == 5) { s.SetInt("openvpn.rcvbuf", 1024 * 64); } else if (openVpnRcvBufIndex == 6) { s.SetInt("openvpn.rcvbuf", 1024 * 128); } else if (openVpnRcvBufIndex == 7) { s.SetInt("openvpn.rcvbuf", 1024 * 256); } else if (openVpnRcvBufIndex == 8) { s.SetInt("openvpn.rcvbuf", 1024 * 512); } // Advanced - DNS s.Set("dns.mode", cboDnsSwitchMode.Text); string dnsMode = cboDnsSwitchMode.Text; if (dnsMode == "Disabled") { s.Set("dns.mode", "none"); } else if (dnsMode == "Automatic") { s.Set("dns.mode", "auto"); } else if (dnsMode == "Resolvconf (Linux only)") { s.Set("dns.mode", "resolvconf"); } else if (dnsMode == "Renaming (Linux only)") { s.Set("dns.mode", "rename"); } else { s.Set("dns.mode", "auto"); } s.SetBool("dns.check", chkDnsCheck.Checked); string dnsServers = ""; foreach (ListViewItem dnsServerItem in lstDnsServers.Items) { if (dnsServers != "") { dnsServers += ","; } dnsServers += dnsServerItem.Text; } s.Set("dns.servers", dnsServers); // Advanced - Lock string lockMode = cboLockMode.Text; 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", chkLockAllowPrivate.Checked); s.SetBool("netlock.allow_ping", chkLockAllowPing.Checked); s.Set("netlock.allowed_ips", txtLockAllowedIPS.Text); // Advanced - Logging s.SetBool("log.file.enabled", chkLoggingEnabled.Checked); s.Set("log.file.path", txtLogPath.Text); s.SetBool("log.level.debug", chkLogLevelDebug.Checked); // Advanced - OVPN Directives s.Set("openvpn.directives", txtOpenVpnDirectivesBase.Text); s.Set("openvpn.custom", txtOpenVpnDirectivesCustom.Text); s.SetBool("openvpn.skip_defaults", (cboOpenVpnDirectivesDefaultSkip.SelectedIndex == 1)); // 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); Platform.Instance.SetAutoStart(chkSystemStart.Checked); Engine.OnSettingsChanged(); }