示例#1
0
        private ResultSet DeleteFiles(ManagerEngine man, Hashtable input)
        {
            ResultSet     rs = new ResultSet(new string[] { "status", "file", "message" });
            ManagerConfig config;
            IFile         file;

            for (int i = 0; input["path" + i] != null; i++)
            {
                file   = man.GetFile(man.DecryptPath((string)input["path" + i]));
                config = file.Config;

                if (!man.IsToolEnabled("delete", config))
                {
                    throw new ManagerException("{#error.no_access}");
                }

                // File exists
                if (!file.Exists)
                {
                    rs.Add("FAILED", man.EncryptPath(file.AbsolutePath), "{#error.file_not_exists}");
                    continue;
                }

                if (config.GetBool("general.demo", false))
                {
                    rs.Add("FAILED", man.EncryptPath(file.AbsolutePath), "{#error.demo}");
                    continue;
                }

                if (!man.VerifyFile(file, "delete"))
                {
                    rs.Add("FAILED", man.EncryptPath(file.AbsolutePath), man.InvalidFileMsg);
                    continue;
                }

                if (!file.CanWrite)
                {
                    rs.Add("FAILED", man.EncryptPath(file.AbsolutePath), "{#error.no_write_access}");
                    continue;
                }

                if (!config.GetBool("filesystem.writable", true))
                {
                    rs.Add("FAILED", man.EncryptPath(file.AbsolutePath), "{#error.no_write_access}");
                    continue;
                }

                if (file.Delete(config.GetBool("filesystem.delete_recursive", true)))
                {
                    rs.Add("OK", man.EncryptPath(file.AbsolutePath), "{#message.delete_success}");
                }
                else
                {
                    rs.Add("FAILED", man.EncryptPath(file.AbsolutePath), "{#error.delete_failed}");
                }
            }

            return(rs);
        }
示例#2
0
        private ResultSet SaveImage(ManagerEngine man, Hashtable input)
        {
            ResultSet rs = new ResultSet(new string[]{"status", "file", "message"});
            IFile file, targetFile;
            ManagerConfig config;

            file = man.GetFile(man.DecryptPath((string) input["path"]));
            config = file.Config;

            if (!man.IsToolEnabled("edit", config))
                throw new ManagerException("{#error.no_access}");

            if (config.GetBool("general.demo", false)) {
                rs.Add("FAILED", man.EncryptPath(file.AbsolutePath), "{#error.demo}");
                this.Cleanup(man, file.ParentFile);
                return rs;
            }

            if (file.Name.IndexOf("mcic_") != 0 && !man.VerifyFile(file, "edit")) {
                rs.Add("FAILED", man.EncryptPath(file.AbsolutePath), man.InvalidFileMsg);
                this.Cleanup(man, file.ParentFile);
                return rs;
            }

            targetFile = man.GetFile(file.Parent, (string) input["target"]);
            if (file.AbsolutePath != targetFile.AbsolutePath) {

                string fileExt = PathUtils.GetExtension(file.Name).ToLower();
                string targetExt = PathUtils.GetExtension(targetFile.Name).ToLower();

                if (fileExt != targetExt) {
                    rs.Add("FAILED", man.EncryptPath(targetFile.AbsolutePath), "{#error.invalid_filename}");
                    this.Cleanup(man, file.ParentFile);
                    return rs;
                }

                if (config.GetBool("filesystem.delete_format_images", false))
                    ImageUtils.DeleteFormatImages(targetFile.AbsolutePath, config.Get("edit.format"));

                if (targetFile.Exists)
                    targetFile.Delete();

                file.RenameTo(targetFile);

                if (config.Get("edit.format") != null)
                    ImageUtils.FormatImage(targetFile.AbsolutePath, config.Get("edit.format"), config.GetInt("edit.jpeg_quality", 90));

                this.Cleanup(man, file.ParentFile);
            }

            rs.Add("OK", man.EncryptPath(file.AbsolutePath), "{#message.save_success}");

            return rs;
        }
