Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="man"></param>
        /// <returns></returns>
        public override bool OnInit(ManagerEngine man)
        {
            string       fs      = man.Config.Get("filesystem", "LocalFileFactory");
            IFileFactory factory = null;

            // Register local file system factroy
            if (fs != "LocalFileFactory")
            {
                if (fs.IndexOf('.') == -1)
                {
                    factory = (IFileFactory)InstanceFactory.CreateInstance("Moxiecode.Manager.FileSystems." + fs);
                }

                if (factory == null)
                {
                    factory = (IFileFactory)InstanceFactory.CreateInstance(fs);
                }

                man.FileSystems["file"] = factory;
            }
            else
            {
                man.FileSystems["file"] = new LocalFileFactory();
            }

            man.FileSystems["root"] = new RootFileFactory();

            return(true);            // Pass to next
        }
Пример #2
0
        private ResultSet InsertFiles(ManagerEngine man, Hashtable input)
        {
            ResultSet rs = new ResultSet(new string[] { "name", "path", "url", "size", "type", "created", "modified", "attribs", "custom" });

            for (int i = 0; input["path" + i] != null; i++)
            {
                Hashtable customInfo = new Hashtable();
                IFile     file;
                string    url, attribs;

                file = man.GetFile(man.DecryptPath((string)input["path" + i]));
                if (!file.Exists)
                {
                    throw new ManagerException("{#error.file_not_exists}");
                }

                man.DispatchEvent(EventType.CustomInfo, file, "insert", customInfo);
                man.DispatchEvent(EventType.InsertFile, file);

                url     = PathUtils.RemoveTrailingSlash(file.Config["preview.urlprefix"]) + man.ConvertPathToURI(file.AbsolutePath) + file.Config["preview.urlsuffix"];
                attribs = "RW";

                rs.Add(file.Name,
                       man.EncryptPath(file.AbsolutePath),
                       url,
                       file.Length,
                       PathUtils.GetExtension(file.Name).ToLower(),
                       StringUtils.GetDate(file.CreationDate, file.Config.Get("filesystem.datefmt", "yyyy-MM-dd HH:mm")),
                       StringUtils.GetDate(file.LastModified, file.Config.Get("filesystem.datefmt", "yyyy-MM-dd HH:mm")),
                       attribs,
                       customInfo);
            }

            return(rs);
        }
Пример #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="man"></param>
        /// <param name="cmd"></param>
        /// <param name="input"></param>
        /// <returns></returns>
        public override object OnRPC(ManagerEngine man, string cmd, Hashtable input)
        {
            switch (cmd)
            {
            case "deleteFiles":
                return(this.DeleteFiles(man, input));

            case "listFiles":
                return(this.ListFiles(man, cmd, input));

            case "createDirs":
                return(this.CreateDirs(man, input));

            case "getConfig":
                return(this.GetConfig(man, input));

            case "insertFiles":
                return(this.InsertFiles(man, input));

            case "keepAlive":
                return(this.KeepAlive(man, input));

            case "loopBack":
                return(this.LoopBack(man, input));
            }

            return(null);
        }
Пример #4
0
        private object AddFavorites(ManagerEngine man, Hashtable input)
        {
            ResultSet rs = new ResultSet(new string[]{"status", "file", "message"});
            HttpResponse response = HttpContext.Current.Response;
            HttpRequest request = HttpContext.Current.Request;
            HttpCookie cookie;
            ArrayList chunks;

            if ((cookie = request.Cookies["fav"]) == null) {
                cookie = new HttpCookie("fav");
                chunks = new ArrayList();
            } else
                chunks = new ArrayList(cookie.Value.Split(new char[]{','}));

            cookie.Expires = DateTime.Now.AddDays(30);

            for (int i=0; input["path" + i] != null; i++) {
                string path = (string) input["path" + i];

                if (chunks.IndexOf(path) == -1)
                    chunks.Add(path);

                rs.Add("OK", man.EncryptPath(path), "Path was added.");
            }

            cookie.Value = this.Implode(chunks, ",");
            response.Cookies.Remove("fav");
            response.Cookies.Add(cookie);

            return rs;
        }
Пример #5
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="man"></param>
        /// <returns></returns>
        public override bool OnInit(ManagerEngine man)
        {
            // Register local file system factroy
            man.FileSystems["zip"] = new ZipFileFactory();

            return true; // Pass to next
        }
Пример #6
0
        private object GetConfig(ManagerEngine man, Hashtable input)
        {
            string prefixes, path;
            IFile  file;

            // Get input
            prefixes = (string)input["prefixes"];
            path     = man.DecryptPath((string)input["path"]);

            // Request all
            if (prefixes == null)
            {
                prefixes = "*";
            }

            // Return config
            file = man.GetFile(path);

            if (!file.Exists)
            {
                throw new ManagerException("{#error.file_not_exists}");
            }

            return(man.GetJSConfig(file.Config, prefixes));
        }
Пример #7
0
        public override bool OnInsertFile(ManagerEngine man, IFile file)
        {
            HttpResponse response = HttpContext.Current.Response;
            HttpRequest request = HttpContext.Current.Request;
            HttpCookie cookie;
            ArrayList chunks;

            if ((cookie = request.Cookies["hist"]) == null)
                cookie = new HttpCookie("hist");

            cookie.Expires = DateTime.Now.AddDays(30);

            if (cookie.Value != null) {
                chunks = new ArrayList(cookie.Value.Split(new char[]{','}));

                if (chunks.IndexOf(man.EncryptPath(file.AbsolutePath)) == -1)
                    chunks.Add(man.EncryptPath(file.AbsolutePath));

                cookie.Value = this.Implode(chunks, ",");
            } else
                cookie.Value = man.EncryptPath(file.AbsolutePath);

            response.Cookies.Remove("hist");
            response.Cookies.Add(cookie);

            return true;
        }
Пример #8
0
        /// <summary>
        ///  
        /// </summary>
        /// <param name="man"></param>
        /// <param name="cmd"></param>
        /// <param name="input"></param>
        /// <returns></returns>
        public override object OnRPC(ManagerEngine man, string cmd, Hashtable input)
        {
            switch (cmd) {
                case "deleteFiles":
                    return this.DeleteFiles(man, input);

                case "listFiles":
                    return this.ListFiles(man, cmd, input);

                case "createDirs":
                    return this.CreateDirs(man, input);

                case "getConfig":
                    return this.GetConfig(man, input);

                case "insertFiles":
                    return this.InsertFiles(man, input);

                case "keepAlive":
                    return this.KeepAlive(man, input);

                case "loopBack":
                    return this.LoopBack(man, input);
            }

            return null;
        }
