public int ConvertFilePathToFileId(string FilePath, int PortalID)
        {
            string FileName = "";
            string FolderName = "";
            int FileId = -1;

            if (FilePath != "")
            {
                FileName = FilePath.Substring(FilePath.LastIndexOf("/") + 1);
                FolderName = FilePath.Replace(FileName, "");
            }

            FileController objFiles = new FileController();
            FolderController objFolders = new FolderController();
            FolderInfo objFolder = objFolders.GetFolder(PortalID, FolderName);
            if (objFolder != null)
            {
                FileInfo objFile = objFiles.GetFile(FileName, PortalID, objFolder.FolderID);
                if (objFile != null)
                {
                    FileId = objFile.FileId;
                }
            }
            return FileId;

        }
示例#2
0
        public void DeleteFile(int PortalId, string FileName, string FolderPath)
        {
            var        objFolders = new FolderController();
            FolderInfo objFolder  = objFolders.GetFolder(PortalId, FolderPath, false);

            DeleteFile(PortalId, FileName, objFolder.FolderID, true);
        }
示例#3
0
        public int ConvertFilePathToFileId(string FilePath, int PortalID)
        {
            string FileName   = "";
            string FolderName = "";
            int    FileId     = -1;

            if (FilePath != "")
            {
                FileName   = FilePath.Substring(FilePath.LastIndexOf("/") + 1);
                FolderName = FilePath.Replace(FileName, "");
            }

            FileController   objFiles   = new FileController();
            FolderController objFolders = new FolderController();
            FolderInfo       objFolder  = objFolders.GetFolder(PortalID, FolderName);

            if (objFolder != null)
            {
                FileInfo objFile = objFiles.GetFile(FileName, PortalID, objFolder.FolderID);
                if (objFile != null)
                {
                    FileId = objFile.FileId;
                }
            }
            return(FileId);
        }
示例#4
0
        public void DeleteFile(int PortalId, string FileName, string FolderPath, bool ClearCache)
        {
            FolderController objFolders = new FolderController();
            FolderInfo       objFolder  = objFolders.GetFolder(PortalId, FolderPath);

            DeleteFile(PortalId, FileName, objFolder.FolderID, ClearCache);
        }
示例#5
0
        public int AddFile(int PortalId, string FileName, string Extension, long Size, int Width, int Height, string ContentType, string FolderPath, bool ClearCache)
        {
            FolderController objFolders = new FolderController();
            FolderInfo       objFolder  = objFolders.GetFolder(PortalId, FolderPath);

            return(AddFile(PortalId, FileName, Extension, Size, Width, Height, ContentType, FolderPath, objFolder.FolderID, ClearCache));
        }
示例#6
0
        public int AddFile(FileInfo file, string folderPath)
        {
            var        objFolders = new FolderController();
            FolderInfo objFolder  = objFolders.GetFolder(file.PortalId, folderPath, false);

            file.FolderId = objFolder.FolderID;
            file.Folder   = folderPath;
            return(AddFile(file));
        }
示例#7
0
        public void UpdateFile(int PortalId, string OriginalFileName, string FileName, string Extension, long Size, int Width, int Height, string ContentType, string SourceFolder, string DestinationFolder, bool ClearCache)
        {
            FolderController objFolders = new FolderController();
            FolderInfo       objFolder  = objFolders.GetFolder(PortalId, DestinationFolder);
            FileInfo         objFile    = GetFile(OriginalFileName, PortalId, objFolder.FolderID);

            if (objFile != null)
            {
                UpdateFile(objFile.FileId, FileName, Extension, Size, Width, Height, ContentType, DestinationFolder, objFolder.FolderID);
            }
        }
示例#8
0
        public ArrayList GetFilesByFolder(int portalId, string folderPath)
        {
            var        objFolders = new FolderController();
            FolderInfo objFolder  = objFolders.GetFolder(portalId, folderPath, false);

            if (objFolder == null)
            {
                return(null);
            }
            return(CBO.FillCollection(GetFiles(portalId, objFolder.FolderID), typeof(FileInfo)));
        }
示例#9
0
        public IDataReader GetFiles(int PortalId, string FolderPath)
        {
            var        objFolders = new FolderController();
            FolderInfo objFolder  = objFolders.GetFolder(PortalId, FolderPath, false);

            if (objFolder == null)
            {
                return(null);
            }
            return(GetFiles(PortalId, objFolder.FolderID));
        }
示例#10
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// CacheMappedDirectory caches the Portal Mapped Directory(s)
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <history>
        ///     [cnurse]    1/27/2005   Moved back to App_Start from Caching Module
        /// </history>
        /// -----------------------------------------------------------------------------
        private static void CacheMappedDirectory()
        {
            //This code is only retained for binary compatability.
#pragma warning disable 612,618
            var objFolderController = new FolderController();
            ArrayList arrPortals = PortalController.Instance.GetPortals();
            int i;
            for (i = 0; i <= arrPortals.Count - 1; i++)
            {
                var objPortalInfo = (PortalInfo)arrPortals[i];
                objFolderController.SetMappedDirectory(objPortalInfo, HttpContext.Current);
            }
#pragma warning restore 612,618
        }
示例#11
0
        public FileInfo GetFile(string FileName, int PortalId, string FolderPath)
        {
            var        objFolders = new FolderController();
            FolderInfo objFolder  = objFolders.GetFolder(PortalId, FolderPath, false);

            if (objFolder == null)
            {
                return(null);
            }
            else
            {
                return(GetFile(FileName, PortalId, objFolder.FolderID));
            }
        }
示例#12
0
        public FileInfo GetFile(string FilePath, int PortalId)
        {
            var        objFolders = new FolderController();
            string     FileName   = Path.GetFileName(FilePath);
            FolderInfo objFolder  = objFolders.GetFolder(PortalId, FilePath.Replace(FileName, ""), false);

            if (objFolder == null)
            {
                return(null);
            }
            else
            {
                return(GetFile(FileName, PortalId, objFolder.FolderID));
            }
        }
示例#13
0
        public void UpdateFile(int PortalId, string OriginalFileName, string FileName, string Extension, long Size, int Width, int Height, string ContentType, string SourceFolder,
                               string DestinationFolder, bool ClearCache)
        {
            var        objFolders = new FolderController();
            FolderInfo objFolder  = objFolders.GetFolder(PortalId, DestinationFolder, false);
            FileInfo   objFile    = GetFile(OriginalFileName, PortalId, objFolder.FolderID);

            objFile.FileName    = FileName;
            objFile.Extension   = Extension;
            objFile.Size        = Convert.ToInt32(Size);
            objFile.Width       = Width;
            objFile.Height      = Height;
            objFile.ContentType = ContentType;
            objFile.Folder      = DestinationFolder;

            if ((objFile != null))
            {
                UpdateFile(objFile);
            }
        }
