version 1.118, 2016/03/17 22:06:44 |
version 1.119, 2016/03/18 13:22:27 |
Line 84 static int validate_filename(const char *); |
|
Line 84 static int validate_filename(const char *); |
|
static int validate_manpath(const struct req *, const char *); |
static int validate_manpath(const struct req *, const char *); |
static int validate_urifrag(const char *); |
static int validate_urifrag(const char *); |
|
|
static const char *scriptname; /* CGI script name */ |
static const char *scriptname = SCRIPT_NAME; |
|
|
static const int sec_prios[] = {1, 4, 5, 8, 6, 3, 7, 2, 9}; |
static const int sec_prios[] = {1, 4, 5, 8, 6, 3, 7, 2, 9}; |
static const char *const sec_numbers[] = { |
static const char *const sec_numbers[] = { |
Line 370 resp_searchform(const struct req *req) |
|
Line 370 resp_searchform(const struct req *req) |
|
|
|
puts("<!-- Begin search form. //-->"); |
puts("<!-- Begin search form. //-->"); |
printf("<DIV ID=\"mancgi\">\n" |
printf("<DIV ID=\"mancgi\">\n" |
"<FORM ACTION=\"%s\" METHOD=\"get\">\n" |
"<FORM ACTION=\"/%s\" METHOD=\"get\">\n" |
"<FIELDSET>\n" |
"<FIELDSET>\n" |
"<LEGEND>Manual Page Search Parameters</LEGEND>\n", |
"<LEGEND>Manual Page Search Parameters</LEGEND>\n", |
scriptname); |
scriptname); |
Line 507 pg_index(const struct req *req) |
|
Line 507 pg_index(const struct req *req) |
|
resp_searchform(req); |
resp_searchform(req); |
printf("<P>\n" |
printf("<P>\n" |
"This web interface is documented in the\n" |
"This web interface is documented in the\n" |
"<A HREF=\"%s/mandoc/man8/man.cgi.8\">man.cgi</A>\n" |
"<A HREF=\"/%s%smandoc/man8/man.cgi.8\">man.cgi</A>\n" |
"manual, and the\n" |
"manual, and the\n" |
"<A HREF=\"%s/mandoc/man1/apropos.1\">apropos</A>\n" |
"<A HREF=\"/%s%smandoc/man1/apropos.1\">apropos</A>\n" |
"manual explains the query syntax.\n" |
"manual explains the query syntax.\n" |
"</P>\n", |
"</P>\n", |
scriptname, scriptname); |
scriptname, *scriptname == '\0' ? "" : "/", |
|
scriptname, *scriptname == '\0' ? "" : "/"); |
resp_end_html(); |
resp_end_html(); |
} |
} |
|
|
Line 536 pg_error_badrequest(const char *msg) |
|
Line 537 pg_error_badrequest(const char *msg) |
|
"<P>\n"); |
"<P>\n"); |
puts(msg); |
puts(msg); |
printf("Try again from the\n" |
printf("Try again from the\n" |
"<A HREF=\"%s\">main page</A>.\n" |
"<A HREF=\"/%s\">main page</A>.\n" |
"</P>", scriptname); |
"</P>", scriptname); |
resp_end_html(); |
resp_end_html(); |
} |
} |
Line 573 pg_searchres(const struct req *req, struct manpage *r, |
|
Line 574 pg_searchres(const struct req *req, struct manpage *r, |
|
* without any delay. |
* without any delay. |
*/ |
*/ |
printf("Status: 303 See Other\r\n"); |
printf("Status: 303 See Other\r\n"); |
printf("Location: http://%s%s/%s/%s", |
printf("Location: http://%s/%s%s%s/%s", |
HTTP_HOST, scriptname, req->q.manpath, r[0].file); |
HTTP_HOST, scriptname, |
|
*scriptname == '\0' ? "" : "/", |
|
req->q.manpath, r[0].file); |
printf("\r\n" |
printf("\r\n" |
"Content-Type: text/html; charset=utf-8\r\n" |
"Content-Type: text/html; charset=utf-8\r\n" |
"\r\n"); |
"\r\n"); |
Line 589 pg_searchres(const struct req *req, struct manpage *r, |
|
Line 592 pg_searchres(const struct req *req, struct manpage *r, |
|
for (i = 0; i < sz; i++) { |
for (i = 0; i < sz; i++) { |
printf("<TR>\n" |
printf("<TR>\n" |
"<TD CLASS=\"title\">\n" |
"<TD CLASS=\"title\">\n" |
"<A HREF=\"%s/%s/%s", |
"<A HREF=\"/%s%s%s/%s", |
scriptname, req->q.manpath, r[i].file); |
scriptname, *scriptname == '\0' ? "" : "/", |
|
req->q.manpath, r[i].file); |
printf("\">"); |
printf("\">"); |
html_print(r[i].names); |
html_print(r[i].names); |
printf("</A>\n" |
printf("</A>\n" |
Line 808 format(const struct req *req, const char *file) |
|
Line 812 format(const struct req *req, const char *file) |
|
memset(&conf, 0, sizeof(conf)); |
memset(&conf, 0, sizeof(conf)); |
conf.fragment = 1; |
conf.fragment = 1; |
usepath = strcmp(req->q.manpath, req->p[0]); |
usepath = strcmp(req->q.manpath, req->p[0]); |
mandoc_asprintf(&conf.man, "%s?query=%%N&sec=%%S%s%s%s%s", |
mandoc_asprintf(&conf.man, "/%s?query=%%N&sec=%%S%s%s%s%s", |
scriptname, |
scriptname, |
req->q.arch ? "&arch=" : "", |
req->q.arch ? "&arch=" : "", |
req->q.arch ? req->q.arch : "", |
req->q.arch ? req->q.arch : "", |
|
|
itimer.it_interval.tv_usec = 0; |
itimer.it_interval.tv_usec = 0; |
if (setitimer(ITIMER_VIRTUAL, &itimer, NULL) == -1) { |
if (setitimer(ITIMER_VIRTUAL, &itimer, NULL) == -1) { |
fprintf(stderr, "setitimer: %s\n", strerror(errno)); |
fprintf(stderr, "setitimer: %s\n", strerror(errno)); |
pg_error_internal(); |
|
return EXIT_FAILURE; |
|
} |
|
|
|
/* Scan our run-time environment. */ |
|
|
|
if (NULL == (scriptname = getenv("SCRIPT_NAME"))) |
|
scriptname = ""; |
|
|
|
if ( ! validate_urifrag(scriptname)) { |
|
fprintf(stderr, "unsafe SCRIPT_NAME \"%s\"\n", |
|
scriptname); |
|
pg_error_internal(); |
pg_error_internal(); |
return EXIT_FAILURE; |
return EXIT_FAILURE; |
} |
} |