Пример #9
0
        /// <summary>
        ///  Initializes a file instance by a absolute path, child name and type.
        ///  This can be userful when filtering non existing files.
        /// </summary>
        /// <param name="man">Reference to manager that requested the file.</param>
        /// <param name="absolute_path">Absolute file/directory path.</param>
        /// <param name="child_name">Name of child file for the directory.</param>
        /// <param name="type">Type of file to create.</param>
        public LocalFile(ManagerEngine man, string absolute_path, string child_name, FileType type)
        {
            this.manager = man;

            if (child_name != "")
                this.absPath = PathUtils.ToUnixPath(absolute_path + "/" + child_name);
            else
                this.absPath = PathUtils.ToUnixPath(absolute_path);

            if (type == FileType.Directory)
                this.dirInfo = new DirectoryInfo(PathUtils.ToOSPath(this.absPath));
            else if (type == FileType.File)
                this.fileInfo = new FileInfo(PathUtils.ToOSPath(this.absPath));
            else {
                // Create file info or dir info
                this.fileInfo = new FileInfo(PathUtils.ToOSPath(this.absPath));
                if (!this.fileInfo.Exists) {
                    this.dirInfo = new DirectoryInfo(PathUtils.ToOSPath(this.absPath));
                    this.fileInfo = null;
                }

                if (this.fileInfo != null)
                    this.absPath = PathUtils.ToUnixPath(this.fileInfo.FullName);

                if (this.dirInfo != null)
                    this.absPath = PathUtils.RemoveTrailingSlash(PathUtils.ToUnixPath(this.dirInfo.FullName));
            }

            this.config = this.manager.Config;
            this.configResolved = false;
            this.triggerEvents = true;
        }
Пример #10
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);
        }
Пример #11
0
        /// <summary>
        ///  Initializes a file instance by a absolute path, child name and type.
        ///  This can be userful when filtering non existing files.
        /// </summary>
        /// <param name="man">Reference to manager that requested the file.</param>
        /// <param name="absolute_path">Absolute file/directory path.</param>
        /// <param name="child_name">Name of child file for the directory.</param>
        /// <param name="type">Type of file to create.</param>
        public BaseFile(ManagerEngine man, string absolute_path, string child_name, FileType type)
        {
            this.manager = man;

            if (child_name != null && child_name != "")
                this.absPath = PathUtils.ToUnixPath(absolute_path + "/" + child_name);
            else
                this.absPath = PathUtils.ToUnixPath(absolute_path);
        }
Пример #12
0
        private ResultSet KeepAlive(ManagerEngine man, Hashtable input)
        {
            ResultSet rs = new ResultSet(new string[] { "status", "time", "message" });

            man.DispatchEvent(EventType.KeepAlive);

            rs.Add("KEEPALIVE", DateTime.Now.Ticks, "{#message.keepalive}");

            return(rs);
        }
Пример #13
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="man"></param>
        /// <param name="file"></param>
        /// <param name="type"></param>
        /// <param name="info"></param>
        /// <returns></returns>
        public override bool OnCustomInfo(ManagerEngine man, IFile file, string type, Hashtable info)
        {
            switch (type) {
                case "list":
                    info["previewable"] = file.IsFile && man.VerifyFile(file, "preview");
                    info["editable"] = file.IsFile && man.VerifyFile(file, "edit");
                    break;
            }

            return true;
        }
Пример #14
0
        public override object OnRPC(ManagerEngine man, string cmd, Hashtable input)
        {
            switch (cmd) {
                case "addFavorites":
                    return this.AddFavorites(man, input);

                case "removeFavorites":
                    return this.RemoveFavorites(man, input);
            }

            return null;
        }
Пример #15
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="man"></param>
        /// <param name="cmd"></param>
        /// <param name="input"></param>
        /// <returns></returns>
        public override object OnUpload(ManagerEngine man, string cmd, NameValueCollection input)
        {
            if (cmd == "upload")
            {
                ResultSet     rs      = new ResultSet(new string[] { "status", "file", "message" });
                HttpRequest   request = HttpContext.Current.Request;
                ManagerConfig config;
                IFile         targetDir;

                // Setup
                targetDir = man.GetFile(man.DecryptPath(input["path"]));
                config    = targetDir.Config;

                // Check access agains config
                if (config.GetBool("general.demo", false))
                {
                    rs.Add("FAILED", man.EncryptPath(targetDir.AbsolutePath), "{#error.demo}");
                    return(rs);
                }

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

                if (config.HasItem("general.disabled_tools", "upload"))
                {
                    rs.Add("FAILED", man.EncryptPath(targetDir.AbsolutePath), "{#error.demo}");
                    return(rs);
                }

                // Handle flash upload
                if (request["html4"] == null)
                {
                    this.HandleChunkedUpload(man, targetDir, request, request["name"], rs);
                    return(rs);
                }

                // Ok lets check the files array out.
                for (int i = 0; request.Files["file" + i] != null; i++)
                {
                    this.HandleUploadedFile(man, targetDir, request.Files["file" + i], input["name" + i], rs);
                }

                return(rs);
            }

            return(null);
        }
Пример #16
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="man"></param>
        /// <param name="file"></param>
        /// <param name="type"></param>
        /// <param name="info"></param>
        /// <returns></returns>
        public override bool OnCustomInfo(ManagerEngine man, IFile file, string type, Hashtable info)
        {
            switch (type) {
                case "insert":
                // Can be used by the insert_templates like this {$custom.mycustomfield}
                info["mycustomfield"] = file.Name.ToUpper();

                // Will be used as title/alt in TinyMCE link/image dialogs
                info["description"] = file.Name + "(" + StringUtils.GetSizeStr(file.Length) + ")";
                break;
            }

            // Pass to next handler
            return true;
        }
