From deca1d8b77b39226fc557c73337191798b1c72c2 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 12 Feb 2020 21:39:09 +0100 Subject: [PATCH] WebServer: Show file size and modification time in directory listings This exposed an issue with the unveil() implementation which currently short-circuits path resolution for any path containing "/..". This will cause the ".." entry to show up with a 1970-01-01 mtime for now. FIXME. Also add some rulers and a nice little footer. :^) --- Servers/WebServer/Client.cpp | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/Servers/WebServer/Client.cpp b/Servers/WebServer/Client.cpp index cd1984478d..4f81e7985b 100644 --- a/Servers/WebServer/Client.cpp +++ b/Servers/WebServer/Client.cpp @@ -32,7 +32,9 @@ #include #include #include +#include #include +#include namespace WebServer { @@ -136,20 +138,40 @@ void Client::handle_directory_listing(const String& requested_path, const String builder.append("

Index of "); builder.append(requested_path); builder.append("

\n"); - builder.append("
    \n"); + builder.append("
    \n"); + builder.append("
    \n");
     
         Core::DirIterator dt(real_path);
         while (dt.has_next()) {
             auto name = dt.next_path();
    -        builder.append("
  • "); builder.append(""); builder.append(name); - builder.append("
  • \n"); + builder.append(""); + for (size_t i = 0; i < (40 - name.length()); ++i) + builder.append(' '); + + StringBuilder path_builder; + path_builder.append(real_path); + path_builder.append('/'); + path_builder.append(name); + struct stat st; + memset(&st, 0, sizeof(st)); + int rc = stat(path_builder.to_string().characters(), &st); + if (rc < 0) { + perror("wut!"); + } + dbg() << "statted _" << path_builder.to_string() << "_, rc = " << rc << " mtime = " << st.st_mtime; + builder.appendf(" %10d", st.st_size); + builder.appendf(" "); + builder.append(Core::DateTime::from_timestamp(st.st_mtime).to_string()); + builder.append("\n"); } - builder.append("
\n"); + builder.append("\n"); + builder.append("
\n"); + builder.append("Generated by WebServer (SerenityOS)\n"); builder.append("\n"); builder.append("\n");