protected override void OnLoad(EventArgs e) { base.OnLoad(e); CommonInit(Messages.WindowsConnectionTitle); m_tabMain = new Eddie.Forms.Controls.TabNavigator(); m_tabMain.Font = Skin.FontNormal; m_tabMain.Top = 0; m_tabMain.Left = 0; m_tabMain.Height = tabMain.Height; m_tabMain.Width = ClientSize.Width; m_tabMain.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom; m_tabMain.ImportTabControl(tabMain); Controls.Add(m_tabMain); m_connectionActive = Connection.BuildConnectionActive(true); txtOvpnGenerated.Text = GuiUtils.NormalizeString(m_connectionActive.OpenVpnProfileStartup.Get()); if (Connection.Path != "") { if (Platform.Instance.FileExists(Connection.Path)) { string ovpnOriginal = Platform.Instance.FileContentsReadText(Connection.Path); txtOvpnOriginal.Text = Platform.Instance.NormalizeString(ovpnOriginal); } } else { m_tabMain.Pages.RemoveAt(1); } EnableIde(); }
public override void AwakeFromNib() { base.AwakeFromNib(); Window.Title = Constants.Name + " - " + Messages.WindowsConnectionTitle; m_connectionActive = Connection.BuildConnectionActive(true); TxtOvpnGenerated.Value = Core.Platform.Instance.NormalizeString(m_connectionActive.OpenVpnProfileStartup.Get()); if (Connection.Path != "") { if (Core.Platform.Instance.FileExists(Connection.Path)) { string original = Core.Platform.Instance.FileContentsReadText(Connection.Path); TxtOvpnOriginal.Value = original; } } else { TabMain.Remove(TabMain.Items[1]); } CmdOk.Activated += (object sender, EventArgs e) => { Window.Close(); NSApplication.SharedApplication.StopModal(); }; CmdCancel.Activated += (object sender, EventArgs e) => { Window.Close(); NSApplication.SharedApplication.StopModal(); }; }
public override bool OnDnsSwitchDo(ConnectionActive connectionActive, IpAddresses dns) { string mode = Engine.Instance.Storage.GetLower("dns.mode"); if (mode == "auto") { string[] interfaces = GetInterfaces(); foreach (string i in interfaces) { string i2 = i.Trim(); string currentStr = SystemShell.Shell("/usr/sbin/networksetup", new string[] { "-getdnsservers", SystemShell.EscapeInsideQuote(i2) }); // v2 IpAddresses current = new IpAddresses(); foreach (string line in currentStr.Split('\n')) { string ip = line.Trim(); if (IpAddress.IsIP(ip)) { current.Add(ip); } } if (dns.Equals(current) == false) { DnsSwitchEntry e = new DnsSwitchEntry(); e.Name = i2; e.Dns = current.Addresses; m_listDnsSwitch.Add(e); SystemShell s = new SystemShell(); s.Path = LocateExecutable("networksetup"); s.Arguments.Add("-setdnsservers"); s.Arguments.Add(SystemShell.EscapeInsideQuote(i2)); if (dns.IPs.Count == 0) { s.Arguments.Add("empty"); } else { foreach (IpAddress ip in dns.IPs) { s.Arguments.Add(ip.Address); } } s.Run(); Engine.Instance.Logs.Log(LogType.Verbose, MessagesFormatter.Format(Messages.OsMacNetworkAdapterDnsDone, i2, ((current.Count == 0) ? "Automatic" : current.Addresses), dns.Addresses)); } } Recovery.Save(); } base.OnDnsSwitchDo(connectionActive, dns); return(true); }
public override void OnBuildConnectionActive(ConnectionInfo connection, ConnectionActive connectionActive) { base.OnBuildConnectionActive(connection, connectionActive); if (connectionActive.OpenVpnProfileStartup.ExistsDirective("auth-retry")) { connectionActive.OpenVpnProfileStartup.AppendDirective("auth-retry", "none", ""); } }
public override void OnBuildConnectionActiveAuth(ConnectionActive connectionActive) { base.OnBuildConnectionActiveAuth(connectionActive); string key = Engine.Instance.Storage.Get("key"); XmlNode nodeUser = User; if (nodeUser != null) { connectionActive.OpenVpnProfileStartup.AppendDirective("<ca>", nodeUser.Attributes["ca"].Value, ""); XmlElement xmlKey = nodeUser.SelectSingleNode("keys/key[@name='" + key + "']") as XmlElement; if (xmlKey != null) { connectionActive.OpenVpnProfileStartup.AppendDirective("<cert>", xmlKey.Attributes["crt"].Value, ""); connectionActive.OpenVpnProfileStartup.AppendDirective("<key>", xmlKey.Attributes["key"].Value, ""); } } }
public override bool OnDnsSwitchDo(ConnectionActive connectionActive, IpAddresses dns) { if (GetDnsSwitchMode() == "rename") { string text = "# " + Engine.Instance.GenerateFileHeader() + "\n\n"; foreach (IpAddress dnsSingle in dns.IPs) { text += "nameserver " + dnsSingle.Address + "\n"; } Engine.Instance.Elevated.DoCommandSync("dns-switch-rename-do", "text", text); Engine.Instance.Logs.Log(LogType.Verbose, LanguageManager.GetText("OsLinuxDnsRenameDone")); } base.OnDnsSwitchDo(connectionActive, dns); return(true); }
public override bool OnDnsSwitchDo(ConnectionActive connectionActive, IpAddresses dns) { string mode = Engine.Instance.Storage.GetLower("dns.mode"); if (mode == "auto") { string result = Engine.Instance.Elevated.DoCommandSync("dns-switch-do", "dns", dns.ToString()); if (result != "") { foreach (string resultItem in result.Split('\n')) { string[] fields = resultItem.Split(';'); if (fields.Length != 3) { continue; } if (fields[0] == "SwitchDNS") { string interfaceName = fields[1]; IpAddresses oldIPs = new IpAddresses(fields[2]); DnsSwitchEntry e = new DnsSwitchEntry(); e.Name = interfaceName; e.Dns = oldIPs.Addresses; m_listDnsSwitch.Add(e); Engine.Instance.Logs.Log(LogType.Verbose, LanguageManager.GetText("OsMacNetworkAdapterDnsDone", interfaceName, ((oldIPs.Count == 0) ? "Automatic" : oldIPs.Addresses), dns.Addresses)); } } } Recovery.Save(); } base.OnDnsSwitchDo(connectionActive, dns); return(true); }
public override void OnBuildConnectionActive(ConnectionInfo connection, ConnectionActive connectionActive) { base.OnBuildConnectionActive(connection, connectionActive); OvpnBuilder ovpn = connectionActive.OpenVpnProfileStartup; ConnectionMode mode = GetMode(); if (mode.Protocol == "SSH") { connectionActive.SshLocalPort = Engine.Instance.Storage.GetInt("ssh.port"); connectionActive.SshRemotePort = mode.Port; connectionActive.SshPortDestination = mode.SshPortDestination; if (connectionActive.SshLocalPort == 0) { connectionActive.SshLocalPort = RandomGenerator.GetInt(1024, 64 * 1024); } } else if (mode.Protocol == "SSL") { connectionActive.SslLocalPort = Engine.Instance.Storage.GetInt("ssl.port"); connectionActive.SslRemotePort = mode.Port; if (connectionActive.SslLocalPort == 0) { connectionActive.SslLocalPort = RandomGenerator.GetInt(1024, 64 * 1024); } } { string modeDirectives = mode.Directives; string paramUserTA = ""; string paramUserTlsCrypt = ""; if (User != null) { paramUserTA = UtilsXml.XmlGetAttributeString(User, "ta", ""); paramUserTlsCrypt = UtilsXml.XmlGetAttributeString(User, "tls_crypt", ""); } modeDirectives = modeDirectives.Replace("{@user-ta}", paramUserTA); modeDirectives = modeDirectives.Replace("{@user-tlscrypt}", paramUserTlsCrypt); ovpn.AppendDirectives(modeDirectives, "Mode level"); } // Pick the IP IpAddress ip = null; string entryIpLayer = Engine.Instance.Storage.Get("network.entry.iplayer"); if (entryIpLayer == "ipv6-ipv4") { ip = connection.IpsEntry.GetV6ByIndex(mode.EntryIndex); if (ip == null) { ip = connection.IpsEntry.GetV4ByIndex(mode.EntryIndex); } } else if (entryIpLayer == "ipv4-ipv6") { ip = connection.IpsEntry.GetV4ByIndex(mode.EntryIndex); if (ip == null) { ip = connection.IpsEntry.GetV6ByIndex(mode.EntryIndex); } } else if (entryIpLayer == "ipv6-only") { ip = connection.IpsEntry.GetV6ByIndex(mode.EntryIndex); } else if (entryIpLayer == "ipv4-only") { ip = connection.IpsEntry.GetV4ByIndex(mode.EntryIndex); } if (ip != null) { IpAddress remoteAddress = ip.Clone(); int remotePort = mode.Port; if (mode.Protocol == "SSH") { remoteAddress = "127.0.0.1"; remotePort = connectionActive.SshLocalPort; } else if (mode.Protocol == "SSL") { remoteAddress = "127.0.0.1"; remotePort = connectionActive.SslLocalPort; } ovpn.AppendDirective("remote", remoteAddress.Address + " " + remotePort.ToString(), ""); // Adjust the protocol OvpnBuilder.Directive dProto = ovpn.GetOneDirective("proto"); if (dProto != null) { dProto.Text = dProto.Text.ToLowerInvariant(); if (dProto.Text == "tcp") { if (remoteAddress.IsV6) { dProto.Text = "tcp6"; } } else if (dProto.Text == "udp") { if (remoteAddress.IsV6) { dProto.Text = "udp6"; } } } if ((mode.Protocol == "SSH") || (mode.Protocol == "SSL")) { if (Constants.FeatureIPv6ControlOptions) { if (((ip.IsV4) && (connectionActive.TunnelIPv4)) || ((ip.IsV6) && (connectionActive.TunnelIPv6))) { connectionActive.AddRoute(ip, "net_gateway", "VPN Entry IP"); } } else { string routesDefault = Engine.Instance.Storage.Get("routes.default"); if (routesDefault == "in") { connectionActive.AddRoute(ip, "net_gateway", "VPN Entry IP"); } } } } connectionActive.Protocol = mode.Protocol; if (ip != null) { connectionActive.Address = ip.Clone(); } }