home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 April / Chip_2003-04_cd1.bin / sharewar / post / pn21ebus.exe / psn2app / psnshare.dll / FILE / 218
Encoding:
Text File  |  2002-12-30  |  6.7 KB  |  271 lines

  1. var s_myIP, s_bIsResolvable, s_dnsIP;
  2.  
  3. function FindProxyForURLEx(url, host, bIsResolvable, myIP, dnsIP)
  4. {
  5.     s_myIP = myIP;
  6.     s_dnsIP = dnsIP;
  7.  
  8.     if ( bIsResolvable == "TRUE" )
  9.         s_bIsResolvable = true;
  10.     else
  11.         s_bIsResolvable = false;
  12.    
  13.     url= url.toUpperCase();
  14.     host = host.toUpperCase();
  15.     return ( FindProxyForURL(url, host));
  16. }
  17.  
  18. function ReturnHost(url) 
  19. {    
  20.     // Returns the host from the specified URL
  21.     var host = url.split(".");
  22.     host[0] = host[0].toUpperCase();
  23.  
  24.     return host[0];
  25. }
  26.  
  27. function ReturnDomain(url) 
  28. {
  29.     // Returns the domain from the specified URL
  30.     // Note: the domain is everything after the first period
  31.     
  32.     url= url.toUpperCase();
  33.     var index = url.indexOf(".");
  34.     if ( index != -1 )
  35.         return url.substring( index, url.length);
  36.     else
  37.         return null;
  38. }
  39.  
  40. function isPlainHostName(host)
  41. {
  42.     // Description: 
  43.     // true if there is no domain name in the hostname (no dots)
  44.  
  45.     // Parameters:
  46.     // host -- the hostname from the URL
  47.     
  48.     host = host.toUpperCase();
  49.     return ( ReturnHost(host) == host );
  50. }
  51.  
  52. function dnsDomainIs(host, domain)
  53. {
  54.  
  55.     // Description: 
  56.     // Returns true if the domain of hostname matches
  57.     
  58.     // Parameters:
  59.     // host -- the hostname from the URL
  60.     // domain -- is the domain name to test the hostname against
  61.     
  62.     host = host.toUpperCase();
  63.     domain = domain.toUpperCase();
  64.  
  65.     return ( ReturnDomain(host) == ReturnDomain(domain) );
  66. }
  67.  
  68. function localHostOrDomainIs(host, hostdom)
  69. {
  70.     // Description: 
  71.     // Is true if the hostname matches exactly the specified 
  72.     // hostname, or if there is no domain name part in the hostname, but 
  73.     // the unqualified hostname matches
  74.     
  75.     // Parameters:
  76.     // host -- the hostname from the URL
  77.     // hostdom -- fully qualified hostname to match against
  78.     
  79.     host = host.toUpperCase();
  80.     hostdom = hostdom.toUpperCase();
  81.  
  82.     if (host == hostdom ) 
  83.         return true; // Exact match
  84.     else if ((ReturnHost(host) == ReturnHost(hostdom) ) && (ReturnDomain(host) == null ))
  85.         return true; // Host names match.  Domain unspecified.
  86.     else if ( host == "127.0.0.1")
  87.         return true;
  88.     else
  89.         return false;
  90. }
  91.  
  92. function isResolvable(host)
  93. {
  94.     // Description: 
  95.     // Returns the static resolvable flag that was set
  96.  
  97.     // Parameters:
  98.     // host -- the hostname from the URL
  99.     
  100.     return s_bIsResolvable;
  101. }
  102.  
  103. function isInNet(host, pattern, mask )
  104. {
  105.     // Description: 
  106.     // true if the IP address of the host matches the specified IP address pattern
  107.  
  108.     // Parameters:
  109.     // host -- host IP.  If host is not an IP, the DNS host IP is used instead.
  110.     // pattern -- an IP address patter in the dot-separated format
  111.     // mask -- mask for the IP address pattern informing which parts of the
  112.     //  IP address should be matched. 0 means ignore. 255 means match
  113.  
  114.     host = host.toUpperCase();
  115.     pattern = pattern.toUpperCase();
  116.     mask = mask.toUpperCase();
  117.  
  118.     var hostIP = host.split(".");
  119.     var ipPat = pattern.split(".");
  120.     var ipMask = mask.split(".");
  121.     
  122.     var ipExp = /^\d+\.\d+\.\d+\.\d+$/;    // Regular expression that checks for IP formatted string
  123.     
  124.     if ( !(ipExp.test(host)))
  125.         hostIP = s_dnsIP.split("."); // Host is not an IP -- default to DNS IP
  126.             
  127.     for ( indx = 0; indx < ipMask.length; indx++)
  128.     {
  129.         if ( ipMask[indx] == 255 )
  130.         {
  131.             if ( hostIP[indx] != ipPat[indx])
  132.                 return false;
  133.         }    
  134.     }
  135.     return true;
  136. }
  137.  
  138. function dnsResolve(host)
  139. {
  140.     // Description: 
  141.     // Resolves the given DNS hostname into an IP address and returns it 
  142.     // in the dot separated format as a string
  143.     
  144.     // Parameters:
  145.     // host -- unused.  Static hostIP is used instead
  146.     
  147.     return s_dnsIP;
  148. }
  149.  
  150. function myIpAddress()
  151. {
  152.     // Description: 
  153.     // Returns the static IP value that was set
  154.     
  155.     return s_myIP;
  156. }
  157.  
  158.  
  159. function dnsDomainLevels(host)
  160. {
  161.     // Description: 
  162.     // Returns the number (integer) of DNS domain levels (number of dots)
  163.     // in the hostname
  164.  
  165.     // Parameters:
  166.     // host -- the hostname from the URL
  167.     
  168.     host = host.toUpperCase();
  169.  
  170.     var hostLevels = host.split(".");
  171.     var nLevels = hostLevels.length-1;
  172.     
  173.     return (nLevels);
  174. }
  175.  
  176. function shExpMatch( compareStr, shellExpression )
  177. {    
  178.     // Description: 
  179.     // Returns true if the string matches the specified shell expression
  180.     
  181.     // Parameters:
  182.     // compareStr -- any string to compare
  183.     // shellExpression -- shell expression to compare against
  184.     
  185.     compareStr = compareStr.toUpperCase();
  186.     shellExpression = shellExpression.toUpperCase();
  187.  
  188.     var compStr = compareStr;
  189.     var shellExp = shellExpression.split("*");
  190.     var len, foundIndx;
  191.     
  192.     for ( indx = 0; indx < shellExp.length; indx++ )
  193.     {
  194.         foundIndx = compStr.indexOf( shellExp[indx] );
  195.         if ( foundIndx != -1 )
  196.         {
  197.             // Strip off matching string
  198.             len = compStr.length;
  199.             compStr = compStr.substring(foundIndx+1, len-1);
  200.         }
  201.         else
  202.         {
  203.             // No match
  204.             return false;
  205.         }
  206.     }
  207.     return true;
  208. }
  209.  
  210. function weekdayRange(wd1, wd2, gmt)
  211. {
  212.     // Description: 
  213.     // If only one parameter is present, the function yields a true value on the 
  214.     // weekday that the parameter represents. If the string "GMT" is specified 
  215.     // as a second parameter, times are taken to be in GMT, otherwise in local timezone. 
  216.     
  217.     // If both wd1 and wd1 are defined, the condition is true if 
  218.     // the current weekday is in between those two weekdays. Bounds are inclusive. If 
  219.     // the "GMT" parameter is specified, times are taken to be in GMT, 
  220.     // otherwise the local timezone is used. 
  221.     
  222.     // Parameters:
  223.     // wd1 (mandatory parameter) -- one of the weekday strings: SUN MON TUE WED THU FRI SAT
  224.     // wd2 (optional parameter) -- one of the weekday strings: SUN MON TUE WED THU FRI SAT
  225.     // gmt (optional parameter) -- is either the string: GMT or is not specified
  226.     
  227.     var weekDay = new Array( "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" );
  228.     var wd1Indx = -1, wd2Indx = -1;
  229.     
  230.     wd1 = wd1.toUpperCase();
  231.     wd2 = wd2.toUpperCase();
  232.     gmt = gmt.toUpperCase();
  233.     
  234.     if ( wd2 == null )
  235.         wd2 = wd1;
  236.     
  237.     for (indx = 0; indx < weekDay.length; indx++)
  238.     {
  239.         // Find the matching entry in the weekDay array
  240.         if (wd1 == weekDay[indx])
  241.             wd1Indx = indx;
  242.         if (wd2 == weekDay[indx])
  243.             wd2Indx = indx;
  244.     }
  245.     if ( wd1Indx == -1 || wd2Indx == -1 )
  246.         return false;    // Incorrect input parameters -- just exit
  247.     else
  248.     {
  249.         var today = new Date();
  250.         var dayNum = today.getDay();
  251.         
  252.         if ( wd2 == "GMT" || gmt == "GMT" )
  253.         {
  254.             // Use Greenwich Mean Time
  255.             dayNum = today.getUTCDay();
  256.         }
  257.         
  258.         if ( (dayNum == wd1Indx) || (dayNum == wd2Indx ))
  259.             return true; // Day matches one of the bounds
  260.         
  261.         // The following will detect the standard weekDays in range during one week.
  262.         // It will also detect the weekDays in range when the start day is one
  263.         //  week and the end day is in the following week
  264.         for (idx = wd1Indx; idx != wd2Indx; idx++, idx %= 7 )
  265.         {
  266.             if ( idx == dayNum )
  267.                 return true;    
  268.         }
  269.     }
  270.     return false;
  271. }