[ Index ] |
PHP Cross Reference of MyBB 1.8.30 |
[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->system_health, "index.php?module=tools-system_health"); 18 19 $sub_tabs['system_health'] = array( 20 'title' => $lang->system_health, 21 'link' => "index.php?module=tools-system_health", 22 'description' => $lang->system_health_desc 23 ); 24 25 $sub_tabs['utf8_conversion'] = array( 26 'title' => $lang->utf8_conversion, 27 'link' => "index.php?module=tools-system_health&action=utf8_conversion", 28 'description' => $lang->utf8_conversion_desc2 29 ); 30 31 $sub_tabs['template_check'] = array( 32 'title' => $lang->check_templates, 33 'link' => "index.php?module=tools-system_health&action=check_templates", 34 'description' => $lang->check_templates_desc 35 ); 36 37 $plugins->run_hooks("admin_tools_system_health_begin"); 38 39 if($mybb->input['action'] == "do_check_templates" && $mybb->request_method == "post") 40 { 41 $query = $db->simple_select("templates", "*", "", array("order_by" => "sid, title", "order_dir" => "ASC")); 42 43 if(!$db->num_rows($query)) 44 { 45 flash_message($lang->error_invalid_input, 'error'); 46 admin_redirect("index.php?module=tools-system_health"); 47 } 48 49 $plugins->run_hooks("admin_tools_system_health_template_do_check_start"); 50 51 $t_cache = array(); 52 while($template = $db->fetch_array($query)) 53 { 54 if(check_template($template['template']) == true) 55 { 56 $t_cache[$template['sid']][] = $template; 57 } 58 } 59 60 if(empty($t_cache)) 61 { 62 flash_message($lang->success_templates_checked, 'success'); 63 admin_redirect("index.php?module=tools-system_health"); 64 } 65 66 $plugins->run_hooks("admin_tools_system_health_template_do_check"); 67 68 $page->add_breadcrumb_item($lang->check_templates); 69 $page->output_header($lang->check_templates); 70 71 $page->output_nav_tabs($sub_tabs, 'template_check'); 72 $page->output_inline_error(array($lang->check_templates_info_desc)); 73 74 $templatesets = array( 75 -2 => array( 76 "title" => "MyBB Master Templates" 77 ) 78 ); 79 $query = $db->simple_select("templatesets", "*"); 80 while($set = $db->fetch_array($query)) 81 { 82 $templatesets[$set['sid']] = $set; 83 } 84 85 $count = 0; 86 foreach($t_cache as $sid => $templates) 87 { 88 if(!$done_set[$sid]) 89 { 90 $table = new Table(); 91 $table->construct_header($templatesets[$sid]['title'], array("colspan" => 2)); 92 93 $done_set[$sid] = 1; 94 ++$count; 95 } 96 97 if($sid == -2) 98 { 99 // Some cheeky clown has altered the master templates! 100 $table->construct_cell($lang->error_master_templates_altered, array("colspan" => 2)); 101 $table->construct_row(); 102 } 103 104 foreach($templates as $template) 105 { 106 if($sid == -2) 107 { 108 $table->construct_cell($template['title'], array('colspan' => 2)); 109 } 110 else 111 { 112 $popup = new PopupMenu("template_{$template['tid']}", $lang->options); 113 $popup->add_item($lang->full_edit, "index.php?module=style-templates&action=edit_template&title=".urlencode($template['title'])."&sid={$sid}"); 114 115 $table->construct_cell("<a href=\"index.php?module=style-templates&action=edit_template&title=".urlencode($template['title'])."&sid={$sid}&from=diff_report\">{$template['title']}</a>", array('width' => '80%')); 116 $table->construct_cell($popup->fetch(), array("class" => "align_center")); 117 } 118 119 $table->construct_row(); 120 } 121 122 if($done_set[$sid] && !$done_output[$sid]) 123 { 124 $done_output[$sid] = 1; 125 if($count == 1) 126 { 127 $table->output($lang->check_templates); 128 } 129 else 130 { 131 $table->output(); 132 } 133 } 134 } 135 136 $page->output_footer(); 137 } 138 139 if($mybb->input['action'] == "check_templates") 140 { 141 $page->add_breadcrumb_item($lang->check_templates); 142 $page->output_header($lang->check_templates); 143 144 $plugins->run_hooks("admin_tools_system_health_template_check"); 145 146 $page->output_nav_tabs($sub_tabs, 'template_check'); 147 148 if($errors) 149 { 150 $page->output_inline_error($errors); 151 } 152 153 $form = new Form("index.php?module=tools-system_health", "post", "check_set"); 154 echo $form->generate_hidden_field("action", "do_check_templates"); 155 156 $form_container = new FormContainer($lang->check_templates); 157 $form_container->output_row($lang->check_templates_title, "", $lang->check_templates_info); 158 $form_container->end(); 159 160 $buttons = array(); 161 $buttons[] = $form->generate_submit_button($lang->proceed); 162 163 $form->output_submit_wrapper($buttons); 164 165 $form->end(); 166 167 $page->output_footer(); 168 } 169 170 if($mybb->input['action'] == "utf8_conversion") 171 { 172 if($db->type == "sqlite" || $db->type == "pgsql") 173 { 174 flash_message($lang->error_not_supported, 'error'); 175 admin_redirect("index.php?module=tools-system_health"); 176 } 177 178 $plugins->run_hooks("admin_tools_system_health_utf8_conversion"); 179 180 if($mybb->request_method == "post" || ($mybb->input['do'] == "all" && !empty($mybb->input['table']))) 181 { 182 if(!empty($mybb->input['mb4']) && version_compare($db->get_version(), '5.5.3', '<')) 183 { 184 flash_message($lang->error_utf8mb4_version, 'error'); 185 admin_redirect("index.php?module=tools-system_health&action=utf8_conversion"); 186 } 187 @set_time_limit(0); 188 189 $old_table_prefix = $db->table_prefix; 190 $db->set_table_prefix(''); 191 192 if(!$db->table_exists($db->escape_string($mybb->input['table']))) 193 { 194 $db->set_table_prefix($old_table_prefix); 195 flash_message($lang->error_invalid_table, 'error'); 196 admin_redirect("index.php?module=tools-system_health&action=utf8_conversion"); 197 } 198 199 $db->set_table_prefix($old_table_prefix); 200 201 $page->add_breadcrumb_item($lang->utf8_conversion, "index.php?module=tools-system_health&action=utf8_conversion"); 202 203 $page->output_header($lang->system_health." - ".$lang->utf8_conversion); 204 205 $sub_tabs['system_health'] = array( 206 'title' => $lang->system_health, 207 'link' => "index.php?module=tools-system_health", 208 'description' => $lang->system_health_desc 209 ); 210 211 $sub_tabs['utf8_conversion'] = array( 212 'title' => $lang->utf8_conversion, 213 'link' => "index.php?module=tools-system_health&action=utf8_conversion", 214 'description' => $lang->utf8_conversion_desc2 215 ); 216 217 $page->output_nav_tabs($sub_tabs, 'utf8_conversion'); 218 219 $old_table_prefix = $db->table_prefix; 220 $db->set_table_prefix(''); 221 222 $table = new Table; 223 224 $table1 = $db->show_create_table($db->escape_string($mybb->input['table'])); 225 preg_match("#CHARSET=([a-zA-Z0-9_]+)\s?#i", $table1, $matches); 226 $charset = $matches[1]; 227 228 if(!empty($mybb->input['mb4'])) 229 { 230 $table->construct_cell("<strong>".$lang->sprintf($lang->converting_to_utf8mb4, $mybb->input['table'], $charset)."</strong>"); 231 } 232 else 233 { 234 $table->construct_cell("<strong>".$lang->sprintf($lang->converting_to_utf8, $mybb->input['table'], $charset)."</strong>"); 235 } 236 $table->construct_row(); 237 238 $table->construct_cell($lang->please_wait); 239 $table->construct_row(); 240 241 $table->output($converting_table." {$mybb->input['table']}"); 242 243 $db->set_table_prefix($old_table_prefix); 244 245 $page->output_footer(false); 246 247 $old_table_prefix = $db->table_prefix; 248 $db->set_table_prefix(''); 249 250 flush(); 251 252 $types = array( 253 'text' => 'blob', 254 'mediumtext' => 'mediumblob', 255 'longtext' => 'longblob', 256 'char' => 'varbinary', 257 'varchar' => 'varbinary', 258 'tinytext' => 'tinyblob' 259 ); 260 261 $blob_types = array( 'blob', 'tinyblob', 'mediumblog', 'longblob', 'text', 'tinytext', 'mediumtext', 'longtext' ); 262 263 // Get next table in list 264 $convert_to_binary = ''; 265 $convert_to_utf8 = ''; 266 $comma = ''; 267 268 if(!empty($mybb->input['mb4'])) 269 { 270 $character_set = 'utf8mb4'; 271 $collation = 'utf8mb4_general_ci'; 272 } 273 else 274 { 275 $character_set = 'utf8'; 276 $collation = 'utf8_general_ci'; 277 } 278 279 // Set table default charset 280 $db->write_query("ALTER TABLE {$mybb->input['table']} DEFAULT CHARACTER SET {$character_set} COLLATE {$collation}"); 281 282 // Fetch any fulltext keys 283 if($db->supports_fulltext($mybb->input['table'])) 284 { 285 $table_structure = $db->show_create_table($mybb->input['table']); 286 switch($db->type) 287 { 288 case "mysql": 289 case "mysqli": 290 preg_match_all("#FULLTEXT KEY `?([a-zA-Z0-9_]+)`? \(([a-zA-Z0-9_`,']+)\)#i", $table_structure, $matches); 291 if(is_array($matches)) 292 { 293 foreach($matches[0] as $key => $matched) 294 { 295 $db->write_query("ALTER TABLE {$mybb->input['table']} DROP INDEX {$matches[1][$key]}"); 296 $fulltext_to_create[$matches[1][$key]] = $matches[2][$key]; 297 } 298 } 299 } 300 } 301 302 // Find out which columns need converting and build SQL statements 303 $query = $db->query("SHOW FULL COLUMNS FROM {$mybb->input['table']}"); 304 while($column = $db->fetch_array($query)) 305 { 306 list($type) = explode('(', $column['Type']); 307 if(array_key_exists($type, $types)) 308 { 309 // Build the actual strings for converting the columns 310 $names = "CHANGE `{$column['Field']}` `{$column['Field']}` "; 311 312 if(($db->type == 'mysql' || $db->type == 'mysqli') && in_array($type, $blob_types)) 313 { 314 if($column['Null'] == 'YES') 315 { 316 $attributes = 'NULL'; 317 } 318 else 319 { 320 $attributes = 'NOT NULL'; 321 } 322 } 323 else 324 { 325 $attributes = " DEFAULT "; 326 if($column['Default'] == 'NULL') 327 { 328 $attributes .= "NULL "; 329 } 330 else 331 { 332 $attributes .= "'".$db->escape_string($column['Default'])."' "; 333 334 if($column['Null'] == 'YES') 335 { 336 $attributes .= 'NULL'; 337 } 338 else 339 { 340 $attributes .= 'NOT NULL'; 341 } 342 } 343 } 344 345 $convert_to_binary .= $comma.$names.preg_replace('/'.$type.'/i', $types[$type], $column['Type']).' '.$attributes; 346 $convert_to_utf8 .= "{$comma}{$names}{$column['Type']} CHARACTER SET {$character_set} COLLATE {$collation} {$attributes}"; 347 348 $comma = ','; 349 } 350 } 351 352 if(!empty($convert_to_binary)) 353 { 354 // This converts the columns to UTF-8 while also doing the same for data 355 $db->write_query("ALTER TABLE {$mybb->input['table']} {$convert_to_binary}"); 356 $db->write_query("ALTER TABLE {$mybb->input['table']} {$convert_to_utf8}"); 357 } 358 359 // Any fulltext indexes to recreate? 360 if(is_array($fulltext_to_create)) 361 { 362 foreach($fulltext_to_create as $name => $fields) 363 { 364 $db->create_fulltext_index($mybb->input['table'], $fields, $name); 365 } 366 } 367 368 $db->set_table_prefix($old_table_prefix); 369 370 $plugins->run_hooks("admin_tools_system_health_utf8_conversion_commit"); 371 372 // Log admin action 373 log_admin_action($mybb->input['table']); 374 375 flash_message($lang->sprintf($lang->success_table_converted, $mybb->input['table']), 'success'); 376 377 if($mybb->input['do'] == "all") 378 { 379 $old_table_prefix = $db->table_prefix; 380 $db->set_table_prefix(''); 381 382 $tables = $db->list_tables($mybb->config['database']['database']); 383 foreach($tables as $key => $tablename) 384 { 385 if(substr($tablename, 0, strlen(TABLE_PREFIX)) == TABLE_PREFIX) 386 { 387 $table = $db->show_create_table($tablename); 388 preg_match("#CHARSET=([a-zA-Z0-9_]+)\s?#i", $table, $matches); 389 if(empty($mybb->input['mb4']) && (fetch_iconv_encoding($matches[1]) == 'utf-8' || $matches[1] == 'utf8mb4') && $mybb->input['table'] != $tablename) 390 { 391 continue; 392 } 393 elseif(!empty($mybb->input['mb4']) && fetch_iconv_encoding($matches[1]) != 'utf-8' && $mybb->input['table'] != $tablename) 394 { 395 continue; 396 } 397 398 $mybb_tables[$key] = $tablename; 399 } 400 } 401 402 asort($mybb_tables); 403 reset($mybb_tables); 404 405 $is_next = false; 406 $nexttable = ""; 407 408 foreach($mybb_tables as $key => $tablename) 409 { 410 if($is_next == true) 411 { 412 $nexttable = $tablename; 413 break; 414 } 415 else if($mybb->input['table'] == $tablename) 416 { 417 $is_next = true; 418 } 419 } 420 421 $db->set_table_prefix($old_table_prefix); 422 423 if($nexttable) 424 { 425 $nexttable = $db->escape_string($nexttable); 426 $mb4 = ''; 427 if(!empty($mybb->input['mb4'])) 428 { 429 $mb4 = "&mb4=1"; 430 } 431 admin_redirect("index.php?module=tools-system_health&action=utf8_conversion&do=all&table={$nexttable}{$mb4}"); 432 exit; 433 } 434 } 435 436 admin_redirect("index.php?module=tools-system_health&action=utf8_conversion"); 437 438 exit; 439 } 440 441 if($mybb->input['table'] || $mybb->input['do'] == "all") 442 { 443 if(!empty($mybb->input['mb4']) && version_compare($db->get_version(), '5.5.3', '<')) 444 { 445 flash_message($lang->error_utf8mb4_version, 'error'); 446 admin_redirect("index.php?module=tools-system_health&action=utf8_conversion"); 447 } 448 449 $old_table_prefix = $db->table_prefix; 450 $db->set_table_prefix(''); 451 452 if($mybb->input['do'] != "all" && !$db->table_exists($db->escape_string($mybb->input['table']))) 453 { 454 $db->set_table_prefix($old_table_prefix); 455 flash_message($lang->error_invalid_table, 'error'); 456 admin_redirect("index.php?module=tools-system_health&action=utf8_conversion"); 457 } 458 459 if($mybb->input['do'] == "all") 460 { 461 $tables = $db->list_tables($mybb->config['database']['database']); 462 foreach($tables as $key => $tablename) 463 { 464 if(substr($tablename, 0, strlen(TABLE_PREFIX)) == TABLE_PREFIX) 465 { 466 $table = $db->show_create_table($tablename); 467 preg_match("#CHARSET=([a-zA-Z0-9_]+)\s?#i", $table, $matches); 468 if(empty($mybb->input['mb4']) && (fetch_iconv_encoding($matches[1]) == 'utf-8' || $matches[1] == 'utf8mb4')) 469 { 470 continue; 471 } 472 elseif(!empty($mybb->input['mb4']) && fetch_iconv_encoding($matches[1]) != 'utf-8') 473 { 474 continue; 475 } 476 $mybb_tables[$key] = $tablename; 477 } 478 } 479 480 if(is_array($mybb_tables)) 481 { 482 asort($mybb_tables); 483 reset($mybb_tables); 484 $nexttable = current($mybb_tables); 485 $table = $db->show_create_table($db->escape_string($nexttable)); 486 $mybb->input['table'] = $nexttable; 487 } 488 else 489 { 490 $db->set_table_prefix($old_table_prefix); 491 flash_message($lang->success_all_tables_already_converted, 'success'); 492 admin_redirect("index.php?module=tools-system_health"); 493 } 494 } 495 else 496 { 497 $table = $db->show_create_table($db->escape_string($mybb->input['table'])); 498 } 499 500 $page->add_breadcrumb_item($lang->utf8_conversion, "index.php?module=tools-system_health&action=utf8_conversion"); 501 502 $db->set_table_prefix($old_table_prefix); 503 504 $page->output_header($lang->system_health." - ".$lang->utf8_conversion); 505 506 $sub_tabs['system_health'] = array( 507 'title' => $lang->system_health, 508 'link' => "index.php?module=tools-system_health", 509 'description' => $lang->system_health_desc 510 ); 511 512 $sub_tabs['utf8_conversion'] = array( 513 'title' => $lang->utf8_conversion, 514 'link' => "index.php?module=tools-system_health&action=utf8_conversion", 515 'description' => $lang->utf8_conversion_desc2 516 ); 517 518 $page->output_nav_tabs($sub_tabs, 'utf8_conversion'); 519 520 $old_table_prefix = $db->table_prefix; 521 $db->set_table_prefix(''); 522 523 preg_match("#CHARSET=([a-zA-Z0-9_]+)\s?#i", $table, $matches); 524 $charset = $matches[1]; 525 526 $mb4 = ''; 527 if(!empty($mybb->input['mb4'])) 528 { 529 $mb4 = "&mb4=1"; 530 } 531 532 $form = new Form("index.php?module=tools-system_health&action=utf8_conversion{$mb4}", "post", "utf8_conversion"); 533 echo $form->generate_hidden_field("table", $mybb->input['table']); 534 535 if($mybb->input['do'] == "all") 536 { 537 echo $form->generate_hidden_field("do", "all"); 538 } 539 540 $table = new Table; 541 542 if(!empty($mybb->input['mb4'])) 543 { 544 $table->construct_cell("<strong>".$lang->sprintf($lang->convert_all_to_utf8mb4, $charset)."</strong>"); 545 $lang->notice_process_long_time .= "<br /><br /><strong>{$lang->notice_mb4_warning}</strong>"; 546 } 547 else 548 { 549 if($mybb->input['do'] == "all") 550 { 551 $table->construct_cell("<strong>".$lang->sprintf($lang->convert_all_to_utf, $charset)."</strong>"); 552 } 553 else 554 { 555 $table->construct_cell("<strong>".$lang->sprintf($lang->convert_to_utf8, $mybb->input['table'], $charset)."</strong>"); 556 } 557 } 558 559 $table->construct_row(); 560 561 $table->construct_cell($lang->notice_process_long_time); 562 $table->construct_row(); 563 564 if($mybb->input['do'] == "all") 565 { 566 $table->output($lang->convert_tables); 567 $buttons[] = $form->generate_submit_button($lang->convert_database_tables); 568 } 569 else 570 { 571 $table->output($lang->convert_table.": {$mybb->input['table']}"); 572 $buttons[] = $form->generate_submit_button($lang->convert_database_table); 573 } 574 575 $form->output_submit_wrapper($buttons); 576 577 $form->end(); 578 579 $db->set_table_prefix($old_table_prefix); 580 581 $page->output_footer(); 582 583 exit; 584 } 585 586 if(!$mybb->config['database']['encoding']) 587 { 588 flash_message($lang->error_db_encoding_not_set, 'error'); 589 admin_redirect("index.php?module=tools-system_health"); 590 } 591 592 $tables = $db->list_tables($mybb->config['database']['database']); 593 594 $old_table_prefix = $db->table_prefix; 595 $db->set_table_prefix(''); 596 597 $encodings = array(); 598 599 foreach($tables as $key => $tablename) 600 { 601 if(substr($tablename, 0, strlen($old_table_prefix)) == $old_table_prefix) 602 { 603 $table = $db->show_create_table($tablename); 604 preg_match("#CHARSET=([a-zA-Z0-9_]+)\s?#i", $table, $matches); 605 $encodings[$key] = fetch_iconv_encoding($matches[1]); 606 $mybb_tables[$key] = $tablename; 607 } 608 } 609 610 $db->set_table_prefix($old_table_prefix); 611 612 $page->add_breadcrumb_item($lang->utf8_conversion, "index.php?module=tools-system_health&action=utf8_conversion"); 613 614 $page->output_header($lang->system_health." - ".$lang->utf8_conversion); 615 616 $page->output_nav_tabs($sub_tabs, 'utf8_conversion'); 617 618 asort($mybb_tables); 619 620 $unique = array_unique($encodings); 621 622 $convert_utf8 = $convert_utf8mb4 = false; 623 foreach($unique as $encoding) 624 { 625 if($encoding == 'utf-8') 626 { 627 $convert_utf8mb4 = true; 628 } 629 elseif($encoding != 'utf8mb4') 630 { 631 $convert_utf8 = true; 632 } 633 } 634 635 if(count($unique) > 1) 636 { 637 $page->output_error("<p><em>{$lang->warning_multiple_encodings}</em></p>"); 638 } 639 640 if(in_array('utf8mb4', $unique) && $mybb->config['database']['encoding'] != 'utf8mb4') 641 { 642 $page->output_error("<p><em>{$lang->warning_utf8mb4_config}</em></p>"); 643 } 644 645 $table = new Table; 646 $table->construct_header($lang->table); 647 $table->construct_header($lang->status_utf8, array("class" => "align_center")); 648 $table->construct_header($lang->status_utf8mb4, array("class" => "align_center")); 649 650 $all_utf8 = $all_utf8mb4 = '-'; 651 if($convert_utf8) 652 { 653 $all_utf8 = "<strong><a href=\"index.php?module=tools-system_health&action=utf8_conversion&do=all\">{$lang->convert_all}</a></strong>"; 654 } 655 if($convert_utf8mb4) 656 { 657 $all_utf8mb4 = "<strong><a href=\"index.php?module=tools-system_health&action=utf8_conversion&do=all&mb4=1\">{$lang->convert_all}</a></strong>"; 658 } 659 $table->construct_cell("<strong>{$lang->all_tables}</strong>"); 660 $table->construct_cell($all_utf8, array("class" => "align_center", 'width' => '15%')); 661 $table->construct_cell($all_utf8mb4, array("class" => "align_center", 'width' => '25%')); 662 $table->construct_row(); 663 664 $db_version = $db->get_version(); 665 666 foreach($mybb_tables as $key => $tablename) 667 { 668 if($encodings[$key] != 'utf-8' && $encodings[$key] != 'utf8mb4') 669 { 670 $status = "<a href=\"index.php?module=tools-system_health&action=utf8_conversion&table={$tablename}\" style=\"background: url(styles/{$page->style}/images/icons/cross.png) no-repeat; padding-left: 20px;\">{$lang->convert_now}</a>"; 671 } 672 else 673 { 674 $status = "<img src=\"styles/{$page->style}/images/icons/tick.png\" alt=\"{$lang->ok}\" />"; 675 } 676 if(version_compare($db_version, '5.5.3', '<')) 677 { 678 $utf8mb4 = $lang->not_available; 679 } 680 elseif($encodings[$key] == 'utf8mb4') 681 { 682 $utf8mb4 = "<img src=\"styles/{$page->style}/images/icons/tick.png\" alt=\"{$lang->ok}\" />"; 683 } 684 elseif($encodings[$key] == 'utf-8') 685 { 686 $utf8mb4 = "<a href=\"index.php?module=tools-system_health&action=utf8_conversion&table={$tablename}&mb4=1\" style=\"background: url(styles/{$page->style}/images/icons/cross.png) no-repeat; padding-left: 20px;\">{$lang->convert_now}</a>"; 687 } 688 else 689 { 690 $utf8mb4 = "-"; 691 } 692 $table->construct_cell("<strong>{$tablename}</strong>"); 693 $table->construct_cell($status, array("class" => "align_center", 'width' => '15%')); 694 $table->construct_cell($utf8mb4, array("class" => "align_center", 'width' => '25%')); 695 $table->construct_row(); 696 } 697 698 $table->output("<div>{$lang->utf8_conversion}</div>"); 699 700 $page->output_footer(); 701 } 702 703 if(!$mybb->input['action']) 704 { 705 $page->output_header($lang->system_health); 706 707 $plugins->run_hooks("admin_tools_system_health_start"); 708 709 $page->output_nav_tabs($sub_tabs, 'system_health'); 710 711 $table = new Table; 712 $table->construct_header($lang->totals, array("colspan" => 2)); 713 $table->construct_header($lang->attachments, array("colspan" => 2)); 714 715 $query = $db->simple_select("attachments", "COUNT(*) AS numattachs, SUM(filesize) as spaceused, SUM(downloads*filesize) as bandwidthused", "visible='1' AND pid > '0'"); 716 $attachs = $db->fetch_array($query); 717 718 $table->construct_cell("<strong>{$lang->total_database_size}</strong>", array('width' => '25%')); 719 $table->construct_cell(get_friendly_size($db->fetch_size()), array('width' => '25%')); 720 $table->construct_cell("<strong>{$lang->attachment_space_used}</strong>", array('width' => '200')); 721 $table->construct_cell(get_friendly_size((int)$attachs['spaceused']), array('width' => '200')); 722 $table->construct_row(); 723 724 if($attachs['spaceused'] > 0) 725 { 726 $attach_average_size = round($attachs['spaceused']/$attachs['numattachs']); 727 $bandwidth_average_usage = round($attachs['bandwidthused']); 728 } 729 else 730 { 731 $attach_average_size = 0; 732 $bandwidth_average_usage = 0; 733 } 734 735 $table->construct_cell("<strong>{$lang->total_cache_size}</strong>", array('width' => '25%')); 736 $table->construct_cell(get_friendly_size($cache->size_of()), array('width' => '25%')); 737 $table->construct_cell("<strong>{$lang->estimated_attachment_bandwidth_usage}</strong>", array('width' => '25%')); 738 $table->construct_cell(get_friendly_size($bandwidth_average_usage), array('width' => '25%')); 739 $table->construct_row(); 740 741 742 $table->construct_cell("<strong>{$lang->max_upload_post_size}</strong>", array('width' => '200')); 743 $table->construct_cell(@ini_get('upload_max_filesize').' / '.@ini_get('post_max_size'), array('width' => '200')); 744 $table->construct_cell("<strong>{$lang->average_attachment_size}</strong>", array('width' => '25%')); 745 $table->construct_cell(get_friendly_size($attach_average_size), array('width' => '25%')); 746 $table->construct_row(); 747 748 $table->output($lang->stats); 749 750 $table->construct_header($lang->task); 751 $table->construct_header($lang->run_time, array("width" => 200, "class" => "align_center")); 752 753 $task_cache = $cache->read("tasks"); 754 $nextrun = $task_cache['nextrun']; 755 756 $query = $db->simple_select("tasks", "*", "nextrun >= '{$nextrun}' AND enabled='1'", array("order_by" => "nextrun", "order_dir" => "asc", 'limit' => 3)); 757 while($task = $db->fetch_array($query)) 758 { 759 $task['title'] = htmlspecialchars_uni($task['title']); 760 $next_run = my_date('normal', $task['nextrun'], "", 2); 761 $table->construct_cell("<strong>{$task['title']}</strong>"); 762 $table->construct_cell($next_run, array("class" => "align_center")); 763 764 $table->construct_row(); 765 } 766 767 if($table->num_rows() == 0) 768 { 769 $table->construct_cell($lang->no_tasks, array('colspan' => 2)); 770 $table->construct_row(); 771 } 772 773 $table->output($lang->next_3_tasks); 774 775 if(isset($mybb->admin['permissions']['tools']['backupdb']) && $mybb->admin['permissions']['tools']['backupdb'] == 1) 776 { 777 $backups = array(); 778 $dir = MYBB_ADMIN_DIR.'backups/'; 779 $handle = opendir($dir); 780 while(($file = readdir($handle)) !== false) 781 { 782 if(filetype(MYBB_ADMIN_DIR.'backups/'.$file) == 'file') 783 { 784 $ext = get_extension($file); 785 if($ext == 'gz' || $ext == 'sql') 786 { 787 $backups[@filemtime(MYBB_ADMIN_DIR.'backups/'.$file)] = array( 788 "file" => $file, 789 "time" => @filemtime(MYBB_ADMIN_DIR.'backups/'.$file), 790 "type" => $ext 791 ); 792 } 793 } 794 } 795 796 $count = count($backups); 797 krsort($backups); 798 799 $table = new Table; 800 $table->construct_header($lang->name); 801 $table->construct_header($lang->backup_time, array("width" => 200, "class" => "align_center")); 802 803 $backupscnt = 0; 804 foreach($backups as $backup) 805 { 806 ++$backupscnt; 807 808 if($backupscnt == 4) 809 { 810 break; 811 } 812 813 $time = "-"; 814 if($backup['time']) 815 { 816 $time = my_date('relative', $backup['time']); 817 } 818 819 $table->construct_cell("<a href=\"index.php?module=tools-backupdb&action=dlbackup&file={$backup['file']}\">{$backup['file']}</a>"); 820 $table->construct_cell($time, array("class" => "align_center")); 821 $table->construct_row(); 822 } 823 824 if($count == 0) 825 { 826 $table->construct_cell($lang->no_backups, array('colspan' => 2)); 827 $table->construct_row(); 828 } 829 830 $table->output($lang->existing_db_backups); 831 } 832 833 if(is_writable(MYBB_ROOT.'inc/settings.php')) 834 { 835 $message_settings = "<span style=\"color: green;\">{$lang->writable}</span>"; 836 } 837 else 838 { 839 $message_settings = "<strong><span style=\"color: #C00\">{$lang->not_writable}</span></strong><br />{$lang->please_chmod_777}"; 840 ++$errors; 841 } 842 843 if(is_writable(MYBB_ROOT.'inc/config.php')) 844 { 845 $message_config = "<span style=\"color: green;\">{$lang->writable}</span>"; 846 } 847 else 848 { 849 $message_config = "<strong><span style=\"color: #C00\">{$lang->not_writable}</span></strong><br />{$lang->please_chmod_777}"; 850 ++$errors; 851 } 852 853 $uploadspath_abs = mk_path_abs($mybb->settings['uploadspath']); 854 if(is_writable($uploadspath_abs)) 855 { 856 $message_upload = "<span style=\"color: green;\">{$lang->writable}</span>"; 857 } 858 else 859 { 860 $message_upload = "<strong><span style=\"color: #C00\">{$lang->not_writable}</span></strong><br />{$lang->please_chmod_777}"; 861 ++$errors; 862 } 863 864 $avataruploadpath_abs = mk_path_abs($mybb->settings['avataruploadpath']); 865 if(is_writable($avataruploadpath_abs)) 866 { 867 $message_avatar = "<span style=\"color: green;\">{$lang->writable}</span>"; 868 } 869 else 870 { 871 $message_avatar = "<strong><span style=\"color: #C00\">{$lang->not_writable}</span></strong><br />{$lang->please_chmod_777}"; 872 ++$errors; 873 } 874 875 if(is_writable(MYBB_ROOT.'inc/languages/')) 876 { 877 $message_language = "<span style=\"color: green;\">{$lang->writable}</span>"; 878 } 879 else 880 { 881 $message_language = "<strong><span style=\"color: #C00\">{$lang->not_writable}</span></strong><br />{$lang->please_chmod_777}"; 882 ++$errors; 883 } 884 885 if(is_writable(MYBB_ROOT.$config['admin_dir'].'/backups/')) 886 { 887 $message_backup = "<span style=\"color: green;\">{$lang->writable}</span>"; 888 } 889 else 890 { 891 $message_backup = "<strong><span style=\"color: #C00\">{$lang->not_writable}</span></strong><br />{$lang->please_chmod_777}"; 892 ++$errors; 893 } 894 895 if(is_writable(MYBB_ROOT.'/cache/')) 896 { 897 $message_cache = "<span style=\"color: green;\">{$lang->writable}</span>"; 898 } 899 else 900 { 901 $message_cache = "<strong><span style=\"color: #C00\">{$lang->not_writable}</span></strong><br />{$lang->please_chmod_777}"; 902 ++$errors; 903 } 904 905 if(is_writable(MYBB_ROOT.'/cache/themes/')) 906 { 907 $message_themes = "<span style=\"color: green;\">{$lang->writable}</span>"; 908 } 909 else 910 { 911 $message_themes = "<strong><span style=\"color: #C00\">{$lang->not_writable}</span></strong><br />{$lang->please_chmod_777}"; 912 ++$errors; 913 } 914 915 if($errors) 916 { 917 $page->output_error("<p><em>{$errors} {$lang->error_chmod}</span></strong> {$lang->chmod_info} <a href=\"https://docs.mybb.com/1.8/administration/security/file-permissions\" target=\"_blank\" rel=\"noopener\">MyBB Docs</a>.</em></p>"); 918 } 919 else 920 { 921 $page->output_success("<p><em>{$lang->success_chmod}</em></p>"); 922 } 923 924 $table = new Table; 925 $table->construct_header($lang->file); 926 $table->construct_header($lang->location, array("colspan" => 2, 'width' => 250)); 927 928 $table->construct_cell("<strong>{$lang->config_file}</strong>"); 929 $table->construct_cell("./inc/config.php"); 930 $table->construct_cell($message_config); 931 $table->construct_row(); 932 933 $table->construct_cell("<strong>{$lang->settings_file}</strong>"); 934 $table->construct_cell("./inc/settings.php"); 935 $table->construct_cell($message_settings); 936 $table->construct_row(); 937 938 $table->construct_cell("<strong>{$lang->file_upload_dir}</strong>"); 939 $table->construct_cell($mybb->settings['uploadspath']); 940 $table->construct_cell($message_upload); 941 $table->construct_row(); 942 943 $table->construct_cell("<strong>{$lang->avatar_upload_dir}</strong>"); 944 $table->construct_cell($mybb->settings['avataruploadpath']); 945 $table->construct_cell($message_avatar); 946 $table->construct_row(); 947 948 $table->construct_cell("<strong>{$lang->language_files}</strong>"); 949 $table->construct_cell("./inc/languages"); 950 $table->construct_cell($message_language); 951 $table->construct_row(); 952 953 $table->construct_cell("<strong>{$lang->backup_dir}</strong>"); 954 $table->construct_cell('./'.$config['admin_dir'].'/backups'); 955 $table->construct_cell($message_backup); 956 $table->construct_row(); 957 958 $table->construct_cell("<strong>{$lang->cache_dir}</strong>"); 959 $table->construct_cell('./cache'); 960 $table->construct_cell($message_cache); 961 $table->construct_row(); 962 963 $table->construct_cell("<strong>{$lang->themes_dir}</strong>"); 964 $table->construct_cell('./cache/themes'); 965 $table->construct_cell($message_themes); 966 $table->construct_row(); 967 968 $plugins->run_hooks("admin_tools_system_health_output_chmod_list"); 969 970 $table->output($lang->chmod_files_and_dirs); 971 972 $page->output_footer(); 973 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
2005 - 2021 © MyBB.de | Alle Rechte vorbehalten! | Sponsor: netcup | Cross-referenced by PHPXref |