public virtual void OnRecoveryLoad(XmlElement root) { XmlElement nodeRoutes = UtilsXml.XmlGetFirstElementByTagName(root, "routes"); if (nodeRoutes != null) { foreach (XmlElement nodeRoute in nodeRoutes.ChildNodes) { Json jRoute = new Json(); UtilsXml.XmlToJson(nodeRoute, jRoute); // m_routes.Add(jRoute); // Removed in 2.17.1 if (jRoute["type"].Value as string == "added") { RouteRemove(jRoute); } else if (jRoute["type"].Value as string == "removed") { RouteAdd(jRoute); } } } OnRouteDefaultRemoveRestore(); OnDnsSwitchRestore(); OnInterfaceRestore(); OnIPv6Restore(); }
private void LoadDefinition(string xml) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xml); string code = UtilsXml.XmlGetAttributeString(xmlDoc.DocumentElement, "code", ""); Definitions[code] = xmlDoc; }
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); }
public virtual void OnRecoverySave(XmlElement root) { XmlDocument doc = root.OwnerDocument; if (m_routes.Count > 0) { XmlElement nodeRoutes = (XmlElement)root.AppendChild(doc.CreateElement("routes")); foreach (Json jRoute in m_routes) { XmlElement nodeRoute = doc.CreateElement("route") as XmlElement; nodeRoutes.AppendChild(nodeRoute); UtilsXml.JsonToXml(jRoute, nodeRoute); } } }
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); }
public void OnRecoveryLoad(XmlElement root) { try { if (m_current != null) { throw new Exception(Messages.NetworkLockRecoveryWhenActive); } XmlElement node = UtilsXml.XmlGetFirstElementByTagName(root, "netlock"); if (node != null) { string code = node.GetAttribute("mode"); foreach (NetworkLockPlugin lockPlugin in Engine.Instance.NetworkLockManager.Modes) { if (lockPlugin.GetCode() == code) { m_current = lockPlugin; break; } } if (m_current != null) { m_current.OnRecoveryLoad(node); } else { Engine.Instance.Logs.Log(LogType.Warning, Messages.NetworkLockRecoveryUnknownMode); } Deactivation(false); } } catch (Exception e) { Engine.Instance.Logs.Log(e); } }
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); }
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(); } } } }
// Used for directive auth-user-pass public virtual string GetPassword() { return(UtilsXml.XmlGetAttributeString(Storage.DocumentElement, "password", "")); }
// Used for directive auth-user-pass public virtual string GetUsername() { return(UtilsXml.XmlGetAttributeString(Storage.DocumentElement, "login", "")); }
public virtual void ClearCredentials() { m_runCredentials = null; UtilsXml.XmlSetAttributeString(Storage.DocumentElement, "login", ""); UtilsXml.XmlSetAttributeString(Storage.DocumentElement, "password", ""); }
public void Load() { lock (this) { try { XmlDocument xmlDoc = new XmlDocument(); Providers = xmlDoc.CreateElement("providers"); if (Get("profile").ToLowerInvariant() == "none") { return; } string path = GetProfilePath(); CompatibilityManager.FixOldProfilePath(path); // 2.15 Engine.Instance.Logs.Log(LogType.Verbose, MessagesFormatter.Format(Messages.OptionsRead, path)); if (Platform.Instance.FileExists(path) == false) { Engine.Instance.Logs.Log(LogType.Verbose, Messages.OptionsNotFound); return; } // CompatibilityManager.FixOldProfile(path); // ClodoTemp xmlDoc.Load(path); ResetAll(true); Providers = UtilsXml.XmlGetFirstElementByTagName(xmlDoc.DocumentElement, "providers"); if (Providers == null) { Providers = xmlDoc.CreateElement("providers"); } XmlNode nodeOptions = xmlDoc.DocumentElement.GetElementsByTagName("options")[0]; Dictionary <string, string> options = new Dictionary <string, string>(); foreach (XmlElement e in nodeOptions) { string name = e.Attributes["name"].Value; string value = e.Attributes["value"].Value; CompatibilityManager.FixOption(ref name, ref value); options[name] = value; } CompatibilityManager.FixOptions(options); foreach (KeyValuePair <string, string> item in options) { Set(item.Key, item.Value); } // For compatibility <3 XmlElement xmlManifest = UtilsXml.XmlGetFirstElementByTagName(xmlDoc.DocumentElement, "manifest"); if (xmlManifest != null) { XmlElement providerAirVpn = xmlDoc.CreateElement("AirVPN"); Providers.AppendChild(providerAirVpn); UtilsXml.XmlCopyElement(xmlManifest, providerAirVpn); XmlElement xmlUser = UtilsXml.XmlGetFirstElementByTagName(xmlDoc.DocumentElement, "user"); if (xmlUser != null) // Compatibility with old manifest < 2.11 { XmlElement oldKeyFormat = xmlUser.SelectSingleNode("keys/key[@id='default']") as XmlElement; if (oldKeyFormat != null) { oldKeyFormat.SetAttribute("name", "Default"); } } if (xmlUser != null) { UtilsXml.XmlCopyElement(xmlUser, providerAirVpn); } } } catch (Exception ex) { Engine.Instance.Logs.Log(LogType.Fatal, MessagesFormatter.Format(Messages.OptionsReverted, ex.Message)); ResetAll(true); } } }
public void Save() { string path = GetProfilePath(); bool remember = GetBool("remember"); lock (this) { try { XmlDocument xmlDoc = new XmlDocument(); XmlDeclaration xmlDeclaration = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null); XmlElement rootNode = xmlDoc.CreateElement("eddie"); xmlDoc.InsertBefore(xmlDeclaration, xmlDoc.DocumentElement); XmlElement optionsNode = xmlDoc.CreateElement("options"); rootNode.AppendChild(optionsNode); xmlDoc.AppendChild(rootNode); foreach (Option option in Options.Values) { bool skip = false; if ((remember == false) && (option.Code == "login")) { skip = true; } if ((remember == false) && (option.Code == "password")) { skip = true; } if (option.CommandLineOnly) { skip = true; } if ((option.Value == "") || (option.Value == option.Default)) { skip = true; } if (skip == false) { XmlElement itemNode = xmlDoc.CreateElement("option"); itemNode.SetAttribute("name", option.Code); itemNode.SetAttribute("value", option.Value); optionsNode.AppendChild(itemNode); } } XmlElement providersNode = xmlDoc.CreateElement("providers"); rootNode.AppendChild(providersNode); foreach (Provider provider in Engine.Instance.ProvidersManager.Providers) { XmlNode providerNode = xmlDoc.ImportNode(provider.Storage.DocumentElement, true); providersNode.AppendChild(providerNode); } if (Engine.Instance.ProvidersManager.Providers.Count == 1) { if (Engine.Instance.ProvidersManager.Providers[0].Code == "AirVPN") { // Move providers->AirVPN to root. XmlElement xmlAirVPN = UtilsXml.XmlGetFirstElementByTagName(providersNode, "AirVPN"); if (xmlAirVPN != null) { foreach (XmlElement xmlChild in xmlAirVPN.ChildNodes) { UtilsXml.XmlCopyElement(xmlChild, xmlDoc.DocumentElement); } providersNode.RemoveChild(xmlAirVPN); } if (providersNode.ChildNodes.Count == 0) { providersNode.ParentNode.RemoveChild(providersNode); } } } xmlDoc.Save(path); Platform.Instance.FileEnsurePermission(path, "600"); } catch (Exception ex) { Engine.Instance.Logs.Log(LogType.Fatal, MessagesFormatter.Format(Messages.OptionsWriteFailed, path, ex.Message)); } } }