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