where # server name is one of $proxy_servers $bypass_file = "/www/data/libraries/online/noproxy_"; # The following is a list of domains that are *never* proxied. This is # done, as there are many non-IP resticted resources indexed in our # catalogue, and we don't want to have to proxy them -- it annoys the # users and loads down the server(s). # # List of parts to search for each is an array of 2 elements: # 1) a match for the domain # 2) a match for the file (optional) # All periods, question marks should be escaped with a slash # Don't forget the trailing "," after each ")"! # eg. # $no_proxy_urls = array( # array("\.nisc\.com","dbname=QWRI"), # array("\.webster\.edu") # ); $no_proxy_urls = array( array("google\.com"), array("usefulutilities\.com","support/list.html") ); # Seed the random number generator srand(make_seed()); $authenticate = true; if (isset($REMOTE_ADDR)){ if (preg_match("/^(".join("|",$local_ip).")/",$REMOTE_ADDR) && (! preg_match("/^(".join("|",$test_bad).")$/",$REMOTE_ADDR))){ $authenticate = false; } } preg_match("#^http\://([a-z0-9\.\:]+)/{0,1}(.*)#i",$_SERVER["argv"][0],$match); if (preg_match("#([a-z0-9\.]+)\:([0-9]+)#i",$match[1],$dom_match)){ $domain = $dom_match[1]; $port = $dom_match[2]; } else { $domain = $match[1]; } $file = $match[2]; # Check url against urls not to proxy foreach ($no_proxy_urls as $tmpAdd){ if (count($tmpAdd)>1){ if (ereg($tmpAdd[0],$domain) && ereg($tmpAdd[1],$file)){ $authenticate = false; } } else { if (ereg($tmpAdd[0],$domain)){ $authenticate = false; } } } # New Url # 2003/06/20 (whikloj) - Altered to do the attempt to get a proxy server first then # decide whether to proxy or not. $server = pick_proxy(); if ($server === 0 || (!$authenticate)){ # print "don't authenticate"; Header("Location: ".$_SERVER["argv"][0]); } else { # print "authenticate"; $send_to = "http://$server/login?url=".$_SERVER["argv"][0]; Header("Location: $send_to"); } exit; ###### Functions ######################################## // seed with microseconds function make_seed() { list($usec, $sec) = explode(' ', microtime()); return (float) $sec + ((float) $usec * 100000); } ######################################################################### function pick_proxy(){ global $proxy_servers,$bypass_file,$proxy_test_fail; $try = 0; do { $randval = rand(1,count($proxy_servers)); $server = $proxy_servers[($randval - 1 )]; $try++; } while (file_exists($bypass_file.$server) && ($try < $proxy_test_fail)); if (file_exists($bypass_file.$server)){ return(0); } else { return($server); } } ?>