Пример #17
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="man"></param>
        /// <param name="action"></param>
        /// <param name="file1"></param>
        /// <param name="file2"></param>
        /// <returns></returns>
        public override bool OnBeforeFileAction(ManagerEngine man, FileAction action, IFile file1, IFile file2)
        {
            ManagerConfig config;

            if (action == FileAction.Delete) {
                config = file1.Config;

                if (config.GetBool("filesystem.delete_format_images", false)) {
                    ImageUtils.DeleteFormatImages(file1.AbsolutePath, config.Get("upload.format"));
                    ImageUtils.DeleteFormatImages(file1.AbsolutePath, config.Get("edit.format"));
                }
            }

            return true;
        }
Пример #18
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="man"></param>
        /// <returns></returns>
        public override bool OnAuthenticate(ManagerEngine man)
        {
            HttpContext context = HttpContext.Current;
            ManagerConfig config = man.Config;
             	string user = context.User.Identity.Name;

             	// Cleanup
             	user = user.Replace("\\", "");
             	user = user.Replace("/", "");
             	user = user.Replace(":", "");

             	// Replace all ${user} with current user
             	for (int i=0; i<config.Keys.Count; i++)
             		config[config.Keys[i]] = config[config.Keys[i]].Replace("${user}", user);

            return context.User.Identity.IsAuthenticated;
        }
Пример #19
0
        /// <summary>
        ///  
        /// </summary>
        /// <param name="man"></param>
        /// <returns></returns>
        public override bool OnInit(ManagerEngine man)
        {
            string fs = man.Config.Get("filesystem", "LocalFileFactory");
            IFileFactory factory = null;

            // Register local file system factroy
            if (fs != "LocalFileFactory") {
                if (fs.IndexOf('.') == -1)
                    factory = (IFileFactory) InstanceFactory.CreateInstance("Moxiecode.Manager.FileSystems." + fs);

                if (factory == null)
                    factory = (IFileFactory) InstanceFactory.CreateInstance(fs);

                man.FileSystems["file"] = factory;
            } else
                man.FileSystems["file"] = new LocalFileFactory();

            man.FileSystems["root"] = new RootFileFactory();

            return true; // Pass to next
        }
Пример #20
0
 /// <summary>
 ///  Gets called when the user selects a file and inserts it into TinyMCE or a form or similar.
 /// </summary>
 /// <param name="man">ManagerEngine reference that the plugin is assigned to.</param>
 /// <param name="file">Implementation of the BaseFile class that was inserted/returned to external system.</param>
 /// <returns>true/false if the execution of the event chain should continue execution.</returns>
 public virtual bool OnInsertFile(ManagerEngine man, IFile file)
 {
     return true;
 }
Пример #21
0
 /// <summary>
 ///  Gets called before the ManagerEngine is initialized. This method
 ///  can setup config and language pack data based on the prefix.
 /// </summary>
 /// <param name="man">ManagerEngine reference that the plugin is assigned to.</param>
 /// <param name="prefix">Prefix to use when setting up config etc.</param>
 /// <returns>true/false if the user is authenticated</returns>
 public virtual bool OnPreInit(ManagerEngine man, string prefix)
 {
     return true;
 }
Пример #22
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="man"></param>
        /// <param name="file"></param>
        /// <param name="type"></param>
        /// <param name="info"></param>
        /// <returns></returns>
        public override bool OnCustomInfo(ManagerEngine man, IFile file, string type, Hashtable info)
        {
            string ext = PathUtils.GetExtension(file.Name).ToLower();

            info["thumbnail"] = false;

            switch (ext) {
                case "gif":
                case "jpeg":
                case "jpg":
                case "png":
                    MediaInfo imageSize = new MediaInfo(file.AbsolutePath);
                    ManagerConfig config = file.Config;
                    int thumbWidth, thumbHeight;
                    double scale;

                    // Constrain proportions
                    scale = Math.Min(config.GetInt("thumbnail.width", 90) / (double) imageSize.Width, config.GetInt("thumbnail.height", 90) / (double) imageSize.Height);

                    if (config.Get("thumbnail.scale_mode", "percentage") == "percentage") {
                        thumbWidth = scale > 1 ? imageSize.Width : (int) Math.Floor(imageSize.Width * scale);
                        thumbHeight = scale > 1 ? imageSize.Height : (int) Math.Floor(imageSize.Height * scale);
                    } else {
                        thumbWidth = config.GetInt("thumbnail.width", 90);
                        thumbHeight = config.GetInt("thumbnail.height", 90);
                    }

                    info["width"] = imageSize.Width;
                    info["height"] = imageSize.Height;
                    info["editable"] = true;
                    info["twidth"] = thumbWidth;
                    info["theight"] = thumbHeight;
                    info["thumbnail"] = true;

                    // Get thumbnail URL
                    if (type == "insert") {
                        IFile thumbFile = man.GetFile(file.Parent + "/" + config.Get("thumbnail.folder", "mcith") + "/" + config.Get("thumbnail.prefix", "mcith") + file.Name);

                        if (thumbFile.Exists)
                            info["thumbnail_url"] = man.ConvertPathToURI(thumbFile.AbsolutePath);
                    }

                    break;
            }

            return true;
        }
Пример #23
0
 /// <summary>
 ///  Gets called when custom data is to be added for a file custom data can for example be
 ///  plugin specific name value items that should get added into a file listning.
 /// </summary>
 /// <param name="man">ManagerEngine reference that the plugin is assigned to.</param>
 /// <param name="file">File reference to add custom info/data to.</param>
 /// <param name="type">Where is the info needed for example list or info.</param>
 /// <param name="custom">Name/Value array to add custom items to.</param>
 /// <returns>true/false if the execution of the event chain should continue execution.</returns>
 public virtual bool OnCustomInfo(ManagerEngine man, IFile file, string type, Hashtable custom)
 {
     return true;
 }
Пример #24
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;
        }
Пример #25
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;
        }
Пример #26
0
 /// <summary>
 ///  Gets called when data is streamed to client. This method should setup HTTP headers, content type
 ///  etc and simply send out the binary data to the client and the return false ones that is done.
 /// </summary>
 /// <param name="man">ManagerEngine reference that the plugin is assigned to.</param>
 /// <param name="cmd">Stream command that is to be performed.</param>
 /// <param name="input">Array of input arguments.</param>
 /// <returns>true/false if the execution of the event chain should continue execution.</returns>
 public virtual bool OnStream(ManagerEngine man, string cmd, NameValueCollection input)
 {
     return(true);
 }
