Esempio n. 1
0
        public FileExplorerResponse ReadData(string path, string filter)
        {
            FileExplorerResponse ReadResponse = new FileExplorerResponse();

            try
            {
                ReadResponse = FileExplorerOperations.ReadData(path, filter);
                string physicalPath = GetPath(path);
                ReadResponse.cwd.permission = GetPathPermission(path);
                if (!ReadResponse.cwd.permission.Read)
                {
                    DirectoryContent[] fileDetails = new DirectoryContent[0];
                    ReadResponse.files = fileDetails;
                    return(ReadResponse);
                }
                var items = ReadResponse.files.ToArray();
                for (int i = 0; i < items.Length; i++)
                {
                    items[i].permission = GetFilePermission(physicalPath, items[i].name, items[i].isFile);
                    if (items[i].isFile)
                    {
                        items[i].permission.EditContents = ReadResponse.cwd.permission.EditContents;
                        items[i].permission.Upload       = ReadResponse.cwd.permission.Upload;
                    }
                }
                ReadResponse.files = items;
                return(ReadResponse);
            }
            catch (Exception e)
            {
                ReadResponse.error = e.GetType().FullName + ", " + e.Message;
                return(ReadResponse);
            }
        }
Esempio n. 2
0
        public string CombineRelativePath(string path, string name)
        {
            string absolutePath = FileExplorerOperations.ToAbsolute(path);
            string fullPath     = FileExplorerOperations.CombinePaths(absolutePath, name);

            return(FileExplorerOperations.ToPhysicalPath(fullPath));
        }
Esempio n. 3
0
        public FileExplorerResponse Remove(string[] names, string path)
        {
            FileExplorerResponse DeleteResponse = new FileExplorerResponse();

            try
            {
                string physicalPath = GetPath(path);
                List <FileAccessRules> FilesPermission = new List <FileAccessRules>();
                for (int i = 0; i < names.Length; i++)
                {
                    FileAccessRules permission = GetFilePermission(physicalPath, names[i], IsFile(CombineRelativePath(path, names[i])));
                    if (!permission.Read || !permission.Edit)
                    {
                        throw new ArgumentException("'" + path + names[i] + "' is not accessible. Access is denied.");
                    }
                    FilesPermission.Add(permission);
                }
                DeleteResponse = FileExplorerOperations.Remove(names, path);
                var items = DeleteResponse.files.ToArray();
                for (int i = 0; i < items.Length; i++)
                {
                    items[i].permission = FilesPermission[i];
                }
                DeleteResponse.files = items;
                return(DeleteResponse);
            }
            catch (Exception e)
            {
                DeleteResponse.error = e.GetType().FullName + ", " + e.Message;
                return(DeleteResponse);
            }
        }
Esempio n. 4
0
 public void PerformJSONPAction()
 {
     if (HttpContext.Current.Request.Files.Count > 0)
     {
         FileExplorerOperations.Upload(HttpContext.Current.Request.Files, HttpContext.Current.Request.QueryString.GetValues("Path")[0]);
     }
 }
Esempio n. 5
0
        public FileExplorerResponse Paste(string sourceDir, string backupDir, string[] names, string option, IEnumerable <CommonFileDetails> commonFiles)
        {
            FileExplorerResponse PasteResponse = new FileExplorerResponse();

            try
            {
                string phyPath = GetPath(sourceDir);
                for (int i = 0; i < names.Length; i++)
                {
                    FileAccessRules FilePermission = GetFilePermission(phyPath, names[i], IsFile(CombineRelativePath(sourceDir, names[i])));
                    if (!FilePermission.Read || !FilePermission.Copy)
                    {
                        throw new ArgumentException("'" + sourceDir + names[i] + "' is not accessible. Access is denied.");
                    }
                }
                FileAccessRules PathPermission = GetPathPermission(backupDir);
                if (!PathPermission.Read || !PathPermission.EditContents)
                {
                    throw new ArgumentException("'" + backupDir + "' is not accessible. Access is denied.");
                }
                PasteResponse       = FileExplorerOperations.Paste(sourceDir, backupDir, names, option, commonFiles);
                PasteResponse.files = SetPermission(backupDir, PasteResponse.files);
                return(PasteResponse);
            }
            catch (Exception e)
            {
                PasteResponse.error = e.GetType().FullName + ", " + e.Message;
                return(PasteResponse);
            }
        }
Esempio n. 6
0
 public HttpResponseMessage Upload()
 {
     FileExplorerOperations.Upload(HttpContext.Current.Request.Files, HttpContext.Current.Request.QueryString.GetValues("Path")[0]);
     return(new HttpResponseMessage()
     {
         Content = new StringContent("ok", Encoding.UTF8, "text/plain")
     });
 }
