Ejemplo n.º 1
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            IpAddressRange two = obj as IpAddressRange;

            if (two == null)
            {
                return(false);
            }

            return(Value == two.Value);
        }
Ejemplo n.º 2
0
        public void AddToIpsList(List <IpAddressRange> result, IpAddressRange ip, bool warning)
        {
            if (ip.Valid == false)
            {
                if (warning == true)
                {
                    Engine.Instance.Log(Engine.LogType.Error, Messages.Format(Messages.NetworkLockAllowedIpInvalid, ip.ToString()));
                }
                return;
            }

            if (result.Contains(ip))
            {
                if (warning == true)
                {
                    Engine.Instance.Log(Engine.LogType.Warning, Messages.Format(Messages.NetworkLockAllowedIpDuplicated, ip.ToString()));
                }
                return;
            }

            result.Add(ip);
        }
Ejemplo n.º 3
0
        public List <IpAddressRange> GetAllIps()
        {
            List <IpAddressRange> result = new List <IpAddressRange>();

            // Custom
            {
                string        list = Engine.Instance.Storage.Get("netlock.allowed_ips");
                List <string> ips  = Utils.CommaStringToListString(list);
                foreach (string ip in ips)
                {
                    string ip2 = ip.Trim();

                    int posComment = ip2.IndexOf("#");
                    if (posComment != -1)
                    {
                        ip2 = ip2.Substring(0, posComment).Trim();
                    }

                    if (ip2 == "")
                    {
                        continue;
                    }

                    AddToIpsList(result, new IpAddressRange(ip2), true);
                }
            }

            // Routes Out
            {
                string   routes  = Engine.Instance.Storage.Get("routes.custom");
                string[] routes2 = routes.Split(';');
                foreach (string route in routes2)
                {
                    string[] routeEntries = route.Split(',');
                    if (routeEntries.Length < 2)
                    {
                        continue;
                    }

                    string ip     = routeEntries[0];
                    string action = routeEntries[1];

                    if (action == "out")
                    {
                        AddToIpsList(result, new IpAddressRange(ip), true);
                    }
                }
            }

            // Hosts
            if (Engine.Instance.Storage.Manifest != null)
            {
                XmlNodeList nodesHosts = Engine.Instance.Storage.Manifest.SelectNodes("//hosts/host");
                foreach (XmlNode nodeHost in nodesHosts)
                {
                    IpAddressRange ip = new IpAddressRange(nodeHost.Attributes["address"].Value);
                    AddToIpsList(result, ip, false);
                }
            }

            // Servers
            lock (Engine.Instance.Servers)
            {
                Dictionary <string, ServerInfo> servers = new Dictionary <string, ServerInfo>(Engine.Instance.Servers);

                foreach (ServerInfo infoServer in servers.Values)
                {
                    AddToIpsList(result, infoServer.IpEntry, false);
                    if (infoServer.IpEntry2.Trim() != "")
                    {
                        AddToIpsList(result, infoServer.IpEntry2, false);
                    }
                }
            }

            return(result);
        }