| 16 |
* Implementation of hook_boot(). |
* Implementation of hook_boot(). |
| 17 |
*/ |
*/ |
| 18 |
function troll_boot() { |
function troll_boot() { |
| 19 |
|
$ip = ip_address(); |
| 20 |
if (troll_is_blacklisted()) { |
if (troll_is_blacklisted()) { |
| 21 |
$alt_page = variable_get('troll_blacklist_alt_page', 0); |
$alt_page = variable_get('troll_blacklist_alt_page', 0); |
| 22 |
if ($alt_page) { |
if ($alt_page) { |
| 23 |
switch ($alt_page) { |
switch ($alt_page) { |
| 24 |
case 'blank': |
case 'blank': |
| 25 |
|
watchdog('troll', 'Alternate blank page displayed to @ip', array('@ip' => $ip), WATCHDOG_INFO); |
| 26 |
exit; |
exit; |
| 27 |
break; |
break; |
| 28 |
case '404': |
case '404': |
| 29 |
// drupal_not_found() can make a mess in admin logs with watchdog() |
// drupal_not_found() can make a mess in admin logs with watchdog() |
| 30 |
drupal_set_header('HTTP/1.0 404 Not Found'); |
drupal_set_header('HTTP/1.0 404 Not Found'); |
| 31 |
drupal_set_title(t('Page not found')); |
drupal_set_title(t('Page not found')); |
| 32 |
|
watchdog('troll', 'Alternate 404 page displayed to @ip', array('@ip' => $ip), WATCHDOG_INFO); |
| 33 |
print theme('page', ''); |
print theme('page', ''); |
| 34 |
exit; |
exit; |
| 35 |
break; |
break; |
| 36 |
case 'redirect': |
case 'redirect': |
| 37 |
// The default value of troll_blacklist_alt_url should not be an |
// The default value of troll_blacklist_alt_url should not be an |
| 38 |
// empty string because then we redirect to ourselves; so use 127.0.0.1. |
// empty string because then we redirect to ourselves; so use 127.0.0.1. |
| 39 |
header('Location: '. variable_get('troll_blacklist_alt_url', 'http://127.0.0.1')); |
$url = variable_get('troll_blacklist_alt_url', 'http://127.0.0.1'); |
| 40 |
|
watchdog('troll', '@ip redirected to @url', array('@ip' => $ip, '@url' => $url), WATCHDOG_INFO); |
| 41 |
|
header('Location: '. $url); |
| 42 |
exit; |
exit; |
| 43 |
break; |
break; |
| 44 |
} |
} |
| 48 |
if ($req_mod == 'notice_post_drop' && !empty($_POST)) { |
if ($req_mod == 'notice_post_drop' && !empty($_POST)) { |
| 49 |
$_POST = array(); |
$_POST = array(); |
| 50 |
drupal_set_message(t('Your data submission was ignored because you are visiting from a blacklisted location.')); |
drupal_set_message(t('Your data submission was ignored because you are visiting from a blacklisted location.')); |
| 51 |
|
watchdog('troll', 'Data submission ignored with notification to user from @ip', array('@ip' => $ip), WATCHDOG_DEBUG); |
| 52 |
} |
} |
| 53 |
elseif ($req_mod == 'silent_post_drop') { |
elseif ($req_mod == 'silent_post_drop') { |
| 54 |
$_POST = array(); |
$_POST = array(); |
| 55 |
|
watchdog('troll', 'Data submission ignored silently from @ip', array('@ip' => $ip), WATCHDOG_DEBUG); |
| 56 |
} |
} |
| 57 |
|
|
| 58 |
if (variable_get('troll_blacklist_stutter', 0)) { |
if (variable_get('troll_blacklist_stutter', 0)) { |
| 59 |
sleep(rand(1, 5)); |
sleep(rand(1, 5)); |
| 60 |
|
watchdog('troll', 'Page load stuttered from @ip', array('@ip' => $ip), WATCHDOG_DEBUG); |
| 61 |
} |
} |
| 62 |
} |
} |
| 63 |
|
|
| 64 |
global $user; |
global $user; |
| 65 |
|
|
| 66 |
if ($user->uid) { |
if ($user->uid) { |
| 67 |
$track = db_result(db_query("SELECT COUNT(ip_address) FROM {troll_ip_track} WHERE uid = %d AND ip_address = '%s'", $user->uid, ip_address())); |
$track = db_result(db_query("SELECT COUNT(ip_address) FROM {troll_ip_track} WHERE uid = %d AND ip_address = '%s'", $user->uid, $ip)); |
| 68 |
if (!empty($track)) { |
if (!empty($track)) { |
| 69 |
// A record for this IP exists. Update accessed timestamp. |
// A record for this IP exists. Update accessed timestamp. |
| 70 |
db_query("UPDATE {troll_ip_track} SET accessed = %d WHERE uid = %d AND ip_address = '%s'", time(), $user->uid, ip_address()); |
db_query("UPDATE {troll_ip_track} SET accessed = %d WHERE uid = %d AND ip_address = '%s'", time(), $user->uid, $ip); |
| 71 |
} |
} |
| 72 |
else { |
else { |
| 73 |
// Insert new IP record for user. |
// Insert new IP record for user. |
| 74 |
db_query("INSERT INTO {troll_ip_track} (uid, ip_address, created, accessed) VALUES (%d, '%s', %d, %d)", $user->uid, ip_address(), time(), time()); |
db_query("INSERT INTO {troll_ip_track} (uid, ip_address, created, accessed) VALUES (%d, '%s', %d, %d)", $user->uid, $ip, time(), time()); |
| 75 |
} |
} |
| 76 |
} |
} |
| 77 |
|
|
| 78 |
if (variable_get('troll_enable_ip_ban', 1)) { |
if (variable_get('troll_enable_ip_ban', 1)) { |
| 79 |
$ban = db_result(db_query('SELECT COUNT(ip_address) FROM {troll_ip_ban} WHERE (expires > %d OR expires = 0) AND ip_address = \'%s\'', time(), ip_address())); |
$domain = db_result(db_query_range("SELECT domain_name FROM {troll_ip_ban} WHERE (expires > %d OR expires = 0) AND ip_address = '%s'", time(), $ip, 0, 1)); |
| 80 |
if (!empty($ban)) { |
if ($domain !== FALSE) { |
| 81 |
global $base_url; |
global $base_url; |
| 82 |
watchdog('troll', 'IP Ban: !addr', array('!addr' => ip_address()), WATCHDOG_NOTICE); |
watchdog('troll', 'IP Ban: @addr Domain: @domain', array('@addr' => $ip, '@domain' => $domain), WATCHDOG_INFO); |
| 83 |
$troll_ip_ban_redirect = variable_get('troll_ip_ban_redirect', ''); |
$troll_ip_ban_redirect = variable_get('troll_ip_ban_redirect', ''); |
| 84 |
if (empty($troll_ip_ban_redirect)) { |
if (empty($troll_ip_ban_redirect)) { |
| 85 |
include_once('includes/common.inc'); |
include_once('includes/common.inc'); |
| 135 |
return '<div class="messages error">'. t('IP banning is currently disabled. You can enable it in the !settings page.', array('!settings' => l(t('settings'), 'admin/user/troll/settings'))); |
return '<div class="messages error">'. t('IP banning is currently disabled. You can enable it in the !settings page.', array('!settings' => l(t('settings'), 'admin/user/troll/settings'))); |
| 136 |
} |
} |
| 137 |
break; |
break; |
| 138 |
|
case 'admin/user/troll/dnsbl': |
| 139 |
|
return t('Please note: Querying DNS blacklists happens real-time on comment submission. Each additional blacklist that gets queried adds to the delay in saving comments. Longer delays could time out page submissions for users or cause your site to appear slow.'); |
| 140 |
|
break; |
| 141 |
} |
} |
| 142 |
} |
} |
| 143 |
|
|
| 365 |
* @param $edit array |
* @param $edit array |
| 366 |
*/ |
*/ |
| 367 |
function troll_remove_blacklist($net, $bcast) { |
function troll_remove_blacklist($net, $bcast) { |
| 368 |
if (db_query('DELETE FROM {troll_blacklist} WHERE net = %d AND bcast = %d', $net, $bcast)) { |
if (db_query('DELETE FROM {troll_blacklist} WHERE net = %f AND bcast = %f', $net, $bcast)) { |
| 369 |
drupal_set_message(t('Blacklist block removed.')); |
drupal_set_message(t('Blacklist block removed.')); |
| 370 |
} |
} |
| 371 |
else { |
else { |
| 379 |
* @param $edit array |
* @param $edit array |
| 380 |
*/ |
*/ |
| 381 |
function troll_remove_whitelist($net, $bcast) { |
function troll_remove_whitelist($net, $bcast) { |
| 382 |
if (db_query('DELETE FROM {troll_whitelist} WHERE net = %d AND bcast = %d', $net, $bcast)) { |
if (db_query('DELETE FROM {troll_whitelist} WHERE net = %f AND bcast = %f', $net, $bcast)) { |
| 383 |
drupal_set_message(t('IP whitelist removed.')); |
drupal_set_message(t('IP whitelist removed.')); |
| 384 |
} |
} |
| 385 |
else { |
else { |
| 457 |
return FALSE; |
return FALSE; |
| 458 |
} |
} |
| 459 |
else { |
else { |
| 460 |
$blacklisted = db_result(db_query('SELECT COUNT(b.net) FROM {troll_blacklist} AS b WHERE b.net <= %d AND b.bcast >= %d', $longip, $longip)); |
$blacklisted = db_result(db_query('SELECT COUNT(b.net) FROM {troll_blacklist} AS b WHERE b.net <= %f AND b.bcast >= %f', $longip, $longip)); |
| 461 |
$whitelisted = db_result(db_query('SELECT COUNT(w.net) FROM {troll_whitelist} AS w WHERE w.net <= %d AND w.bcast >= %d', $longip, $longip)); |
$whitelisted = db_result(db_query('SELECT COUNT(w.net) FROM {troll_whitelist} AS w WHERE w.net <= %f AND w.bcast >= %f', $longip, $longip)); |
| 462 |
return $whitelisted ? FALSE : $blacklisted; |
return $whitelisted ? FALSE : $blacklisted; |
| 463 |
} |
} |
| 464 |
} |
} |