示例#3
0
        private ResultSet RotateImage(ManagerEngine man, Hashtable input)
        {
            ResultSet rs = new ResultSet(new string[]{"status", "file", "message"});
            IFile file, targetFile;
            ManagerConfig config;
            string tempName;
            RotateFlipType rotateFlipType = RotateFlipType.Rotate90FlipNone;

            file = man.GetFile(man.DecryptPath((string) input["path"]));
            config = file.Config;

            if (!man.IsToolEnabled("edit", config))
                throw new ManagerException("{#error.no_access}");

            if (!file.Exists) {
                rs.Add("FAILED", man.EncryptPath(file.AbsolutePath), "{#error.file_not_exists}");
                return rs;
            }

            if (file.Name.IndexOf("mcic_") != 0 && !man.VerifyFile(file, "edit")) {
                rs.Add("FATAL", man.EncryptPath(file.AbsolutePath), man.InvalidFileMsg);
                return rs;
            }

            if (input["temp"] != null && (bool) input["temp"]) {
                tempName = "mcic_" + HttpContext.Current.Session.SessionID + "." + PathUtils.GetExtension(file.Name);

                if (input["target"] != null)
                    targetFile = man.GetFile(man.DecryptPath((string) input["target"]), tempName);
                else
                    targetFile = man.GetFile(file.Parent, tempName);
            } else
                targetFile = file;

            switch (Convert.ToInt32(input["angle"])) {
                case 90:
                    rotateFlipType = RotateFlipType.Rotate90FlipNone;
                    break;

                case 180:
                    rotateFlipType = RotateFlipType.Rotate180FlipNone;
                    break;

                case 270:
                    rotateFlipType = RotateFlipType.Rotate270FlipNone;
                    break;
            }

            try {
                ImageUtils.RotateFlipImage(file.AbsolutePath, targetFile.AbsolutePath, rotateFlipType, config.GetInt("edit.jpeg_quality", 90));
                rs.Add("OK", man.EncryptPath(targetFile.AbsolutePath), "{#message.rotate_success}");
            } catch (Exception ex) {
                man.Logger.Error(ex.ToString());
                rs.Add("FAILED", man.EncryptPath(targetFile.AbsolutePath), "{#error.rotate_failed}");
            }

            return rs;
        }
示例#4
0
        private ResultSet CropImage(ManagerEngine man, Hashtable input)
        {
            ResultSet rs = new ResultSet(new string[]{"status", "file", "message"});
            IFile file, targetFile;
            ManagerConfig config;
            string tempName;
            int x, y, w, h;

            file = man.GetFile(man.DecryptPath((string) input["path"]));
            config = file.Config;

            if (!man.IsToolEnabled("edit", config))
                throw new ManagerException("{#error.no_access}");

            if (!file.Exists) {
                rs.Add("FAILED", man.EncryptPath(file.AbsolutePath), "{#error.file_not_exists}");
                return rs;
            }

            if (file.Name.IndexOf("mcic_") != 0 && !man.VerifyFile(file, "edit")) {
                rs.Add("FATAL", man.EncryptPath(file.AbsolutePath), man.InvalidFileMsg);
                return rs;
            }

            if (input["temp"] != null && (bool) input["temp"]) {
                tempName = "mcic_" + HttpContext.Current.Session.SessionID + "." + PathUtils.GetExtension(file.Name);

                if (input["target"] != null)
                    targetFile = man.GetFile(man.DecryptPath((string) input["target"]), tempName);
                else
                    targetFile = man.GetFile(file.Parent, tempName);
            } else
                targetFile = file;

            x = Convert.ToInt32(input["left"]);
            y = Convert.ToInt32(input["top"]);
            w = Convert.ToInt32(input["width"]);
            h = Convert.ToInt32(input["height"]);

            //man.Logger.Debug(x, y, w, h, file.AbsolutePath, targetFile.AbsolutePath);

            try {
                ImageUtils.CropImage(file.AbsolutePath, targetFile.AbsolutePath, x, y, w, h, config.GetInt("edit.jpeg_quality", 90));
                rs.Add("OK", man.EncryptPath(targetFile.AbsolutePath), "{#message.crop_success}");
            } catch (Exception ex) {
                man.Logger.Error(ex.ToString());
                rs.Add("FAILED", man.EncryptPath(targetFile.AbsolutePath), "{#error.crop_failed}");
            }

            return rs;
        }
