Module Name:    src
Committed By:   mrg
Date:           Tue Dec  4 02:52:42 UTC 2018

Modified Files:
        src/libexec/httpd: CHANGES bozohttpd.8 bozohttpd.c dir-index-bozo.c

Log Message:
use html tables for directory index.
from "Rajeev V. Pillai" <rajeev_v_pil...@yahoo.com>

call this bozohttpd 20181204.


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/libexec/httpd/CHANGES
cvs rdiff -u -r1.74 -r1.75 src/libexec/httpd/bozohttpd.8
cvs rdiff -u -r1.100 -r1.101 src/libexec/httpd/bozohttpd.c
cvs rdiff -u -r1.28 -r1.29 src/libexec/httpd/dir-index-bozo.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/libexec/httpd/CHANGES
diff -u src/libexec/httpd/CHANGES:1.30 src/libexec/httpd/CHANGES:1.31
--- src/libexec/httpd/CHANGES:1.30	Sun Nov 25 23:48:14 2018
+++ src/libexec/httpd/CHANGES	Tue Dec  4 02:52:42 2018
@@ -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_pil...@yahoo.com
 
 changes in bozohttpd 20181125:
 	o  fixes for option parsing introduced in bozohttpd 20181123

Index: src/libexec/httpd/bozohttpd.8
diff -u src/libexec/httpd/bozohttpd.8:1.74 src/libexec/httpd/bozohttpd.8:1.75
--- src/libexec/httpd/bozohttpd.8:1.74	Fri Nov 23 08:11:20 2018
+++ src/libexec/httpd/bozohttpd.8	Tue Dec  4 02:52:42 2018
@@ -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 @@ The focus has always been simplicity and
 and regular code audits.
 This manual documents
 .Nm
-version 20181123.
+version 20181204.
 .Sh AUTHORS
 .An -nosplit
 .Nm
@@ -717,7 +717,7 @@ HTTP basic authorization support and muc
 .It
 .An Rajeev V. Pillai
 .Aq Mt rajeev_v_pil...@yahoo.com
-provided several fixes for virtual hosting
+provided several fixes for virtual hosting and directory indexing
 .It
 .An Jeremy C. Reed
 .Aq Mt r...@netbsd.org

Index: src/libexec/httpd/bozohttpd.c
diff -u src/libexec/httpd/bozohttpd.c:1.100 src/libexec/httpd/bozohttpd.c:1.101
--- src/libexec/httpd/bozohttpd.c:1.100	Tue Dec  4 00:26:15 2018
+++ src/libexec/httpd/bozohttpd.c	Tue Dec  4 02:52:42 2018
@@ -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 @@ check_bzredirect(bozo_httpreq_t *request
 	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 @@ bozo_escape_html(bozohttpd_t *httpd, con
 		case '&':
 			j += 5;
 			break;
+		case '"':
+			j += 6;
+			break;
 		}
 	}
 
@@ -2106,6 +2109,10 @@ bozo_escape_html(bozohttpd_t *httpd, con
 			memcpy(tmp + j, "&amp;", 5);
 			j += 5;
 			break;
+		case '"':
+			memcpy(tmp + j, "&quot;", 6);
+			j += 6;
+			break;
 		default:
 			tmp[j++] = url[i];
 		}

Index: src/libexec/httpd/dir-index-bozo.c
diff -u src/libexec/httpd/dir-index-bozo.c:1.28 src/libexec/httpd/dir-index-bozo.c:1.29
--- src/libexec/httpd/dir-index-bozo.c:1.28	Thu Nov 22 08:54:08 2018
+++ src/libexec/httpd/dir-index-bozo.c	Tue Dec  4 02:52:42 2018
@@ -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 @@ bozo_dir_index(bozo_httpreq_t *request, 
 	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 @@ bozo_dir_index(bozo_httpreq_t *request, 
 	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 @@ bozo_dir_index(bozo_httpreq_t *request, 
 		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);
-
-			/* 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);
+			strftime(buf, sizeof buf, "%d-%b-%Y %R", gmtime(&sb.st_mtime));
+			bozo_printf(httpd, "<td>%s", buf);
 
-			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 @@ bozo_dir_index(bozo_httpreq_t *request, 
 	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 @@ done:
 	return 1;
 }
 #endif /* NO_DIRINDEX_SUPPORT */
-

Reply via email to