public override CmsDependencyMessage[] ValidateDependency()
        {
            string nothing = Guid.NewGuid().ToString();
            List <CmsDependencyMessage> ret = new List <CmsDependencyMessage>();

            switch (_mode)
            {
            case ExistsMode.MustExist:
                if (CmsConfig.getConfigValue(configKey, nothing) == nothing)
                {
                    ret.Add(CmsDependencyMessage.Error("Required configuration key \"" + configKey + "\" is not set in the web.config file"));
                }
                break;

            case ExistsMode.MustNotExist:
                if (CmsConfig.getConfigValue(configKey, nothing) != nothing)
                {
                    ret.Add(CmsDependencyMessage.Error("Configuration key \"" + configKey + "\" should NOT exist in the web.config file"));
                }
                break;

            default: throw new ArgumentException("Error: invalid validation mode"); break;
            }
            return(ret.ToArray());
        }
예제 #2
0
        /// <summary>
        /// Checks if the control has required parameters.
        /// Invalid:
        ///   - ##RenderControl(_system/[controlName])##
        /// Valid:
        ///   - ##RenderControl(_system/[controlName] key1="value1" key2="value2")##
        /// </summary>
        /// <returns></returns>
        public override CmsDependencyMessage[] ValidateDependency()
        {
            List <CmsDependencyMessage> ret = new List <CmsDependencyMessage>();

            string[] templates = CmsContext.getTemplateNamesForCurrentUser();
            CmsPage  dummyPage = new CmsPage();

            foreach (string template in templates)
            {
                dummyPage.TemplateName = template;

                CmsControlDefinition[] controlDefs = dummyPage.getAllControlDefinitions();
                controlDefs = CmsControlDefinition.GetByControlNameOrPath(controlDefs, ControlName);
                foreach (CmsControlDefinition controlDef in controlDefs)
                {
                    foreach (string keyToTest in keys)
                    {
                        bool keyExists = CmsControlUtils.hasControlParameterKey(CmsContext.currentPage, controlDef, keyToTest);
                        if (!keyExists && existsMode == ExistsMode.MustExist)
                        {
                            ret.Add(CmsDependencyMessage.Error("CMS Control parameter '" + keyToTest + "' for control '" + controlDef.ControlNameOrPath + "' in template '" + dummyPage.TemplateName + "' is required, but was not found."));
                        }
                        else if (keyExists && existsMode == ExistsMode.MustNotExist)
                        {
                            ret.Add(CmsDependencyMessage.Error("CMS Control parameter '" + keyToTest + "' for control '" + controlDef.ControlNameOrPath + "' in template '" + dummyPage.TemplateName + "' was found, and must be removed."));
                        }
                    }
                } // foreach controlDef
            }     // foreach template

            return(ret.ToArray());
        }
            private CmsDependencyMessage[] TestColumn(DBColumnDescription col, DataRowCollection rows, string tableName)
            {
                List <CmsDependencyMessage> ret = new List <CmsDependencyMessage>();
                bool colFound = false;

                foreach (DataRow dr in rows)
                {
                    string fieldName = dr["Field"].ToString();
                    string fieldType = dr["Type"].ToString();

                    if (String.Compare(fieldName, col.ColumnName, true) == 0)
                    {
                        //TODO: add comparison of (optional) column types
                        colFound = true;

                        break;
                    }
                } // foreach

                if (col.existsMode == ExistsMode.MustExist && !colFound)
                {
                    ret.Add(CmsDependencyMessage.Error(tableName + " table does not have a required column named '" + col.ColumnName + "'"));
                }
                else if (col.existsMode == ExistsMode.MustNotExist && colFound)
                {
                    ret.Add(CmsDependencyMessage.Error(tableName + " table has a column named '" + col.ColumnName + "' that must be removed."));
                }

                return(ret.ToArray());
            }
            public CmsDependencyMessage[] TestTable(string TableName, DBColumnDescription[] Columns)
            {
                List <CmsDependencyMessage> ret = new List <CmsDependencyMessage>();

                try
                {
                    string  sql = "DESCRIBE `" + TableName + "`;";
                    DataSet ds  = this.RunSelectQuery(sql);
                    if (hasRows(ds))
                    {
                        if (Columns.Length > 0)
                        {
                            foreach (DBColumnDescription col in Columns)
                            {
                                ret.AddRange(TestColumn(col, ds.Tables[0].Rows, TableName));
                            } // foreach
                        }
                    }
                    else
                    {
                        ret.Add(CmsDependencyMessage.Error("Database table '" + TableName + "' does not exist, or has no columns."));
                    }
                }
                catch (Exception ex)
                {
                    ret.Add(CmsDependencyMessage.Error(ex));
                }

                return(ret.ToArray());
            } // TestTable
