public async Task Delete(string id)
        {
            IPRestrictionId ipId = new IPRestrictionId(id);

            Context.Response.StatusCode = (int)HttpStatusCode.NoContent;

            Site site = (ipId.SiteId != null) ? SiteHelper.GetSite(ipId.SiteId.Value) : null;

            if (site != null)
            {
                IPRestrictionsHelper.GetSection(site, ipId.Path, ManagementUnit.ResolveConfigScope()).RevertToParent();

                if (ManagementUnit.ServerManager.GetApplicationHostConfiguration().HasSection(IPRestrictionsGlobals.DynamicIPSecuritySectionName))
                {
                    IPRestrictionsHelper.GetDynamicSecuritySection(site, ipId.Path, ManagementUnit.ResolveConfigScope()).RevertToParent();
                }

                ManagementUnit.Current.Commit();
            }

            if (ipId.SiteId == null && IPRestrictionsHelper.IsFeatureEnabled())
            {
                await IPRestrictionsHelper.SetFeatureEnabled(false);
            }
        }
Ejemplo n.º 2
0
        public void Delete(string id)
        {
            RuleId ruleId = new RuleId(id);

            Site site = ruleId.SiteId == null ? null : SiteHelper.GetSite(ruleId.SiteId.Value);

            if (ruleId.SiteId != null && site == null)
            {
                // The rule id specified a site but we couldn't find it, therefore we can't get the rule
                Context.Response.StatusCode = (int)HttpStatusCode.NoContent;
                return;
            }

            Rule rule = IPRestrictionsHelper.GetRules(site, ruleId.Path).Where(r => r.IpAddress.ToString().Equals(ruleId.IpAddress)).FirstOrDefault();

            if (rule != null)
            {
                var section = IPRestrictionsHelper.GetSection(site, ruleId.Path, ManagementUnit.ResolveConfigScope());

                IPRestrictionsHelper.DeleteRule(rule, section);

                ManagementUnit.Current.Commit();
            }

            Context.Response.StatusCode = (int)HttpStatusCode.NoContent;
        }
Ejemplo n.º 3
0
        public object Patch(string id, [FromBody] dynamic model)
        {
            RuleId ruleId = new RuleId(id);

            Site site = ruleId.SiteId == null ? null : SiteHelper.GetSite(ruleId.SiteId.Value);

            if (ruleId.SiteId != null && site == null)
            {
                // The rule id specified a site but we couldn't find it, therefore we can't get the rule
                return(NotFound());
            }

            string configPath = model == null ? null : ManagementUnit.ResolveConfigScope(model);
            var    section    = IPRestrictionsHelper.GetSection(site, ruleId.Path, configPath);
            Rule   rule       = section.IpAddressFilters.Where(r => r.IpAddress.ToString().Equals(ruleId.IpAddress)).FirstOrDefault();

            if (rule == null)
            {
                return(NotFound());
            }

            rule = IPRestrictionsHelper.SetRule(rule, model, section);

            ManagementUnit.Current.Commit();

            dynamic rle = IPRestrictionsHelper.RuleToJsonModel(rule, site, ruleId.Path);

            if (rle.id != id)
            {
                return(LocationChanged(IPRestrictionsHelper.GetRuleLocation(rle.id), rle));
            }

            return(rle);
        }
Ejemplo n.º 4
0
        public object Post([FromBody] dynamic model)
        {
            if (model == null)
            {
                throw new ApiArgumentException("model");
            }

            // Rule must be created for a specific ip restriction section
            if (model.ip_restriction == null)
            {
                throw new ApiArgumentException("ip_restriction");
            }
            if (!(model.ip_restriction is JObject))
            {
                throw new ApiArgumentException("ip_restriction");
            }
            string ipUuid = DynamicHelper.Value(model.ip_restriction.id);

            if (ipUuid == null)
            {
                throw new ApiArgumentException("ip_restriction.id");
            }

            // Get the ip restriction feature id
            IPRestrictionId ipId = new IPRestrictionId(ipUuid);

            // Get site
            Site site = ipId.SiteId == null ? null : SiteHelper.GetSite(ipId.SiteId.Value);

            string            configPath = ManagementUnit.ResolveConfigScope(model);
            IPSecuritySection section    = IPRestrictionsHelper.GetSection(site, ipId.Path, configPath);

            // Create ip restriction rule
            Rule rule = IPRestrictionsHelper.CreateRule(model, section);

            // Add it
            IPRestrictionsHelper.AddRule(rule, section);

            // Save
            ManagementUnit.Current.Commit();

            //
            // Create response
            dynamic r = IPRestrictionsHelper.RuleToJsonModel(rule, site, ipId.Path);

            return(Created(IPRestrictionsHelper.GetRuleLocation(r.id), r));
        }