Пример #27
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="man"></param>
 /// <param name="path"></param>
 /// <param name="child"></param>
 /// <param name="type"></param>
 public RootFile(ManagerEngine man, string path, string child, FileType type) : base(man, path, child, type)
 {
 }
Пример #28
0
 /// <summary>
 ///  Gets called before a RPC command is handled.
 /// </summary>
 /// <param name="man">ManagerEngine reference that the plugin is assigned to.</param>
 /// <param name="cmd">RPC Command to be executed.</param>
 /// <param name="input">RPC input object data.</param>
 /// <returns>true/false if the execution of the event chain should continue execution.</returns>
 public virtual bool OnBeforeRPC(ManagerEngine man, string cmd, Hashtable input)
 {
     return(true);
 }
Пример #29
0
 /// <summary>
 ///  Gets executed when a RPC command is to be executed.
 /// </summary>
 /// <param name="man">ManagerEngine reference that the plugin is assigned to.</param>
 /// <param name="cmd">RPC Command to be executed.</param>
 /// <param name="input">RPC input object data.</param>
 /// <returns>true/false if the execution of the event chain should continue execution.</returns>
 public virtual object OnRPC(ManagerEngine man, string cmd, Hashtable input)
 {
     return(null);
 }
Пример #30
0
 /// <summary>
 ///  Gets called after a file action was perforem for example after a rename or copy.
 /// </summary>
 /// <param name="man">ManagerEngine reference that the plugin is assigned to.</param>
 /// <param name="action">File action type.</param>
 /// <param name="file1">File object 1 for example from in a copy operation.</param>
 /// <param name="file2">File object 2 for example to in a copy operation. Might be null in for example a delete.</param>
 /// <returns>true/false if the execution of the event chain should continue execution.</returns>
 public virtual bool OnFileAction(ManagerEngine man, FileAction action, IFile file1, IFile file2)
 {
     return(true);
 }
Пример #31
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);
        }
Пример #32
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="man"></param>
        /// <param name="cmd"></param>
        /// <param name="input"></param>
        /// <returns></returns>
        public override bool OnStream(ManagerEngine man, string cmd, NameValueCollection input)
        {
            HttpContext   context = HttpContext.Current;
            string        path, contentType;
            ManagerConfig config;
            IFile         file;

            switch (cmd)
            {
            case "streamFile":
                // Get input
                path = man.DecryptPath(input["path"]);

                // Get and stream file
                file   = man.GetFile(path);
                config = file.Config;

                if (file is LocalFile)
                {
                    string url = PathUtils.RemoveTrailingSlash(config["preview.urlprefix"]) + man.ConvertPathToURI(file.AbsolutePath) + config["preview.urlsuffix"];

                    // Pass through rnd
                    if (input["rnd"] != null)
                    {
                        context.Response.Redirect(url + (url.IndexOf('?') == -1 ? ("?rnd=" + input["rnd"]) : ("&rnd" + input["rnd"])), true);
                    }

                    context.Response.Redirect(url, true);
                }
                else
                {
                    // Verify that we can stream the file
                    if (!man.VerifyFile(file, "stream"))
                    {
                        throw new ManagerException("Requested resource could not be found. Or access was denied.");
                    }

                    // Set content type
                    contentType = man.MimeTypes[PathUtils.GetExtension(path).ToLower()];
                    if (contentType != null)
                    {
                        context.Response.ContentType = contentType;
                    }

                    IOUtils.StreamFromTo(file.Open(FileMode.Open), context.Response.OutputStream, 1024);
                }

                break;

            case "download":
                // Get input
                path = man.DecryptPath(input["path"]);

                // Get and stream file
                file   = man.GetFile(path);
                config = file.Config;

                // Verify that we can stream the file
                if (!man.VerifyFile(file, "download"))
                {
                    throw new ManagerException("Requested resource could not be found. Or access was denied.");
                }

                // Set content type
                //contentType = man.MimeTypes[PathUtils.GetExtension(path).ToLower()];
                context.Response.ContentType = "application/octet-stream";
                context.Response.AddHeader("Content-Disposition:", "attachment; filename=\"" + file.Name + "\"");
                //IOUtils.StreamFromTo(file.Open(FileMode.Open), context.Response.OutputStream, 4096);

                byte[] buff = new byte[4096];
                int    len;
                Stream inStream = file.Open(FileMode.Open), outStream = context.Response.OutputStream;

                try {
                    while ((len = inStream.Read(buff, 0, buff.Length)) > 0)
                    {
                        outStream.Write(buff, 0, len);
                        outStream.Flush();
                        context.Response.Flush();
                    }
                } finally {
                    if (inStream != null)
                    {
                        inStream.Close();
                    }

                    if (outStream != null)
                    {
                        outStream.Close();
                    }
                }

                break;
            }

            // Devkit commands
            switch (cmd)
            {
            case "viewServerInfo":
                if (!man.Config.GetBool("general.debug", false))
                {
                    throw new ManagerException("You have to enable debugging in config by setting general.debug to true.");
                }

                context.Response.ContentType = "text/html";
                context.Trace.IsEnabled      = true;

                context.Response.Write("<pre># Config from Web.config\r\n\r\n");

                foreach (string key in man.Config.Keys)
                {
                    context.Response.Write(key + "=" + man.Config[key] + "\r\n");
                }

                context.Response.Write("</pre>");

                break;

            case "downloadServerInfo":
                if (!man.Config.GetBool("general.debug", false))
                {
                    throw new ManagerException("You have to enable debugging in config by setting general.debug to true.");
                }

                context.Response.AppendHeader("Content-Disposition", "attachment; filename=trace.htm");
                context.Response.ContentType = "text/html";
                context.Trace.IsEnabled      = true;

                context.Response.Write("<pre># Config from Web.config\r\n\r\n");

                foreach (string key in man.Config.Keys)
                {
                    context.Response.Write(key + "=" + man.Config[key] + "\r\n");
                }

                context.Response.Write("</pre>");

                break;

            case "viewLog":
                if (!man.Config.GetBool("general.debug", false))
                {
                    throw new ManagerException("You have to enable debugging in config by setting general.debug to true.");
                }

                if (input["level"] == "debug")
                {
                    if (File.Exists(man.MapPath("logs/debug.log")))
                    {
                        context.Response.WriteFile(man.MapPath("logs/debug.log"));
                    }
                }
                else
                {
                    if (File.Exists(man.MapPath("logs/error.log")))
                    {
                        context.Response.WriteFile(man.MapPath("logs/error.log"));
                    }
                }

                break;

            case "clearLog":
                if (!man.Config.GetBool("general.debug", false))
                {
                    throw new ManagerException("You have to enable debugging in config by setting general.debug to true.");
                }

                if (input["level"] == "debug")
                {
                    File.Delete(man.MapPath("logs/debug.log"));
                }
                else
                {
                    File.Delete(man.MapPath("logs/error.log"));
                }

                context.Response.Write("Log cleared.");

                break;
            }

            return(true);
        }
