/[drupal]/contributions/modules/troll/troll.module
ViewVC logotype

Diff of /contributions/modules/troll/troll.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.9.2.2 by deekayen, Mon Mar 5 07:33:47 2007 UTC revision 1.9.2.3 by deekayen, Tue May 5 20:21:24 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: troll.module,v 1.9.2.1 2007/03/05 07:17:33 deekayen Exp $  // $Id: troll.module,v 1.9.2.2 2007/03/05 07:33:47 deekayen Exp $
3    
4  function troll_init() {  function troll_init() {
5    global $user;    global $user;
6    if($user->uid) {    if ($user->uid) {
7      $track = db_fetch_object(db_query("SELECT * FROM {troll_ip_track} WHERE uid = %d AND ip_address = '%s'", $user->uid,  $_SERVER['REMOTE_ADDR']));      $track = db_fetch_object(db_query("SELECT * FROM {troll_ip_track} WHERE uid = %d AND ip_address = '%s'", $user->uid,  $_SERVER['REMOTE_ADDR']));
8      if($track->uid) {      if ($track->uid) {
9        // record for this IP exists, update accessed timestamp        // record for this IP exists, update accessed timestamp
10        db_query("UPDATE {troll_ip_track} SET accessed = %d WHERE uid = %d AND ip_address = '%s'", time(), $user->uid,  $_SERVER['REMOTE_ADDR']);        db_query("UPDATE {troll_ip_track} SET accessed = %d WHERE uid = %d AND ip_address = '%s'", time(), $user->uid,  $_SERVER['REMOTE_ADDR']);
11      }      }
# Line 15  function troll_init() { Line 15  function troll_init() {
15      }      }
16    }    }
17    
18    if(variable_get('troll_enable_ip_ban', FALSE)) {    if (variable_get('troll_enable_ip_ban', FALSE)) {
19      $ban = db_fetch_object(db_query('SELECT * FROM {troll_ip_ban} WHERE (expires > %d OR expires = 0) AND ip_address = \'%s\'', time(), $_SERVER['REMOTE_ADDR']));      $ban = db_fetch_object(db_query('SELECT * FROM {troll_ip_ban} WHERE (expires > %d OR expires = 0) AND ip_address = \'%s\'', time(), $_SERVER['REMOTE_ADDR']));
20      if($ban->ip_address) {      if ($ban->ip_address) {
21        global $base_url;        global $base_url;
22        watchdog('troll', 'IP Ban: '. $_SERVER['REMOTE_ADDR'], WATCHDOG_NOTICE);        watchdog('troll', 'IP Ban: '. $_SERVER['REMOTE_ADDR'], WATCHDOG_NOTICE);
23        $page = variable_get('troll_ip_ban_redirect', 'modules/troll/blocked.html');        $page = variable_get('troll_ip_ban_redirect', 'modules/troll/blocked.html');
# Line 151  function troll_ip_ban($op = NULL, $iid = Line 151  function troll_ip_ban($op = NULL, $iid =
151  }  }
152    
153  function troll_ip_form($iid = NULL) {  function troll_ip_form($iid = NULL) {
154    if($iid) {    if ($iid) {
155      $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));
156      $form = form_hidden('iid', $ip->iid);      $form = form_hidden('iid', $ip->iid);
157      $submit = form_submit('Update Banned IP');      $submit = form_submit('Update Banned IP');
# Line 192  function troll_display_ip() { Line 192  function troll_display_ip() {
192    
193    $sql = 'SELECT iid, ip_address, domain_name, expires, uid FROM {troll_ip_ban}';    $sql = 'SELECT iid, ip_address, domain_name, expires, uid FROM {troll_ip_ban}';
194    
195          $headers = array(    $headers = array(
196                  array('data' => t('IP Address'), 'field' => 'ip_address'),      array('data' => t('IP Address'), 'field' => 'ip_address'),
197                  array('data' => t('Domain Name'), 'field' => 'domain_name'),      array('data' => t('Domain Name'), 'field' => 'domain_name'),
198      array('data' => t('Expires'), 'field' => 'expires', 'sort' => 'desc'),      array('data' => t('Expires'), 'field' => 'expires', 'sort' => 'desc'),
199      array('data' => t('Actions'), 'field' => 'delete')      array('data' => t('Actions'), 'field' => 'delete')
200          );    );
201    
202          $sql .= tablesort_sql($headers);    $sql .= tablesort_sql($headers);
203          $result = pager_query($sql, 25);    $result = pager_query($sql, 25);
204    while($row = db_fetch_object($result)) {    while ($row = db_fetch_object($result)) {
205      $thisip = l($row->ip_address, 'admin/troll/ip_ban/edit/'. $row->iid);      $thisip = l($row->ip_address, 'admin/troll/ip_ban/edit/'. $row->iid);
206      $thisdom = l(($row->domain_name ? $row->domain_name : shell_exec('host '. $row->ip_address)), 'admin/troll/ip_ban/edit/'. $row->iid);      $thisdom = l(($row->domain_name ? $row->domain_name : shell_exec('host '. $row->ip_address)), 'admin/troll/ip_ban/edit/'. $row->iid);
207      $expires = ($row->expires ? date('M d, Y', $row->expires) : t('never'));      $expires = ($row->expires ? date('M d, Y', $row->expires) : t('never'));
# Line 209  function troll_display_ip() { Line 209  function troll_display_ip() {
209      $rows[] = array($thisip, $thisdom, $expires, $action);      $rows[] = array($thisip, $thisdom, $expires, $action);
210    }    }
211    
212          $pager = theme('pager', NULL, 25, 0, tablesort_pager());    $pager = theme('pager', NULL, 25, 0, tablesort_pager());
213          if (!empty($pager)) {    if (!empty($pager)) {
214                  $rows[] = array(array('data' => $pager, 'colspan' => 5));      $rows[] = array(array('data' => $pager, 'colspan' => 5));
215          }    }
216    
217    $content = theme("table", $headers, $rows);    $content = theme("table", $headers, $rows);
218    
# Line 246  function troll_update_ip($edit) { Line 246  function troll_update_ip($edit) {
246    
247    $expires = ($edit['expires'] ? mktime(23, 59, 0, $edit['month'], $edit['day'], $edit['year']) : 0);    $expires = ($edit['expires'] ? mktime(23, 59, 0, $edit['month'], $edit['day'], $edit['year']) : 0);
248    
249    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 = '%s', domain_name = '%s', expires = %d, uid = %d WHERE iid = %d", $edit['ip_address'], $edit['domain_name'], $expires, $user->uid, $edit['iid'])) {
250      drupal_set_message(t('IP ban updated'));      drupal_set_message(t('IP ban updated'));
251    }    }
252    else {    else {
# Line 256  function troll_update_ip($edit) { Line 256  function troll_update_ip($edit) {
256    
257  function troll_confirm_delete_ip($iid) {  function troll_confirm_delete_ip($iid) {
258    $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));
259    if($ip) {    if ($ip) {
260      $form = form_submit(t('Remove')).form_submit(t('Cancel'));      $form = form_submit(t('Remove')).form_submit(t('Cancel'));
261      return form(form_item(t('Remove Ban for IP %ip?', array('%ip' => $ip->ip_address)), $form, t('Are you sure you want to remove the ban on this IP?')));      return form(form_item(t('Remove Ban for IP %ip?', array('%ip' => $ip->ip_address)), $form, t('Are you sure you want to remove the ban on this IP?')));
262    }    }
# Line 325  function troll_list_users($edit) { Line 325  function troll_list_users($edit) {
325    
326    $where[] = 'u.uid != 0';    $where[] = 'u.uid != 0';
327    
328    if(strlen($edit['username']) > 0) {    if (strlen($edit['username']) > 0) {
329      $where[] = "LOWER(u.name) LIKE '%%" . strtolower($edit['username']) . "%%' ";      $where[] = "LOWER(u.name) LIKE '%%" . strtolower($edit['username']) . "%%' ";
330    }    }
331    if(strlen($edit['mail']) > 0) {    if (strlen($edit['mail']) > 0) {
332      $where[] = "LOWER(u.mail) LIKE '%%" . strtolower($edit['mail']) . "%%' ";      $where[] = "LOWER(u.mail) LIKE '%%" . strtolower($edit['mail']) . "%%' ";
333    }    }
334    if(strlen($edit['ip_address']) > 0) {    if (strlen($edit['ip_address']) > 0) {
335      $where[] = "LOWER(t.ip_address) LIKE '%%" . strtolower($edit['ip_address']) . "%%' ";      $where[] = "LOWER(t.ip_address) LIKE '%%" . strtolower($edit['ip_address']) . "%%' ";
336    }    }
337    if(strlen($edit['date_created']) > 0) {    if (strlen($edit['date_created']) > 0) {
338      $where[] = "u.created > '" . strtotime($edit['date_created']) . "' ";      $where[] = "u.created > '" . strtotime($edit['date_created']) . "' ";
339    }    }
340    
# Line 342  function troll_list_users($edit) { Line 342  function troll_list_users($edit) {
342    
343    $sql .= ' WHERE '. implode(' AND ', $where);    $sql .= ' WHERE '. implode(' AND ', $where);
344    
345          $headers = array(    $headers = array(
346                  array('data' => t('Username'), 'field' => 'u.name'),      array('data' => t('Username'), 'field' => 'u.name'),
347      array('data' => t('Email'), 'field' => 'u.mail'),      array('data' => t('Email'), 'field' => 'u.mail'),
348                  array('data' => t('Status'), 'field' => 'u.status'),      array('data' => t('Status'), 'field' => 'u.status'),
349      array('data' => t('IP Address'), 'field' => 't.ip_address'),      array('data' => t('IP Address'), 'field' => 't.ip_address'),
350                  array('data' => t('Last Access'), 'field' => 't.created'),      array('data' => t('Last Access'), 'field' => 't.created'),
351      array('data' => t('Account Created'), 'field' => 'u.created'),      array('data' => t('Account Created'), 'field' => 'u.created'),
352      array('data' => t('Actions'), 'field' => 'actions')      array('data' => t('Actions'), 'field' => 'actions')
353          );    );
354    
355    $sql .= ' GROUP BY u.uid, u.name, u.mail, u.status, t.ip_address, u.created';    $sql .= ' GROUP BY u.uid, u.name, u.mail, u.status, t.ip_address, u.created';
356    $sql .= tablesort_sql($headers);    $sql .= tablesort_sql($headers);
# Line 358  function troll_list_users($edit) { Line 358  function troll_list_users($edit) {
358    $count = 'SELECT COUNT(*) FROM {users} u LEFT JOIN {troll_ip_track} t ON u.uid = t.uid WHERE '. implode(' AND ', $where) .' AND u.uid != 0';    $count = 'SELECT COUNT(*) FROM {users} u LEFT JOIN {troll_ip_track} t ON u.uid = t.uid WHERE '. implode(' AND ', $where) .' AND u.uid != 0';
359    $result = pager_query($sql, 25, 0, $count);    $result = pager_query($sql, 25, 0, $count);
360    
361    while($user = db_fetch_object($result)) {    while ($user = db_fetch_object($result)) {
362      $name = l($user->name, 'admin/troll/view/'. $user->uid, array('title' => t('View detailed user information')));      $name = l($user->name, 'admin/troll/view/'. $user->uid, array('title' => t('View detailed user information')));
363      $email = $user->mail;      $email = $user->mail;
364      $status = ($user->status ? t('Active') : t('Blocked'));      $status = ($user->status ? t('Active') : t('Blocked'));
# Line 367  function troll_list_users($edit) { Line 367  function troll_list_users($edit) {
367      $created = date('M d, Y', $user->created);      $created = date('M d, Y', $user->created);
368      $actions = array();      $actions = array();
369    
370      if(variable_get('troll_block_role', NULL)) {      if (variable_get('troll_block_role', NULL)) {
371        $actions[] = l(t('Block User'), 'admin/troll/block/'. $user->uid);        $actions[] = l(t('Block User'), 'admin/troll/block/'. $user->uid);
372      }      }
373      else {      else {
374        $actions[] = l(t('Setup Block Role'), 'admin/settings/troll');        $actions[] = l(t('Setup Block Role'), 'admin/settings/troll');
375      }      }
376      if($user->ip_address) {      if ($user->ip_address) {
377        $actions[] = l(t('Ban IP'), 'admin/troll/ip_ban/user/'. $user->uid);        $actions[] = l(t('Ban IP'), 'admin/troll/ip_ban/user/'. $user->uid);
378      }      }
379      $action = theme('links', $actions);      $action = theme('links', $actions);
380      $rows[] = array($name, $email, $status, $ip, $recorded, $created, $action);      $rows[] = array($name, $email, $status, $ip, $recorded, $created, $action);
381    }    }
382    
383          $pager = theme('pager', NULL, 25, 0, array_merge(tablesort_pager(), $edit));    if (isset($edit) && is_array($edit) && count($edit) > 0) {
384        $pager = array_merge(tablesort_pager(), $edit);
385      }
386      else {
387        $pager = tablesort_pager();
388      }
389      $pager = theme('pager', NULL, 25, 0, $pager);
390    
391          if (!empty($pager)) {    if (!empty($pager)) {
392                  $rows[] = array(array('data' => $pager, 'colspan' => 5));      $rows[] = array(array('data' => $pager, 'colspan' => 5));
393          }    }
394    
395    return theme("table", $headers, $rows);    return theme("table", $headers, $rows);
396  }  }
# Line 405  function troll_search_user_detail($uid) Line 411  function troll_search_user_detail($uid)
411    $group .= form_item(t('Account Created'), format_date($user->created, 'long'));    $group .= form_item(t('Account Created'), format_date($user->created, 'long'));
412    $group .= form_item(t('Last Access'), format_date($user->changed, 'long'));    $group .= form_item(t('Last Access'), format_date($user->changed, 'long'));
413    $links[] = l(t('Block User'), 'admin/troll/block/'. $user->uid);    $links[] = l(t('Block User'), 'admin/troll/block/'. $user->uid);
414    if($user->ip_address) {    if ($user->ip_address) {
415      $links[] = l(t('Ban IP'), 'admin/troll/ip_ban/user/'. $user->uid);      $links[] = l(t('Ban IP'), 'admin/troll/ip_ban/user/'. $user->uid);
416    }    }
417    $group .= form_item(t('Status'), ($user->status ? t('Active') : t('Blocked')));    $group .= form_item(t('Status'), ($user->status ? t('Active') : t('Blocked')));
# Line 446  function troll_search_user_detail($uid) Line 452  function troll_search_user_detail($uid)
452    while ($node = db_fetch_object($rdat)) {    while ($node = db_fetch_object($rdat)) {
453      $rows[] = array(l($node->title, 'node/'. $node->nid) .' '. theme('mark', node_mark($node->nid, $node->changed)), node_invoke($node, 'node_name'), date('M d, Y', $node->created), ($node->status ? t('published') : t('not published')));      $rows[] = array(l($node->title, 'node/'. $node->nid) .' '. theme('mark', node_mark($node->nid, $node->changed)), node_invoke($node, 'node_name'), date('M d, Y', $node->created), ($node->status ? t('published') : t('not published')));
454    }    }
455    if($rows) {    if ($rows) {
456      $pheader = array(t('Title'), t('Type'), t('Created'), t('Status'));      $pheader = array(t('Title'), t('Type'), t('Created'), t('Status'));
457      $posts = theme('table', $pheader, $rows);      $posts = theme('table', $pheader, $rows);
458    }    }
# Line 463  function troll_search_user_detail($uid) Line 469  function troll_search_user_detail($uid)
469      $rows[] = array(l($node->subject, 'node/'. $node->nid .'#comment-'. $node->cid) .' '. theme('mark', node_mark($node->nid, $node->changed)), date('M d, Y', $node->timestamp), ($node->status ? t('published') : t('not published')));      $rows[] = array(l($node->subject, 'node/'. $node->nid .'#comment-'. $node->cid) .' '. theme('mark', node_mark($node->nid, $node->changed)), date('M d, Y', $node->timestamp), ($node->status ? t('published') : t('not published')));
470    }    }
471    
472    if($rows) {    if ($rows) {
473      $cheader = array(t('Subject'), t('Date Created'), t('Status'));      $cheader = array(t('Subject'), t('Date Created'), t('Status'));
474      $posts = theme('table', $cheader, $rows);      $posts = theme('table', $cheader, $rows);
475    }    }
# Line 475  function troll_search_user_detail($uid) Line 481  function troll_search_user_detail($uid)
481  function troll_block_user($uid) {  function troll_block_user($uid) {
482    db_query('UPDATE {users} SET status = 0 WHERE uid = %d', $uid);    db_query('UPDATE {users} SET status = 0 WHERE uid = %d', $uid);
483    db_query('DELETE FROM {users_roles} WHERE uid = %d', $uid);    db_query('DELETE FROM {users_roles} WHERE uid = %d', $uid);
484    if(variable_get('troll_block_role', NULL)) {    if (variable_get('troll_block_role', NULL)) {
485      db_query('INSERT INTO {users_roles} (uid, rid) VALUES (%d, %d)', $uid, variable_get('troll_block_role', '0'));      db_query('INSERT INTO {users_roles} (uid, rid) VALUES (%d, %d)', $uid, variable_get('troll_block_role', '0'));
486    }    }
487    drupal_set_message(t('Blocked user %link', array('%link' => l($uid, 'admin/troll/view/'. $uid))));    drupal_set_message(t('Blocked user %link', array('%link' => l($uid, 'admin/troll/view/'. $uid))));
488  }  }
   
 ?>  

Legend:
Removed from v.1.9.2.2  
changed lines
  Added in v.1.9.2.3

  ViewVC Help
Powered by ViewVC 1.1.3