Example #1
0
        public IActionResult FileManager(string path)
        {
            string fullPath         = string.Empty;
            IHostingEnvironment env = HttpContext.RequestServices.GetService <IHostingEnvironment>();

            if (string.IsNullOrEmpty(path))
            {
                fullPath = env.GetStorageFolderFullPath();
            }
            else
            {
                Regex regex = new Regex(@"^((\w|-|_)+)(>(\w|-|_)+)*$");
                if (!regex.IsMatch(path))
                {
                    return(Redirect($"{HttpContext.Request.Path}?pageID={(int)AdminPanelPages.FileManager}"));
                }
                fullPath = env.GetStorageFolderFullPath() + path.Replace('>', '/').Insert(path.Length, "/");
            }
            // Проверяем можно ли зайти в текущую директорию
            if (!FileManagerManagementFunctions.HasAccessToFolder(fullPath, env))
            {
                return(Redirect($"{HttpContext.Request.Path}?pageID={(int)AdminPanelPages.FileManager}"));
            }
            // Получаем файлы и папки в текущей директории
            FileManagerObject[] fileManagerObjects = FileManagerManagementFunctions.GetFilesAndFolders(fullPath, env, out bool pathExists);
            if (!pathExists)
            {
                return(Redirect($"{HttpContext.Request.Path}?pageID={(int)AdminPanelPages.FileManager}"));
            }
            HttpContext.Items["pageID"] = AdminPanelPages.FileManager;

            // Получаем навигационную цепочку
            LinkedList <KeyValuePair <string, string> > breadcrumbs = new LinkedList <KeyValuePair <string, string> >();
            // Key - название; Value - путь
            StringBuilder pathBuilder = new StringBuilder();

            breadcrumbs.AddLast(new KeyValuePair <string, string>("/", string.Empty));
            if (!string.IsNullOrEmpty(path))
            {
                string[] subdirectories = path.Split('>');
                for (int i = 0; i < subdirectories.Length; ++i)
                {
                    pathBuilder.Clear();
                    for (int j = 0; j <= i; ++j)
                    {
                        pathBuilder.Append($"{subdirectories[j]}");
                        if (j != i)
                        {
                            pathBuilder.Append(">");
                        }
                    }
                    breadcrumbs.AddLast(new KeyValuePair <string, string>(subdirectories[i], pathBuilder.ToString()));
                }
            }
            HttpContext.Items["CurrentDirectoryBreadcrumbs"] = breadcrumbs;

            return(View("FileManager/Index", fileManagerObjects));
        }
Example #2
0
        public IActionResult EditScriptFile(string path)
        {
            Regex regex = new Regex(@"^((\w|-|_)+)(>(\w|-|_)+)*\.js$");

            if (!regex.IsMatch(path))
            {
                return(Redirect($"{HttpContext.Request.Path}?pageID={(int)AdminPanelPages.FileManager}"));
            }
            HttpContext.Items["PathToFile"] = path;
            IHostingEnvironment env = HttpContext.RequestServices.GetService <IHostingEnvironment>();

            HttpContext.Items["pageID"] = AdminPanelPages.EditScript;
            string scriptFileFullName = path.Substring(path.LastIndexOf('>') + 1);

            path = path.Substring(0, path.Length - scriptFileFullName.Length);
            if (!string.IsNullOrEmpty(path))
            {
                path = path.Replace('>', '/');
                if (!path[path.Length - 1].Equals('/'))
                {
                    path = path.Insert(path.Length, "/");
                }
            }
            path = $"{env.GetStorageFolderFullPath()}{path}";
            string pathToFile = path + scriptFileFullName;

            if (!System.IO.File.Exists(pathToFile) || !FileManagerManagementFunctions.HasAccessToFolder(path, env))
            {
                return(Redirect($"{HttpContext.Request.Path}?pageID={(int)AdminPanelPages.FileManager}"));
            }
            string     scriptFileContent = OtherFunctions.GetFileContent(pathToFile);
            StyleModel model             = new StyleModel {
                FileName = scriptFileFullName.Substring(0, scriptFileFullName.Length - 3), FileContent = scriptFileContent
            };

            return(View("FileManager/EditScriptFile", model));
        }