diff options
author | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2015-11-05 20:55:47 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2015-11-05 20:55:47 +0000 |
commit | e1349eb2f87fe30a6954b60c0f066ea1f0e45d53 (patch) | |
tree | b157d3b1c58a6328b0720c99d9de651aa787b57f /usr.bin | |
parent | 5184734d5b37441da73b5404473516444c0f88a7 (diff) |
Use include files "header.html" and "footer.html" rather than a
compiled-in string. This is not a security risk, we read the file
manpath.conf from the same directory, anyway. No error handling
is needed; even if the files are absent, that's not an error.
This is more flexible without causing complication of the code or
the user interface. It helps the upcoming revamp of the online
manual pages on man.NetBSD.org.
Based on an idea by Jean-Yves Migeon <jeanyves dot migeon at free dot fr>,
but implemented in a much simpler way.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/mandoc/cgi.c | 22 | ||||
-rw-r--r-- | usr.bin/mandoc/cgi.h.example | 2 | ||||
-rw-r--r-- | usr.bin/mandoc/man.cgi.8 | 16 |
3 files changed, 28 insertions, 12 deletions
diff --git a/usr.bin/mandoc/cgi.c b/usr.bin/mandoc/cgi.c index 88aa391c742..4b9d2b20bb2 100644 --- a/usr.bin/mandoc/cgi.c +++ b/usr.bin/mandoc/cgi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cgi.c,v 1.52 2015/11/05 17:47:53 schwarze Exp $ */ +/* $OpenBSD: cgi.c,v 1.53 2015/11/05 20:55:46 schwarze Exp $ */ /* * Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2014, 2015 Ingo Schwarze <schwarze@usta.de> @@ -75,6 +75,7 @@ static void pg_searchres(const struct req *, static void pg_show(struct req *, const char *); static void resp_begin_html(int, const char *); static void resp_begin_http(int, const char *); +static void resp_copy(const char *); static void resp_end_html(void); static void resp_searchform(const struct req *); static void resp_show(const struct req *, const char *); @@ -366,6 +367,20 @@ resp_begin_http(int code, const char *msg) } static void +resp_copy(const char *filename) +{ + char buf[4096]; + ssize_t sz; + int fd; + + if ((fd = open(filename, O_RDONLY)) != -1) { + fflush(stdout); + while ((sz = read(fd, buf, sizeof(buf))) > 0) + write(STDOUT_FILENO, buf, sz); + } +} + +static void resp_begin_html(int code, const char *msg) { @@ -382,12 +397,16 @@ resp_begin_html(int code, const char *msg) "<BODY>\n" "<!-- Begin page content. //-->\n", CSS_DIR, CUSTOMIZE_TITLE); + + resp_copy(MAN_DIR "/header.html"); } static void resp_end_html(void) { + resp_copy(MAN_DIR "/footer.html"); + puts("</BODY>\n" "</HTML>"); } @@ -397,7 +416,6 @@ resp_searchform(const struct req *req) { int i; - puts(CUSTOMIZE_BEGIN); puts("<!-- Begin search form. //-->"); printf("<DIV ID=\"mancgi\">\n" "<FORM ACTION=\"%s\" METHOD=\"get\">\n" diff --git a/usr.bin/mandoc/cgi.h.example b/usr.bin/mandoc/cgi.h.example index f4c78318675..c4878d34a19 100644 --- a/usr.bin/mandoc/cgi.h.example +++ b/usr.bin/mandoc/cgi.h.example @@ -4,6 +4,4 @@ #define MAN_DIR "/var/www/man" #define CSS_DIR "" #define CUSTOMIZE_TITLE "Manual pages with mandoc" -#define CUSTOMIZE_BEGIN "<H2>\nManual pages with " \ - "<A HREF=\"http://mdocml.bsd.lv/\">mandoc</A>\n</H2>" #define COMPAT_OLDURI Yes diff --git a/usr.bin/mandoc/man.cgi.8 b/usr.bin/mandoc/man.cgi.8 index 19087611aae..1e564de086b 100644 --- a/usr.bin/mandoc/man.cgi.8 +++ b/usr.bin/mandoc/man.cgi.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: man.cgi.8,v 1.11 2015/11/05 17:47:53 schwarze Exp $ +.\" $OpenBSD: man.cgi.8,v 1.12 2015/11/05 20:55:46 schwarze Exp $ .\" .\" Copyright (c) 2014 Ingo Schwarze <schwarze@openbsd.org> .\" @@ -182,14 +182,8 @@ and to be specified without a trailing slash. When not specified, the CSS files are assumed to be in the document root. This is used in generated HTML code. -.It Ev CUSTOMIZE_BEGIN -A HTML string to be inserted right after opening the -.Aq BODY -element. .It Ev CUSTOMIZE_TITLE -An ASCII string to be used for the HTML -.Aq TITLE -element. +An ASCII string to be used for the HTML <TITLE> element. .It Ev HTTP_HOST The FQDN of the (possibly virtual) host the HTTP server is running on. This is used for @@ -366,6 +360,12 @@ or any character not contained in the .Sx Restricted character set , .Nm reports an internal server error and exits without doing anything. +.It Pa /man/header.html +An optional file containing static HTML code to be inserted right +after opening the <BODY> element. +.It Pa /man/footer.html +An optional file containing static HTML code to be inserted right +before closing the <BODY> element. .It Pa /man/OpenBSD-current/man1/mandoc.1 An example .Xr mdoc 7 |