public void Delete(string id) { SegmentId segId = new SegmentId(id); Site site = segId.SiteId == null ? null : SiteHelper.GetSite(segId.SiteId.Value); if (segId.SiteId != null && site == null) { Context.Response.StatusCode = (int)HttpStatusCode.NoContent; return; } HiddenSegment segment = HiddenSegmentsHelper.getSegments(site, segId.Path).Where(s => s.Segment.ToString().Equals(segId.Segment)).FirstOrDefault(); if (segment != null) { var section = RequestFilteringHelper.GetRequestFilteringSection(site, segId.Path, ManagementUnit.ResolveConfigScope()); HiddenSegmentsHelper.DeleteSegment(segment, section); ManagementUnit.Current.Commit(); } Context.Response.StatusCode = (int)HttpStatusCode.NoContent; return; }
public static List <QueryStringRule> GetQueryStrings(Site site, string path) { RequestFilteringSection requestFilteringSection = RequestFilteringHelper.GetRequestFilteringSection(site, path); // Consolidates the underlying allow query strings and deny query strings into a single collection List <QueryStringRule> queryStrings = new List <QueryStringRule>(); var allowedCollection = requestFilteringSection.AlwaysAllowedQueryStrings; if (allowedCollection != null) { allowedCollection.ToList().ForEach(allowed => queryStrings.Add(new QueryStringRule() { QueryString = allowed.QueryString, Allow = true })); } var deniedCollection = requestFilteringSection.DenyQueryStringSequences; if (deniedCollection != null) { deniedCollection.ToList().ForEach(allowed => queryStrings.Add(new QueryStringRule() { QueryString = allowed.Sequence, Allow = false })); } return(queryStrings); }
public void Delete(string id) { UrlId urlId = new UrlId(id); Site site = urlId.SiteId == null ? null : SiteHelper.GetSite(urlId.SiteId.Value); if (urlId.SiteId != null && site == null) { Context.Response.StatusCode = (int)HttpStatusCode.NoContent; return; } UrlRule url = UrlsHelper.GetUrls(site, urlId.Path).Where(u => u.Url.ToString().Equals(urlId.Url)).FirstOrDefault(); if (url != null) { var section = RequestFilteringHelper.GetRequestFilteringSection(site, urlId.Path, ManagementUnit.ResolveConfigScope()); UrlsHelper.DeleteUrl(url, section); ManagementUnit.Current.Commit(); } Context.Response.StatusCode = (int)HttpStatusCode.NoContent; return; }
public void Delete(string id) { QueryStringId queryStringId = new QueryStringId(id); Site site = queryStringId.SiteId == null ? null : SiteHelper.GetSite(queryStringId.SiteId.Value); if (queryStringId.SiteId != null && site == null) { Context.Response.StatusCode = (int)HttpStatusCode.NoContent; return; } QueryStringRule queryString = QueryStringsHelper.GetQueryStrings(site, queryStringId.Path).FirstOrDefault(r => r.QueryString.ToString().Equals(queryStringId.QueryString)); if (queryString != null) { var section = RequestFilteringHelper.GetRequestFilteringSection(site, queryStringId.Path, ManagementUnit.ResolveConfigScope()); QueryStringsHelper.DeleteQueryString(queryString, section); ManagementUnit.Current.Commit(); } Context.Response.StatusCode = (int)HttpStatusCode.NoContent; return; }
public void Delete(string id) { RuleId ruleId = new RuleId(id); Site site = ruleId.SiteId == null ? null : SiteHelper.GetSite(ruleId.SiteId.Value); Application app = ApplicationHelper.GetApplication(ruleId.Path, site); if (ruleId.SiteId != null && site == null) { Context.Response.StatusCode = (int)HttpStatusCode.NoContent; return; } Rule rule = RulesHelper.GetRules(site, ruleId.Path).Where(r => r.Name.ToString().Equals(ruleId.Name)).FirstOrDefault(); if (rule != null) { var section = RequestFilteringHelper.GetRequestFilteringSection(site, ruleId.Path, ManagementUnit.ResolveConfigScope()); RulesHelper.DeleteRule(rule, section); ManagementUnit.Current.Commit(); } Context.Response.StatusCode = (int)HttpStatusCode.NoContent; }
public static List <UrlRule> GetUrls(Site site, string path) { // Get request filtering section RequestFilteringSection requestFilteringSection = RequestFilteringHelper.GetRequestFilteringSection(site, path); // Consolidates the underlying allow query strings and deny query strings into a single collection List <UrlRule> urls = new List <UrlRule>(); var allowedCollection = requestFilteringSection.AlwaysAllowedUrls; if (allowedCollection != null) { allowedCollection.ToList().ForEach(u => urls.Add(new UrlRule() { Url = u.Url.TrimStart(new char[] { '/' }), Allow = true })); } var deniedCollection = requestFilteringSection.DenyUrlSequences; if (deniedCollection != null) { deniedCollection.ToList().ForEach(u => urls.Add(new UrlRule() { Url = u.Sequence, Allow = false })); } return(urls); }
public static List <HiddenSegment> getSegments(Site site, string path) { // Get request filtering section RequestFilteringSection requestFilteringSection = RequestFilteringHelper.GetRequestFilteringSection(site, path); var collection = requestFilteringSection.HiddenSegments; if (collection != null) { return(collection.ToList()); } return(new List <HiddenSegment>()); }
public static List <HeaderLimit> GetHeaderLimits(Site site, string path, string configPath = null) { // Get request filtering section RequestFilteringSection requestFilteringSection = RequestFilteringHelper.GetRequestFilteringSection(site, path, configPath); var collection = requestFilteringSection.RequestLimits.HeaderLimits; if (collection != null) { return(collection.ToList()); } return(new List <HeaderLimit>()); }
public static List <Extension> GetExtensions(Site site, string path, string configPath = null) { // Get request filtering section RequestFilteringSection requestFilteringSection = RequestFilteringHelper.GetRequestFilteringSection(site, path, configPath); var collection = requestFilteringSection.FileExtensions; if (collection != null) { return(collection.ToList()); } return(new List <Extension>()); }
public static List <VerbElement> GetVerbs(Site site, string path, string configPath = null) { // Get request filtering section RequestFilteringSection requestFilteringSection = RequestFilteringHelper.GetRequestFilteringSection(site, path, configPath); var collection = requestFilteringSection.Verbs; if (collection != null) { return(collection.ToList()); } return(new List <VerbElement>()); }
public object Post([FromBody] dynamic model) { Rule rule = null; Site site = null; RequestFilteringId reqId = null; if (model == null) { throw new ApiArgumentException("model"); } // Rule must be created for a specific request filtering section if (model.request_filtering == null) { throw new ApiArgumentException("request_filtering"); } if (!(model.request_filtering is JObject)) { throw new ApiArgumentException(String.Empty, "request_filtering"); } string reqUuid = DynamicHelper.Value(model.request_filtering.id); if (reqUuid == null) { throw new ApiArgumentException("request_filtering.id"); } // Get the feature id reqId = new RequestFilteringId(reqUuid); // Get site the rule is for if applicable site = reqId.SiteId == null ? null : SiteHelper.GetSite(reqId.SiteId.Value); string configPath = ManagementUnit.ResolveConfigScope(model); RequestFilteringSection section = RequestFilteringHelper.GetRequestFilteringSection(site, reqId.Path, configPath); // Create filtering rule rule = RulesHelper.CreateRule(model, section); // Add it RulesHelper.AddRule(rule, section); // Save ManagementUnit.Current.Commit(); // // Create response dynamic r = RulesHelper.ToJsonModel(rule, site, reqId.Path, null, true); return(Created(RulesHelper.GetLocation(r.id), r)); }
public object Post([FromBody] dynamic model) { Extension extension = null; Site site = null; RequestFilteringId reqId = null; if (model == null) { throw new ApiArgumentException("model"); } if (model.request_filtering == null) { throw new ApiArgumentException("request_filtering"); } if (!(model.request_filtering is JObject)) { throw new ApiArgumentException(String.Empty, "request_filtering"); } string reqUuid = DynamicHelper.Value(model.request_filtering.id); if (reqUuid == null) { throw new ApiArgumentException("request_filtering.id"); } // Get the feature id reqId = new RequestFilteringId(reqUuid); site = reqId.SiteId == null ? null : SiteHelper.GetSite(reqId.SiteId.Value); string configPath = ManagementUnit.ResolveConfigScope(model); RequestFilteringSection section = RequestFilteringHelper.GetRequestFilteringSection(site, reqId.Path, configPath); extension = ExtensionsHelper.CreateExtension(model, section); ExtensionsHelper.AddExtension(extension, section); ManagementUnit.Current.Commit(); // // Create response dynamic ext = ExtensionsHelper.ToJsonModel(extension, site, reqId.Path); return(Created(ExtensionsHelper.GetLocation(ext.id), ext)); }
public object Post([FromBody] dynamic model) { QueryStringRule queryString = null; Site site = null; RequestFilteringId reqId = null; if (model == null) { throw new ApiArgumentException("model"); } if (model.request_filtering == null) { throw new ApiArgumentException("request_filtering"); } if (!(model.request_filtering is JObject)) { throw new ApiArgumentException("request_filtering"); } string reqUuid = DynamicHelper.Value(model.request_filtering.id); if (reqUuid == null) { throw new ApiArgumentException("request_filtering.id"); } reqId = new RequestFilteringId(reqUuid); site = reqId.SiteId == null ? null : SiteHelper.GetSite(reqId.SiteId.Value); string configPath = ManagementUnit.ResolveConfigScope(model); RequestFilteringSection section = RequestFilteringHelper.GetRequestFilteringSection(site, reqId.Path, configPath); queryString = QueryStringsHelper.CreateQueryString(model); QueryStringsHelper.AddQueryString(queryString, section); ManagementUnit.Current.Commit(); // // Create response dynamic qs = QueryStringsHelper.ToJsonModel(queryString, site, reqId.Path); return(Created(QueryStringsHelper.GetLocation(qs.id), qs)); }
public object Post([FromBody] dynamic model) { HiddenSegment segment = null; Site site = null; RequestFilteringId reqId = null; if (model == null) { throw new ApiArgumentException("model"); } if (model.request_filtering == null) { throw new ApiArgumentException("request_filtering"); } if (!(model.request_filtering is JObject)) { throw new ApiArgumentException("request_filtering"); } string reqUuid = DynamicHelper.Value(model.request_filtering.id); if (reqUuid == null) { throw new ApiArgumentException("request_filtering.id"); } // Get the feature id reqId = new RequestFilteringId(reqUuid); site = reqId.SiteId == null ? null : SiteHelper.GetSite(reqId.SiteId.Value); string configPath = ManagementUnit.ResolveConfigScope(model); RequestFilteringSection section = RequestFilteringHelper.GetRequestFilteringSection(site, reqId.Path, configPath); segment = HiddenSegmentsHelper.CreateSegment(model, section); HiddenSegmentsHelper.AddSegment(segment, section); ManagementUnit.Current.Commit(); dynamic hidden_segment = HiddenSegmentsHelper.ToJsonModel(segment, site, reqId.Path); return(Created(HiddenSegmentsHelper.GetLocation(hidden_segment.id), hidden_segment)); }
public void Delete(string id) { RequestFilteringId reqId = new RequestFilteringId(id); Context.Response.StatusCode = (int)HttpStatusCode.NoContent; Site site = (reqId.SiteId != null) ? SiteHelper.GetSite(reqId.SiteId.Value) : null; if (site == null) { return; } var section = RequestFilteringHelper.GetRequestFilteringSection(site, reqId.Path, ManagementUnit.ResolveConfigScope()); section.RevertToParent(); ManagementUnit.Current.Commit(); }
public object Post([FromBody] dynamic model) { HeaderLimit headerLimit = null; Site site = null; RequestFilteringId reqId = null; if (model == null) { throw new ApiArgumentException("model"); } if (model.request_filtering == null) { throw new ApiArgumentException("request_filtering"); } if (!(model.request_filtering is JObject)) { throw new ApiArgumentException(String.Empty, "request_filtering"); } string reqUuid = DynamicHelper.Value(model.request_filtering.id); if (reqUuid == null) { throw new ApiArgumentException("request_filtering.id"); } reqId = new RequestFilteringId(reqUuid); site = reqId.SiteId == null ? null : SiteHelper.GetSite(reqId.SiteId.Value); string configPath = ManagementUnit.ResolveConfigScope(model); RequestFilteringSection section = RequestFilteringHelper.GetRequestFilteringSection(site, reqId.Path, configPath); headerLimit = HeaderLimitsHelper.CreateHeaderLimit(model, section); HeaderLimitsHelper.AddHeaderLimit(headerLimit, section); ManagementUnit.Current.Commit(); dynamic header_limit = HeaderLimitsHelper.ToJsonModel(headerLimit, site, reqId.Path); return(Created(HeaderLimitsHelper.GetLocation(header_limit.id), header_limit)); }
public async Task Delete(string id) { RequestFilteringId reqId = new RequestFilteringId(id); Context.Response.StatusCode = (int)HttpStatusCode.NoContent; Site site = (reqId.SiteId != null) ? SiteHelper.GetSite(reqId.SiteId.Value) : null; if (site != null) { var section = RequestFilteringHelper.GetRequestFilteringSection(site, reqId.Path, ManagementUnit.ResolveConfigScope()); section.RevertToParent(); ManagementUnit.Current.Commit(); } if (reqId.SiteId == null && RequestFilteringHelper.IsFeatureEnabled()) { await RequestFilteringHelper.SetFeatureEnabled(false); } }
public object Patch(string id, [FromBody] dynamic model) { RequestFilteringId reqId = new RequestFilteringId(id); Site site = reqId.SiteId == null ? null : SiteHelper.GetSite(reqId.SiteId.Value); if (reqId.SiteId != null && site == null) { Context.Response.StatusCode = (int)HttpStatusCode.NotFound; return(null); } // Check for config_scope string configPath = model == null ? null : ManagementUnit.ResolveConfigScope(model); RequestFilteringSection section = RequestFilteringHelper.GetRequestFilteringSection(site, reqId.Path, configPath); RequestFilteringHelper.UpdateFeatureSettings(model, section); ManagementUnit.Current.Commit(); return(RequestFilteringHelper.ToJsonModel(site, reqId.Path)); }
public void Delete(string id) { HeaderLimitId headerId = new HeaderLimitId(id); Site site = headerId.SiteId == null ? null : SiteHelper.GetSite(headerId.SiteId.Value); if (headerId.SiteId != null && site == null) { Context.Response.StatusCode = (int)HttpStatusCode.NoContent; return; } HeaderLimit headerLimit = HeaderLimitsHelper.GetHeaderLimits(site, headerId.Path).Where(h => h.Header.ToString().Equals(headerId.Header)).FirstOrDefault(); if (headerLimit != null) { var section = RequestFilteringHelper.GetRequestFilteringSection(site, headerId.Path, ManagementUnit.ResolveConfigScope()); HeaderLimitsHelper.DeleteHeaderLimit(headerLimit, section); ManagementUnit.Current.Commit(); } Context.Response.StatusCode = (int)HttpStatusCode.NoContent; }
public void Delete(string id) { ExtensionId extId = new ExtensionId(id); Site site = extId.SiteId == null ? null : SiteHelper.GetSite(extId.SiteId.Value); if (extId.SiteId != null && site == null) { Context.Response.StatusCode = (int)HttpStatusCode.NoContent; return; } Extension extension = ExtensionsHelper.GetExtensions(site, extId.Path).Where(e => e.FileExtension.ToString().Equals(extId.FileExtension)).FirstOrDefault(); if (extension != null) { var section = RequestFilteringHelper.GetRequestFilteringSection(site, extId.Path, ManagementUnit.ResolveConfigScope()); ExtensionsHelper.DeleteExtension(extension, section); ManagementUnit.Current.Commit(); } Context.Response.StatusCode = (int)HttpStatusCode.NoContent; }
public static void UpdateQueryString(QueryStringRule queryString, dynamic model, Site site, string path, string configPath = null) { if (queryString == null) { throw new ArgumentNullException("queryString"); } if (queryString.QueryString == null) { throw new ArgumentNullException("queryString.QueryString"); } if (model == null) { throw new ApiArgumentException("model"); } bool? allow = DynamicHelper.To <bool>(model.allow); string queryStringName = DynamicHelper.Value(model.query_string); // Empty change set if (string.IsNullOrEmpty(queryStringName) && allow == null) { return; } var section = RequestFilteringHelper.GetRequestFilteringSection(site, path, configPath); try { // Remove the old query string if (queryString.Allow) { // We have to retrieve the configuration element from the allow collection var allowCollection = section.AlwaysAllowedQueryStrings; var allowElement = allowCollection.First(s => s.QueryString.Equals(queryString.QueryString)); // Remove the query string from the allow collection allowCollection.Remove(allowElement); } else { var denyCollection = section.DenyQueryStringSequences; var denyElement = denyCollection.First(s => s.Sequence.Equals(queryString.QueryString)); denyCollection.Remove(denyElement); } } catch (FileLoadException e) { throw new LockedException(section.SectionPath, e); } catch (DirectoryNotFoundException e) { throw new ConfigScopeNotFoundException(e); } // Update the query string to its new state queryString.Allow = allow == null ? queryString.Allow : allow.Value; queryString.QueryString = string.IsNullOrEmpty(queryStringName) ? queryString.QueryString : queryStringName; try { // Add the updated query string back into its respective collection if (queryString.Allow) { // Insert the query string into the allow collection section.AlwaysAllowedQueryStrings.Add(queryString.QueryString); } else { // Insert the query string into the deny collection section.DenyQueryStringSequences.Add(queryString.QueryString); } } catch (FileLoadException e) { throw new LockedException(section.SectionPath, e); } catch (DirectoryNotFoundException e) { throw new ConfigScopeNotFoundException(e); } }
public static void UpdateUrl(UrlRule url, dynamic model, Site site, string path, string configPath = null) { if (url == null) { throw new ArgumentNullException("url"); } if (url.Url == null) { throw new ArgumentNullException("url.Url"); } if (model == null) { throw new ApiArgumentException("model"); } bool allow = DynamicHelper.To <bool>(model.allow) ?? url.Allow; string newUrl = DynamicHelper.Value(model.url); var section = RequestFilteringHelper.GetRequestFilteringSection(site, path, configPath); // Url is in as an allow url if (url.Allow) { AlwaysAllowedUrl targetUrl = section.AlwaysAllowedUrls.FirstOrDefault(u => u.Url.Equals(url.Url, StringComparison.OrdinalIgnoreCase)); if (targetUrl == null) { throw new NotFoundException("url"); } section.AlwaysAllowedUrls.Remove(targetUrl); } // Url is in the configuration as a deny url sequence else { DenyUrlSequence denySequence = section.DenyUrlSequences.FirstOrDefault(u => u.Sequence.Equals(url.Url, StringComparison.OrdinalIgnoreCase)); if (denySequence == null) { throw new NotFoundException("url"); } section.DenyUrlSequences.Remove(denySequence); } try { // The target url has been removed from either allow or deny collection. // Add updated url to proper collection if (allow) { var elem = section.AlwaysAllowedUrls.CreateElement(); elem.Url = newUrl ?? url.Url; section.AlwaysAllowedUrls.Add(elem); url.Allow = true; } else { var elem = section.DenyUrlSequences.CreateElement(); elem.Sequence = newUrl ?? url.Url; section.DenyUrlSequences.Add(elem); url.Allow = false; } url.Url = newUrl ?? url.Url; } catch (FileLoadException e) { throw new LockedException(section.SectionPath, e); } catch (DirectoryNotFoundException e) { throw new ConfigScopeNotFoundException(e); } }