[ Index ]

PHP Cross Reference of MyBB 1.6.7

title

Body

[close]

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

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


Generated: Sat Mar 31 17:55:03 2012 Cross-referenced by PHPXref 0.7.1