public object Create(object parent, object configContext, System.Xml.XmlNode section) { IDSGlobalSettings settings = new IDSGlobalSettings(); IDSBaseSettings ibs = (IDSBaseSettings)settings; //Load base IDS settings LoadBaseSettings(ref ibs, section); //Get page exclusions XmlNodeList xnl = section.SelectNodes("excludepage"); foreach (XmlNode n in xnl) { string pagetoexclude = GetAttribute(n, "page", true); settings.ExcludedPages.Add(pagetoexclude); } //Get regex exclusions xnl = section.SelectNodes("excluderegex"); foreach (XmlNode n in xnl) { string pattern = GetAttribute(n, "pattern", true); bool ignorecase = bool.Parse(GetAttribute(n, "ignorecase", true)); settings.ExcludedRegexen.Add(new RegexSettings(pattern, ignorecase)); } //Get the global callbacks xnl = section.SelectNodes("callback"); foreach (XmlNode n in xnl) { string method = GetAttribute(n, "method", true); string namespaceandtype = GetAttribute(n, "namespaceandtype", true); string assembly = GetAttribute(n, "assembly", true); settings.Callbacks.Add(new IDSCallback(method, namespaceandtype, assembly)); } //Get page settings xnl = section.SelectNodes("pagesetup"); foreach (XmlNode n in xnl) { string pagename = GetAttribute(n, "page", true); //Create a page settings object IDSPageSettings ips = new IDSPageSettings(settings); try { settings.PageSettings.Add(pagename, ips); } catch (Exception e) { throw new ApplicationException("Only one config section can exist for the page named \"" + pagename + "\"", e); } //Populate base data IDSBaseSettings pagebase = (IDSBaseSettings)ips; LoadBaseSettings(ref pagebase, n); //Look for page callbacks XmlNodeList pagecallbacks = n.SelectNodes("callback"); foreach (XmlNode pagecallback in pagecallbacks) { string method = GetAttribute(pagecallback, "method", true); string namespaceandtype = GetAttribute(pagecallback, "namespaceandtype", true); string assembly = GetAttribute(pagecallback, "assembly", true); ips.Callbacks.Add(new IDSCallback(method, namespaceandtype, assembly)); } } return(settings); }
private void LoadBaseSettings(ref IDSBaseSettings settings, XmlNode xn) { //Cookie exclusions XmlNodeList configoption = xn.SelectNodes("cookieexclusion"); foreach (XmlNode cookieexclusion in configoption) { settings.CookieExclusions.Add(GetAttribute(cookieexclusion, "name", true)); } //DecodeJS configoption = xn.SelectNodes("decodejs"); if (configoption.Count > 0) { bool decodejs = true; if (!bool.TryParse(GetAttribute(configoption[0], "value", true), out decodejs)) { throw new ApplicationException("The value parameter of \"decodejs\" must be either \"true\" or \"false\"."); } settings.DecodeJS = decodejs; } //DecodeUTF7 configoption = xn.SelectNodes("decodeutf7"); if (configoption.Count > 0) { bool decodeutf7 = true; if (!bool.TryParse(GetAttribute(configoption[0], "value", true), out decodeutf7)) { throw new ApplicationException("The value parameter of \"decodeutf7\" must be either \"true\" or \"false\"."); } settings.DecodeUTF7 = decodeutf7; } //Exclusions configoption = xn.SelectNodes("exclusion"); foreach (XmlNode exclusion in configoption) { settings.Exclusions.Add(GetAttribute(exclusion, "name", true)); } //Get Exclusions configoption = xn.SelectNodes("getexclusion"); foreach (XmlNode getexclusion in configoption) { settings.GetExclusions.Add(GetAttribute(getexclusion, "name", true)); } //Header Exclusions configoption = xn.SelectNodes("headerexclusion"); foreach (XmlNode headerexclusion in configoption) { settings.HeaderExclusions.Add(GetAttribute(headerexclusion, "name", true)); } //Header Exclusions configoption = xn.SelectNodes("postexclusion"); foreach (XmlNode postexclusion in configoption) { settings.PostExclusions.Add(GetAttribute(postexclusion, "name", true)); } //Scan cookies configoption = xn.SelectNodes("scancookies"); if (configoption.Count > 0) { bool scancookies = true; if (!bool.TryParse(GetAttribute(configoption[0], "value", true), out scancookies)) { throw new ApplicationException("The value parameter of \"scancookies\" must be either \"true\" or \"false\"."); } settings.ScanCookies = scancookies; } //Scan get configoption = xn.SelectNodes("scanget"); if (configoption.Count > 0) { bool scanget = true; if (!bool.TryParse(GetAttribute(configoption[0], "value", true), out scanget)) { throw new ApplicationException("The value parameter of \"scanget\" must be either \"true\" or \"false\"."); } settings.ScanGet = scanget; } //Scan headers configoption = xn.SelectNodes("scanheaders"); if (configoption.Count > 0) { bool scanheaders = true; if (!bool.TryParse(GetAttribute(configoption[0], "value", true), out scanheaders)) { throw new ApplicationException("The value parameter of \"scanheaders\" must be either \"true\" or \"false\"."); } settings.ScanHeaders = scanheaders; } //Scan keys configoption = xn.SelectNodes("scankeys"); if (configoption.Count > 0) { bool scankeys = true; if (!bool.TryParse(GetAttribute(configoption[0], "value", true), out scankeys)) { throw new ApplicationException("The value parameter of \"scankeys\" must be either \"true\" or \"false\"."); } settings.ScanKeys = scankeys; } //Scan output configoption = xn.SelectNodes("scanoutput"); if (configoption.Count > 0) { bool scanoutput = true; if (!bool.TryParse(GetAttribute(configoption[0], "value", true), out scanoutput)) { throw new ApplicationException("The value parameter of \"scanoutput\" must be either \"true\" or \"false\"."); } settings.ScanOutput = scanoutput; } //Scan post configoption = xn.SelectNodes("scanpost"); if (configoption.Count > 0) { bool scanpost = true; if (!bool.TryParse(GetAttribute(configoption[0], "value", true), out scanpost)) { throw new ApplicationException("The value parameter of \"scanpost\" must be either \"true\" or \"false\"."); } settings.ScanPost = scanpost; } }