public ModuleResults GetResults(IInstanceInfo instanceInfo) { var dbService = instanceInfo.DBService; var results = dbService.ExecuteAndGetPrintsFromFile("ScheduledTasksModule.sql"); var res = new ModuleResults { Result = results, }; if (results.Any(x => x.Contains("DISABLE SCHEDULED TASK!") || x.Contains("DO NOT RUN THE task as EXTERNAL") || x.Contains("RUN THE task as EXTERNAL"))) { res.Status = Status.Warning; } return(res); }
public ModuleResults GetResults(IInstanceInfo instanceInfo) { ModuleResults result; Version kenticoVersion = instanceInfo.Version; string pathToWebConfig = instanceInfo.Directory.ToString(); if ((kenticoVersion >= new Version("8.0")) && !(instanceInfo.Directory.ToString().EndsWith("\\CMS\\") || instanceInfo.Directory.ToString().EndsWith("\\CMS"))) { pathToWebConfig += "\\CMS"; } ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap { ExeConfigFilename = pathToWebConfig + "\\web.config" }; Configuration configuration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None); var entry = configuration.AppSettings.Settings["CMSXFrameOptionsExcluded"]; bool hasEntry = entry != null; if (hasEntry) { result = new ModuleResults(); result.Result = entry.Value; result.Status = Status.Warning; result.ResultComment = @"Click jacking protection is disabled for the paths specified in ModuleResults.Result. See https://docs.kentico.com/display/K9/Clickjacking"; } else { result = new ModuleResults(); result.Status = Status.Good; result.ResultComment = @"Click jacking protection is enabled by default. See https://docs.kentico.com/display/K9/Clickjacking"; } return(result); }
public ModuleResults GetResults(IInstanceInfo instanceInfo) { var dbService = instanceInfo.DBService; var sqlFile = instanceInfo.Version.Major <= 10 ? "Setup/GlobalAdminSetupModule.sql" : "Setup/GlobalAdminSetupModule-V10.sql"; var results = dbService.ExecuteAndGetDataSetFromFile(sqlFile); string pathToWebConfig = instanceInfo.Directory.ToString(); if ((instanceInfo.Version.Major >= 8) && !(instanceInfo.Directory.ToString().EndsWith("\\CMS\\") || instanceInfo.Directory.ToString().EndsWith("\\CMS"))) { pathToWebConfig += "\\CMS"; } pathToWebConfig += "\\web.config"; var result = new ModuleResults(); // Try touching the web.config to restart the site if (System.IO.File.Exists(pathToWebConfig)) { System.IO.File.SetLastWriteTimeUtc(pathToWebConfig, DateTime.UtcNow); result.ResultComment = "The default administrator user with UserID=53 has been reset. The application was restarted."; } else { result.ResultComment = "The default administrator user with UserID=53 has been reset. Application could not be restarted. You may need to recycle the application pool for changes to take effect."; } return(result); }
public ModuleResults GetResults(IInstanceInfo instanceInfo) { var dbService = instanceInfo.DBService; var webPartsWithColumns = dbService.ExecuteAndGetTableFromFile("SiteTemplatesModule-WebPartsWithColumns.sql"); var templates = dbService.ExecuteAndGetTableFromFile("SiteTemplatesModule-Templates.sql"); DataSet results = new DataSet(); bool duplicateTemplateCodeName = false; foreach (DataRow template in templates.Rows) { TemplateWebParts templateWP = GetTemplateWebPartsFromXML(template["PageTemplateWebParts"].ToString()); string templateName = template["PageTemplateCodeName"].ToString(); if (results.Tables.Contains(templateName)) { // Page template code names should be unique templateName += " - DUPLICATE CODENAME (ID: " + template["PageTemplateID"] + ")"; duplicateTemplateCodeName = true; } DataTable result = GetTableForTemplateResult(templateName); if (templateWP.WebPartZones != null) { foreach (var zone in templateWP.WebPartZones) { if (zone.WebParts == null || zone.WebParts.Length == 0) { continue; } foreach (var wp in zone.WebParts) { var row = result.NewRow(); row["WebPartTitle"] = GetWebPartPropertyValue(wp, "webparttitle"); row["WebPartType"] = wp.Type; row["ID"] = wp.ControlID; row["Zone"] = zone.ID; row["ContentCache"] = GetWebPartPropertyValue(wp, "cacheminutes"); row["PartialCache"] = GetWebPartPropertyValue(wp, "partialcacheminutes"); row["ViewStateDisabled"] = GetWebPartPropertyValue(wp, "disableviewstate"); DataRow dr = webPartsWithColumns.Select("WebPartName = '" + wp.Type + "'").FirstOrDefault(); if (dr != null) { if ((int)dr["Columns"] == 1) { string colsVal = GetWebPartPropertyValue(wp, "columns"); row["Columns"] = string.IsNullOrEmpty(colsVal) ? "NOT SET" : colsVal; } if ((int)dr["TopN"] == 1) { string topVal = GetWebPartPropertyValue(wp, "SelectTopN"); if (string.IsNullOrEmpty(topVal)) { topVal = GetWebPartPropertyValue(wp, "TopN"); } row["TopN"] = string.IsNullOrEmpty(topVal) ? "NOT SET" : topVal; } } result.Rows.Add(row); } } } results.Tables.Add(result); var documents = dbService.ExecuteAndGetTableFromFile("SiteTemplatesModule-Documents.sql", new SqlParameter("PageTemplateID", template["PageTemplateID"])); documents.TableName = $"{templateName} - Documents"; results.Tables.Add(documents.Copy()); } var moduleResults = new ModuleResults { Result = results, }; if (duplicateTemplateCodeName) { moduleResults.Status = Status.Warning; moduleResults.ResultComment = "Duplicate template code name(s) found, incorrect item(s) are denoted by 'DUPLICATE CODENAME' in its name."; } return(moduleResults); }
public ModuleResults GetResults(IInstanceInfo instanceInfo) { var dbService = instanceInfo.DBService; var siteID = dbService.ExecuteAndGetScalar <int>(string.Format(@"SELECT s.SiteID FROM CMS_Site AS s LEFT JOIN CMS_SiteDomainAlias AS sa ON s.SiteID = sa.SiteID WHERE ('{0}' LIKE '%' + s.SiteDomainName + '%' OR '{0}' LIKE '%' + sa.SiteDomainAliasName + '%') AND s.SiteStatus = N'RUNNING'", instanceInfo.Uri)); var results = new ModuleResults(); var aliases = dbService.ExecuteAndGetTableFromFile("PagesAnalyzerModule.sql", new SqlParameter("SiteId", siteID.ToString())); var allLinks = new Dictionary <string, List <string> >(); Dictionary <string, string> faviconAvailabilityCache = new Dictionary <string, string>(); Dictionary <string, string> touchIconAvailabilityCache = new Dictionary <string, string>(); // Workaround to ignore invalid SSL certificates ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback((a, b, c, d) => { return(true); }); foreach (DataRow alias in aliases.Rows) { var redirected = alias["Redirected"].ToString(); switch (redirected) { // If version 8 and higher is used and page is redirected to first child case "1": continue; // If version 7 and lower is used, database column does not exist case "DOESNOTEXIST": alias["Redirected"] = "N/A"; break; default: alias["Redirected"] = "NO"; break; } var aliasPath = alias["AliasPath"].ToString().TrimStart('/'); // In case of MVC page skip if (aliasPath.StartsWith("ROUTE")) { continue; } var uri = new Uri(instanceInfo.Uri, aliasPath + ".aspx"); var html = string.Empty; try { HttpWebRequest request = WebRequest.CreateHttp(uri); Stopwatch sw = Stopwatch.StartNew(); using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { // Get size of the request using (StreamReader sr = new StreamReader(response.GetResponseStream())) { html = sr.ReadToEnd(); alias["Response"] = response.StatusCode.ToString(); } alias["Response type"] = response.ContentType; } sw.Stop(); alias["Response Time [ms]"] = sw.ElapsedMilliseconds; } catch (WebException e) { // Probably 404 alias["Response"] = e.Status.ToString(); } alias["HTML Size [KB]"] = html.Length / 1024; var viewState = Regex.Match(html, "(?<=__VIEWSTATE\" value=\")(?<val>.*?)(?=\")").Groups["val"].Value; alias["ViewState Size [KB]"] = viewState.Length / 1024; var linksRegex = new Regex("(href|src)=\"(/[^\"]+)|url\\('(/[^\']+)|url\\(\"(/[^\"]+)"); var links = linksRegex.Matches(html); // Evaluate favicon availability alias["Favicon"] = EvaluateFaviconAvailability(html, uri, faviconAvailabilityCache); // Evaluate Apple touch icon and precomposed icon availability alias["Apple Touch Icon"] = EvaluateAppleTouchIconAvailability(html, uri, touchIconAvailabilityCache); alias["Apple Touch Icon Precomposed"] = EvaluateAppleTouchIconAvailability(html, uri, touchIconAvailabilityCache, true); alias["Images without alt"] = GetImagesWithoutAlt(html); // Evaluate links count alias["Link count"] = links.Count; if (links.Count > 0) { foreach (Match match in links) { string link = match.Groups[2].ToString(); if (string.IsNullOrEmpty(link)) { link = match.Groups[3].ToString(); if (string.IsNullOrEmpty(link)) { link = match.Groups[4].ToString(); } } if (!link.ToLower().Contains("/webresource") && !link.ToLower().Contains("/scriptresource")) { if (allLinks.ContainsKey(link)) { allLinks[link].Add(aliasPath); } else { allLinks[link] = new List <string> { aliasPath }; } } } } } foreach (var linkList in allLinks) { // all the links are here, TODO: request them and get the response status } results.Result = aliases; return(results); }