示例#5
0
        private void HandleUploadedFile(ManagerEngine man, IFile target_dir, HttpPostedFile uploaded_file, string file_name, ResultSet rs)
        {
            long maxSizeBytes;
            IFile file;
            ManagerConfig config;

            try {
                maxSizeBytes = StringUtils.GetSizeLong(target_dir.Config.Get("upload.maxsize", "10mb"), "10mb");

                if (file_name != null)
                    file = man.GetFile(target_dir.AbsolutePath, file_name + "." + PathUtils.GetExtension(uploaded_file.FileName), FileType.File);
                else
                    file = man.GetFile(target_dir.AbsolutePath, uploaded_file.FileName, FileType.File);

                config = file.Config;

                if (!man.IsToolEnabled("upload", config))
                    throw new ManagerException("{#error.no_access}");

                if (!man.VerifyFile(file, "upload")) {
                    rs.Add("FILTER_ERROR", man.EncryptPath(file.AbsolutePath), man.InvalidFileMsg);
                    return;
                }

                // To large
                if (uploaded_file.ContentLength > maxSizeBytes) {
                    rs.Add("SIZE_ERROR", man.EncryptPath(file.AbsolutePath), "{#error.error_to_large}");
                    return;
                }

                // File exists
                if (file.Exists) {
                    if (!config.GetBool("upload.overwrite", false)) {
                        rs.Add("OVERWRITE_ERROR", man.EncryptPath(file.AbsolutePath), "{#error.file_exists}");
                        return;
                    } else
                        file.Delete();
                }

                if (file is LocalFile) {
                    uploaded_file.SaveAs(file.AbsolutePath);
                    file.ImportFile(file.AbsolutePath); // Dispatch add
                } else {
                    Stream outStream = file.Open(FileMode.Create);
                    byte[] buff = new byte[1024];
                    int len;

                    while ((len = uploaded_file.InputStream.Read(buff, 0, buff.Length)) > 0)
                        outStream.Write(buff, 0, len);

                    outStream.Close();
                }

                rs.Add("OK", man.EncryptPath(file.AbsolutePath), "{#message.upload_ok}");
            } catch (Exception e) {
                man.Logger.Error(e.ToString());
                rs.Add("FAILED", file_name, "{#error.upload_failed}");
            }
        }
示例#6
0
        private void HandleChunkedUpload(ManagerEngine man, IFile target_dir, HttpRequest req, string file_name, ResultSet rs)
        {
            long maxSizeBytes;
            IFile file;
            ManagerConfig config;
            int chunk = req["chunk"] == null ? 0 : Convert.ToInt32(req["chunk"]), chunks = req["chunks"] == null ? 1 : Convert.ToInt32(req["chunks"]);

            try {
                maxSizeBytes = StringUtils.GetSizeLong(target_dir.Config.Get("upload.maxsize", "10mb"), "10mb");
                file = man.GetFile(target_dir.AbsolutePath, file_name, FileType.File);

                config = file.Config;

                if (!man.IsToolEnabled("upload", config))
                    throw new ManagerException("{#error.no_access}");

                if (!man.VerifyFile(file, "upload")) {
                    rs.Add("FILTER_ERROR", man.EncryptPath(file.AbsolutePath), man.InvalidFileMsg);
                    return;
                }

                // File exists
                if (file.Exists && chunk == 0) {
                    if (!config.GetBool("upload.overwrite", false)) {
                        rs.Add("OVERWRITE_ERROR", man.EncryptPath(file.AbsolutePath), "{#error.file_exists}");
                        return;
                    } else if (file.Exists)
                        file.Delete();
                }

                Stream outStream = file.Open(chunk == 0 ? FileMode.Create : FileMode.Append);
                byte[] buff = new byte[1024];
                int len;

                if (req.Files["file"] != null) {
                    while ((len = req.Files["file"].InputStream.Read(buff, 0, buff.Length)) > 0)
                        outStream.Write(buff, 0, len);
                } else {
                    while ((len = req.InputStream.Read(buff, 0, buff.Length)) > 0)
                        outStream.Write(buff, 0, len);
                }

                outStream.Close();

                // To large
                if (file.Length > maxSizeBytes) {
                    rs.Add("SIZE_ERROR", man.EncryptPath(file.AbsolutePath), "{#error.error_to_large}");
                    file.Delete();
                    return;
                }

                rs.Add("OK", man.EncryptPath(file.AbsolutePath), "{#message.upload_ok}");

                if (chunk == chunks - 1)
                    file.ImportFile(file.AbsolutePath); // Dispatch add
            } catch (Exception e) {
                man.Logger.Error(e.ToString());
                rs.Add("FAILED", file_name, "{#error.upload_failed}");
            }
        }
