2 require_once('init.php');
4 header('Content-type: text/html; charset=utf-8');
6 // check blocks in place for external servers
7 if (strpos($_SERVER["REMOTE_ADDR"],'193.63.75.') !== 0 &&
8 strpos(CONST_WhitelistedIPs, ','.$_SERVER["REMOTE_ADDR"].',') === false)
11 $aBucketKeys = array();
13 if (isset($_SERVER["HTTP_REFERER"])) $aBucketKeys[] = str_replace('www.','',strtolower(parse_url($_SERVER["HTTP_REFERER"], PHP_URL_HOST)));
14 if (isset($_SERVER["REMOTE_ADDR"])) $aBucketKeys[] = $_SERVER["REMOTE_ADDR"];
15 if (isset($_GET["email"])) $aBucketKeys[] = $_GET["email"];
17 $fBucketVal = doBucket($aBucketKeys,
18 (defined('CONST_ConnectionBucket_PageType')?constant('CONST_ConnectionBucket_Cost_'.CONST_ConnectionBucket_PageType):1) + user_busy_cost(),
19 CONST_ConnectionBucket_LeakRate, CONST_ConnectionBucket_BlockLimit);
21 if ($fBucketVal > CONST_ConnectionBucket_WaitLimit && $fBucketVal < CONST_ConnectionBucket_BlockLimit)
23 $m = getBucketMemcache();
24 $iCurrentSleeping = $m->increment('sleepCounter');
25 if (false === $iCurrentSleeping)
27 $m->add('sleepCounter', 0);
28 $iCurrentSleeping = $m->increment('sleepCounter');
30 if ($iCurrentSleeping >= CONST_ConnectionBucket_MaxSleeping || isBucketSleeping($aBucketKeys))
32 // Too many threads sleeping already. This becomes a hard block.
33 $fBucketVal = doBucket($aBucketKeys, CONST_ConnectionBucket_BlockLimit, CONST_ConnectionBucket_LeakRate, CONST_ConnectionBucket_BlockLimit);
37 setBucketSleeping($aBucketKeys, true);
38 sleep(($fBucketVal - CONST_ConnectionBucket_WaitLimit)/CONST_ConnectionBucket_LeakRate);
39 $fBucketVal = doBucket($aBucketKeys, CONST_ConnectionBucket_LeakRate, CONST_ConnectionBucket_LeakRate, CONST_ConnectionBucket_BlockLimit);
40 setBucketSleeping($aBucketKeys, false);
42 $m->decrement('sleepCounter');
45 if (strpos(CONST_BlockedIPs, ','.$_SERVER["REMOTE_ADDR"].',') !== false || $fBucketVal >= CONST_ConnectionBucket_BlockLimit)
47 echo "Your IP has been blocked. \n";
48 echo "Please create a nominatim trac ticket (http://trac.openstreetmap.org/newticket?component=nominatim) to request this to be removed. \n";
49 echo "Information on the Nominatim usage policy can be found here: http://wiki.openstreetmap.org/wiki/Nominatim#Usage_Policy \n";