f you have multiple proxy servers that support many clients, you can use a client autoconfiguration file to configure all of your Netscape Navigator clients. The autoconfiguration file contains a JavaScript function that determines which proxy, if any, the Navigator uses when accessing various URLs.
When Netscape Navigator starts, it loads the autoconfiguration file. Each time the user clicks a link or types in a URL, the Navigator uses the configuration file to determine if it should use a proxy, and if so, which proxy it should use. This feature lets you provide an easy way to configure all Netscape Navigators in your organization. There are several ways you can get the autoconfiguration file to your clients.
file:// URL.
The proxy configuration file is written in JavaScript. The JavaScript file defines a single function (called FindProxyForURL) that determines which proxy server, if any, the Navigator should use for each URL. Navigator sends the JavaScript function two parameters: the host name of the computer the Navigator is running from and the URL it's trying to obtain. The JavaScript function returns a value to the Navigator that tells it how to proceed.
The autoconfiguration file makes it possible to specify different proxies (or no proxy at all) for various types of URLs, various servers, or even various times of the day. In other words, you can have multiple specialized proxies so that, for example, one serves the .com domain, another the .edu domain, and yet another serves everything else. This lets you divide the load and get more efficient use of your proxies' disks, because there is only a single copy of any given file in the cache (instead of multiple proxies all storing the same documents).
Autoconfiguration files also support proxy failover, so if a proxy server is unavailable, the Navigator will transparently switch to another proxy server.
http://[proxy.domain]/[URI]
For example, the URL could be http://proxy.netscape.com. You don't need to specify a URI (path); however, if you do use a URI, you can then use a template to control access to the various autoconfiguration files. For example, if you create a URI called /test that contains an autoconfiguration file called /proxy.pac, you could create a template with the resource pattern http://proxy.mysite.com:8080/test/.*. You could then use that template to set up access control specifically to that directory.
You can create multiple autoconfiguration files and have them accessed through different URLs. The following table lists some example URIs and the URLs the clients would use to access them.
|
URI (path)
|
URL to the proxy
|
|
/
|
http://proxy.mysite.com
|
|
/group1
|
http://proxy.mysite.com/group1
|
|
/employees
|
http://proxy.mysite.com/employees
|
|
/managers
|
http://proxy.mysite.com/managers
|
Using pac files with a reverse proxy
Because of the way a reverse proxy works, it can be very difficult to have a proxy server work as a reverse proxy and have it server .pac files. This is because the proxy server gets a request for a file and it needs to determine if the request is for a local .pac file or if the request is for a remote document.
In order to have the proxy server act as a reverse proxy in addition to maintaining and serving a .pac file, you need to manually edit the obj.conf file to make sure the order of the NameTrans functions is correct.
Create a regular mapping to have the proxy server act as a reverse proxy. This typically tells the proxy to route all requests to the remote content server. You can add a proxy autoconfiguration file and map it to a specific directory, such as /pac. In this case, any client who wants to get the .pac file would use a URL such as:
http://proxy.mysite.com/pac
Warning!
With this mapping, however, you must be sure that the remote content server
doesn't have a similar directory.
Edit the obj.conf file to make sure that the directive and function for the proxy autoconfiguration file appears before any other mappings. This is because the proxy server normally runs through all NameTrans functions before servicing the request.
The exception is with autoconfiguration files: the proxy immediately recognizes the path and returns the .pac file. Here's an example from an obj.conf file that both uses a reverse proxy and maintains an autoconfiguration file:
<Object name="default">
NameTrans from="file:" fn="map" to="ftp:"
NameTrans from="/pac" fn="pac-map" name="file" to="/ns-home/proxy/pac/proxy.pac"
NameTrans fn="redirect" from="http://foo.*" url="http://www.acme.com"
NameTrans from="/ns-icons" fn="pfx2dir" dir="/ns-home/ns-icons" name="file"
NameTrans fn="reverse-map" from="http://web.acme.com" to="http://proxy.acme.com:8080"
NameTrans fn="map" from="http://proxy.acme.com:8080" to="http://web.acme.com"
NameTrans fn="map" from="/" to="http://web.acme.com"
PathCheck fn="url-check"
Service fn="deny-service"
AddLog fn="flex-log" name="access"
AddLog fn="urldb-record"
</Object>
Using the Server Manager forms
To create an autoconfiguration file using the Server Manager forms,
http://winternal instead of the fully qualified domain name. In this case, the Navigator goes directly to the web server instead of to the proxy.Connecting to a host in domain lets you specify up to three domain names that Navigator can access directly. When specifying the domains, begin with the dot character. For example, you could type
.netscape.com.Connecting to a resolvable host makes the Navigator go directly to the server when the client can resolve the host. This is typically used when DNS is set to resolve only local (internal) hosts. The clients would use a proxy server when connecting to servers outside of the local network.
Connecting to a host in subnet makes the Navigator go directly to the server when the client accesses a server within a particular subnet. This is useful when an organization has many subnets within a geographical area. For example, some companies might have one domain name that applies to subnets around the world, but each subnet is specific to a particular region.
Except when connecting to hosts lets you specify exceptions to the rule of going directly to a server. For example, if you entered
.netscape.com as a domain to go directly to, you could make an exception for going to home.netscape.com. This tells Navigator to use your proxy when going to home.netscape.com but go directly to any other server in the netscape.com domain.Secondary failover proxy specifies a second proxy to use if your proxy server isn't running.
Failover direct tells Navigator to go directly to the servers if your proxy server isn't running. If you specified a secondary failover proxy, Navigator tries the second proxy server before going directly to the server.
[server-root]/proxy-[identifier]/pac. You'll get a confirmation message saying the file was created correctly. Repeat these steps to create as many autoconfiguration files as you need.
See the Netscape web site or the Navigator documentation for information on JavaScript.The proxy autoconfiguration file is written using client-side JavaScript. Each file contains a single JavaScript function called FindProxyForURL that determines which proxy server, if any, the Navigator should use for each URL. Navigator sends the JavaScript function two parameters: the host name of the computer the Navigator is running from and the URL it's trying to obtain. The JavaScript function returns a value to the Navigator that tells it how to proceed. The following section describes the function syntax and the possible return values.
function FindProxyForURL(url, host)
{
...
}
For every URL Netscape Navigator accesses, the Navigator sends the url and host parameters and calls the function in the following way:
ret = FindProxyForURL(url, host);
If Netscape Navigator encounters an unavailable proxy server, Navigator will automatically retry the previously unresponsive proxy after 30 minutes, then after 1 hour, and so on, at 30 minute intervals. This means that if you temporarily shut down a proxy server, your clients will resume using the proxy no later than 30 minutes after it was restarted.
If all of the proxies are down, and the DIRECT return value isn't specified, Netscape Navigator will ask the user if it should temporarily ignore proxies and attempt direct connections instead. The Navigator will ask if proxies should be retried after 20 minutes, then again in another 20 minutes, and so on at 20 minute intervals.
Example return values
In the following example, the return value tells Netscape Navigator to use the proxy called w3proxy.netscape.com on port 8080, but if that proxy is unavailable, Navigator uses the proxy called mozilla.netscape.com on port 8080:
PROXY w3proxy.netscape.com:8080; PROXY mozilla.netscape.com:8080
In the next example, the primary proxy is w3proxy.netscape.com:8080; if that proxy is unavailable, Navigator uses mozilla.netscape.com:8080. If both proxies are unavailable, then Navigator goes directly to the server (and after 20 minutes, Navigator asks the user if they should retry the first proxy):
PROXY w3proxy.netscape.com:8080; PROXY mozilla.netscape.com:8080;
DIRECT
JavaScript functions and environment
JavaScript has several predefined functions and environmental conditions that are useful with proxying. Each of these functions checks whether or not a certain condition is met, and then returns either a value of true or false. The related utility functions are an exception because they return a DNS host name or IP address. You can use these functions within the main FindProxyForURL function to determine what return value to send to Netscape Navigator. See the examples later in this chapter for ideas on using these functions.
Each of the functions or environmental conditions is described in this section. The functions and environmental conditions that apply to Netscape Navigator integration with the proxy are:
Hostname-based conditions:
dnsDomainIs()
isInNet()
isPlainHostName()
isResolvable()
localHostOrDomainIs()
dnsDomainLevels()
dnsResolve()
myIpAddress()
shExpMatch()
dateRange()
timeRange()
weekdayRange()
This function is also useful when you are using multiple proxies for load balancing in situations where the proxy that receives the request is selected from a group of proxies based on which DNS domain the URL belongs to. For example, if you were doing load balancing by directing URLs with .edu to one proxy and those with .com to another proxy, you could check the URL host name using dnsDomainIs().
Parameters
host is the host name from the URL.
domain is the domain name to test the host name against.
Returns
true or falseExample
The following statement would be true:dnsDomainIs("www.netscape.com", ".netscape.com")The following statements would be false:dnsDomainIs("www", ".netscape.com")
dnsDomainIs("www.mcom.com", ".netscape.com")
host is a DNS host name or IP address. If a host name is passed, this function will resolve it into an IP address. pattern is an IP address pattern in the dot-separated format mask is the IP address pattern mask that determines which parts of the IP address should be matched against. 0 means ignore, 255 means match. This function is true if the IP address of the host matches the specified IP address pattern.Returns
true or falseExample
The following statement is true only if the IP address of the host matches exactly 198.95.249.79.The following statement is true only if the IP address of the host matches 198.95.*.*.isInNet(host, "198.95.249.79", "255.255.255.255")
isInNet(host, "198.95.0.0", "255.255.0.0")
host is the host name from the URL (excluding port number), only if the host name has no domain name (no dotted segments).Returns
true if host is local; false if host is remoteExample
isPlainHostName("host")If host is something likewww, then it returns true; if host is something likewww.netscape.com, it returns false.
host is the host name from the URL. This tries to resolve the host name and returns true if it succeeds.Returns
true if it can resolve the host name, or false if it cannotExample
isResolvable("host")If host is something likewwwand it can be resolved through DNS, then this function returns true.
The localHostOrDomainIs() returns true if the host name matches the specified host name exactly or if there is no domain name part in the host name that the unqualified host name matches.
Parameters
host is the host name from the URL. hostdom is the fully qualified host name to match.Returns
true or falseExample
The following statement is true (exact match): localHostOrDomainIs("www.netscape.com", "www.netscape.com")The following statement is true (host name match, domain name not specified):
localHostOrDomainIs("www", "www.netscape.com")The following statement is false (domain name mismatch):localHostOrDomainIs("www.mcom.com", "www.netscape.com")The following statement is false (host name mismatch):localHostOrDomainIs("home.netscape.com", "www.netscape.com")
host is the host name from the URL.Returns
number (integer) of DNS domain levels.Example
dnsDomainLevels("www")returns 0.dnsDomainLevels("www.netscape.com")returns 2.
host is the host name to resolve. Resolves the given DNS host name into an IP address, and returns it in the dot separated format as a string.Returns
dotted quad IP address as a string valueExample
The following example would return the string "198.95.249.79".dnsResolve("home.netscape.com")
dotted quad IP address as a string valueExample
The following example returns the string "198.95.249.79" if you were running the Navigator on the computer home.netscape.com.myIpAddress()
str is any string to compare (for example, the URL or the host name). shexp is a regular expression to compare against. This expression is true if the string matches the specified regular expression. Although the name implies shell expressions, this function currently uses regular expressions. See example 6 on page 159.Returns
true or falseExample
The first example returns true; the second returns false.shExpMatch("http://home.netscape.com/people/index.html",
".*/people/.*")shExpMatch("http://home.netscape.com/people/yourpage/index.html",
".*/mypage/.*")
dateRange(day)
dateRange(day1, day2)
dateRange(mon)
dateRange(month1, month2)
dateRange(year)
dateRange(year1, year2)
dateRange(day1, month1, day2, month2)
dateRange(month1, year1, month2, year2)
dateRange(day1, month1, year1, day2, month2, year2)
dateRange(day1, month1, year1, day2, month2, year2, gmt)
Parameters
day is an integer between 1 and 31 for the day of month. month is one of the month strings:Examples:JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DECyear is an integer for the full year number (for example, 1996). gmt is either the string "GMT," which makes time comparisons occur in Greenwich Mean Time; or it is left blank so that times are assumed to be in the local time zone. The GMT parameter can be specified in any of the call profiles, always as the last parameter. If only a single value is specified (from each category: day, month, year), the function returns a true value only on days that match that specification. If two values are specified, the result is true from the first time specified through the second time specified.
This statement is true on the first day of each month, local time zone.dateRange(1)This statement is true on the first day of each month, Greenwich Mean Time.dateRange(1, "GMT")This statement is true for the first half of each month.dateRange(1, 15)This statement is true on the 24th of December each year.dateRange(24, "DEC")This statement is true on the 24th of December, 1995.dateRange(24, "DEC", 1995)This statement is true during the first quarter of the year.dateRange("JAN", "MAR")This statement is true from June 1st through August 15th, each year.dateRange(1, "JUN", 15, "AUG")This statement is true from June 1st, 1995, until August 15th, 1995.dateRange(1, "JUN", 15, 1995, "AUG", 1995)This statement is true from October 1995 through March 1996.dateRange("OCT", 1995, "MAR", 1996)This statement is true during the entire year of 1995.dateRange(1995)This statement is true from the beginning of 1995 until the end of 1997.dateRange(1995, 1997)
timeRange(hour)
timeRange(hour1, hour2)
timeRange(hour1, min1, hour2, min2)
timeRange(hour1, min1, sec1, hour2, min2, sec2)
Parameters
hour is the hour from 0 to 23. (0 is midnight, 23 is 11:00 p.m.) min is the number of minutes from 0 to 59. sec is the number of seconds from 0 to 59. gmt is either the string "GMT" for GMT time zone, or not specified for local time zone. This parameter can be used with each of the parameter profiles, and is always the last parameter.Returns
true or falseExample
This statement is true from noon to 1:00 p.m.timerange(12, 13)This statement is true noon to 12:59 p.m. GMT.timerange(12, "GMT")This statement is true from 9:00 a.m. to 5:00 p.m.timerange(9, 17)true between midnight and 30 seconds past midnight.timerange(0, 0, 0, 0, 0, 30)
wd1 and wd2 are any one of these weekday strings:Examples:SUN MON TUE WED THU FRI SATgmt is eitherGMTfor Greenwich Mean Time, or is left out for local time. Only the first parameter, wd1, is mandatory. Either wd2, gmt, or both can be left out. If only one parameter is present, the function returns a true value on the weekday that the parameter represents. If the stringGMTis specified as a second parameter, times are taken to be in GMT, otherwise the times are in your local time zone. If both wd1 and wd2 are defined, the condition is true if the current weekday is between those two weekdays. Bounds are inclusive. The order of parameters is important; "MON", "WED" is Monday through Wednesday, but "WED", "MON" is from Wednesday to the Monday of the next week.
The following is true Monday through Friday (local time zone).weekdayRange("MON", "FRI")The following is true Monday through Friday, in Greenwich Mean Time.weekdayRange("MON", "FRI", "GMT")The following is true on Saturdays, local time.weekdayRange("SAT")The following is true on Saturdays, in Greenwich Mean Time.weekdayRange("SAT", "GMT")The following is true Friday through Monday (the order is important)weekdayRange("FRI", "MON")
Note
function FindProxyForURL(url, host)
{
if (isPlainHostName(host) ||
dnsDomainIs(host, ".netscape.com") ||
dnsDomainIs(host, ".mcom.com"))
return "DIRECT";
else
return "PROXY w3proxy.netscape.com:8080; DIRECT";
}
function FindProxyForURL(url, host)This example uses the proxy for everything except local hosts in the netscape.com domain. The hosts www.netscape.com and merchant.netscape.com also go through the proxy. The order of the exceptions increases efficiency: localHostOrDomainIs() functions get executed only for URLs that are in the local domain, not for every URL. In particular, notice the parentheses around the or expression before the and expression.
{
if ((isPlainHostName(host) ||
dnsDomainIs(host, ".netscape.com")) &&
!localHostOrDomainIs(host, "www.netscape.com") &&
!localHostOrDoaminIs(host, "merchant.netscape.com"))
return "DIRECT";
else
return "PROXY w3proxy.netscape.com:8080; DIRECT";
}
function FindProxyForURL(url, host)This example requires consulting the DNS every time, so it should be grouped with other rules so that DNS is consulted only if other rules do not yield a result:
{
if (isResolvable(host))
return "DIRECT";
else
return "PROXY proxy.mydomain.com:8080";
}
function FindProxyForURL(url, host)
{
if (isPlainHostName(host) ||
dnsDomainIs(host, ".mydomain.com") ||
isResolvable(host))
return "DIRECT";
else
return "PROXY proxy.mydomain.com:8080";
}
function FindProxyForURL(url, host)
{
if (isInNet(host, "198.95.0.0", "255.255.0.0"))
return "DIRECT";
else
return "PROXY proxy.mydomain.com:8080";You can minimize the use of DNS in this example by adding redundant rules in the beginning:
}
function FindProxyForURL(url, host)
{
if (isPlainHostName(host) ||
dnsDomainIs(host, ".mydomain.com") ||
isInNet(host, "198.95.0.0", "255.255.0.0"))
return "DIRECT";
else
return "PROXY proxy.mydomain.com:8080";
}
|
Proxy
|
Purpose
#1 |
| .com domain
#2 |
| .edu domain
#3 |
all other domains |
#4 |
hot stand-by |
|
|---|
All local accesses should be direct. All proxy servers run on the port 8080. You can concatenate strings by using the + operator in JavaScript.
function FindProxyForURL(url, host)
{
if (isPlainHostName(host) || dnsDomainIs(host, ".mydomain.com"))
return "DIRECT";
else if (dnsDomainIs(host, ".com"))
return "PROXY proxy1.mydomain.com:8080; " +
"PROXY proxy4.mydomain.com:8080";
else if (dnsDomainIs(host, ".edu"))
return "PROXY proxy2.mydomain.com:8080; " +
"PROXY proxy4.mydomain.com:8080";
else
return "PROXY proxy3.mydomain.com:8080; " +
"PROXY proxy4.mydomain.com:8080";
}
Example 6: balancing proxy load
This example is essentially the same as 5, but instead of using dnsDomainIs(), this example uses shExpMatch().
function FindProxyForURL(url, host)
{
if (isPlainHostName(host) || dnsDomainIs(host, ".mydomain.com"))
return "DIRECT";
else if (shExpMatch(host, "*.com"))
return "PROXY proxy1.mydomain.com:8080; " +
"PROXY proxy4.mydomain.com:8080";
else if (shExpMatch(host, "*.edu"))
return "PROXY proxy2.mydomain.com:8080; " +
"PROXY proxy4.mydomain.com:8080";
else
return "PROXY proxy3.mydomain.com:8080; " +
"PROXY proxy4.mydomain.com:8080";
}
Example 7: proxying a specific protocol
You can set a proxy to be for a specific protocol. Most of the standard JavaScript functionality is available for use in the FindProxyForURL() function. For example, to set different proxies based on the protocol, you can use the substring() function:
function FindProxyForURL(url, host)
You can also accomplish this using the shExpMatch() function; for example:
{
if (url.substring(0, 5) == "http:") {
return "PROXY http-proxy.mydomain.com:8080";
}
else if (url.substring(0, 4) == "ftp:") {
return "PROXY ftp-proxy.mydomain.com:8080";
}
else if (url.substring(0, 7) == "gopher:") {
return "PROXY gopher-proxy.mydomain.com:8080";
}
else if (url.substring(0, 6) == "https:" ||
url.substring(0, 6) == "snews:") {
return "PROXY security-proxy.mydomain.com:8080";
}
else {
return "DIRECT";
}
}
...
if (shExpMatch(url, "http:*")) {
return "PROXY http-proxy.mydomain.com:8080;
}
...