示例#7
0
        private ResultSet DeleteFiles(ManagerEngine man, Hashtable input)
        {
            ResultSet rs = new ResultSet(new string[]{"status", "file", "message"});
            ManagerConfig config;
            IFile file;

            for (int i=0; input["path" + i] != null; i++) {
                file = man.GetFile(man.DecryptPath((string) input["path" + i]));
                config = file.Config;

                if (!man.IsToolEnabled("delete", config))
                    throw new ManagerException("{#error.no_access}");

                // File exists
                if (!file.Exists) {
                    rs.Add("FAILED", man.EncryptPath(file.AbsolutePath), "{#error.file_not_exists}");
                    continue;
                }

                if (config.GetBool("general.demo", false)) {
                    rs.Add("FAILED", man.EncryptPath(file.AbsolutePath), "{#error.demo}");
                    continue;
                }

                if (!man.VerifyFile(file, "delete")) {
                    rs.Add("FAILED", man.EncryptPath(file.AbsolutePath), man.InvalidFileMsg);
                    continue;
                }

                if (!file.CanWrite) {
                    rs.Add("FAILED", man.EncryptPath(file.AbsolutePath), "{#error.no_write_access}");
                    continue;
                }

                if (!config.GetBool("filesystem.writable", true)) {
                    rs.Add("FAILED", man.EncryptPath(file.AbsolutePath), "{#error.no_write_access}");
                    continue;
                }

                if (file.Delete(config.GetBool("filesystem.delete_recursive", true)))
                    rs.Add("OK", man.EncryptPath(file.AbsolutePath), "{#message.delete_success}");
                else
                    rs.Add("FAILED", man.EncryptPath(file.AbsolutePath), "{#error.delete_failed}");
            }

            return rs;
        }
示例#8
0
        private ResultSet CreateDirs(ManagerEngine man, Hashtable input)
        {
            ResultSet rs = new ResultSet(new string[]{"status", "file", "message"});
            string path, name, template = null;
            IFile dir, file, templateFile;
            ManagerConfig config;

            path = man.DecryptPath((string) input["path"]);
            dir = man.GetFile(path);
            config = dir.Config;

            if (!man.IsToolEnabled("createdir", config))
                throw new ManagerException("{#error.no_access}");

            // Handle demo mode
            if (config.GetBool("general.demo", false)) {
                rs.Add("DEMO_ERROR", man.EncryptPath(dir.AbsolutePath), "{#error.demo}");
                return rs;
            }

            for (int i=0; input["name" + i] != null; i++) {
                // Get dir info
                name = (string) input["name" + i];

                if (input["template" + i] != null && ((string) input["template" + i]) != "")
                    template = man.DecryptPath((string) input["template" + i]);

                // Setup target file
                file = man.GetFile(path, name, FileType.Directory);

                // Check if valid target file
                if (!man.VerifyFile(file, "createdir")) {
                    rs.Add("FAILED", man.EncryptPath(file.AbsolutePath), man.InvalidFileMsg);
                    continue;
                }

                // Setup template dir
                if (template != null) {
                    templateFile = man.GetFile(template);

                    if (!man.VerifyFile(templateFile, "createdir")) {
                        rs.Add("ACCESS_ERROR", man.EncryptPath(file.AbsolutePath), man.InvalidFileMsg);
                        continue;
                    }

                    if (!templateFile.Exists) {
                        rs.Add("TEMPLATE_ERROR", man.EncryptPath(templateFile.AbsolutePath), "{#error.template_missing}");
                        continue;
                    }
                } else
                    templateFile = null;

                // Check if target exists
                if (file.Exists) {
                    rs.Add("EXISTS_ERROR", man.EncryptPath(file.AbsolutePath), "{#error.folder_exists}");
                    continue;
                }

                // Create directory
                if (templateFile != null)
                    templateFile.CopyTo(file);
                else
                    file.MkDir();

                rs.Add("OK", man.EncryptPath(file.AbsolutePath), "{#message.directory_ok}");
            }

            return rs;
        }
