Exemplo n.º 1
0
        public override string DeleteFile(string path)
        {
            try
            {
                string virtualPathAndFile = FileSystemValidation.ToVirtualPath(path);

                string returnValue = DNNValidator.OnDeleteFile(virtualPathAndFile);
                if (!(string.IsNullOrEmpty(returnValue)))
                {
                    return(returnValue);
                }

                returnValue = TelerikContent.DeleteFile(virtualPathAndFile);

                if (string.IsNullOrEmpty(returnValue))
                {
                    string     virtualPath = FileSystemValidation.RemoveFileName(virtualPathAndFile);
                    FolderInfo dnnFolder   = DNNValidator.GetUserFolder(virtualPath);
                    DNNFileCtrl.DeleteFile(PortalSettings.PortalId, Path.GetFileName(virtualPathAndFile), dnnFolder.FolderID, true);
                }

                return(returnValue);
            }
            catch (Exception ex)
            {
                return(DNNValidator.LogUnknownError(ex, path));
            }
        }
Exemplo n.º 2
0
        public override string CopyFile(string path, string newPath)
        {
            try
            {
                string virtualPathAndFile    = FileSystemValidation.ToVirtualPath(path);
                string virtualNewPathAndFile = FileSystemValidation.ToVirtualPath(newPath);

                string returnValue = DNNValidator.OnCopyFile(virtualPathAndFile, virtualNewPathAndFile);
                if (!(string.IsNullOrEmpty(returnValue)))
                {
                    return(returnValue);
                }

                //Returns errors or empty string when successful (ie: NewFileAlreadyExists)
                returnValue = TelerikContent.CopyFile(virtualPathAndFile, virtualNewPathAndFile);

                if (string.IsNullOrEmpty(returnValue))
                {
                    string     virtualNewPath = FileSystemValidation.RemoveFileName(virtualNewPathAndFile);
                    FolderInfo dnnFolder      = DNNValidator.GetUserFolder(virtualNewPath);
                    var        dnnFileInfo    = new Services.FileSystem.FileInfo();
                    FillFileInfo(virtualNewPathAndFile, ref dnnFileInfo);

                    DNNFileCtrl.AddFile(PortalSettings.PortalId, dnnFileInfo.FileName, dnnFileInfo.Extension, dnnFileInfo.Size, dnnFileInfo.Width, dnnFileInfo.Height, dnnFileInfo.ContentType, dnnFolder.FolderPath, dnnFolder.FolderID, true);
                }

                return(returnValue);
            }
            catch (Exception ex)
            {
                return(DNNValidator.LogUnknownError(ex, path, newPath));
            }
        }
        public override string DeleteDirectory(string path)
        {
            try
            {
                string virtualPath = FileSystemValidation.ToVirtualPath(path);

                string returnValue = DNNValidator.OnDeleteFolder(virtualPath);
                if (!(string.IsNullOrEmpty(returnValue)))
                {
                    return(returnValue);
                }

                //Are all items visible to user?
                FolderInfo folder = DNNValidator.GetUserFolder(virtualPath);
                if (!CheckAllChildrenVisible(ref folder))
                {
                    return(DNNValidator.LogDetailError(ErrorCodes.CannotDeleteFolder_ChildrenVisible));
                }

                returnValue = TelerikContent.DeleteDirectory(virtualPath);

                if (string.IsNullOrEmpty(returnValue))
                {
                    FolderManager.Instance.DeleteFolder(folder);
                }

                return(returnValue);
            }
            catch (Exception ex)
            {
                return(DNNValidator.LogUnknownError(ex, path));
            }
        }
        public override string MoveDirectory(string path, string newPath)
        {
            try
            {
                string virtualPath            = (string)(string)FileSystemValidation.ToVirtualPath(path);
                string virtualNewPath         = (string)(string)FileSystemValidation.ToVirtualPath(newPath);
                string virtualDestinationPath = FileSystemValidation.GetDestinationFolder(virtualNewPath);

                string returnValue = string.Empty;
                if (FileSystemValidation.GetDestinationFolder(virtualPath) == virtualDestinationPath)
                {
                    //rename directory
                    returnValue = DNNValidator.OnRenameFolder(virtualPath);
                    if (!(string.IsNullOrEmpty(returnValue)))
                    {
                        return(returnValue);
                    }
                }
                else
                {
                    //move directory
                    returnValue = DNNValidator.OnMoveFolder(virtualPath, virtualDestinationPath);
                    if (!(string.IsNullOrEmpty(returnValue)))
                    {
                        return(returnValue);
                    }
                }

                //Are all items visible to user?
                FolderInfo folder = DNNValidator.GetUserFolder(virtualPath);
                if (!(CheckAllChildrenVisible(ref folder)))
                {
                    return(DNNValidator.LogDetailError(ErrorCodes.CannotMoveFolder_ChildrenVisible));
                }

                //Returns errors or empty string when successful (ie: Cannot create a file when that file already exists)
                returnValue = TelerikContent.MoveDirectory(virtualPath, virtualNewPath);

                if (string.IsNullOrEmpty(returnValue))
                {
                    //make sure folder name is being updated in database
                    DNNValidator.OnFolderRenamed(virtualPath, virtualNewPath);
                    //Sync to remove old folder & files
                    FileSystemUtils.SynchronizeFolder(PortalSettings.PortalId, HttpContext.Current.Request.MapPath(virtualPath), FileSystemValidation.ToDBPath(virtualPath), true, true, true);
                    //Sync to add new folder & files
                    FileSystemUtils.SynchronizeFolder(PortalSettings.PortalId, HttpContext.Current.Request.MapPath(virtualNewPath), FileSystemValidation.ToDBPath(virtualNewPath), true, true, true);
                }

                return(returnValue);
            }
            catch (Exception ex)
            {
                return(DNNValidator.LogUnknownError(ex, path, newPath));
            }
        }
