Re: [squid-users] Add a prefix/suffix if a domain is not resolved?

From: Olivier Sannier <obones_at_free.fr>
Date: Mon, 17 Aug 2009 10:45:56 +0200

Henrik Nordstrom wrote:
> mån 2009-08-10 klockan 10:40 +0200 skrev Olivier Sannier:
>
>
>>> Indeed.. and didn't I write such a script some many years ago? Or was it
>>> someone else who posted one.. don't remember.
>>>
>>>
>> Well, I must not have used the proper search terms then. Would you have
>> any clues as to what I should look for to find this script?
>>
>
> Good question. I don't remember. It's even possible it never got
> written.
>
> Have you investigater the PAC approach? It's my recommended way of doing
> this.

Well, thank you for insisting on the PAC approach, at first I did not
think it could help me.
But as it turns out, it's pretty simple to use and it works quite well.
Just in case someone finds it useful, here is the script I wrote:

function FindProxyForURL(url, host) {

  // If URL has no dots in host name, send traffic direct.
    if (isPlainHostName(host))
        return "DIRECT";

  // If specific URL needs to bypass proxy, send traffic direct.
    if (shExpMatch(url,"*domain1.com*") ||
        shExpMatch(url,"*domain2.com*"))
        return "DIRECT";
   
    // If host is not resolvable, send direct. This will allow browser
to retry with prefix/suffix
    if (!isResolvable(host)) return "DIRECT";

  // If IP address is internal or hostname resolves to internal IP, send
direct.
    var resolved_ip = dnsResolve(host);

    if (isInNet(resolved_ip, "10.0.0.0", "255.0.0.0") ||
        isInNet(resolved_ip, "172.16.0.0", "255.240.0.0") ||
        isInNet(resolved_ip, "192.168.0.0", "255.255.0.0") ||
        isInNet(resolved_ip, "127.0.0.0", "255.255.255.0"))
        return "DIRECT";
       
    return "PROXY proxy_host:3128";
}
Received on Mon Aug 17 2009 - 08:46:08 MDT

This archive was generated by hypermail 2.2.0 : Mon Aug 17 2009 - 12:00:03 MDT