示例#9
0
        private ResultSet CreateDirs(ManagerEngine man, Hashtable input)
        {
            ResultSet     rs = new ResultSet(new string[] { "status", "file", "message" });
            string        path, name, template = null;
            IFile         dir, file, templateFile;
            ManagerConfig config;

            path   = man.DecryptPath((string)input["path"]);
            dir    = man.GetFile(path);
            config = dir.Config;

            if (!man.IsToolEnabled("createdir", config))
            {
                throw new ManagerException("{#error.no_access}");
            }

            // Handle demo mode
            if (config.GetBool("general.demo", false))
            {
                rs.Add("DEMO_ERROR", man.EncryptPath(dir.AbsolutePath), "{#error.demo}");
                return(rs);
            }

            for (int i = 0; input["name" + i] != null; i++)
            {
                // Get dir info
                name = (string)input["name" + i];

                if (input["template" + i] != null && ((string)input["template" + i]) != "")
                {
                    template = man.DecryptPath((string)input["template" + i]);
                }

                // Setup target file
                file = man.GetFile(path, name, FileType.Directory);

                // Check if valid target file
                if (!man.VerifyFile(file, "createdir"))
                {
                    rs.Add("FAILED", man.EncryptPath(file.AbsolutePath), man.InvalidFileMsg);
                    continue;
                }

                // Setup template dir
                if (template != null)
                {
                    templateFile = man.GetFile(template);

                    if (!man.VerifyFile(templateFile, "createdir"))
                    {
                        rs.Add("ACCESS_ERROR", man.EncryptPath(file.AbsolutePath), man.InvalidFileMsg);
                        continue;
                    }

                    if (!templateFile.Exists)
                    {
                        rs.Add("TEMPLATE_ERROR", man.EncryptPath(templateFile.AbsolutePath), "{#error.template_missing}");
                        continue;
                    }
                }
                else
                {
                    templateFile = null;
                }

                // Check if target exists
                if (file.Exists)
                {
                    rs.Add("EXISTS_ERROR", man.EncryptPath(file.AbsolutePath), "{#error.folder_exists}");
                    continue;
                }

                // Create directory
                if (templateFile != null)
                {
                    templateFile.CopyTo(file);
                }
                else
                {
                    file.MkDir();
                }

                rs.Add("OK", man.EncryptPath(file.AbsolutePath), "{#message.directory_ok}");
            }

            return(rs);
        }
示例#10
0
        private void HandleUploadedFile(ManagerEngine man, IFile target_dir, HttpPostedFile uploaded_file, string file_name, ResultSet rs)
        {
            long          maxSizeBytes;
            IFile         file;
            ManagerConfig config;

            try {
                maxSizeBytes = StringUtils.GetSizeLong(target_dir.Config.Get("upload.maxsize", "10mb"), "10mb");

                if (file_name != null)
                {
                    file = man.GetFile(target_dir.AbsolutePath, file_name + "." + PathUtils.GetExtension(uploaded_file.FileName), FileType.File);
                }
                else
                {
                    file = man.GetFile(target_dir.AbsolutePath, uploaded_file.FileName, FileType.File);
                }

                config = file.Config;

                if (!man.IsToolEnabled("upload", config))
                {
                    throw new ManagerException("{#error.no_access}");
                }

                if (!man.VerifyFile(file, "upload"))
                {
                    rs.Add("FILTER_ERROR", man.EncryptPath(file.AbsolutePath), man.InvalidFileMsg);
                    return;
                }

                // To large
                if (uploaded_file.ContentLength > maxSizeBytes)
                {
                    rs.Add("SIZE_ERROR", man.EncryptPath(file.AbsolutePath), "{#error.error_to_large}");
                    return;
                }

                // File exists
                if (file.Exists)
                {
                    if (!config.GetBool("upload.overwrite", false))
                    {
                        rs.Add("OVERWRITE_ERROR", man.EncryptPath(file.AbsolutePath), "{#error.file_exists}");
                        return;
                    }
                    else
                    {
                        file.Delete();
                    }
                }

                if (file is LocalFile)
                {
                    uploaded_file.SaveAs(file.AbsolutePath);
                    file.ImportFile(file.AbsolutePath);                     // Dispatch add
                }
                else
                {
                    Stream outStream = file.Open(FileMode.Create);
                    byte[] buff      = new byte[1024];
                    int    len;

                    while ((len = uploaded_file.InputStream.Read(buff, 0, buff.Length)) > 0)
                    {
                        outStream.Write(buff, 0, len);
                    }

                    outStream.Close();
                }

                rs.Add("OK", man.EncryptPath(file.AbsolutePath), "{#message.upload_ok}");
            } catch (Exception e) {
                man.Logger.Error(e.ToString());
                rs.Add("FAILED", file_name, "{#error.upload_failed}");
            }
        }