Esempio n. 7
0
        public void Upload(HttpFileCollection files, string path)
        {
            FileAccessRules PathPermission = GetPathPermission(path);

            if (!PathPermission.Read || !PathPermission.Upload)
            {
                throw new ArgumentNullException("'" + path + "' is not accessible. Access is denied.");
            }
            FileExplorerOperations.Upload(files, path);
        }
Esempio n. 8
0
        public object doJSONPAction(string callback, string json)
        {
            object             Data       = null;
            var                serializer = new JavaScriptSerializer();
            FileExplorerParams args       = (FileExplorerParams)serializer.Deserialize(json, typeof(FileExplorerParams));

            try
            {
                if (args.ActionType != "Paste" && args.ActionType != "GetDetails")
                {
                    string FilePath = FileExplorerOperations.ToPhysicalPath(FileExplorerOperations.ToAbsolute(args.Path));
                }
                FileOperationController Rule      = new FileOperationController();
                FileAccessOperations    operation = new FileAccessOperations(Rule.GetRules());
                switch (args.ActionType)
                {
                case "Read":
                    Data = operation.ReadData(args.Path, args.ExtensionsAllow);
                    break;

                case "Search":
                    Data = operation.Search(args.Path, args.ExtensionsAllow, args.SearchString, args.CaseSensitive);
                    break;

                case "CreateFolder":
                    Data = operation.NewFolder(args.Path, args.Name);
                    break;

                case "Paste":
                    Data = operation.Paste(args.LocationFrom, args.LocationTo, args.Names, args.Action, args.CommonFiles);
                    break;

                case "Remove":
                    Data = operation.Remove(args.Names, args.Path);
                    break;

                case "Rename":
                    Data = operation.Rename(args.Path, args.Name, args.NewName, args.CommonFiles);
                    break;

                case "GetDetails":
                    Data = operation.GetDetails(args.Path, args.Names);
                    break;
                }
                HttpContext.Current.Response.Write(string.Format("{0}({1});", callback, serializer.Serialize(Data)));
                return("");
            }
            catch (Exception e)
            {
                FileExplorerResponse Response = new FileExplorerResponse();
                Response.error = e.GetType().FullName + ", " + e.Message;
                HttpContext.Current.Response.Write(string.Format("{0}({1});", callback, serializer.Serialize(Response)));
                return("");
            }
        }
Esempio n. 9
0
 public void PerformAction(string ActionType, string Path)
 {
     if (ActionType == "Download")
     {
         FileExplorerOperations.Download(Path, HttpContext.Current.Request.QueryString.GetValues("Names"));
     }
     else if (ActionType == "GetImage")
     {
         FileExplorerOperations.GetImage(Path);
     }
 }
Esempio n. 10
0
 public void Download(string Path)
 {
     if (HttpContext.Current.Request.QueryString.GetValues("Names") != null)
     {
         FileExplorerOperations.Download(Path, HttpContext.Current.Request.QueryString.GetValues("Names"));
     }
     else
     {
         FileExplorerOperations.Download(Path);
     }
 }
Esempio n. 11
0
        public object doJSONAction()
        {
            FileExplorerParams args = FileExplorerOperations.GetAjaxData(Request);

            if (args.ActionType == "Upload")
            {
                FileExplorerOperations.Upload(args.Files, args.Path);
                return(new HttpResponseMessage()
                {
                    Content = new StringContent("ok", Encoding.UTF8, "text/plain")
                });
            }
            try
            {
                if (args.ActionType != "Paste" && args.ActionType != "GetDetails")
                {
                    var FilePath = FileExplorerOperations.ToPhysicalPath(FileExplorerOperations.ToAbsolute(args.Path));
                }
                FileOperationController Rule      = new FileOperationController();
                FileAccessOperations    operation = new FileAccessOperations(Rule.GetRules());
                switch (args.ActionType)
                {
                case "Read":
                    return(operation.ReadData(args.Path, args.ExtensionsAllow));

                case "Search":
                    return(operation.Search(args.Path, args.ExtensionsAllow, args.SearchString, args.CaseSensitive));

                case "CreateFolder":
                    return(operation.NewFolder(args.Path, args.Name));

                case "Paste":
                    return(operation.Paste(args.LocationFrom, args.LocationTo, args.Names, args.Action, args.CommonFiles));

                case "Remove":
                    return(operation.Remove(args.Names, args.Path));

                case "Rename":
                    return(operation.Rename(args.Path, args.Name, args.NewName, args.CommonFiles));

                case "GetDetails":
                    return(operation.GetDetails(args.Path, args.Names));
                }
                return("");
            }
            catch (Exception e) {
                FileExplorerResponse Response = new FileExplorerResponse();
                Response.error = e.GetType().FullName + ", " + e.Message;
                return(Response);
            }
        }