示例#14
0
        public int AddFile(int portalId, string fileName, string extension, long size, int width, int height, string ContentType, string FolderPath, bool ClearCache)
        {
            var        objFolders = new FolderController();
            FolderInfo objFolder  = objFolders.GetFolder(portalId, FolderPath, false);
            var        objFile    = new FileInfo();

            objFile.UniqueId    = Guid.NewGuid();
            objFile.VersionGuid = Guid.NewGuid();

            objFile.PortalId    = portalId;
            objFile.FileName    = fileName;
            objFile.Extension   = extension;
            objFile.Size        = Convert.ToInt32(size);
            objFile.Width       = width;
            objFile.Height      = height;
            objFile.ContentType = ContentType;
            objFile.Folder      = FileSystemUtils.FormatFolderPath(FolderPath);
            objFile.FolderId    = objFolder.FolderID;
            objFile.IsCached    = ClearCache;

            return(AddFile(objFile));
        }
        /// <summary>
        /// Processes all Folders from the template
        /// </summary>
        /// <param name="nodeFolders">Template file node for the Folders</param>
        /// <param name="PortalId">PortalId of the new portal</param>
        /// <history>
        /// 	[cnurse]	11/09/2004	Created
        /// </history>
        private void ParseFolders( XmlNode nodeFolders, int PortalId )
        {
            int FolderId = 0;
            FolderController objController = new FolderController();
            FolderInfo objInfo = null;
            string folderPath = null;
            int storageLocation = 0;
            bool isProtected = false;

            foreach( XmlNode node in nodeFolders.SelectNodes( "//folder" ) )
            {
                folderPath = XmlUtils.GetNodeValue( node, "folderpath", "" );

                //First check if the folder exists
                objInfo = objController.GetFolder( PortalId, folderPath );

                if( objInfo == null )
                {
                    isProtected = FileSystemUtils.DefaultProtectedFolders( folderPath );
                    if( isProtected == true )
                    {
                        // protected folders must use insecure storage
                        storageLocation = (int)FolderController.StorageLocationTypes.InsecureFileSystem;
                    }
                    else
                    {
                        storageLocation = Convert.ToInt32( XmlUtils.GetNodeValue( node, "storagelocation", "0" ) );
                        isProtected = Convert.ToBoolean( XmlUtils.GetNodeValue( node, "isprotected", "0" ) );
                    }
                    //Save new folder 
                    FolderId = objController.AddFolder( PortalId, folderPath, storageLocation, isProtected, false );
                    objInfo = objController.GetFolder( PortalId, folderPath );
                }
                else
                {
                    //Get Id from Folder
                    FolderId = objInfo.FolderID;
                }

                XmlNodeList nodeFolderPermissions = node.SelectNodes( "folderpermissions/permission" );
                ParseFolderPermissions( nodeFolderPermissions, PortalId, FolderId, folderPath );

                XmlNodeList nodeFiles = node.SelectNodes( "files/file" );
                if( folderPath != "" )
                {
                    folderPath += "/";
                }
                ParseFiles( nodeFiles, PortalId, objInfo );
            }
        }
        /// <summary>
        /// Processess a template file for the new portal. This method will be called twice: for the portal template and for the admin template
        /// </summary>
        /// <param name="PortalId">PortalId of the new portal</param>
        /// <param name="TemplatePath">Path for the folder where templates are stored</param>
        /// <param name="TemplateFile">Template file to process</param>
        /// <param name="AdministratorId">UserId for the portal administrator. This is used to assign roles to this user</param>
        /// <param name="mergeTabs">Flag to determine whether Module content is merged.</param>
        /// <param name="IsNewPortal">Flag to determine is the template is applied to an existing portal or a new one.</param>
        /// <remarks>
        /// The roles and settings nodes will only be processed on the portal template file.
        /// </remarks>
        /// <history>
        /// 	[VMasanas]	27/08/2004	Created
        /// </history>
        public void ParseTemplate( int PortalId, string TemplatePath, string TemplateFile, int AdministratorId, PortalTemplateModuleAction mergeTabs, bool IsNewPortal )
        {
            XmlDocument xmlDoc = new XmlDocument();
            XmlNode node = null;
            int AdministratorRoleId = -1;
            int RegisteredRoleId = -1;
            int SubscriberRoleId = -1;
            RoleController objrole = new RoleController();
            bool isAdminTemplate = false;

            isAdminTemplate = ( TemplateFile == "admin.template" );

            // open the XML file
            try
            {
                xmlDoc.Load( TemplatePath + TemplateFile );
            }
            catch // error
            {
                // 
            }

            // settings, roles, folders and files can only be specified in portal templates, will be ignored on the admin template
            if( !isAdminTemplate )
            {
                // parse roles if available
                node = xmlDoc.SelectSingleNode( "//portal/roles" );
                if( node != null )
                {
                    ParseRoles( node, PortalId, AdministratorId, ref AdministratorRoleId, ref RegisteredRoleId, ref SubscriberRoleId );
                }

                // create required roles if not already created
                if( AdministratorRoleId == -1 )
                {
                    AdministratorRoleId = CreateRole( PortalId, "Administrators", "Portal Administrators", 0F, 0, "M", 0F, 0, "N", false, false );
                }
                if( RegisteredRoleId == -1 )
                {
                    RegisteredRoleId = CreateRole( PortalId, "Registered Users", "Registered Users", 0F, 0, "M", 0F, 0, "N", false, true );
                }
                if( SubscriberRoleId == -1 )
                {
                    SubscriberRoleId = CreateRole( PortalId, "Subscribers", "A public role for portal subscriptions", 0F, 0, "M", 0F, 0, "N", true, true );
                }

                objrole.AddUserRole( PortalId, AdministratorId, AdministratorRoleId, Null.NullDate, Null.NullDate );
                objrole.AddUserRole( PortalId, AdministratorId, RegisteredRoleId, Null.NullDate, Null.NullDate );
                objrole.AddUserRole( PortalId, AdministratorId, SubscriberRoleId, Null.NullDate, Null.NullDate );

                // parse portal folders
                node = xmlDoc.SelectSingleNode( "//portal/folders" );
                if( node != null )
                {
                    ParseFolders( node, PortalId );
                }
                // force creation of root folder if not present on template
                FolderController objController = new FolderController();
                if( objController.GetFolder( PortalId, "" ) == null )
                {
                    int folderid = objController.AddFolder( PortalId, "", (int)FolderController.StorageLocationTypes.InsecureFileSystem, true, false );
                    PermissionController objPermissionController = new PermissionController();
                    ArrayList arr = objPermissionController.GetPermissionByCodeAndKey( "SYSTEM_FOLDER", "" );
                    foreach( PermissionInfo objpermission in arr )
                    {
                        FileSystemUtils.SetFolderPermission( PortalId, folderid, objpermission.PermissionID, AdministratorRoleId, "" );
                        if( objpermission.PermissionKey == "READ" )
                        {
                            // add READ permissions to the All Users Role
                            FileSystemUtils.SetFolderPermission( PortalId, folderid, objpermission.PermissionID, int.Parse( Globals.glbRoleAllUsers ), "" );
                        }
                    }
                }

                // parse portal settings if available only for new portals
                node = xmlDoc.SelectSingleNode( "//portal/settings" );
                if( node != null & IsNewPortal )
                {
                    ParsePortalSettings( node, PortalId );
                }

                // update portal setup
                PortalInfo objportal = null;
                objportal = GetPortal( PortalId );
                UpdatePortalSetup( PortalId, AdministratorId, AdministratorRoleId, RegisteredRoleId, objportal.SplashTabId, objportal.HomeTabId, objportal.LoginTabId, objportal.UserTabId, objportal.AdminTabId );

                //Remove Exising Tabs if doing a "Replace"
                if( mergeTabs == PortalTemplateModuleAction.Replace )
                {
                    TabController objTabs = new TabController();
                    TabInfo objTab = null;
                    foreach( KeyValuePair<int, TabInfo> tabPair in objTabs.GetTabsByPortal( PortalId ) )
                    {
                        objTab = tabPair.Value;
                        if( !objTab.IsAdminTab )
                        {
                            //soft delete Tab
                            objTab.TabName = objTab.TabName + "_old";
                            objTab.IsDeleted = true;
                            objTabs.UpdateTab( objTab );
                            //Delete all Modules
                            ModuleController objModules = new ModuleController();
                            ModuleInfo objModule = null;
                            foreach( KeyValuePair<int, ModuleInfo> modulePair in objModules.GetTabModules( objTab.TabID ) )
                            {
                                objModule = modulePair.Value;
                                objModules.DeleteTabModule( objModule.TabID, objModule.ModuleID );
                            }
                        }
                    }
                }
            }

            // parse portal tabs
            node = xmlDoc.SelectSingleNode( "//portal/tabs" );
            if( node != null )
            {
                ParseTabs( node, PortalId, isAdminTemplate, mergeTabs, IsNewPortal );
            }
        }
        /// <summary>
        /// Creates a new portal.
        /// </summary>
        /// <param name="PortalName">Name of the portal to be created</param>
        /// <param name="FirstName">Portal Administrator's first name</param>
        /// <param name="LastName">Portal Administrator's last name</param>
        /// <param name="Username">Portal Administrator's username</param>
        /// <param name="Password">Portal Administrator's password</param>
        /// <param name="Email">Portal Administrator's email</param>
        /// <param name="Description">Description for the new portal</param>
        /// <param name="KeyWords">KeyWords for the new portal</param>
        /// <param name="TemplatePath">Path where the templates are stored</param>
        /// <param name="TemplateFile">Template file</param>
        /// <param name="PortalAlias">Portal Alias String</param>
        /// <param name="ServerPath">The Path to the root of the Application</param>
        /// <param name="ChildPath">The Path to the Child Portal Folder</param>
        /// <param name="IsChildPortal">True if this is a child portal</param>
        /// <returns>PortalId of the new portal if there are no errors, -1 otherwise.</returns>
        /// <remarks>
        /// After the selected portal template is parsed the admin template ("admin.template") will be
        /// also processed. The admin template should only contain the "Admin" menu since it's the same
        /// on all portals. The selected portal template can contain a <settings/> node to specify portal
        /// properties and a <roles/> node to define the roles that will be created on the portal by default.
        /// </remarks>
        /// <history>
        /// 	[cnurse]	11/08/2004	created (most of this code was moved from SignUp.ascx.vb)
        /// </history>
        public int CreatePortal( string PortalName, string FirstName, string LastName, string Username, string Password, string Email, string Description, string KeyWords, string TemplatePath, string TemplateFile, string HomeDirectory, string PortalAlias, string ServerPath, string ChildPath, bool IsChildPortal )
        {
            FolderController objFolderController = new FolderController();
            string strMessage = Null.NullString;
            int AdministratorId = Null.NullInteger;
            UserInfo objAdminUser = new UserInfo();

            //Attempt to create a new portal
            int intPortalId = CreatePortal( PortalName, HomeDirectory );

            if( intPortalId != -1 )
            {
                if( HomeDirectory == "" )
                {
                    HomeDirectory = "Portals/" + intPortalId.ToString();
                }
                string MappedHomeDirectory = objFolderController.GetMappedDirectory( Globals.ApplicationPath + "/" + HomeDirectory + "/" );

                strMessage += CreateProfileDefinitions( intPortalId, TemplatePath, TemplateFile );
                if( strMessage == Null.NullString )
                {
                    // add administrator
                    try
                    {
                        objAdminUser.PortalID = intPortalId;
                        objAdminUser.FirstName = FirstName;
                        objAdminUser.LastName = LastName;
                        objAdminUser.Username = Username;
                        objAdminUser.DisplayName = FirstName + " " + LastName;
                        objAdminUser.Membership.Password = Password;
                        objAdminUser.Email = Email;
                        objAdminUser.IsSuperUser = false;
                        objAdminUser.Membership.Approved = true;

                        objAdminUser.Profile.FirstName = FirstName;
                        objAdminUser.Profile.LastName = LastName;

                        UserCreateStatus createStatus = UserController.CreateUser( ref objAdminUser );

                        if( createStatus == UserCreateStatus.Success )
                        {
                            AdministratorId = objAdminUser.UserID;
                        }
                        else
                        {
                            strMessage += UserController.GetUserCreateStatus( createStatus );
                        }
                    }
                    catch( Exception Exc )
                    {
                        strMessage += Localization.GetString( "CreateAdminUser.Error" ) + Exc.Message + Exc.StackTrace;
                    }
                }
                else
                {
                    throw new Exception( strMessage );
                }

                if( strMessage == "" & AdministratorId > 0 )
                {
                    try
                    {
                        // the upload directory may already exist if this is a new DB working with a previously installed application
                        if( Directory.Exists( MappedHomeDirectory ) )
                        {
                            Globals.DeleteFolderRecursive( MappedHomeDirectory );
                        }
                    }
                    catch( Exception Exc )
                    {
                        strMessage += Localization.GetString( "DeleteUploadFolder.Error" ) + Exc.Message + Exc.StackTrace;
                    }

                    //Set up Child Portal
                    if( strMessage == Null.NullString )
                    {
                        try
                        {
                            if( IsChildPortal )
                            {
                                // create the subdirectory for the new portal
                                if( !( Directory.Exists( ChildPath ) ) )
                                {
                                    Directory.CreateDirectory( ChildPath );
                                }

                                // create the subhost default.aspx file
                                if( !( File.Exists( ChildPath + "\\" + Globals.glbDefaultPage ) ) )
                                {
                                    File.Copy( Globals.HostMapPath + "subhost.aspx", ChildPath + "\\" + Globals.glbDefaultPage );
                                }
                            }
                        }
                        catch( Exception Exc )
                        {
                            strMessage += Localization.GetString( "ChildPortal.Error" ) + Exc.Message + Exc.StackTrace;
                        }
                    }
                    else
                    {
                        throw new Exception( strMessage );
                    }

                    if( strMessage == Null.NullString )
                    {
                        try
                        {
                            // create the upload directory for the new portal
                            Directory.CreateDirectory( MappedHomeDirectory );

                            // copy the default stylesheet to the upload directory
                            File.Copy( Globals.HostMapPath + "portal.css", MappedHomeDirectory + "portal.css" );

                            // process zip resource file if present
                            ProcessResourceFile( MappedHomeDirectory, TemplatePath + TemplateFile );
                        }
                        catch( Exception Exc )
                        {
                            strMessage += Localization.GetString( "ChildPortal.Error" ) + Exc.Message + Exc.StackTrace;
                        }
                    }
                    else
                    {
                        throw new Exception( strMessage );
                    }

                    if( strMessage == Null.NullString )
                    {
                        // parse portal template
                        try
                        {
                            ParseTemplate( intPortalId, TemplatePath, TemplateFile, AdministratorId, PortalTemplateModuleAction.Replace, true );
                        }
                        catch( Exception Exc )
                        {
                            strMessage += Localization.GetString( "PortalTemplate.Error" ) + Exc.Message + Exc.StackTrace;
                        }

                        // parse admin template
                        try
                        {
                            ParseTemplate( intPortalId, TemplatePath, "admin.template", AdministratorId, PortalTemplateModuleAction.Replace, true );
                        }
                        catch( Exception Exc )
                        {
                            strMessage += Localization.GetString( "AdminTemplate.Error" ) + Exc.Message + Exc.StackTrace;
                        }
                    }
                    else
                    {
                        throw new Exception( strMessage );
                    }

                    if( strMessage == Null.NullString )
                    {
                        // update portal setup
                        PortalInfo objportal = GetPortal( intPortalId );

                        // update portal info
                        objportal.Description = Description;
                        objportal.KeyWords = KeyWords;
                        UpdatePortalInfo( objportal.PortalID, objportal.PortalName, objportal.LogoFile, objportal.FooterText, objportal.ExpiryDate, objportal.UserRegistration, objportal.BannerAdvertising, objportal.Currency, objportal.AdministratorId, objportal.HostFee, objportal.HostSpace, objportal.PageQuota, objportal.UserQuota, objportal.PaymentProcessor, objportal.ProcessorUserId, objportal.ProcessorPassword, objportal.Description, objportal.KeyWords, objportal.BackgroundFile, objportal.SiteLogHistory, objportal.SplashTabId, objportal.HomeTabId, objportal.LoginTabId, objportal.UserTabId, objportal.DefaultLanguage, objportal.TimeZoneOffset, objportal.HomeDirectory );

                        //Update Administrators Locale/TimeZone
                        objAdminUser.Profile.PreferredLocale = objportal.DefaultLanguage;
                        objAdminUser.Profile.TimeZone = objportal.TimeZoneOffset;

                        //Save Admin User
                        UserController.UpdateUser( objportal.PortalID, objAdminUser );

                        //clear portal alias cache
                        DataCache.ClearHostCache( true );

                        // clear roles cache
                        DataCache.RemoveCache( "GetRoles" );

                        //Create Portal Alias
                        AddPortalAlias( intPortalId, PortalAlias );

                        // log installation event
                        try
                        {
                            LogInfo objEventLogInfo = new LogInfo();
                            objEventLogInfo.LogTypeKey = EventLogController.EventLogType.HOST_ALERT.ToString();
                            objEventLogInfo.LogTypeKey = EventLogController.EventLogType.HOST_ALERT.ToString();
                            objEventLogInfo.LogProperties.Add( new LogDetailInfo( "Install Portal:", PortalName ) );
                            objEventLogInfo.LogProperties.Add( new LogDetailInfo( "FirstName:", FirstName ) );
                            objEventLogInfo.LogProperties.Add( new LogDetailInfo( "LastName:", LastName ) );
                            objEventLogInfo.LogProperties.Add( new LogDetailInfo( "Username:"******"Email:", Email ) );
                            objEventLogInfo.LogProperties.Add( new LogDetailInfo( "Description:", Description ) );
                            objEventLogInfo.LogProperties.Add( new LogDetailInfo( "Keywords:", KeyWords ) );
                            objEventLogInfo.LogProperties.Add( new LogDetailInfo( "TemplatePath:", TemplatePath ) );
                            objEventLogInfo.LogProperties.Add( new LogDetailInfo( "TemplateFile:", TemplateFile ) );
                            objEventLogInfo.LogProperties.Add( new LogDetailInfo( "HomeDirectory:", HomeDirectory ) );
                            objEventLogInfo.LogProperties.Add( new LogDetailInfo( "PortalAlias:", PortalAlias ) );
                            objEventLogInfo.LogProperties.Add( new LogDetailInfo( "ServerPath:", ServerPath ) );
                            objEventLogInfo.LogProperties.Add( new LogDetailInfo( "ChildPath:", ChildPath ) );
                            objEventLogInfo.LogProperties.Add( new LogDetailInfo( "IsChildPortal:", IsChildPortal.ToString() ) );
                            EventLogController objEventLog = new EventLogController();
                            objEventLog.AddLog( objEventLogInfo );
                        }
                        catch( Exception ex )
                        {
                            // error
                        }
                    }
                    else
                    {
                        throw new Exception( strMessage );
                    }
                }
                else // clean up
                {
                    DeletePortalInfo( intPortalId );
                    intPortalId = -1;
                    throw new Exception( strMessage );
                }
            }
            else
            {
                strMessage += Localization.GetString( "CreatePortal.Error" );
                throw new Exception( strMessage );
            }

            return intPortalId;
        }
