| 249 |
'access arguments' => array('administer troll'), |
'access arguments' => array('administer troll'), |
| 250 |
'type' => MENU_CALLBACK |
'type' => MENU_CALLBACK |
| 251 |
); |
); |
| 252 |
|
$items['admin/user/troll/dnsbl'] = array( |
| 253 |
|
'title' => 'DNS Blacklist', |
| 254 |
|
'page callback' => 'drupal_get_form', |
| 255 |
|
'page arguments' => array('troll_dnsbl_settings'), |
| 256 |
|
'access arguments' => array('administer troll'), |
| 257 |
|
'weight' => 5, |
| 258 |
|
'type' => MENU_LOCAL_TASK |
| 259 |
|
); |
| 260 |
|
$items['admin/user/troll/dnsbl/test'] = array( |
| 261 |
|
'title' => 'IP test', |
| 262 |
|
'page callback' => 'drupal_get_form', |
| 263 |
|
'page arguments' => array('troll_dnsbl_test_form'), |
| 264 |
|
'access arguments' => array('administer troll'), |
| 265 |
|
'type' => MENU_CALLBACK |
| 266 |
|
); |
| 267 |
$items['admin/user/troll/settings'] = array( |
$items['admin/user/troll/settings'] = array( |
| 268 |
'title' => 'Settings', |
'title' => 'Settings', |
| 269 |
'page callback' => 'drupal_get_form', |
'page callback' => 'drupal_get_form', |
| 270 |
'page arguments' => array('troll_admin_settings'), |
'page arguments' => array('troll_admin_settings'), |
| 271 |
'access arguments' => array('administer site configuration'), |
'access arguments' => array('administer site configuration'), |
| 272 |
'type' => MENU_LOCAL_TASK, |
'type' => MENU_LOCAL_TASK, |
| 273 |
'weight' => 5 |
'weight' => 6 |
| 274 |
); |
); |
| 275 |
$items['user/%troll_user/troll'] = array( |
$items['user/%troll_user/troll'] = array( |
| 276 |
'title' => 'Troll Track', |
'title' => 'Troll Track', |
| 501 |
drupal_set_message(t('Blocked user !link.', array('!link' => l($name, "admin/user/troll/search/view/$uid")))); |
drupal_set_message(t('Blocked user !link.', array('!link' => l($name, "admin/user/troll/search/view/$uid")))); |
| 502 |
} |
} |
| 503 |
} |
} |
| 504 |
|
|
| 505 |
|
/** |
| 506 |
|
* Implementation of hook_comment(). |
| 507 |
|
*/ |
| 508 |
|
function troll_comment($comment, $op) { |
| 509 |
|
if (variable_get('troll_dnsbl_active', 0) != 1) { |
| 510 |
|
return; |
| 511 |
|
} |
| 512 |
|
|
| 513 |
|
switch ($op) { |
| 514 |
|
case 'insert': |
| 515 |
|
case 'update': |
| 516 |
|
$comment = (object)$comment; |
| 517 |
|
|
| 518 |
|
$ip = ip_address(); |
| 519 |
|
$blacklisted = _troll_dnsbl_blacklisted($ip); |
| 520 |
|
|
| 521 |
|
if ($blacklisted == TRUE) { |
| 522 |
|
$operation = comment_operations('unpublish'); |
| 523 |
|
$query = $operation['unpublish'][1]; |
| 524 |
|
db_query($query, $comment->cid); |
| 525 |
|
drupal_set_message(t('Your comment has been queued for moderation by site administrators and will be published after approval.')); |
| 526 |
|
watchdog('troll', 'Comment unpublished for DNSBL: %subject.', array('%subject' => $comment->subject), WATCHDOG_INFO, l(t('view'), 'node/'. $comment->nid, array('fragment' => 'comment-'. $comment->cid))); |
| 527 |
|
} |
| 528 |
|
else { |
| 529 |
|
watchdog('troll', 'IP %ip is not DNS blacklisted.', array('%ip' => $ip), WATCHDOG_INFO, l(t('view'), 'node/'. $comment->nid, array('fragment' => 'comment-'. $comment->cid))); |
| 530 |
|
} |
| 531 |
|
return; |
| 532 |
|
default: |
| 533 |
|
return; |
| 534 |
|
} |
| 535 |
|
} |
| 536 |
|
|
| 537 |
|
/** |
| 538 |
|
* Check if an IP is blacklisted or not. |
| 539 |
|
* |
| 540 |
|
* @param $ip the IP to check. |
| 541 |
|
* @return true if blacklisted or false |
| 542 |
|
*/ |
| 543 |
|
function _troll_dnsbl_blacklisted($ip) { |
| 544 |
|
$servers = _troll_dnsbl_default_servers(); |
| 545 |
|
$servers = explode("\n", $servers); |
| 546 |
|
|
| 547 |
|
$threshold = variable_get('troll_dnsbl_threshold', 1); |
| 548 |
|
|
| 549 |
|
foreach ($servers as $server) { |
| 550 |
|
// we trim because we end up with a new line at the end of each server |
| 551 |
|
// for an obscure reason! |
| 552 |
|
if (_troll_dnsbl_check($ip, trim($server))) { |
| 553 |
|
$threshold--; |
| 554 |
|
} |
| 555 |
|
|
| 556 |
|
if ($threshold == 0) { |
| 557 |
|
return TRUE; |
| 558 |
|
} |
| 559 |
|
} |
| 560 |
|
|
| 561 |
|
return FALSE; |
| 562 |
|
} |
| 563 |
|
|
| 564 |
|
/** |
| 565 |
|
* Perform a DNS query |
| 566 |
|
* |
| 567 |
|
* @param $ip the IP to check |
| 568 |
|
* @param $server the DNS to check. |
| 569 |
|
* @return true if the entry is there otherise false even if there's an error. |
| 570 |
|
*/ |
| 571 |
|
function _troll_dnsbl_check($ip, $server) { |
| 572 |
|
// Let's reverse the IP |
| 573 |
|
$ip = implode('.', array_reverse(explode('.', $ip))); |
| 574 |
|
|
| 575 |
|
$request = implode('.', array($ip, $server)); |
| 576 |
|
|
| 577 |
|
$result = gethostbyname($request); |
| 578 |
|
|
| 579 |
|
if ($request == $result) { |
| 580 |
|
// No domain |
| 581 |
|
return FALSE; |
| 582 |
|
} |
| 583 |
|
else { |
| 584 |
|
$octats = explode('.', $result); |
| 585 |
|
return $octats[0] == 127; |
| 586 |
|
} |
| 587 |
|
} |
| 588 |
|
|
| 589 |
|
/** |
| 590 |
|
* Return the list of default DNSBL servers |
| 591 |
|
* |
| 592 |
|
* @return the list of default servers. |
| 593 |
|
*/ |
| 594 |
|
function _troll_dnsbl_default_servers() { |
| 595 |
|
return variable_get('troll_dnsbl_list', implode("\n", array( |
| 596 |
|
'dnsbl.sorbs.net', |
| 597 |
|
'bl.spamcop.net', |
| 598 |
|
'dnsbl.njabl.org', |
| 599 |
|
'cbl.abuseat.org', |
| 600 |
|
'sbl-xbl.spamhaus.org' |
| 601 |
|
))); |
| 602 |
|
} |