[ Index ]

PHP Cross Reference of MyBB 1.8.40

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 && $mybb->input['type'] == 1)
  39      {
  40          $ip_address = $db->escape_string($mybb->input['filter']);
  41          $subnet_mask = "0";
  42          if(strpos($ip_address, "*") !== false)
  43          {
  44              $ip_address = str_replace("*", "0", $ip_address);
  45          }
  46          else if(strpos($ip_address, "/") !== false)
  47          {
  48              list($ip_address, $subnet_mask) = explode("/", $ip_address);
  49          }
  50  
  51          $is_valid_v4 = filter_var($ip_address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) && $subnet_mask <= 32 && $subnet_mask >= 0;
  52          $is_valid_v6 = filter_var($ip_address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) && $subnet_mask <= 128 && $subnet_mask >= 0;
  53  
  54          if (!$is_valid_v4 && !$is_valid_v6 || !ctype_digit($subnet_mask))
  55          {
  56              $errors[] = $lang->error_invalid_filter;
  57          }
  58      }
  59  
  60      if(!$errors)
  61      {
  62          $new_filter = array(
  63              "filter" => $db->escape_string($mybb->input['filter']),
  64              "type" => $mybb->get_input('type', MyBB::INPUT_INT),
  65              "dateline" => TIME_NOW
  66          );
  67          $fid = $db->insert_query("banfilters", $new_filter);
  68  
  69          $plugins->run_hooks("admin_config_banning_add_commit");
  70  
  71          if($mybb->input['type'] == 1)
  72          {
  73              $cache->update_bannedips();
  74          }
  75          else if($mybb->input['type'] == 3)
  76          {
  77              $cache->update_bannedemails();
  78          }
  79  
  80          // Log admin action
  81          log_admin_action($fid, $mybb->input['filter'], (int)$mybb->input['type']);
  82  
  83          if($mybb->input['type'] == 1)
  84          {
  85              flash_message($lang->success_ip_banned, 'success');
  86              admin_redirect("index.php?module=config-banning");
  87          }
  88          else if($mybb->input['type'] == 2)
  89          {
  90              flash_message($lang->success_username_disallowed, 'success');
  91              admin_redirect("index.php?module=config-banning&type=usernames");
  92          }
  93          else if($mybb->input['type'] == 3)
  94          {
  95              flash_message($lang->success_email_disallowed, 'success');
  96              admin_redirect("index.php?module=config-banning&type=emails");
  97          }
  98      }
  99      else
 100      {
 101          if($mybb->input['type'] == 1)
 102          {
 103              $mybb->input['type'] = "ips";
 104          }
 105          else if($mybb->input['type'] == 2)
 106          {
 107              $mybb->input['type'] = "usernames";
 108          }
 109          else if($mybb->input['type'] == 3)
 110          {
 111              $mybb->input['type'] = "emails";
 112          }
 113          $mybb->input['action'] = '';
 114      }
 115  }
 116  
 117  if($mybb->input['action'] == "delete")
 118  {
 119      $query = $db->simple_select("banfilters", "*", "fid='".$mybb->get_input('fid', MyBB::INPUT_INT)."'");
 120      $filter = $db->fetch_array($query);
 121  
 122      // Does the filter not exist?
 123      if(!$filter)
 124      {
 125          flash_message($lang->error_filter_not_found, 'error');
 126          admin_redirect("index.php?module=config-banning");
 127      }
 128  
 129      $plugins->run_hooks("admin_config_banning_delete");
 130  
 131      if($filter['type'] == 3)
 132      {
 133          $type = "emails";
 134      }
 135      else if($filter['type'] == 2)
 136      {
 137          $type = "usernames";
 138      }
 139      else
 140      {
 141          $type = "ips";
 142      }
 143  
 144      // User clicked no
 145      if($mybb->get_input('no'))
 146      {
 147          admin_redirect("index.php?module=config-banning&type={$type}");
 148      }
 149  
 150      if($mybb->request_method == "post")
 151      {
 152          // Delete the ban filter
 153          $db->delete_query("banfilters", "fid='{$filter['fid']}'");
 154  
 155          $plugins->run_hooks("admin_config_banning_delete_commit");
 156  
 157          // Log admin action
 158          log_admin_action($filter['fid'], $filter['filter'], (int)$filter['type']);
 159  
 160          // Banned IP? Rebuild banned IP cache
 161          if($filter['type'] == 1)
 162          {
 163              $cache->update_bannedips();
 164          }
 165          else if($filter['type'] == 3)
 166          {
 167              $cache->update_bannedemails();
 168          }
 169  
 170          flash_message($lang->success_ban_deleted, 'success');
 171          admin_redirect("index.php?module=config-banning&type={$type}");
 172      }
 173      else
 174      {
 175          $page->output_confirm_action("index.php?module=config-banning&amp;action=delete&amp;fid={$filter['fid']}", $lang->confirm_ban_deletion);
 176      }
 177  }
 178  
 179  if(!$mybb->input['action'])
 180  {
 181      $plugins->run_hooks("admin_config_banning_start");
 182  
 183      switch($mybb->get_input('type'))
 184      {
 185          case "emails":
 186              $type = "3";
 187              $title = $lang->disallowed_email_addresses;
 188              break;
 189          case "usernames":
 190              $type = "2";
 191              $title = $lang->disallowed_usernames;
 192              break;
 193          default:
 194              $type = "1";
 195              $title = $lang->banned_ip_addresses;
 196              $mybb->input['type'] = "ips";
 197      }
 198  
 199      $page->output_header($title);
 200  
 201      $sub_tabs['ips'] = array(
 202          'title' => $lang->banned_ips,
 203          'link' => "index.php?module=config-banning",
 204          'description' => $lang->banned_ips_desc
 205      );
 206  
 207      $sub_tabs['users'] = array(
 208          'title' => $lang->banned_accounts,
 209          'link' => "index.php?module=user-banning"
 210      );
 211  
 212      $sub_tabs['usernames'] = array(
 213          'title' => $lang->disallowed_usernames,
 214          'link' => "index.php?module=config-banning&amp;type=usernames",
 215          'description' => $lang->disallowed_usernames_desc
 216      );
 217  
 218      $sub_tabs['emails'] = array(
 219          'title' => $lang->disallowed_email_addresses,
 220          'link' => "index.php?module=config-banning&amp;type=emails",
 221          'description' => $lang->disallowed_email_addresses_desc
 222      );
 223  
 224      $page->output_nav_tabs($sub_tabs, $mybb->input['type']);
 225  
 226      if($errors)
 227      {
 228          $page->output_inline_error($errors);
 229      }
 230  
 231      $query = $db->simple_select("banfilters", "COUNT(fid) AS filter", "type='{$type}'");
 232      $total_rows = $db->fetch_field($query, "filter");
 233  
 234      $pagenum = $mybb->get_input('page', MyBB::INPUT_INT);
 235      if($pagenum)
 236      {
 237          $start = ($pagenum - 1) * 20;
 238          $pages = ceil($total_rows / 20);
 239          if($pagenum > $pages)
 240          {
 241              $start = 0;
 242              $pagenum = 1;
 243          }
 244      }
 245      else
 246      {
 247          $start = 0;
 248          $pagenum = 1;
 249      }
 250  
 251      $form = new Form("index.php?module=config-banning&amp;action=add", "post", "add");
 252  
 253      if($mybb->input['type'] == "usernames")
 254      {
 255          $form_container = new FormContainer($lang->add_disallowed_username);
 256          $form_container->output_row($lang->username." <em>*</em>", $lang->username_desc, $form->generate_text_box('filter', $mybb->input['filter'], array('id' => 'filter')), 'filter');
 257          $buttons[] = $form->generate_submit_button($lang->disallow_username);
 258      }
 259      else if($mybb->input['type'] == "emails")
 260      {
 261          $form_container = new FormContainer($lang->add_disallowed_email_address);
 262          $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');
 263          $buttons[] = $form->generate_submit_button($lang->disallow_email_address);
 264      }
 265      else
 266      {
 267          $form_container = new FormContainer($lang->ban_an_ip_address);
 268          $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');
 269          $buttons[] = $form->generate_submit_button($lang->ban_ip_address);
 270      }
 271  
 272      $form_container->end();
 273      echo $form->generate_hidden_field("type", $type);
 274      $form->output_submit_wrapper($buttons);
 275      $form->end();
 276  
 277      echo '<br />';
 278  
 279      $table = new Table;
 280      if($mybb->input['type'] == "usernames")
 281      {
 282          $table->construct_header($lang->username);
 283          $table->construct_header($lang->date_disallowed, array("class" => "align_center", "width" => 200));
 284          $table->construct_header($lang->last_attempted_use, array("class" => "align_center", "width" => 200));
 285      }
 286      else if($mybb->input['type'] == "emails")
 287      {
 288          $table->construct_header($lang->email_address);
 289          $table->construct_header($lang->date_disallowed, array("class" => "align_center", "width" => 200));
 290          $table->construct_header($lang->last_attempted_use, array("class" => "align_center", "width" => 200));
 291      }
 292      else
 293      {
 294          $table->construct_header($lang->ip_address);
 295          $table->construct_header($lang->ban_date, array("class" => "align_center", "width" => 200));
 296          $table->construct_header($lang->last_access, array("class" => "align_center", "width" => 200));
 297      }
 298      $table->construct_header($lang->controls, array("width" => 1));
 299  
 300      $query = $db->simple_select("banfilters", "*", "type='{$type}'", array('limit_start' => $start, 'limit' => 20, "order_by" => "filter", "order_dir" => "asc"));
 301      while($filter = $db->fetch_array($query))
 302      {
 303          $filter['filter'] = htmlspecialchars_uni($filter['filter']);
 304  
 305          if($filter['lastuse'] > 0)
 306          {
 307              $last_use = my_date('relative', $filter['lastuse']);
 308          }
 309          else
 310          {
 311              $last_use = $lang->never;
 312          }
 313  
 314          if($filter['dateline'] > 0)
 315          {
 316              $date = my_date('relative', $filter['dateline']);
 317          }
 318          else
 319          {
 320              $date = $lang->na;
 321          }
 322  
 323          $table->construct_cell($filter['filter']);
 324          $table->construct_cell($date, array("class" => "align_center"));
 325          $table->construct_cell($last_use, array("class" => "align_center"));
 326          $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"));
 327          $table->construct_row();
 328      }
 329  
 330      if($table->num_rows() == 0)
 331      {
 332          $table->construct_cell($lang->no_bans, array("colspan" => 4));
 333          $table->construct_row();
 334      }
 335  
 336      $table->output($title);
 337  
 338      echo "<br />".draw_admin_pagination($pagenum, "20", $total_rows, "index.php?module=config-banning&amp;type={$mybb->get_input('type')}&amp;page={page}");
 339  
 340      $page->output_footer();
 341  }
 342  


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