Пример #33
0
 /// <summary>
 ///  Gets called when data is streamed to client. This method should setup HTTP headers, content type
 ///  etc and simply send out the binary data to the client and the return false ones that is done.
 /// </summary>
 /// <param name="man">ManagerEngine reference that the plugin is assigned to.</param>
 /// <param name="cmd">Stream command that is to be performed.</param>
 /// <param name="input">Array of input arguments.</param>
 /// <returns>true/false if the execution of the event chain should continue execution.</returns>
 public virtual bool OnStream(ManagerEngine man, string cmd, NameValueCollection input)
 {
     return true;
 }
Пример #34
0
 /// <summary>
 ///  Gets called when data is streamed/uploaded from client. This method should take care of
 ///  any uploaded files and move them to the correct location.
 /// </summary>
 /// <param name="man">ManagerEngine reference that the plugin is assigned to.</param>
 /// <param name="cmd">Upload command that is to be performed.</param>
 /// <param name="input">Array of input arguments.</param>
 /// <returns>true/false if the execution of the event chain should continue execution.</returns>
 public virtual object OnUpload(ManagerEngine man, string cmd, NameValueCollection input)
 {
     return(null);
 }
Пример #35
0
        private ResultSet ListFiles(ManagerEngine man, string cmd, Hashtable input)
        {
            ResultSet       rs = new ResultSet(new string[] { "name", "path", "size", "type", "created", "modified", "attribs", "custom" });
            Hashtable       customInfo;
            ArrayList       files = new ArrayList();
            BasicFileFilter filter;
            IFile           listDir;
            ManagerConfig   config = man.Config;
            bool            onlyDirs, onlyFiles, remember, hasParent = false;
            string          type, attribs, path, rootPath, configPrefixes, name, tmpPath;
            int             pages, pageSize;
            HttpRequest     req  = HttpContext.Current.Request;
            HttpResponse    resp = HttpContext.Current.Response;

            // Handle remember_last_path state
            if (input["remember_last_path"] != null)
            {
                // URL specified
                if (((string)input["path"]) == "{default}")
                {
                    if (input["url"] != null && (string)input["url"] != "")
                    {
                        input["path"] = man.ConvertURIToPath((string)input["url"]);
                    }
                }

                path = (string)input["path"];

                if (input["remember_last_path"] is bool)
                {
                    remember = (bool)input["remember_last_path"];
                }
                else if (((string)input["remember_last_path"]) != "auto")
                {
                    remember = StringUtils.CheckBool((string)input["remember_last_path"]);
                }
                else
                {
                    remember = config.GetBool("general.remember_last_path", false);
                }

                // Get/set cookie
                if (remember)
                {
                    if (path == "{default}" && req.Cookies["MCManager_" + man.Prefix + "_lastPath"] != null)
                    {
                        tmpPath = req.Cookies["MCManager_" + man.Prefix + "_lastPath"].Value;

                        if (tmpPath != null && man.GetFSFromPath(tmpPath) == "file")
                        {
                            input["path"] = tmpPath;
                        }
                    }
                    else
                    {
                        HttpCookie cookie = new HttpCookie("MCManager_" + man.Prefix + "_lastPath");

                        cookie.Expires = DateTime.Now.AddDays(30);
                        cookie.Value   = path;

                        resp.Cookies.Remove("MCManager_" + man.Prefix + "_lastPath");

                        if (man.GetFSFromPath(path) == "file")
                        {
                            resp.Cookies.Add(cookie);
                        }
                    }
                }
            }

            path           = man.DecryptPath((string)input["path"]);
            rootPath       = man.DecryptPath((string)input["root_path"]);
            onlyDirs       = input["only_dirs"] != null && (bool)input["only_dirs"];
            onlyFiles      = input["only_files"] != null && (bool)input["only_files"];
            configPrefixes = (string)input["config"];

            if (man.GetFSFromPath(path) == "file" && !man.VerifyPath(path))
            {
                path = man.Config.Get("filesystem.path");
            }

            // Move path into rootpath
            if (rootPath != null && !PathUtils.IsChildPath(rootPath, path) && man.GetFSFromPath(path) == "file")
            {
                path = rootPath;
            }

            listDir = man.GetFile(path);

            // Use default path instead
            if (!listDir.Exists)
            {
                path    = config["filesystem.path"];
                listDir = man.GetFile(path);
            }

            rs.Header["path"]        = man.EncryptPath(path);
            rs.Header["visual_path"] = man.ToVisualPath(path, rootPath);
            rs.Header["attribs"]     = (listDir.CanRead ? "R" : "-") + (listDir.CanWrite ? "W" : "-");

            // List files
            if (listDir.IsDirectory)
            {
                config = listDir.Config;

                // Return part of the config
                if (configPrefixes != null)
                {
                    rs.Config = man.GetJSConfig(config, configPrefixes);
                }

                // Verify filesystem config
                filter = new BasicFileFilter();
                filter.IncludeDirectoryPattern = config["filesystem.include_directory_pattern"];
                filter.ExcludeDirectoryPattern = config["filesystem.exclude_directory_pattern"];
                filter.IncludeFilePattern      = config["filesystem.include_file_pattern"];
                filter.ExcludeFilePattern      = config["filesystem.exclude_file_pattern"];
                filter.IncludeExtensions       = config["filesystem.extensions"];
                filter.OnlyDirs = onlyDirs;

                // Directory is hidden use parent dir
                if (!filter.Accept(listDir))
                {
                    listDir = listDir.ParentFile;

                    rs.Header["path"]        = man.EncryptPath(listDir.AbsolutePath);
                    rs.Header["visual_path"] = man.ToVisualPath(listDir.AbsolutePath, rootPath);
                }

                if (input["filter"] != null)
                {
                    filter.IncludeWildcardPattern = (string)input["filter"];
                }

                if (input["only_files"] != null)
                {
                    filter.OnlyFiles = onlyFiles;
                }
                else if (!onlyDirs)
                {
                    filter.OnlyFiles = !config.GetBool("filesystem.list_directories", false);
                }

                // Add parent
                if (path != rootPath && input["only_files"] == null && (input["only_dirs"] != null || man.Config.GetBool("filesystem.list_directories", true)))
                {
                    if (man.VerifyPath(listDir.Parent))
                    {
                        hasParent = true;
                        rs.Add("..", man.EncryptPath(listDir.Parent), -1, "parent", "", "", "", new NameValueCollection());
                    }
                }

                // Setup input filter
                BasicFileFilter inputFilter = new BasicFileFilter();

                if (input["include_directory_pattern"] != null)
                {
                    filter.IncludeDirectoryPattern = (string)input["include_directory_pattern"];
                }

                if (input["exclude_directory_pattern"] != null)
                {
                    filter.ExcludeDirectoryPattern = (string)input["exclude_directory_pattern"];
                }

                if (input["include_file_pattern"] != null)
                {
                    filter.IncludeFilePattern = (string)input["include_file_pattern"];
                }

                if (input["exclude_file_pattern"] != null)
                {
                    filter.ExcludeFilePattern = (string)input["exclude_file_pattern"];
                }

                if (input["extensions"] != null)
                {
                    filter.IncludeExtensions = (string)input["extensions"];
                }

                // Combine the filters
                CombinedFileFilter combinedFilter = new CombinedFileFilter();

                combinedFilter.AddFilter(inputFilter);
                combinedFilter.AddFilter(filter);

                files.AddRange(listDir.ListFilesFiltered(combinedFilter));

                if (input["page_size"] != null)
                {
                    if (hasParent)
                    {
                        pageSize = Convert.ToInt32(input["page_size"]) - 1;
                    }
                    else
                    {
                        pageSize = Convert.ToInt32(input["page_size"]);
                    }

                    pages = (int)Math.Ceiling(files.Count / (double)pageSize);

                    // Setup response
                    rs.Header["pages"] = (pages > 1 ? pages : 1);
                    rs.Header["count"] = files.Count;

                    // Remove non visible files
                    int start = Convert.ToInt32(input["page"]) * pageSize;
                    int len   = pageSize;
                    len   = start + len > files.Count ? len - ((start + len) - files.Count) : len;
                    files = files.GetRange(start, len);
                }

                // Sort Files
                files.Sort(new FileComparer());

                // Output folders
                foreach (IFile file in files)
                {
                    if (file.IsDirectory)
                    {
                        // Setup attribs
                        attribs = "RW";

                        type = "folder";

                        // Fill custom info
                        customInfo = new Hashtable();
                        man.DispatchEvent(EventType.CustomInfo, file, "list", customInfo);

                        // Special treatment of roots
                        name = file.Name;
                        if (path == "root:///")
                        {
                            if (man.RootNames[file.AbsolutePath] != null)
                            {
                                name = man.RootNames[file.AbsolutePath];
                            }
                        }

                        // Add to resultset
                        rs.Add(
                            name,
                            man.EncryptPath(file.AbsolutePath),
                            file.IsDirectory ? -1 : file.Length,
                            type,
                            StringUtils.GetDate(file.CreationDate, listDir.Config.Get("filesystem.datefmt", "yyyy-MM-dd HH:mm")),
                            StringUtils.GetDate(file.LastModified, listDir.Config.Get("filesystem.datefmt", "yyyy-MM-dd HH:mm")),
                            attribs,
                            customInfo
                            );
                    }
                }

                // Output files
                foreach (IFile file in files)
                {
                    if (file.IsFile)
                    {
                        // Setup attribs
                        attribs = "RW";

                        type = PathUtils.GetExtension(file.AbsolutePath).ToLower();

                        // Fill custom info
                        customInfo = new Hashtable();
                        man.DispatchEvent(EventType.CustomInfo, file, "list", customInfo);

                        // Add to resultset
                        rs.Add(
                            file.Name,
                            man.EncryptPath(file.AbsolutePath),
                            file.Length,
                            type,
                            StringUtils.GetDate(file.CreationDate, listDir.Config.Get("filesystem.datefmt", "yyyy-MM-dd HH:mm")),
                            StringUtils.GetDate(file.LastModified, listDir.Config.Get("filesystem.datefmt", "yyyy-MM-dd HH:mm")),
                            attribs,
                            customInfo
                            );
                    }
                }
            }
            else
            {
                throw new ManagerException("{#error.file_not_exists}");
            }

            return(rs);
        }
