public static CheckActionForDirectory ( IFilesStorageProviderV30 provider, string directory, string action, string currentUser, string groups ) : bool | ||
provider | IFilesStorageProviderV30 | The provider that manages the directory. |
directory | string | The full path of the directory. |
action | string | The action the user is attempting to perform. |
currentUser | string | The current user. |
groups | string | The groups the user is member of. |
return | bool |
protected void Page_Load(object sender, EventArgs e) { currentWiki = DetectWiki(); SetProvider(); SetInputData(); string currentUser = SessionFacade.GetCurrentUsername(); string[] currentGroups = SessionFacade.GetCurrentGroupNames(currentWiki); string dir = Tools.GetDirectoryName(file); // Verify permissions AuthChecker authChecker = new AuthChecker(Collectors.CollectorsBox.GetSettingsProvider(currentWiki)); bool canUpload = authChecker.CheckActionForDirectory(provider, dir, Actions.ForDirectories.UploadFiles, currentUser, currentGroups); bool canDeleteFiles = authChecker.CheckActionForDirectory(provider, dir, Actions.ForDirectories.DeleteFiles, currentUser, currentGroups); if (!canUpload || !canDeleteFiles) { UrlTools.Redirect("AccessDenied.aspx"); } // Inject the proper stylesheet in page head Literal l = new Literal(); l.Text = Tools.GetIncludes(currentWiki, DetectNamespace()); Page.Header.Controls.Add(l); ResizeImage(); }
/// <summary> /// Detects the permissions of the current user for the current directory. /// </summary> private void DetectPermissions() { var currentUser = SessionFacade.GetCurrentUsername(); var currentGroups = SessionFacade.GetCurrentGroupNames(); canList = AuthChecker.CheckActionForDirectory(provider, CurrentDirectory, Actions.ForDirectories.List, currentUser, currentGroups); canDownload = AuthChecker.CheckActionForDirectory(provider, CurrentDirectory, Actions.ForDirectories.DownloadFiles, currentUser, currentGroups); canUpload = AuthChecker.CheckActionForDirectory(provider, CurrentDirectory, Actions.ForDirectories.UploadFiles, currentUser, currentGroups); canCreateDirs = AuthChecker.CheckActionForDirectory(provider, CurrentDirectory, Actions.ForDirectories.CreateDirectories, currentUser, currentGroups); canDeleteFiles = AuthChecker.CheckActionForDirectory(provider, CurrentDirectory, Actions.ForDirectories.DeleteFiles, currentUser, currentGroups); canDeleteDirs = AuthChecker.CheckActionForDirectory(provider, CurrentDirectory, Actions.ForDirectories.DeleteDirectories, currentUser, currentGroups); canSetPerms = AuthChecker.CheckActionForGlobals(Actions.ForGlobals.ManagePermissions, currentUser, currentGroups); isAdmin = currentGroups.Contains(Settings.AdministratorsGroup); }
/// <summary> /// Detects the permissions of the current user for the current directory. /// </summary> private void DetectPermissions() { string currentUser = SessionFacade.GetCurrentUsername(); string[] currentGroups = SessionFacade.GetCurrentGroupNames(); canList = AuthChecker.CheckActionForDirectory(provider, CurrentDirectory, Actions.ForDirectories.List, currentUser, currentGroups); canDownload = AuthChecker.CheckActionForDirectory(provider, CurrentDirectory, Actions.ForDirectories.DownloadFiles, currentUser, currentGroups); canUpload = AuthChecker.CheckActionForDirectory(provider, CurrentDirectory, Actions.ForDirectories.UploadFiles, currentUser, currentGroups); canCreateDirs = AuthChecker.CheckActionForDirectory(provider, CurrentDirectory, Actions.ForDirectories.CreateDirectories, currentUser, currentGroups); canDeleteFiles = AuthChecker.CheckActionForDirectory(provider, CurrentDirectory, Actions.ForDirectories.DeleteFiles, currentUser, currentGroups); canDeleteDirs = AuthChecker.CheckActionForDirectory(provider, CurrentDirectory, Actions.ForDirectories.DeleteDirectories, currentUser, currentGroups); canSetPerms = AuthChecker.CheckActionForGlobals(Actions.ForGlobals.ManagePermissions, currentUser, currentGroups); isAdmin = Array.Find(currentGroups, delegate(string g) { return(g == Settings.AdministratorsGroup); }) != null; }
/// <summary> /// Enters a sub-directory of the current directory. /// </summary> /// <param name="name">The name of the current directory.</param> private void EnterDirectory(string name) { string newDirectory = CurrentDirectory + name + "/"; bool canListThisSubDir = AuthChecker.CheckActionForDirectory(provider, newDirectory, Actions.ForDirectories.List, SessionFacade.GetCurrentUsername(), SessionFacade.GetCurrentGroupNames()); if (!canListThisSubDir) { return; } CurrentDirectory += name + "/"; DetectPermissions(); SetupControlsForPermissions(); rptItems.DataBind(); PopulateBreadcrumb(); }
protected void Page_Load(object sender, EventArgs e) { string filename = Request["File"]; if (filename == null) { Response.StatusCode = 404; Response.Write(Properties.Messages.FileNotFound); return; } string currentWiki = Tools.DetectCurrentWiki(); // Remove ".." sequences that might be a security issue filename = filename.Replace("..", ""); bool isPageAttachment = !string.IsNullOrEmpty(Request["Page"]); PageContent pageContent = isPageAttachment ? Pages.FindPage(currentWiki, Request["Page"]) : null; if (isPageAttachment && pageContent == null) { Response.StatusCode = 404; Response.Write(Properties.Messages.FileNotFound); return; } IFilesStorageProviderV40 provider; if (!string.IsNullOrEmpty(Request["Provider"])) { provider = Collectors.CollectorsBox.FilesProviderCollector.GetProvider(Request["Provider"], currentWiki); } else { if (isPageAttachment) { provider = FilesAndAttachments.FindPageAttachmentProvider(currentWiki, pageContent.FullName, filename); } else { provider = FilesAndAttachments.FindFileProvider(currentWiki, filename); } } if (provider == null) { Response.StatusCode = 404; Response.Write("File not found."); return; } // Use canonical path format (leading with /) if (!isPageAttachment) { if (!filename.StartsWith("/")) { filename = "/" + filename; } filename = filename.Replace("\\", "/"); } // Verify permissions bool canDownload = false; AuthChecker authChecker = new AuthChecker(Collectors.CollectorsBox.GetSettingsProvider(currentWiki)); if (isPageAttachment) { canDownload = authChecker.CheckActionForPage(pageContent.FullName, Actions.ForPages.DownloadAttachments, SessionFacade.GetCurrentUsername(), SessionFacade.GetCurrentGroupNames(currentWiki)); } else { string dir = Tools.GetDirectoryName(filename); canDownload = authChecker.CheckActionForDirectory(provider, dir, Actions.ForDirectories.DownloadFiles, SessionFacade.GetCurrentUsername(), SessionFacade.GetCurrentGroupNames(currentWiki)); } if (!canDownload) { Response.StatusCode = 401; return; } long size = -1; FileDetails details = null; if (isPageAttachment) { details = provider.GetPageAttachmentDetails(pageContent.FullName, filename); } else { details = provider.GetFileDetails(filename); } if (details != null) { size = details.Size; } else { Log.LogEntry("Attempted to download an inexistent file/attachment (" + (pageContent != null ? pageContent.FullName + "/" : "") + filename + ")", EntryType.Warning, Log.SystemUsername, currentWiki); Response.StatusCode = 404; Response.Write("File not found."); return; } string mime = ""; try { string ext = Path.GetExtension(filename); if (ext.StartsWith(".")) { ext = ext.Substring(1).ToLowerInvariant(); // Remove trailing dot } mime = GetMimeType(ext); } catch { // ext is null -> no mime type -> abort Response.Write(filename + "<br />"); Response.StatusCode = 404; Response.Write("File not found."); //mime = "application/octet-stream"; return; } // Prepare response Response.Clear(); Response.AddHeader("content-type", mime); if (Request["AsStreamAttachment"] != null) { Response.AddHeader("content-disposition", "attachment;filename=\"" + Path.GetFileName(filename) + "\""); } else { Response.AddHeader("content-disposition", "inline;filename=\"" + Path.GetFileName(filename) + "\""); } Response.AddHeader("content-length", size.ToString()); bool retrieved = false; if (isPageAttachment) { try { retrieved = provider.RetrievePageAttachment(pageContent.FullName, filename, Response.OutputStream); } catch (ArgumentException ex) { Log.LogEntry("Attempted to download an inexistent attachment (" + pageContent.FullName + "/" + filename + ")\n" + ex.ToString(), EntryType.Warning, Log.SystemUsername, currentWiki); } } else { try { retrieved = provider.RetrieveFile(filename, Response.OutputStream); } catch (ArgumentException ex) { Log.LogEntry("Attempted to download an inexistent file/attachment (" + filename + ")\n" + ex.ToString(), EntryType.Warning, Log.SystemUsername, currentWiki); } } if (!retrieved) { Response.StatusCode = 404; Response.Write("File not found."); return; } // Set the cache duration accordingly to the file date/time //Response.AddFileDependency(filename); //Response.Cache.SetETagFromFileDependencies(); //Response.Cache.SetLastModifiedFromFileDependencies(); Response.Cache.SetETag(filename.GetHashCode().ToString() + "-" + size.ToString()); Response.Cache.SetCacheability(HttpCacheability.Public); Response.Cache.SetSlidingExpiration(true); Response.Cache.SetValidUntilExpires(true); Response.Cache.VaryByParams["File"] = true; Response.Cache.VaryByParams["Provider"] = true; Response.Cache.VaryByParams["Page"] = true; Response.Cache.VaryByParams["IsPageAttachment"] = true; }
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(); }
/// <summary> /// Tries to enter a directory. /// </summary> /// <param name="provider">The provider.</param> /// <param name="directory">The full path of the directory.</param> public void TryEnterDirectory(string provider, string directory) { if (string.IsNullOrEmpty(directory) || string.IsNullOrEmpty(provider)) { return; } if (!directory.StartsWith("/")) { directory = "/" + directory; } if (!directory.EndsWith("/")) { directory += "/"; } directory = directory.Replace("//", "/"); LoadProviders(); IFilesStorageProviderV40 realProvider = Collectors.CollectorsBox.FilesProviderCollector.GetProvider(provider, currentWiki); if (realProvider == null) { return; } this.provider = realProvider; // Detect existence try { realProvider.ListDirectories(directory); } catch (ArgumentException) { return; } AuthChecker authChecker = new AuthChecker(Collectors.CollectorsBox.GetSettingsProvider(currentWiki)); bool canListThisSubDir = authChecker.CheckActionForDirectory(realProvider, directory, Actions.ForDirectories.List, SessionFacade.GetCurrentUsername(), SessionFacade.GetCurrentGroupNames(currentWiki)); if (!canListThisSubDir) { return; } lstProviders.SelectedIndex = -1; foreach (ListItem item in lstProviders.Items) { if (item.Value == provider) { item.Selected = true; break; } } //lstProviders_SelectedIndexChanged(this, null); string parent = "/"; string trimmedDirectory = directory.TrimEnd('/'); if (trimmedDirectory.Length > 0) { int lastSlash = trimmedDirectory.LastIndexOf("/"); if (lastSlash != -1) { parent = "/" + trimmedDirectory.Substring(0, lastSlash) + "/"; } } if (parent != directory) { CurrentDirectory = parent; EnterDirectory(Tools.ExtractDirectoryName(directory)); } }
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; }
/// <summary> /// Performs a search. /// </summary> /// <param name="query">The search query.</param> /// <param name="mode">The search mode.</param> /// <param name="selectedCategories">The selected categories.</param> /// <param name="searchUncategorized">A value indicating whether to search uncategorized pages.</param> /// <param name="searchInAllNamespacesAndCategories">A value indicating whether to search in all namespaces and categories.</param> /// <param name="searchFilesAndAttachments">A value indicating whether to search files and attachments.</param> private void PerformSearch(string query, SearchOptions mode, List <string> selectedCategories, bool searchUncategorized, bool searchInAllNamespacesAndCategories, bool searchFilesAndAttachments) { SearchResultCollection results = null; DateTime begin = DateTime.Now; try { results = SearchTools.Search(query, true, searchFilesAndAttachments, mode); } catch (ArgumentException ex) { Log.LogEntry("Search threw an exception\n" + ex, EntryType.Warning, SessionFacade.CurrentUsername); results = new SearchResultCollection(); } DateTime end = DateTime.Now; // Build a list of SearchResultRow for display in the repeater List <SearchResultRow> rows = new List <SearchResultRow>(Math.Min(results.Count, MaxResults)); string currentUser = SessionFacade.GetCurrentUsername(); string[] currentGroups = SessionFacade.GetCurrentGroupNames(); CategoryInfo[] pageCategories; int count = 0; foreach (SearchResult res in results) { // Filter by category PageInfo currentPage = null; pageCategories = new CategoryInfo[0]; if (res.Document.TypeTag == PageDocument.StandardTypeTag) { currentPage = (res.Document as PageDocument).PageInfo; pageCategories = Pages.GetCategoriesForPage(currentPage); // Verify permissions bool canReadPage = AuthChecker.CheckActionForPage(currentPage, Actions.ForPages.ReadPage, currentUser, currentGroups); if (!canReadPage) { continue; // Skip } } else if (res.Document.TypeTag == MessageDocument.StandardTypeTag) { currentPage = (res.Document as MessageDocument).PageInfo; pageCategories = Pages.GetCategoriesForPage(currentPage); // Verify permissions bool canReadDiscussion = AuthChecker.CheckActionForPage(currentPage, Actions.ForPages.ReadDiscussion, currentUser, currentGroups); if (!canReadDiscussion) { continue; // Skip } } else if (res.Document.TypeTag == PageAttachmentDocument.StandardTypeTag) { currentPage = (res.Document as PageAttachmentDocument).Page; pageCategories = Pages.GetCategoriesForPage(currentPage); // Verify permissions bool canDownloadAttn = AuthChecker.CheckActionForPage(currentPage, Actions.ForPages.DownloadAttachments, currentUser, currentGroups); if (!canDownloadAttn) { continue; // Skip } } else if (res.Document.TypeTag == FileDocument.StandardTypeTag) { string[] fields = ((FileDocument)res.Document).Name.Split('|'); IFilesStorageProviderV30 provider = Collectors.FilesProviderCollector.GetProvider(fields[0]); string directory = Tools.GetDirectoryName(fields[1]); // Verify permissions bool canDownloadFiles = AuthChecker.CheckActionForDirectory(provider, directory, Actions.ForDirectories.DownloadFiles, currentUser, currentGroups); if (!canDownloadFiles) { continue; // Skip } } string currentNamespace = DetectNamespace(); if (string.IsNullOrEmpty(currentNamespace)) { currentNamespace = null; } if (currentPage != null) { // Check categories match, if page is set if (searchInAllNamespacesAndCategories || Array.Find(pageCategories, delegate(CategoryInfo c) { return(selectedCategories.Contains(c.FullName)); }) != null || pageCategories.Length == 0 && searchUncategorized) { // ... then namespace if (searchInAllNamespacesAndCategories || NameTools.GetNamespace(currentPage.FullName) == currentNamespace) { rows.Add(SearchResultRow.CreateInstance(res)); count++; } } } else { // No associated page (-> file), add result rows.Add(SearchResultRow.CreateInstance(res)); count++; } if (count >= MaxResults) { break; } } rptResults.DataSource = rows; rptResults.DataBind(); PrintStats(end - begin, rows.Count); }
/// <summary> /// Performs a search. /// </summary> /// <param name="query">The search query.</param> /// <param name="mode">The search mode.</param> /// <param name="selectedCategories">The selected categories.</param> /// <param name="searchUncategorized">A value indicating whether to search uncategorized pages.</param> /// <param name="searchInAllNamespacesAndCategories">A value indicating whether to search in all namespaces and categories.</param> /// <param name="searchFilesAndAttachments">A value indicating whether to search files and attachments.</param> private void PerformSearch(string query, SearchOptions mode, List <string> selectedCategories, bool searchUncategorized, bool searchInAllNamespacesAndCategories, bool searchFilesAndAttachments) { List <SearchResult> results = null; DateTime begin = DateTime.Now; try { List <SearchField> searchFields = new List <SearchField>(2) { SearchField.Title, SearchField.Content }; if (searchFilesAndAttachments) { searchFields.AddRange(new SearchField[] { SearchField.FileName, SearchField.FileContent }); } results = SearchClass.Search(currentWiki, searchFields.ToArray(), query, mode); } catch (ArgumentException ex) { Log.LogEntry("Search threw an exception\n" + ex.ToString(), EntryType.Warning, SessionFacade.CurrentUsername, currentWiki); results = new List <SearchResult>(); } DateTime end = DateTime.Now; // Build a list of SearchResultRow for display in the repeater List <SearchResultRow> rows = new List <SearchResultRow>(Math.Min(results.Count, MaxResults)); string currentUser = SessionFacade.GetCurrentUsername(); string[] currentGroups = SessionFacade.GetCurrentGroupNames(currentWiki); AuthChecker authChecker = new AuthChecker(Collectors.CollectorsBox.GetSettingsProvider(currentWiki)); CategoryInfo[] pageCategories; int count = 0; foreach (SearchResult res in results) { // Filter by category PageContent currentPage = null; pageCategories = new CategoryInfo[0]; if (res.DocumentType == DocumentType.Page) { PageDocument doc = res.Document as PageDocument; currentPage = Pages.FindPage(doc.Wiki, doc.PageFullName); pageCategories = Pages.GetCategoriesForPage(currentPage); // Verify permissions bool canReadPage = authChecker.CheckActionForPage(currentPage.FullName, Actions.ForPages.ReadPage, currentUser, currentGroups); if (!canReadPage) { continue; // Skip } } else if (res.DocumentType == DocumentType.Message) { MessageDocument doc = res.Document as MessageDocument; currentPage = Pages.FindPage(doc.Wiki, doc.PageFullName); pageCategories = Pages.GetCategoriesForPage(currentPage); // Verify permissions bool canReadDiscussion = authChecker.CheckActionForPage(currentPage.FullName, Actions.ForPages.ReadDiscussion, currentUser, currentGroups); if (!canReadDiscussion) { continue; // Skip } } else if (res.DocumentType == DocumentType.Attachment) { PageAttachmentDocument doc = res.Document as PageAttachmentDocument; currentPage = Pages.FindPage(doc.Wiki, doc.PageFullName); pageCategories = Pages.GetCategoriesForPage(currentPage); // Verify permissions bool canDownloadAttn = authChecker.CheckActionForPage(currentPage.FullName, Actions.ForPages.DownloadAttachments, currentUser, currentGroups); if (!canDownloadAttn) { continue; // Skip } } else if (res.DocumentType == DocumentType.File) { FileDocument doc = res.Document as FileDocument; string[] fields = doc.FileName.Split('|'); IFilesStorageProviderV40 provider = Collectors.CollectorsBox.FilesProviderCollector.GetProvider(fields[0], currentWiki); string directory = Tools.GetDirectoryName(fields[1]); // Verify permissions bool canDownloadFiles = authChecker.CheckActionForDirectory(provider, directory, Actions.ForDirectories.DownloadFiles, currentUser, currentGroups); if (!canDownloadFiles) { continue; // Skip } } string currentNamespace = DetectNamespace(); if (string.IsNullOrEmpty(currentNamespace)) { currentNamespace = null; } if (currentPage != null) { // Check categories match, if page is set if (searchInAllNamespacesAndCategories || Array.Find(pageCategories, delegate(CategoryInfo c) { return(selectedCategories.Contains(c.FullName)); }) != null || pageCategories.Length == 0 && searchUncategorized) { // ... then namespace if (searchInAllNamespacesAndCategories || NameTools.GetNamespace(currentPage.FullName) == currentNamespace) { rows.Add(SearchResultRow.CreateInstance(res)); count++; } } } else { // No associated page (-> file), add result rows.Add(SearchResultRow.CreateInstance(res)); count++; } if (count >= MaxResults) { break; } } rptResults.DataSource = rows; rptResults.DataBind(); }