/// <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; }
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; }
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; }
/// <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; }
/// <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); }
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); }