Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

It is necessary for several of our laptops to operate on both our own and customer-based networks. This often involves switching proxy settings, which we did via a custom proxy.pac file at first (after some help from you here). Now, one of the networks we use has their own proxy.pac that we must use which means that currently, we have to manually change our proxy.pac location for that network.

So, is there a way to write a proxy.pac such that it defers to another proxy.pac in some circumstances?

share|improve this question

2 Answers 2

up vote 5 down vote accepted

No, not within a static .pac file. The problem would be that you would end up redefining the FindProxyForURL() function when the second file was loaded which would set off the javascript interpreter.

You would need to develop a dynamic page (ASP, PHP, etc) that would implement the required logic and then, based on the decision, read in the contents of the desired .pac file and serve it back to the client. I used to do this to build in some dynamic load balancing between proxies that I had in different physical locations and it worked well for me.

If you choose to go this route, make sure that the script you write sets the return mime type to application/x-ns-proxy-autoconfig or application/x-javascript-config, otherwise your browser will not recognize it as a pac file.

share|improve this answer
    
Thanks, I suspected that it might be complicated. In order for this to work, the dynamic page would have to run locally, otherwise, how could the proxy be properly configured to reach it if it was needed to properly configure the proxy? head explodes –  Jeff Yates Aug 24 '09 at 17:33
    
Yeah, if you don't have concurrent connections to both networks you're at a bit of a loss... If you're using Firefox there are some add-ins that will let you switch between mutliple configurations. Other than that I think you're about stuck. –  squillman Aug 24 '09 at 17:44
    
Thanks for the help. Really appreciated. I'll post an update if I get something working. –  Jeff Yates Aug 24 '09 at 18:09

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...

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.