[ Index ]

PHP Cross Reference of MyBB 1.8.40

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


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