void AddBadges(Bootstrap4 bootstrap, WebPageAttribute pageAttribute) { string badgeType; switch (pageAttribute.AuthType) { case WebServerAuthType.Basic: badgeType = "badge-danger"; break; case WebServerAuthType.Session: badgeType = "badge-primary"; break; default: badgeType = "badge-default"; break; } bootstrap.AddHtml(Bootstrap4.GetBadge(pageAttribute.AuthType.ToString(), badgeType)); if (pageAttribute.AuthData != null) { bootstrap.AddHtml(" "); bootstrap.AddHtml(Bootstrap4.GetBadge(pageAttribute.AuthData, "badge-info")); } }
void GetStaticFileListing(WebData data) { string url = Uri.UnescapeDataString(data.Request.DecodedUrl).Trim('/'); string path = FileSystem.Combine(StaticFilesPath, url); var entries = new List <WebDirectoryEntry>(); string root = FileSystem.Combine(path, ".."); if (FileSystem.IsRelative(root, StaticFilesPath)) { FileSystemInfo info = new DirectoryInfo(root); var entry = new WebDirectoryEntry() { DateTime = info.LastWriteTime, Name = "..", Type = WebDirectoryEntryType.Directory, Link = "/" + url + "/..", }; entries.Add(entry); } if (FileSystem.IsRelative(path, StaticFilesPath)) { foreach (string dir in Directory.GetDirectories(path)) { FileSystemInfo info = new DirectoryInfo(dir); var entry = new WebDirectoryEntry() { DateTime = info.LastWriteTime, Name = info.Name, Type = WebDirectoryEntryType.Directory, Link = "/" + FileSystem.Combine('/', url, info.Name), }; entries.Add(entry); } foreach (string file in Directory.GetFiles(path)) { var info = new FileInfo(file); var entry = new WebDirectoryEntry() { DateTime = info.LastWriteTime, Size = info.Length, Name = info.Name, Type = WebDirectoryEntryType.File, Link = "/" + FileSystem.Combine('/', url, info.Name), }; entries.Add(entry); } } var pb = new HtmlPageBuilder(data.Request); pb.Content.CardOpenText($"File Listing:"); pb.Content.ParagraphText($"{entries.Count} entries"); pb.Content.TableOpen(new string[] { "Type", "Size", "Name" }, "table-striped table-responsive"); foreach (WebDirectoryEntry entry in entries) { pb.Content.TableRowOpen(); pb.Content.TableHtmlCell(Bootstrap4.GetBadge(entry.Type.ToString(), "badge-default")); pb.Content.TableCell(entry.Type == WebDirectoryEntryType.Directory ? string.Empty : entry.Size.FormatBinarySize()); pb.Content.TableHtmlCell(Bootstrap4.GetLink(entry.Name, entry.Link)); pb.Content.TableRowClose(); } pb.Content.TableClose(); pb.Content.CardClose(); pb.Content.AddHtml(" "); data.Answer = pb.ToAnswer(WebMessage.Create("FileListing", "File listing retrieved.")); }