Esempio n. 1
0
        private void LoadDefinition(string xml)
        {
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.LoadXml(xml);

            string code = UtilsXml.XmlGetAttributeString(xmlDoc.DocumentElement, "code", "");

            Definitions[code] = xmlDoc;
        }
Esempio n. 2
0
 public void ReadXML(XmlElement node)
 {
     Title              = UtilsXml.XmlGetAttributeString(node, "title", "");
     Protocol           = UtilsXml.XmlGetAttributeString(node, "protocol", "").ToUpperInvariant();
     Port               = UtilsXml.XmlGetAttributeInt(node, "port", 0);
     EntryIndex         = UtilsXml.XmlGetAttributeInt(node, "entry_index", 0);
     Specs              = UtilsXml.XmlGetAttributeString(node, "specs", "");
     MinVersion         = UtilsXml.XmlGetAttributeString(node, "openvpn_minversion", "");
     Directives         = UtilsXml.XmlGetAttributeString(node, "openvpn_directives", "");
     SshPortDestination = UtilsXml.XmlGetAttributeInt(node, "ssh_destination", 0);
 }
Esempio n. 3
0
        public XmlElement GetDataAddProviders()
        {
            XmlElement xmlData = UtilsXml.XmlCreateElement("data");

            foreach (KeyValuePair <string, XmlDocument> providerDefinition in Definitions)
            {
                string code          = providerDefinition.Key;
                string providerClass = UtilsXml.XmlGetAttributeString(providerDefinition.Value.DocumentElement, "class", "");
                if (providerClass == "service")                 // Only one instance
                {
                    if (ExistsProvider(code))
                    {
                        continue;
                    }
                }

                xmlData.AppendChild(xmlData.OwnerDocument.ImportNode(providerDefinition.Value.DocumentElement, true));
            }

            return(xmlData);
        }
Esempio n. 4
0
        public Provider AddProvider(string providerCode, XmlElement xmlStorage)
        {
            if (Definitions.ContainsKey(providerCode) == false)
            {
                return(null);
            }

            XmlDocument xmlDefiniton = Definitions[providerCode];

            string providerClass = UtilsXml.XmlGetAttributeString(xmlDefiniton.DocumentElement, "class", "");

            Provider provider = null;

            if (providerClass == "service")
            {
                provider = new Providers.Service();
            }
            else if (providerClass == "openvpn")
            {
                provider = new Providers.OpenVPN();
            }
            else
            {
                return(null);
            }

            if (provider != null)
            {
                provider.Definition = xmlDefiniton.DocumentElement;

                provider.OnInit();

                provider.OnLoad(xmlStorage);

                m_providers.Add(provider);
            }

            return(provider);
        }
Esempio n. 5
0
        public static void Init()
        {
            if (Platform.IsWindows())
            {
                // < 2.9 - Old Windows Firewall original backup rules path
                string oldPathRulesBackupFirstTime = Engine.Instance.Storage.GetPathInData("winfirewallrulesorig.wfw");
                string newPathRulesBackupFirstTime = Environment.SystemDirectory + Platform.Instance.DirSep + "winfirewall_rules_original.airvpn";
                if (Platform.Instance.FileExists(oldPathRulesBackupFirstTime))
                {
                    if (Platform.Instance.FileExists(newPathRulesBackupFirstTime))
                    {
                        Platform.Instance.FileDelete(oldPathRulesBackupFirstTime);
                    }
                    else
                    {
                        Platform.Instance.FileMove(oldPathRulesBackupFirstTime, newPathRulesBackupFirstTime);
                    }
                }

                string oldPathRulesBackupSession = Engine.Instance.Storage.GetPathInData("winfirewallrules.wfw");
                string newPathRulesBackupSession = Environment.SystemDirectory + Platform.Instance.DirSep + "winfirewall_rules_backup.airvpn";
                if (Platform.Instance.FileExists(oldPathRulesBackupFirstTime))
                {
                    if (Platform.Instance.FileExists(newPathRulesBackupSession))
                    {
                        Platform.Instance.FileDelete(oldPathRulesBackupSession);
                    }
                    else
                    {
                        Platform.Instance.FileMove(oldPathRulesBackupSession, newPathRulesBackupSession);
                    }
                }
            }

            if (Platform.Instance.IsLinuxSystem())
            {
                // < 2.11 - Old file name
                if (Platform.Instance.FileExists("/etc/resolv.conf.airvpn"))
                {
                    Platform.Instance.FileDelete("/etc/resolv.conf.airvpn");
                }

                // A bug in old experimental 2.11 cause the set of immutable flag in rare cases.
                if (Platform.Instance.FileImmutableGet("/etc/resolv.conf"))
                {
                    Platform.Instance.FileImmutableSet("/etc/resolv.conf", false);
                }
            }

            // < 2.9 - New certificate for SSL connections
            if (Engine.Instance.IsLogged())
            {
                if (Engine.Instance.AirVPN != null)
                {
                    if (UtilsXml.XmlGetAttributeString(Engine.Instance.AirVPN.User, "ssl_crt", "") == "")
                    {
                        Engine.Instance.ReAuth();
                    }

                    if (UtilsXml.XmlGetAttributeString(Engine.Instance.AirVPN.User, "tls_crypt", "") == "")
                    {
                        Engine.Instance.ReAuth();
                    }
                }
            }
        }
Esempio n. 6
0
 // Used for directive auth-user-pass
 public virtual string GetPassword()
 {
     return(UtilsXml.XmlGetAttributeString(Storage.DocumentElement, "password", ""));
 }
Esempio n. 7
0
 // Used for directive auth-user-pass
 public virtual string GetUsername()
 {
     return(UtilsXml.XmlGetAttributeString(Storage.DocumentElement, "login", ""));
 }