From: Fabian Keil Date: Mon, 1 Mar 2021 11:22:06 +0000 (+0100) Subject: Add a CGI handler for /wpad.dat X-Git-Tag: v_3_0_33~43 X-Git-Url: http://www.privoxy.org/gitweb/?p=privoxy.git;a=commitdiff_plain;h=10fc609bee8f3c6832d9107e01f59386febe341a Add a CGI handler for /wpad.dat ... that returns a Proxy Auto-Configuration (PAC) file. Among other things, it can be used to instruct clients through DHCP to use Privoxy as proxy. For example with the dnsmasq option: dhcp-option=252,http://config.privoxy.org/wpad.dat Initial patch by Richard Schneidt. --- diff --git a/cgi.c b/cgi.c index 6c788064..cb1f0725 100644 --- a/cgi.c +++ b/cgi.c @@ -221,6 +221,9 @@ static const struct cgi_dispatcher cgi_dispatchers[] = { { "user-manual", cgi_send_user_manual, NULL, TRUE /* Send user-manual */ }, + { "wpad.dat", + cgi_send_wpad, + NULL, TRUE /* Send wpad.dat proxy autoconfiguration file */ }, { NULL, /* NULL Indicates end of list and default page */ cgi_error_404, NULL, TRUE /* Unknown CGI page */ } diff --git a/cgisimple.c b/cgisimple.c index e465be36..96506273 100644 --- a/cgisimple.c +++ b/cgisimple.c @@ -870,6 +870,50 @@ jb_err cgi_send_stylesheet(struct client_state *csp, } +/********************************************************************* + * + * Function : cgi_send_wpad + * + * Description : CGI function that sends a Proxy Auto-Configuration + * (PAC) file. + * + * Parameters : + * 1 : csp = Current client state (buffers, headers, etc...) + * 2 : rsp = http_response data structure for output + * 3 : parameters = map of cgi parameters + * + * CGI Parameters : None + * + * Returns : JB_ERR_OK on success + * JB_ERR_MEMORY on out-of-memory error. + * + *********************************************************************/ +jb_err cgi_send_wpad(struct client_state *csp, + struct http_response *rsp, + const struct map *parameters) +{ + struct map *exports; + + assert(csp); + assert(rsp); + assert(parameters); + + if (NULL == (exports = default_exports(csp, NULL))) + { + return JB_ERR_MEMORY; + } + + if (enlist(rsp->headers, "Content-Type: application/x-ns-proxy-autoconfig")) + { + free_map(exports); + return JB_ERR_MEMORY; + } + + return template_fill_for_cgi(csp, "wpad.dat", exports, rsp); + +} + + /********************************************************************* * * Function : cgi_send_url_info_osd diff --git a/cgisimple.h b/cgisimple.h index 01e6a9e8..ab975dc6 100644 --- a/cgisimple.h +++ b/cgisimple.h @@ -84,6 +84,9 @@ extern jb_err cgi_send_default_favicon (struct client_state *csp, extern jb_err cgi_send_stylesheet(struct client_state *csp, struct http_response *rsp, const struct map *parameters); +extern jb_err cgi_send_wpad(struct client_state *csp, + struct http_response *rsp, + const struct map *parameters); extern jb_err cgi_send_url_info_osd(struct client_state *csp, struct http_response *rsp, const struct map *parameters); diff --git a/templates/wpad.dat b/templates/wpad.dat new file mode 100644 index 00000000..d47d7786 --- /dev/null +++ b/templates/wpad.dat @@ -0,0 +1,11 @@ +function FindProxyForURL(url, host) { + var proxy = "PROXY @my-ip-address@:@my-port@; DIRECT"; + var direct = "DIRECT"; + if (isPlainHostName(host)) { + return direct; + } + if (url.substring(0, 4) == "ftp:" || url.substring(0, 6) == "rsync:") { + return direct; + } + return proxy; +}