linux poison RSS
linux poison Email

Automatic Web Browser Proxy Configuration using PAC file

The Web Proxy Auto-Discovery Protocol (WPAD) is a method used by clients to locate a URL of a configuration file using DHCP and/or DNS discovery methods. Once detection and download of the configuration file is complete it can be executed to determine the proxy for a specified URL. The WPAD protocol only outlines the mechanism for discovering the location of this file, but the most commonly deployed configuration file format is the Proxy auto-config (PAC) format originally designed by Netscape.

A PAC file is a specialized JavaScript function definition that a browser calls to determine how requests are handled. Clients must specify (in their browser settings) the URL from which the PAC file is loaded. You can store a PAC file on web Server (or on any server in your network) and then provide the URL for this file to your clients.

NOTE:
You should save the JavaScript function to file with a .pac filename extension; for example: proxy.pac
You should save the JavaScript function by itself, not embed it in HTML.

Next, if you are using web server to hold your pac file, you should configure your web server to map the .pac filename extension to the MIME type: application/x-ns-proxy-autoconfig

In apache (for example) put the following in your mime.types file
application/x-ns-proxy-autoconfig pac
Firefox Browser Configuration:
Go to Edit > Preferences > Advance (Network > Settings)


The client machines download the script when they startup from a web server. This web server has to serve the file as a different mime-type. The Auto-Config script is normally a .pac file, so if you aren't already using this for something else you should put the mime type in your mime config file for your web server.

Sample PAC File
The following sample PAC file instructs browsers to connect directly to all hosts without a fully-qualified domain name and to all hosts in the local domain. All other requests go to the Proxy Server named myproxy.company.com.

function FindProxyForURL(url, host)
{
   if (isInNet(host, "192.168.1.0", "255.255.255.0")) {
      return "DIRECT";
   } else {
      if (shExpMatch(url, "http:*"))
         return "PROXY myproxy.company.com:3128" ;
      if (shExpMatch(url, "https:*"))
         return "PROXY myproxy.company.com:3128" ;
      if (shExpMatch(url, "ftp:*"))
         return "PROXY myproxy.company.com:3128" ;
      return "DIRECT";
   }
}


0 comments:

Post a Comment

Related Posts with Thumbnails