protected void rptItems_DataBinding(object sender, EventArgs e) { if (pageFullName == null) { return; } // Build a DataTable containing the proper information DataTable table = new DataTable("Items"); table.Columns.Add("Name"); table.Columns.Add("Size"); table.Columns.Add("Link"); string currentWiki = Tools.DetectCurrentWiki(); foreach (IFilesStorageProviderV40 provider in Collectors.CollectorsBox.FilesProviderCollector.GetAllProviders(currentWiki)) { string[] attachments = provider.ListPageAttachments(pageFullName); foreach (string s in attachments) { DataRow row = table.NewRow(); row["Name"] = s; row["Size"] = Tools.BytesToString(provider.GetPageAttachmentDetails(pageFullName, s).Size); row["Link"] = "GetFile.aspx?File=" + Tools.UrlEncode(s).Replace("'", "'") + "&AsStreamAttachment=1&Provider=" + provider.GetType().FullName + "&IsPageAttachment=1&Page=" + Tools.UrlEncode(pageFullName); table.Rows.Add(row); } } rptItems.DataSource = table; }
protected void Page_Load(object sender, EventArgs e) { string currentWiki = Tools.DetectCurrentWiki(); if (!Page.IsPostBack) { // Localized strings for JavaScript StringBuilder sb = new StringBuilder(); sb.Append(@"<script type=""text/javascript"">" + "\r\n<!--\n"); sb.Append("var ConfirmMessage = '"); sb.Append(Properties.Messages.ConfirmOperation); sb.Append("';\r\n"); sb.AppendFormat("var UploadControl = '{0}';\r\n", fileUpload.ClientID); //sb.AppendFormat("var RefreshCommandParameter = '{0}';\r\n", btnRefresh.UniqueID); sb.AppendFormat("var OverwriteControl = '{0}';\r\n", chkOverwrite.ClientID); sb.Append("// -->\n</script>\n"); lblStrings.Text = sb.ToString(); // Setup upload information (max file size, allowed file types) lblUploadFilesInfo.Text = lblUploadFilesInfo.Text.Replace("$1", Tools.BytesToString(GlobalSettings.MaxFileSize * 1024)); sb = new StringBuilder(); string[] aft = Settings.GetAllowedFileTypes(currentWiki); for (int i = 0; i < aft.Length; i++) { sb.Append(aft[i].ToUpper()); if (i != aft.Length - 1) { sb.Append(", "); } } lblUploadFilesInfo.Text = lblUploadFilesInfo.Text.Replace("$2", sb.ToString()); // Load Providers foreach (IFilesStorageProviderV40 prov in Collectors.CollectorsBox.FilesProviderCollector.GetAllProviders(currentWiki)) { ListItem item = new ListItem(prov.Information.Name, prov.GetType().FullName); if (item.Value == GlobalSettings.DefaultFilesProvider) { item.Selected = true; } lstProviders.Items.Add(item); } if (CurrentPage == null) { btnUpload.Enabled = false; } } // Set provider provider = Collectors.CollectorsBox.FilesProviderCollector.GetProvider(lstProviders.SelectedValue, currentWiki); if (!Page.IsPostBack) { rptItems.DataBind(); } DetectPermissions(); SetupControls(); }
protected void rptItems_DataBinding(object sender, EventArgs e) { provider = Collectors.FilesProviderCollector.GetProvider(lstProviders.SelectedValue); if (provider == null || CurrentPage == null) { return; } // Build a DataTable containing the proper information var table = new DataTable("Items"); table.Columns.Add("Name"); table.Columns.Add("Size"); table.Columns.Add("Editable", typeof(bool)); table.Columns.Add("Page"); table.Columns.Add("Link"); table.Columns.Add("Downloads"); table.Columns.Add("CanDelete", typeof(bool)); table.Columns.Add("CanDownload", typeof(bool)); var attachments = provider.ListPageAttachments(CurrentPage); foreach (var s in attachments) { FileDetails details = provider.GetPageAttachmentDetails(CurrentPage, s); DataRow row = table.NewRow(); var ext = Path.GetExtension(s).ToLowerInvariant(); row["Name"] = s; row["Size"] = Tools.BytesToString(details.Size); row["Editable"] = canUpload && canDelete && (ext == ".jpg" || ext == ".jpeg" || ext == ".png"); row["Page"] = CurrentPage.FullName; if (canDownload) { row["Link"] = "GetFile.aspx?File=" + Tools.UrlEncode(s).Replace("'", "'") + "&AsStreamAttachment=1&Provider=" + provider.GetType().FullName + "&IsPageAttachment=1&Page=" + Tools.UrlEncode(CurrentPage.FullName) + "&NoHit=1"; } else { row["Link"] = ""; } row["Downloads"] = details.RetrievalCount.ToString(); row["CanDelete"] = canDelete; row["CanDownload"] = canDownload; table.Rows.Add(row); } rptItems.DataSource = table; }
/// <summary> /// Initializes a new instance of the <see cref="T:IndexRow" /> class. /// </summary> /// <param name="provider">The original provider.</param> public IndexRow(IPagesStorageProviderV30 provider) { this.provider = provider.Information.Name; providerType = provider.GetType().FullName; int docCount, wordCount, matchCount; long size; provider.GetIndexStats(out docCount, out wordCount, out matchCount, out size); this.documents = docCount.ToString(); this.words = wordCount.ToString(); this.occurrences = matchCount.ToString(); this.size = Tools.BytesToString(size); this.isOk = !provider.IsIndexCorrupted; }
/// <summary> /// Prints the search statistics. /// </summary> /// <param name="time">The time the search required.</param> /// <param name="results">The number of results.</param> private void PrintStats(TimeSpan time, int results) { int totalDocuments = 0; int totalWords = 0; long totalSize = 0; foreach (IPagesStorageProviderV30 prov in Collectors.PagesProviderCollector.AllProviders) { int dc, wc, oc; long s; prov.GetIndexStats(out dc, out wc, out oc, out s); totalDocuments += dc; totalWords += wc; totalSize += s; } lblStats.Text = string.Format(Properties.Messages.SearchStats, Tools.BytesToString(totalSize), totalDocuments, totalWords, time.TotalSeconds, results); }
private List <TreeElement> BuildFilesSubTree(IFilesStorageProviderV40 provider, string path) { string[] dirs = new string[0]; string[] files = new string[0]; if (chkFilesAttachments.Checked) { // Load page attachments files = provider.ListPageAttachments(currentPage.FullName); } else { // Load files dirs = provider.ListDirectories(path); files = provider.ListFiles(path); } List <TreeElement> result = new List <TreeElement>(100); foreach (string d in dirs) { TreeElement item = new TreeElement(d, Tools.ExtractDirectoryName(d), BuildFilesSubTree(provider, d)); // Do not display empty folders to reduce "noise" if (item.SubItems.Count > 0) { result.Add(item); } } foreach (string f in files) { long size = chkFilesAttachments.Checked ? provider.GetPageAttachmentDetails(currentPage.FullName, f).Size : provider.GetFileDetails(f).Size; TreeElement item = new TreeElement(f, f.Substring(f.LastIndexOf("/") + 1) + " (" + Tools.BytesToString(size) + ")", "javascript:return SelectFile('" + (chkFilesAttachments.Checked ? "(" + Tools.UrlEncode(currentPage.FullName) + ")" : "") + "', '" + f.Replace("'", "\\\\\\'") + "');"); result.Add(item); } return(result); }
protected void Page_Load(object sender, EventArgs e) { string filename = Request["File"]; if (string.IsNullOrEmpty(filename)) { Response.Write("No file specified."); return; } // Remove ".." sequences that might be a security issue filename = filename.Replace("..", ""); string page = Request["Page"]; PageInfo pageInfo = Pages.FindPage(page); bool isPageAttachment = !string.IsNullOrEmpty(page); if (isPageAttachment && pageInfo == null) { Response.StatusCode = 404; Response.Write("File not found."); return; } IFilesStorageProviderV30 provider = null; if (!string.IsNullOrEmpty(Request["Provider"])) { provider = Collectors.FilesProviderCollector.GetProvider(Request["Provider"]); } else { if (isPageAttachment) { provider = FilesAndAttachments.FindPageAttachmentProvider(pageInfo, filename); } else { provider = FilesAndAttachments.FindFileProvider(filename); } } if (provider == null) { Response.StatusCode = 404; Response.Write("File not found."); return; } string size = Request["Size"]; if (string.IsNullOrEmpty(size)) { size = "small"; } size = size.ToLowerInvariant(); // Verify permissions bool canDownload = false; if (pageInfo != null) { canDownload = AuthChecker.CheckActionForPage(pageInfo, Actions.ForPages.DownloadAttachments, SessionFacade.GetCurrentUsername(), SessionFacade.GetCurrentGroupNames()); } else { string dir = Tools.GetDirectoryName(filename); canDownload = AuthChecker.CheckActionForDirectory(provider, dir, Actions.ForDirectories.DownloadFiles, SessionFacade.GetCurrentUsername(), SessionFacade.GetCurrentGroupNames()); } if (!canDownload) { Response.StatusCode = 401; } // Contains the image bytes MemoryStream ms = new MemoryStream(1048576); long fileSize = 0; // Load from provider if (string.IsNullOrEmpty(page)) { bool retrieved = false; try { retrieved = provider.RetrieveFile(filename, ms, false); } catch (ArgumentException ex) { Log.LogEntry("Attempted to create thumb of inexistent file (" + filename + ")\n" + ex, EntryType.Warning, Log.SystemUsername); } if (!retrieved) { Response.StatusCode = 404; Response.Write("File not found."); return; } fileSize = provider.GetFileDetails(filename).Size; } else { if (pageInfo == null) { Response.StatusCode = 404; Response.Write("Page not found."); return; } bool retrieved = false; try { retrieved = provider.RetrievePageAttachment(pageInfo, filename, ms, false); } catch (ArgumentException ex) { Log.LogEntry("Attempted to create thumb of inexistent attachment (" + page + "/" + filename + ")\n" + ex, EntryType.Warning, Log.SystemUsername); } if (!retrieved) { Response.StatusCode = 404; Response.Write("File not found."); return; } fileSize = provider.GetPageAttachmentDetails(pageInfo, filename).Size; } ms.Seek(0, SeekOrigin.Begin); int rotation = 0; int.TryParse(Request["Rot"], out rotation); // Load the source image System.Drawing.Image source = System.Drawing.Image.FromStream(ms); // Destination bitmap Bitmap result = null; System.Drawing.Imaging.PixelFormat pixelFormat = System.Drawing.Imaging.PixelFormat.Format32bppArgb; if (size == "big") { // Big thumb (outer size 200x200) result = new Bitmap(200, 200, pixelFormat); } else if (size == "imgeditprev") { // Image Editor Preview thumb (outer size from Request["dim"], if null 200x200) if (!string.IsNullOrEmpty(Request["Width"]) && !string.IsNullOrEmpty(Request["Height"])) { try { result = new Bitmap( rotation != 90 && rotation != 270 ? int.Parse(Request["Width"]) : int.Parse(Request["Height"]), rotation != 90 && rotation != 270 ? int.Parse(Request["Height"]) : int.Parse(Request["Width"]), pixelFormat); } catch (FormatException) { result = new Bitmap(200, 200, pixelFormat); } } else { result = new Bitmap(200, 200, pixelFormat); } } else { // Small thumb (outer size 48x48) result = new Bitmap(48, 48, pixelFormat); } // Get Graphics object for destination bitmap Graphics g = Graphics.FromImage(result); if (source.PixelFormat == System.Drawing.Imaging.PixelFormat.Format32bppArgb) { g.Clear(Color.Transparent); } else { g.Clear(Color.White); } g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; g.SmoothingMode = SmoothingMode.HighQuality; g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear; g.TranslateTransform(result.Width / 2, result.Height / 2); g.RotateTransform(rotation); g.TranslateTransform(-result.Width / 2, -result.Height / 2); // Draw bitmap g.DrawImage(source, GetImageRectangle(result.Width, result.Height, rotation != 90 && rotation != 270 ? source.Width : source.Height, rotation != 90 && rotation != 270 ? source.Height : source.Width, rotation == 90 || rotation == 270)); if (!string.IsNullOrEmpty(Request["Info"]) && size == "big") { // Draw image information RectangleF r = new RectangleF(0, 0, result.Width, 20); StringFormat f = new StringFormat(); f.Alignment = StringAlignment.Center; //f.LineAlignment = StringAlignment.Center; GraphicsPath path = new GraphicsPath(); path.AddString(string.Format("{0}x{1} - {2}", source.Width, source.Height, Tools.BytesToString(fileSize)), new FontFamily("Verdana"), 0, 12, new Point(result.Width / 2, 2), f); Pen pen = new Pen(Brushes.Black, 2F); g.DrawPath(pen, path); g.FillPath(Brushes.White, path); } // Write result in output stream in JPEG or PNG format if (source.PixelFormat == System.Drawing.Imaging.PixelFormat.Format32bppArgb) { Response.ContentType = "image/png"; } else { Response.ContentType = "image/jpeg"; } // This invariably throws an exception (A generic error occurred in GDI+) - an intermediate buffer is needed // The possible cause is that PNG format requires to read from the output stream, and Response.OutputStream does not support reading //result.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Png); MemoryStream tempStream = new MemoryStream(65536); // 32 KB if (source.PixelFormat == System.Drawing.Imaging.PixelFormat.Format32bppArgb) { result.Save(tempStream, System.Drawing.Imaging.ImageFormat.Png); } else { result.Save(tempStream, System.Drawing.Imaging.ImageFormat.Jpeg); } Response.OutputStream.Write(tempStream.ToArray(), 0, (int)tempStream.Length); tempStream.Dispose(); ms.Dispose(); source.Dispose(); g.Dispose(); result.Dispose(); }
protected void Page_Load(object sender, EventArgs e) { currentWiki = Tools.DetectCurrentWiki(); if (!Page.IsPostBack) { permissionsManager.CurrentResourceName = "/"; // Localized strings for JavaScript StringBuilder sb = new StringBuilder(); sb.Append(@"<script type=""text/javascript"">" + "\n<!--\n"); sb.Append("var ConfirmMessage = '"); sb.Append(Properties.Messages.ConfirmOperation); sb.Append("';\r\n"); sb.AppendFormat("var CurrentNamespace = \"{0}\";\r\n", Tools.DetectCurrentNamespace()); sb.Append("// -->\n</script>\n"); lblStrings.Text = sb.ToString(); // Setup upload information (max file size, allowed file types) lblUploadFilesInfo.Text = lblUploadFilesInfo.Text.Replace("$1", Tools.BytesToString(GlobalSettings.MaxFileSize * 1024)); sb = new StringBuilder(); string[] aft = Settings.GetAllowedFileTypes(currentWiki); for (int i = 0; i < aft.Length; i++) { sb.Append(aft[i].ToUpper()); if (i != aft.Length - 1) { sb.Append(", "); } } lblUploadFilesInfo.Text = lblUploadFilesInfo.Text.Replace("$2", sb.ToString()); LoadProviders(); permissionsManager.CurrentFilesProvider = lstProviders.SelectedValue; // See if a dir is specified in query string if (Request["Dir"] != null) { string currDir = Request["Dir"]; if (!currDir.StartsWith("/")) { currDir = "/" + currDir; } if (!currDir.EndsWith("/")) { currDir += "/"; } CurrentDirectory = currDir; } } // Set provider provider = Collectors.CollectorsBox.FilesProviderCollector.GetProvider(lstProviders.SelectedValue, currentWiki); // The following actions are verified ***FOR THE CURRENT DIRECTORY***: // - List contents // - Download files // - Upload files // - Create directories // - Delete/Rename files -> hide/show buttons in repeater // - Delete/Rename directories --> hide/show buttons in repeater // - Manage Permissions -> avoid setting permissionsManager.CurrentResourceName/CurrentFilesProvider if not authorized // - Member of Administrators -> hide/show provider selection // ---> recheck everywhere an action is performed DetectPermissions(); if (!Page.IsPostBack) { rptItems.DataBind(); } PopulateBreadcrumb(); SetupControlsForPermissions(); }
protected void rptItems_DataBinding(object sender, EventArgs e) { permissionsManager.CurrentResourceName = CurrentDirectory; permissionsManager.CurrentFilesProvider = lstProviders.SelectedValue; // Build a DataTable containing the proper information DataTable table = new DataTable("Items"); table.Columns.Add("Type"); table.Columns.Add("Name"); table.Columns.Add("Size"); table.Columns.Add("WikiMarkupLink"); table.Columns.Add("Link"); table.Columns.Add("Editable", typeof(bool)); table.Columns.Add("FullPath"); table.Columns.Add("CanDelete", typeof(bool)); table.Columns.Add("CanDownload", typeof(bool)); if (!canList) { lblNoList.Visible = true; rptItems.DataSource = table; // This is empty return; } lblNoList.Visible = false; string currDir = CurrentDirectory; string[] dirs = provider.ListDirectories(currDir); string currentUser = SessionFacade.GetCurrentUsername(); string[] currentGroups = SessionFacade.GetCurrentGroupNames(currentWiki); AuthChecker authChecker = new AuthChecker(Collectors.CollectorsBox.GetSettingsProvider(currentWiki)); foreach (string s in dirs) { bool canListThisSubDir = authChecker.CheckActionForDirectory(provider, s, Actions.ForDirectories.List, currentUser, currentGroups); DataRow row = table.NewRow(); row["Type"] = "D"; row["Name"] = GetItemName(s) /* + "/"*/; row["Size"] = "(" + ((int)(provider.ListFiles(s).Length + provider.ListDirectories(s).Length)).ToString() + ")"; row["WikiMarkupLink"] = " "; row["Link"] = ""; row["Editable"] = false; row["FullPath"] = s; row["CanDelete"] = canDeleteDirs; row["CanDownload"] = canListThisSubDir; table.Rows.Add(row); } string[] files = provider.ListFiles(currDir); foreach (string s in files) { FileDetails details = provider.GetFileDetails(s); DataRow row = table.NewRow(); string ext = Path.GetExtension(s).ToLowerInvariant(); row["Type"] = "F"; row["Name"] = GetItemName(s); row["Size"] = Tools.BytesToString(details.Size); row["WikiMarkupLink"] = "{UP}" + s; if (canDownload) { row["Link"] = "GetFile.aspx?File=" + Tools.UrlEncode(s).Replace("'", "'") + "&AsStreamAttachment=1&Provider=" + provider.GetType().FullName + "&NoHit=1"; } else { row["Link"] = ""; } row["Editable"] = canUpload && canDeleteFiles && (ext == ".jpg" || ext == ".jpeg" || ext == ".png"); row["FullPath"] = s; row["CanDelete"] = canDeleteFiles; row["CanDownload"] = canDownload; table.Rows.Add(row); } rptItems.DataSource = table; }