Esempio n. 12
0
        public void Download(string path, string[] names)
        {
            string physicalPath = GetPath(path);

            for (int i = 0; i < names.Length; i++)
            {
                FileAccessRules FilePermission = GetFilePermission(physicalPath, names[i], true);
                if (!FilePermission.Read || !FilePermission.Download)
                {
                    throw new ArgumentNullException("'" + path + names[i] + "' is not accessible. Access is denied.");
                }
            }
            FileExplorerOperations.Download(path, names);
        }
Esempio n. 13
0
        public FileExplorerResponse NewFolder(string path, string name)
        {
            FileExplorerResponse CreateResponse = new FileExplorerResponse();

            try
            {
                FileAccessRules PathPermission = GetPathPermission(path);
                if (!PathPermission.Read || !PathPermission.EditContents)
                {
                    throw new ArgumentException("'" + path + "' is not accessible. Access is denied.");
                }
                CreateResponse       = FileExplorerOperations.NewFolder(path, name);
                CreateResponse.files = SetPermission(path, CreateResponse.files);
                return(CreateResponse);
            }
            catch (Exception e)
            {
                CreateResponse.error = e.GetType().FullName + ", " + e.Message;
                return(CreateResponse);
            }
        }
Esempio n. 14
0
        public FileExplorerResponse Rename(string path, string oldName, string newName, IEnumerable <CommonFileDetails> commonFiles)
        {
            FileExplorerResponse RenameResponse = new FileExplorerResponse();

            try
            {
                FileAccessRules FilePermission = GetFilePermission(GetPath(path), oldName, IsFile(CombineRelativePath(path, oldName)));
                if (!FilePermission.Read || !FilePermission.Edit)
                {
                    throw new ArgumentException("'" + path + oldName + "' is not accessible. Access is denied.");
                }
                RenameResponse       = FileExplorerOperations.Rename(path, oldName, newName, commonFiles);
                RenameResponse.files = SetPermission(path, RenameResponse.files);
                return(RenameResponse);
            }
            catch (Exception e)
            {
                RenameResponse.error = e.GetType().FullName + ", " + e.Message;
                return(RenameResponse);
            }
        }
Esempio n. 15
0
        public FileExplorerResponse Search(string path, string filter, string searchString, bool caseSensitive)
        {
            FileExplorerResponse SearchResponse = new FileExplorerResponse();

            try
            {
                string          physicalPath   = GetPath(path);
                FileAccessRules RootPermission = GetPathPermission(path);
                if (!RootPermission.Read)
                {
                    throw new ArgumentException("'" + path + "' is not accessible. Access is denied.");
                }
                SearchResponse = FileExplorerOperations.Search(path, filter, searchString, caseSensitive);
                var items = SearchResponse.files.ToArray();
                for (int i = 0; i < items.Length; i++)
                {
                    FileAccessRules PathPermission = GetPathPermission(path + items[i].filterPath.Replace("\\", "/"));
                    if (!PathPermission.Read)
                    {
                        items = items.Where((val, idx) => idx != i).ToArray();
                        i--;
                        continue;
                    }
                    items[i].permission = GetFilePermission(physicalPath + items[i].filterPath, items[i].name, items[i].isFile);
                    if (items[i].isFile)
                    {
                        items[i].permission.EditContents = PathPermission.EditContents;
                        items[i].permission.Upload       = PathPermission.Upload;
                    }
                }
                SearchResponse.files = items;
                return(SearchResponse);
            }
            catch (Exception e)
            {
                SearchResponse.error = e.GetType().FullName + ", " + e.Message;
                return(SearchResponse);
            }
        }
Esempio n. 16
0
        public FileExplorerResponse GetDetails(string path, string[] names)
        {
            FileExplorerResponse DetailsResponse = new FileExplorerResponse();

            try
            {
                DetailsResponse = FileExplorerOperations.GetDetails(path, names);
                string physicalPath = GetPath(path);
                var    items        = DetailsResponse.details.ToArray();
                for (int i = 0; i < items.Length; i++)
                {
                    items[i].Permission = GetFilePermission(physicalPath, items[i].Name, items[i].Type != "File Folder");
                }
                DetailsResponse.details = items;
                return(DetailsResponse);
            }
            catch (Exception e)
            {
                DetailsResponse.error = e.GetType().FullName + ", " + e.Message;
                return(DetailsResponse);
            }
        }
Esempio n. 17
0
 public string GetPath(string path)
 {
     return(FileExplorerOperations.ToPhysicalPath(FileExplorerOperations.ToAbsolute(path)));
 }