Tuesday, January 24, 2012

Using Automatic Proxy Configuration

Automatic proxy (auto-proxy) makes system administration easier, because you can automatically configure proxy settings such as server addresses and bypass lists. To configure more advanced settings for auto-proxy, you can create a separate .js, .jvs, or .pac script file and then copy the file to a server location. Then, you can specify the server location for the script file within the Automatic Configuration settings of browser. The auto-proxy script file is executed whenever a network request is made. Within the script, you can configure multiple proxy servers for each protocol type; then, if a proxy server connection fails, browser automatically attempts to connect to another proxy server that you have specified.
PAC File
A proxy auto-config (PAC) file defines how web browsers and other user agents can automatically choose the appropriate proxy server (access method) for fetching a given URL. The Proxy auto-config file format was originally designed by Netscape in 1996 for the Netscape Navigator 2.0 and is a text file that defines at least one JavaScript function, FindProxyForURL(url, host), with two arguments. By convention, the PAC file is normally named proxy.pac.
The JS function syntax: string FindProxyForURL(url, host)
url The full URL being accessed or URL of the object
host The hostname extracted from the URL. This is only for convenience, it is the exact same string as between :// and the first : or / after that. The port number is not included in this parameter. It can be extracted from the URL when necessary.
return value A string describing the configuration. The return value of the function should be a semicolon seperated list of options from the following list:
DIRECT Connections should be made directly, without any proxies.
PROXY host:port The specified proxy should be used.
SOCKS host:port The specified SOCKS server should be used.
A null string is the same as DIRECT. Each option will be tried in turn until one is useable.
To use it, a PAC file is published to a web server, and client user agents are instructed to use it, either by entering the URL in the proxy connection settings of the browser or through the use of the WPAD protocol. Even though most clients will process the script regardless of the MIME type returned in the HTTP request, for the sake of completeness and to maximize compatibility, the web server should be configured to declare the MIME type of this file to be either application/x-ns-proxy-autoconfig or application/x-javascript-config.
Example :
1. function FindProxyForURL(url, host)
{
     if (isPlainHostName(host))
         return "DIRECT";
     else
          return "PROXY proxy:80";
}
2. function FindProxyForURL(url, host)
{
     if (url.substring(0, 5) == "http:")
     {
          return "PROXY proxy:80";
     }
     else if (url.substring(0, 4) == "ftp:")
     {
          return "PROXY fproxy:80";
     }
     else if (url.substring(0, 7) == "gopher:")
     {
          return "PROXY gproxy";
     }
     else if (url.substring(0, 6) == "https:")
     {
          return "PROXY secproxy:8080";
     }
     else
     {
          return "DIRECT";
     }
}
Autoconfigure the Proxy Settings from a Local Copy of the PROXY.PAC File (IE or Netscape) :
To use local copy of PROXY.PAC file, copy the file to some local directory, and point to it.
1. Copy the PROXY.PAC file to the C:\WINDOWS directory, or other directory of your choice.
2. In the browser proxy settings, configure the Automatic Proxy Configuration (Netscape) or Use Automatic Configuration Script (IE) URL to:
Netscape, use: file:///c|/windows/proxy.pac
Internet Explorer, use: file://c:/windows/proxy.pac
In Netscape, click on the Reload button.
The Web Proxy Auto-Discovery Protocol (WPAD)
WPAD is not designed to find the actual proxy settings, but to find the PAC script which tell the browser which settings to use. WPAD uses several methods for finding out location of the PAC script. If the method does not provide information about the port or the path name, then the client should use, as defaults, port 80 and /wpad.dat respectively. The client should not use a default host.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.