Пример #36
0
 private object LoopBack(ManagerEngine man, Hashtable input)
 {
     return(input);
 }
Пример #37
0
        private IFile MakeThumb(ManagerEngine man, IFile file)
        {
            ManagerConfig config = file.Config;
            IFile thumbFile;
            int thumbWidth, thumbHeight;
            int configWidth, configHeight;
            double scale;
            MediaInfo thumbSize = new MediaInfo();

            // Is not enabled
            if (!config.GetBool("thumbnail.enabled", true))
                return file;

            // Setup thumbnail path
            IFile thumbDir = man.GetFile(file.Parent, config.Get("thumbnail.folder", "mcith"));
            if (!thumbDir.Exists)
                thumbDir.MkDir();

            configWidth = config.GetInt("thumbnail.width", 90);
            configHeight = config.GetInt("thumbnail.height", 90);

            // Make thumbnail
            thumbFile = man.GetFile(thumbDir.AbsolutePath, config.Get("thumbnail.prefix", "mcith") + file.Name);
            MediaInfo imageSize = new MediaInfo(file.AbsolutePath);

            // Need to scale?
            if (imageSize.Width < configWidth && imageSize.Height < configHeight)
                return file;

            // To large
            if (imageSize.Width > config.GetInt("thumbnail.max_width", 65535) || imageSize.Height > config.GetInt("thumbnail.max_height", 65535))
                return file;

            // Constrain proportions
            scale = Math.Min(configWidth / (double) imageSize.Width, configHeight / (double) imageSize.Height);

            if (config.Get("thumbnail.scale_mode", "percentage") == "percentage") {
                thumbWidth = scale > 1 ? imageSize.Width : (int) Math.Floor(imageSize.Width * scale);
                thumbHeight = scale > 1 ? imageSize.Height : (int) Math.Floor(imageSize.Height * scale);
            } else {
                thumbWidth = config.GetInt("thumbnail.width", 90);
                thumbHeight = config.GetInt("thumbnail.height", 90);
            }

            if (thumbFile.Exists)
                thumbSize = new MediaInfo(thumbFile.AbsolutePath);

            if (!thumbFile.Exists || thumbSize.Width != thumbWidth || thumbSize.Height != thumbHeight || file.LastModified != thumbFile.LastModified)
                ImageUtils.MakeThumbnail(file.AbsolutePath, thumbFile.AbsolutePath, thumbWidth, thumbHeight, file.LastModified, config.GetInt("thumbnail.jpeg_quality", 75));

            return thumbFile;
        }
