<?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>techrageo.us &#187; Browsers</title>
	<atom:link href="http://techrageo.us/taxonomy/categories/browsers/feed/" rel="self" type="application/rss+xml" />
	<link>http://techrageo.us</link>
	<description>insight on technology</description>
	<lastBuildDate>Sat, 22 Oct 2011 12:18:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Leaving your work proxy at work</title>
		<link>http://techrageo.us/2007/06/16/leaving-your-work-proxy-at-work/</link>
		<comments>http://techrageo.us/2007/06/16/leaving-your-work-proxy-at-work/#comments</comments>
		<pubDate>Sat, 16 Jun 2007 20:59:22 +0000</pubDate>
		<dc:creator>grant</dc:creator>
				<category><![CDATA[Browsers]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://techrageo.us/2007/06/16/leaving-your-work-proxy-at-work/</guid>
		<description><![CDATA[The problem If you have a company laptop and your company forces you to use a proxy server you probably know about the mild annoyance of bringing your laptop home and finding that the internet doesn&#8217;t work because your browsers are setup to use a proxy that it can no longer find. So you probably [...]]]></description>
			<content:encoded><![CDATA[<h3>The problem</h3>
<p>If you have a company laptop and your company forces you to use a proxy server you probably know about the mild annoyance of bringing your laptop home and finding that the internet doesn&#8217;t work because your browsers are setup to use a proxy that it can no longer find.  So you probably go into your preferences/options and force the browser to connect directly to the internet, then switch it back when you get back to work the next day.  Rinse, repeat, annoy.</p>
<p>Well, as it turns out most major browsers like <a href="http://www.microsoft.com/ie">Internet Explorer</a>, <a href="http://getfirefox.com">Firefox</a>, and <a href="http://www.opera.com/">Opera</a> all allow you to use a bit of javascript to automatically set the proxy server to different things under different circumstances.  You save this javascript code into a &#8220;proxy.pac&#8221; file and then you just let your browser know where it is.</p>
<h3>Creating a simple proxy.pac</h3>
<p>So open up your favorite text editor and lets create a proxy.pac.  The javascript in this file should just be one function, called <b>FindProxyForURL</b>.  It always will give you two parameters to work with and it should always return a string with a proxy (or several) to use.  Below is a very, very simple version that will always try to use the proxy server unless it cannot connect, the it will try a direct connection:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> FindProxyForURL<span style="color: #009900;">&#40;</span>url<span style="color: #339933;">,</span> host<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
   <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #3366CC;">&quot;PROXY proxy.myworplace.com:1080; DIRECT&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h3>Using day and time features</h3>
<p>If you generally work the same hours every day and have a pretty set schedule then your proxy.pac will be fairly simple.  We want to use a direct connection whenever we are hitting the local machine, on weekends, and during certain hours on the weekdays.  Otherwise it will try to use the named proxy as a starting point.  Regardless of which method is picked, if no connection can be made the browser should try the other method, since we just ordered them differently in the if-else statment.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> FindProxyForURL<span style="color: #009900;">&#40;</span>url<span style="color: #339933;">,</span> host<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> host <span style="color: #339933;">==</span> <span style="color: #3366CC;">&quot;localhost&quot;</span> <span style="color: #339933;">||</span>
  	host <span style="color: #339933;">==</span> <span style="color: #3366CC;">&quot;127.0.0.1&quot;</span> <span style="color: #339933;">||</span>  <span style="color: #006600; font-style: italic;">//bypass for local hosts</span>
    weekdayRange<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;SAT&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;SUN&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span>   <span style="color: #006600; font-style: italic;">//bypass on saturday or sunday</span>
    timeRange<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">18</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">7</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>  <span style="color: #006600; font-style: italic;">//bypass after 6pm and before 7am</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #3366CC;">&quot;DIRECT; PROXY proxy.mycompany.com:1080&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #006600; font-style: italic;">/*with both the DIRECT and the PROXY listed it will try the
    	first and then fall back on the second*/</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #3366CC;">&quot;PROXY proxy.mycompany.com:1080; DIRECT&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h3>Proxy by IP address</h3>
<p>If you have a different IP address at work than you do at home then you can use that to filter off of instead of the time.  We&#8217;ll just split the IP and if the first number isn&#8217;t equal to the first number of your IP at work then you must be elsewhere.  We&#8217;ll also make it a bit more elegant and define our proxy server at the top of the file.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> FindProxyForURL<span style="color: #009900;">&#40;</span>url<span style="color: #339933;">,</span> host<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #003366; font-weight: bold;">var</span> myProxy <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;proxy.mycompany.com:1080&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #003366; font-weight: bold;">var</span> ipSubs <span style="color: #339933;">=</span> myIpAddress<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> host <span style="color: #339933;">==</span> <span style="color: #3366CC;">&quot;localhost&quot;</span> <span style="color: #339933;">||</span>
  	host <span style="color: #339933;">==</span> <span style="color: #3366CC;">&quot;127.0.0.1&quot;</span> <span style="color: #339933;">||</span>
  	ipSubs<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> <span style="color: #3366CC;">&quot;172&quot;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #3366CC;">&quot;DIRECT; PROXY &quot;</span> <span style="color: #339933;">+</span> myProxy<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #3366CC;">&quot;PROXY &quot;</span> <span style="color: #339933;">+</span> myProxy <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;; DIRECT&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h3>Setting up the browser</h3>
<p>So you&#8217;ve got your file, but now what?  You need to find a place to put it (it doesn&#8217;t matter where, as long as you know where it is located at).  For our example we&#8217;ll say that it is located at &#8220;C:\stuff\proxy.pac&#8221;.</p>
<p>To setup Internet Explorer:</p>
<ol>
<li>Go to Tools->Internet Options</li>
<li>Go to the Connections Tab</li>
<li>Click the LAN Settings button</li>
<li>Check the box labeled &#8220;Use automatic configuration script&#8221;</li>
<li>Type in the address using this format: <b>file://c:/stuff/proxy.pac</b></li>
<li>Keep clicking &#8220;OK&#8221; until you get back to the main screen</li>
</ol>
<p>To setup Firefox (v2):</p>
<ol>
<li>Go to Tools->Options (Edit->Preferences on Linux)</li>
<li>Go to the Network tab</li>
<li>Click on the Settings button</li>
<li>Click the radio button labeled &#8220;Automatic proxy configuration URL&#8221;</li>
<li>Type in the address using this format: <b>file:///c:/stuff/proxy.pac</b></li>
<li>Keep clicking &#8220;OK&#8221; until you get back to the main screen</li>
</ol>
<p>To setup Opera:<br />
Just setup IE and Opera is smart enough to grab that file and use it.</p>
<h3>Conclusion and Resources</h3>
<p>You&#8217;ll probably have a little trial and error period, but you should be able to get something that works for you and will keep you from having to go into your preferences/options.</p>
<div class="readlink">
Read <a href="http://wp.netscape.com/eng/mozilla/2.0/relnotes/demo/proxy-live.html">a great proxy.pac resource</a> at Netscape.<br />
Read <a href="http://en.wikipedia.org/wiki/Proxy_auto-config">the entry for proxy.pac</a> at Wikipedia.
</div>
]]></content:encoded>
			<wfw:commentRss>http://techrageo.us/2007/06/16/leaving-your-work-proxy-at-work/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

