public virtual bool RouteRemove(Json jRoute) { lock (m_routes) { bool known = false; for (int i = 0; i < m_routes.Count; i++) { Json jRouteC = m_routes[i] as Json; if ((jRouteC["address"].Value as string == jRoute["address"].Value as string) && (jRouteC["gateway"].Value as string == jRoute["gateway"].Value as string) && (jRouteC["type"].Value as string == "added")) { Engine.Instance.Logs.LogVerbose(LanguageManager.GetText("RouteDelAdded", new IpAddress(jRoute["address"].Value as string).ToCIDR(), new IpAddress(jRoute["gateway"].Value as string).ToCIDR())); m_routes.RemoveAt(i); known = true; break; } } if (known == false) { Engine.Instance.Logs.LogVerbose(LanguageManager.GetText("RouteDelExist", new IpAddress(jRoute["address"].Value as string).ToCIDR(), new IpAddress(jRoute["gateway"].Value as string).ToCIDR())); jRoute["type"].Value = "removed"; m_routes.Add(jRoute); } } Recovery.Save(); return(true); }
public void Deactivation(bool onExit) { if (m_current != null) { if (onExit == false) { Engine.Instance.WaitMessageSet(LanguageManager.GetText("NetworkLockDeactivation"), false); Engine.Instance.Logs.Log(LogType.InfoImportant, LanguageManager.GetText("NetworkLockDeactivation")); } else { Engine.Instance.Logs.Log(LogType.Verbose, LanguageManager.GetText("NetworkLockDeactivation")); } try { m_current.Deactivation(); } catch (Exception e) { Engine.Instance.Logs.Log(e); } m_current = null; } Recovery.Save(); }
public virtual bool RouteAdd(Json jRoute) { lock (m_routes) { bool known = false; for (int i = 0; i < m_routes.Count; i++) { Json jRouteC = m_routes[i]; if ((jRouteC["address"].Value as string == jRoute["address"].Value as string) && (jRouteC["gateway"].Value as string == jRoute["gateway"].Value as string) && (jRouteC["type"].Value as string == "removed")) { Engine.Instance.Logs.LogVerbose(MessagesFormatter.Format(Messages.RouteAddRemoved, new IpAddress(jRoute["address"].Value as string).ToCIDR(), new IpAddress(jRoute["gateway"].Value as string).ToCIDR())); m_routes.RemoveAt(i); known = true; break; } } if (known == false) { Engine.Instance.Logs.LogVerbose(MessagesFormatter.Format(Messages.RouteAddNew, new IpAddress(jRoute["address"].Value as string).ToCIDR(), new IpAddress(jRoute["gateway"].Value as string).ToCIDR())); jRoute["type"].Value = "added"; m_routes.Add(jRoute); } } Recovery.Save(); return(true); }
public void Activation() { try { if (m_current != null) { throw new Exception(LanguageManager.GetText("NetworkLockUnexpectedAlreadyActive")); } NetworkLockPlugin nextCurrent = null; string requestedMode = Engine.Instance.Storage.GetLower("netlock.mode"); if (requestedMode == "auto") { requestedMode = Platform.Instance.OnNetworkLockRecommendedMode(); } if (requestedMode != "none") { foreach (NetworkLockPlugin plugin in Modes) { if (plugin.GetSupport()) { if (requestedMode == plugin.GetCode()) { nextCurrent = plugin; break; } } } } if (nextCurrent == null) { Engine.Instance.Logs.Log(LogType.Fatal, LanguageManager.GetText("NetworkLockNoMode")); } else { string message = LanguageManager.GetText("NetworkLockActivation") + " - " + nextCurrent.GetName(); Engine.Instance.WaitMessageSet(message, false); Engine.Instance.Logs.Log(LogType.InfoImportant, message); // This is not useless: resolve hostnames (available later as cache) before a possible lock of DNS server. nextCurrent.GetIpsWhiteListOutgoing(true); nextCurrent.Activation(); m_current = nextCurrent; } } catch (Exception e) { Engine.Instance.Logs.Log(LogType.Fatal, e); } Recovery.Save(); }
public virtual bool OnRouteDefaultRemoveRestore() { if (m_routeDefaultRemove != null) { m_routeDefaultRemove.Add(); m_routeDefaultRemove = null; Recovery.Save(); } return(true); }
public void Activation() { try { if (m_current != null) { throw new Exception(Messages.NetworkLockUnexpectedAlreadyActive); } NetworkLockPlugin nextCurrent = null; string requestedMode = Engine.Instance.Storage.GetLower("netlock.mode"); if (requestedMode == "auto") { requestedMode = Platform.Instance.OnNetworkLockRecommendedMode(); } if (requestedMode != "none") { foreach (NetworkLockPlugin plugin in Modes) { if (requestedMode == plugin.GetCode()) { nextCurrent = plugin; break; } } } if (nextCurrent == null) { Engine.Instance.Logs.Log(LogType.Fatal, Messages.NetworkLockNoMode); } else { string message = Messages.NetworkLockActivation + " - " + nextCurrent.GetName(); Engine.Instance.WaitMessageSet(message, false); Engine.Instance.Logs.Log(LogType.InfoImportant, message); nextCurrent.Activation(); m_current = nextCurrent; } } catch (Exception e) { Engine.Instance.Logs.Log(LogType.Fatal, e); } Recovery.Save(); }
public virtual void OnVpnDisconnected() { if (m_current != null) { try { m_current.OnVpnDisconnected(); Recovery.Save(); } catch (Exception e) { Engine.Instance.Logs.Log(e); } } }
public void OnUpdateIps() { if (m_current != null) { try { m_current.OnUpdateIps(); Recovery.Save(); } catch (Exception e) { Engine.Instance.Logs.Log(e); } } }
public virtual bool OnRouteDefaultRemoveDo() { List <RouteEntry> routeEntries = RouteList(); foreach (RouteEntry routeEntry in routeEntries) { if (routeEntry.Mask.ToString() == "0.0.0.0") { m_routeDefaultRemove = routeEntry; routeEntry.Remove(); Recovery.Save(); } } return(true); }