示例#18
0
 /// <summary>
 /// Gets all the folders for a Portal
 /// </summary>
 /// <param name="PortalID">The Id of the Portal</param>
 /// <remarks>
 /// </remarks>
 public static ArrayList GetFolders( int PortalID )
 {
     FolderController objFolderController = new FolderController();
     ArrayList arrFolders = (ArrayList)( DataCache.GetCache( "Folders:" + PortalID.ToString() ) );
     if( arrFolders == null )
     {
         arrFolders = objFolderController.GetFoldersByPortal( PortalID );
         DataCache.SetCache( "Folders:" + PortalID.ToString(), arrFolders );
     }
     return arrFolders;
 }
示例#19
0
        /// <summary>
        /// Unzips a File
        /// </summary>
        /// <param name="fileName">The zip File Name</param>
        /// <param name="DestFolder">The folder where the file is extracted to</param>
        /// <param name="settings">The Portal Settings for the Portal/Host Account</param>
        /// <remarks>
        /// </remarks>
        public static string UnzipFile( string fileName, string DestFolder, PortalSettings settings )
        {
            int FolderPortalId = GetFolderPortalId( settings );
            bool isHost = Convert.ToBoolean( ( ( settings.ActiveTab.ParentId == settings.SuperTabId ) ? true : false ) );

            PortalController objPortalController = new PortalController();
            FolderController objFolderController = new FolderController();
            FileController objFileController = new FileController();
            string sourceFolderName = Globals.GetSubFolderPath( fileName );
            string sourceFileName = GetFileName( fileName );
            FolderInfo folder = objFolderController.GetFolder( FolderPortalId, sourceFolderName );
            Services.FileSystem.FileInfo file = objFileController.GetFile( sourceFileName, FolderPortalId, folder.FolderID );
            int storageLocation = folder.StorageLocation;
            ZipInputStream objZipInputStream;
            ZipEntry objZipEntry;
            string strMessage = "";
            string strFileName = "";

            //Get the source Content from wherever it is

            //Create a Zip Input Stream
            try
            {
                objZipInputStream = new ZipInputStream( GetFileStream( file ) );
            }
            catch( Exception ex )
            {
                return ex.Message;
            }

            ArrayList sortedFolders = new ArrayList();

            objZipEntry = objZipInputStream.GetNextEntry();
            //add initial entry if required
            if( objZipEntry.IsDirectory )
            {
                sortedFolders.Add( objZipEntry.Name.ToString() );
            }
            //iterate other folders
            while( objZipEntry != null )
            {
                if( objZipEntry.IsDirectory )
                {
                    try
                    {
                        sortedFolders.Add( objZipEntry.Name.ToString() );
                    }
                    catch( Exception ex )
                    {
                        objZipInputStream.Close();
                        return ex.Message;
                    }
                }
                objZipEntry = objZipInputStream.GetNextEntry();
            }

            sortedFolders.Sort();

            foreach( string s in sortedFolders )
            {
                try
                {
                    AddFolder( settings, DestFolder, s.ToString(), storageLocation );
                }
                catch( Exception ex )
                {
                    return ex.Message;
                }
            }

            objZipEntry = objZipInputStream.GetNextEntry();
            while( objZipEntry != null )
            {
                if( objZipEntry.IsDirectory )
                {
                    try
                    {
                        AddFolder( settings, DestFolder, objZipEntry.Name, storageLocation );
                    }
                    catch( Exception ex )
                    {
                        objZipInputStream.Close();
                        return ex.Message;
                    }
                }
                objZipEntry = objZipInputStream.GetNextEntry();
            }

            //Recreate the Zip Input Stream and parse it for the files
            objZipInputStream = new ZipInputStream( GetFileStream( file ) );
            objZipEntry = objZipInputStream.GetNextEntry();
            while( objZipEntry != null )
            {
                if( !objZipEntry.IsDirectory )
                {
                    if( objPortalController.HasSpaceAvailable( FolderPortalId, objZipEntry.Size ) )
                    {
                        strFileName = Path.GetFileName( objZipEntry.Name );
                        if( !String.IsNullOrEmpty( strFileName ) )
                        {
                            string strExtension = Path.GetExtension( strFileName ).Replace( ".", "" );
                            string a = "," + settings.HostSettings["FileExtensions"].ToString().ToLower();
                            if( ( a.IndexOf( "," + strExtension.ToLower(), 0 ) + 1 ) != 0 || isHost )
                            {
                                try
                                {
                                    string folderPath = Path.GetDirectoryName( DestFolder + objZipEntry.Name.Replace( "/", "\\" ) );
                                    DirectoryInfo Dinfo = new DirectoryInfo( folderPath );
                                    if( !Dinfo.Exists )
                                    {
                                        AddFolder( settings, DestFolder, objZipEntry.Name.Substring( 0, objZipEntry.Name.Replace( "/", "\\" ).LastIndexOf( "\\" ) ) );
                                    }

                                    string zipEntryFileName = DestFolder + objZipEntry.Name.Replace( "/", "\\" );
                                    strMessage += AddFile( FolderPortalId, objZipInputStream, zipEntryFileName, "", objZipEntry.Size, Globals.GetSubFolderPath( zipEntryFileName ), false, false );
                                }
                                catch( Exception ex )
                                {
                                    objZipInputStream.Close();
                                    return ex.Message;
                                }
                            }
                            else
                            {
                                // restricted file type
                                strMessage += "<br>" + string.Format( Localization.GetString( "RestrictedFileType" ), strFileName, settings.HostSettings["FileExtensions"].ToString().Replace( ",", ", *." ) );
                            }
                        }
                    }
                    else // file too large
                    {
                        strMessage += "<br>" + string.Format( Localization.GetString( "DiskSpaceExceeded" ), strFileName );
                    }
                }

                objZipEntry = objZipInputStream.GetNextEntry();
            }

            objZipInputStream.Close();

            return strMessage;
        }
