Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/libexec/httpd use html tables for directory index.



details:   https://anonhg.NetBSD.org/src/rev/6cc9f959e8d4
branches:  trunk
changeset: 446394:6cc9f959e8d4
user:      mrg <mrg%NetBSD.org@localhost>
date:      Tue Dec 04 02:52:42 2018 +0000

description:
use html tables for directory index.
from "Rajeev V. Pillai" <rajeev_v_pillai%yahoo.com@localhost>

call this bozohttpd 20181204.

diffstat:

 libexec/httpd/CHANGES          |   6 ++-
 libexec/httpd/bozohttpd.8      |   8 ++--
 libexec/httpd/bozohttpd.c      |  11 ++++-
 libexec/httpd/dir-index-bozo.c |  83 +++++++++++------------------------------
 4 files changed, 40 insertions(+), 68 deletions(-)

diffs (247 lines):

diff -r b55be4cc48f1 -r 6cc9f959e8d4 libexec/httpd/CHANGES
--- a/libexec/httpd/CHANGES     Tue Dec 04 01:35:15 2018 +0000
+++ b/libexec/httpd/CHANGES     Tue Dec 04 02:52:42 2018 +0000
@@ -1,4 +1,8 @@
-$NetBSD: CHANGES,v 1.30 2018/11/25 23:48:14 mrg Exp $
+$NetBSD: CHANGES,v 1.31 2018/12/04 02:52:42 mrg Exp $
+
+changes in bozohttpd 20181204:
+       o  change directory indexing to use html tables.  from
+          rajeev_v_pillai%yahoo.com@localhost
 
 changes in bozohttpd 20181125:
        o  fixes for option parsing introduced in bozohttpd 20181123
diff -r b55be4cc48f1 -r 6cc9f959e8d4 libexec/httpd/bozohttpd.8
--- a/libexec/httpd/bozohttpd.8 Tue Dec 04 01:35:15 2018 +0000
+++ b/libexec/httpd/bozohttpd.8 Tue Dec 04 02:52:42 2018 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: bozohttpd.8,v 1.74 2018/11/23 08:11:20 mrg Exp $
+.\"    $NetBSD: bozohttpd.8,v 1.75 2018/12/04 02:52:42 mrg Exp $
 .\"
 .\"    $eterna: bozohttpd.8,v 1.101 2011/11/18 01:25:11 mrg Exp $
 .\"
@@ -26,7 +26,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd November 19, 2018
+.Dd December 4, 2018
 .Dt BOZOHTTPD 8
 .Os
 .Sh NAME
@@ -599,7 +599,7 @@
 and regular code audits.
 This manual documents
 .Nm
-version 20181123.
+version 20181204.
 .Sh AUTHORS
 .An -nosplit
 .Nm
@@ -717,7 +717,7 @@
 .It
 .An Rajeev V. Pillai
 .Aq Mt rajeev_v_pillai%yahoo.com@localhost
-provided several fixes for virtual hosting
+provided several fixes for virtual hosting and directory indexing
 .It
 .An Jeremy C. Reed
 .Aq Mt reed%NetBSD.org@localhost
diff -r b55be4cc48f1 -r 6cc9f959e8d4 libexec/httpd/bozohttpd.c
--- a/libexec/httpd/bozohttpd.c Tue Dec 04 01:35:15 2018 +0000
+++ b/libexec/httpd/bozohttpd.c Tue Dec 04 02:52:42 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bozohttpd.c,v 1.100 2018/12/04 00:26:15 mrg Exp $      */
+/*     $NetBSD: bozohttpd.c,v 1.101 2018/12/04 02:52:42 mrg Exp $      */
 
 /*     $eterna: bozohttpd.c,v 1.178 2011/11/18 09:21:15 mrg Exp $      */
 
@@ -1441,7 +1441,7 @@
        bozohttpd_t *httpd = request->hr_httpd;
        struct stat sb;
        char dir[MAXPATHLEN], redir[MAXPATHLEN], redirpath[MAXPATHLEN + 1],
