Fri Apr 26 20:27:12 2024 UTC (13d)
Create mobile-friendly directory listings

A typical mobile browser on a smartphone assumes a page without a "viewport"
<meta> tag is designed for desktop browsers. It displays the page in a
virtual window that simulates a wider screen and does not adjust it for
the phone's pixel density. The usual result is that the content on the page
looks small, and interacting with the page comfortably and precisely requires
zoom. This is currently the case with bozohttpd directory listing pages.

from D. Bohdan in PR bin/57962


(maya)
diff -r1.36 -r1.37 src/libexec/httpd/dir-index-bozo.c

cvs diff -r1.36 -r1.37 src/libexec/httpd/dir-index-bozo.c (expand / switch to unified diff)

--- src/libexec/httpd/dir-index-bozo.c 2022/05/18 00:37:11 1.36
+++ src/libexec/httpd/dir-index-bozo.c 2024/04/26 20:27:12 1.37
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: dir-index-bozo.c,v 1.36 2022/05/18 00:37:11 mrg Exp $ */ 1/* $NetBSD: dir-index-bozo.c,v 1.37 2024/04/26 20:27:12 maya Exp $ */
2 2
3/* $eterna: dir-index-bozo.c,v 1.20 2011/11/18 09:21:15 mrg Exp $ */ 3/* $eterna: dir-index-bozo.c,v 1.20 2011/11/18 09:21:15 mrg Exp $ */
4 4
5/* 5/*
6 * Copyright (c) 1997-2022 Matthew R. Green 6 * Copyright (c) 1997-2022 Matthew R. Green
7 * All rights reserved. 7 * All rights reserved.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
@@ -113,26 +113,27 @@ bozo_dir_index(bozo_httpreq_t *request,  @@ -113,26 +113,27 @@ bozo_dir_index(bozo_httpreq_t *request,
113 if (strcmp(printname, httpd->index_html) == 0) 113 if (strcmp(printname, httpd->index_html) == 0)
114 strcpy(printname, "/"); /* is ``slashdir'' */ 114 strcpy(printname, "/"); /* is ``slashdir'' */
115 else 115 else
116 *p = '\0'; /* strip unwanted ``index_html'' */ 116 *p = '\0'; /* strip unwanted ``index_html'' */
117 } 117 }
118 if ((p = bozo_escape_html(httpd, printname)) != NULL) { 118 if ((p = bozo_escape_html(httpd, printname)) != NULL) {
119 free(printname); 119 free(printname);
120 printname = p; 120 printname = p;
121 } 121 }
122 122
123 bozo_printf(httpd, 123 bozo_printf(httpd,
124 "<!DOCTYPE html>\r\n" 124 "<!DOCTYPE html>\r\n"
125 "<html><head><meta charset=\"utf-8\"/>\r\n" 125 "<html><head><meta charset=\"utf-8\"/>\r\n"
 126 "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\r\n"
126 "<style type=\"text/css\">\r\n" 127 "<style type=\"text/css\">\r\n"
127 "table {\r\n" 128 "table {\r\n"
128 "\tborder-top: 1px solid black;\r\n" 129 "\tborder-top: 1px solid black;\r\n"
129 "\tborder-bottom: 1px solid black;\r\n" 130 "\tborder-bottom: 1px solid black;\r\n"
130 "}\r\n" 131 "}\r\n"
131 "th { background: aquamarine; }\r\n" 132 "th { background: aquamarine; }\r\n"
132 "tr:nth-child(even) { background: lavender; }\r\n" 133 "tr:nth-child(even) { background: lavender; }\r\n"
133 "</style>\r\n"); 134 "</style>\r\n");
134 bozo_printf(httpd, "<title>Index of %s</title></head>\r\n", 135 bozo_printf(httpd, "<title>Index of %s</title></head>\r\n",
135 printname); 136 printname);
136 bozo_printf(httpd, "<body><h1>Index of %s</h1>\r\n", 137 bozo_printf(httpd, "<body><h1>Index of %s</h1>\r\n",
137 printname); 138 printname);
138 bozo_printf(httpd, 139 bozo_printf(httpd,