示例#20
0
 /// <summary>
 /// CacheMappedDirectory caches the Portal Mapped Directory(s)
 /// </summary>
 /// <history>
 ///     [cnurse]    1/27/2005   Moved back to App_Start from Caching Module
 /// </history>
 private void CacheMappedDirectory()
 {
     //Cache the mapped physical home directory for each portal
     //so the mapped directories are available outside
     //of httpcontext.   This is especially necessary
     //when the /Portals or portal home directory has been
     //mapped in IIS to another directory or server.
     FolderController objFolderController = new FolderController();
     PortalController objPortalController = new PortalController();
     ArrayList arrPortals = objPortalController.GetPortals();
     int i;
     for( i = 0; i <= arrPortals.Count - 1; i++ )
     {
         PortalInfo objPortalInfo = (PortalInfo)arrPortals[i];
         objFolderController.SetMappedDirectory( objPortalInfo, HttpContext.Current );
     }
 }
示例#21
0
        /// <summary>
        /// Check if Folder is a Secure Folder
        /// </summary>
        /// <param name="folderPath">The folder path.</param>
        /// <returns>
        /// Returns if folder is Secure
        /// </returns>
        private FolderController.StorageLocationTypes GetStorageLocationType(string folderPath)
        {
            if (string.IsNullOrEmpty(folderPath))
            {
                return FolderController.StorageLocationTypes.InsecureFileSystem;
            }

            try
            {
                folderPath = folderPath.Substring(this._portalSettings.HomeDirectoryMapPath.Length).Replace("\\", "/");
            }
            catch (Exception)
            {
                folderPath = folderPath.Replace("\\", "/");
            }

            FolderController.StorageLocationTypes storagelocationType;

            try
            {
                var folderInfo = new FolderController().GetFolder(this._portalSettings.PortalId, folderPath, false);

                storagelocationType = (FolderController.StorageLocationTypes)folderInfo.StorageLocation;
            }
            catch (Exception)
            {
                storagelocationType = FolderController.StorageLocationTypes.InsecureFileSystem;
            }

            return storagelocationType;
        }