Exemplo n.º 5
0
        private DirectoryItem GetDirectoryItemWithDNNPermissions(string path)
        {
            var radDirectory = TelerikContent.ResolveDirectory(FileSystemValidation.ToVirtualPath(path));

            if (radDirectory.FullPath == PortalSettings.HomeDirectory)
            {
                radDirectory.Name = DNNValidator.GetString("Root");
            }
            Logger.DebugFormat("GetDirectoryItemWithDNNPermissions - path: {0}, radDirectory: {1}", path, radDirectory);
            //var directoryArray = new[] {radDirectory};
            return(AddChildDirectoriesToList(radDirectory));
        }
        private DirectoryItem GetDirectoryItemWithDNNPermissions(string path, bool loadFiles)
        {
            var radDirectory   = TelerikContent.ResolveDirectory(FileSystemValidation.ToVirtualPath(path));
            var directoryArray = new[] { radDirectory };
            var returnValues   = AddChildDirectoriesToList(ref directoryArray, true, loadFiles);

            if (returnValues != null && returnValues.Length > 0)
            {
                return(returnValues[0]);
            }

            return(null);
        }
Exemplo n.º 7
0
        private DirectoryItem AddChildDirectoriesToList(DirectoryItem radDirectory)
        {
            var parentFolderPath = radDirectory.FullPath.EndsWith("/") ? radDirectory.FullPath : radDirectory.FullPath + "/";

            if (parentFolderPath.StartsWith(PortalSettings.HomeDirectory))
            {
                parentFolderPath = parentFolderPath.Remove(0, PortalSettings.HomeDirectory.Length);
            }

            var dnnParentFolder = FolderManager.Instance.GetFolder(PortalSettings.PortalId, parentFolderPath);

            if (!DNNValidator.CanViewFilesInFolder(dnnParentFolder.FolderPath))
            {
                return(null);
            }

            var dnnChildFolders = FolderManager.Instance.GetFolders(dnnParentFolder).Where(folder => (FileSystemValidation.HasPermission(folder, "BROWSE,READ")));
            var radDirectories  = new List <DirectoryItem>();

            foreach (var dnnChildFolder in dnnChildFolders)
            {
                if (!dnnChildFolder.FolderPath.ToLowerInvariant().StartsWith("cache/") &&
                    !dnnChildFolder.FolderPath.ToLowerInvariant().StartsWith("users/") &&
                    !dnnChildFolder.FolderPath.ToLowerInvariant().StartsWith("groups/"))
                {
                    var radSubDirectory =
                        TelerikContent.ResolveDirectory(FileSystemValidation.ToVirtualPath(dnnChildFolder.FolderPath));
                    radSubDirectory.Permissions = FileSystemValidation.TelerikPermissions(dnnChildFolder);
                    radDirectories.Add(radSubDirectory);
                }
            }

            radDirectory.Files = IncludeFilesForCurrentFolder(dnnParentFolder);

            if (parentFolderPath == "")
            {
                var userFolder = FolderManager.Instance.GetUserFolder(PortalSettings.UserInfo);
                if (userFolder.PortalID == PortalSettings.PortalId)
                {
                    var radUserFolder = TelerikContent.ResolveDirectory(FileSystemValidation.ToVirtualPath(userFolder.FolderPath));
                    radUserFolder.Name        = DNNValidator.GetString("MyFolder");
                    radUserFolder.Permissions = FileSystemValidation.TelerikPermissions(userFolder);
                    radDirectories.Add(radUserFolder);
                }
            }

            radDirectory.Directories = radDirectories.ToArray();
            return(radDirectory);
        }
