예제 #1
0
파일: OpenVPN.cs 프로젝트: siemantic/Eddie
        public override void OnBuildOvpn(ConnectionInfo connection, OvpnBuilder ovpn)
        {
            base.OnBuildOvpn(connection, ovpn);

            if (ovpn.ExistsDirective("auth-retry"))
            {
                ovpn.AppendDirective("auth-retry", "none", "");
            }
        }
예제 #2
0
        public override void OnBuildOvpn(OvpnBuilder ovpn)
        {
            base.OnBuildOvpn(ovpn);

            if (GetDnsSwitchMode() == "resolvconf")
            {
                string dnsScriptPath = Software.FindResource("update-resolv-conf");
                if (dnsScriptPath != "")
                {
                    EnsureExecutablePermissions(dnsScriptPath);
                    Engine.Instance.Logs.Log(LogType.Verbose, Messages.DnsResolvConfScript);
                    ovpn.AppendDirective("script-security", "2", "");
                    ovpn.AppendDirective("up", dnsScriptPath, "");
                    ovpn.AppendDirective("down", dnsScriptPath, "");
                }
            }

            ovpn.AppendDirective("route-delay", "5", ""); // 2.8, to resolve some issue on some distro, ex. Fedora 21
        }
예제 #3
0
        public override void OnBuildOvpnAuth(OvpnBuilder ovpn)
        {
            base.OnBuildOvpnAuth(ovpn);

            string key = Engine.Instance.Storage.Get("key");

            XmlNode nodeUser = User;

            ovpn.AppendDirective("<ca>", nodeUser.Attributes["ca"].Value, "");
            XmlElement xmlKey = nodeUser.SelectSingleNode("keys/key[@name='" + key + "']") as XmlElement;

            if (xmlKey == null)
            {
                throw new Exception(Messages.Format(Messages.KeyNotFound, key));
            }
            ovpn.AppendDirective("<cert>", xmlKey.Attributes["crt"].Value, "");
            ovpn.AppendDirective("<key>", xmlKey.Attributes["key"].Value, "");
            ovpn.AppendDirective("key-direction", "1", "");
            ovpn.AppendDirective("<tls-auth>", nodeUser.Attributes["ta"].Value, "");
        }
예제 #4
0
        public override void OnBuildOvpnAuth(OvpnBuilder ovpn)
        {
            base.OnBuildOvpnAuth(ovpn);

            string key = Engine.Instance.Storage.Get("key");

            XmlNode nodeUser = User;
            ovpn.AppendDirective("<ca>", nodeUser.Attributes["ca"].Value, "");
            XmlElement xmlKey = nodeUser.SelectSingleNode("keys/key[@name='" + key + "']") as XmlElement;
            if (xmlKey == null)
                throw new Exception(MessagesFormatter.Format(Messages.KeyNotFound, key));
            ovpn.AppendDirective("<cert>", xmlKey.Attributes["crt"].Value, "");
            ovpn.AppendDirective("<key>", xmlKey.Attributes["key"].Value, "");
            ovpn.AppendDirective("key-direction","1", "");
            ovpn.AppendDirective("<tls-auth>", nodeUser.Attributes["ta"].Value, "");
        }