예제 #5
0
        public override CmsDependencyMessage[] ValidateDependency()
        {
            List <CmsDependencyMessage> ret = new List <CmsDependencyMessage>();

            if (!System.IO.Directory.Exists(DirectoryPath))
            {
                ret.Add(CmsDependencyMessage.Error("Error: required directory was NOT found!! (\"" + DirectoryPath + "\") "));
            }
            else
            {
                try
                {
                    if (!DirectoryPath.EndsWith(Path.DirectorySeparatorChar.ToString()))
                    {
                        DirectoryPath += Path.DirectorySeparatorChar;
                    }
                    string   testFilename     = DirectoryPath + Guid.NewGuid().ToString() + ".txt";
                    string[] testFileContents = new string[] { "Test file to check if the folder is writable" };
                    try
                    {
                        System.IO.File.WriteAllLines(testFilename, testFileContents);
                    }
                    finally
                    {
                        System.IO.File.Delete(testFilename);
                    }
                }
                catch (Exception ex)
                {
                    ret.Add(CmsDependencyMessage.Error("Error: directory \"" + DirectoryPath + "\" is not writable by the web application!. "));
                }
            }

            return(ret.ToArray());
        }
예제 #6
0
 public override CmsDependencyMessage[] ValidateDependency()
 {
     if (Directory.Exists(FullPathToDir))
     {
         return new CmsDependencyMessage[] { CmsDependencyMessage.Error("The directory \"" + FullPathToDir + "\" should NOT exist") }
     }
     ;
     else
     {
         return(new CmsDependencyMessage[0]);
     }
 }