Exemplo n.º 8
0
        public override string StoreBitmap(System.Drawing.Bitmap bitmap, string url, System.Drawing.Imaging.ImageFormat format)
        {
            try
            {
                //base calls CheckWritePermissions method
                string virtualPathAndFile = FileSystemValidation.ToVirtualPath(url);
                string virtualPath        = FileSystemValidation.RemoveFileName(virtualPathAndFile);
                string returnValue        = DNNValidator.OnCreateFile(virtualPathAndFile, 0);
                if (!(string.IsNullOrEmpty(returnValue)))
                {
                    return(returnValue);
                }

                returnValue = TelerikContent.StoreBitmap(bitmap, virtualPathAndFile, format);

                var dnnFileInfo = new Services.FileSystem.FileInfo();
                FillFileInfo(virtualPathAndFile, ref dnnFileInfo);

                //check again with real contentLength
                string errMsg = DNNValidator.OnCreateFile(virtualPathAndFile, dnnFileInfo.Size);
                if (!(string.IsNullOrEmpty(errMsg)))
                {
                    TelerikContent.DeleteFile(virtualPathAndFile);
                    return(errMsg);
                }

                FolderInfo dnnFolder = DNNValidator.GetUserFolder(virtualPath);
                Services.FileSystem.FileInfo dnnFile = DNNFileCtrl.GetFile(dnnFileInfo.FileName, PortalSettings.PortalId, dnnFolder.FolderID);

                if (dnnFile != null)
                {
                    DNNFileCtrl.UpdateFile(dnnFile.FileId, dnnFileInfo.FileName, dnnFileInfo.Extension, dnnFileInfo.Size, bitmap.Width, bitmap.Height, dnnFileInfo.ContentType, dnnFolder.FolderPath, dnnFolder.FolderID);
                }
                else
                {
                    DNNFileCtrl.AddFile(PortalSettings.PortalId, dnnFileInfo.FileName, dnnFileInfo.Extension, dnnFileInfo.Size, bitmap.Width, bitmap.Height, dnnFileInfo.ContentType, dnnFolder.FolderPath, dnnFolder.FolderID, true);
                }

                return(returnValue);
            }
            catch (Exception ex)
            {
                return(DNNValidator.LogUnknownError(ex, url));
            }
        }
Exemplo n.º 9
0
        public override string CreateDirectory(string path, string name)
        {
            try
            {
                var directoryName = name.Trim();
                var virtualPath   = FileSystemValidation.ToVirtualPath(path);

                var returnValue = DNNValidator.OnCreateFolder(virtualPath, directoryName);
                if (!(string.IsNullOrEmpty(returnValue)))
                {
                    return(returnValue);
                }

                //Returns errors or empty string when successful (ie: DirectoryAlreadyExists, InvalidCharactersInPath)
                returnValue = TelerikContent.CreateDirectory(virtualPath, directoryName);

                if (!(string.IsNullOrEmpty(returnValue)))
                {
                    return(GetTelerikMessage(returnValue));
                }

                if (string.IsNullOrEmpty(returnValue))
                {
                    var virtualNewPath = FileSystemValidation.CombineVirtualPath(virtualPath, directoryName);
                    var newFolderID    = DNNFolderCtrl.AddFolder(PortalSettings.PortalId, FileSystemValidation.ToDBPath(virtualNewPath));
                    FileSystemUtils.SetFolderPermissions(PortalSettings.PortalId, newFolderID, FileSystemValidation.ToDBPath(virtualNewPath));
                    //make sure that the folder is flagged secure if necessary
                    DNNValidator.OnFolderCreated(virtualNewPath, virtualPath);
                }

                return(returnValue);
            }
            catch (Exception ex)
            {
                return(DNNValidator.LogUnknownError(ex, path, name));
            }
        }
