Only in troll: CVS
Only in ./scripts/troll: LICENSE.txt
diff -up ./scripts/troll/troll.admin.inc troll/troll.admin.inc
--- ./scripts/troll/troll.admin.inc	2010-05-05 22:37:01.000000000 -0400
+++ troll/troll.admin.inc	2011-01-24 15:57:08.000000000 -0500
@@ -571,14 +571,14 @@ function troll_ip_ban_form($form_state, 
   $form['ip_address'] = array(
     '#type' => 'textfield',
     '#title' => t('IP Address'),
-    '#default_value' => !empty($ip->ip_address) ? $ip->ip_address : '',
+    '#default_value' => !empty($ip->ip_address) ? long2ip($ip->ip_address) : '',
     '#description' => t('The IP address to ban.'),
     '#required' => TRUE
   );
   $form['domain_name'] = array(
     '#type' => 'textfield',
     '#title' => t('Domain Name'),
-    '#default_value' => !empty($ip->domain_name) ? $ip->domain_name : (!empty($ip->ip_address) ? gethostbyaddr($ip->ip_address) : ''),
+    '#default_value' => !empty($ip->domain_name) ? $ip->domain_name : (!empty($ip->ip_address) ? gethostbyaddr(long2ip($ip->ip_address)) : ''),
     '#description' => t('The Domain Name of the IP address to ban - for reference only.')
   );
 
@@ -612,8 +612,7 @@ function troll_ip_ban_form_submit($form,
  * Helper function to return the expire form elements.
  */
 function troll_ip_ban_expire_form(&$form, $ip) {
-  $timestamp = isset($ip->expires) ? $ip->expires : time();
-
+  $timestamp = (isset($ip->expires) && $ip->expires > 0) ? $ip->expires : time();
   $date = getdate(gmmktime());
   $curyear = $date['year'];
   $i = 0;
@@ -635,7 +634,7 @@ function troll_ip_ban_expire_form(&$form
   );
   $form['timestamp']['expires'] = array(
     '#type' => 'checkbox',
-    '#default_value' => isset($ip->expires) ? TRUE : FALSE
+    '#default_value' => (isset($ip->expires) && $ip->expires > 0) ? TRUE : FALSE
   );
   $form['timestamp']['month'] = array(
     '#type' => 'select',
@@ -673,8 +672,8 @@ function troll_display_ip() {
   $sql .= tablesort_sql($headers);
   $result = pager_query($sql, 25, 0, $count_sql);
   while ($row = db_fetch_object($result)) {
-    $thisip = l($row->ip_address, 'admin/user/troll/ip_ban/edit/'. $row->iid);
-    $thisdom = l(($row->domain_name ? $row->domain_name : gethostbyname($row->ip_address)), 'admin/user/troll/ip_ban/edit/'. $row->iid);
+    $thisip = l(long2ip($row->ip_address), 'admin/user/troll/ip_ban/edit/'. $row->iid);
+    $thisdom = l(($row->domain_name ? $row->domain_name : gethostbyname(long2ip($row->ip_address))), 'admin/user/troll/ip_ban/edit/'. $row->iid);
     $expires = ($row->expires ? date('M d, Y', $row->expires) : t('never'));
     $action = l(t('remove'), 'admin/user/troll/ip_ban/delete/'. $row->iid);
     $rows[] = array($thisip, $thisdom, $expires, $action);
@@ -697,7 +696,7 @@ function troll_confirm_delete_ip_form($f
     '#type' => 'value',
     '#value' => $iid,
   );
-  return confirm_form($form, t('Remove Ban for IP %ip?', array('%ip' => $ip->ip_address)), 'admin/user/troll/ip_ban', t('Are you sure you want to remove the ban on this IP?'));
+  return confirm_form($form, t('Remove Ban for IP %ip?', array('%ip' => long2ip($ip->ip_address))), 'admin/user/troll/ip_ban', t('Are you sure you want to remove the ban on this IP?'));
 }
 
 /**
@@ -717,15 +716,15 @@ function troll_confirm_ban_ip_form($form
   $ip = db_fetch_object(db_query_range('SELECT ip_address FROM {troll_ip_track} WHERE uid = %d ORDER BY accessed DESC', $uid, 0, 1));
   $form['ip_address'] = array(
     '#type' => 'value',
-    '#value' => $ip->ip_address,
+    '#value' => long2ip($ip->ip_address),
   );
   $form['domain_name'] = array(
     '#type' => 'value',
-    '#value' => gethostbyaddr($ip->ip_address),
+    '#value' => gethostbyaddr(long2ip($ip->ip_address)),
   );
   troll_ip_ban_expire_form($form, $ip);
 
-  return confirm_form($form, t('Ban IP %ip?', array('%ip' => $ip->ip_address)), 'admin/user/troll/ip_ban', t('Are you sure you want to ban this IP?'));
+  return confirm_form($form, t('Ban IP %ip?', array('%ip' => long2ip($ip->ip_address))), 'admin/user/troll/ip_ban', t('Are you sure you want to ban this IP?'));
 }
 
 /**
@@ -897,8 +896,8 @@ function troll_list_users($edit) {
     $args[] = drupal_strtolower($edit['mail']);
   }
   if (!empty($edit['ip_address'])) {
-    $where[] = "LOWER(t.ip_address) LIKE '%%%s%%' ";
-    $args[] = drupal_strtolower($edit['ip_address']);
+    $where[] = "t.ip_address LIKE '%%%d%%' ";
+    $args[] = troll_ip_address($edit['ip_address']);
   }
   if (!empty($edit['date_created'])) {
     $where[] = "u.created > %d ";
@@ -929,7 +928,7 @@ function troll_list_users($edit) {
     $name = l($user->name, 'admin/user/troll/search/view/'. $user->uid, array('title' => t('View detailed user information')));
     $email = $user->mail;
     $status = ($user->status ? t('Active') : t('Blocked'));
-    $ip = ($user->ip_address ? l($user->ip_address, 'admin/user/troll/search/view/'. $user->uid, array('title' => t('View detailed user information'))) : t('none'));
+    $ip = ($user->ip_address ? l(long2ip($user->ip_address), 'admin/user/troll/search/view/'. $user->uid, array('title' => t('View detailed user information'))) : t('none'));
     $recorded = ($user->recorded ? date('M d, Y', $user->recorded) : t('none recorded'));
     $created = date('M d, Y', $user->created);
     $actions = array();
@@ -1031,7 +1030,7 @@ function troll_search_user_detail($uid) 
   // Get IP history.
   $results = db_query('SELECT * FROM {troll_ip_track} WHERE uid = %d ORDER BY created DESC', $uid);
   while ($ip = db_fetch_object($results)) {
-    $banned = db_fetch_object(db_query('SELECT * FROM {troll_ip_ban} WHERE ip_address = \'%s\'', $ip->ip_address));
+    $banned = db_fetch_object(db_query('SELECT * FROM {troll_ip_ban} WHERE ip_address = %d', long2ip($ip->ip_address)));
     if (!empty($banned->ip_address)) {
       if ($banned->expires && $banned->expires < time()) {
         $status = l(t('expired'), 'admin/user/troll/ip_ban/edit/'. $banned->iid, array('title' => t('Edit IP ban information')));
@@ -1043,7 +1042,7 @@ function troll_search_user_detail($uid) 
     else {
       $status = l(t('not banned'), 'admin/user/troll/ip_ban/user/'. $uid, array('title' => t('Ban this IP')));
     }
-    $rows[] = array($ip->ip_address, $status, format_date($ip->accessed, 'large'), format_date($ip->created, 'large'), exec('host '. $ip->ip_address));
+    $rows[] = array(long2ip($ip->ip_address), $status, format_date($ip->accessed, 'large'), format_date($ip->created, 'large'), exec('host '. long2ip($ip->ip_address)));
   }
 
   if ($rows) {
diff -up ./scripts/troll/troll.info troll/troll.info
--- ./scripts/troll/troll.info	2010-11-12 07:23:00.000000000 -0500
+++ troll/troll.info	2011-01-19 16:50:51.000000000 -0500
@@ -1,12 +1,6 @@
 ; $Id $
 name = Troll
 description = Provides tools for community sites including users by IP address, banning IP addresses, advanced user searching, and blocking user by role.
+version = 6.x-1.0
 core = 6.x
 php = 5.2
-
-; Information added by drupal.org packaging script on 2010-11-12
-version = "6.x-1.x-dev"
-core = "6.x"
-project = "troll"
-datestamp = "1289564580"
-
diff -up ./scripts/troll/troll.install troll/troll.install
--- ./scripts/troll/troll.install	2009-05-09 01:47:46.000000000 -0400
+++ troll/troll.install	2011-01-19 16:50:51.000000000 -0500
@@ -79,6 +79,35 @@ function troll_update_6000() {
 }
 
 /**
+ * Implementation of hook_update_N().
+ */
+function troll_update_6100() {
+  $ret = array();
+  global  $db_url;
+
+  if ('mysql' == drupal_substr($db_url, 0, 5)) {
+    $ret[] = update_sql("UPDATE {troll_ip_track} SET ip_address = INET_ATON(ip_address)");
+    $ret[] = update_sql("UPDATE {troll_ip_ban} SET ip_address = INET_ATON(ip_address)");
+  }
+  else {
+    $result = db_result(db_query("SELECT * FROM {troll_ip_track} order by created ASC"));
+    while ($ip = db_fetch_object($result)) {
+      $ret[] = update_sql("UPDATE {troll_ip_track} SET ip_address = " . troll_ip_address($ip->ip_address) . " WHERE uid = $ip->uid and created = $ip->created");
+    }
+
+    $result = db_result(db_query("SELECT * FROM {troll_ip_ban} order by created ASC"));
+    while ($ip = db_fetch_object($result)) {
+      $ret[] = update_sql("UPDATE {troll_ip_ban} SET ip_address = " . troll_ip_address($ip->ip_address) . " WHERE iid = $ip->iid");
+    }
+  }
+
+  db_drop_unique_key($ret, 'troll_ip_ban', 'ip');
+  db_change_field($ret, 'troll_ip_ban', 'ip_address', 'ip_address', array('type' => 'int', 'size' => 'big', 'length' => '20', 'not null' => TRUE, 'default' => 0), array('unique keys' => array('ip' => array('ip_address'))));
+  db_change_field($ret, 'troll_ip_track', 'ip_address', 'ip_address', array('type' => 'int', 'size' => 'big', 'length' => '20', 'not null' => TRUE, 'default' => 0), array('indexes' => array('ip' => array('uid', 'ip_address'))));
+  return $ret;
+}
+
+/**
  * Implementation of hook_uninstall().
  */
 function troll_uninstall() {
@@ -105,31 +134,33 @@ function troll_schema() {
   );
   $schema['troll_ip_track'] = array(
     'fields' => array(
-         'uid' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'disp-width' => '11'),
-         'accessed' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '11'),
-         'ip_address' => array('type' => 'varchar', 'length' => '39', 'not null' => TRUE, 'default' => ''),
-         'created' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'disp-width' => '11')),
+      'uid' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'disp-width' => '11'),
+      'accessed' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '11'),
+      'ip_address' => array('type' => 'int', 'size' => 'big', 'length' => '20', 'not null' => TRUE, 'default' => 0),
+      'created' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'disp-width' => '11')),
     'indexes' => array(
-         'uid' => array('uid')),
+      'uid' => array('uid'),
+      'ip' => array('ip_address')
+    ),
   );
   $schema['troll_ip_ban'] = array(
     'fields' => array(
-         'iid' => array('type' => 'serial', 'not null' => TRUE, 'disp-width' => '11'),
-         'ip_address' => array('type' => 'varchar', 'length' => '39', 'not null' => TRUE, 'default' => ''),
-         'domain_name' => array('type' => 'varchar', 'length' => '255', 'not null' => TRUE, 'default' => ''),
-         'expires' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '11'),
-         'created' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '11'),
-         'uid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10')),
+       'iid' => array('type' => 'serial', 'not null' => TRUE, 'disp-width' => '11'),
+       'ip_address' => array('type' => 'int', 'size' => 'big', 'length' => '20', 'not null' => TRUE, 'default' => 0),
+       'domain_name' => array('type' => 'varchar', 'length' => '255', 'not null' => TRUE, 'default' => ''),
+       'expires' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '11'),
+       'created' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '11'),
+       'uid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10')),
     'primary key' => array('iid'),
     'unique keys' => array(
-         'ip' => array('ip_address')),
+       'ip' => array('ip_address')),
   );
   $schema['troll_blacklist'] = array(
     'fields' => array(
-         'net' => array('type' => 'int', 'size' => 'big', 'not null' => TRUE),
-         'bcast' => array('type' => 'int', 'size' => 'big', 'not null' => TRUE)),
+       'net' => array('type' => 'int', 'size' => 'big', 'not null' => TRUE),
+       'bcast' => array('type' => 'int', 'size' => 'big', 'not null' => TRUE)),
     'unique keys' => array(
-         'net' => array('net', 'bcast')),
+       'net' => array('net', 'bcast')),
   );
 
   return $schema;