示例#22
0
        /*
        /// <summary>
        ///  Get an Resized Image
        /// </summary>
        /// <param name="imgPhoto">
        /// Original Image
        /// </param>
        /// <param name="ts">
        /// New Size
        /// </param>
        /// <returns>
        /// The Resized Image
        /// </returns>
        private static Image GetResizedImage(Image imgPhoto, Size ts)
        {
            int sourceWidth = imgPhoto.Width;
            int sourceHeight = imgPhoto.Height;
            const int sourceX = 0;
            const int sourceY = 0;
            int destX = 0;
            int destY = 0;

            float nPercent;

            bool sourceVertical = sourceWidth < sourceHeight;
            bool targetVeritcal = ts.Width < ts.Height;

            if (sourceVertical != targetVeritcal)
            {
                int t = ts.Width;
                ts.Width = ts.Height;
                ts.Height = t;
            }

            float nPercentW = ts.Width / (float)sourceWidth;
            float nPercentH = ts.Height / (float)sourceHeight;

            if (nPercentH < nPercentW)
            {
                nPercent = nPercentH;
                destX = Convert.ToInt16((ts.Width - (sourceWidth * nPercent)) / 2);
            }
            else
            {
                nPercent = nPercentW;
                destY = Convert.ToInt16((ts.Height - (sourceHeight * nPercent)) / 2);
            }

            int destWidth = (int)(sourceWidth * nPercent);
            int destHeight = (int)(sourceHeight * nPercent);

            Bitmap bmPhoto = new Bitmap(ts.Width, ts.Height, PixelFormat.Format24bppRgb);

            bmPhoto.MakeTransparent(Color.Transparent);

            bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);

            Graphics grPhoto = Graphics.FromImage(bmPhoto);

            // grPhoto.Clear(Color.White);
            grPhoto.Clear(Color.Transparent);

            grPhoto.InterpolationMode = InterpolationMode.HighQualityBicubic;

            grPhoto.DrawImage(
                imgPhoto,
                new Rectangle(destX, destY, destWidth, destHeight),
                new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight),
                GraphicsUnit.Pixel);

            grPhoto.Dispose();
            return bmPhoto;
        }*/
        /// <summary>
        /// Check if Folder is a Secure Folder
        /// </summary>
        /// <param name="folderId">The folder id.</param>
        /// <returns>
        /// Returns if folder is Secure
        /// </returns>
        private FolderController.StorageLocationTypes GetStorageLocationType(int folderId)
        {
            FolderController.StorageLocationTypes storagelocationType;

            try
            {
                var folderInfo = new FolderController().GetFolderInfo(this._portalSettings.PortalId, folderId);

                storagelocationType = (FolderController.StorageLocationTypes)folderInfo.StorageLocation;
            }
            catch (Exception)
            {
                storagelocationType = FolderController.StorageLocationTypes.InsecureFileSystem;
            }

            return storagelocationType;
        }
        private void CheckUserFolderExist_Local()
        {
            FolderController ctlFolder = new FolderController();
            //Create root folder
            if (!Directory.Exists(PortalSettings.HomeDirectoryMapPath + Local_FolderRootPrefix ))
            {
                // 创建根目录,注意此处用filesystemutils来创建,这样可以设置缺省的文件夹权限
                FileSystemUtils.AddFolder(PortalSettings, PortalSettings.HomeDirectoryMapPath, Local_FolderRootPrefix, 0);
               // Directory.CreateDirectory(PortalSettings.HomeDirectoryMapPath + Local_FolderRootPrefix);
            }
            if (ctlFolder.GetFolder(PortalSettings.PortalId, Local_FolderRootPrefix + "/", true)==null)//检查该folder是否存在数据库中,
            {
                ctlFolder.AddFolder(PortalSettings.PortalId, Local_FolderRootPrefix + "/");//不存在则添加
            }

            //Check user root folder
            if (!Directory.Exists(Local_UserFolderPath_Physical))
            {
                // 创建用户根目录,注意此处用filesystemutils来创建,这样可以设置缺省的文件夹权限
                FileSystemUtils.AddFolder(PortalSettings, PortalSettings.HomeDirectoryMapPath + Local_FolderRootPrefix, CurrentUserId.ToString(), 0);
               // Directory.CreateDirectory(Local_UserFolderPath_Physical);
            }
            if (ctlFolder.GetFolder(PortalSettings.PortalId, Local_UserFolderPath_Relative, true) == null)
            {
                ctlFolder.AddFolder(PortalSettings.PortalId, Local_UserFolderPath_Relative);//不存在则添加
            }
        }
示例#24
0
        public static void AddFile(string strFileName, string strExtension, string FolderPath, string strContentType, int Length, int imageWidth, int imageHeight)
        {
#pragma warning disable 612,618
            // Obtain PortalSettings from Current Context
            PortalSettings _portalSettings = PortalController.GetCurrentPortalSettings();
            int PortalId = FileSystemUtils.GetFolderPortalId(_portalSettings);
            var objFiles = new FileController();
            var objFolders = new FolderController();
            FolderInfo objFolder = objFolders.GetFolder(PortalId, FolderPath, false);
            if ((objFolder != null))
            {
                var objFile = new FileInfo(PortalId, strFileName, strExtension, Length, imageWidth, imageHeight, strContentType, FolderPath, objFolder.FolderID, objFolder.StorageLocation, true);
                objFiles.AddFile(objFile);
            }
#pragma warning restore 612,618
        }
示例#25
0
        /// <summary>
        /// Updates a File
        /// </summary>
        /// <param name="strSourceFile">The original File Name</param>
        /// <param name="strDestFile">The new File Name</param>
        /// <param name="PortalId"></param>
        /// <param name="isCopy">Flag determines whether file is to be be moved or copied</param>
        /// <param name="ClearCache"></param>
        private static string UpdateFile( string strSourceFile, string strDestFile, int PortalId, bool isCopy, bool isNew, bool ClearCache )
        {
            string retValue = "";
            retValue += CheckValidFileName( strSourceFile ) + " ";
            retValue += CheckValidFileName( strDestFile );
            if( retValue.Length > 1 )
            {
                return retValue;
            }
            retValue = "";

            try
            {
                FolderController objFolderController = new FolderController();
                FileController objFileController = new FileController();
                string sourceFolderName = Globals.GetSubFolderPath( strSourceFile );
                string sourceFileName = GetFileName( strSourceFile );
                FolderInfo sourceFolder = objFolderController.GetFolder( PortalId, sourceFolderName );

                string destFileName = GetFileName( strDestFile );
                string destFolderName = Globals.GetSubFolderPath( strDestFile );

                if( sourceFolder != null )
                {
                    Services.FileSystem.FileInfo file = objFileController.GetFile( sourceFileName, PortalId, sourceFolder.FolderID );
                    if( file != null )
                    {
                        //Get the source Content from wherever it is
                        Stream sourceStream = GetFileStream( file );

                        if( isCopy )
                        {
                            //Add the new File
                            AddFile( PortalId, sourceStream, strDestFile, "", file.Size, destFolderName, true, ClearCache );
                        }
                        else
                        {
                            //Move/Update existing file
                            FolderInfo destinationFolder = objFolderController.GetFolder( PortalId, destFolderName );

                            //Now move the file
                            if( destinationFolder != null )
                            {
                                objFileController.UpdateFile( file.FileId, destFileName, file.Extension, file.Size, file.Width, file.Height, file.ContentType, destFolderName, destinationFolder.FolderID );

                                //Write the content to the Destination
                                WriteStream( file.FileId, sourceStream, strDestFile, destinationFolder.StorageLocation, true );

                                //Now we need to clean up the original files
                                if( sourceFolder.StorageLocation == (int)FolderController.StorageLocationTypes.InsecureFileSystem )
                                {
                                    //try and delete the Insecure file
                                    AttemptFileDeletion( strSourceFile );
                                }
                                if( sourceFolder.StorageLocation == (int)FolderController.StorageLocationTypes.SecureFileSystem )
                                {
                                    //try and delete the Secure file
                                    AttemptFileDeletion( strSourceFile + Globals.glbProtectedExtension );
                                }
                            }
                        }
                    }
                }
            }
            catch( Exception ex )
            {
                retValue = ex.Message;
            }

            return retValue;
        }
