[ Index ]

PHP Cross Reference of MyBB 1.8.21

title

Body

[close]

/admin/modules/tools/ -> spamlog.php (source)

   1  <?php
   2  /**
   3   * MyBB 1.8
   4   * Copyright 2014 MyBB Group, All Rights Reserved
   5   * Website: http://www.mybb.com
   6   * License: http://www.mybb.com/about/license
   7  
   8   */
   9  
  10  // Disallow direct access to this file for security reasons
  11  if(!defined("IN_MYBB"))
  12  {
  13      die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
  14  }
  15  
  16  $page->add_breadcrumb_item($lang->spam_logs, "index.php?module=tools-spamlog");
  17  
  18  $sub_tabs['spam_logs'] = array(
  19      'title' => $lang->spam_logs,
  20      'link' => "index.php?module=tools-spamlog",
  21      'description' => $lang->spam_logs_desc
  22  );
  23  $sub_tabs['prune_spam_logs'] = array(
  24      'title' => $lang->prune_spam_logs,
  25      'link' => "index.php?module=tools-spamlog&amp;action=prune",
  26      'description' => $lang->prune_spam_logs_desc
  27  );
  28  
  29  $plugins->run_hooks("admin_tools_spamlog_begin");
  30  
  31  if($mybb->input['action'] == 'prune')
  32  {
  33      if(!is_super_admin($mybb->user['uid']))
  34      {
  35          flash_message($lang->cannot_perform_action_super_admin_general, 'error');
  36          admin_redirect("index.php?module=tools-spamlog");
  37      }
  38  
  39      $plugins->run_hooks("admin_tools_spamlog_prune");
  40  
  41      if($mybb->request_method == 'post')
  42      {
  43          $is_today = false;
  44          $mybb->input['older_than'] = $mybb->get_input('older_than', MyBB::INPUT_INT);
  45          if($mybb->input['older_than'] <= 0)
  46          {
  47              $is_today = true;
  48              $mybb->input['older_than'] = 1;
  49          }
  50          $where = 'dateline < '.(TIME_NOW-($mybb->input['older_than']*86400));
  51  
  52          // Searching for entries in a specific module
  53          if($mybb->input['filter_username'])
  54          {
  55              $where .= " AND username='".$db->escape_string($mybb->input['filter_username'])."'";
  56          }
  57          
  58          // Searching for entries in a specific module
  59          if($mybb->input['filter_email'])
  60          {
  61              $where .= " AND email='".$db->escape_string($mybb->input['filter_email'])."'";
  62          }
  63  
  64          $query = $db->delete_query("spamlog", $where);
  65          $num_deleted = $db->affected_rows();
  66  
  67          $plugins->run_hooks("admin_tools_spamlog_prune_commit");
  68  
  69          // Log admin action
  70          log_admin_action($mybb->input['older_than'], $mybb->input['filter_username'], $mybb->input['filter_email'], $num_deleted);
  71  
  72          $success = $lang->success_pruned_spam_logs;
  73          if($is_today == true && $num_deleted > 0)
  74          {
  75              $success .= ' '.$lang->note_logs_locked;
  76          }
  77          elseif($is_today == true && $num_deleted == 0)
  78          {
  79              flash_message($lang->note_logs_locked, 'error');
  80              admin_redirect('index.php?module=tools-spamlog');
  81          }
  82          flash_message($success, 'success');
  83          admin_redirect('index.php?module=tools-spamlog');
  84      }
  85      $page->add_breadcrumb_item($lang->prune_spam_logs, 'index.php?module=tools-spamlog&amp;action=prune');
  86      $page->output_header($lang->prune_spam_logs);
  87      $page->output_nav_tabs($sub_tabs, 'prune_spam_logs');
  88  
  89      // Fetch filter options
  90      $sortbysel[$mybb->input['sortby']] = 'selected="selected"';
  91      $ordersel[$mybb->input['order']] = 'selected="selected"';
  92  
  93      $form = new Form("index.php?module=tools-spamlog&amp;action=prune", "post");
  94      $form_container = new FormContainer($lang->prune_spam_logs);
  95      $form_container->output_row($lang->spam_username, "", $form->generate_text_box('filter_username', $mybb->input['filter_username'], array('id' => 'filter_username')), 'filter_username');
  96      $form_container->output_row($lang->spam_email, "", $form->generate_text_box('filter_email', $mybb->input['filter_email'], array('id' => 'filter_email')), 'filter_email');
  97      if(!$mybb->input['older_than'])
  98      {
  99          $mybb->input['older_than'] = '30';
 100      }
 101      $form_container->output_row($lang->date_range, "", $lang->older_than.$form->generate_numeric_field('older_than', $mybb->input['older_than'], array('id' => 'older_than', 'style' => 'width: 50px', 'min' => 0))." {$lang->days}", 'older_than');
 102      $form_container->end();
 103      $buttons[] = $form->generate_submit_button($lang->prune_spam_logs);
 104      $form->output_submit_wrapper($buttons);
 105      $form->end();
 106  
 107      $page->output_footer();
 108  }
 109  
 110  if(!$mybb->input['action'])
 111  {
 112      $plugins->run_hooks("admin_tools_spamlog_start");
 113  
 114      $page->output_header($lang->spam_logs);
 115  
 116      $page->output_nav_tabs($sub_tabs, 'spam_logs');
 117      
 118      $perpage = $mybb->get_input('perpage', MyBB::INPUT_INT);
 119      if(!$perpage)
 120      {
 121          $perpage = 20;
 122      }
 123  
 124      $where = '1=1';
 125  
 126      $additional_criteria = array();
 127  
 128      // Searching for entries witha  specific username
 129      if($mybb->input['username'])
 130      {
 131          $where .= " AND username='".$db->escape_string($mybb->input['username'])."'";
 132          $additional_criteria[] = "username=".urlencode($mybb->input['username']);
 133      }
 134  
 135      // Searching for entries with a specific email
 136      if($mybb->input['email'])
 137      {
 138          $where .= " AND email='".$db->escape_string($mybb->input['email'])."'";
 139          $additional_criteria[] = "email=".urlencode($mybb->input['email']);
 140      }
 141      
 142      // Searching for entries with a specific IP
 143      if($mybb->input['ipaddress'] > 0)
 144      {
 145          $where .= " AND ipaddress=".$db->escape_binary(my_inet_pton($mybb->input['ipaddress']));
 146          $additional_criteria[] = "ipaddress=".urlencode($mybb->input['ipaddress']);
 147      }
 148  
 149      if($additional_criteria)
 150      {
 151          $additional_criteria = "&amp;".implode("&amp;", $additional_criteria);
 152      }
 153      else
 154      {
 155          $additional_criteria = '';
 156      }
 157  
 158      // Order?
 159      switch($mybb->input['sortby'])
 160      {
 161          case "username":
 162              $sortby = "username";
 163              break;
 164          case "email":
 165              $sortby = "email";
 166              break;
 167          case "ipaddress":
 168              $sortby = "ipaddress";
 169              break;
 170          default:
 171              $sortby = "dateline";
 172      }
 173      $order = $mybb->input['order'];
 174      if($order != "asc")
 175      {
 176          $order = "desc";
 177      }
 178  
 179      $query = $db->simple_select("spamlog", "COUNT(sid) AS count", $where);
 180      $rescount = $db->fetch_field($query, "count");
 181  
 182      // Figure out if we need to display multiple pages.
 183      if($mybb->input['page'] != "last")
 184      {
 185          $pagecnt = $mybb->get_input('page', MyBB::INPUT_INT);
 186      }
 187  
 188      $logcount = (int)$rescount;
 189      $pages = $logcount / $perpage;
 190      $pages = ceil($pages);
 191  
 192      if($mybb->input['page'] == "last")
 193      {
 194          $pagecnt = $pages;
 195      }
 196  
 197      if($pagecnt > $pages)
 198      {
 199          $pagecnt = 1;
 200      }
 201  
 202      if($pagecnt)
 203      {
 204          $start = ($pagecnt-1) * $perpage;
 205      }
 206      else
 207      {
 208          $start = 0;
 209          $pagecnt = 1;
 210      }
 211  
 212      $table = new Table;
 213      $table->construct_header($lang->spam_username, array('width' => '20%'));
 214      $table->construct_header($lang->spam_email, array("class" => "align_center", 'width' => '20%'));
 215      $table->construct_header($lang->spam_ip, array("class" => "align_center", 'width' => '20%'));
 216      $table->construct_header($lang->spam_date, array("class" => "align_center", 'width' => '20%'));
 217      $table->construct_header($lang->spam_confidence, array("class" => "align_center", 'width' => '20%'));
 218  
 219      $query = $db->simple_select("spamlog", "*", $where, array('order_by' => $sortby, 'order_dir' => $order, 'limit_start' => $start, 'limit' => $perpage));
 220      while($row = $db->fetch_array($query))
 221      {
 222          $username   = htmlspecialchars_uni($row['username']);
 223          $email      = htmlspecialchars_uni($row['email']);
 224          $ip_address = my_inet_ntop($db->unescape_binary($row['ipaddress']));
 225  
 226          $dateline = '';
 227          if($row['dateline'] > 0)
 228          {
 229              $dateline = my_date('relative', $row['dateline']);
 230          }
 231  
 232          $confidence = '0%';
 233          $data       = @my_unserialize($row['data']);
 234          if(is_array($data) && !empty($data))
 235          {
 236              if(isset($data['confidence']))
 237              {
 238                  $confidence = (double)$data['confidence'].'%';
 239              }
 240          }
 241  
 242          $search_sfs = "<div class=\"float_right\"><a href=\"http://www.stopforumspam.com/ipcheck/{$ip_address}\" target=\"_blank\" rel=\"noopener\"><img src=\"styles/{$page->style}/images/icons/find.png\" title=\"{$lang->search_ip_on_sfs}\" alt=\"{$lang->search}\" /></a></div>";
 243  
 244          $table->construct_cell($username);
 245          $table->construct_cell($email);
 246          $table->construct_cell("{$search_sfs}<div>{$ip_address}</div>");
 247          $table->construct_cell($dateline);
 248          $table->construct_cell($confidence);
 249          $table->construct_row();
 250      }
 251  
 252      if($table->num_rows() == 0)
 253      {
 254          $table->construct_cell($lang->no_spam_logs, array("colspan" => "5"));
 255          $table->construct_row();
 256      }
 257  
 258      $table->output($lang->spam_logs);
 259  
 260      // Do we need to construct the pagination?
 261      if($rescount > $perpage)
 262      {
 263          echo draw_admin_pagination($pagecnt, $perpage, $rescount, "index.php?module=tools-spamlog&amp;perpage={$perpage}{$additional_criteria}&amp;sortby={$mybb->input['sortby']}&amp;order={$order}")."<br />";
 264      }
 265  
 266      // Fetch filter options
 267      $sortbysel[$mybb->input['sortby']] = "selected=\"selected\"";
 268      $ordersel[$mybb->input['order']] = "selected=\"selected\"";
 269  
 270      $sort_by = array(
 271          'dateline' => $lang->spam_date,
 272          'username' => $lang->spam_username,
 273          'email' => $lang->spam_email,
 274          'ipaddress' => $lang->spam_ip,
 275      );
 276  
 277      $order_array = array(
 278          'asc' => $lang->asc,
 279          'desc' => $lang->desc
 280      );
 281  
 282      $form = new Form("index.php?module=tools-spamlog", "post");
 283      $form_container = new FormContainer($lang->filter_spam_logs);
 284      $form_container->output_row($lang->spam_username, "", $form->generate_text_box('username', htmlspecialchars_uni($mybb->get_input('username')), array('id' => 'username')), 'suername');
 285      $form_container->output_row($lang->spam_email, "", $form->generate_text_box('email', $mybb->input['email'], array('id' => 'email')), 'email');
 286      $form_container->output_row($lang->spam_ip, "", $form->generate_text_box('ipaddress', $mybb->input['ipaddress'], array('id' => 'ipaddress')), 'ipaddress');
 287      $form_container->output_row($lang->sort_by, "", $form->generate_select_box('sortby', $sort_by, $mybb->input['sortby'], array('id' => 'sortby'))." {$lang->in} ".$form->generate_select_box('order', $order_array, $order, array('id' => 'order'))." {$lang->order}", 'order');
 288      $form_container->output_row($lang->results_per_page, "", $form->generate_numeric_field('perpage', $perpage, array('id' => 'perpage', 'min' => 1)), 'perpage');
 289  
 290      $form_container->end();
 291      $buttons[] = $form->generate_submit_button($lang->filter_spam_logs);
 292      $form->output_submit_wrapper($buttons);
 293      $form->end();
 294  
 295      $page->output_footer();
 296  }


2005 - 2019 © MyBB.de | Alle Rechte vorbehalten! | Sponsor: netcup Cross-referenced by PHPXref 0.7.1