-           path[MAXPATHLEN];
+           path[MAXPATHLEN + 1];
        char *basename, *finalredir;
        int rv, absolute;
 
@@ -2076,6 +2076,9 @@
                case '&':
                        j += 5;
                        break;
+               case '"':
+                       j += 6;
+                       break;
                }
        }
 
@@ -2106,6 +2109,10 @@
                        memcpy(tmp + j, "&amp;", 5);
                        j += 5;
                        break;
+               case '"':
+                       memcpy(tmp + j, "&quot;", 6);
+                       j += 6;
+                       break;
                default:
                        tmp[j++] = url[i];
                }
diff -r b55be4cc48f1 -r 6cc9f959e8d4 libexec/httpd/dir-index-bozo.c
--- a/libexec/httpd/dir-index-bozo.c    Tue Dec 04 01:35:15 2018 +0000
+++ b/libexec/httpd/dir-index-bozo.c    Tue Dec 04 02:52:42 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dir-index-bozo.c,v 1.28 2018/11/22 08:54:08 mrg Exp $  */
+/*     $NetBSD: dir-index-bozo.c,v 1.29 2018/12/04 02:52:42 mrg Exp $  */
 
 /*     $eterna: dir-index-bozo.c,v 1.20 2011/11/18 09:21:15 mrg Exp $  */
 
@@ -45,14 +45,6 @@
 
 #include "bozohttpd.h"
 
-static void
-directory_hr(bozohttpd_t *httpd)
-{
-
-       bozo_printf(httpd,
-               "<hr noshade align=\"left\" width=\"80%%\">\r\n\r\n");
-}
-
 /*
  * output a directory index.  return 1 if it actually did something..
  */
@@ -62,12 +54,10 @@
        bozohttpd_t *httpd = request->hr_httpd;
        struct stat sb;
        struct dirent **de, **deo;
-       struct tm *tm;
        DIR *dp;
        char buf[MAXPATHLEN];
-       char spacebuf[48];
        char *file = NULL, *printname = NULL;
-       int l, k, j, i;
+       int k, j, i;
 
        if (!isindex || !httpd->dir_indexing)
                return 0;
@@ -117,23 +107,19 @@
        printname = bozostrdup(httpd, request, request->hr_file);
 #endif /* !NO_USER_SUPPORT */
 
