home *** CD-ROM | disk | FTP | other *** search
- var s_myIP, s_bIsResolvable, s_dnsIP;
-
- function FindProxyForURLEx(url, host, bIsResolvable, myIP, dnsIP)
- {
- s_myIP = myIP;
- s_dnsIP = dnsIP;
-
- if ( bIsResolvable == "TRUE" )
- s_bIsResolvable = true;
- else
- s_bIsResolvable = false;
-
- url= url.toUpperCase();
- host = host.toUpperCase();
- return ( FindProxyForURL(url, host));
- }
-
- function ReturnHost(url)
- {
- // Returns the host from the specified URL
- var host = url.split(".");
- host[0] = host[0].toUpperCase();
-
- return host[0];
- }
-
- function ReturnDomain(url)
- {
- // Returns the domain from the specified URL
- // Note: the domain is everything after the first period
-
- url= url.toUpperCase();
- var index = url.indexOf(".");
- if ( index != -1 )
- return url.substring( index, url.length);
- else
- return null;
- }
-
- function isPlainHostName(host)
- {
- // Description:
- // true if there is no domain name in the hostname (no dots)
-
- // Parameters:
- // host -- the hostname from the URL
-
- host = host.toUpperCase();
- return ( ReturnHost(host) == host );
- }
-
- function dnsDomainIs(host, domain)
- {
-
- // Description:
- // Returns true if the domain of hostname matches
-
- // Parameters:
- // host -- the hostname from the URL
- // domain -- is the domain name to test the hostname against
-
- host = host.toUpperCase();
- domain = domain.toUpperCase();
-
- return ( ReturnDomain(host) == ReturnDomain(domain) );
- }
-
- function localHostOrDomainIs(host, hostdom)
- {
- // Description:
- // Is true if the hostname matches exactly the specified
- // hostname, or if there is no domain name part in the hostname, but
- // the unqualified hostname matches
-
- // Parameters:
- // host -- the hostname from the URL
- // hostdom -- fully qualified hostname to match against
-
- host = host.toUpperCase();
- hostdom = hostdom.toUpperCase();
-
- if (host == hostdom )
- return true; // Exact match
- else if ((ReturnHost(host) == ReturnHost(hostdom) ) && (ReturnDomain(host) == null ))
- return true; // Host names match. Domain unspecified.
- else if ( host == "127.0.0.1")
- return true;
- else
- return false;
- }
-
- function isResolvable(host)
- {
- // Description:
- // Returns the static resolvable flag that was set
-
- // Parameters:
- // host -- the hostname from the URL
-
- return s_bIsResolvable;
- }
-
- function isInNet(host, pattern, mask )
- {
- // Description:
- // true if the IP address of the host matches the specified IP address pattern
-
- // Parameters:
- // host -- host IP. If host is not an IP, the DNS host IP is used instead.
- // pattern -- an IP address patter in the dot-separated format
- // mask -- mask for the IP address pattern informing which parts of the
- // IP address should be matched. 0 means ignore. 255 means match
-
- host = host.toUpperCase();
- pattern = pattern.toUpperCase();
- mask = mask.toUpperCase();
-
- var hostIP = host.split(".");
- var ipPat = pattern.split(".");
- var ipMask = mask.split(".");
-
- var ipExp = /^\d+\.\d+\.\d+\.\d+$/; // Regular expression that checks for IP formatted string
-
- if ( !(ipExp.test(host)))
- hostIP = s_dnsIP.split("."); // Host is not an IP -- default to DNS IP
-
- for ( indx = 0; indx < ipMask.length; indx++)
- {
- if ( ipMask[indx] == 255 )
- {
- if ( hostIP[indx] != ipPat[indx])
- return false;
- }
- }
- return true;
- }
-
- function dnsResolve(host)
- {
- // Description:
- // Resolves the given DNS hostname into an IP address and returns it
- // in the dot separated format as a string
-
- // Parameters:
- // host -- unused. Static hostIP is used instead
-
- return s_dnsIP;
- }
-
- function myIpAddress()
- {
- // Description:
- // Returns the static IP value that was set
-
- return s_myIP;
- }
-
-
- function dnsDomainLevels(host)
- {
- // Description:
- // Returns the number (integer) of DNS domain levels (number of dots)
- // in the hostname
-
- // Parameters:
- // host -- the hostname from the URL
-
- host = host.toUpperCase();
-
- var hostLevels = host.split(".");
- var nLevels = hostLevels.length-1;
-
- return (nLevels);
- }
-
- function shExpMatch( compareStr, shellExpression )
- {
- // Description:
- // Returns true if the string matches the specified shell expression
-
- // Parameters:
- // compareStr -- any string to compare
- // shellExpression -- shell expression to compare against
-
- compareStr = compareStr.toUpperCase();
- shellExpression = shellExpression.toUpperCase();
-
- var compStr = compareStr;
- var shellExp = shellExpression.split("*");
- var len, foundIndx;
-
- for ( indx = 0; indx < shellExp.length; indx++ )
- {
- foundIndx = compStr.indexOf( shellExp[indx] );
- if ( foundIndx != -1 )
- {
- // Strip off matching string
- len = compStr.length;
- compStr = compStr.substring(foundIndx+1, len-1);
- }
- else
- {
- // No match
- return false;
- }
- }
- return true;
- }
-
- function weekdayRange(wd1, wd2, gmt)
- {
- // Description:
- // If only one parameter is present, the function yields a true value on the
- // weekday that the parameter represents. If the string "GMT" is specified
- // as a second parameter, times are taken to be in GMT, otherwise in local timezone.
-
- // If both wd1 and wd1 are defined, the condition is true if
- // the current weekday is in between those two weekdays. Bounds are inclusive. If
- // the "GMT" parameter is specified, times are taken to be in GMT,
- // otherwise the local timezone is used.
-
- // Parameters:
- // wd1 (mandatory parameter) -- one of the weekday strings: SUN MON TUE WED THU FRI SAT
- // wd2 (optional parameter) -- one of the weekday strings: SUN MON TUE WED THU FRI SAT
- // gmt (optional parameter) -- is either the string: GMT or is not specified
-
- var weekDay = new Array( "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" );
- var wd1Indx = -1, wd2Indx = -1;
-
- wd1 = wd1.toUpperCase();
- wd2 = wd2.toUpperCase();
- gmt = gmt.toUpperCase();
-
- if ( wd2 == null )
- wd2 = wd1;
-
- for (indx = 0; indx < weekDay.length; indx++)
- {
- // Find the matching entry in the weekDay array
- if (wd1 == weekDay[indx])
- wd1Indx = indx;
- if (wd2 == weekDay[indx])
- wd2Indx = indx;
- }
- if ( wd1Indx == -1 || wd2Indx == -1 )
- return false; // Incorrect input parameters -- just exit
- else
- {
- var today = new Date();
- var dayNum = today.getDay();
-
- if ( wd2 == "GMT" || gmt == "GMT" )
- {
- // Use Greenwich Mean Time
- dayNum = today.getUTCDay();
- }
-
- if ( (dayNum == wd1Indx) || (dayNum == wd2Indx ))
- return true; // Day matches one of the bounds
-
- // The following will detect the standard weekDays in range during one week.
- // It will also detect the weekDays in range when the start day is one
- // week and the end day is in the following week
- for (idx = wd1Indx; idx != wd2Indx; idx++, idx %= 7 )
- {
- if ( idx == dayNum )
- return true;
- }
- }
- return false;
- }