예제 #5
0
        public override void OnBuildOvpn(OvpnBuilder ovpn)
        {
            base.OnBuildOvpn(ovpn);

            // Move here AirVPN specific of Session thread (protocol, remote, alt, port, proxy)

            ServerInfo CurrentServer = Engine.Instance.CurrentServer;

            string protocol = Engine.Instance.Storage.Get("mode.protocol").ToUpperInvariant();
            int port = Engine.Instance.Storage.GetInt("mode.port");
            int alt = Engine.Instance.Storage.GetInt("mode.alt");
            int proxyPort = 0;

            if (protocol == "AUTO")
            {
                protocol = CurrentServer.Provider.GetKeyValue("mode_protocol", "UDP");
                string proxyMode = Engine.Instance.Storage.GetLower("proxy.mode");
                if (proxyMode != "none")
                    protocol = "TCP";
                port = Conversions.ToInt32(CurrentServer.Provider.GetKeyValue("mode_port", "443"));
                alt = Conversions.ToInt32(CurrentServer.Provider.GetKeyValue("mode_alt", "0"));
            }

            if (protocol == "SSH")
            {
                proxyPort = Engine.Instance.Storage.GetInt("ssh.port");
                if (proxyPort == 0)
                    proxyPort = RandomGenerator.GetInt(1024, 64 * 1024);
            }
            else if (protocol == "SSL")
            {
                proxyPort = Engine.Instance.Storage.GetInt("ssl.port");
                if (proxyPort == 0)
                    proxyPort = RandomGenerator.GetInt(1024, 64 * 1024);
            }
            else
            {
                proxyPort = 0;
            }

            if (protocol == "UDP")
            {
                ovpn.AppendDirective("proto", "udp", "");
            }
            else // TCP, SSH, SSL, Tor
            {
                ovpn.AppendDirective("proto", "tcp", "");
            }

            string ip = CurrentServer.IpEntry;
            if (alt == 1)
                ip = CurrentServer.IpEntry2;

            if (protocol == "SSH")
                ovpn.AppendDirective("remote", "127.0.0.1 " + Conversions.ToString(proxyPort), "");
            else if (protocol == "SSL")
                ovpn.AppendDirective("remote", "127.0.0.1 " + Conversions.ToString(proxyPort), "");
            else
                ovpn.AppendDirective("remote", ip + " " + port.ToString(), "");

            string routesDefault = Engine.Instance.Storage.Get("routes.default");
            if (routesDefault == "in")
            {
                if ((protocol == "SSH") || (protocol == "SSL"))
                {
                    ovpn.AppendDirective("route", ip + " 255.255.255.255 net_gateway", "VPN Entry IP");
                }
            }

            ovpn.Protocol = protocol;
            ovpn.Address = ip;
            ovpn.Port = port;
            ovpn.ProxyPort = proxyPort;
        }
예제 #6
0
        public void ScanDir(string path, bool recursive, List <ConnectionInfo> connections)
        {
            if (path == "")
            {
                return;
            }

            try
            {
                foreach (string filePath in Directory.GetFiles(path))
                {
                    FileInfo fileInfo = new FileInfo(filePath);

                    string extension = fileInfo.Extension.ToLowerInvariant().Trim();
                    if ((extension != ".ovpn") && (extension != ".conf"))
                    {
                        continue;
                    }

                    // Already listed?
                    XmlElement nodeProfile = null;
                    foreach (XmlElement nodeFind in Profiles.ChildNodes)
                    {
                        string pathFind = UtilsXml.XmlGetAttributeString(nodeFind, "path", "");
                        if (pathFind == fileInfo.FullName)
                        {
                            nodeProfile = nodeFind;
                            break;
                        }
                    }

                    // Skip if is already checked
                    if ((nodeProfile != null) && (UtilsXml.XmlGetAttributeString(nodeProfile, "checked", "") != ""))
                    {
                        continue;
                    }

                    if (Platform.Instance.FileExists(filePath) == false)
                    {
                        continue;
                    }

                    // Compute values
                    FileInfo file  = new FileInfo(filePath);
                    string   hosts = "";

                    try
                    {
                        string ovpnOriginal = Platform.Instance.FileContentsReadText(file.FullName);

                        OvpnBuilder ovpnBuilder = new OvpnBuilder();
                        ovpnBuilder.AppendDirectives(ovpnOriginal, "Original");
                        //string ovpnNormalized = ovpnBuilder.Get();

                        foreach (OvpnBuilder.Directive remoteDirective in ovpnBuilder.GetDirectiveList("remote"))
                        {
                            string host    = remoteDirective.Text;
                            int    posPort = host.IndexOf(" ");
                            if (posPort != -1)
                            {
                                host = host.Substring(0, posPort).Trim();
                            }
                            if (hosts != "")
                            {
                                hosts += ",";
                            }
                            hosts += host;
                        }

                        if (nodeProfile == null)
                        {
                            nodeProfile = Profiles.OwnerDocument.CreateElement("profile");
                            Profiles.AppendChild(nodeProfile);
                        }

                        UtilsXml.XmlSetAttributeString(nodeProfile, "remote", hosts);
                        UtilsXml.XmlSetAttributeString(nodeProfile, "path", file.FullName);

                        UtilsXml.XmlSetAttributeString(nodeProfile, "checked", "1");
                    }
                    catch (System.Exception e)
                    {
                        string message = MessagesFormatter.Format(Messages.ProvidersOpenVpnErrorProfile, file.FullName, this.Title, e.Message);                         // TOTRANSLATE
                        Engine.Instance.Logs.Log(LogType.Warning, message);
                    }
                }

                if (recursive)
                {
                    foreach (string dirPath in Directory.GetDirectories(path))
                    {
                        ScanDir(dirPath, recursive, connections);
                    }
                }
            }
            catch (System.Exception e)
            {
                Engine.Instance.Logs.Log(e);
            }
        }
