[ Index ]

PHP Cross Reference of MyBB 1.8.38

title

Body

[close]

/admin/modules/config/ -> banning.php (source)

   1  <?php
   2  /**
   3   * MyBB 1.8
   4   * Copyright 2014 MyBB Group, All Rights Reserved
   5   *
   6   * Website: http://www.mybb.com
   7   * License: http://www.mybb.com/about/license
   8   *
   9   */
  10  
  11  // Disallow direct access to this file for security reasons
  12  if(!defined("IN_MYBB"))
  13  {
  14      die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
  15  }
  16  
  17  $page->add_breadcrumb_item($lang->banning, "index.php?module=config-banning");
  18  
  19  $plugins->run_hooks("admin_config_banning_begin");
  20  
  21  $mybb->input['filter'] = $mybb->get_input('filter');
  22  
  23  if($mybb->input['action'] == "add" && $mybb->request_method == "post")
  24  {
  25      $plugins->run_hooks("admin_config_banning_add");
  26  
  27      if(!trim($mybb->input['filter']))
  28      {
  29          $errors[] = $lang->error_missing_ban_input;
  30      }
  31  
  32      $query = $db->simple_select("banfilters", "fid", "filter = '".$db->escape_string($mybb->input['filter'])."' AND type = '".$mybb->get_input('type', MyBB::INPUT_INT)."'");
  33      if($db->num_rows($query))
  34      {
  35          $errors[] = $lang->error_filter_already_banned;
  36      }
  37  
  38      if(!$errors)
  39      {
  40          $new_filter = array(
  41              "filter" => $db->escape_string($mybb->input['filter']),
  42              "type" => $mybb->get_input('type', MyBB::INPUT_INT),
  43              "dateline" => TIME_NOW
  44          );
  45          $fid = $db->insert_query("banfilters", $new_filter);
  46  
  47          $plugins->run_hooks("admin_config_banning_add_commit");
  48  
  49          if($mybb->input['type'] == 1)
  50          {
  51              $cache->update_bannedips();
  52          }
  53          else if($mybb->input['type'] == 3)
  54          {
  55              $cache->update_bannedemails();
  56          }
  57  
  58          // Log admin action
  59          log_admin_action($fid, $mybb->input['filter'], (int)$mybb->input['type']);
  60  
  61          if($mybb->input['type'] == 1)
  62          {
  63              flash_message($lang->success_ip_banned, 'success');
  64              admin_redirect("index.php?module=config-banning");
  65          }
  66          else if($mybb->input['type'] == 2)
  67          {
  68              flash_message($lang->success_username_disallowed, 'success');
  69              admin_redirect("index.php?module=config-banning&type=usernames");
  70          }
  71          else if($mybb->input['type'] == 3)
  72          {
  73              flash_message($lang->success_email_disallowed, 'success');
  74              admin_redirect("index.php?module=config-banning&type=emails");
  75          }
  76      }
  77      else
  78      {
  79          if($mybb->input['type'] == 1)
  80          {
  81              $mybb->input['type'] = "ips";
  82          }
  83          else if($mybb->input['type'] == 2)
  84          {
  85              $mybb->input['type'] = "usernames";
  86          }
  87          else if($mybb->input['type'] == 3)
  88          {
  89              $mybb->input['type'] = "emails";
  90          }
  91          $mybb->input['action'] = '';
  92      }
  93  }
  94  
  95  if($mybb->input['action'] == "delete")
  96  {
  97      $query = $db->simple_select("banfilters", "*", "fid='".$mybb->get_input('fid', MyBB::INPUT_INT)."'");
  98      $filter = $db->fetch_array($query);
  99  
 100      // Does the filter not exist?
 101      if(!$filter)
 102      {
 103          flash_message($lang->error_invalid_filter, 'error');
 104          admin_redirect("index.php?module=config-banning");
 105      }
 106  
 107      $plugins->run_hooks("admin_config_banning_delete");
 108  
 109      if($filter['type'] == 3)
 110      {
 111          $type = "emails";
 112      }
 113      else if($filter['type'] == 2)
 114      {
 115          $type = "usernames";
 116      }
 117      else
 118      {
 119          $type = "ips";
 120      }
 121  
 122      // User clicked no
 123      if($mybb->get_input('no'))
 124      {
 125          admin_redirect("index.php?module=config-banning&type={$type}");
 126      }
 127  
 128      if($mybb->request_method == "post")
 129      {
 130          // Delete the ban filter
 131          $db->delete_query("banfilters", "fid='{$filter['fid']}'");
 132  
 133          $plugins->run_hooks("admin_config_banning_delete_commit");
 134  
 135          // Log admin action
 136          log_admin_action($filter['fid'], $filter['filter'], (int)$filter['type']);
 137  
 138          // Banned IP? Rebuild banned IP cache
 139          if($filter['type'] == 1)
 140          {
 141              $cache->update_bannedips();
 142          }
 143          else if($filter['type'] == 3)
 144          {
 145              $cache->update_bannedemails();
 146          }
 147  
 148          flash_message($lang->success_ban_deleted, 'success');
 149          admin_redirect("index.php?module=config-banning&type={$type}");
 150      }
 151      else
 152      {
 153          $page->output_confirm_action("index.php?module=config-banning&amp;action=delete&amp;fid={$filter['fid']}", $lang->confirm_ban_deletion);
 154      }
 155  }
 156  
 157  if(!$mybb->input['action'])
 158  {
 159      $plugins->run_hooks("admin_config_banning_start");
 160  
 161      switch($mybb->get_input('type'))
 162      {
 163          case "emails":
 164              $type = "3";
 165              $title = $lang->disallowed_email_addresses;
 166              break;
 167          case "usernames":
 168              $type = "2";
 169              $title = $lang->disallowed_usernames;
 170              break;
 171          default:
 172              $type = "1";
 173              $title = $lang->banned_ip_addresses;
 174              $mybb->input['type'] = "ips";
 175      }
 176  
 177      $page->output_header($title);
 178  
 179      $sub_tabs['ips'] = array(
 180          'title' => $lang->banned_ips,
 181          'link' => "index.php?module=config-banning",
 182          'description' => $lang->banned_ips_desc
 183      );
 184  
 185      $sub_tabs['users'] = array(
 186          'title' => $lang->banned_accounts,
 187          'link' => "index.php?module=user-banning"
 188      );
 189  
 190      $sub_tabs['usernames'] = array(
 191          'title' => $lang->disallowed_usernames,
 192          'link' => "index.php?module=config-banning&amp;type=usernames",
 193          'description' => $lang->disallowed_usernames_desc
 194      );
 195  
 196      $sub_tabs['emails'] = array(
 197          'title' => $lang->disallowed_email_addresses,
 198          'link' => "index.php?module=config-banning&amp;type=emails",
 199          'description' => $lang->disallowed_email_addresses_desc
 200      );
 201  
 202      $page->output_nav_tabs($sub_tabs, $mybb->input['type']);
 203  
 204      if($errors)
 205      {
 206          $page->output_inline_error($errors);
 207      }
 208  
 209      $query = $db->simple_select("banfilters", "COUNT(fid) AS filter", "type='{$type}'");
 210      $total_rows = $db->fetch_field($query, "filter");
 211  
 212      $pagenum = $mybb->get_input('page', MyBB::INPUT_INT);
 213      if($pagenum)
 214      {
 215          $start = ($pagenum - 1) * 20;
 216          $pages = ceil($total_rows / 20);
 217          if($pagenum > $pages)
 218          {
 219              $start = 0;
 220              $pagenum = 1;
 221          }
 222      }
 223      else
 224      {
 225          $start = 0;
 226          $pagenum = 1;
 227      }
 228  
 229      $form = new Form("index.php?module=config-banning&amp;action=add", "post", "add");
 230  
 231      if($mybb->input['type'] == "usernames")
 232      {
 233          $form_container = new FormContainer($lang->add_disallowed_username);
 234          $form_container->output_row($lang->username." <em>*</em>", $lang->username_desc, $form->generate_text_box('filter', $mybb->input['filter'], array('id' => 'filter')), 'filter');
 235          $buttons[] = $form->generate_submit_button($lang->disallow_username);
 236      }
 237      else if($mybb->input['type'] == "emails")
 238      {
 239          $form_container = new FormContainer($lang->add_disallowed_email_address);
 240          $form_container->output_row($lang->email_address." <em>*</em>", $lang->email_address_desc, $form->generate_text_box('filter', $mybb->input['filter'], array('id' => 'filter')), 'filter');
 241          $buttons[] = $form->generate_submit_button($lang->disallow_email_address);
 242      }
 243      else
 244      {
 245          $form_container = new FormContainer($lang->ban_an_ip_address);
 246          $form_container->output_row($lang->ip_address." <em>*</em>", $lang->ip_address_desc, $form->generate_text_box('filter', $mybb->input['filter'], array('id' => 'filter')), 'filter');
 247          $buttons[] = $form->generate_submit_button($lang->ban_ip_address);
 248      }
 249  
 250      $form_container->end();
 251      echo $form->generate_hidden_field("type", $type);
 252      $form->output_submit_wrapper($buttons);
 253      $form->end();
 254  
 255      echo '<br />';
 256  
 257      $table = new Table;
 258      if($mybb->input['type'] == "usernames")
 259      {
 260          $table->construct_header($lang->username);
 261          $table->construct_header($lang->date_disallowed, array("class" => "align_center", "width" => 200));
 262          $table->construct_header($lang->last_attempted_use, array("class" => "align_center", "width" => 200));
 263      }
 264      else if($mybb->input['type'] == "emails")
 265      {
 266          $table->construct_header($lang->email_address);
 267          $table->construct_header($lang->date_disallowed, array("class" => "align_center", "width" => 200));
 268          $table->construct_header($lang->last_attempted_use, array("class" => "align_center", "width" => 200));
 269      }
 270      else
 271      {
 272          $table->construct_header($lang->ip_address);
 273          $table->construct_header($lang->ban_date, array("class" => "align_center", "width" => 200));
 274          $table->construct_header($lang->last_access, array("class" => "align_center", "width" => 200));
 275      }
 276      $table->construct_header($lang->controls, array("width" => 1));
 277  
 278      $query = $db->simple_select("banfilters", "*", "type='{$type}'", array('limit_start' => $start, 'limit' => 20, "order_by" => "filter", "order_dir" => "asc"));
 279      while($filter = $db->fetch_array($query))
 280      {
 281          $filter['filter'] = htmlspecialchars_uni($filter['filter']);
 282  
 283          if($filter['lastuse'] > 0)
 284          {
 285              $last_use = my_date('relative', $filter['lastuse']);
 286          }
 287          else
 288          {
 289              $last_use = $lang->never;
 290          }
 291  
 292          if($filter['dateline'] > 0)
 293          {
 294              $date = my_date('relative', $filter['dateline']);
 295          }
 296          else
 297          {
 298              $date = $lang->na;
 299          }
 300  
 301          $table->construct_cell($filter['filter']);
 302          $table->construct_cell($date, array("class" => "align_center"));
 303          $table->construct_cell($last_use, array("class" => "align_center"));
 304          $table->construct_cell("<a href=\"index.php?module=config-banning&amp;action=delete&amp;fid={$filter['fid']}&amp;my_post_key={$mybb->post_code}\" onclick=\"return AdminCP.deleteConfirmation(this, '{$lang->confirm_ban_deletion}');\"><img src=\"styles/{$page->style}/images/icons/delete.png\" title=\"{$lang->delete}\" alt=\"{$lang->delete}\" /></a>", array("class" => "align_center"));
 305          $table->construct_row();
 306      }
 307  
 308      if($table->num_rows() == 0)
 309      {
 310          $table->construct_cell($lang->no_bans, array("colspan" => 4));
 311          $table->construct_row();
 312      }
 313  
 314      $table->output($title);
 315  
 316      echo "<br />".draw_admin_pagination($pagenum, "20", $total_rows, "index.php?module=config-banning&amp;type={$mybb->get_input('type')}&amp;page={page}");
 317  
 318      $page->output_footer();
 319  }
 320  


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