示例#26
0
        private string ExportModule( int ModuleID, string FileName )
        {
            string strMessage = "";

            ModuleController objModules = new ModuleController();
            ModuleInfo objModule = objModules.GetModule( ModuleID, TabId, false );
            if (objModule != null)
            {
                if (objModule.BusinessControllerClass != "" & objModule.IsPortable)
                {
                    try
                    {
                        object objObject = Reflection.CreateObject(objModule.BusinessControllerClass, objModule.BusinessControllerClass);

                        //Double-check
                        if (objObject is IPortable)
                        {

                            string Content = Convert.ToString(((IPortable)objObject).ExportModule(ModuleID));

                            if (Content != "")
                            {
                                // add attributes to XML document
                                Content = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" + "<content type=\"" + CleanName(objModule.FriendlyName) + "\" version=\"" + objModule.Version + "\">" + Content + "</content>";

                                //First check the Portal limits will not be exceeded (this is approximate)
                                PortalController objPortalController = new PortalController();
                                string strFile = PortalSettings.HomeDirectoryMapPath + FileName;
                                if (objPortalController.HasSpaceAvailable(PortalId, Content.Length))
                                {
                                    // save the file
                                    StreamWriter objStream = File.CreateText(strFile);
                                    objStream.WriteLine(Content);
                                    objStream.Close();

                                    // add file to Files table
                                    FileController objFiles = new FileController();
                                    FileInfo finfo = new FileInfo(strFile);
                                    FolderController objFolders = new FolderController();
                                    FolderInfo objFolder = objFolders.GetFolder(PortalId, "");
                                    Services.FileSystem.FileInfo objFile = objFiles.GetFile(lblFile.Text, PortalId, objFolder.FolderID);
                                    if (objFile == null)
                                    {
                                        objFiles.AddFile(PortalId, lblFile.Text, "xml", finfo.Length, 0, 0, "application/octet-stream", "", objFolder.FolderID, true);
                                    }
                                    else
                                    {
                                        objFiles.UpdateFile(objFile.FileId, objFile.FileName, "xml", finfo.Length, 0, 0, "application/octet-stream", "", objFolder.FolderID);
                                    }
                                }
                                else
                                {
                                    strMessage += "<br>" + string.Format(Localization.GetString("DiskSpaceExceeded"), strFile);
                                }
                            }
                            else
                            {
                                strMessage = Localization.GetString("NoContent", this.LocalResourceFile);
                            }
                        }
                        else
                        {
                            strMessage = Localization.GetString("ExportNotSupported", this.LocalResourceFile);
                        }
                    }
                    catch
                    {
                        strMessage = Localization.GetString("Error", this.LocalResourceFile);
                    }
                }
                else
                {
                    strMessage = Localization.GetString("ExportNotSupported", this.LocalResourceFile);
                }
            }

            return strMessage;
        }
示例#27
0
        public static void AddFile(string strFileName, string strExtension, string FolderPath, string strContentType, int Length, int imageWidth, int imageHeight)
        {
            // Obtain PortalSettings from Current Context
            PortalSettings portalSettings = PortalController.GetCurrentPortalSettings();
            int portalId = IsHostTab(portalSettings.ActiveTab.TabID) ? Null.NullInteger : portalSettings.PortalId;
            var objFiles = new FileController();
            var objFolders = new FolderController();
			FolderInfo objFolder = objFolders.GetFolder(portalId, FolderPath, false);
            if ((objFolder != null))
            {
				var objFile = new FileInfo(portalId, strFileName, strExtension, Length, imageWidth, imageHeight, strContentType, FolderPath, objFolder.FolderID, objFolder.StorageLocation, true);
                objFiles.AddFile(objFile);
            }
        }
示例#28
0
        /// <summary>
        /// Serializes all Files
        /// </summary>
        /// <param name="xmlTemplate">Reference to XmlDocument context</param>
        /// <param name="nodeFiles">Node to add the serialized objects</param>
        /// <param name="objportal">Portal to serialize</param>
        /// <param name="folderPath">The folder containing the files</param>
        /// <param name="zipFile"></param>
        /// <remarks>
        /// The serialization uses the xml attributes defined in FileInfo class.
        /// </remarks>
        /// <history>
        /// 	[cnurse]	11/08/2004	Created
        ///     [cnurse]    05/20/2004  Extracted adding of file to zip to new FileSystemUtils method
        /// </history>
        
        public void SerializeFiles(XmlDocument xmlTemplate, XmlNode nodeFiles, PortalInfo objportal, string folderPath, ref ZipOutputStream zipFile)
        {            
            FolderController objFolders = new FolderController();
            FolderInfo objFolder = objFolders.GetFolder( objportal.PortalID, folderPath );
            ArrayList arrFiles = FileSystemUtils.GetFilesByFolder(objportal.PortalID, objFolder.FolderID);

            XmlSerializer xser = new XmlSerializer(typeof(FileInfo));

            foreach (FileInfo objFile in arrFiles)
            {
                // verify that the file exists on the file system
                string filePath = objportal.HomeDirectoryMapPath + folderPath + objFile.FileName;
                if (File.Exists(filePath))
                {
                    StringWriter sw = new StringWriter();
                    xser.Serialize(sw, objFile);

                    //Add node to template
                    XmlDocument xmlFile = new XmlDocument();
                    xmlFile.LoadXml(sw.GetStringBuilder().ToString());
                    XmlNode nodeFile = xmlFile.SelectSingleNode("file");
                    nodeFile.Attributes.Remove(nodeFile.Attributes["xmlns:xsd"]);
                    nodeFile.Attributes.Remove(nodeFile.Attributes["xmlns:xsi"]);
                    nodeFiles.AppendChild(xmlTemplate.ImportNode(nodeFile, true));

                    FileSystemUtils.AddToZip(ref zipFile, filePath, objFile.FileName, folderPath);

                }
            }
        }
示例#29
0
        /// <summary>
        /// Adds a Folder
        /// </summary>
        /// <param name="portalId">The Id of the Portal</param>
        /// <param name="relativePath">The relative path of the folder</param>
        /// <param name="storageLocation">The type of storage location</param>
        /// <history>
        ///     [cnurse]    04/26/2006  Created
        /// </history>
        private static int AddFolder( int portalId, string relativePath, int storageLocation )
        {
            FolderController objFolderController = new FolderController();
            bool isProtected = DefaultProtectedFolders( relativePath );
            int id = objFolderController.AddFolder( portalId, relativePath, storageLocation, isProtected, false );

            if( portalId != Null.NullInteger )
            {
                //Set Folder Permissions to inherit from parent
                SetFolderPermissions( portalId, id, relativePath );
            }

            return id;
        }
示例#30
0
 public static FolderInfo GetFolder( int PortalID, string FolderPath )
 {
     FolderController objFolderController = new FolderController();
     FolderInfo objFolder = objFolderController.GetFolder( PortalID, FolderPath );
     if( HostSettings.GetHostSetting( "EnableFileAutoSync" ) != "N" )
     {
         // synchronize files in folder
         if( objFolder != null )
         {
             SynchronizeFolder( objFolder.PortalID, objFolder.PhysicalPath, objFolder.FolderPath, false, true, false );
         }
     }
     return objFolder;
 }
示例#31
0
        /// <summary>
        /// Create a New Sub Folder
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void CreateFolder_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(this.tbFolderName.Text))
            {
                if (Utility.ValidatePath(this.tbFolderName.Text))
                {
                    this.tbFolderName.Text = Utility.CleanPath(this.tbFolderName.Text);
                }

                this.tbFolderName.Text = Utility.CleanPath(this.tbFolderName.Text);

                var newDirPath = Path.Combine(this.lblCurrentDir.Text, this.tbFolderName.Text);

                try
                {
                    string sFolder = newDirPath;

                    sFolder = sFolder.Substring(this._portalSettings.HomeDirectoryMapPath.Length).Replace("\\", "/");

                    FolderController folderController = new FolderController();

                    var storageLocation = (int)FolderController.StorageLocationTypes.InsecureFileSystem;

                    var currentStorageLocationType = this.GetStorageLocationType(this.lblCurrentDir.Text);

                    switch (currentStorageLocationType)
                    {
                        case FolderController.StorageLocationTypes.SecureFileSystem:
                            storageLocation = (int)FolderController.StorageLocationTypes.SecureFileSystem;
                            break;
                        case FolderController.StorageLocationTypes.DatabaseSecure:
                            storageLocation = (int)FolderController.StorageLocationTypes.DatabaseSecure;
                            break;
                    }

                    if (!Directory.Exists(newDirPath))
                    {
                        Directory.CreateDirectory(newDirPath);

                        var folderId = folderController.AddFolder(this._portalSettings.PortalId, sFolder, storageLocation, false, false);

                        this.SetFolderPermission(folderId);
                    }

                    this.lblCurrentDir.Text = string.Format("{0}\\", newDirPath);
                }
                catch (Exception exception)
                {
                    this.Response.Write("<script type=\"text/javascript\">");

                    var message =
                    exception.Message.Replace("'", string.Empty).Replace("\r\n", string.Empty).Replace(
                        "\n", string.Empty).Replace("\r", string.Empty);

                    this.Response.Write(string.Format("javascript:alert('{0}');", this.Context.Server.HtmlEncode(message)));

                    this.Response.Write("</script>");
                }
                finally
                {
                    this.FillFolderTree(this.StartingDir());

                    this.ShowFilesIn(newDirPath);

                    RadTreeNode tnNewFolder = this.FoldersTree.FindNodeByText(this.tbFolderName.Text);

                    if (tnNewFolder != null)
                    {
                        tnNewFolder.Selected = true;
                        tnNewFolder.ExpandParentNodes();
                    }
                }
            }

            this.panCreate.Visible = false;
        }