diff -up ./scripts/troll/troll.module troll/troll.module
--- ./scripts/troll/troll.module	2010-05-05 22:43:17.000000000 -0400
+++ troll/troll.module	2011-01-19 16:50:51.000000000 -0500
@@ -17,6 +17,7 @@
  */
 function troll_boot() {
   $ip = ip_address();
+  $troll_ip = troll_ip_address();
   if (troll_is_blacklisted()) {
     $alt_page = variable_get('troll_blacklist_alt_page', 0);
     if ($alt_page) {
@@ -65,19 +66,19 @@ function troll_boot() {
   global $user;
 
   if ($user->uid) {
-    $track = db_result(db_query("SELECT COUNT(ip_address) FROM {troll_ip_track} WHERE uid = %d AND ip_address = '%s'", $user->uid, $ip));
+    $track = db_result(db_query("SELECT COUNT(ip_address) FROM {troll_ip_track} WHERE uid = %d AND ip_address = %d", $user->uid, $troll_ip));
     if (!empty($track)) {
       // A record for this IP exists. Update accessed timestamp.
-      db_query("UPDATE {troll_ip_track} SET accessed = %d WHERE uid = %d AND ip_address = '%s'", time(), $user->uid, $ip);
+      db_query("UPDATE {troll_ip_track} SET accessed = %d WHERE uid = %d AND ip_address = %d", time(), $user->uid, $troll_ip);
     }
     else {
       // Insert new IP record for user.
-      db_query("INSERT INTO {troll_ip_track} (uid, ip_address, created, accessed) VALUES (%d, '%s', %d, %d)", $user->uid, $ip, time(), time());
+      db_query("INSERT INTO {troll_ip_track} (uid, ip_address, created, accessed) VALUES (%d, %d, %d, %d)", $user->uid, $troll_ip, time(), time());
     }
   }
 
   if (variable_get('troll_enable_ip_ban', 1)) {
-    $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));
+    $domain = db_result(db_query_range("SELECT domain_name FROM {troll_ip_ban} WHERE (expires > %d OR expires = 0) AND ip_address = %d)", time(), $troll_ip, 0, 1));
     if ($domain !== FALSE) {
       global $base_url;
       watchdog('troll', 'IP Ban: @addr Domain: @domain', array('@addr' => $ip, '@domain' => $domain), WATCHDOG_INFO);
@@ -375,6 +376,20 @@ function troll_remove_blacklist($net, $b
 }
 
 /**
+ * Converts a quad-dotted IP address string to an integer.
+ *
+ * @param $ip
+ *  String IP address
+ * @return
+ * String containing the unsigned integer value.  Because PHP's integer type is signed, and many IP addresses will result in negative integers,
+ * but a string representation can show the unsigned IP address.
+ */
+function troll_ip_address($ip = "0") {
+  $ip = empty($ip) ? ip_address() : $ip;
+  return sprintf("%u", ip2long($ip));
+}
+
+/**
  * Removes IP block from the whitelist.
  *
  * @param $edit array
@@ -398,8 +413,8 @@ function troll_insert_ip($edit) {
 
   $expires = ($edit['expires'] == 1) ? mktime(23, 59, 0, $edit['month'], $edit['day'], $edit['year']) : 0;
 
-  db_query("DELETE FROM {troll_ip_ban} WHERE ip_address = '%s'", $edit['ip_address']);
-  if (db_query("INSERT INTO {troll_ip_ban} (ip_address, domain_name, created, expires, uid) VALUES ('%s', '%s', %d, %d, %d)", $edit['ip_address'], $edit['domain_name'], time(), $expires, $user->uid)) {
+  db_query("DELETE FROM {troll_ip_ban} WHERE ip_address = %d)", troll_ip_address($edit['ip_address']));
+  if (db_query("INSERT INTO {troll_ip_ban} (ip_address, domain_name, created, expires, uid) VALUES (%d, '%s', %d, %d, %d)", troll_ip_address($edit['ip_address']), $edit['domain_name'], time(), $expires, $user->uid)) {
     drupal_set_message(t('IP ban added: %ip', array('%ip' => $edit['ip_address'])));
   }
   else {
@@ -417,7 +432,7 @@ function troll_update_ip($edit) {
 
   $expires = ($edit['expires'] == 1) ? mktime(23, 59, 0, $edit['month'], $edit['day'], $edit['year']) : 0;
 
-  if (db_query("UPDATE {troll_ip_ban} SET ip_address = '%s', domain_name = '%s', expires = %d, uid = %d WHERE iid = %d", $edit['ip_address'], $edit['domain_name'], $expires, $user->uid, $edit['iid'])) {
+  if (db_query("UPDATE {troll_ip_ban} SET ip_address = %d, domain_name = '%s', expires = %d, uid = %d WHERE iid = %d", troll_ip_address($edit['ip_address']), $edit['domain_name'], $expires, $user->uid, $edit['iid'])) {
     drupal_set_message(t('IP ban updated: %ip', array('%ip' => $edit['ip_address'])));
   }
   else {
@@ -431,12 +446,12 @@ function troll_update_ip($edit) {
  */
 function troll_check_ip() {
   global $user;
-  $sql = "SELECT uid FROM {troll_ip_track} WHERE ip_address = '%s' AND uid = %d";
-  $chk = db_query($sql, ip_address(), $user->uid);
+  $sql = "SELECT uid FROM {troll_ip_track} WHERE ip_address = %d) AND uid = %d";
+  $chk = db_query($sql, troll_ip_address(), $user->uid);
   $check = db_fetch_array($chk);
   if (!isset($check['uid'])) {
-    $isql = "INSERT INTO {troll_ip_track} (uid, ip_address, created) VALUES (%d, '%s', %d)";
-    db_query($isql, $user->uid, ip_address(), time());
+    $isql = "INSERT INTO {troll_ip_track} (uid, ip_address, created) VALUES (%d, %d, %d)";
+    db_query($isql, $user->uid, troll_ip_address(), time());
   }
 }
 
