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); }
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)); }
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)); }