예제 #7
0
        public override void OnBuildOvpn(OvpnBuilder ovpn)
        {
            base.OnBuildOvpn(ovpn);

            // Move here AirVPN specific of Session thread (protocol, remote, alt, port, proxy)

            ServerInfo CurrentServer = Engine.Instance.CurrentServer;

            string protocol  = Engine.Instance.Storage.Get("mode.protocol").ToUpperInvariant();
            int    port      = Engine.Instance.Storage.GetInt("mode.port");
            int    alt       = Engine.Instance.Storage.GetInt("mode.alt");
            int    proxyPort = 0;

            if (protocol == "AUTO")
            {
                protocol = CurrentServer.Provider.GetKeyValue("mode_protocol", "UDP");
                string proxyMode = Engine.Instance.Storage.GetLower("proxy.mode");
                if (proxyMode != "none")
                {
                    protocol = "TCP";
                }
                port = Conversions.ToInt32(CurrentServer.Provider.GetKeyValue("mode_port", "443"));
                alt  = Conversions.ToInt32(CurrentServer.Provider.GetKeyValue("mode_alt", "0"));
            }

            if (protocol == "SSH")
            {
                proxyPort = Engine.Instance.Storage.GetInt("ssh.port");
                if (proxyPort == 0)
                {
                    proxyPort = RandomGenerator.GetInt(1024, 64 * 1024);
                }
            }
            else if (protocol == "SSL")
            {
                proxyPort = Engine.Instance.Storage.GetInt("ssl.port");
                if (proxyPort == 0)
                {
                    proxyPort = RandomGenerator.GetInt(1024, 64 * 1024);
                }
            }
            else
            {
                proxyPort = 0;
            }

            if (protocol == "UDP")
            {
                ovpn.AppendDirective("proto", "udp", "");
            }
            else // TCP, SSH, SSL, Tor
            {
                ovpn.AppendDirective("proto", "tcp", "");
            }

            string ip = CurrentServer.IpEntry;

            if (alt == 1)
            {
                ip = CurrentServer.IpEntry2;
            }

            if (protocol == "SSH")
            {
                ovpn.AppendDirective("remote", "127.0.0.1 " + Conversions.ToString(proxyPort), "");
            }
            else if (protocol == "SSL")
            {
                ovpn.AppendDirective("remote", "127.0.0.1 " + Conversions.ToString(proxyPort), "");
            }
            else
            {
                ovpn.AppendDirective("remote", ip + " " + port.ToString(), "");
            }

            string routesDefault = Engine.Instance.Storage.Get("routes.default");

            if (routesDefault == "in")
            {
                if ((protocol == "SSH") || (protocol == "SSL"))
                {
                    ovpn.AppendDirective("route", ip + " 255.255.255.255 net_gateway", "VPN Entry IP");
                }
            }


            ovpn.Protocol  = protocol;
            ovpn.Address   = ip;
            ovpn.Port      = port;
            ovpn.ProxyPort = proxyPort;
        }
