Results of the module that are used in the IModule.GetResults method.
        public ModuleResults GetResults(InstanceInfo 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("DON NOT RUN THE task as EXTERNAL") 
                || x.Contains("RUN THE task as EXTERNAL")))
            {
                res.Status = Status.Warning;
            }

            return res;
        }
Exemplo n.º 2
0
        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 results = new ModuleResults();

            var dbService = instanceInfo.DBService;
            var sql = $@"SELECT s.SiteID FROM CMS_Site AS s LEFT JOIN CMS_SiteDomainAlias AS sa ON s.SiteID = sa.SiteID
                            WHERE ('{instanceInfo.Uri}' LIKE '%' + s.SiteDomainName + '%'
                            OR '{instanceInfo.Uri}' LIKE '%' + sa.SiteDomainAliasName + '%') AND s.SiteStatus = N'RUNNING'";

            var siteIDRaw = dbService.ExecuteAndGetScalar<string>(sql);
            int siteID = 0;
            if(!int.TryParse(siteIDRaw, out siteID))
            {
                results.Result = $"No site found matching the URL: {instanceInfo.Uri}";
                results.Status = Status.Error;
                return results;
            }

            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().ToLower();
                switch (redirected)
                {
                    // If version 8 and higher is used and page is redirected to first child
                    case "1":
                    case "true":
                        alias["Redirected"] = "True";
                        continue;
                    case "doesnotexist": // If version 7 and lower is used, database column does not exist
                    default:
                        alias["Redirected"] = "False";
                        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;
        }
Exemplo n.º 4
0
        public ModuleResults GetResults(InstanceInfo 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 = String.Format("{0} - Documents", templateName);
                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;
        }