| 1 |
<?php |
<?php |
| 2 |
// $Id: troll.admin.inc,v 1.1.2.1 2009/02/11 18:52:14 deekayen Exp $ |
// $Id: troll.admin.inc,v 1.1.2.2 2009/02/11 19:10:49 deekayen Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 7 |
*/ |
*/ |
| 8 |
|
|
| 9 |
/** |
/** |
|
* Implementation of hook_settings(). |
|
|
* |
|
| 10 |
* @return array |
* @return array |
| 11 |
*/ |
*/ |
| 12 |
function troll_admin_settings() { |
function troll_admin_settings() { |
| 361 |
* @return string |
* @return string |
| 362 |
*/ |
*/ |
| 363 |
function troll_blacklist_search($ip_address) { |
function troll_blacklist_search($ip_address) { |
| 364 |
|
$headers = array( |
| 365 |
|
array('data' => t('Network Address'), 'field' => 'net', 'sort' => 'asc'), |
| 366 |
|
array('data' => t('Broadcast Address'), 'field' => 'bcast'), |
| 367 |
|
array('data' => t('Actions'), 'field' => 'delete') |
| 368 |
|
); |
| 369 |
|
|
| 370 |
if ($ip_address == '') { |
if ($ip_address == '') { |
| 371 |
$sql = "SELECT net, bcast FROM {troll_blacklist}"; |
$result = pager_query("SELECT net, bcast FROM {troll_blacklist}", 25, 0, NULL); |
| 372 |
} |
} |
| 373 |
else { |
else { |
| 374 |
$sql = "SELECT net, bcast FROM {troll_blacklist} WHERE net <= %d AND bcast >= %d"; |
$sql = "SELECT net, bcast FROM {troll_blacklist} WHERE net <= %d AND bcast >= %d"; |
| 375 |
$longip = _troll_longip($ip_address); |
$longip = _troll_longip($ip_address); |
| 376 |
|
$sql .= tablesort_sql($headers); |
| 377 |
|
$result = pager_query($sql, 25, 0, NULL, $longip, $longip); |
| 378 |
} |
} |
|
$headers = array( |
|
|
array('data' => t('Network Address'), 'field' => 'net', 'sort' => 'asc'), |
|
|
array('data' => t('Broadcast Address'), 'field' => 'bcast'), |
|
|
array('data' => t('Actions'), 'field' => 'delete') |
|
|
); |
|
| 379 |
|
|
|
$sql .= tablesort_sql($headers); |
|
|
$result = pager_query($sql, 25, 0, NULL, $longip, $longip); |
|
| 380 |
while ($row = db_fetch_object($result)) { |
while ($row = db_fetch_object($result)) { |
| 381 |
$printnet = long2ip($row->net); |
$printnet = long2ip($row->net); |
| 382 |
$printbcast = long2ip($row->bcast); |
$printbcast = long2ip($row->bcast); |
| 383 |
$action = l(t('remove'), "admin/settings/troll/ip_blacklist/deleteblack/{$row->net}/{$row->bcast}"); |
$action = l(t('remove'), "admin/settings/troll/ip_blacklist/deleteblack/{$row->net}/{$row->bcast}"); |
| 384 |
$rows[] = array($printnet, $printbcast, $action); |
$rows[] = array($printnet, $printbcast, $action); |
| 385 |
} |
} |
| 386 |
if ($rows) { |
if (!empty($rows)) { |
| 387 |
$pager = theme('pager', NULL, 25, 0); |
$pager = theme('pager', NULL, 25, 0); |
| 388 |
if (!empty($pager)) { |
if (!empty($pager)) { |
| 389 |
$rows[] = array(array('data' => $pager, 'colspan' => 3)); |
$rows[] = array(array('data' => $pager, 'colspan' => 3)); |
| 440 |
'#title' => t('Starting IP Address'), |
'#title' => t('Starting IP Address'), |
| 441 |
'#size' => 15, |
'#size' => 15, |
| 442 |
'#maxlength' => 15, |
'#maxlength' => 15, |
| 443 |
'#default_value' => $net ? long2ip($net) : '', |
'#default_value' => isset($net) ? long2ip($net) : '', |
| 444 |
'#description' => t('IP or start to range of IPs to whitelist.'), |
'#description' => t('IP or start to range of IPs to whitelist.'), |
| 445 |
'#required' => TRUE |
'#required' => TRUE |
| 446 |
); |
); |
| 449 |
'#title' => t('Ending IP Address'), |
'#title' => t('Ending IP Address'), |
| 450 |
'#size' => 15, |
'#size' => 15, |
| 451 |
'#maxlength' => 15, |
'#maxlength' => 15, |
| 452 |
'#default_value' => $bcast ? long2ip($bcast) : '', |
'#default_value' => isset($bcast) ? long2ip($bcast) : '', |
| 453 |
'#description' => t('End of IP range to whitelist. If whitelisting a single IP, leave this blank.'), |
'#description' => t('End of IP range to whitelist. If whitelisting a single IP, leave this blank.'), |
| 454 |
'#required' => false |
'#required' => false |
| 455 |
); |
); |
| 522 |
$ip = db_fetch_object(db_query('SELECT * FROM {troll_ip_ban} WHERE iid = %d', $iid)); |
$ip = db_fetch_object(db_query('SELECT * FROM {troll_ip_ban} WHERE iid = %d', $iid)); |
| 523 |
$form['iid'] = array( |
$form['iid'] = array( |
| 524 |
'#type' => 'value', |
'#type' => 'value', |
| 525 |
'#value' => $ip->iid, |
'#value' => isset($ip->iid) ? $ip->iid : '', |
| 526 |
); |
); |
| 527 |
$form['ip_address'] = array( |
$form['ip_address'] = array( |
| 528 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 529 |
'#title' => t('IP Address'), |
'#title' => t('IP Address'), |
| 530 |
'#default_value' => $ip->ip_address, |
'#default_value' => isset($ip->ip_address) ? $ip->ip_address : '', |
| 531 |
'#description' => t('The IP address to ban.'), |
'#description' => t('The IP address to ban.'), |
| 532 |
'#required' => TRUE |
'#required' => TRUE |
| 533 |
); |
); |
| 534 |
$form['domain_name'] = array( |
$form['domain_name'] = array( |
| 535 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 536 |
'#title' => t('Domain Name'), |
'#title' => t('Domain Name'), |
| 537 |
'#default_value' => ($ip->domain_name ? $ip->domain_name : ($ip->ip_address ? gethostbyaddr($ip->ip_address) : '')), |
'#default_value' => !empty($ip->domain_name) ? $ip->domain_name : (!empty($ip->ip_address) ? gethostbyaddr($ip->ip_address) : ''), |
| 538 |
'#description' => t('The Domain Name of the IP address to ban - for reference only.') |
'#description' => t('The Domain Name of the IP address to ban - for reference only.') |
| 539 |
); |
); |
| 540 |
|
|
| 548 |
* Helper function to return the expire form elements. |
* Helper function to return the expire form elements. |
| 549 |
*/ |
*/ |
| 550 |
function troll_ip_ban_expire_form(&$form, $ip) { |
function troll_ip_ban_expire_form(&$form, $ip) { |
| 551 |
$timestamp = ($ip->expires ? $ip->expires : time()); |
$timestamp = isset($ip->expires) ? $ip->expires : time(); |
| 552 |
|
|
| 553 |
$date = getdate(gmmktime()); |
$date = getdate(gmmktime()); |
| 554 |
$curyear = $date['year']; |
$curyear = $date['year']; |
| 571 |
); |
); |
| 572 |
$form['timestamp']['expires'] = array( |
$form['timestamp']['expires'] = array( |
| 573 |
'#type' => 'checkbox', |
'#type' => 'checkbox', |
| 574 |
'#default_value' => ($ip->expires ? TRUE : FALSE) |
'#default_value' => isset($ip->expires) ? TRUE : FALSE |
| 575 |
); |
); |
| 576 |
$form['timestamp']['month'] = array( |
$form['timestamp']['month'] = array( |
| 577 |
'#type' => 'select', |
'#type' => 'select', |
| 635 |
$rows[] = array($thisip, $thisdom, $expires, $action); |
$rows[] = array($thisip, $thisdom, $expires, $action); |
| 636 |
} |
} |
| 637 |
|
|
| 638 |
|
$rows = array(); |
| 639 |
$pager = theme('pager', NULL, 25, 0); |
$pager = theme('pager', NULL, 25, 0); |
| 640 |
if (!empty($pager)) { |
if (!empty($pager)) { |
| 641 |
$rows[] = array(array('data' => $pager, 'colspan' => 5)); |
$rows[] = array(array('data' => $pager, 'colspan' => 5)); |
| 824 |
*/ |
*/ |
| 825 |
function troll_list_users($edit) { |
function troll_list_users($edit) { |
| 826 |
|
|
| 827 |
|
$args = array(); |
| 828 |
$where[] = 'u.uid <> 0'; |
$where[] = 'u.uid <> 0'; |
| 829 |
|
|
| 830 |
if (!empty($edit['username'])) { |
if (!empty($edit['username'])) { |
| 835 |
$where[] = "LOWER(u.mail) LIKE '%%%s%%' "; |
$where[] = "LOWER(u.mail) LIKE '%%%s%%' "; |
| 836 |
$args[] = drupal_strtolower($edit['mail']); |
$args[] = drupal_strtolower($edit['mail']); |
| 837 |
} |
} |
| 838 |
if (!empty($edit['ip_address']) > 0) { |
if (!empty($edit['ip_address'])) { |
| 839 |
$where[] = "LOWER(t.ip_address) LIKE '%%%s%%' "; |
$where[] = "LOWER(t.ip_address) LIKE '%%%s%%' "; |
| 840 |
$args[] = drupal_strtolower($edit['ip_address']); |
$args[] = drupal_strtolower($edit['ip_address']); |
| 841 |
} |
} |
| 842 |
if (!empty($edit['date_created']) > 0) { |
if (!empty($edit['date_created'])) { |
| 843 |
$where[] = "u.created > %d "; |
$where[] = "u.created > %d "; |
| 844 |
$args[] = drupal_strtotime($edit['date_created']); |
$args[] = drupal_strtotime($edit['date_created']); |
| 845 |
} |
} |