示例#11
0
        private void HandleChunkedUpload(ManagerEngine man, IFile target_dir, HttpRequest req, string file_name, ResultSet rs)
        {
            long          maxSizeBytes;
            IFile         file;
            ManagerConfig config;
            int           chunk = req["chunk"] == null ? 0 : Convert.ToInt32(req["chunk"]), chunks = req["chunks"] == null ? 1 : Convert.ToInt32(req["chunks"]);

            try {
                maxSizeBytes = StringUtils.GetSizeLong(target_dir.Config.Get("upload.maxsize", "10mb"), "10mb");
                file         = man.GetFile(target_dir.AbsolutePath, file_name, FileType.File);

                config = file.Config;

                if (!man.IsToolEnabled("upload", config))
                {
                    throw new ManagerException("{#error.no_access}");
                }

                if (!man.VerifyFile(file, "upload"))
                {
                    rs.Add("FILTER_ERROR", man.EncryptPath(file.AbsolutePath), man.InvalidFileMsg);
                    return;
                }

                // File exists
                if (file.Exists && chunk == 0)
                {
                    if (!config.GetBool("upload.overwrite", false))
                    {
                        rs.Add("OVERWRITE_ERROR", man.EncryptPath(file.AbsolutePath), "{#error.file_exists}");
                        return;
                    }
                    else if (file.Exists)
                    {
                        file.Delete();
                    }
                }

                Stream outStream = file.Open(chunk == 0 ? FileMode.Create : FileMode.Append);
                byte[] buff      = new byte[1024];
                int    len;

                if (req.Files["file"] != null)
                {
                    while ((len = req.Files["file"].InputStream.Read(buff, 0, buff.Length)) > 0)
                    {
                        outStream.Write(buff, 0, len);
                    }
                }
                else
                {
                    while ((len = req.InputStream.Read(buff, 0, buff.Length)) > 0)
                    {
                        outStream.Write(buff, 0, len);
                    }
                }

                outStream.Close();

                // To large
                if (file.Length > maxSizeBytes)
                {
                    rs.Add("SIZE_ERROR", man.EncryptPath(file.AbsolutePath), "{#error.error_to_large}");
                    file.Delete();
                    return;
                }

                rs.Add("OK", man.EncryptPath(file.AbsolutePath), "{#message.upload_ok}");

                if (chunk == chunks - 1)
                {
                    file.ImportFile(file.AbsolutePath);                     // Dispatch add
                }
            } catch (Exception e) {
                man.Logger.Error(e.ToString());
                rs.Add("FAILED", file_name, "{#error.upload_failed}");
            }
        }
示例#12
0
        private Hashtable SaveContent(ManagerEngine man, Hashtable input)
        {
            Hashtable result = new Hashtable();
            IFile file;
            ManagerConfig config;
            StreamWriter writer = null;
            Stream stream = null;

            file = man.GetFile(man.DecryptPath((string) input["path"]));
            config = file.Config;

            if (!man.IsToolEnabled("edit", config))
                throw new ManagerException("{#error.no_access}");

            if (config.GetBool("general.demo", false))
                throw new ManagerException("{#error.demo}");

            if (!man.VerifyFile(file, "edit"))
                throw new ManagerException(man.InvalidFileMsg);

            if (!file.CanWrite)
                throw new ManagerException("{#error.no_write_access}");

            if (!config.GetBool("filesystem.writable", true))
                throw new ManagerException("{#error.no_write_access}");

            // Load content
            try {
                if (file.Exists)
                    file.Delete();

                stream = file.Open(FileMode.CreateNew);
                if (stream != null) {
                    writer = new StreamWriter(stream);
                    writer.Write(input["content"]);
                    writer.Close();
                } else
                    throw new ManagerException("{#error.no_access}");
            } finally {
                if (stream != null)
                    stream.Close();
            }

            return result;
        }
