Esempio n. 1
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;
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
        public object Get(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
                return(NotFound());
            }

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

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

            return(IPRestrictionsHelper.RuleToJsonModel(rule, site, ruleId.Path));
        }