示例#32
0
        public static ArrayList GetFoldersByUser( int PortalID, bool IncludeSecure, bool IncludeDatabase, bool AllowAccess, string Permissions )
        {
            FolderController objFolderController = new FolderController();
            ArrayList arrFolders = new ArrayList();
            UserInfo user = UserController.GetCurrentUserInfo();
            if( user.IsSuperUser )
            {
                //Get all the folders for the Portal
                ArrayList tempFolders = objFolderController.GetFoldersByPortal( PortalID );
                foreach( FolderInfo folder in tempFolders )
                {
                    bool canAdd = true;
                    if( folder.StorageLocation == (int)FolderController.StorageLocationTypes.DatabaseSecure )
                    {
                        canAdd = IncludeDatabase;
                    }
                    else if( folder.StorageLocation == (int)FolderController.StorageLocationTypes.SecureFileSystem )
                    {
                        canAdd = IncludeSecure;
                    }
                    if( canAdd )
                    {
                        arrFolders.Add( folder );
                    }
                }
            }
            else
            {
                //Get the folders for the Portal for the curent User
                arrFolders = objFolderController.GetFoldersByUser( PortalID, user.UserID, IncludeSecure, IncludeDatabase, AllowAccess, Permissions );
            }

            return arrFolders;
        }
示例#33
0
        /// <summary>
        /// Deletes a file
        /// </summary>
        /// <param name="strSourceFile">The File to delete</param>
        /// <param name="settings">The Portal Settings for the Portal/Host Account</param>
        /// <param name="ClearCache"></param>
        public static string DeleteFile( string strSourceFile, PortalSettings settings, bool ClearCache )
        {
            string retValue = "";
            try
            {
                //try and delete the Insecure file
                AttemptFileDeletion( strSourceFile );

                //try and delete the Secure file
                AttemptFileDeletion( strSourceFile + Globals.glbProtectedExtension );

                string folderName = Globals.GetSubFolderPath( strSourceFile );
                string fileName = GetFileName( strSourceFile );
                int PortalId = GetFolderPortalId( settings );

                //Remove file from DataBase
                FileController objFileController = new FileController();
                FolderController objFolders = new FolderController();
                FolderInfo objFolder = objFolders.GetFolder( PortalId, folderName );
                objFileController.DeleteFile( PortalId, fileName, objFolder.FolderID, ClearCache );
            }
            catch( Exception ex )
            {
                retValue = ex.Message;
            }

            return retValue;
        }
示例#34
0
        /// <summary>
        /// Uploads a File
        /// </summary>
        /// <param name="file">
        /// The Uploaded File
        /// </param>
        /// <param name="command">
        /// The Upload Command Type
        /// </param>
        private void UploadFile(HttpPostedFile file, string command)
        {
            var fileName = Path.GetFileName(file.FileName).Trim();

            if (!string.IsNullOrEmpty(fileName))
            {
                // Replace dots in the name with underscores (only one dot can be there... security issue).
                fileName = Regex.Replace(fileName, @"\.(?![^.]*$)", "_", RegexOptions.None);

                // Check for Illegal Chars
                if (Utility.ValidateFileName(fileName))
                {
                    fileName = Utility.CleanFileName(fileName);
                }

                // Convert Unicode Chars
                fileName = Utility.ConvertUnicodeChars(fileName);
            }
            else
            {
                return;
            }

            if (fileName.Length > 220)
            {
                fileName = fileName.Substring(fileName.Length - 220);
            }

            string sExtension = Path.GetExtension(file.FileName);
            sExtension = sExtension.TrimStart('.');

            bool bAllowUpl = false;

            switch (command)
            {
                case "FlashUpload":
                    if (this.allowedFlashExt.Any(sAllowExt => sAllowExt.Equals(sExtension.ToLower())))
                    {
                        bAllowUpl = true;
                    }

                    break;
                case "ImageUpload":
                    if (this.allowedImageExt.Any(sAllowExt => sAllowExt.Equals(sExtension.ToLower())))
                    {
                        bAllowUpl = true;
                    }

                    break;
                case "FileUpload":
                    if (this.extensionWhiteList.Contains(sExtension.ToLower()))
                    {
                        bAllowUpl = true;
                    }

                    break;
            }

            if (bAllowUpl)
            {
                string sFileNameNoExt = Path.GetFileNameWithoutExtension(fileName);

                int iCounter = 0;

                string sUploadDir = this.StartingDir();

                if (!this.currentSettings.UploadDirId.Equals(-1) && !this.currentSettings.SubDirs)
                {
                    var uploadFolder = new FolderController().GetFolderInfo(this._portalSettings.PortalId, this.currentSettings.UploadDirId);

                    if (uploadFolder != null)
                    {
                        sUploadDir = uploadFolder.PhysicalPath;
                    }
                }

                string sFilePath = Path.Combine(sUploadDir, fileName);

                if (File.Exists(sFilePath))
                {
                    iCounter++;
                    fileName = string.Format("{0}_{1}{2}", sFileNameNoExt, iCounter, Path.GetExtension(file.FileName));

                    // oFile.SaveAs(Path.Combine(sUploadDir, sFileName));
                    FileSystemUtils.UploadFile(sUploadDir, file, fileName);
                }
                else
                {
                    FileSystemUtils.UploadFile(sUploadDir, file, fileName);
                }

                this.Response.Write("<script type=\"text/javascript\">");
                this.Response.Write(this.GetJsUploadCode(fileName, MapUrl(sUploadDir)));
                this.Response.Write("</script>");
            }
            else
            {
                var error2Script = string.Format(
                     "javascript:alert('{0}')", Localization.GetString("Error2.Text", this.ResXFile, this.LanguageCode));

                this.Page.ClientScript.RegisterStartupScript(this.GetType(), "errorScript", error2Script, true);

                this.Response.End();
            }
        }
示例#35
0
        /// <summary>
        /// Gets the user folder ("userfiles\[USERID]").
        /// </summary>
        /// <param name="startingDir">The Starting Directory.</param>
        /// <returns>Returns the user folder path</returns>
        private string GetUserFolder(string startingDir)
        {
            var userFolderPath = Path.Combine(startingDir, "userfiles");

            // Create "userfiles" folder if not exists
            if (!Directory.Exists(userFolderPath))
            {
                var folderStart = userFolderPath;

                folderStart =
                    folderStart.Substring(this._portalSettings.HomeDirectoryMapPath.Length).Replace(
                        "\\", "/");

                var folderId = new FolderController().AddFolder(this._portalSettings.PortalId, folderStart);

                Directory.CreateDirectory(userFolderPath);

                this.SetFolderPermission(folderId);
            }

            // Create user folder based on the user id
            userFolderPath = Path.Combine(
                userFolderPath,
                string.Format("{0}\\", UserController.GetCurrentUserInfo().UserID));

            if (!Directory.Exists(userFolderPath))
            {
                var folderStart = userFolderPath;

                folderStart =
                    folderStart.Substring(this._portalSettings.HomeDirectoryMapPath.Length).Replace(
                        "\\", "/");

                var folderId = new FolderController().AddFolder(this._portalSettings.PortalId, folderStart);

                Directory.CreateDirectory(userFolderPath);

                this.SetFolderPermission(folderId);

                this.SetUserFolderPermission(folderId, UserController.GetCurrentUserInfo());
            }
            else
            {
                var userFolderInfo = Utility.ConvertFilePathToFolderInfo(userFolderPath, this._portalSettings);

                // make sure the user has the correct permissions set
                this.SetUserFolderPermission(userFolderInfo.FolderID, UserController.GetCurrentUserInfo());
            }

            return userFolderPath;
        }
示例#36
0
 public static void RemoveOrphanedFolders( int PortalId )
 {
     bool blnInvalidateCache = false;
     FolderController objFolderController = new FolderController();
     ArrayList arrFolders = GetFolders( PortalId );
     foreach( FolderInfo objFolder in arrFolders )
     {
         if( objFolder.StorageLocation != (int)FolderController.StorageLocationTypes.DatabaseSecure )
         {
             if( Directory.Exists( objFolder.PhysicalPath ) == false )
             {
                 RemoveOrphanedFiles( objFolder, PortalId );
                 objFolderController.DeleteFolder( PortalId, objFolder.FolderPath );
                 blnInvalidateCache = true;
             }
         }
     }
     if( blnInvalidateCache )
     {
         DataCache.RemoveCache( "Folders:" + PortalId.ToString() );
     }
 }
