예제 #1
0
 public void ReadXML(XmlElement node)
 {
     Title      = Utils.XmlGetAttributeString(node, "title", "");
     Protocol   = Utils.XmlGetAttributeString(node, "protocol", "").ToUpperInvariant();
     Port       = Utils.XmlGetAttributeInt(node, "port", 0);
     EntryIndex = Utils.XmlGetAttributeInt(node, "entry_index", 0);
     Specs      = Utils.XmlGetAttributeString(node, "specs", "");
     MinVersion = Utils.XmlGetAttributeString(node, "openvpn_minversion", "");
     Directives = Utils.XmlGetAttributeString(node, "openvpn_directives", "");
 }
예제 #2
0
        private void LoadDefinition(string xml)
        {
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.LoadXml(xml);

            string title = Utils.XmlGetAttributeString(xmlDoc.DocumentElement, "title", "");

            Definitions[title] = xmlDoc;
        }
예제 #3
0
        public static void Init()
        {
            if (Platform.IsWindows())
            {
                // < 2.9 - Old Windows Firewall original backup rules path
                string oldPathRulesBackupFirstTime = Storage.DataPath + Platform.Instance.DirSep + "winfirewallrulesorig.wfw";
                string newPathRulesBackupFirstTime = Environment.SystemDirectory + Platform.Instance.DirSep + "winfirewall_rules_original.airvpn";
                if (File.Exists(oldPathRulesBackupFirstTime))
                {
                    if (File.Exists(newPathRulesBackupFirstTime))
                    {
                        File.Delete(oldPathRulesBackupFirstTime);
                    }
                    else
                    {
                        File.Move(oldPathRulesBackupFirstTime, newPathRulesBackupFirstTime);
                    }
                }

                string oldPathRulesBackupSession = Storage.DataPath + Platform.Instance.DirSep + "winfirewallrules.wfw";
                string newPathRulesBackupSession = Environment.SystemDirectory + Platform.Instance.DirSep + "winfirewall_rules_backup.airvpn";
                if (File.Exists(oldPathRulesBackupFirstTime))
                {
                    if (File.Exists(newPathRulesBackupSession))
                    {
                        File.Delete(oldPathRulesBackupSession);
                    }
                    else
                    {
                        File.Move(oldPathRulesBackupSession, newPathRulesBackupSession);
                    }
                }
            }

            // < 2.9 - New certificate for SSL connections
            if (Engine.Instance.IsLogged())
            {
                if (Engine.Instance.AirVPN != null)
                {
                    if (Utils.XmlGetAttributeString(Engine.Instance.AirVPN.User, "ssl_crt", "") == "")
                    {
                        Engine.Instance.ReAuth();
                    }
                }
            }
        }
예제 #4
0
        public Provider AddProvider(string providerCode, XmlElement xmlStorage)
        {
            if (Definitions.ContainsKey(providerCode) == false)
            {
                return(null);
            }

            XmlDocument xmlDefiniton = Definitions[providerCode];

            string providerClass = Utils.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);

                if (provider.GetCode() == "AirVPN")
                {
                    Engine.Instance.AirVPN = provider as Providers.Service;
                }
            }

            return(provider);
        }
예제 #5
0
        public XmlElement GetDataAddProviders()
        {
            XmlElement xmlData = Utils.XmlCreateElement("data");

            foreach (KeyValuePair <string, XmlDocument> providerDefinition in Definitions)
            {
                string code          = providerDefinition.Key;
                string providerClass = Utils.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);
        }
예제 #6
0
 // Used for directive auth-user-pass
 public virtual string GetPassword()
 {
     return(Utils.XmlGetAttributeString(Storage.DocumentElement, "password", ""));
 }
예제 #7
0
 // Used for directive auth-user-pass
 public virtual string GetLogin()
 {
     return(Utils.XmlGetAttributeString(Storage.DocumentElement, "login", ""));
 }
예제 #8
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 (Utils.XmlGetAttributeString(Engine.Instance.AirVPN.User, "ssl_crt", "") == "")
                    {
                        Engine.Instance.ReAuth();
                    }
                }
            }
        }