Source-Changes-HG archive

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

[src/trunk]: src/libexec/httpd Add -R flag to specify a README file to add at...



details:   https://anonhg.NetBSD.org/src/rev/0c122a7e9be5
branches:  trunk
changeset: 1011702:0c122a7e9be5
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Mon Jul 06 23:31:36 2020 +0000

description:
Add -R flag to specify a README file to add at the bottom of directory
autoindex listings.

diffstat:

 libexec/httpd/bozohttpd.8      |   9 +++++++--
 libexec/httpd/bozohttpd.c      |   5 ++++-
 libexec/httpd/bozohttpd.h      |   3 ++-
 libexec/httpd/dir-index-bozo.c |  24 ++++++++++++++++++++++--
 libexec/httpd/main.c           |   9 +++++++--
 5 files changed, 42 insertions(+), 8 deletions(-)

diffs (158 lines):

diff -r 075608672ddb -r 0c122a7e9be5 libexec/httpd/bozohttpd.8
--- a/libexec/httpd/bozohttpd.8 Mon Jul 06 22:46:50 2020 +0000
+++ b/libexec/httpd/bozohttpd.8 Mon Jul 06 23:31:36 2020 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: bozohttpd.8,v 1.79 2019/02/28 08:28:21 mrg Exp $
+.\"    $NetBSD: bozohttpd.8,v 1.80 2020/07/06 23:31:36 jmcneill 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 February 27, 2019
+.Dd July 6, 2020
 .Dt BOZOHTTPD 8
 .Os
 .Sh NAME
@@ -40,6 +40,7 @@
 .Op Fl L Ar prefix script
 .Op Fl M Ar suffix type encoding encoding11
 .Op Fl P Ar pidfile
+.Op Fl R Ar readme
 .Op Fl S Ar server_software
 .Op Fl T Ar type timeout
 .Op Fl U Ar username
@@ -232,6 +233,10 @@
 .Dq public_html
 to
 .Ar pubdir .
+.It Fl R Ar readme
+When directory indexing is enabled, include the contents of the file
+.Ar readme
+in the footer of the directory index.
 .It Fl S Ar server_software
 Sets the internal server version to
 .Ar server_software .
diff -r 075608672ddb -r 0c122a7e9be5 libexec/httpd/bozohttpd.c
--- a/libexec/httpd/bozohttpd.c Mon Jul 06 22:46:50 2020 +0000
+++ b/libexec/httpd/bozohttpd.c Mon Jul 06 23:31:36 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bozohttpd.c,v 1.114 2020/06/07 23:33:02 fox Exp $      */
+/*     $NetBSD: bozohttpd.c,v 1.115 2020/07/06 23:31:36 jmcneill Exp $ */
 
 /*     $eterna: bozohttpd.c,v 1.178 2011/11/18 09:21:15 mrg Exp $      */
 
@@ -2570,6 +2570,9 @@
            strcmp(cp, "true") == 0) {
                httpd->dir_indexing = 1;
        }
+       if ((cp = bozo_get_pref(prefs, "directory index readme")) != NULL) {
+               httpd->dir_readme = bozostrdup(httpd, NULL, cp);
+       }
        if ((cp = bozo_get_pref(prefs, "public_html")) != NULL) {
                httpd->public_html = bozostrdup(httpd, NULL, cp);
        }
diff -r 075608672ddb -r 0c122a7e9be5 libexec/httpd/bozohttpd.h
--- a/libexec/httpd/bozohttpd.h Mon Jul 06 22:46:50 2020 +0000
+++ b/libexec/httpd/bozohttpd.h Mon Jul 06 23:31:36 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bozohttpd.h,v 1.60 2019/03/08 03:12:28 mrg Exp $       */
+/*     $NetBSD: bozohttpd.h,v 1.61 2020/07/06 23:31:36 jmcneill Exp $  */
 
 /*     $eterna: bozohttpd.h,v 1.39 2011/11/18 09:21:15 mrg Exp $       */
 
@@ -117,6 +117,7 @@
        struct pollfd   *fds;           /* current poll fd set */
        int              request_times; /* # times a request was processed */
        int              dir_indexing;  /* handle directories */
