Exemplo n.º 1
0
        /// <summary>
        /// update an existing IP filter
        /// </summary>
        /// <param name="ipFilter">filter details</param>
        public void UpdateIPFilter(IPFilterInfo ipFilter)
        {
            Requires.NotNull("ipFilter", ipFilter);
            AssertValidIPFilter(ipFilter);

            DataProvider.Instance().UpdateIPFilter(ipFilter.IPFilterID, ipFilter.IPAddress, ipFilter.SubnetMask, ipFilter.RuleType, UserController.Instance.GetCurrentUserInfo().UserID);
        }
        /// <summary>
        /// add a new IP filter
        /// </summary>
        /// <param name="ipFilter">filter details</param>
        /// <returns>filter id</returns>
        public int AddIPFilter(IPFilterInfo ipFilter)
        {
            Requires.NotNull("ipFilter", ipFilter);
            int id = DataProvider.Instance().AddIPFilter(ipFilter.IPAddress, ipFilter.SubnetMask, ipFilter.RuleType, UserController.Instance.GetCurrentUserInfo().UserID);

            return(id);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Check if a new rule would block the existing IP address
        /// </summary>
        /// <param name="currentIP">current IP address</param>
        /// <param name="ipFilter">new propose rule</param>
        /// <returns>true if rule would not block current IP, false otherwise</returns>
        public bool IsAllowableDeny(string currentIP, IPFilterInfo ipFilter)
        {
            if (ipFilter.RuleType == (int)FilterType.Allow)
            {
                return(true);
            }

            if (NetworkUtils.IsIPInRange(currentIP, ipFilter.IPAddress, ipFilter.SubnetMask))
            {
                return(false);
            }
            return(true);
        }
Exemplo n.º 4
0
        private static void AssertValidIPFilter(IPFilterInfo ipFilter)
        {
            IPAddress parsed;

            if (IPAddress.TryParse(ipFilter.IPAddress, out parsed) == false)
            {
                throw new ArgumentException(Localization.GetExceptionMessage("IPAddressIncorrect", "IP address is not in correct format"));
            }

            bool isIPRange = string.IsNullOrEmpty(ipFilter.SubnetMask) == false;

            if (isIPRange && IPAddress.TryParse(ipFilter.SubnetMask, out parsed) == false)
            {
                throw new ArgumentException(Localization.GetExceptionMessage("SubnetMaskIncorrect", "Subnet mask is not in correct format"));
            }
        }
Exemplo n.º 5
0
 public void DeleteIPFilter(IPFilterInfo ipFilter)
 {
     Requires.PropertyNotNegative("ipFilter", "ipFilter.IPFilterID", ipFilter.IPFilterID);
     DataProvider.Instance().DeleteIPFilter(ipFilter.IPFilterID);
 }
Exemplo n.º 6
0
        protected void DeleteFilter(object sender, EventArgs e)
        {
            //Get the index of the row to delete
            var btnDel = ((LinkButton) (sender));
            int removedIpf = Convert.ToInt32(btnDel.CommandArgument);

            IList<IPFilterInfo> currentRules = IPFilterController.Instance.GetIPFilters();

            List<IPFilterInfo> currentWithDeleteRemoved = (from p in currentRules where p.IPFilterID != removedIpf select p).ToList();

            if (IPFilterController.Instance.CanIPStillAccess(Request.UserHostAddress, currentWithDeleteRemoved) == false)
            {
                Skin.AddModuleMessage(this, Localization.GetString("CannotDelete.Text", LocalResourceFile), ModuleMessage.ModuleMessageType.RedError);
            }
            else
            {
                var ipf = new IPFilterInfo();
                ipf.IPFilterID = removedIpf;
                IPFilterController.Instance.DeleteIPFilter(ipf);
                BindFilters();
            }
        }
Exemplo n.º 7
0
        private void OnSaveFilterClick(object sender, EventArgs e)
        {
            var ipf = new IPFilterInfo();
            ipf.IPAddress = txtFirstIP.Text;
            ipf.SubnetMask = txtSubnet.Text;
            ipf.RuleType = Convert.ToInt32(cboType.SelectedValue);

            if ((ipf.IPAddress == "127.0.0.1" || ipf.IPAddress == "localhost" || ipf.IPAddress == "::1" || ipf.IPAddress=="*" ) && ipf.RuleType == 2)
            {
                Skin.AddModuleMessage(this, Localization.GetString("CannotDeleteLocalhost.Text", LocalResourceFile), ModuleMessage.ModuleMessageType.RedError);
                return;
            }

            if (IPFilterController.Instance.IsAllowableDeny(Request.UserHostAddress, ipf) == false)
            {
                Skin.AddModuleMessage(this, Localization.GetString("CannotDeleteIPInUse.Text", LocalResourceFile), ModuleMessage.ModuleMessageType.RedError);
                return;
            }

            if (!String.IsNullOrEmpty(Request.QueryString["IPFilterID"]))
            {
                ipf.IPFilterID = Convert.ToInt32(Request.QueryString["IPFilterID"]);
                IPFilterController.Instance.UpdateIPFilter(ipf);
            }
            else
            {
                IPFilterController.Instance.AddIPFilter(ipf);
            }
            Response.Redirect(Globals.NavigateURL(TabId), true);
        }