-       bozo_printf(httpd,
-               "<html><head><title>Index of %s</title></head>\r\n",
+       bozo_printf(httpd, "<!DOCTYPE html>\r\n");
+       bozo_printf(httpd, "<html><head><meta charset=\"utf-8\"/>\r\n");
+       bozo_printf(httpd, "<style type=\"text/css\">tr.o {background:#f4f4f4;}</style>\r\n");
+       bozo_printf(httpd, "<title>Index of %s</title></head>\r\n",
                printname);
        bozo_printf(httpd, "<body><h1>Index of %s</h1>\r\n",
                printname);
-       bozo_printf(httpd, "<pre>\r\n");
-#define NAMELEN 40
-#define LMODLEN 19
-       bozo_printf(httpd, "Name                                     "
-           "Last modified          "
-           "Size\n");
-       bozo_printf(httpd, "</pre>");
-       directory_hr(httpd);
-       bozo_printf(httpd, "<pre>");
+       bozo_printf(httpd, "<table>\r\n<thead>\r\n");
+       bozo_printf(httpd, "<tr class=\"o\"><th>Name<th>Last modified<th align=right>Size\r\n");
+       bozo_printf(httpd, "<tbody>\r\n");
 
-       for (j = k = scandir(dirpath, &de, NULL, alphasort), deo = de;
-           j--; de++) {
+       for (j = k = scandir(dirpath, &de, NULL, alphasort), deo = de, i = 1;
+           j--; de++, i++) {
                int nostat = 0;
                char *name = (*de)->d_name;
                char *urlname, *htmlname;
@@ -147,62 +133,39 @@
                if (stat(buf, &sb))
                        nostat = 1;
 
-               l = 0;
-
                urlname = bozo_escape_rfc3986(httpd, name, 0);
                htmlname = bozo_escape_html(httpd, name);
                if (htmlname == NULL)
                        htmlname = name;
+               bozo_printf(httpd, "<tr class=\"%s\"><td>", (i & 1) ? "o" : "e");
                if (strcmp(name, "..") == 0) {
                        bozo_printf(httpd, "<a href=\"../\">");
-                       l += bozo_printf(httpd, "Parent Directory");
+                       bozo_printf(httpd, "Parent Directory");
                } else if (!nostat && S_ISDIR(sb.st_mode)) {
                        bozo_printf(httpd, "<a href=\"%s/\">", urlname);
-                       l += bozo_printf(httpd, "%s/", htmlname);
+                       bozo_printf(httpd, "%s/", htmlname);
                } else if (strchr(name, ':') != NULL) {
                        /* RFC 3986 4.2 */
                        bozo_printf(httpd, "<a href=\"./%s\">", urlname);
-                       l += bozo_printf(httpd, "%s", htmlname);
+                       bozo_printf(httpd, "%s", htmlname);
                } else {
                        bozo_printf(httpd, "<a href=\"%s\">", urlname);
-                       l += bozo_printf(httpd, "%s", htmlname);
+                       bozo_printf(httpd, "%s", htmlname);
                }
                if (htmlname != name)
                        free(htmlname);
                bozo_printf(httpd, "</a>");
 
-               /* NAMELEN spaces */
-               /*LINTED*/
-               assert(/*CONSTCOND*/sizeof(spacebuf) > NAMELEN);
-               i = (l < NAMELEN) ? (NAMELEN - l) : 0;
-               i++;
-               memset(spacebuf, ' ', (size_t)i);
-               spacebuf[i] = '\0';
-               bozo_printf(httpd, "%s", spacebuf);
-               l += i;
-
                if (nostat)
-                       bozo_printf(httpd, "?                         ?");
+                       bozo_printf(httpd, "<td>?<td>?\r\n");
                else {
                        unsigned long long len;
 
-                       len = ((unsigned long long)sb.st_size + 1023) / 1024;
-
-                       tm = gmtime(&sb.st_mtime);
-                       strftime(buf, sizeof buf, "%d-%b-%Y %R", tm);
-                       l += bozo_printf(httpd, "%s", buf);
+                       strftime(buf, sizeof buf, "%d-%b-%Y %R", gmtime(&sb.st_mtime));
+                       bozo_printf(httpd, "<td>%s", buf);
 
-                       /* LMODLEN spaces */
-                       /*LINTED*/
-                       assert(/*CONSTCOND*/sizeof(spacebuf) > LMODLEN);
-                       i = (l < (LMODLEN+NAMELEN+1)) ?
-                               ((LMODLEN+NAMELEN+1) - l) : 0;
-                       i++;
-                       memset(spacebuf, ' ', (size_t)i);
-                       spacebuf[i] = '\0';
-                       bozo_printf(httpd, "%s", spacebuf);
-
-                       bozo_printf(httpd, "%12llukB", len);
+                       len = ((unsigned long long)sb.st_size + 1023) / 1024;
+                       bozo_printf(httpd, "<td align=right>%llukB", len);
                }
                bozo_printf(httpd, "\r\n");
        }
@@ -211,8 +174,7 @@
        while (k--)
                free(deo[k]);
        free(deo);
-       bozo_printf(httpd, "</pre>");
-       directory_hr(httpd);
+       bozo_printf(httpd, "</table>\r\n");
        bozo_printf(httpd, "</body></html>\r\n\r\n");
        bozo_flush(httpd, stdout);
 
@@ -222,4 +184,3 @@
        return 1;
 }
 #endif /* NO_DIRINDEX_SUPPORT */
-



Home | Main Index | Thread Index | Old Index