예제 #7
0
        public CmsDependencyMessage[] ValidateByPageId()
        {
            List <CmsDependencyMessage> ret = new List <CmsDependencyMessage>();

            if (LanguagesThatMustHavePagePath.Length == 0)
            {
                ret.Add(CmsDependencyMessage.Error("Could not run CmsPageDependency for pageId '" + PageId + "' - no languages are configured!"));
            }
            else
            {
                foreach (CmsLanguage lang in LanguagesThatMustHavePagePath)
                {
                    try
                    {
                        CmsPage page = CmsContext.getPageById(PageId);
                        if (Exists == ExistsMode.MustExist)
                        {
                            if (page.ID < 0)
                            {
                                ret.Add(CmsDependencyMessage.Error("Could not find required pageId '" + PageId + "' in language '" + lang.shortCode + "'"));
                            }
                            else if (PageTemplate != "" && String.Compare(page.TemplateName, PageTemplate, true) != 0)
                            {
                                ret.Add(CmsDependencyMessage.Error("The required page '" + PagePath + "' was found, but does not have the correct template (required: '" + PageTemplate + "'); actual: '" + page.TemplateName + "'"));
                            }
                            else
                            {
                                ret.AddRange(CmsTemplateDependency.testTemplate(page.TemplateName, "Page ID #" + PageId.ToString()));
                            }
                        }
                        else if (Exists == ExistsMode.MustNotExist)
                        {
                            if (page.ID >= 0)
                            {
                                ret.Add(CmsDependencyMessage.Error("PageId '" + PageId + "' in language '" + lang.shortCode + "' should NOT exist."));
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        if (Exists == ExistsMode.MustExist)
                        {
                            ret.Add(CmsDependencyMessage.Error("Could not find required pageId '" + PageId + "' in language '" + lang.shortCode + "'"));
                        }
                    }
                } // foreach Language
            }
            return(ret.ToArray());
        }
예제 #8
0
        public static CmsDependencyMessage[] testTemplate(string _templateName, string _dependencySource)
        {
            List <CmsDependencyMessage> ret = new List <CmsDependencyMessage>();

            try
            {
                if (!CmsContext.currentPage.TemplateEngine.templateExists(_templateName))
                {
                    ret.Add(CmsDependencyMessage.Error("Error: the template \"" + _templateName + "\" was NOT found!! (source: " + _dependencySource + ") "));
                }
            }
            catch (Exception e)
            {
                ret.Add(CmsDependencyMessage.Error("Error validating template  '" + _templateName + "' : " + e.Message));
            }

            return(ret.ToArray());
        } // testTemplate
예제 #9
0
        public override CmsDependencyMessage[] ValidateDependency()
        {
            bool exists = PlaceholderUtils.PlaceholderExists(placeholderType);

            if (existsMode == ExistsMode.MustExist && !exists)
            {
                return new CmsDependencyMessage[] { CmsDependencyMessage.Error("The placeholder type \"" + placeholderType + "\" was not found. It was specified in template \"" + templateName + "\". Perhaps this placeholder has been removed from HatCMS?") }
            }
            ;
            else if (existsMode == ExistsMode.MustNotExist && exists)
            {
                return new CmsDependencyMessage[] { CmsDependencyMessage.Error("The placeholder type \"" + placeholderType + "\" must be removed in template \"" + templateName + "\".") }
            }
            ;
            else
            {
                return(new CmsDependencyMessage[0]);
            }
        }
예제 #10
0
        public override CmsDependencyMessage[] ValidateDependency()
        {
            System.Version hatCmsVersion    = CmsContext.currentHatCMSCoreVersion;
            List <CmsDependencyMessage> ret = new List <CmsDependencyMessage>();
            List <string> reqVersionStrings = new List <string>();

            foreach (System.Version ver in AcceptedVersions)
            {
                int    levelToCompare = ver.ToString().Split(new char[] { '.' }).Length;
                string verStr         = ver.ToString(levelToCompare);
                reqVersionStrings.Add(verStr);
                if (hatCmsVersion.ToString(levelToCompare).CompareTo(verStr) == 0)
                {
                    return(ret.ToArray()); // no errors if this version is a match
                }
            }

            ret.Add(CmsDependencyMessage.Error(callerName + " requires HatCMS version " + StringUtils.Join(", ", " or ", reqVersionStrings.ToArray())));
            return(ret.ToArray());
        }
        public override CmsDependencyMessage[] ValidateDependency()
        {
            List <CmsDependencyMessage> ret = new List <CmsDependencyMessage>();

            try
            {
                // -- remove the .ascx filename extension if one was provided.
                if (controlNameOrPath.EndsWith(".ascx", StringComparison.CurrentCultureIgnoreCase))
                {
                    controlNameOrPath = controlNameOrPath.Substring(0, controlNameOrPath.Length - (".ascx".Length));
                }

                string controlPathWithoutOption = controlNameOrPath.Split(new char[] { ' ' })[0];
                if (CmsContext.currentPage.TemplateEngine.controlExists(controlPathWithoutOption))
                {
                    if (existsMode == ExistsMode.MustNotExist)
                    {
                        ret.Add(CmsDependencyMessage.Error("CMS Control should not exist: '" + controlPathWithoutOption + "'"));
                    }
                    else if (existsMode == ExistsMode.MustExist)
                    {
                        DateTime lastModified = CmsContext.currentPage.TemplateEngine.getControlLastModifiedDate(controlPathWithoutOption);
                        if (lastModified != DateTime.MinValue && lastModified.Ticks < FileShouldBeLastModifiedAfter.Ticks)
                        {
                            ret.Add(CmsDependencyMessage.Error("CMS Control \"" + controlPathWithoutOption + "\" should have a last modified date after " + FileShouldBeLastModifiedAfter.ToString("d MMM yyyy hh:mm")));
                        }
                    }
                }
                else if (existsMode == ExistsMode.MustExist)
                {
                    ret.Add(CmsDependencyMessage.Error("CMS Control was not found: '" + controlNameOrPath + "'"));
                }
            }
            catch (Exception ex)
            {
                ret.Add(CmsDependencyMessage.Error("CMS Control could not be found: '" + controlNameOrPath + "'"));
            }
            return(ret.ToArray());
        }
예제 #12
0
        public override CmsDependencyMessage[] ValidateDependency()
        {
            List <CmsDependencyMessage> ret = new List <CmsDependencyMessage>();

            switch (_mode)
            {
            case ExistsMode.MustExist:
                if (CmsConfig.KeyExists(configKey) == false)
                {
                    ret.Add(CmsDependencyMessage.Error("Required configuration key \"" + configKey + "\" is not set in the web.config file"));
                }
                break;

            case ExistsMode.MustNotExist:
                if (CmsConfig.KeyExists(configKey) == true)
                {
                    ret.Add(CmsDependencyMessage.Error("Configuration key \"" + configKey + "\" should NOT exist in the web.config file"));
                }
                break;

            default: throw new ArgumentException("Error: invalid validation mode"); break;
            }
            return(ret.ToArray());
        }
 public override CmsDependencyMessage[] ValidateDependency()
 {
     return(new CmsDependencyMessage[] { CmsDependencyMessage.Error(msg) });
 }
예제 #14
0
        public override CmsDependencyMessage[] ValidateDependency()
        {
            List <CmsDependencyMessage> ret = new List <CmsDependencyMessage>();

            try
            {
                // -- .aspx files must exist in the CmsConfig.URLsToNotRemap array
                if (String.Compare(Path.GetExtension(FullFilePath), ".aspx", true) == 0)
                {
                    string appPathFullDir = System.Web.Hosting.HostingEnvironment.MapPath(CmsContext.ApplicationPath);
                    string relPath        = Hatfield.Web.Portal.PathUtils.RelativePathTo(appPathFullDir, FullFilePath);
                    if (relPath.StartsWith(@"\"))
                    {
                        relPath = relPath.Substring(1);       // remove first slash
                    }
                    string url = relPath.Replace(@"\", @"/"); // switch slashes

#if !DEBUG
                    if (String.Compare(url, "setup/default.aspx", true) == 0)
                    {
                        ret.Add(CmsDependencyMessage.Error("'setup/default.aspx' should be taken out of the \"URLsToNotRemap\" configuration entry on production sites."));
                        return(ret.ToArray());
                    }
#endif

                    if (String.Compare(url, "default.aspx", true) != 0 &&
                        Hatfield.Web.Portal.StringUtils.IndexOf(CmsConfig.URLsToNotRemap, url, StringComparison.CurrentCultureIgnoreCase) < 0)
                    {
                        ret.Add(CmsDependencyMessage.Error("\"" + url + "\" is a required ASPX page, and should be listed in the \"URLsToNotRemap\" configuration entry."));
                    }
                }

                if (File.Exists(FullFilePath))
                {
                    if (_mode == ExistsMode.MustNotExist)
                    {
                        ret.Add(CmsDependencyMessage.Error("File must NOT exist: \"" + FullFilePath + "\""));
                    }
                    else if (FileShouldBeLastModifiedAfter.Ticks != DateTime.MinValue.Ticks)
                    {
                        FileInfo fi = new FileInfo(FullFilePath);
                        if (fi.LastWriteTime.Ticks < FileShouldBeLastModifiedAfter.Ticks)
                        {
                            ret.Add(CmsDependencyMessage.Error("\"" + FullFilePath + "\" should have a last modified date after " + FileShouldBeLastModifiedAfter.ToString("d MMM yyyy hh:mm")));
                        }
                    }
                }
                else
                {
                    if (_mode == ExistsMode.MustExist)
                    {
                        ret.Add(CmsDependencyMessage.Error("File does not exist: \"" + FullFilePath + "\""));
                    }
                }
            }
            catch (Exception ex)
            {
                ret.Add(CmsDependencyMessage.Error(ex));
            }
            return(ret.ToArray());
        }