示例#13
0
        private ResultSet MoveFiles(ManagerEngine man, Hashtable input)
        {
            ResultSet rs = new ResultSet(new string[]{"status", "fromfile", "tofile", "message"});
            IFile fromFile, toFile;
            ManagerConfig toConfig;
            FileType fromType;

            for (int i=0; input["frompath" + i] != null; i++) {
                fromFile = man.GetFile(man.DecryptPath((string) input["frompath" + i]));
                fromType = fromFile.IsFile ? FileType.File : FileType.Directory;

                if (input["topath" + i] != null)
                    toFile = man.GetFile(man.DecryptPath((string) input["topath" + i]), "", fromType);
                else {
                    if (input["toname" + i] != null)
                        toFile = man.GetFile(fromFile.Parent, (string) input["toname" + i], fromType);
                    else
                        toFile = man.GetFile(man.DecryptPath((string) input["topath"]), fromFile.Name, fromType);
                }

                toConfig = toFile.Config;

                if (!man.IsToolEnabled("cut", toConfig) && !man.IsToolEnabled("rename", toConfig))
                    throw new ManagerException("{#error.no_access}");

                // From file missing
                if (!fromFile.Exists) {
                    rs.Add("FAILED", man.EncryptPath(fromFile.AbsolutePath), man.EncryptPath(toFile.AbsolutePath), "{#error.no_from_file}");
                    continue;
                }

                // User tried to change extension
                if (fromFile.IsFile && PathUtils.GetExtension(fromFile.Name) != PathUtils.GetExtension(toFile.Name)) {
                    rs.Add("FAILED", man.EncryptPath(fromFile.AbsolutePath), man.EncryptPath(toFile.AbsolutePath), "{#error.move_failed}");
                    continue;
                }

                if (toConfig.GetBool("general.demo", false)) {
                    rs.Add("FAILED", man.EncryptPath(fromFile.AbsolutePath), man.EncryptPath(toFile.AbsolutePath), "{#error.demo}");
                    continue;
                }

                if (!man.VerifyFile(toFile, "rename")) {
                    rs.Add("FAILED", man.EncryptPath(fromFile.AbsolutePath), man.EncryptPath(toFile.AbsolutePath), man.InvalidFileMsg);
                    continue;
                }

                if (!toFile.CanWrite) {
                    rs.Add("FAILED", man.EncryptPath(fromFile.AbsolutePath), man.EncryptPath(toFile.AbsolutePath), "{#error.no_write_access}");
                    continue;
                }

                if (!toConfig.GetBool("filesystem.writable", true)) {
                    rs.Add("FAILED", man.EncryptPath(fromFile.AbsolutePath), man.EncryptPath(toFile.AbsolutePath), "{#error.no_write_access}");
                    continue;
                }

                // To file there
                if (toFile.Exists) {
                    rs.Add("FAILED", man.EncryptPath(fromFile.AbsolutePath), man.EncryptPath(toFile.AbsolutePath), "{#error.tofile_exists}");
                    continue;
                }

                // Zip check
                if (toFile is ZipFileImpl) {
                    if (!man.VerifyFile(fromFile, "zip")) {
                        rs.Add("FAILED", man.EncryptPath(fromFile.AbsolutePath), man.EncryptPath(toFile.AbsolutePath), man.InvalidFileMsg);
                        continue;
                    }
                }

                // Unzip check
                if (fromFile is ZipFileImpl) {
                    if (!man.VerifyFile(toFile, "unzip")) {
                        rs.Add("FAILED", man.EncryptPath(fromFile.AbsolutePath), man.EncryptPath(toFile.AbsolutePath), man.InvalidFileMsg);
                        continue;
                    }
                }

                string fromPath = fromFile.AbsolutePath;

                if (fromFile.RenameTo(toFile))
                    rs.Add("OK", man.EncryptPath(fromPath), man.EncryptPath(toFile.AbsolutePath), "{#message.move_success}");
                else
                    rs.Add("FAILED", man.EncryptPath(fromFile.AbsolutePath), man.EncryptPath(toFile.AbsolutePath), "{#error.move_failed}");
            }

            return rs;
        }