Exemplo n.º 10
0
        public override string CopyDirectory(string path, string newPath)
        {
            try
            {
                string virtualPath            = FileSystemValidation.ToVirtualPath(path);
                string virtualNewPath         = FileSystemValidation.ToVirtualPath(newPath);
                string virtualDestinationPath = FileSystemValidation.GetDestinationFolder(virtualNewPath);

                string returnValue = DNNValidator.OnCopyFolder(virtualPath, virtualDestinationPath);
                if (!(string.IsNullOrEmpty(returnValue)))
                {
                    return(returnValue);
                }

                //Are all items visible to user?
                //todo: copy visible files and folders only?
                FolderInfo folder = DNNValidator.GetUserFolder(virtualPath);
                if (!(CheckAllChildrenVisible(ref folder)))
                {
                    return(DNNValidator.LogDetailError(ErrorCodes.CannotCopyFolder_ChildrenVisible));
                }

                returnValue = TelerikContent.CopyDirectory(virtualPath, virtualNewPath);

                if (string.IsNullOrEmpty(returnValue))
                {
                    //Sync to add new folder & files
                    FileSystemUtils.SynchronizeFolder(PortalSettings.PortalId, HttpContext.Current.Request.MapPath(virtualNewPath), FileSystemValidation.ToDBPath(virtualNewPath), true, true, true);
                }

                return(returnValue);
            }
            catch (Exception ex)
            {
                return(DNNValidator.LogUnknownError(ex, path, newPath));
            }
        }
Exemplo n.º 11
0
 public override string GetFileName(string url)
 {
     return(TelerikContent.GetFileName(FileSystemValidation.ToVirtualPath(url)));
 }
        private DirectoryItem[] AddChildDirectoriesToList(ref DirectoryItem[] radDirectories, bool recursive, bool loadFiles)
        {
            var newDirectories = new ArrayList();
            var invalidFolders = new List <DirectoryItem>();

            foreach (var radDirectory in radDirectories)
            {
                System.Diagnostics.Debug.WriteLine(DateTime.Now.ToLongTimeString() + " AddChildDirectoriesToList " + radDirectory.Name);

                var endUserPath = (string)FileSystemValidation.ToEndUserPath(radDirectory.FullPath);

                var folderPath = radDirectory.FullPath.EndsWith("/") ? radDirectory.FullPath : radDirectory.FullPath + "/";

                var dnnFolder = DNNValidator.GetUserFolder(folderPath);

                if (dnnFolder == null)
                {
                    invalidFolders.Add(radDirectory);
                    continue;
                }

                //Don't show protected folders
                if (!string.IsNullOrEmpty(dnnFolder.FolderPath) && dnnFolder.IsProtected)
                {
                    invalidFolders.Add(radDirectory);
                    continue;
                }

                //Don't show Cache folder
                if (dnnFolder.FolderPath.ToLowerInvariant() == "cache/")
                {
                    invalidFolders.Add(radDirectory);
                    continue;
                }

                var showFiles         = new ArrayList();
                var folderPermissions = PathPermissions.Read;

                if (DNNValidator.CanViewFilesInFolder(dnnFolder))
                {
                    if (DNNValidator.CanAddToFolder(dnnFolder))
                    {
                        folderPermissions = folderPermissions | PathPermissions.Upload;
                    }

                    if (DNNValidator.CanDeleteFolder(dnnFolder))
                    {
                        folderPermissions = folderPermissions | PathPermissions.Delete;
                    }

                    if (loadFiles)
                    {
                        var files = FolderManager.Instance.GetFiles(dnnFolder);
                        foreach (var fileInfo in files)
                        {
                            showFiles.Add(new FileItem(fileInfo.FileName, fileInfo.Extension, fileInfo.Size, "", GetFileUrl(fileInfo), "", folderPermissions));
                        }
                    }

                    var folderFiles = (FileItem[])showFiles.ToArray(typeof(FileItem));

                    //Root folder name
                    var dirName = radDirectory.Name;
                    if (dnnFolder.FolderPath == "" && dnnFolder.FolderName == "")
                    {
                        dirName = FileSystemValidation.EndUserHomeDirectory;
                    }

                    DirectoryItem newDirectory;
                    if (recursive)
                    {
                        var directory = TelerikContent.ResolveRootDirectoryAsTree(radDirectory.Path);
                        var tempVar2  = directory.Directories;
                        if (dnnFolder.FolderPath == "" && dnnFolder.FolderName == "") //Replace USERS folder by the particular User Folder
                        {
                            AddUserFolder(ref tempVar2, loadFiles);
                        }
                        AddChildDirectoriesToList(ref tempVar2, false, false);
                        newDirectory             = new DirectoryItem(dirName, "", endUserPath, "", folderPermissions, folderFiles, tempVar2);
                        radDirectory.Directories = tempVar2;
                    }
                    else
                    {
                        newDirectory = new DirectoryItem(dirName, "", endUserPath, "", folderPermissions, folderFiles, new DirectoryItem[0]);
                    }

                    newDirectories.Add(newDirectory);
                }
                else
                {
                    invalidFolders.Add(radDirectory);
                }
            }
            //remove invalid folders
            radDirectories = radDirectories.Where(d => !invalidFolders.Contains(d)).ToArray();

            return((DirectoryItem[])newDirectories.ToArray(typeof(DirectoryItem)));
        }