+       const char      *dir_readme;    /* include README footer in indexes */
        int              hide_dots;     /* hide .* */
        int              process_cgi;   /* use the cgi handler */
        char            *cgibin;        /* cgi-bin directory */
diff -r 075608672ddb -r 0c122a7e9be5 libexec/httpd/dir-index-bozo.c
--- a/libexec/httpd/dir-index-bozo.c    Mon Jul 06 22:46:50 2020 +0000
+++ b/libexec/httpd/dir-index-bozo.c    Mon Jul 06 23:31:36 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dir-index-bozo.c,v 1.32 2019/02/28 08:28:21 mrg Exp $  */
+/*     $NetBSD: dir-index-bozo.c,v 1.33 2020/07/06 23:31:36 jmcneill Exp $     */
 
 /*     $eterna: dir-index-bozo.c,v 1.20 2011/11/18 09:21:15 mrg Exp $  */
 
@@ -38,9 +38,11 @@
 
 #include <dirent.h>
 #include <errno.h>
+#include <fcntl.h>
 #include <string.h>
 #include <stdlib.h>
 #include <time.h>
+#include <unistd.h>
 #include <assert.h>
 
 #include "bozohttpd.h"
@@ -57,7 +59,8 @@
        DIR *dp;
        char buf[MAXPATHLEN];
        char *file = NULL, *printname = NULL, *p;
-       int k, j;
+       int k, j, fd;
+       ssize_t rlen;
 
        if (!isindex || !httpd->dir_indexing)
                return 0;
@@ -197,6 +200,23 @@
                free(deo[k]);
        free(deo);
        bozo_printf(httpd, "</table>\r\n");
+       if (httpd->dir_readme != NULL) {
+               if (httpd->dir_readme[0] == '/')
+                       snprintf(buf, sizeof buf, "%s", httpd->dir_readme);
+               else
+                       snprintf(buf, sizeof buf, "%s/%s", dirpath, httpd->dir_readme);
+               fd = open(buf, O_RDONLY);
+               if (fd != -1) {
+                       bozo_flush(httpd, stdout);
+                       do {
+                               rlen = read(fd, buf, sizeof buf);
+                               if (rlen <= 0)
+                                       break;
+                               bozo_write(httpd, STDOUT_FILENO, buf, rlen);
+                       } while (1);
+                       close(fd);
+               }
+       }
        bozo_printf(httpd, "</body></html>\r\n\r\n");
        bozo_flush(httpd, stdout);
 
diff -r 075608672ddb -r 0c122a7e9be5 libexec/httpd/main.c
--- a/libexec/httpd/main.c      Mon Jul 06 22:46:50 2020 +0000
+++ b/libexec/httpd/main.c      Mon Jul 06 23:31:36 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.22 2018/11/25 07:37:20 mrg Exp $    */
+/*     $NetBSD: main.c,v 1.23 2020/07/06 23:31:36 jmcneill Exp $       */
 
 /*     $eterna: main.c,v 1.6 2011/11/18 09:21:15 mrg Exp $     */
 /* from: eterna: bozohttpd.c,v 1.159 2009/05/23 02:14:30 mrg Exp       */
@@ -160,7 +160,7 @@
         */
 
        while ((c = getopt(argc, argv,
-           "C:EGHI:L:M:P:S:T:U:VXZ:bc:defhi:np:st:uv:x:z:")) != -1) {
+           "C:EGHI:L:M:P:R:S:T:U:VXZ:bc:defhi:np:st:uv:x:z:")) != -1) {
                switch (c) {
 
                case 'b':
@@ -299,6 +299,11 @@
                        bozo_set_pref(&httpd, &prefs, "public_html", optarg);
                        break;
 
+               case 'R':
+                       bozo_set_pref(&httpd, &prefs, "directory index readme",
+                                     optarg);
+                       break;
+
                case 'S':
                        bozo_set_pref(&httpd, &prefs, "server software",
                                      optarg);



Home | Main Index | Thread Index | Old Index