예제 #1
0
        /// <summary>
        /// Check IP in stIPFilter structure set
        /// </summary>
        /// <param name="ipData">stIPFilter structure set</param>
        /// <param name="ipu">IP unsigned int, produced IpStringToUInt()</param>
        /// <returns>Boolean is found reverse true/false for Black or White list</returns>
        public static bool IpFilterCheck(this stIPFilter ipData, uint ipu = 0)
        {
            if (ipu == 0)
            {
                return(true);
            }
            if ((ipu == localHost) || (ipData == null))
            {
                return(false);
            }

            bool ret  = false;
            bool cond = ((ipData.IpFilterType == IpFilterType.WhiteList) ? false : true);

            if (ipData.IpRange.Count > 0)
            {
                ret = ipData.IpRange.IpFilterIpRange(
                    ipu,
                    cond
                    );
            }
            if (
                (((ret) && (!cond)) || ((!ret) && (cond))) &&
                (ipData.GeoDataASN.Count > 0)
                )
            {
                cond = ((ipData.GeoAsnFilterType == IpFilterType.WhiteList) ? false : true);
                /// prototype stGeo.GeoFilter.InGeoRange(
                ///     uint ip address,
                ///     List<int> list numer asn or contry,
                ///     int type (int)enum stACL.IpFilterType asn or contry,
                ///     bool isBlackList)
                ret = ipData.GeoAction(
                    ipu,
                    ipData.GeoDataASN,
                    (int)stACL.IpFilterType.GeoASN,
                    cond
                    );
            }
            if (
                (((ret) && (!cond)) || ((!ret) && (cond))) &&
                (ipData.GeoDataCounry.Count > 0)
                )
            {
                cond = ((ipData.GeoCountryFilterType == IpFilterType.WhiteList) ? false : true);
                ret  = ipData.GeoAction(
                    ipu,
                    ipData.GeoDataCounry,
                    (int)stACL.IpFilterType.GeoCountry,
                    cond
                    );
            }
            return(ret);
        }
예제 #2
0
        /// <summary>
        /// Check IP in stIPFilter structure set
        /// </summary>
        /// <param name="ipData">stIPFilter structure set</param>
        /// <param name="ips">IP string</param>
        /// <returns>Boolean is found reverse true/false for Black or White list</returns>
        public static bool IpFilterCheck(this stIPFilter ipData, string ips)
        {
            if ((string.IsNullOrWhiteSpace(ips)) || (ipData == null))
            {
                return(false);
            }

            uint ipu = 0;

            try
            {
                ipu = ips.IpStringToUInt();
                if (ipu == 0)
                {
                    return(false);
                }
            }
            catch (Exception)
            {
                return(false);
            }
            return(stACL.IpFilterCheck(ipData, ipu));
        }
예제 #3
0
        /// <summary>
        /// Check IP in stIPFilter structure set
        /// </summary>
        /// <param name="ipData">stIPFilter structure set</param>
        /// <param name="ipa">IP <see cref="System.Net.IPAddress"/></param>
        /// <returns>Boolean is found reverse true/false for Black or White list</returns>
        public static bool IpFilterCheck(this stIPFilter ipData, IPAddress ipa)
        {
            if ((ipa == null) || (ipData == null))
            {
                return(false);
            }

            uint ipu = 0;

            try
            {
                ipu = ipa.IpAddressToUInt();
                if (ipu == 0)
                {
                    return(false);
                }
            }
            catch (Exception)
            {
                return(false);
            }
            return(stACL.IpFilterCheck(ipData, ipu));
        }
