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(); }
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 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)); } } }