void httpd_handler(int fd, char *url, char *buf) { int idx, url_length; char *cgi_params; cgi_params = strchr(url, '?'); url_length = strlen(url); if (cgi_params) { url_length -= strlen(cgi_params); } for (idx = 0; pages[idx].page != NULL; idx++) { if (!strncmp(url, pages[idx].page, url_length)) { switch (pages[idx].type) { case HTTPD_CGI: case HTTPD_WWW: httpd_header(fd, 200, NULL); httpd_start_html(fd); pages[idx].proc(fd, buf, cgi_params); httpd_end_html(fd); break; case HTTPD_RAW: httpd_header(fd, 200, NULL); pages[idx].proc(fd, buf, cgi_params); break; case HTTPD_CGI_REDIRECT: pages[idx].proc(fd, buf, cgi_params); break; } return ; } } httpd_www_404(fd, url, buf); return ; }
void httpd_www_404(int fd, char *url, char *args) { httpd_header(fd, 404, NULL); httpd_start_html(fd); httpd_www_err(fd, "Not Found", args, "The requested URL %s was not found on this server.\n", url); httpd_end_html(fd); return ; }
void httpd_www_syserr(int fd, char *str, char *args) { httpd_header(fd, 200, NULL); httpd_start_html(fd); httpd_www_syserr_msg(fd, str, args); httpd_end_html(fd); return ; }
static void httpd_on_cgi_child(const struct client_info *cinfo, pid_t child) { if (child > 0) { if (!USE_PARALLEL_CGI) { httpd_wait_cgi_child(child, 0); } } else { httpd_header(cinfo, 500, strerror(-child)); } }
void httpd_www_gerror(int fd, char *title, char *raw, char *msg, ...) { va_list ap; char buf[1024]; va_start(ap, msg); vsnprintf(buf, sizeof(buf), msg, ap); va_end(ap); httpd_header(fd, 200, NULL); httpd_start_html(fd); httpd_www_err(fd, title, raw, buf); httpd_end_html(fd); return ; }
static void httpd_client_process(struct client_info *cinfo) { struct http_req hreq; int err; char httpd_inbuf[BUFF_SZ]; char httpd_outbuf[BUFF_SZ]; if (0 > (err = httpd_build_request(cinfo, &hreq, httpd_inbuf, sizeof(httpd_inbuf)))) { httpd_error("can't build request: %s", strerror(-err)); } httpd_debug("method=%s uri_target=%s uri_query=%s", hreq.method, hreq.uri.target, hreq.uri.query); if (httpd_try_respond_file(cinfo, &hreq, httpd_outbuf, sizeof(httpd_outbuf))) { /* file sent, nothing to do */ } else { httpd_header(cinfo, 404, ""); } }
static void httpd_client_process(struct client_info *cinfo) { struct http_req hreq; pid_t cgi_child; int err; if ((err = httpd_build_request(cinfo, &hreq, httpd_g_inbuf, sizeof(httpd_g_inbuf)))) { httpd_error("can't build request: %s", strerror(-err)); } httpd_debug("method=%s uri_target=%s uri_query=%s", hreq.method, hreq.uri.target, hreq.uri.query); if ((cgi_child = httpd_try_respond_script(cinfo, &hreq))) { httpd_on_cgi_child(cinfo, cgi_child); } else if (USE_REAL_CMD && (cgi_child = httpd_try_respond_cmd(cinfo, &hreq))) { httpd_on_cgi_child(cinfo, cgi_child); } else if (httpd_try_respond_file(cinfo, &hreq, httpd_g_outbuf, sizeof(httpd_g_outbuf))) { /* file sent, nothing to do */ } else { httpd_header(cinfo, 404, ""); } }
int httpd_cgi_conf_compile(int fd, char *raw, char *cgi) { char *nval, *old_www, *new_url; int i; lprintf("[ghost/notice] compiling config options ...\n"); if (!alt_cfg) { lprintf("[ghost/notice] no alternative config hashtable, aborted!\n"); httpd_header(fd, 302, "/config.html"); return 0; } old_www = strdup(hashtable_lookup(cfg, "http-admin-url")); if (!old_www) { lerror("calloc"); httpd_header(fd, 302, "/config.html"); return 0; } for (i = 0; cfg_truthtable[i].tag != NULL; i++) { if (cfg_truthtable[i].tag_mode == STATIC) { continue; } nval = hashtable_lookup(alt_cfg, cfg_truthtable[i].tag); if (nval) { lprintf("[ghost/notice]\t* %s -> %s\n", cfg_truthtable[i].tag, nval); hashtable_insert(cfg, cfg_truthtable[i].tag, nval); hashtable_delete(alt_cfg, cfg_truthtable[i].tag); } } if (!cfg_validate_all(cfg, GLITCH_MODE)) { httpd_www_gerror(fd, "Validation Failed!", raw, \ "Unable to validate new configuration layout. Please refer to the <A HREF=\"/log.html\">log</A> for more details!"); free(old_www); return 0; } proxy_build_limits(); lprintf("[ghost/notice] new config options are now in place!\n"); if (!strcmp(hashtable_lookup(cfg, "http-analyzer"), "off")) { httpd_header(fd, 200, NULL); httpd_msg_page(fd, "HTTP-ANALYZER", -1, NULL, "You have choosen to deactivate the HTTP-ANALYZER option. <BR> \n \ Therefor the Web Interface is no longer accessable. <BR> \n \ You can manually reactivate it by restarting the program!"); free(old_www); return 1; }