예제 #4
0
        private static stIPFilter _IpFilterCreate(
            StringCollection strIPList,
            StringCollection strASNList,
            StringCollection strCountryList,
            bool isIpBlackList,
            bool isGeoAsnBlackList,
            bool isGeoCountryBlackList,
            Func <uint, List <int>, int, bool, bool> GeoAction,
            Func <string, int> GeoCountryFunc
            )
        {
            stIPFilter IpFilter = new stIPFilter();

            try
            {
                if ((strIPList != null) && (strIPList.Count > 0))
                {
                    foreach (string rip in strIPList)
                    {
                        if (string.IsNullOrWhiteSpace(rip))
                        {
                            continue;
                        }
                        stACL._IpFilterAddIpRange(IpFilter.IpRange, rip);
                    }
                    IpFilter.IpFilterType = ((isIpBlackList) ? stACL.IpFilterType.BlackList : stACL.IpFilterType.WhiteList);
                }
                if ((strASNList != null) && (strASNList.Count > 0))
                {
                    foreach (string num in strASNList)
                    {
                        string asn;
                        if (num.StartsWith("ASN"))
                        {
                            asn = num.Substring(3, (num.Length - 3));
                        }
                        else if (num.StartsWith("AS"))
                        {
                            asn = num.Substring(2, (num.Length - 2));
                        }
                        else
                        {
                            asn = num;
                        }
                        int n = 0;
                        if (Int32.TryParse(asn.Trim(), out n))
                        {
                            IpFilter.GeoDataASN.Add(n);
                        }
                    }
                    IpFilter.GeoAsnFilterType = ((isGeoAsnBlackList) ? stACL.IpFilterType.BlackList : stACL.IpFilterType.WhiteList);
                }
                if ((strCountryList != null) && (strCountryList.Count > 0))
                {
                    foreach (string num in strCountryList)
                    {
                        int    n       = 0;
                        string country = num.Trim();
                        if (Int32.TryParse(country, out n))
                        {
                            IpFilter.GeoDataCounry.Add(n);
                        }
                        else
                        {
                            if ((GeoCountryFunc != null) && (country.Length == 2))
                            {
                                if ((n = GeoCountryFunc(country)) != -1)
                                {
                                    IpFilter.GeoDataCounry.Add(n);
                                }
                            }
                        }
                    }
                    IpFilter.GeoCountryFilterType = ((isGeoCountryBlackList) ? stACL.IpFilterType.BlackList : stACL.IpFilterType.WhiteList);
                }
                if (GeoAction != null)
                {
                    IpFilter.GeoAction = GeoAction;
                }
            }
            catch (Exception e)
            {
                throw new ArgumentException(e.Message);
            }
            return(IpFilter);
        }
예제 #5
0
        private void _AddHandler(WebHandleTypes ht, Action <string, object, object> httpRequestHandler, stIPFilter ipFilter, string path, string dir)
        {
            this._Check();

            if (httpRequestHandler == null)
            {
                throw new ArgumentNullException(Properties.Resources.httpCallbackNull);
            }
            if (string.IsNullOrWhiteSpace(path))
            {
                path = httpRequestHandler.ToString();
            }

            path = ((!path.StartsWith("/")) ? "/" + path : path);
            path = ((!path.EndsWith("/")) ? path + "/" : path);

            stWebResourceLocator resLocator = new stWebResourceLocator()
            {
                IPFilter    = ((ipFilter == null) ? new stIPFilter() : ipFilter),
                ReqCallBack = httpRequestHandler,
                HandleTypes = ht
            };

            if (!this._ResourceLocator.ContainsKey(path))
            {
                this._ResourceLocator.Add(path, resLocator);
            }
            else
            {
                this._ResourceLocator[path] = resLocator;
            }
            if (!this._listener.Prefixes.Contains(path))
            {
                try
                {
                    this._listener.Prefixes.Add(
                        string.Format(
                            @"{0}{1}",
                            this._SrvUri,
                            path
                            )
                        );
                }
                catch (Exception e)
                {
                    throw new ArgumentException(
                              string.Format(
                                  Properties.Resources.httpListenerExceptionAddResource,
                                  e.Message
                                  )
                              );
                }
            }
            if (
                ((this._isConcat) || (this._isMinify)) &&
                (!string.IsNullOrWhiteSpace(dir))
                )
            {
                path = path.Substring(1, (path.Length - 2));
                path = Path.Combine(dir, path);

                if (Directory.Exists(path))
                {
                    stBootStrap minify = null;

                    try
                    {
                        minify = new stBootStrap(this._isConcat, this._isMinify, this._iLog);
                        if (this._WatchChange)
                        {
                            minify.Minify(path, this._AddContentChangeWatch);
                        }
                        else
                        {
                            minify.Minify(path, null);
                        }
                    }
                    catch (Exception e)
                    {
                        throw new ArgumentException(e.Message);
                    }
                    finally
                    {
                        if (minify != null)
                        {
                            minify.Dispose();
                        }
                    }
                }
            }
        }
예제 #6
0
 public void AddHandler(WebHandleTypes ht, Action <string, object, object> httpRequestHandler, string path = null, stIPFilter ipFilter = null, string dir = null)
 {
     this._AddHandler(ht, httpRequestHandler, ipFilter, path, dir);
 }