예제 #8
0
        public override void OnBuildOvpnDefaults(OvpnBuilder ovpn)
        {
            base.OnBuildOvpnDefaults(ovpn);

            ovpn.AppendDirectives(Manifest.Attributes["openvpn_directives"].Value.Replace("\t", "").Trim(), "Provider level");
        }
예제 #9
0
        // Parse the OpenVPN configuration file. Check if is valid, import external files, normalize.
        public Dictionary<string, string> OvpnParse(FileInfo file, bool interactive)
        {
            try
            {
                Dictionary<string, string> dictInfo = new Dictionary<string, string>();

                string ovpnOriginal = Platform.Instance.FileContentsReadText(file.FullName);

                OvpnBuilder ovpnBuilder = new OvpnBuilder();
                ovpnBuilder.AppendDirectives(ovpnOriginal, "Original");
                string ovpnNormalized = ovpnBuilder.Get();

                OvpnBuilder.Directive directiveRemote = ovpnBuilder.GetOneDirective("remote");
                if(directiveRemote != null)
                {
                    string host = directiveRemote.Text;
                    int posPort = host.IndexOf(" ");
                    if (posPort != -1)
                        host = host.Substring(0, posPort).Trim();
                    dictInfo["remote"] = host;
                }
                else
                    dictInfo["remote"] = "";

                dictInfo["ovpn"] = ovpnNormalized;
                dictInfo["path"] = file.FullName;
                dictInfo["country"] = "";

                // Compute user-friendly name
                {
                    string name = TitleForDisplay + file.FullName;

                    name = name.Replace(GetPathScan(), "").Trim();

                    //name = Regex.Replace(name, "udp", "", RegexOptions.IgnoreCase);
                    //name = Regex.Replace(name, "tcp", "", RegexOptions.IgnoreCase);
                    name = Regex.Replace(name, "tblk", "", RegexOptions.IgnoreCase); // TunnelBlick
                    name = Regex.Replace(name, "ovpn", "", RegexOptions.IgnoreCase); // OpenVPN

                    foreach (string countryName in CountriesManager.Name2Code.Keys)
                    {
                        if (name.IndexOf(countryName) != -1)
                        {
                            dictInfo["country"] = CountriesManager.Name2Code[countryName];
                        }
                    }

                    // Cleaning
                    name = name.Replace("-", " - ").Trim();
                    name = name.Replace("_", " - ").Trim();
                    name = name.Replace(".", " - ").Trim();

                    name = name.Replace("\\", " - ").Trim();
                    name = name.Replace("/", " - ").Trim();

                    for (; ; )
                    {
                        string orig = name;

                        name = name.Replace("  ", " ");
                        name = name.Replace("\t", " ");
                        name = name.Replace("- -", "-");

                        name = name.Trim(" -".ToCharArray());

                        if (name == orig)
                            break;
                    }

                    if (dictInfo.ContainsKey("protocol"))
                        name += " - " + dictInfo["protocol"].ToUpperInvariant();

                    dictInfo["name"] = name;
                }

                return dictInfo;
            }
            catch (System.Exception e)
            {
                string message = MessagesFormatter.Format("Profiles scan, {1} (in profile '{1}')", e.Message, file.FullName); // TOTRANSLATE
                if (interactive)
                    Engine.Instance.Logs.Log(LogType.Fatal, message);
                else
                    Engine.Instance.Logs.Log(LogType.Warning, message);
                return null;
            }
        }
