After getting annoyed with IE for not having a quick and easy way to turn proxy settings off, this question inspired me to write this PAC file in PHP.
It determines whether a request for the file is made from internally (in which case, use the proxy server) or externally: go direct. Perhaps someone can adjust it for their own needs.
<?php
$proxy = "192.168.0.x";
$port = "8080";
header ("Content-type: application/x-ns-proxy-autoconfig");
header ("Date: " . gmdate('D, d M Y H:i:s \G\M\T', time ()));
header ("Last-Modified: " . gmdate('D, d M Y H:i:s \G\M\T', time ()));
header ("Expires: " . gmdate('D, d M Y H:i:s \G\M\T', time () + 60 * 30));
echo "// Request from: " . $_SERVER ['REMOTE_ADDR'] . "\n";
if (substr ($_SERVER ['REMOTE_ADDR'], 0, 8) == "192.168.")
{
?>
// We're inside the firewall
var external = false;
<?php
}
else
{
?>
// We're outside the firewall
var external = true;
<?php
}
?>
// Default connection
var direct = "DIRECT";
// Alternate Proxy Server
var proxy = "PROXY <?php echo $proxy; ?>:<?php echo $port; ?>";
//
// Proxy Logic
//
function FindProxyForURL(url, host)
{
if (external || isPlainHostName(host) || shExpMatch(host, "192.168.*") || (dnsDomainIs(host, ".example.com")) && !localHostOrDomainIs(host, "www.example.com") || dnsDomainIs (host, ".example2.com"))
{
return direct;
}
else
{
return proxy;
}
}
I have now adjusted my Group Policy settings so that all browsers will point to this file which is located on a webserver within the firewall. Now if laptops go offsite, their proxy file will change automatically without the need to reconfigure the browser's proxy setting.
Edit: updated to match local IP address hosts also...