Пример #38
0
 /// <summary>
 ///  Gets called when custom data is to be added for a file custom data can for example be
 ///  plugin specific name value items that should get added into a file listning.
 /// </summary>
 /// <param name="man">ManagerEngine reference that the plugin is assigned to.</param>
 /// <param name="file">File reference to add custom info/data to.</param>
 /// <param name="type">Where is the info needed for example list or info.</param>
 /// <param name="custom">Name/Value array to add custom items to.</param>
 /// <returns>true/false if the execution of the event chain should continue execution.</returns>
 public virtual bool OnCustomInfo(ManagerEngine man, IFile file, string type, Hashtable custom)
 {
     return(true);
 }
Пример #39
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}");
            }
        }
Пример #40
0
 /// <summary>
 ///  Gets called when the user selects a file and inserts it into TinyMCE or a form or similar.
 /// </summary>
 /// <param name="man">ManagerEngine reference that the plugin is assigned to.</param>
 /// <param name="file">Implementation of the BaseFile class that was inserted/returned to external system.</param>
 /// <returns>true/false if the execution of the event chain should continue execution.</returns>
 public virtual bool OnInsertFile(ManagerEngine man, IFile file)
 {
     return(true);
 }
Пример #41
0
        private bool StreamThumb(ManagerEngine man, NameValueCollection input)
        {
            HttpContext context = HttpContext.Current;
            string path, contentType;
            ManagerConfig config;
            IFile file;

            // Get input
            path = man.DecryptPath((string) input["path"]);

            // Find mime type
            contentType = man.MimeTypes[PathUtils.GetExtension(path).ToLower()];
            if (contentType != null)
                context.Response.ContentType = contentType;

            // Get and stream file
            file = man.GetFile(path);
            config = file.Config;
            try {
                path = MakeThumb(man, file).AbsolutePath;
            } catch (Exception) {
                // Ignore
            }

            // Stream thumbnail
            if (file is LocalFile)
                context.Response.WriteFile(path);
            else
                IOUtils.StreamFromTo(file.Open(FileMode.Open), context.Response.OutputStream, 1024);

            return false;
        }
Пример #42
0
 /// <summary>
 ///  Gets called on a authenication request. This method should check sessions or simmilar to verify that the user has access to the backend.
 ///  This method should return true if the current request is authenicated or false if it's not.
 /// </summary>
 /// <param name="man">ManagerEngine reference that the plugin is assigned to.</param>
 /// <returns>true/false if the user is authenticated</returns>
 public virtual bool OnAuthenticate(ManagerEngine man)
 {
     return(false);
 }
Пример #43
0
 /// <summary>
 ///  Gets called before a RPC command is handled.
 /// </summary>
 /// <param name="man">ManagerEngine reference that the plugin is assigned to.</param>
 /// <param name="cmd">RPC Command to be executed.</param>
 /// <param name="input">RPC input object data.</param>
 /// <returns>true/false if the execution of the event chain should continue execution.</returns>
 public virtual bool OnBeforeRPC(ManagerEngine man, string cmd, Hashtable input)
 {
     return true;
 }
Пример #44
0
 /// <summary>
 ///  Gets called before the ManagerEngine is initialized. This method
 ///  can setup config and language pack data based on the prefix.
 /// </summary>
 /// <param name="man">ManagerEngine reference that the plugin is assigned to.</param>
 /// <param name="prefix">Prefix to use when setting up config etc.</param>
 /// <returns>true/false if the user is authenticated</returns>
 public virtual bool OnPreInit(ManagerEngine man, string prefix)
 {
     return(true);
 }
Пример #45
0
 /// <summary>
 ///  Gets called after any authenication is performed and verified.
 ///  This method should return false if the execution chain is to be broken.
 /// </summary>
 /// <param name="man">ManagerEngine reference that the plugin is assigned to.</param>
 /// <returns>true/false if the execution of the event chain should continue execution.</returns>
 public virtual bool OnInit(ManagerEngine man)
 {
     return true;
 }
Пример #46
0
 /// <summary>
 ///  Gets called when a user has logged out from the system. This event should be dispatched from the logout page.
 ///  These events is not fired internaly and should be fired/dispatched externally.
 /// </summary>
 /// <param name="man">ManagerEngine reference that the plugin is assigned to.</param>
 /// <returns>true/false if the execution of the event chain should continue execution.</returns>
 public virtual bool OnLogout(ManagerEngine man)
 {
     return(true);
 }
Пример #47
0
 /// <summary>
 ///  Gets called when a user has logged out from the system. This event should be dispatched from the logout page.
 ///  These events is not fired internaly and should be fired/dispatched externally.
 /// </summary>
 /// <param name="man">ManagerEngine reference that the plugin is assigned to.</param>
 /// <returns>true/false if the execution of the event chain should continue execution.</returns>
 public virtual bool OnLogout(ManagerEngine man)
 {
     return true;
 }
Пример #48
0
 /// <summary>
 ///  Gets called before data is streamed/uploaded from client.
 /// </summary>
 /// <param name="man">ManagerEngine reference that the plugin is assigned to.</param>
 /// <param name="cmd">Upload command that is to was performed.</param>
 /// <param name="input">Array of input arguments.</param>
 /// <returns>true/false if the execution of the event chain should continue execution.</returns>
 public virtual bool OnAfterUpload(ManagerEngine man, string cmd, NameValueCollection input)
 {
     return true;
 }
