[Privoxy-commits] [privoxy] 27/30: Add a CGI handler for /wpad.dat
User Git
git at git.privoxy.org
Thu Nov 11 04:42:17 UTC 2021
This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch master
in repository privoxy.
commit 10fc609bee8f3c6832d9107e01f59386febe341a
Author: Fabian Keil <fk at fabiankeil.de>
AuthorDate: Mon Mar 1 12:22:06 2021 +0100
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.
---
cgi.c | 3 +++
cgisimple.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
cgisimple.h | 3 +++
templates/wpad.dat | 11 +++++++++++
4 files changed, 61 insertions(+)
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;
+}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Privoxy-commits
mailing list