示例#14
0
        private ResultSet CreateZip(ManagerEngine man, Hashtable input)
        {
            ResultSet rs = new ResultSet(new string[]{"status", "fromfile", "tofile", "message"});

            if (man.GetFile(man.DecryptPath((string) input["topath"]), (string) input["toname"] + ".zip").Exists)
                throw new ManagerException("{#error.tofile_exists}");

            for (int i=0; input["frompath" + i] != null; i++) {
                IFile fromFile = man.GetFile(man.DecryptPath((string) input["frompath" + i]));
                IFile toFile = man.GetFile("zip://" + PathUtils.AddTrailingSlash(man.DecryptPath((string) input["topath"])) + input["toname"] + ".zip", fromFile.Name);

                if (!man.IsToolEnabled("zip", toFile.Config))
                    throw new ManagerException("{#error.no_access}");

                if (!fromFile.Exists) {
                    rs.Add("FAILED", man.EncryptPath(fromFile.AbsolutePath), man.EncryptPath(toFile.AbsolutePath), "{#error.no_from_file}");
                    continue;
                }

                // Zip check
                if (!man.VerifyFile(fromFile, "zip")) {
                    rs.Add("FAILED", man.EncryptPath(fromFile.AbsolutePath), man.EncryptPath(toFile.AbsolutePath), man.InvalidFileMsg);
                    continue;
                }

                if (fromFile.CopyTo(toFile))
                    rs.Add("OK", man.EncryptPath(fromFile.AbsolutePath), man.EncryptPath(toFile.AbsolutePath), "{#message.zip_success}");
            }

            return rs;
        }
示例#15
0
        private ResultSet CreateDocs(ManagerEngine man, Hashtable input)
        {
            ResultSet rs = new ResultSet(new string[]{"status", "fromfile", "tofile", "message"});
            IFile fromFile, toFile;
            ManagerConfig toConfig;
            string ext;
            Hashtable fields;

            for (int i=0; input["frompath" + i] != null && input["toname" + i] != null; i++) {
                fromFile = man.GetFile(man.DecryptPath((string) input["frompath" + i]));
                ext = PathUtils.GetExtension(fromFile.Name);
                toFile = man.GetFile(man.DecryptPath((string) input["topath" + i]), (string) input["toname" + i] + "." + ext, FileType.File);
                toConfig = toFile.Config;

                if (!man.IsToolEnabled("createdoc", toConfig))
                    throw new ManagerException("{#error.no_access}");

                if (toConfig.GetBool("general.demo", false)) {
                    rs.Add("FAILED", man.EncryptPath(fromFile.AbsolutePath), man.EncryptPath(toFile.AbsolutePath), "{#error.demo}");
                    continue;
                }

                if (!fromFile.Exists) {
                    rs.Add("FAILED", man.EncryptPath(fromFile.AbsolutePath), man.EncryptPath(toFile.AbsolutePath), "{#error.template_missing}");
                    continue;
                }

                if (!man.VerifyFile(toFile, "createdoc")) {
                    rs.Add("FAILED", man.EncryptPath(fromFile.AbsolutePath), man.EncryptPath(toFile.AbsolutePath), man.InvalidFileMsg);
                    continue;
                }

                if (!toFile.CanWrite) {
                    rs.Add("FAILED", man.EncryptPath(fromFile.AbsolutePath), man.EncryptPath(toFile.AbsolutePath), "{#error.no_write_access}");
                    continue;
                }

                if (!toConfig.GetBool("filesystem.writable", true)) {
                    rs.Add("FAILED", man.EncryptPath(fromFile.AbsolutePath), man.EncryptPath(toFile.AbsolutePath), "{#error.no_write_access}");
                    continue;
                }

                if (fromFile.CopyTo(toFile)) {
                    // Replace title
                    fields = (Hashtable) input["fields"];

                    // Replace all fields
                    if (fields != null) {
                        // Read all data
                        StreamReader reader = new StreamReader(toFile.Open(FileMode.Open));
                        string fileData = reader.ReadToEnd();
                        reader.Close();

                        // Replace fields
                        foreach (string name in fields.Keys)
                            fileData = fileData.Replace("${" + name + "}", (string) fields[name]);

                        // Write file data
                        StreamWriter writer = new StreamWriter(toFile.Open(FileMode.Create));
                        writer.Write(fileData);
                        writer.Close();
                    }

                    rs.Add("OK", man.EncryptPath(fromFile.AbsolutePath), man.EncryptPath(toFile.AbsolutePath), "{#message.createdoc_success}");
                } else
                    rs.Add("FAILED", man.EncryptPath(fromFile.AbsolutePath), man.EncryptPath(toFile.AbsolutePath), "{#error.createdoc_failed}");
            }

            return rs;
        }