/// <summary> /// UpgradeApplication - This overload is used for version specific application upgrade operations. /// </summary> /// <remarks> /// This should be used for file system modifications or upgrade operations which /// should only happen once. Database references are not recommended because future /// versions of the application may result in code incompatibilties. /// </remarks> /// <param name="Version">The Version being Upgraded</param> private static string UpgradeApplication(string Version) { string strExceptions = ""; try { switch (Version) { case "02.00.00": IDataReader dr; // change portal upload directory from GUID to ID - this only executes for version 2.0.0 string strServerPath = HttpContext.Current.Request.MapPath(Globals.ApplicationPath); string strPortalsDirMapPath = Globals.ApplicationMapPath + "/Portals/"; dr = DataProvider.Instance().GetPortals(); while (dr.Read()) { // if GUID folder exists if (Directory.Exists(strPortalsDirMapPath + dr["GUID"])) { // if ID folder exists ( this may happen because the 2.x release contains a default ID=0 folder ) if (Directory.Exists(strPortalsDirMapPath + dr["PortalID"])) { // rename the ID folder try { Directory.Move(strPortalsDirMapPath + dr["PortalID"], strServerPath + "\\Portals\\" + dr["PortalID"] + "_old"); } catch (Exception ex) { // error moving the directory - security issue? strExceptions += "Could Not Move Folder " + strPortalsDirMapPath + dr["GUID"] + " To " + strPortalsDirMapPath + dr["PortalID"] + ". Error: " + ex.Message + "\r\n"; } } // move GUID folder to ID folder try { Directory.Move(strPortalsDirMapPath + dr["GUID"], strPortalsDirMapPath + dr["PortalID"]); } catch (Exception ex) { // error moving the directory - security issue? strExceptions += "Could Not Move Folder " + strPortalsDirMapPath + dr["GUID"] + " To " + strPortalsDirMapPath + dr["PortalID"] + ". Error: " + ex.Message + "\r\n"; } } } dr.Close(); // copy the default style sheet to the default portal ( if it does not already exist ) if (File.Exists(strPortalsDirMapPath + "0\\portal.css") == false) { if (File.Exists(Globals.HostMapPath + "portal.css")) { File.Copy(Globals.HostMapPath + "portal.css", strPortalsDirMapPath + "0\\portal.css"); } } break; case "02.02.00": string strProviderPath = PortalSettings.GetProviderPath(); if (strProviderPath.StartsWith("ERROR:")) { strExceptions += strProviderPath; break; } //Optionally Install the memberRoleProvider bool installMemberRole = true; if (Config.GetSetting("InstallMemberRole") != null) { installMemberRole = bool.Parse(Config.GetSetting("InstallMemberRole")); } if (installMemberRole) { HtmlUtils.WriteFeedback(HttpContext.Current.Response, 0, "Installing MemberRole Provider:<br>"); strExceptions += InstallMemberRoleProvider(strProviderPath); } PortalController objPortalController = new PortalController(); ArrayList arrPortals; arrPortals = objPortalController.GetPortals(); int intViewModulePermissionID; int intEditModulePermissionID; int intViewTabPermissionID; int intEditTabPermissionID; int intReadFolderPermissionID; int intWriteFolderPermissionID; PermissionController objPermissionController = new PermissionController(); PermissionInfo objPermission = new PermissionInfo(); objPermission.PermissionCode = "SYSTEM_MODULE_DEFINITION"; objPermission.PermissionKey = "VIEW"; objPermission.PermissionName = "View"; objPermission.ModuleDefID = Null.NullInteger; objPermissionController.AddPermission(objPermission); objPermission.PermissionKey = "EDIT"; objPermission.PermissionName = "Edit"; objPermissionController.AddPermission(objPermission); objPermission.PermissionCode = "SYSTEM_TAB"; objPermission.PermissionKey = "VIEW"; objPermission.PermissionName = "View Tab"; objPermissionController.AddPermission(objPermission); objPermission.PermissionKey = "EDIT"; objPermission.PermissionName = "Edit Tab"; objPermissionController.AddPermission(objPermission); objPermission.PermissionCode = "SYSTEM_FOLDER"; objPermission.PermissionKey = "READ"; objPermission.PermissionName = "View Folder"; intReadFolderPermissionID = objPermissionController.AddPermission(objPermission); objPermission.PermissionKey = "WRITE"; objPermission.PermissionName = "Write to Folder"; intWriteFolderPermissionID = objPermissionController.AddPermission(objPermission); FolderController objFolderController = new FolderController(); FolderPermissionController objFolderPermissionController = new FolderPermissionController(); int PortalCount; for (PortalCount = 0; PortalCount <= arrPortals.Count - 1; PortalCount++) { PortalInfo objPortal = (PortalInfo)arrPortals[PortalCount]; int FolderID = objFolderController.AddFolder(objPortal.PortalID, "", (int)FolderController.StorageLocationTypes.InsecureFileSystem, true, false); FolderPermissionInfo objFolderPermission = new FolderPermissionInfo(); objFolderPermission.FolderID = FolderID; objFolderPermission.PermissionID = intReadFolderPermissionID; objFolderPermission.AllowAccess = true; objFolderPermission.RoleID = objPortal.AdministratorRoleId; objFolderPermissionController.AddFolderPermission(objFolderPermission); objFolderPermission.PermissionID = intWriteFolderPermissionID; objFolderPermissionController.AddFolderPermission(objFolderPermission); //TODO: loop through folders recursively here //in case they created any nested folders //and assign priveledges accordingly } //Transfer Users to the Membership Provider MembershipProvider provider = MembershipProvider.Instance(); provider.TransferUsersToMembershipProvider(); ModuleController objModuleController = new ModuleController(); ArrayList arrModules = objModuleController.GetAllModules(); ModulePermissionController objModulePermissionController = new ModulePermissionController(); int ModCount; for (ModCount = 0; ModCount <= arrModules.Count - 1; ModCount++) { ModuleInfo objModule = (ModuleInfo)arrModules[ModCount]; ModulePermissionInfo objModulePermission = new ModulePermissionInfo(); objModulePermission.ModuleID = objModule.ModuleID; int k; string[] roles; if (objModule.AuthorizedViewRoles.IndexOf(";") > 0) { roles = objModule.AuthorizedViewRoles.Split(';'); for (k = 0; k <= roles.Length - 1; k++) { if (Int32.TryParse(roles[k], out intViewModulePermissionID)) { objModulePermission.PermissionID = intViewModulePermissionID; objModulePermission.AllowAccess = true; objModulePermission.RoleID = Convert.ToInt32(roles[k]); objModulePermissionController.AddModulePermission(objModulePermission); } } } if (objModule.AuthorizedEditRoles.IndexOf(";") > 0) { roles = objModule.AuthorizedEditRoles.Split(';'); for (k = 0; k <= roles.Length - 1; k++) { if (Int32.TryParse(roles[k], out intEditModulePermissionID)) { objModulePermission.PermissionID = intEditModulePermissionID; objModulePermission.AllowAccess = true; objModulePermission.RoleID = Convert.ToInt32(roles[k]); objModulePermissionController.AddModulePermission(objModulePermission); } } } } ArrayList arrTabs; TabController objTabController = new TabController(); arrTabs = objTabController.GetAllTabs(); TabPermissionController objTabPermissionController = new TabPermissionController(); for (ModCount = 0; ModCount <= arrTabs.Count - 1; ModCount++) { TabInfo objTab = (TabInfo)arrTabs[ModCount]; TabPermissionInfo objTabPermission = new TabPermissionInfo(); objTabPermission.TabID = objTab.TabID; int k; string[] roles; if (objTab.AuthorizedRoles.IndexOf(";") > 0) { roles = objTab.AuthorizedRoles.Split(';'); for (k = 0; k <= roles.Length - 1; k++) { if (Int32.TryParse(roles[k], out intViewTabPermissionID)) { objTabPermission.PermissionID = intViewTabPermissionID; objTabPermission.AllowAccess = true; objTabPermission.RoleID = Convert.ToInt32(roles[k]); objTabPermissionController.AddTabPermission(objTabPermission); } } } if (objTab.AdministratorRoles.IndexOf(";") > 0) { roles = objTab.AdministratorRoles.Split(';'); for (k = 0; k <= roles.Length - 1; k++) { if (Int32.TryParse(roles[k], out intEditTabPermissionID)) { objTabPermission.PermissionID = intEditTabPermissionID; objTabPermission.AllowAccess = true; objTabPermission.RoleID = Convert.ToInt32(roles[k]); objTabPermissionController.AddTabPermission(objTabPermission); } } } } break; case "03.00.01": objTabController = new TabController(); arrTabs = objTabController.GetAllTabs(); int TabCount; for (TabCount = 0; TabCount <= arrTabs.Count - 1; TabCount++) { TabInfo objTab = (TabInfo)arrTabs[TabCount]; if (objTab != null) { objTab.TabPath = Globals.GenerateTabPath(objTab.ParentId, objTab.TabName); DataProvider.Instance().UpdateTab(objTab.TabID, objTab.TabName, objTab.IsVisible, objTab.DisableLink, objTab.ParentId, objTab.IconFile, objTab.Title, objTab.Description, objTab.KeyWords, objTab.IsDeleted, objTab.Url, objTab.SkinSrc, objTab.ContainerSrc, objTab.TabPath, objTab.StartDate, objTab.EndDate); } } break; case "03.00.06": //Need to clear the cache to pick up new HostSettings from the SQLDataProvider script DataCache.RemoveCache("GetHostSettings"); break; case "03.00.11": //Need to convert any Profile Data to use XmlSerialization as Binary Formatting //is not supported under Medium Trust //Get all the Profiles PersonalizationController objPersonalizationController = new PersonalizationController(); dr = DataProvider.Instance().GetAllProfiles(); while (dr.Read()) { //Load Profile Data (using Binary Formatter method) PersonalizationInfo objPersonalization = new PersonalizationInfo(); try { objPersonalization.UserId = Convert.ToInt32(Null.SetNull(dr["UserID"], objPersonalization.UserId)); } catch { } try { objPersonalization.PortalId = Convert.ToInt32(Null.SetNull(dr["PortalId"], objPersonalization.PortalId)); } catch { } objPersonalization.Profile = Globals.DeserializeHashTableBase64(dr["ProfileData"].ToString()); objPersonalization.IsModified = true; //Save Profile Data (using XML Serializer) objPersonalizationController.SaveProfile(objPersonalization); } dr.Close(); break; case "03.00.12": //If we are upgrading from a 3.0.x version then we need to upgrade the MembershipProvider if (upgradeMemberShipProvider) { strProviderPath = PortalSettings.GetProviderPath(); StreamReader objStreamReader; string strScript; //Upgrade provider HtmlUtils.WriteFeedback(HttpContext.Current.Response, 0, "Executing UpgradeMembershipProvider.sql<br>"); objStreamReader = File.OpenText(strProviderPath + "UpgradeMembershipProvider.sql"); strScript = objStreamReader.ReadToEnd(); objStreamReader.Close(); strExceptions += PortalSettings.ExecuteScript(strScript); } break; case "03.01.00": LogController objLogController = new LogController(); XmlDocument xmlDoc = new XmlDocument(); string xmlConfigFile = Globals.HostMapPath + "Logs\\LogConfig\\LogConfig.xml.resources"; try { xmlDoc.Load(xmlConfigFile); } catch (FileNotFoundException) { xmlConfigFile = Globals.HostMapPath + "Logs\\LogConfig\\LogConfigTemplate.xml.resources"; xmlDoc.Load(xmlConfigFile); } XmlNodeList LogType = xmlDoc.SelectNodes("/LogConfig/LogTypes/LogType"); foreach (XmlNode LogTypeInfo in LogType) { LogTypeInfo objLogTypeInfo = new LogTypeInfo(); objLogTypeInfo.LogTypeKey = LogTypeInfo.Attributes["LogTypeKey"].Value; objLogTypeInfo.LogTypeFriendlyName = LogTypeInfo.Attributes["LogTypeFriendlyName"].Value; objLogTypeInfo.LogTypeDescription = LogTypeInfo.Attributes["LogTypeDescription"].Value; objLogTypeInfo.LogTypeCSSClass = LogTypeInfo.Attributes["LogTypeCSSClass"].Value; objLogTypeInfo.LogTypeOwner = LogTypeInfo.Attributes["LogTypeOwner"].Value; objLogController.AddLogType(objLogTypeInfo); } XmlNodeList LogTypeConfig = xmlDoc.SelectNodes("/LogConfig/LogTypeConfig"); foreach (XmlNode LogTypeConfigInfo in LogTypeConfig) { LogTypeConfigInfo objLogTypeConfig = new LogTypeConfigInfo(); objLogTypeConfig.EmailNotificationIsActive = Convert.ToBoolean((LogTypeConfigInfo.Attributes["EmailNotificationStatus"].Value == "On") ? true : false); objLogTypeConfig.KeepMostRecent = LogTypeConfigInfo.Attributes["KeepMostRecent"].Value; objLogTypeConfig.LoggingIsActive = Convert.ToBoolean((LogTypeConfigInfo.Attributes["LoggingStatus"].Value == "On") ? true : false); objLogTypeConfig.LogTypeKey = LogTypeConfigInfo.Attributes["LogTypeKey"].Value; objLogTypeConfig.LogTypePortalID = LogTypeConfigInfo.Attributes["LogTypePortalID"].Value; objLogTypeConfig.MailFromAddress = LogTypeConfigInfo.Attributes["MailFromAddress"].Value; objLogTypeConfig.MailToAddress = LogTypeConfigInfo.Attributes["MailToAddress"].Value; objLogTypeConfig.NotificationThreshold = Convert.ToInt32(LogTypeConfigInfo.Attributes["NotificationThreshold"].Value); objLogTypeConfig.NotificationThresholdTime = Convert.ToInt32(LogTypeConfigInfo.Attributes["NotificationThresholdTime"].Value); objLogTypeConfig.NotificationThresholdTimeType = (LogTypeConfigInfo.NotificationThresholdTimeTypes)Enum.Parse(typeof(LogTypeConfigInfo.NotificationThresholdTimeTypes), LogTypeConfigInfo.Attributes["NotificationThresholdTimeType"].Value); objLogController.AddLogTypeConfigInfo(objLogTypeConfig); } ScheduleItem objScheduleItem = new ScheduleItem(); objScheduleItem.TypeFullName = "DotNetNuke.Services.Cache.PurgeCache, DOTNETNUKE"; objScheduleItem.AttachToEvent = ""; objScheduleItem.CatchUpEnabled = false; if (Globals.WebFarmEnabled) { objScheduleItem.Enabled = true; } else { objScheduleItem.Enabled = false; } objScheduleItem.ObjectDependencies = ""; objScheduleItem.RetainHistoryNum = 10; objScheduleItem.Servers = ""; objScheduleItem.TimeLapse = 2; objScheduleItem.TimeLapseMeasurement = "hz"; objScheduleItem.RetryTimeLapse = 30; objScheduleItem.RetryTimeLapseMeasurement = "m"; SchedulingProvider.Instance().AddSchedule(objScheduleItem); break; case "03.02.03": //add new SecurityException LogController objSecLogController = new LogController(); XmlDocument xmlSecDoc = new XmlDocument(); string xmlSecConfigFile = Globals.HostMapPath + "Logs\\LogConfig\\SecurityExceptionTemplate.xml.resources"; try { xmlSecDoc.Load(xmlSecConfigFile); } catch (FileNotFoundException) { // xmlConfigFile = Common.Globals.HostMapPath + "Logs\LogConfig\LogConfigTemplate.xml.resources" // xmlDoc.Load(xmlConfigFile) } LogType = xmlSecDoc.SelectNodes("/LogConfig/LogTypes/LogType"); foreach (XmlNode LogTypeInfo in LogType) { LogTypeInfo objLogTypeInfo = new LogTypeInfo(); objLogTypeInfo.LogTypeKey = LogTypeInfo.Attributes["LogTypeKey"].Value; objLogTypeInfo.LogTypeFriendlyName = LogTypeInfo.Attributes["LogTypeFriendlyName"].Value; objLogTypeInfo.LogTypeDescription = LogTypeInfo.Attributes["LogTypeDescription"].Value; objLogTypeInfo.LogTypeCSSClass = LogTypeInfo.Attributes["LogTypeCSSClass"].Value; objLogTypeInfo.LogTypeOwner = LogTypeInfo.Attributes["LogTypeOwner"].Value; objSecLogController.AddLogType(objLogTypeInfo); } LogTypeConfig = xmlSecDoc.SelectNodes("/LogConfig/LogTypeConfig"); foreach (XmlNode LogTypeConfigInfo in LogTypeConfig) { LogTypeConfigInfo objLogTypeConfig = new LogTypeConfigInfo(); objLogTypeConfig.EmailNotificationIsActive = Convert.ToBoolean((LogTypeConfigInfo.Attributes["EmailNotificationStatus"].Value == "On") ? true : false); objLogTypeConfig.KeepMostRecent = LogTypeConfigInfo.Attributes["KeepMostRecent"].Value; objLogTypeConfig.LoggingIsActive = Convert.ToBoolean((LogTypeConfigInfo.Attributes["LoggingStatus"].Value == "On") ? true : false); objLogTypeConfig.LogTypeKey = LogTypeConfigInfo.Attributes["LogTypeKey"].Value; objLogTypeConfig.LogTypePortalID = LogTypeConfigInfo.Attributes["LogTypePortalID"].Value; objLogTypeConfig.MailFromAddress = LogTypeConfigInfo.Attributes["MailFromAddress"].Value; objLogTypeConfig.MailToAddress = LogTypeConfigInfo.Attributes["MailToAddress"].Value; objLogTypeConfig.NotificationThreshold = Convert.ToInt32(LogTypeConfigInfo.Attributes["NotificationThreshold"].Value); objLogTypeConfig.NotificationThresholdTime = Convert.ToInt32(LogTypeConfigInfo.Attributes["NotificationThresholdTime"].Value); objLogTypeConfig.NotificationThresholdTimeType = (LogTypeConfigInfo.NotificationThresholdTimeTypes)Enum.Parse(typeof(LogTypeConfigInfo.NotificationThresholdTimeTypes), LogTypeConfigInfo.Attributes["NotificationThresholdTimeType"].Value); objSecLogController.AddLogTypeConfigInfo(objLogTypeConfig); } break; } } catch (Exception ex) { strExceptions += "Error: " + ex.Message + "\r\n"; try { Exceptions.Exceptions.LogException(ex); } catch { // ignore } } return strExceptions; }
/// <summary> /// Sets a Folder Permission /// </summary> /// <param name="PortalId">The Id of the Portal</param> /// <param name="FolderId">The Id of the Folder</param> /// <param name="PermissionId">The Id of the Permission</param> /// <param name="RoleId">The Id of the Role</param> /// <param name="relativePath">The folder's Relative Path</param> /// <remarks> /// </remarks> public static void SetFolderPermission( int PortalId, int FolderId, int PermissionId, int RoleId, string relativePath ) { FolderPermissionController objFolderPermissionController = new FolderPermissionController(); FolderPermissionCollection objCurrentFolderPermissions; FolderPermissionInfo objFolderPermissionInfo = new FolderPermissionInfo(); objCurrentFolderPermissions = objFolderPermissionController.GetFolderPermissionsCollectionByFolderPath( PortalId, relativePath ); //Iterate current permissions to see if permisison has already been added foreach( FolderPermissionInfo tempLoopVar_objFolderPermissionInfo in objCurrentFolderPermissions ) { objFolderPermissionInfo = tempLoopVar_objFolderPermissionInfo; if( objFolderPermissionInfo.FolderID == FolderId && objFolderPermissionInfo.PermissionID == PermissionId && objFolderPermissionInfo.RoleID == RoleId && objFolderPermissionInfo.AllowAccess ) { return; } } //Permission not found so Add objFolderPermissionInfo = (FolderPermissionInfo)CBO.InitializeObject( objFolderPermissionInfo, typeof( FolderPermissionInfo ) ); objFolderPermissionInfo.FolderID = FolderId; objFolderPermissionInfo.PermissionID = PermissionId; objFolderPermissionInfo.RoleID = RoleId; objFolderPermissionInfo.AllowAccess = true; objFolderPermissionController.AddFolderPermission( objFolderPermissionInfo ); }
/// <summary> /// The cmdUpdate_Click server event handler on this user control runs when the /// Update button is clicked /// </summary> /// <history> /// [DYNST] 2/1/2004 Created /// [Jon Henning] 11/1/2004 Updated to use ClientAPI/DNNTree /// [Jon Henning] 4/21/2004 Rebind grid after update to reflect update - DNN-178 /// </history> protected void cmdUpdate_Click( Object sender, EventArgs e ) { string strFolderPath = FileSystemUtils.StripFolderPath( this.LastFolderPath ).Replace( "\\", "/" ); FolderController objFolderController = new FolderController(); FolderInfo objFolderInfo = objFolderController.GetFolder( FolderPortalID, strFolderPath ); if( objFolderInfo == null ) { //file system needs synchronizing //with database...this folder is new. Synchronize(); objFolderInfo = objFolderController.GetFolder( FolderPortalID, strFolderPath ); } FolderPermissionController objFolderPermissionController = new FolderPermissionController(); FolderPermissionCollection objCurrentFolderPermissions; objCurrentFolderPermissions = objFolderPermissionController.GetFolderPermissionsCollectionByFolderPath( FolderPortalID, strFolderPath ); if( ! objCurrentFolderPermissions.CompareTo( dgPermissions.Permissions ) ) { objFolderPermissionController.DeleteFolderPermissionsByFolder( FolderPortalID, strFolderPath ); foreach (FolderPermissionInfo objFolderPermission in dgPermissions.Permissions) { objFolderPermission.FolderID = objFolderInfo.FolderID; if( objFolderPermission.AllowAccess ) { objFolderPermissionController.AddFolderPermission( objFolderPermission ); } } GeneratePermissionsGrid(); //rebind the grid to reflect updated values - it is possible for the grid controls and the database to become out of sync } }