示例#37
0
		protected void Save_OnClick(object sender, EventArgs e)
		{
			try
			{
				if (FolderList.Items.Count == 0)
				{
					return;
				}

				DotNetNuke.Entities.Portals.PortalSettings portalSettings = DotNetNuke.Entities.Portals.PortalSettings.Current;

				string fileContents = htmlText2.Text.Trim();
				string newFileName = FileName.Text;
				if (! (newFileName.EndsWith(".html")))
				{
					newFileName = newFileName + ".html";
				}

				string rootFolder = portalSettings.HomeDirectoryMapPath;
				string dbFolderPath = FolderList.SelectedValue;
				string virtualFolder = (string)(string)FileSystemValidation.ToVirtualPath(dbFolderPath);
				rootFolder = rootFolder + FolderList.SelectedValue;
				rootFolder = rootFolder.Replace("/", "\\");

				string errorMessage = string.Empty;
				FolderController folderCtrl = new FolderController();
				FolderInfo folder = folderCtrl.GetFolder(portalSettings.PortalId, dbFolderPath, false);

				if ((folder == null))
				{
					ShowSaveTemplateMessage(GetString("msgFolderDoesNotExist.Text"));
					return;
				}

				// Check file name is valid
				FileSystemValidation dnnValidator = new FileSystemValidation();
				errorMessage = dnnValidator.OnCreateFile(virtualFolder + newFileName, fileContents.Length);
				if (! (string.IsNullOrEmpty(errorMessage)))
				{
					ShowSaveTemplateMessage(errorMessage);
					return;
				}

				FileController fileCtrl = new FileController();
				DotNetNuke.Services.FileSystem.FileInfo existingFile = fileCtrl.GetFile(newFileName, portalSettings.PortalId, folder.FolderID);

				// error if file exists
				if (! Overwrite.Checked && existingFile != null)
				{
					ShowSaveTemplateMessage(GetString("msgFileExists.Text"));
					return;
				}

				FileInfo newFile = existingFile;
				if ((newFile == null))
				{
					newFile = new FileInfo();
				}

				newFile.FileName = newFileName;
				newFile.ContentType = "text/plain";
				newFile.Extension = "html";
				newFile.Size = fileContents.Length;
				newFile.FolderId = folder.FolderID;

				errorMessage = FileSystemUtils.CreateFileFromString(rootFolder, newFile.FileName, fileContents, newFile.ContentType, string.Empty, false);

				if (! (string.IsNullOrEmpty(errorMessage)))
				{
					ShowSaveTemplateMessage(errorMessage);
					return;
				}

				existingFile = fileCtrl.GetFile(newFileName, portalSettings.PortalId, folder.FolderID);
				if (newFile.FileId != existingFile.FileId)
				{
					newFile.FileId = existingFile.FileId;
				}

				if (newFile.FileId != Null.NullInteger)
				{
					fileCtrl.UpdateFile(newFile.FileId, newFile.FileName, newFile.Extension, newFile.Size, newFile.Width, newFile.Height, newFile.ContentType, folder.FolderPath, folder.FolderID);
				}
				else
				{
					fileCtrl.AddFile(portalSettings.PortalId, newFile.FileName, newFile.Extension, newFile.Size, newFile.Width, newFile.Height, newFile.ContentType, folder.FolderPath, folder.FolderID, true);
				}

				ShowSaveTemplateMessage(string.Empty);
			}
			catch (Exception ex)
			{
				DotNetNuke.Services.Exceptions.Exceptions.LogException(ex);
				throw ex;
			}
		}
示例#38
0
        /// <summary>
        /// Set Folder Permission
        /// </summary>
        /// <param name="folderId">The Folder Id.</param>
        private void SetFolderPermission(int folderId)
        {
            var folder = new FolderController().GetFolderInfo(this._portalSettings.PortalId, folderId);

            FileSystemUtils.SetFolderPermissions(this._portalSettings.PortalId, folderId, folder.FolderPath);
        }
示例#39
0
        /// <summary>
        /// Serializes all Folders including Permissions
        /// </summary>
        /// <param name="xmlTemplate">Reference to XmlDocument context</param>
        /// <param name="nodeFolders"></param>
        /// <param name="objportal">Portal to serialize</param>
        /// <param name="zipFile"></param>
        /// <remarks>
        /// The serialization uses the xml attributes defined in FolderInfo class.
        /// </remarks>
        /// <history>
        /// 	[cnurse]	11/08/2004	Created
        /// </history>        
        public void SerializeFolders( XmlDocument xmlTemplate, XmlNode nodeFolders, PortalInfo objportal, ref ZipOutputStream zipFile )
        {
            // Sync db and filesystem before exporting so all required files are found
            FileSystemUtils.Synchronize(objportal.PortalID, objportal.AdministratorRoleId, objportal.HomeDirectoryMapPath);

            FolderController objFolders = new FolderController();
            ArrayList arrFolders = objFolders.GetFoldersByPortal( objportal.PortalID );

            XmlSerializer xser = new XmlSerializer( typeof( FolderInfo ) );
            foreach( FolderInfo objFolder in arrFolders )
            {
                StringWriter sw = new StringWriter();
                xser.Serialize( sw, objFolder );

                XmlDocument xmlFolder = new XmlDocument();
                xmlFolder.LoadXml( sw.GetStringBuilder().ToString() );
                XmlNode nodeFolder = xmlFolder.SelectSingleNode( "folder" );
                nodeFolder.Attributes.Remove( nodeFolder.Attributes["xmlns:xsd"] );
                nodeFolder.Attributes.Remove( nodeFolder.Attributes["xmlns:xsi"] );

                //Serialize Folder Permissions
                XmlNode nodePermissions = xmlTemplate.CreateElement( "folderpermissions" );
                SerializeFolderPermissions( xmlTemplate, nodePermissions, objportal, objFolder.FolderPath );
                nodeFolder.AppendChild( xmlFolder.ImportNode( nodePermissions, true ) );

                // Serialize files
                XmlNode nodeFiles = xmlTemplate.CreateElement( "files" );
                SerializeFiles( xmlTemplate, nodeFiles, objportal, objFolder.FolderPath, ref zipFile );
                nodeFolder.AppendChild( xmlFolder.ImportNode( nodeFiles, true ) );

                nodeFolders.AppendChild( xmlTemplate.ImportNode( nodeFolder, true ) );
            }
        }
示例#40
0
        /// <summary>
        /// Set Folder Permission for the Current User
        /// </summary>
        /// <param name="folderId">The Folder Id.</param>
        /// <param name="currentUserInfo">The current user info.</param>
        private void SetUserFolderPermission(int folderId, UserInfo currentUserInfo)
        {
            var folder = new FolderController().GetFolderInfo(this._portalSettings.PortalId, folderId);

            if (FolderPermissionController.CanManageFolder(folder))
            {
                return;
            }

            foreach (
                var folderPermission in from PermissionInfo permission in PermissionController.GetPermissionsByFolder()
                                        where
                                            permission.PermissionKey.ToUpper() == "READ"
                                            || permission.PermissionKey.ToUpper() == "WRITE"
                                            || permission.PermissionKey.ToUpper() == "BROWSE"
                                        select
                                            new FolderPermissionInfo(permission)
                                                {
                                                    FolderID = folder.FolderID,
                                                    UserID = currentUserInfo.UserID,
                                                    RoleID = Null.NullInteger,
                                                    AllowAccess = true
                                                })
            {
                folder.FolderPermissions.Add(folderPermission);
            }

            FolderPermissionController.SaveFolderPermissions(folder);
        }
示例#41
0
 public static ArrayList GetFilesByFolder(int PortalId, string folderPath)
 {
     var objFolders = new FolderController();
     FolderInfo objFolder = objFolders.GetFolder(PortalId, folderPath, false);
     if (objFolder == null)
     {
         return null;
     }
     return GetFilesByFolder(PortalId, objFolder.FolderID);
 }
示例#42
0
        /// <summary>
        /// Get the Current Starting Directory
        /// </summary>
        /// <returns>
        /// Returns the Starting Directory.
        /// </returns>
        private string StartingDir()
        {
            var startingDir = this._portalSettings.HomeDirectoryMapPath;

            if (!this.currentSettings.BrowserRootDirId.Equals(-1))
            {
                var rootFolder = new FolderController().GetFolderInfo(this._portalSettings.PortalId, this.currentSettings.BrowserRootDirId);

                if (rootFolder != null)
                {
                    startingDir = rootFolder.PhysicalPath;
                }
            }

            if (Utility.IsInRoles(this._portalSettings.AdministratorRoleName, this._portalSettings))
            {
                return startingDir;
            }

            if (this.currentSettings.SubDirs)
            {
                startingDir = this.GetUserFolder(startingDir);
            }
            else
            {
                return startingDir;
            }

            if (!Directory.Exists(startingDir))
            {
                string sFolderStart = startingDir;

                sFolderStart =
                    sFolderStart.Substring(this._portalSettings.HomeDirectoryMapPath.Length).Replace(
                        "\\", "/");

                var folderId = new FolderController().AddFolder(this._portalSettings.PortalId, sFolderStart);

                Directory.CreateDirectory(startingDir);

                this.SetFolderPermission(folderId);
            }

            return startingDir;
        }