proxy.pac CGI script

In my OpenWrt box I have two internal networks,one for my LAN and other for the wifi guests. I have configured a proxy server, and to distribute the configuration to the clients, I did a little script to generate a proxy.pac file dependent on the client IP.

I have this in /www/cgi-bin/proxy.pac:

eval $(/bin/ $REMOTE_ADDR $mynetmask)
if [ "$NETWORK" = "" ]; then
  proxy=""PROXY; DIRECT""
  proxy=""PROXY; DIRECT""

echo Content-Type: application/x-ns-proxy-autoconfig
echo ""

echo "function FindProxyForURL(url, host)
  return $proxy;

Make it executable, you can test it in command line passing the client IP:

# REMOTE_ADDR= sh -x /www/cgi-bin/proxy.pac

Finally, add the option 252 to the DHCP of the interfaces you want:



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s