| [ Index ] |
PHP Cross Reference of MyBB 1.8.41 |
[Summary view] [Print] [Text view]
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=user-banning"); 18 19 20 $sub_tabs['ips'] = array( 21 'title' => $lang->banned_ips, 22 'link' => "index.php?module=config-banning", 23 ); 24 25 $sub_tabs['bans'] = array( 26 'title' => $lang->banned_accounts, 27 'link' => "index.php?module=user-banning", 28 'description' => $lang->banned_accounts_desc 29 ); 30 31 $sub_tabs['usernames'] = array( 32 'title' => $lang->disallowed_usernames, 33 'link' => "index.php?module=config-banning&type=usernames", 34 ); 35 36 $sub_tabs['emails'] = array( 37 'title' => $lang->disallowed_email_addresses, 38 'link' => "index.php?module=config-banning&type=emails", 39 ); 40 41 // Fetch banned groups 42 $query = $db->simple_select("usergroups", "gid,title", "isbannedgroup=1", array('order_by' => 'title')); 43 $banned_groups = array(); 44 while($group = $db->fetch_array($query)) 45 { 46 $banned_groups[$group['gid']] = $group['title']; 47 } 48 49 // Fetch ban times 50 $ban_times = fetch_ban_times(); 51 52 $plugins->run_hooks("admin_user_banning_begin"); 53 54 if($mybb->input['action'] == "prune") 55 { 56 // User clicked no 57 if($mybb->get_input('no')) 58 { 59 admin_redirect("index.php?module=user-banning"); 60 } 61 62 $query = $db->simple_select("banned", "*", "uid='{$mybb->input['uid']}'"); 63 $ban = $db->fetch_array($query); 64 65 if(!$ban) 66 { 67 flash_message($lang->error_invalid_ban, 'error'); 68 admin_redirect("index.php?module=user-banning"); 69 } 70 71 $user = get_user($ban['uid']); 72 73 if(!$user || (is_super_admin($user['uid']) && ($mybb->user['uid'] != $user['uid'] && !is_super_admin($mybb->user['uid'])))) 74 { 75 flash_message($lang->cannot_perform_action_super_admin_general, 'error'); 76 admin_redirect("index.php?module=user-banning"); 77 } 78 79 $plugins->run_hooks("admin_user_banning_prune"); 80 81 if($mybb->request_method == "post") 82 { 83 require_once MYBB_ROOT."inc/class_moderation.php"; 84 $moderation = new Moderation(); 85 86 $query = $db->simple_select("threads", "tid", "uid='{$user['uid']}'"); 87 while($thread = $db->fetch_array($query)) 88 { 89 $moderation->delete_thread($thread['tid']); 90 } 91 92 $query = $db->simple_select("posts", "pid", "uid='{$user['uid']}'"); 93 while($post = $db->fetch_array($query)) 94 { 95 $moderation->delete_post($post['pid']); 96 } 97 98 $plugins->run_hooks("admin_user_banning_prune_commit"); 99 100 $cache->update_reportedcontent(); 101 102 // Log admin action 103 log_admin_action($user['uid'], $user['username']); 104 105 flash_message($lang->success_pruned, 'success'); 106 admin_redirect("index.php?module=user-banning"); 107 } 108 else 109 { 110 $page->output_confirm_action("index.php?module=user-banning&action=prune&uid={$user['uid']}", $lang->confirm_prune); 111 } 112 } 113 114 if($mybb->input['action'] == "lift") 115 { 116 // User clicked no 117 if($mybb->get_input('no')) 118 { 119 admin_redirect("index.php?module=user-banning"); 120 } 121 122 $query = $db->simple_select("banned", "*", "uid='{$mybb->input['uid']}'"); 123 $ban = $db->fetch_array($query); 124 125 if(!$ban) 126 { 127 flash_message($lang->error_invalid_ban, 'error'); 128 admin_redirect("index.php?module=user-banning"); 129 } 130 131 $user = get_user($ban['uid']); 132 133 if(!$user || (is_super_admin($user['uid']) && ($mybb->user['uid'] != $user['uid'] && !is_super_admin($mybb->user['uid'])))) 134 { 135 flash_message($lang->cannot_perform_action_super_admin_general, 'error'); 136 admin_redirect("index.php?module=user-banning"); 137 } 138 139 $plugins->run_hooks("admin_user_banning_lift"); 140 141 if($mybb->request_method == "post") 142 { 143 $updated_group = array( 144 'usergroup' => $ban['oldgroup'], 145 'additionalgroups' => $db->escape_string($ban['oldadditionalgroups']), 146 'displaygroup' => $ban['olddisplaygroup'] 147 ); 148 $db->delete_query("banned", "uid='{$ban['uid']}'"); 149 150 $plugins->run_hooks("admin_user_banning_lift_commit"); 151 152 $db->update_query("users", $updated_group, "uid='{$ban['uid']}'"); 153 154 $cache->update_moderators(); 155 156 $cache->update_awaitingactivation(); 157 158 // Log admin action 159 log_admin_action($ban['uid'], $user['username']); 160 161 flash_message($lang->success_ban_lifted, 'success'); 162 admin_redirect("index.php?module=user-banning"); 163 } 164 else 165 { 166 $page->output_confirm_action("index.php?module=user-banning&action=lift&uid={$ban['uid']}", $lang->confirm_lift_ban); 167 } 168 } 169 170 if($mybb->input['action'] == "edit") 171 { 172 $query = $db->simple_select("banned", "*", "uid='{$mybb->input['uid']}'"); 173 $ban = $db->fetch_array($query); 174 175 if(!$ban) 176 { 177 flash_message($lang->error_invalid_ban, 'error'); 178 admin_redirect("index.php?module=user-banning"); 179 } 180 181 $user = get_user($ban['uid']); 182 183 $plugins->run_hooks("admin_user_banning_edit"); 184 185 if($mybb->request_method == "post") 186 { 187 if(empty($ban['uid'])) 188 { 189 $errors[] = $lang->error_invalid_username; 190 } 191 // Is the user we're trying to ban a super admin and we're not? 192 else if(is_super_admin($ban['uid']) && !is_super_admin($ban['uid'])) 193 { 194 $errors[] = $lang->error_no_perm_to_ban; 195 } 196 197 if($ban['uid'] == $mybb->user['uid']) 198 { 199 $errors[] = $lang->error_ban_self; 200 } 201 202 // No errors? Update 203 if(!$errors) 204 { 205 // Ban the user 206 if($mybb->input['bantime'] == '---') 207 { 208 $lifted = 0; 209 } 210 else 211 { 212 $lifted = ban_date2timestamp($mybb->input['bantime'], $ban['dateline']); 213 } 214 215 $reason = my_substr($mybb->input['reason'], 0, 255); 216 217 if(count($banned_groups) == 1) 218 { 219 $group = array_keys($banned_groups); 220 $mybb->input['usergroup'] = $group[0]; 221 } 222 if(!array_key_exists($mybb->get_input('usergroup', MyBB::INPUT_INT), $banned_groups)) 223 { 224 $errors[] = $lang->error_invalid_ban_group; 225 } 226 227 if(!$errors) 228 { 229 $update_array = array( 230 'gid' => $mybb->get_input('usergroup', MyBB::INPUT_INT), 231 'dateline' => TIME_NOW, 232 'bantime' => $db->escape_string($mybb->input['bantime']), 233 'lifted' => $db->escape_string($lifted), 234 'reason' => $db->escape_string($reason) 235 ); 236 237 $db->update_query('banned', $update_array, "uid='{$ban['uid']}'"); 238 239 // Move the user to the banned group 240 $update_array = array( 241 'usergroup' => $mybb->get_input('usergroup', MyBB::INPUT_INT), 242 'displaygroup' => 0, 243 'additionalgroups' => '', 244 ); 245 $db->update_query('users', $update_array, "uid = {$ban['uid']}"); 246 247 $plugins->run_hooks("admin_user_banning_edit_commit"); 248 249 $cache->update_awaitingactivation(); 250 251 // Log admin action 252 log_admin_action($ban['uid'], $user['username']); 253 254 flash_message($lang->success_ban_updated, 'success'); 255 admin_redirect("index.php?module=user-banning"); 256 } 257 } 258 } 259 $page->add_breadcrumb_item($lang->edit_ban); 260 $page->output_header($lang->edit_ban); 261 262 $sub_tabs = array(); 263 $sub_tabs['edit'] = array( 264 'title' => $lang->edit_ban, 265 'description' => $lang->edit_ban_desc 266 ); 267 $page->output_nav_tabs($sub_tabs, "edit"); 268 269 $form = new Form("index.php?module=user-banning&action=edit&uid={$ban['uid']}", "post"); 270 if($errors) 271 { 272 $page->output_inline_error($errors); 273 } 274 else 275 { 276 $mybb->input = array_merge($mybb->input, $ban); 277 } 278 279 if(!empty($ban['gid'])) 280 { 281 $mybb->input['usergroup'] = $ban['gid']; 282 } 283 else if(!empty($user['usergroup'])) 284 { 285 $mybb->input['usergroup'] = $user['usergroup']; 286 } 287 else 288 { 289 $mybb->input['usergroup'] = 0; 290 } 291 292 $form_container = new FormContainer($lang->edit_ban); 293 $form_container->output_row($lang->ban_username, "", htmlspecialchars_uni($user['username'])); 294 $form_container->output_row($lang->ban_reason, "", $form->generate_text_area('reason', $mybb->input['reason'], array('id' => 'reason', 'maxlength' => '255')), 'reason'); 295 if(count($banned_groups) > 1) 296 { 297 $form_container->output_row($lang->ban_group, $lang->ban_group_desc, $form->generate_select_box('usergroup', $banned_groups, $mybb->input['usergroup'], array('id' => 'usergroup')), 'usergroup'); 298 } 299 300 if($mybb->input['bantime'] == 'perm' || $mybb->input['bantime'] == '' || $mybb->input['lifted'] == 'perm' ||$mybb->input['lifted'] == '') 301 { 302 $mybb->input['bantime'] = '---'; 303 $mybb->input['lifted'] = '---'; 304 } 305 306 foreach($ban_times as $time => $period) 307 { 308 if($time != '---') 309 { 310 $friendly_time = my_date("D, jS M Y @ {$mybb->settings['timeformat']}", ban_date2timestamp($time)); 311 $period = "{$period} ({$friendly_time})"; 312 } 313 $length_list[$time] = $period; 314 } 315 $form_container->output_row($lang->ban_time, "", $form->generate_select_box('bantime', $length_list, $mybb->input['bantime'], array('id' => 'bantime')), 'bantime'); 316 317 $form_container->end(); 318 319 $buttons[] = $form->generate_submit_button($lang->update_ban); 320 $form->output_submit_wrapper($buttons); 321 $form->end(); 322 323 $page->output_footer(); 324 } 325 326 if(!$mybb->input['action']) 327 { 328 $where_sql_full = $where_sql = ''; 329 330 $plugins->run_hooks("admin_user_banning_start"); 331 332 if($mybb->request_method == "post") 333 { 334 $options = array( 335 'fields' => array('username', 'usergroup', 'additionalgroups', 'displaygroup') 336 ); 337 338 $user = get_user_by_username($mybb->input['username'], $options); 339 340 // Are we searching a user? 341 if(is_array($user) && isset($mybb->input['search'])) 342 { 343 $where_sql = 'uid=\''.(int)$user['uid'].'\''; 344 $where_sql_full = 'WHERE b.uid=\''.(int)$user['uid'].'\''; 345 } 346 else 347 { 348 if(!$user) 349 { 350 $errors[] = $lang->error_invalid_username; 351 } 352 // Is the user we're trying to ban a super admin and we're not? 353 else if(is_super_admin($user['uid']) && !is_super_admin($mybb->user['uid'])) 354 { 355 $errors[] = $lang->error_no_perm_to_ban; 356 } 357 else 358 { 359 $query = $db->simple_select("banned", "uid", "uid='{$user['uid']}'"); 360 if($db->fetch_field($query, "uid")) 361 { 362 $errors[] = $lang->error_already_banned; 363 } 364 365 // Get PRIMARY usergroup information 366 $usergroups = $cache->read("usergroups"); 367 if(!empty($usergroups[$user['usergroup']]) && $usergroups[$user['usergroup']]['isbannedgroup'] == 1) 368 { 369 $errors[] = $lang->error_already_banned; 370 } 371 372 if($user['uid'] == $mybb->user['uid']) 373 { 374 $errors[] = $lang->error_ban_self; 375 } 376 } 377 378 // No errors? Insert 379 if(!$errors) 380 { 381 // Ban the user 382 if($mybb->input['bantime'] == '---') 383 { 384 $lifted = 0; 385 } 386 else 387 { 388 $lifted = ban_date2timestamp($mybb->input['bantime']); 389 } 390 391 $reason = my_substr($mybb->input['reason'], 0, 255); 392 393 if(count($banned_groups) == 1) 394 { 395 $group = array_keys($banned_groups); 396 $mybb->input['usergroup'] = $group[0]; 397 } 398 if(!array_key_exists($mybb->get_input('usergroup', MyBB::INPUT_INT), $banned_groups)) 399 { 400 $errors[] = $lang->error_invalid_ban_group; 401 } 402 403 if(!$errors) 404 { 405 $insert_array = array( 406 'uid' => $user['uid'], 407 'gid' => $mybb->get_input('usergroup', MyBB::INPUT_INT), 408 'oldgroup' => $user['usergroup'], 409 'oldadditionalgroups' => $db->escape_string($user['additionalgroups']), 410 'olddisplaygroup' => $user['displaygroup'], 411 'admin' => (int)$mybb->user['uid'], 412 'dateline' => TIME_NOW, 413 'bantime' => $db->escape_string($mybb->input['bantime']), 414 'lifted' => $db->escape_string($lifted), 415 'reason' => $db->escape_string($reason) 416 ); 417 $db->insert_query('banned', $insert_array); 418 419 // Move the user to the banned group 420 $update_array = array( 421 'usergroup' => $mybb->get_input('usergroup', MyBB::INPUT_INT), 422 'displaygroup' => 0, 423 'additionalgroups' => '', 424 ); 425 426 $db->delete_query("forumsubscriptions", "uid = '{$user['uid']}'"); 427 $db->delete_query("threadsubscriptions", "uid = '{$user['uid']}'"); 428 429 $plugins->run_hooks("admin_user_banning_start_commit"); 430 431 $db->update_query('users', $update_array, "uid = '{$user['uid']}'"); 432 433 // Log admin action 434 log_admin_action($user['uid'], $user['username'], $lifted); 435 436 flash_message($lang->success_banned, 'success'); 437 admin_redirect("index.php?module=user-banning"); 438 } 439 } 440 } 441 } 442 443 $page->output_header($lang->banned_accounts); 444 445 $page->output_nav_tabs($sub_tabs, "bans"); 446 447 $query = $db->simple_select("banned", "COUNT(*) AS ban_count", $where_sql); 448 $ban_count = $db->fetch_field($query, "ban_count"); 449 450 $per_page = 20; 451 452 $mybb->input['page'] = $mybb->get_input('page', MyBB::INPUT_INT); 453 if($mybb->input['page'] > 0) 454 { 455 $current_page = $mybb->input['page']; 456 $start = ($current_page-1)*$per_page; 457 $pages = $ban_count / $per_page; 458 $pages = ceil($pages); 459 if($current_page > $pages) 460 { 461 $start = 0; 462 $current_page = 1; 463 } 464 } 465 else 466 { 467 $start = 0; 468 $current_page = 1; 469 } 470 471 $pagination = draw_admin_pagination($current_page, $per_page, $ban_count, "index.php?module=user-banning&page={page}"); 472 473 $form = new Form("index.php?module=user-banning", "post"); 474 if($errors) 475 { 476 $page->output_inline_error($errors); 477 } 478 479 $mybb->input['username'] = $mybb->get_input('username'); 480 $mybb->input['reason'] = $mybb->get_input('reason'); 481 $mybb->input['bantime'] = $mybb->get_input('bantime'); 482 483 if(isset($mybb->input['uid']) && empty($mybb->input['username'])) 484 { 485 $user = get_user($mybb->input['uid']); 486 $mybb->input['username'] = $user['username']; 487 } 488 489 if(empty($mybb->input['usergroup'])) 490 { 491 if(!empty($mybb->settings['purgespammerbangroup'])) 492 { 493 $mybb->input['usergroup'] = $mybb->settings['purgespammerbangroup']; 494 } 495 else if(count($banned_groups)) 496 { 497 $group = array_keys($banned_groups); 498 $mybb->input['usergroup'] = $group[0]; 499 } 500 else 501 { 502 $mybb->input['usergroup'] = 0; 503 } 504 } 505 506 $form_container = new FormContainer($lang->ban_a_user); 507 $form_container->output_row($lang->ban_username, $lang->autocomplete_enabled, $form->generate_text_box('username', $mybb->input['username'], array('id' => 'username')), 'username'); 508 $form_container->output_row($lang->ban_reason, "", $form->generate_text_area('reason', $mybb->input['reason'], array('id' => 'reason', 'maxlength' => '255')), 'reason'); 509 if(count($banned_groups) > 1) 510 { 511 $form_container->output_row($lang->ban_group, $lang->ban_group_desc, $form->generate_select_box('usergroup', $banned_groups, $mybb->input['usergroup'], array('id' => 'usergroup')), 'usergroup'); 512 } 513 foreach($ban_times as $time => $period) 514 { 515 if($time != "---") 516 { 517 $friendly_time = my_date("D, jS M Y @ {$mybb->settings['timeformat']}", ban_date2timestamp($time)); 518 $period = "{$period} ({$friendly_time})"; 519 } 520 $length_list[$time] = $period; 521 } 522 $form_container->output_row($lang->ban_time, "", $form->generate_select_box('bantime', $length_list, $mybb->input['bantime'], array('id' => 'bantime')), 'bantime'); 523 524 $form_container->end(); 525 526 // Autocompletion for usernames 527 echo ' 528 <link rel="stylesheet" href="../jscripts/select2/select2.css"> 529 <script type="text/javascript" src="../jscripts/select2/select2.min.js?ver=1804"></script> 530 <script type="text/javascript"> 531 <!-- 532 $("#username").select2({ 533 placeholder: "'.$lang->search_for_a_user.'", 534 minimumInputLength: 2, 535 multiple: false, 536 ajax: { // instead of writing the function to execute the request we use Select2\'s convenient helper 537 url: "../xmlhttp.php?action=get_users", 538 dataType: \'json\', 539 data: function (term, page) { 540 return { 541 query: term, // search term 542 }; 543 }, 544 results: function (data, page) { // parse the results into the format expected by Select2. 545 // since we are using custom formatting functions we do not need to alter remote JSON data 546 return {results: data}; 547 } 548 }, 549 initSelection: function(element, callback) { 550 var query = $(element).val(); 551 if (query !== "") { 552 $.ajax("../xmlhttp.php?action=get_users&getone=1", { 553 data: { 554 query: query 555 }, 556 dataType: "json" 557 }).done(function(data) { callback(data); }); 558 } 559 }, 560 }); 561 562 $(\'[for=username]\').on(\'click\', function(){ 563 $("#username").select2(\'open\'); 564 return false; 565 }); 566 // --> 567 </script>'; 568 569 $buttons[] = $form->generate_submit_button($lang->ban_user); 570 $buttons[] = $form->generate_submit_button($lang->search_for_a_user, array('name' => 'search')); 571 $form->output_submit_wrapper($buttons); 572 $form->end(); 573 574 echo '<br />'; 575 576 $table = new Table; 577 $table->construct_header($lang->user); 578 $table->construct_header($lang->ban_lifts_on, array("class" => "align_center", "width" => 150)); 579 $table->construct_header($lang->time_left, array("class" => "align_center", "width" => 150)); 580 $table->construct_header($lang->controls, array("class" => "align_center", "colspan" => 2, "width" => 200)); 581 $table->construct_header($lang->moderation, array("class" => "align_center", "colspan" => 1, "width" => 200)); 582 583 // Fetch bans 584 $query = $db->query(" 585 SELECT b.*, a.username AS adminuser, u.username 586 FROM ".TABLE_PREFIX."banned b 587 LEFT JOIN ".TABLE_PREFIX."users u ON (b.uid=u.uid) 588 LEFT JOIN ".TABLE_PREFIX."users a ON (b.admin=a.uid) 589 {$where_sql_full} 590 ORDER BY dateline DESC 591 LIMIT {$start}, {$per_page} 592 "); 593 594 // Get the banned users 595 while($ban = $db->fetch_array($query)) 596 { 597 $profile_link = build_profile_link(htmlspecialchars_uni($ban['username']), $ban['uid'], "_blank"); 598 $ban_date = my_date($mybb->settings['dateformat'], $ban['dateline']); 599 if($ban['lifted'] == 'perm' || $ban['lifted'] == '' || $ban['bantime'] == 'perm' || $ban['bantime'] == '---') 600 { 601 $ban_period = $lang->permenantly; 602 $time_remaining = $lifts_on = $lang->na; 603 } 604 else 605 { 606 $ban_period = $lang->for." ".$ban_times[$ban['bantime']]; 607 608 $remaining = $ban['lifted']-TIME_NOW; 609 $time_remaining = nice_time($remaining, array('short' => 1, 'seconds' => false)).""; 610 611 if($remaining < 3600) 612 { 613 $time_remaining = "<span style=\"color: red;\">{$time_remaining}</span>"; 614 } 615 else if($remaining < 86400) 616 { 617 $time_remaining = "<span style=\"color: maroon;\">{$time_remaining}</span>"; 618 } 619 else if($remaining < 604800) 620 { 621 $time_remaining = "<span style=\"color: green;\">{$time_remaining}</span>"; 622 } 623 624 $lifts_on = my_date($mybb->settings['dateformat'], $ban['lifted']); 625 } 626 627 if(!$ban['adminuser']) 628 { 629 if($ban['admin'] == 0) 630 { 631 $ban['adminuser'] = $lang->mybb_engine; 632 } 633 else 634 { 635 $ban['adminuser'] = $ban['admin']; 636 } 637 } 638 639 $table->construct_cell($lang->sprintf($lang->bannedby_x_on_x, $profile_link, htmlspecialchars_uni($ban['adminuser']), $ban_date, $ban_period)); 640 $table->construct_cell($lifts_on, array("class" => "align_center")); 641 $table->construct_cell($time_remaining, array("class" => "align_center")); 642 $table->construct_cell("<a href=\"index.php?module=user-banning&action=edit&uid={$ban['uid']}\">{$lang->edit}</a>", array("class" => "align_center")); 643 $table->construct_cell("<a href=\"index.php?module=user-banning&action=lift&uid={$ban['uid']}&my_post_key={$mybb->post_code}\" onclick=\"return AdminCP.deleteConfirmation(this, '{$lang->confirm_lift_ban}');\">{$lang->lift}</a>", array("class" => "align_center")); 644 $table->construct_cell("<a href=\"index.php?module=user-banning&action=prune&uid={$ban['uid']}&my_post_key={$mybb->post_code}\" onclick=\"return AdminCP.deleteConfirmation(this, '{$lang->confirm_prune}');\">{$lang->prune_threads_and_posts}</a>", array("class" => "align_center")); 645 $table->construct_row(); 646 } 647 648 if($table->num_rows() == 0) 649 { 650 $table->construct_cell($lang->no_banned_users, array("colspan" => "6")); 651 $table->construct_row(); 652 } 653 $table->output($lang->banned_accounts); 654 echo $pagination; 655 656 $page->output_footer(); 657 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| 2005 - 2021 © MyBB.de | Alle Rechte vorbehalten! | Sponsor: netcup | Cross-referenced by PHPXref |