[ Index ] |
PHP Cross Reference of MyBB 1.8.38 |
[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->admin_logs, "index.php?module=tools-adminlog"); 18 19 $sub_tabs['admin_logs'] = array( 20 'title' => $lang->admin_logs, 21 'link' => "index.php?module=tools-adminlog", 22 'description' => $lang->admin_logs_desc 23 ); 24 $sub_tabs['prune_admin_logs'] = array( 25 'title' => $lang->prune_admin_logs, 26 'link' => "index.php?module=tools-adminlog&action=prune", 27 'description' => $lang->prune_admin_logs_desc 28 ); 29 30 $plugins->run_hooks("admin_tools_adminlog_begin"); 31 32 if($mybb->input['action'] == 'prune') 33 { 34 if(!is_super_admin($mybb->user['uid'])) 35 { 36 flash_message($lang->cannot_perform_action_super_admin_general, 'error'); 37 admin_redirect("index.php?module=tools-adminlog"); 38 } 39 40 $plugins->run_hooks("admin_tools_adminlog_prune"); 41 42 if($mybb->request_method == 'post') 43 { 44 $is_today = false; 45 $mybb->input['older_than'] = $mybb->get_input('older_than', MyBB::INPUT_INT); 46 if($mybb->input['older_than'] <= 0) 47 { 48 $is_today = true; 49 $mybb->input['older_than'] = 1; 50 } 51 $where = 'dateline < '.(TIME_NOW-($mybb->input['older_than']*86400)); 52 53 // Searching for entries by a particular user 54 if($mybb->input['uid']) 55 { 56 $where .= " AND uid='".$mybb->get_input('uid', MyBB::INPUT_INT)."'"; 57 } 58 59 // Searching for entries in a specific module 60 if($mybb->input['filter_module']) 61 { 62 $where .= " AND module='".$db->escape_string($mybb->input['filter_module'])."'"; 63 } 64 65 $query = $db->delete_query("adminlog", $where); 66 $num_deleted = $db->affected_rows(); 67 68 $plugins->run_hooks("admin_tools_adminlog_prune_commit"); 69 70 // Log admin action 71 log_admin_action($mybb->input['older_than'], $mybb->input['uid'], $mybb->input['filter_module'], $num_deleted); 72 73 $success = $lang->success_pruned_admin_logs; 74 if($is_today == true && $num_deleted > 0) 75 { 76 $success .= ' '.$lang->note_logs_locked; 77 } 78 elseif($is_today == true && $num_deleted == 0) 79 { 80 flash_message($lang->note_logs_locked, 'error'); 81 admin_redirect("index.php?module=tools-adminlog"); 82 } 83 flash_message($success, 'success'); 84 admin_redirect("index.php?module=tools-adminlog"); 85 } 86 $page->add_breadcrumb_item($lang->prune_admin_logs, "index.php?module=tools-adminlog&action=prune"); 87 $page->output_header($lang->prune_admin_logs); 88 $page->output_nav_tabs($sub_tabs, 'prune_admin_logs'); 89 90 // Fetch filter options 91 $sortbysel[$mybb->get_input('sortby')] = 'selected="selected"'; 92 $ordersel[$mybb->get_input('order')] = 'selected="selected"'; 93 94 $user_options[''] = $lang->all_administrators; 95 $user_options['0'] = '----------'; 96 97 $query = $db->query(" 98 SELECT DISTINCT l.uid, u.username 99 FROM ".TABLE_PREFIX."adminlog l 100 LEFT JOIN ".TABLE_PREFIX."users u ON (l.uid=u.uid) 101 ORDER BY u.username ASC 102 "); 103 while($user = $db->fetch_array($query)) 104 { 105 $user_options[$user['uid']] = htmlspecialchars_uni($user['username']); 106 } 107 108 $module_options = array(); 109 $module_options[''] = $lang->all_modules; 110 $module_options['0'] = '----------'; 111 $query = $db->query(" 112 SELECT DISTINCT l.module 113 FROM ".TABLE_PREFIX."adminlog l 114 ORDER BY l.module ASC 115 "); 116 while($module = $db->fetch_array($query)) 117 { 118 $module_options[$module['module']] = str_replace(' ', ' -> ', ucwords(str_replace('/', ' ', $module['module']))); 119 } 120 121 $form = new Form("index.php?module=tools-adminlog&action=prune", "post"); 122 $form_container = new FormContainer($lang->prune_administrator_logs); 123 $form_container->output_row($lang->module, "", $form->generate_select_box('filter_module', $module_options, $mybb->get_input('filter_module'), array('id' => 'filter_module')), 'filter_module'); 124 $form_container->output_row($lang->administrator, "", $form->generate_select_box('uid', $user_options, $mybb->get_input('uid'), array('id' => 'uid')), 'uid'); 125 if(!$mybb->get_input('older_than')) 126 { 127 $mybb->input['older_than'] = '30'; 128 } 129 $form_container->output_row($lang->date_range, "", $lang->older_than.$form->generate_numeric_field('older_than', $mybb->get_input('older_than'), array('id' => 'older_than', 'style' => 'width: 50px', 'min' => 0))." {$lang->days}", 'older_than'); 130 $form_container->end(); 131 $buttons[] = $form->generate_submit_button($lang->prune_administrator_logs); 132 $form->output_submit_wrapper($buttons); 133 $form->end(); 134 135 $page->output_footer(); 136 } 137 138 if(!$mybb->input['action']) 139 { 140 $page->output_header($lang->admin_logs); 141 $page->output_nav_tabs($sub_tabs, 'admin_logs'); 142 143 $perpage = $mybb->get_input('perpage', MyBB::INPUT_INT); 144 if(!$perpage) 145 { 146 if(!$mybb->settings['threadsperpage'] || (int)$mybb->settings['threadsperpage'] < 1) 147 { 148 $mybb->settings['threadsperpage'] = 20; 149 } 150 151 $perpage = $mybb->settings['threadsperpage']; 152 } 153 154 $where = ''; 155 156 $plugins->run_hooks("admin_tools_adminlog_start"); 157 158 // Searching for entries by a particular user 159 if(!empty($mybb->input['uid'])) 160 { 161 $where .= " AND l.uid='".$mybb->get_input('uid', MyBB::INPUT_INT)."'"; 162 } 163 164 // Searching for entries in a specific module 165 if(!empty($mybb->input['filter_module'])) 166 { 167 $where .= " AND module='".$db->escape_string($mybb->input['filter_module'])."'"; 168 } 169 170 // Order? 171 switch($mybb->get_input('sortby')) 172 { 173 case "username": 174 $sortby = "u.username"; 175 break; 176 default: 177 $sortby = "l.dateline"; 178 } 179 $order = $mybb->get_input('order'); 180 if($order != 'asc') 181 { 182 $order = 'desc'; 183 } 184 185 $query = $db->query(" 186 SELECT COUNT(l.dateline) AS count 187 FROM ".TABLE_PREFIX."adminlog l 188 LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=l.uid) 189 WHERE 1=1 {$where} 190 "); 191 $rescount = $db->fetch_field($query, "count"); 192 193 // Figure out if we need to display multiple pages. 194 if($mybb->get_input('page') != "last") 195 { 196 $pagecnt = $mybb->get_input('page', MyBB::INPUT_INT); 197 } 198 199 $postcount = (int)$rescount; 200 $pages = $postcount / $perpage; 201 $pages = ceil($pages); 202 203 if($mybb->get_input('page') == "last") 204 { 205 $pagecnt = $pages; 206 } 207 208 if($pagecnt > $pages) 209 { 210 $pagecnt = 1; 211 } 212 213 if($pagecnt) 214 { 215 $start = ($pagecnt-1) * $perpage; 216 } 217 else 218 { 219 $start = 0; 220 $pagecnt = 1; 221 } 222 223 $table = new Table; 224 $table->construct_header($lang->username, array('width' => '10%')); 225 $table->construct_header($lang->date, array('class' => 'align_center', 'width' => '15%')); 226 $table->construct_header($lang->information, array('class' => 'align_center', 'width' => '65%')); 227 $table->construct_header($lang->ipaddress, array('class' => 'align_center', 'width' => '10%')); 228 229 $query = $db->query(" 230 SELECT l.*, u.username, u.usergroup, u.displaygroup 231 FROM ".TABLE_PREFIX."adminlog l 232 LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=l.uid) 233 WHERE 1=1 {$where} 234 ORDER BY {$sortby} {$order} 235 LIMIT {$start}, {$perpage} 236 "); 237 while($logitem = $db->fetch_array($query)) 238 { 239 $information = ''; 240 $trow = alt_trow(); 241 $logitem['username'] = htmlspecialchars_uni($logitem['username']); 242 $username = format_name($logitem['username'], $logitem['usergroup'], $logitem['displaygroup']); 243 244 $logitem['data'] = my_unserialize($logitem['data']); 245 $logitem['profilelink'] = build_profile_link($username, $logitem['uid'], "_blank"); 246 $logitem['dateline'] = my_date('relative', $logitem['dateline']); 247 248 // Get detailed information from meta 249 $information = get_admin_log_action($logitem); 250 251 $table->construct_cell($logitem['profilelink']); 252 $table->construct_cell($logitem['dateline'], array('class' => 'align_center')); 253 $table->construct_cell($information); 254 $table->construct_cell(my_inet_ntop($db->unescape_binary($logitem['ipaddress'])), array('class' => 'align_center')); 255 $table->construct_row(); 256 } 257 258 if($table->num_rows() == 0) 259 { 260 $table->construct_cell($lang->no_adminlogs, array('colspan' => '4')); 261 $table->construct_row(); 262 } 263 264 $table->output($lang->admin_logs); 265 266 // Do we need to construct the pagination? 267 if($rescount > $perpage) 268 { 269 echo draw_admin_pagination($pagecnt, $perpage, $rescount, "index.php?module=tools-adminlog&perpage=$perpage&uid={$mybb->get_input('uid')}&fid={$mybb->get_input('fid')}&sortby={$mybb->get_input('sortby')}&order={$order}&filter_module=".htmlspecialchars_uni($mybb->get_input('filter_module')))."<br />"; 270 } 271 272 // Fetch filter options 273 $sortbysel[$mybb->get_input('sortby')] = 'selected="selected"'; 274 $ordersel[$mybb->get_input('order')] = 'selected="selected"'; 275 276 $user_options[''] = $lang->all_administrators; 277 $user_options['0'] = '----------'; 278 279 $query = $db->query(" 280 SELECT DISTINCT l.uid, u.username 281 FROM ".TABLE_PREFIX."adminlog l 282 LEFT JOIN ".TABLE_PREFIX."users u ON (l.uid=u.uid) 283 ORDER BY u.username ASC 284 "); 285 while($user = $db->fetch_array($query)) 286 { 287 $user_options[$user['uid']] = htmlspecialchars_uni($user['username']); 288 } 289 290 $module_options = array(); 291 $module_options[''] = $lang->all_modules; 292 $module_options['0'] = '----------'; 293 $query = $db->query(" 294 SELECT DISTINCT l.module 295 FROM ".TABLE_PREFIX."adminlog l 296 ORDER BY l.module ASC 297 "); 298 while($module = $db->fetch_array($query)) 299 { 300 $module_options[$module['module']] = str_replace(' ', ' -> ', ucwords(str_replace('/', ' ', $module['module']))); 301 } 302 303 $sort_by = array( 304 'dateline' => $lang->date, 305 'username' => $lang->username 306 ); 307 308 $order_array = array( 309 'asc' => $lang->asc, 310 'desc' => $lang->desc 311 ); 312 313 $form = new Form("index.php?module=tools-adminlog", "post"); 314 $form_container = new FormContainer($lang->filter_administrator_logs); 315 $form_container->output_row($lang->module, "", $form->generate_select_box('filter_module', $module_options, $mybb->get_input('filter_module'), array('id' => 'filter_module')), 'filter_module'); 316 $form_container->output_row($lang->administrator, "", $form->generate_select_box('uid', $user_options, $mybb->get_input('uid'), array('id' => 'uid')), 'uid'); 317 $form_container->output_row($lang->sort_by, "", $form->generate_select_box('sortby', $sort_by, $mybb->get_input('sortby'), array('id' => 'sortby'))." {$lang->in} ".$form->generate_select_box('order', $order_array, $order, array('id' => 'order'))." {$lang->order}", 'order'); 318 $form_container->output_row($lang->results_per_page, "", $form->generate_numeric_field('perpage', $perpage, array('id' => 'perpage', 'min' => 1)), 'perpage'); 319 320 $form_container->end(); 321 $buttons[] = $form->generate_submit_button($lang->filter_administrator_logs); 322 $form->output_submit_wrapper($buttons); 323 $form->end(); 324 325 $page->output_footer(); 326 } 327 328 /** 329 * Returns language-friendly string describing $logitem 330 * @param array $logitem The log item (one row from mybb_adminlogs) 331 * @return string The description 332 */ 333 function get_admin_log_action($logitem) 334 { 335 global $lang, $plugins, $mybb; 336 337 $logitem['module'] = str_replace('/', '-', $logitem['module']); 338 339 $module_path = explode('-', $logitem['module']); 340 $module = $module_path[0]; 341 if(isset($module_path[1])) 342 { 343 $action = $module_path[1]; 344 } 345 else 346 { 347 $action = null; 348 } 349 350 $lang_string = 'admin_log_'.$module.'_'.$action.'_'.$logitem['action']; 351 352 // Specific page overrides 353 switch($lang_string) 354 { 355 // == CONFIG == 356 case 'admin_log_config_banning_add': // Banning IP/Username/Email 357 case 'admin_log_config_banning_delete': // Removing banned IP/username/emails 358 switch($logitem['data'][2]) 359 { 360 case 1: 361 $lang_string = 'admin_log_config_banning_'.$logitem['action'].'_ip'; 362 break; 363 case 2: 364 $lang_string = 'admin_log_config_banning_'.$logitem['action'].'_username'; 365 break; 366 case 3: 367 $lang_string = 'admin_log_config_banning_'.$logitem['action'].'_email'; 368 break; 369 } 370 break; 371 372 case 'admin_log_config_help_documents_add': // Help documents and sections 373 case 'admin_log_config_help_documents_edit': 374 case 'admin_log_config_help_documents_delete': 375 $lang_string .= "_{$logitem['data'][2]}"; // adds _section or _document 376 break; 377 378 case 'admin_log_config_languages_edit': // Editing language variables 379 $logitem['data'][1] = basename($logitem['data'][1]); 380 if($logitem['data'][2] == 1) 381 { 382 $lang_string = 'admin_log_config_languages_edit_admin'; 383 } 384 break; 385 386 case 'admin_log_config_mycode_toggle_status': // Custom MyCode toggle activation 387 if($logitem['data'][2] == 1) 388 { 389 $lang_string .= '_enabled'; 390 } 391 else 392 { 393 $lang_string .= '_disabled'; 394 } 395 break; 396 case 'admin_log_config_plugins_activate': // Installing plugin 397 if($logitem['data'][1]) 398 { 399 $lang_string .= '_install'; 400 } 401 break; 402 case 'admin_log_config_plugins_deactivate': // Uninstalling plugin 403 if($logitem['data'][1]) 404 { 405 $lang_string .= '_uninstall'; 406 } 407 break; 408 // == FORUM == 409 case 'admin_log_forum_attachments_delete': // Deleting attachments 410 if($logitem['data'][2]) 411 { 412 $lang_string .= '_post'; 413 } 414 break; 415 case 'admin_log_forum_management_copy': // Forum copy 416 if(!empty($logitem['data'][4])) 417 { 418 $lang_string .= '_with_permissions'; 419 } 420 break; 421 case 'admin_log_forum_management_': // add mod, permissions, forum orders 422 // first parameter already set with action 423 $lang_string .= $logitem['data'][0]; 424 if($logitem['data'][0] == 'orders' && !empty($logitem['data'][1])) 425 { 426 $lang_string .= '_sub'; // updating forum orders in a subforum 427 } 428 break; 429 case 'admin_log_forum_moderation_queue_': //moderation queue 430 // first parameter already set with action 431 $lang_string .= $logitem['data'][0]; 432 break; 433 // == HOME == 434 case 'admin_log_home_preferences_': // 2FA 435 $lang_string .= $logitem['data'][0]; // either "enabled" or "disabled" 436 break; 437 // == STYLE == 438 case 'admin_log_style_templates_delete_template': // deleting templates 439 // global template set 440 if($logitem['data'][2] == -1) 441 { 442 $lang_string .= '_global'; 443 } 444 break; 445 case 'admin_log_style_templates_edit_template': // editing templates 446 // global template set 447 if($logitem['data'][2] == -1) 448 { 449 $lang_string .= '_global'; 450 } 451 break; 452 // == TOOLS == 453 case 'admin_log_tools_adminlog_prune': // Admin Log Pruning 454 if($logitem['data'][1] && !$logitem['data'][2]) 455 { 456 $lang_string = 'admin_log_tools_adminlog_prune_user'; 457 } 458 elseif($logitem['data'][2] && !$logitem['data'][1]) 459 { 460 $lang_string = 'admin_log_tools_adminlog_prune_module'; 461 } 462 elseif($logitem['data'][1] && $logitem['data'][2]) 463 { 464 $lang_string = 'admin_log_tools_adminlog_prune_user_module'; 465 } 466 break; 467 case 'admin_log_tools_modlog_prune': // Moderator Log Pruning 468 if($logitem['data'][1] && !$logitem['data'][2]) 469 { 470 $lang_string = 'admin_log_tools_modlog_prune_user'; 471 } 472 elseif($logitem['data'][2] && !$logitem['data'][1]) 473 { 474 $lang_string = 'admin_log_tools_modlog_prune_forum'; 475 } 476 elseif($logitem['data'][1] && $logitem['data'][2]) 477 { 478 $lang_string = 'admin_log_tools_modlog_prune_user_forum'; 479 } 480 break; 481 case 'admin_log_tools_backupdb_backup': // Create backup 482 if($logitem['data'][0] == 'download') 483 { 484 $lang_string = 'admin_log_tools_backupdb_backup_download'; 485 } 486 487 if(isset($logitem['data'][1])) 488 { 489 $logitem['data'][1] = '...'.substr($logitem['data'][1], -20); 490 } 491 break; 492 case 'admin_log_tools_backupdb_dlbackup': // Download backup 493 $logitem['data'][0] = '...'.substr($logitem['data'][0], -20); 494 break; 495 case 'admin_log_tools_backupdb_delete': // Delete backup 496 $logitem['data'][0] = '...'.substr($logitem['data'][0], -20); 497 break; 498 case 'admin_log_tools_optimizedb_': // Optimize DB 499 $logitem['data'][0] = @implode(', ', my_unserialize($logitem['data'][0])); 500 break; 501 case 'admin_log_tools_recount_rebuild_': // Recount and rebuild 502 $detail_lang_string = $lang_string.$logitem['data'][0]; 503 if(isset($lang->$detail_lang_string)) 504 { 505 $lang_string = $detail_lang_string; 506 } 507 break; 508 case 'admin_log_tools_spamlog_prune': // Spam Log Pruning 509 if($logitem['data'][1] && !$logitem['data'][2]) 510 { 511 $lang_string = 'admin_log_tools_spamlog_prune_user'; 512 } 513 elseif($logitem['data'][2] && !$logitem['data'][1]) 514 { 515 $lang_string = 'admin_log_tools_spamlog_prune_email'; 516 } 517 elseif($logitem['data'][1] && $logitem['data'][2]) 518 { 519 $lang_string = 'admin_log_tools_spamlog_prune_user_email'; 520 } 521 break; 522 // == USERS == 523 case 'admin_log_user_admin_permissions_edit': // editing default/group/user admin permissions 524 if($logitem['data'][0] > 0) 525 { 526 // User 527 $lang_string .= '_user'; 528 } 529 elseif($logitem['data'][0] < 0) 530 { 531 // Group 532 $logitem['data'][0] = abs($logitem['data'][0]); 533 $lang_string .= '_group'; 534 } 535 break; 536 case 'admin_log_user_admin_permissions_delete': // deleting group/user admin permissions 537 if($logitem['data'][0] > 0) 538 { 539 // User 540 $lang_string .= '_user'; 541 } 542 elseif($logitem['data'][0] < 0) 543 { 544 // Group 545 $logitem['data'][0] = abs($logitem['data'][0]); 546 $lang_string .= '_group'; 547 } 548 break; 549 case 'admin_log_user_awaiting_activation_activate': 550 if($logitem['data'][0] == 'deleted') 551 { 552 $lang_string .= '_deleted'; 553 } 554 else 555 { 556 $lang_string .= '_activated'; 557 } 558 break; 559 case 'admin_log_user_banning_': // banning 560 if($logitem['data'][2] == 0) 561 { 562 $lang_string = 'admin_log_user_banning_add_permanent'; 563 } 564 else 565 { 566 $logitem['data'][2] = my_date($mybb->settings['dateformat'], $logitem['data'][2]); 567 $lang_string = 'admin_log_user_banning_add_temporary'; 568 } 569 break; 570 case 'admin_log_user_groups_join_requests': 571 if($logitem['data'][0] == 'approve') 572 { 573 $lang_string = 'admin_log_user_groups_join_requests_approve'; 574 } 575 else 576 { 577 $lang_string = 'admin_log_user_groups_join_requests_deny'; 578 } 579 break; 580 case 'admin_log_user_users_inline_banned': 581 if($logitem['data'][1] == 0) 582 { 583 $lang_string = 'admin_log_user_users_inline_banned_perm'; 584 } 585 else 586 { 587 $logitem['data'][1] = my_date($mybb->settings['dateformat'], $logitem['data'][1]); 588 $lang_string = 'admin_log_user_users_inline_banned_temp'; 589 } 590 break; 591 } 592 593 $plugin_array = array('logitem' => &$logitem, 'lang_string' => &$lang_string); 594 $plugins->run_hooks("admin_tools_get_admin_log_action", $plugin_array); 595 596 foreach($logitem['data'] as $key => $value) 597 { 598 $logitem['data'][$key] = htmlspecialchars_uni($value); 599 } 600 601 if(isset($lang->$lang_string)) 602 { 603 array_unshift($logitem['data'], $lang->$lang_string); // First parameter for sprintf is the format string 604 $string = call_user_func_array(array($lang, 'sprintf'), $logitem['data']); 605 if(!$string) 606 { 607 $string = $lang->$lang_string; // Fall back to the one in the language pack 608 } 609 } 610 else 611 { 612 if(isset($logitem['data']['type']) && $logitem['data']['type'] == 'admin_locked_out') 613 { 614 $string = $lang->sprintf($lang->admin_log_admin_locked_out, (int) $logitem['data']['uid'], htmlspecialchars_uni($logitem['data']['username'])); 615 } 616 else 617 { 618 // Build a default string 619 $string = $logitem['module'].' - '.$logitem['action']; 620 if(is_array($logitem['data']) && count($logitem['data']) > 0) 621 { 622 $string .= '('.implode(', ', $logitem['data']).')'; 623 } 624 } 625 } 626 return $string; 627 } 628 629
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
2005 - 2021 © MyBB.de | Alle Rechte vorbehalten! | Sponsor: netcup | Cross-referenced by PHPXref |