Пример #49
0
 /// <summary>
 ///  Gets executed when a RPC command is to be executed.
 /// </summary>
 /// <param name="man">ManagerEngine reference that the plugin is assigned to.</param>
 /// <param name="cmd">RPC Command to be executed.</param>
 /// <param name="input">RPC input object data.</param>
 /// <returns>true/false if the execution of the event chain should continue execution.</returns>
 public virtual object OnRPC(ManagerEngine man, string cmd, Hashtable input)
 {
     return null;
 }
Пример #50
0
 /// <summary>
 ///  Gets called before a file action occurs for example before a rename or copy.
 /// </summary>
 /// <param name="man">ManagerEngine reference that the plugin is assigned to.</param>
 /// <param name="action">File action type.</param>
 /// <param name="file1">File object 1 for example from in a copy operation.</param>
 /// <param name="file2">File object 2 for example to in a copy operation. Might be null in for example a delete.</param>
 /// <returns>true/false if the execution of the event chain should continue execution.</returns>
 public virtual bool OnBeforeFileAction(ManagerEngine man, FileAction action, IFile file1, IFile file2)
 {
     return true;
 }
Пример #51
0
 /// <summary>
 ///  Gets called when data is streamed/uploaded from client. This method should take care of
 ///  any uploaded files and move them to the correct location.
 /// </summary>
 /// <param name="man">ManagerEngine reference that the plugin is assigned to.</param>
 /// <param name="cmd">Upload command that is to be performed.</param>
 /// <param name="input">Array of input arguments.</param>
 /// <returns>true/false if the execution of the event chain should continue execution.</returns>
 public virtual object OnUpload(ManagerEngine man, string cmd, NameValueCollection input)
 {
     return null;
 }
Пример #52
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}");
            }
        }
Пример #53
0
 /// <summary>
 ///  Gets called on a authenication request. This method should check sessions or simmilar to verify that the user has access to the backend.
 ///  This method should return true if the current request is authenicated or false if it's not.
 /// </summary>
 /// <param name="man">ManagerEngine reference that the plugin is assigned to.</param>
 /// <returns>true/false if the user is authenticated</returns>
 public virtual bool OnAuthenticate(ManagerEngine man)
 {
     return false;
 }
Пример #54
0
        private ResultSet GetMediaInfo(ManagerEngine man, Hashtable input)
        {
            ResultSet rs = new ResultSet(new string[]{"name", "path", "url", "size", "type", "created", "modified", "width", "height", "attribs", "next", "prev", "custom"});
            BasicFileFilter fileFilter;
            IFile file, parent;
            IFile[] files;
            string prev, next, attribs, url, ext;
            int width, height;
            bool match;
            Hashtable customInfo = new Hashtable();
            ManagerConfig config;

            if (input["url"] != null)
                input["path"] = man.ConvertURIToPath(new Uri((string) input["url"]).AbsolutePath);

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

            if (parent.IsDirectory) {
                // Setup file filter
                fileFilter = new BasicFileFilter();
                //fileFilter->setDebugMode(true);
                fileFilter.IncludeDirectoryPattern = config["filesystem.include_directory_pattern"];
                fileFilter.ExcludeDirectoryPattern = config["filesystem.exclude_directory_pattern"];
                fileFilter.IncludeFilePattern = config["filesystem.include_file_pattern"];
                fileFilter.ExcludeFilePattern = config["filesystem.exclude_file_pattern"];
                fileFilter.IncludeExtensions = config["filesystem.extensions"];
                fileFilter.OnlyFiles = true;

                // List files
                files = parent.ListFilesFiltered(fileFilter);
            } else
                throw new ManagerException("{#error.file_not_exists}");

            match = false;
            prev = "";
            next = "";

            // Find next and prev
            foreach (IFile curFile in files) {
                if (curFile.AbsolutePath == file.AbsolutePath) {
                    match = true;
                    continue;
                } else if (!match)
                    prev = curFile.AbsolutePath;

                if (match) {
                    next = curFile.AbsolutePath;
                    break;
                }
            }

            ext = PathUtils.GetExtension(file.Name).ToLower();

            // Input default size?
            MediaInfo size = new MediaInfo(file.AbsolutePath);
            width = size.Width != -1 ? size.Width : 425;
            height = size.Height != -1 ? size.Height : 350;

            // Get custom info
            man.DispatchEvent(EventType.CustomInfo, file, "info", customInfo);

            attribs = (file.CanRead && config.GetBool("filesystem.readable", true) ? "R" : "-") + (file.CanWrite && config.GetBool("filesystem.writable", true) ? "W" : "-");
            url = PathUtils.RemoveTrailingSlash(config["preview.urlprefix"]) + man.ConvertPathToURI(file.AbsolutePath);
            rs.Add(file.Name,
                       man.EncryptPath(file.AbsolutePath),
                       url,
                       file.Length,
                       ext,
                       StringUtils.GetDate(file.CreationDate, config.Get("filesystem.datefmt", "yyyy-MM-dd HH:mm")),
                       StringUtils.GetDate(file.LastModified, config.Get("filesystem.datefmt", "yyyy-MM-dd HH:mm")),
                       width,
                       height,
                       attribs,
                       man.EncryptPath(next),
                       man.EncryptPath(prev),
                       customInfo);

            return rs;
        }
Пример #55
0
 /// <summary>
 ///  Gets called before data is streamed/uploaded from client.
 /// </summary>
 /// <param name="man">ManagerEngine reference that the plugin is assigned to.</param>
 /// <param name="cmd">Upload command that is to was performed.</param>
 /// <param name="input">Array of input arguments.</param>
 /// <returns>true/false if the execution of the event chain should continue execution.</returns>
 public virtual bool OnAfterUpload(ManagerEngine man, string cmd, NameValueCollection input)
 {
     return(true);
 }
Пример #56
0
 /// <summary>
 ///  Returns a file based on path, child path and type.
 /// </summary>
 /// <param name="man">Manager engine reference.</param>
 /// <param name="path">Absolute path to file or directory.</param>
 /// <param name="child">Child path inside directory or empty string.</param>
 /// <param name="type">File type, force it to be a file or directory.</param>
 public IFile GetFile(ManagerEngine man, string path, string child, FileType type)
 {
     return(new RootFile(man, path, child, type));
 }