예제 #10
0
        public override void OnBuildOvpn(OvpnBuilder ovpn)
        {
            base.OnBuildOvpn(ovpn);

            ovpn.AppendDirective("route-delay", "5", "");             // 2.8, to resolve some issue on some distro, ex. Fedora 21
        }
예제 #11
0
        public override void OnBuildOvpn(ConnectionInfo connection, OvpnBuilder ovpn)
        {
            base.OnBuildOvpn(connection, ovpn);

            ConnectionMode mode = GetMode();

            int proxyPort = 0;

            if (mode.Protocol == "SSH")
            {
                proxyPort = Engine.Instance.Storage.GetInt("ssh.port");
                if (proxyPort == 0)
                {
                    proxyPort = RandomGenerator.GetInt(1024, 64 * 1024);
                }
            }
            else if (mode.Protocol == "SSL")
            {
                proxyPort = Engine.Instance.Storage.GetInt("ssl.port");
                if (proxyPort == 0)
                {
                    proxyPort = RandomGenerator.GetInt(1024, 64 * 1024);
                }
            }
            else
            {
                proxyPort = 0;
            }

            {
                string modeDirectives = mode.Directives;
                string paramUserTA    = "";
                if (User != null)
                {
                    paramUserTA = Utils.XmlGetAttributeString(User, "ta", "");
                }
                modeDirectives = modeDirectives.Replace("{@user-ta}", paramUserTA);
                ovpn.AppendDirectives(modeDirectives, "Mode level");
            }

            // Pick the IP
            IpAddress ip            = null;
            string    protocolEntry = Engine.Instance.Storage.Get("protocol.ip.entry");

            if (protocolEntry == "ipv6-ipv4")
            {
                ip = connection.IpsEntry.GetV6ByIndex(mode.EntryIndex);
                if (ip == null)
                {
                    ip = connection.IpsEntry.GetV4ByIndex(mode.EntryIndex);
                }
            }
            else if (protocolEntry == "ipv4-ipv6")
            {
                ip = connection.IpsEntry.GetV4ByIndex(mode.EntryIndex);
                if (ip == null)
                {
                    ip = connection.IpsEntry.GetV6ByIndex(mode.EntryIndex);
                }
            }
            else if (protocolEntry == "ipv6-only")
            {
                ip = connection.IpsEntry.GetV6ByIndex(mode.EntryIndex);
            }
            else if (protocolEntry == "ipv4-only")
            {
                ip = connection.IpsEntry.GetV4ByIndex(mode.EntryIndex);
            }

            if (ip != null)
            {
                if (mode.Protocol == "SSH")
                {
                    ovpn.AppendDirective("remote", "127.0.0.1 " + Conversions.ToString(proxyPort), "");
                }
                else if (mode.Protocol == "SSL")
                {
                    ovpn.AppendDirective("remote", "127.0.0.1 " + Conversions.ToString(proxyPort), "");
                }
                else
                {
                    ovpn.AppendDirective("remote", ip.AddressQ + " " + mode.Port.ToString(), "");
                }

                string routesDefault = Engine.Instance.Storage.Get("routes.default");
                if (routesDefault == "in")
                {
                    if ((mode.Protocol == "SSH") || (mode.Protocol == "SSL"))
                    {
                        ovpn.AppendDirective("route", ip.ToOpenVPN() + " net_gateway", "VPN Entry IP");                         // ClodoIPv6 // ToFix
                    }
                }
            }

            ovpn.Protocol  = mode.Protocol; // TOCLEAN
            ovpn.Address   = ip;
            ovpn.Port      = mode.Port;
            ovpn.ProxyPort = proxyPort;
        }
