Beispiel #1
0
        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);
        }
Beispiel #2
0
        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();
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        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();
        }
Beispiel #5
0
        public virtual bool OnRouteDefaultRemoveRestore()
        {
            if (m_routeDefaultRemove != null)
            {
                m_routeDefaultRemove.Add();
                m_routeDefaultRemove = null;

                Recovery.Save();
            }

            return(true);
        }
Beispiel #6
0
        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();
        }
Beispiel #7
0
 public virtual void OnVpnDisconnected()
 {
     if (m_current != null)
     {
         try
         {
             m_current.OnVpnDisconnected();
             Recovery.Save();
         }
         catch (Exception e)
         {
             Engine.Instance.Logs.Log(e);
         }
     }
 }
Beispiel #8
0
 public void OnUpdateIps()
 {
     if (m_current != null)
     {
         try
         {
             m_current.OnUpdateIps();
             Recovery.Save();
         }
         catch (Exception e)
         {
             Engine.Instance.Logs.Log(e);
         }
     }
 }
Beispiel #9
0
        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);
        }