[ Index ]

PHP Cross Reference of MyBB 1.8.38

title

Body

[close]

/admin/modules/tools/ -> system_health.php (source)

   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&amp;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&amp;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&amp;action=edit_template&amp;title=".urlencode($template['title'])."&amp;sid={$sid}");
 114  
 115                  $table->construct_cell("<a href=\"index.php?module=style-templates&amp;action=edit_template&amp;title=".urlencode($template['title'])."&amp;sid={$sid}&amp;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&amp;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&amp;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($lang->sprintf($lang->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          $fulltext_to_create = array();
 284          if($db->supports_fulltext($mybb->input['table']))
 285          {
 286              $table_structure = $db->show_create_table($mybb->input['table']);
 287              switch($db->type)
 288              {
 289                  case "mysql":
 290                  case "mysqli":
 291                      preg_match_all("#FULLTEXT KEY `?([a-zA-Z0-9_]+)`? \(([a-zA-Z0-9_`,']+)\)#i", $table_structure, $matches);
 292                      if(is_array($matches))
 293                      {
 294                          foreach($matches[0] as $key => $matched)
 295                          {
 296                              $db->write_query("ALTER TABLE {$mybb->input['table']} DROP INDEX {$matches[1][$key]}");
 297                              $fulltext_to_create[$matches[1][$key]] = $matches[2][$key];
 298                          }
 299                      }
 300              }
 301          }
 302  
 303          // Find out which columns need converting and build SQL statements
 304          $query = $db->query("SHOW FULL COLUMNS FROM {$mybb->input['table']}");
 305          while($column = $db->fetch_array($query))
 306          {
 307              list($type) = explode('(', $column['Type']);
 308              if(array_key_exists($type, $types))
 309              {
 310                  // Build the actual strings for converting the columns
 311                  $names = "CHANGE `{$column['Field']}` `{$column['Field']}` ";
 312  
 313                  if(($db->type == 'mysql' || $db->type == 'mysqli') && in_array($type, $blob_types))
 314                  {
 315                      if($column['Null'] == 'YES')
 316                      {
 317                          $attributes = 'NULL';
 318                      }
 319                      else
 320                      {
 321                          $attributes = 'NOT NULL';
 322                      }
 323                  }
 324                  else
 325                  {
 326                      $attributes = " DEFAULT ";
 327                      if($column['Default'] == 'NULL')
 328                      {
 329                          $attributes .= "NULL ";
 330                      }
 331                      else
 332                      {
 333                          $attributes .= "'".$db->escape_string($column['Default'])."' ";
 334  
 335                          if($column['Null'] == 'YES')
 336                          {
 337                              $attributes .= 'NULL';
 338                          }
 339                          else
 340                          {
 341                              $attributes .= 'NOT NULL';
 342                          }
 343                      }
 344                  }
 345  
 346                  $convert_to_binary .= $comma.$names.preg_replace('/'.$type.'/i', $types[$type], $column['Type']).' '.$attributes;
 347                  $convert_to_utf8 .= "{$comma}{$names}{$column['Type']} CHARACTER SET {$character_set} COLLATE {$collation} {$attributes}";
 348  
 349                  $comma = ',';
 350              }
 351          }
 352  
 353          if(!empty($convert_to_binary))
 354          {
 355              // This converts the columns to UTF-8 while also doing the same for data
 356              $db->write_query("ALTER TABLE {$mybb->input['table']} {$convert_to_binary}");
 357              $db->write_query("ALTER TABLE {$mybb->input['table']} {$convert_to_utf8}");
 358          }
 359  
 360          // Any fulltext indexes to recreate?
 361          foreach($fulltext_to_create as $name => $fields)
 362          {
 363              $db->create_fulltext_index($mybb->input['table'], $fields, $name);
 364          }
 365  
 366          $db->set_table_prefix($old_table_prefix);
 367  
 368          $plugins->run_hooks("admin_tools_system_health_utf8_conversion_commit");
 369  
 370          // Log admin action
 371          log_admin_action($mybb->input['table']);
 372  
 373          flash_message($lang->sprintf($lang->success_table_converted, $mybb->input['table']), 'success');
 374  
 375          if($mybb->input['do'] == "all")
 376          {
 377              $old_table_prefix = $db->table_prefix;
 378              $db->set_table_prefix('');
 379  
 380              $tables = $db->list_tables($mybb->config['database']['database']);
 381              foreach($tables as $key => $tablename)
 382              {
 383                  if(substr($tablename, 0, strlen(TABLE_PREFIX)) == TABLE_PREFIX)
 384                  {
 385                      $table = $db->show_create_table($tablename);
 386                      preg_match("#CHARSET=([a-zA-Z0-9_]+)\s?#i", $table, $matches);
 387                      if(empty($mybb->input['mb4']) && (fetch_iconv_encoding($matches[1]) == 'utf-8' || $matches[1] == 'utf8mb4') && $mybb->input['table'] != $tablename)
 388                      {
 389                          continue;
 390                      }
 391                      elseif(!empty($mybb->input['mb4']) && fetch_iconv_encoding($matches[1]) != 'utf-8' && $mybb->input['table'] != $tablename)
 392                      {
 393                          continue;
 394                      }
 395  
 396                      $mybb_tables[$key] = $tablename;
 397                  }
 398              }
 399  
 400              asort($mybb_tables);
 401              reset($mybb_tables);
 402  
 403              $is_next = false;
 404              $nexttable = "";
 405  
 406              foreach($mybb_tables as $key => $tablename)
 407              {
 408                  if($is_next == true)
 409                  {
 410                      $nexttable = $tablename;
 411                      break;
 412                  }
 413                  else if($mybb->input['table'] == $tablename)
 414                  {
 415                      $is_next = true;
 416                  }
 417              }
 418  
 419              $db->set_table_prefix($old_table_prefix);
 420  
 421              if($nexttable)
 422              {
 423                  $nexttable = $db->escape_string($nexttable);
 424                  $mb4 = '';
 425                  if(!empty($mybb->input['mb4']))
 426                  {
 427                      $mb4 = "&amp;mb4=1";
 428                  }
 429                  admin_redirect("index.php?module=tools-system_health&action=utf8_conversion&do=all&table={$nexttable}{$mb4}");
 430                  exit;
 431              }
 432          }
 433  
 434          admin_redirect("index.php?module=tools-system_health&action=utf8_conversion");
 435  
 436          exit;
 437      }
 438  
 439      if(!empty($mybb->input['table']) || $mybb->input['do'] == "all")
 440      {
 441          if(!empty($mybb->input['mb4']) && version_compare($db->get_version(), '5.5.3', '<'))
 442          {
 443              flash_message($lang->error_utf8mb4_version, 'error');
 444              admin_redirect("index.php?module=tools-system_health&action=utf8_conversion");
 445          }
 446  
 447          $old_table_prefix = $db->table_prefix;
 448          $db->set_table_prefix('');
 449  
 450          if($mybb->input['do'] != "all" && !$db->table_exists($db->escape_string($mybb->input['table'])))
 451          {
 452              $db->set_table_prefix($old_table_prefix);
 453              flash_message($lang->error_invalid_table, 'error');
 454              admin_redirect("index.php?module=tools-system_health&action=utf8_conversion");
 455          }
 456  
 457          if($mybb->input['do'] == "all")
 458          {
 459              $tables = $db->list_tables($mybb->config['database']['database']);
 460              foreach($tables as $key => $tablename)
 461              {
 462                  if(substr($tablename, 0, strlen(TABLE_PREFIX)) == TABLE_PREFIX)
 463                  {
 464                      $table = $db->show_create_table($tablename);
 465                      preg_match("#CHARSET=([a-zA-Z0-9_]+)\s?#i", $table, $matches);
 466                      if(empty($mybb->input['mb4']) && (fetch_iconv_encoding($matches[1]) == 'utf-8' || $matches[1] == 'utf8mb4'))
 467                      {
 468                          continue;
 469                      }
 470                      elseif(!empty($mybb->input['mb4']) && fetch_iconv_encoding($matches[1]) != 'utf-8')
 471                      {
 472                          continue;
 473                      }
 474                      $mybb_tables[$key] = $tablename;
 475                  }
 476              }
 477  
 478              if(is_array($mybb_tables))
 479              {
 480                  asort($mybb_tables);
 481                  reset($mybb_tables);
 482                  $nexttable = current($mybb_tables);
 483                  $table = $db->show_create_table($db->escape_string($nexttable));
 484                  $mybb->input['table'] = $nexttable;
 485              }
 486              else
 487              {
 488                  $db->set_table_prefix($old_table_prefix);
 489                  flash_message($lang->success_all_tables_already_converted, 'success');
 490                  admin_redirect("index.php?module=tools-system_health");
 491              }
 492          }
 493          else
 494          {
 495              $table = $db->show_create_table($db->escape_string($mybb->input['table']));
 496          }
 497  
 498          $page->add_breadcrumb_item($lang->utf8_conversion, "index.php?module=tools-system_health&amp;action=utf8_conversion");
 499  
 500          $db->set_table_prefix($old_table_prefix);
 501  
 502          $page->output_header($lang->system_health." - ".$lang->utf8_conversion);
 503  
 504          $sub_tabs['system_health'] = array(
 505              'title' => $lang->system_health,
 506              'link' => "index.php?module=tools-system_health",
 507              'description' => $lang->system_health_desc
 508          );
 509  
 510          $sub_tabs['utf8_conversion'] = array(
 511              'title' => $lang->utf8_conversion,
 512              'link' => "index.php?module=tools-system_health&amp;action=utf8_conversion",
 513              'description' => $lang->utf8_conversion_desc2
 514          );
 515  
 516          $page->output_nav_tabs($sub_tabs, 'utf8_conversion');
 517  
 518          $old_table_prefix = $db->table_prefix;
 519          $db->set_table_prefix('');
 520  
 521                  preg_match("#CHARSET=([a-zA-Z0-9_]+)\s?#i", $table, $matches);
 522          $charset = $matches[1];
 523  
 524          $mb4 = '';
 525          if(!empty($mybb->input['mb4']))
 526          {
 527              $mb4 = "&amp;mb4=1";
 528          }
 529  
 530          $form = new Form("index.php?module=tools-system_health&amp;action=utf8_conversion{$mb4}", "post", "utf8_conversion");
 531          echo $form->generate_hidden_field("table", $mybb->input['table']);
 532  
 533          if($mybb->input['do'] == "all")
 534          {
 535              echo $form->generate_hidden_field("do", "all");
 536          }
 537  
 538          $table = new Table;
 539  
 540          if(!empty($mybb->input['mb4']))
 541          {
 542              $table->construct_cell("<strong>".$lang->sprintf($lang->convert_all_to_utf8mb4, $charset)."</strong>");
 543              $lang->notice_process_long_time .= "<br /><br /><strong>{$lang->notice_mb4_warning}</strong>";
 544          }
 545          else
 546          {
 547              if($mybb->input['do'] == "all")
 548              {
 549                  $table->construct_cell("<strong>".$lang->sprintf($lang->convert_all_to_utf, $charset)."</strong>");
 550              }
 551              else
 552              {
 553                  $table->construct_cell("<strong>".$lang->sprintf($lang->convert_to_utf8, $mybb->input['table'], $charset)."</strong>");
 554              }
 555          }
 556  
 557          $table->construct_row();
 558  
 559          $table->construct_cell($lang->notice_process_long_time);
 560          $table->construct_row();
 561  
 562          if($mybb->input['do'] == "all")
 563          {
 564              $table->output($lang->convert_tables);
 565              $buttons[] = $form->generate_submit_button($lang->convert_database_tables);
 566          }
 567          else
 568          {
 569              $table->output($lang->convert_table.": {$mybb->input['table']}");
 570              $buttons[] = $form->generate_submit_button($lang->convert_database_table);
 571          }
 572  
 573          $form->output_submit_wrapper($buttons);
 574  
 575          $form->end();
 576  
 577          $db->set_table_prefix($old_table_prefix);
 578  
 579          $page->output_footer();
 580  
 581          exit;
 582      }
 583  
 584      if(!$mybb->config['database']['encoding'])
 585      {
 586          flash_message($lang->error_db_encoding_not_set, 'error');
 587          admin_redirect("index.php?module=tools-system_health");
 588      }
 589  
 590      $tables = $db->list_tables($mybb->config['database']['database']);
 591  
 592      $old_table_prefix = $db->table_prefix;
 593      $db->set_table_prefix('');
 594  
 595      $encodings = array();
 596  
 597      foreach($tables as $key => $tablename)
 598      {
 599          if(substr($tablename, 0, strlen($old_table_prefix)) == $old_table_prefix)
 600          {
 601              $table = $db->show_create_table($tablename);
 602              preg_match("#CHARSET=([a-zA-Z0-9_]+)\s?#i", $table, $matches);
 603              $encodings[$key] = fetch_iconv_encoding($matches[1]);
 604              $mybb_tables[$key] = $tablename;
 605          }
 606      }
 607  
 608      $db->set_table_prefix($old_table_prefix);
 609  
 610      $page->add_breadcrumb_item($lang->utf8_conversion, "index.php?module=tools-system_health&amp;action=utf8_conversion");
 611  
 612      $page->output_header($lang->system_health." - ".$lang->utf8_conversion);
 613  
 614      $page->output_nav_tabs($sub_tabs, 'utf8_conversion');
 615  
 616      asort($mybb_tables);
 617  
 618      $unique = array_unique($encodings);
 619  
 620      $convert_utf8 = $convert_utf8mb4 = false;
 621      foreach($unique as $encoding)
 622      {
 623          if($encoding == 'utf-8')
 624          {
 625              $convert_utf8mb4 = true;
 626          }
 627          elseif($encoding != 'utf8mb4')
 628          {
 629              $convert_utf8 = true;
 630          }
 631      }
 632  
 633      if(count($unique) > 1)
 634      {
 635          $page->output_error("<p><em>{$lang->warning_multiple_encodings}</em></p>");
 636      }
 637  
 638      if(in_array('utf8mb4', $unique) && $mybb->config['database']['encoding'] != 'utf8mb4')
 639      {
 640          $page->output_error("<p><em>{$lang->warning_utf8mb4_config}</em></p>");
 641      }
 642  
 643      $table = new Table;
 644      $table->construct_header($lang->table);
 645      $table->construct_header($lang->status_utf8, array("class" => "align_center"));
 646      $table->construct_header($lang->status_utf8mb4, array("class" => "align_center"));
 647  
 648      $all_utf8 = $all_utf8mb4 = '-';
 649      if($convert_utf8)
 650      {
 651          $all_utf8 = "<strong><a href=\"index.php?module=tools-system_health&amp;action=utf8_conversion&amp;do=all\">{$lang->convert_all}</a></strong>";
 652      }
 653      if($convert_utf8mb4)
 654      {
 655          $all_utf8mb4 = "<strong><a href=\"index.php?module=tools-system_health&amp;action=utf8_conversion&amp;do=all&amp;mb4=1\">{$lang->convert_all}</a></strong>";
 656      }
 657      $table->construct_cell("<strong>{$lang->all_tables}</strong>");
 658      $table->construct_cell($all_utf8, array("class" => "align_center", 'width' => '15%'));
 659      $table->construct_cell($all_utf8mb4, array("class" => "align_center", 'width' => '25%'));
 660      $table->construct_row();
 661  
 662      $db_version = $db->get_version();
 663  
 664      foreach($mybb_tables as $key => $tablename)
 665      {
 666          if($encodings[$key] != 'utf-8' && $encodings[$key] != 'utf8mb4')
 667          {
 668              $status = "<a href=\"index.php?module=tools-system_health&amp;action=utf8_conversion&amp;table={$tablename}\" style=\"background: url(styles/{$page->style}/images/icons/cross.png) no-repeat; padding-left: 20px;\">{$lang->convert_now}</a>";
 669          }
 670          else
 671          {
 672              $status = "<img src=\"styles/{$page->style}/images/icons/tick.png\" alt=\"{$lang->ok}\" />";
 673          }
 674          if(version_compare($db_version, '5.5.3', '<'))
 675          {
 676              $utf8mb4 = $lang->not_available;
 677          }
 678          elseif($encodings[$key] == 'utf8mb4')
 679          {
 680              $utf8mb4 = "<img src=\"styles/{$page->style}/images/icons/tick.png\" alt=\"{$lang->ok}\" />";
 681          }
 682          elseif($encodings[$key] == 'utf-8')
 683          {
 684              $utf8mb4 = "<a href=\"index.php?module=tools-system_health&amp;action=utf8_conversion&amp;table={$tablename}&amp;mb4=1\" style=\"background: url(styles/{$page->style}/images/icons/cross.png) no-repeat; padding-left: 20px;\">{$lang->convert_now}</a>";
 685          }
 686          else
 687          {
 688              $utf8mb4 = "-";
 689          }
 690          $table->construct_cell("<strong>{$tablename}</strong>");
 691          $table->construct_cell($status, array("class" => "align_center", 'width' => '15%'));
 692          $table->construct_cell($utf8mb4, array("class" => "align_center", 'width' => '25%'));
 693          $table->construct_row();
 694      }
 695  
 696      $table->output("<div>{$lang->utf8_conversion}</div>");
 697  
 698      $page->output_footer();
 699  }
 700  
 701  if(!$mybb->input['action'])
 702  {
 703      $page->output_header($lang->system_health);
 704  
 705      $plugins->run_hooks("admin_tools_system_health_start");
 706  
 707      $page->output_nav_tabs($sub_tabs, 'system_health');
 708  
 709      $table = new Table;
 710      $table->construct_header($lang->totals, array("colspan" => 2));
 711      $table->construct_header($lang->attachments, array("colspan" => 2));
 712  
 713      $query = $db->simple_select("attachments", "COUNT(*) AS numattachs, SUM(filesize) as spaceused, SUM(downloads*filesize) as bandwidthused", "visible='1' AND pid > '0'");
 714      $attachs = $db->fetch_array($query);
 715  
 716      $table->construct_cell("<strong>{$lang->total_database_size}</strong>", array('width' => '25%'));
 717      $table->construct_cell(get_friendly_size($db->fetch_size()), array('width' => '25%'));
 718      $table->construct_cell("<strong>{$lang->attachment_space_used}</strong>", array('width' => '200'));
 719      $table->construct_cell(get_friendly_size((int)$attachs['spaceused']), array('width' => '200'));
 720      $table->construct_row();
 721  
 722      if($attachs['spaceused'] > 0)
 723      {
 724          $attach_average_size = round($attachs['spaceused']/$attachs['numattachs']);
 725          $bandwidth_average_usage = round($attachs['bandwidthused']);
 726      }
 727      else
 728      {
 729          $attach_average_size = 0;
 730          $bandwidth_average_usage = 0;
 731      }
 732  
 733      $table->construct_cell("<strong>{$lang->total_cache_size}</strong>", array('width' => '25%'));
 734      $table->construct_cell(get_friendly_size($cache->size_of()), array('width' => '25%'));
 735      $table->construct_cell("<strong>{$lang->estimated_attachment_bandwidth_usage}</strong>", array('width' => '25%'));
 736      $table->construct_cell(get_friendly_size($bandwidth_average_usage), array('width' => '25%'));
 737      $table->construct_row();
 738  
 739  
 740      $table->construct_cell("<strong>{$lang->max_upload_post_size}</strong>", array('width' => '200'));
 741      $table->construct_cell(@ini_get('upload_max_filesize').' / '.@ini_get('post_max_size'), array('width' => '200'));
 742      $table->construct_cell("<strong>{$lang->average_attachment_size}</strong>", array('width' => '25%'));
 743      $table->construct_cell(get_friendly_size($attach_average_size), array('width' => '25%'));
 744      $table->construct_row();
 745  
 746      $table->output($lang->stats);
 747  
 748      $table->construct_header($lang->task);
 749      $table->construct_header($lang->run_time, array("width" => 200, "class" => "align_center"));
 750  
 751      $task_cache = $cache->read("tasks");
 752      $nextrun = $task_cache['nextrun'];
 753  
 754      $query = $db->simple_select("tasks", "*", "nextrun >= '{$nextrun}' AND enabled='1'", array("order_by" => "nextrun", "order_dir" => "asc", 'limit' => 3));
 755      while($task = $db->fetch_array($query))
 756      {
 757          $task['title'] = htmlspecialchars_uni($task['title']);
 758          $next_run = my_date('normal', $task['nextrun'], "", 2);
 759          $table->construct_cell("<strong>{$task['title']}</strong>");
 760          $table->construct_cell($next_run, array("class" => "align_center"));
 761  
 762          $table->construct_row();
 763      }
 764  
 765      if($table->num_rows() == 0)
 766      {
 767          $table->construct_cell($lang->no_tasks, array('colspan' => 2));
 768          $table->construct_row();
 769      }
 770  
 771      $table->output($lang->next_3_tasks);
 772  
 773      if(isset($mybb->admin['permissions']['tools']['backupdb']) && $mybb->admin['permissions']['tools']['backupdb'] == 1)
 774      {
 775          $backups = array();
 776          $dir = MYBB_ADMIN_DIR.'backups/';
 777          $handle = opendir($dir);
 778          while(($file = readdir($handle)) !== false)
 779          {
 780              if(filetype(MYBB_ADMIN_DIR.'backups/'.$file) == 'file')
 781              {
 782                  $ext = get_extension($file);
 783                  if($ext == 'gz' || $ext == 'sql')
 784                  {
 785                      $backups[@filemtime(MYBB_ADMIN_DIR.'backups/'.$file)] = array(
 786                          "file" => $file,
 787                          "time" => @filemtime(MYBB_ADMIN_DIR.'backups/'.$file),
 788                          "type" => $ext
 789                      );
 790                  }
 791              }
 792          }
 793  
 794          $count = count($backups);
 795          krsort($backups);
 796  
 797          $table = new Table;
 798          $table->construct_header($lang->name);
 799          $table->construct_header($lang->backup_time, array("width" => 200, "class" => "align_center"));
 800  
 801          $backupscnt = 0;
 802          foreach($backups as $backup)
 803          {
 804              ++$backupscnt;
 805  
 806              if($backupscnt == 4)
 807              {
 808                  break;
 809              }
 810  
 811              $time = "-";
 812              if($backup['time'])
 813              {
 814                  $time = my_date('relative', $backup['time']);
 815              }
 816  
 817              $table->construct_cell("<a href=\"index.php?module=tools-backupdb&amp;action=dlbackup&amp;file={$backup['file']}\">{$backup['file']}</a>");
 818              $table->construct_cell($time, array("class" => "align_center"));
 819              $table->construct_row();
 820          }
 821  
 822          if($count == 0)
 823          {
 824              $table->construct_cell($lang->no_backups, array('colspan' => 2));
 825              $table->construct_row();
 826          }
 827  
 828          $table->output($lang->existing_db_backups);
 829      }
 830  
 831      if(is_writable(MYBB_ROOT.'inc/settings.php'))
 832      {
 833          $message_settings = "<span style=\"color: green;\">{$lang->writable}</span>";
 834      }
 835      else
 836      {
 837          $message_settings = "<strong><span style=\"color: #C00\">{$lang->not_writable}</span></strong><br />{$lang->please_chmod_777}";
 838          ++$errors;
 839      }
 840  
 841      if(is_writable(MYBB_ROOT.'inc/config.php'))
 842      {
 843          $message_config = "<span style=\"color: green;\">{$lang->writable}</span>";
 844      }
 845      else
 846      {
 847          $message_config = "<strong><span style=\"color: #C00\">{$lang->not_writable}</span></strong><br />{$lang->please_chmod_777}";
 848          ++$errors;
 849      }
 850  
 851      $uploadspath_abs = mk_path_abs($mybb->settings['uploadspath']);
 852      if(is_writable($uploadspath_abs))
 853      {
 854          $message_upload = "<span style=\"color: green;\">{$lang->writable}</span>";
 855      }
 856      else
 857      {
 858          $message_upload = "<strong><span style=\"color: #C00\">{$lang->not_writable}</span></strong><br />{$lang->please_chmod_777}";
 859          ++$errors;
 860      }
 861  
 862      $avataruploadpath_abs = mk_path_abs($mybb->settings['avataruploadpath']);
 863      if(is_writable($avataruploadpath_abs))
 864      {
 865          $message_avatar = "<span style=\"color: green;\">{$lang->writable}</span>";
 866      }
 867      else
 868      {
 869          $message_avatar = "<strong><span style=\"color: #C00\">{$lang->not_writable}</span></strong><br />{$lang->please_chmod_777}";
 870          ++$errors;
 871      }
 872  
 873      if(is_writable(MYBB_ROOT.'inc/languages/'))
 874      {
 875          $message_language = "<span style=\"color: green;\">{$lang->writable}</span>";
 876      }
 877      else
 878      {
 879          $message_language = "<strong><span style=\"color: #C00\">{$lang->not_writable}</span></strong><br />{$lang->please_chmod_777}";
 880          ++$errors;
 881      }
 882  
 883      if(is_writable(MYBB_ROOT.$config['admin_dir'].'/backups/'))
 884      {
 885          $message_backup = "<span style=\"color: green;\">{$lang->writable}</span>";
 886      }
 887      else
 888      {
 889          $message_backup = "<strong><span style=\"color: #C00\">{$lang->not_writable}</span></strong><br />{$lang->please_chmod_777}";
 890          ++$errors;
 891      }
 892  
 893      if(is_writable(MYBB_ROOT.'/cache/'))
 894      {
 895          $message_cache = "<span style=\"color: green;\">{$lang->writable}</span>";
 896      }
 897      else
 898      {
 899          $message_cache = "<strong><span style=\"color: #C00\">{$lang->not_writable}</span></strong><br />{$lang->please_chmod_777}";
 900          ++$errors;
 901      }
 902  
 903      if(is_writable(MYBB_ROOT.'/cache/themes/'))
 904      {
 905          $message_themes = "<span style=\"color: green;\">{$lang->writable}</span>";
 906      }
 907      else
 908      {
 909          $message_themes = "<strong><span style=\"color: #C00\">{$lang->not_writable}</span></strong><br />{$lang->please_chmod_777}";
 910          ++$errors;
 911      }
 912  
 913      if($errors)
 914      {
 915          $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>");
 916      }
 917      else
 918      {
 919          $page->output_success("<p><em>{$lang->success_chmod}</em></p>");
 920      }
 921  
 922      $table = new Table;
 923      $table->construct_header($lang->file);
 924      $table->construct_header($lang->location, array("colspan" => 2, 'width' => 250));
 925  
 926      $table->construct_cell("<strong>{$lang->config_file}</strong>");
 927      $table->construct_cell("./inc/config.php");
 928      $table->construct_cell($message_config);
 929      $table->construct_row();
 930  
 931      $table->construct_cell("<strong>{$lang->settings_file}</strong>");
 932      $table->construct_cell("./inc/settings.php");
 933      $table->construct_cell($message_settings);
 934      $table->construct_row();
 935  
 936      $table->construct_cell("<strong>{$lang->file_upload_dir}</strong>");
 937      $table->construct_cell($mybb->settings['uploadspath']);
 938      $table->construct_cell($message_upload);
 939      $table->construct_row();
 940  
 941      $table->construct_cell("<strong>{$lang->avatar_upload_dir}</strong>");
 942      $table->construct_cell($mybb->settings['avataruploadpath']);
 943      $table->construct_cell($message_avatar);
 944      $table->construct_row();
 945  
 946      $table->construct_cell("<strong>{$lang->language_files}</strong>");
 947      $table->construct_cell("./inc/languages");
 948      $table->construct_cell($message_language);
 949      $table->construct_row();
 950  
 951      $table->construct_cell("<strong>{$lang->backup_dir}</strong>");
 952      $table->construct_cell('./'.$config['admin_dir'].'/backups');
 953      $table->construct_cell($message_backup);
 954      $table->construct_row();
 955  
 956      $table->construct_cell("<strong>{$lang->cache_dir}</strong>");
 957      $table->construct_cell('./cache');
 958      $table->construct_cell($message_cache);
 959      $table->construct_row();
 960  
 961      $table->construct_cell("<strong>{$lang->themes_dir}</strong>");
 962      $table->construct_cell('./cache/themes');
 963      $table->construct_cell($message_themes);
 964      $table->construct_row();
 965  
 966      $plugins->run_hooks("admin_tools_system_health_output_chmod_list");
 967  
 968      $table->output($lang->chmod_files_and_dirs);
 969  
 970      $page->output_footer();
 971  }


2005 - 2021 © MyBB.de | Alle Rechte vorbehalten! | Sponsor: netcup Cross-referenced by PHPXref