<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>cluberti.com &#187; Proxy Autoconfig</title>
	<atom:link href="http://www.cluberti.com/blog/category/proxyautoconfig/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.cluberti.com/blog</link>
	<description>Random bits of flair pinned to the internet</description>
	<lastBuildDate>Thu, 29 Jul 2010 16:41:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Proxy PAC configuration file</title>
		<link>http://www.cluberti.com/blog/2009/12/18/proxy-pac-configuration-file/</link>
		<comments>http://www.cluberti.com/blog/2009/12/18/proxy-pac-configuration-file/#comments</comments>
		<pubDate>Fri, 18 Dec 2009 22:36:42 +0000</pubDate>
		<dc:creator>cluberti</dc:creator>
				<category><![CDATA[Internet Explorer]]></category>
		<category><![CDATA[Proxy Autoconfig]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.cluberti.com/blog/2009/12/18/proxy-pac-configuration-file/</guid>
		<description><![CDATA[Had to work on one of these for a client, and decided that while there’s a whole host of documentation out there, there aren’t a lot of good working examples of how to use the proxy auto config functions properly in a complex file. Since I spent the better part of 8 hours getting something [...]]]></description>
			<content:encoded><![CDATA[<p>Had to work on one of these for a client, and decided that while there’s a whole host of documentation out there, there aren’t a lot of good working examples of how to use the proxy auto config functions properly in a complex file.</p>
<p>Since I spent the better part of 8 hours getting something that works properly in the environment (including site blocking to a custom server), I figured I’d share it with the users of this series of tubes in the hope it helps someone.</p>
<pre class="brush: jscript;">
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// NAME:        proxy.pac
//
// Original:    http://www.cluberti.com/blog
// Last Update: 14th May 2010
//
// Comment:     Proxy.pac example file for use as an auto configuration script
//              template.
//
// NOTE:        Provided as-is - usage of this source assumes that you are at the
//              very least familiar with the javascript language being used and
//              the tools used to create and debug this file.
//
//              In other words, if you break it, you get to keep the pieces.
//
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// javascript:alert (&quot;Using PAC file&quot;);

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Start of the PAC file - function FindProxyForUrl:

function FindProxyForURL(url, host)
{

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Set proxy values as strings to use during return
// NOTE that if a rule directs the browser to return proxy_block, in this example
// the browser should attempt to visit http://internalserver:80, and will display
// the default web site at that location.

	var proxy_primary = &quot;PROXY proxy.primary.internal.domain.com:80&quot;;
	var proxy_secondary = &quot;PROXY proxy.secondary.internal.domain.com:80&quot;;
	var proxy_testing = &quot;PROXY proxy.testing.internal.domain.com:80&quot;;
	var proxy_block = &quot;PROXY internalserver:80&quot;; //&lt;- useful for blocking sites
	var proxy_no = &quot;DIRECT&quot;;

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Some proxies may have issues with mixed-case URLs, so change host variable to
// all lower case, and resolve the host IP to reduce DNS lookups later:

	host = host.toLowerCase();
	var resolved_IP = dnsResolve(host);

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Master blocked sites list
// NOTE: Add all sies you wish to redirect to proxy_block here:

	// if destination is .someblockeddomain.com, return proxy_block:
	if (dnsDomainIs(host, &quot;.someblockeddomain.com&quot;))
	{
		return proxy_block;
	}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// If URL has no dots in host name, send traffic direct.

	if (isPlainHostName(host))
	{
		return proxy_no;
	}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Master proxy bypass list
// NOTE: Add all other proxy bypass entries into this section:

	// If destination is to an RFC 1918 IP, return direct:
	if (isInNet(resolved_IP, &quot;10.0.0.0&quot;, &quot;255.0.0.0&quot;) ||
			isInNet(resolved_IP, &quot;172.16.0.0&quot;,  &quot;255.240.0.0&quot;) ||
			isInNet(resolved_IP, &quot;192.168.0.0&quot;, &quot;255.255.0.0&quot;) ||
			isInNet(resolved_IP, &quot;127.0.0.0&quot;, &quot;255.255.255.0&quot;))
	{
		return proxy_no;
	}

	// If request matches certain hosts in our IP range, return direct:
	if (isInNet(resolved_IP, &quot;11.11.11.11&quot;, &quot;255.0.0.0&quot;) ||
			isInNet(resolved_IP, &quot;11.11.11.12&quot;, &quot;255.0.0.0&quot;))
	{
		return proxy_no;
	}

		If request begins with &quot;xww&quot;, return direct:
	if (shExpMatch(host, &quot;xww.*&quot;))
	{
		return proxy_no;
	}

	// If request matches for *.internal.ourdomain.com/.net/.org, return direct:
	if (shExpMatch(host, &quot;*.internal.ourdomain.com&quot;) ||
			shExpMatch(host, &quot;*.internal.ourdomain.net&quot;) ||
			shExpMatch(host, &quot;*.internal.ourdomain.org&quot;))
	{
		return proxy_no;
	}

	// If request resolves to .external/.testing.ourdomain.com, return direct:
	if (dnsDomainIs(host, &quot;.external.ourdomain.com&quot;) ||
			dnsDomainIs(host, &quot;.testing.ourdomain.com&quot;))
	{
		return proxy_no;
	}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Hosts/domains to proxy
// NOTE: Add all hosts/domains that should go through the proxy into this section:

        // If request is for *.ourdomain.com and we've gotten this far, further
        // parsing is required:
        if (shExpMatch(host, &quot;*.ourdomain.com&quot;))
        {

                // If request is for .us.ourdomain.com, use primary proxy:
                if (dnsDomainIs(host, &quot;.us.ourdomain.com&quot;))
                {
                        return proxy_primary;
                }

                // If request is for .world.ourdomain.com, use secondary proxy:
                if (dnsDomainIs(host, &quot;.world.ourdomain.com&quot;))
                {
                        return proxy_secondary;
                }
        }

        // If browsing to *.microsoft.com, further parsing is required:
        if (shExpMatch(host, &quot;*.microsoft.com&quot;))
        {

                // If request is specifically for www.microsoft.com, try the secondary
                // proxy first:
                if (localHostOrDomainIs(host, &quot;www.microsoft.com&quot;))
                {
                        return proxy_secondary + &quot;; &quot; + proxy_primary ;
                }

                // Otherwise, try the primary proxy first to other microsoft sites:
                if (dnsDomainIs(host, &quot;.microsoft.com&quot;))
                {
                        return proxy_primary + &quot;; &quot; + proxy_secondary ;
                }
        }

        // If browsing to *.someotherdomain.com, further parsing is required:
        if (shExpMatch(host, &quot;*.someotherdomain.com&quot;))
        {

                // 172.16.0.0/255.255.0.0 IP address block -- try primary proxy first:
                if (isInNet(myIpAddress(), &quot;172.16.0.0&quot;, &quot;255.255.0.0&quot;))
                {
                        return proxy_primary + &quot;; &quot; + proxy_secondary ;
                }

                // 172.31.0.0/255.255.0.0 IP address block -- try secondary proxy first:
                if (isInNet(myIpAddress(), &quot;172.31.0.0&quot;, &quot;255.255.0.0&quot;))
                {
                        return proxy_secondary + &quot;; &quot; + proxy_primary ;
                }
        }

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Advanced proxying based on computer IP Address via the myIpAddress() function
// NOTE: Add all IP Address ranges you wish to proxy for in this section:

        // If the computer's IP address is in the 172.16.0.0/255.255.0.0 range, use
        // the the primary proxy Monday through Friday:
        if (isInNet(myIpAddress(), &quot;172.16.0.0&quot;, &quot;255.255.0.0&quot;))
        {
                if (weekdayRange(&quot;MON&quot;, &quot;FRI&quot;))
                {
                        return proxy_primary;
                }
        // If this check is done on Saturday or Sunday, this will fall through and
        // parsing will continue.
        }

        // If the computer's IP address is in the 172.31.0.0/255.255.0.0 range, use
        // the secondary proxy from January to June, and September to December:
        if (isInNet(myIpAddress(), &quot;172.31.0.0&quot;, &quot;255.255.0.0&quot;))
        {
                if (dateRange(&quot;JAN&quot;, &quot;JUN&quot;))
                {
                        return proxy_secondary;
                }
                if (dateRange(&quot;SEP&quot;, &quot;DEC&quot;))
                {
                        return proxy_secondary;
                }
        // If this check is done in July or August, this will fall through and parsing
        // will continue.
        }

        // If the computer's IP address is in the 192.168.0.0/255.255.0.0 range, use
        // the testing proxy from 8AM to 6PM local time:
        if (isInNet(myIpAddress(), &quot;192.168.0.0&quot;, &quot;255.255.0.0&quot;))
        {
                if (timeRange(8, 18))
                {
                        return proxy_testing;
                }
        // If this check is done before 8AM or after 6PM, this will fall through and
        // parsing will continue.
        }

        // If the computer's IP address is in the 10.0.0.0/255.0.0.0 range, use the
        // testing proxy:
        if (isInNet(myIpAddress(), &quot;10.0.0.0&quot;, &quot;255.0.0.0&quot;))
        {
                return proxy_testing;
        }

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Default return direct rule

// If the request matches no other parsing rules, return direct:
else
        // javascript:alert (&quot;PAC finished parsing for: &quot; + host + &quot;\nFrom IP: &quot; + myIpAddress() + &quot;\nReturning: &quot; + proxy_no);
        return proxy_no;
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.cluberti.com/blog/2009/12/18/proxy-pac-configuration-file/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
