... 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.
{ "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 */ }
}
+/*********************************************************************
+ *
+ * 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
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);
--- /dev/null
+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;
+}