예제 #12
0
        // Parse the OpenVPN configuration file. Check if is valid, import external files, normalize.
        public Dictionary <string, string> OvpnParse(FileInfo file, bool interactive)
        {
            try
            {
                Dictionary <string, string> dictInfo = new Dictionary <string, string>();

                string ovpnOriginal = Platform.Instance.FileContentsReadText(file.FullName);


                OvpnBuilder ovpnBuilder = new OvpnBuilder();
                ovpnBuilder.AppendDirectives(ovpnOriginal, "Original");
                string ovpnNormalized = ovpnBuilder.Get();

                OvpnBuilder.Directive directiveRemote = ovpnBuilder.GetOneDirective("remote");
                if (directiveRemote != null)
                {
                    string host    = directiveRemote.Text;
                    int    posPort = host.IndexOf(" ");
                    if (posPort != -1)
                    {
                        host = host.Substring(0, posPort).Trim();
                    }
                    dictInfo["remote"] = host;
                }
                else
                {
                    dictInfo["remote"] = "";
                }

                dictInfo["ovpn"]    = ovpnNormalized;
                dictInfo["path"]    = file.FullName;
                dictInfo["country"] = "";

                // Compute user-friendly name
                {
                    string name = TitleForDisplay + file.FullName;

                    name = name.Replace(GetPathScan(), "").Trim();

                    //name = Regex.Replace(name, "udp", "", RegexOptions.IgnoreCase);
                    //name = Regex.Replace(name, "tcp", "", RegexOptions.IgnoreCase);
                    name = Regex.Replace(name, "tblk", "", RegexOptions.IgnoreCase);                     // TunnelBlick
                    name = Regex.Replace(name, "ovpn", "", RegexOptions.IgnoreCase);                     // OpenVPN

                    foreach (string countryName in CountriesManager.Name2Code.Keys)
                    {
                        if (name.IndexOf(countryName) != -1)
                        {
                            dictInfo["country"] = CountriesManager.Name2Code[countryName];
                        }
                    }

                    // Cleaning
                    name = name.Replace("-", " - ").Trim();
                    name = name.Replace("_", " - ").Trim();
                    name = name.Replace(".", " - ").Trim();

                    name = name.Replace("\\", " - ").Trim();
                    name = name.Replace("/", " - ").Trim();

                    for (; ;)
                    {
                        string orig = name;

                        name = name.Replace("  ", " ");
                        name = name.Replace("\t", " ");
                        name = name.Replace("- -", "-");

                        name = name.Trim(" -".ToCharArray());

                        if (name == orig)
                        {
                            break;
                        }
                    }

                    if (dictInfo.ContainsKey("protocol"))
                    {
                        name += " - " + dictInfo["protocol"].ToUpperInvariant();
                    }

                    dictInfo["name"] = name;
                }

                return(dictInfo);
            }
            catch (System.Exception e)
            {
                string message = MessagesFormatter.Format("Profiles scan, {1} (in profile '{1}')", e.Message, file.FullName);                 // TOTRANSLATE
                if (interactive)
                {
                    Engine.Instance.Logs.Log(LogType.Fatal, message);
                }
                else
                {
                    Engine.Instance.Logs.Log(LogType.Warning, message);
                }
                return(null);
            }
        }
예제 #13
0
 public string ComputeFriendlyNameFromPath(string path, OvpnBuilder ovpn)
 {
     return(path);
 }
예제 #14
0
 public override void OnBuildOvpn(OvpnBuilder ovpn)
 {
     base.OnBuildOvpn(ovpn);
 }
예제 #15
0
 public string ComputeFriendlyNameFromPath(string path, OvpnBuilder ovpn)
 {
     return path;
 }
예제 #16
0
        public override void OnBuildOvpnDefaults(OvpnBuilder ovpn)
        {
            base.OnBuildOvpnDefaults(ovpn);

            ovpn.AppendDirectives(Manifest.Attributes["openvpn_directives"].Value.Replace("\t", "").Trim(), "Provider level");
        }
예제 #17
0
        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();
            }
        }
예제 #18
0
 public override void OnBuildOvpn(OvpnBuilder ovpn)
 {
     base.OnBuildOvpn(ovpn);
 }