[ Index ]

PHP Cross Reference of MyBB 1.8.37

title

Body

[close]

/install/ -> index.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  @set_time_limit(0);
  12  
  13  define('MYBB_ROOT', dirname(dirname(__FILE__))."/");
  14  define("INSTALL_ROOT", dirname(__FILE__)."/");
  15  define("TIME_NOW", time());
  16  define("IN_MYBB", 1);
  17  define("IN_INSTALL", 1);
  18  
  19  if(function_exists('date_default_timezone_set') && !ini_get('date.timezone'))
  20  {
  21      date_default_timezone_set('GMT');
  22  }
  23  
  24  require_once  MYBB_ROOT.'inc/class_error.php';
  25  $error_handler = new errorHandler();
  26  
  27  require_once  MYBB_ROOT.'inc/class_core.php';
  28  $mybb = new MyBB;
  29  
  30  // Include the files necessary for installation
  31  require_once  MYBB_ROOT.'inc/class_timers.php';
  32  require_once  MYBB_ROOT.'inc/functions.php';
  33  
  34  $admin_dir = "admin";
  35  
  36  // Perform a check if MyBB is already installed or not
  37  $installed = false;
  38  if(file_exists(MYBB_ROOT."/inc/config.php"))
  39  {
  40      require MYBB_ROOT."/inc/config.php";
  41      if(isset($config) && is_array($config))
  42      {
  43          $installed = true;
  44          if(isset($config['admindir']))
  45          {
  46              $admin_dir = $config['admindir'];
  47          }
  48          else if(isset($config['admin_dir']))
  49          {
  50              $admin_dir = $config['admin_dir'];
  51          }
  52      }
  53  }
  54  
  55  require_once  MYBB_ROOT.'inc/functions_user.php';
  56  require_once  MYBB_ROOT.'inc/class_language.php';
  57  $lang = new MyLanguage();
  58  $lang->set_path(INSTALL_ROOT.'resources');
  59  $lang->load('language');
  60  
  61  // Load DB interface
  62  require_once  MYBB_ROOT."inc/db_base.php";
  63  require_once  MYBB_ROOT."inc/AbstractPdoDbDriver.php";
  64  
  65  // Prevent any shut down functions from running
  66  $done_shutdown = 1;
  67  
  68  // Include the necessary constants for installation
  69  $grouppermignore = array('gid', 'type', 'title', 'description', 'namestyle', 'usertitle', 'stars', 'starimage', 'image');
  70  $groupzerogreater = array('pmquota', 'maxpmrecipients', 'maxreputationsday', 'attachquota', 'maxemails', 'maxwarningsday', 'maxposts', 'edittimelimit', 'canusesigxposts', 'maxreputationsperuser', 'maxreputationsperthread', 'emailfloodtime');
  71  $displaygroupfields = array('title', 'description', 'namestyle', 'usertitle', 'stars', 'starimage', 'image');
  72  $fpermfields = array('canview', 'canviewthreads', 'candlattachments', 'canpostthreads', 'canpostreplys', 'canpostattachments', 'canratethreads', 'caneditposts', 'candeleteposts', 'candeletethreads', 'caneditattachments', 'canpostpolls', 'canvotepolls', 'cansearch', 'modposts', 'modthreads', 'modattachments', 'mod_edit_posts');
  73  
  74  // Include the installation resources
  75  require_once  INSTALL_ROOT.'resources/output.php';
  76  $output = new installerOutput;
  77  
  78  $dboptions = array();
  79  
  80  if(function_exists('mysqli_connect'))
  81  {
  82      $dboptions['mysqli'] = array(
  83          'class' => 'DB_MySQLi',
  84          'title' => 'MySQL Improved',
  85          'short_title' => 'MySQLi',
  86          'structure_file' => 'mysql_db_tables.php',
  87          'population_file' => 'mysql_db_inserts.php'
  88      );
  89  }
  90  
  91  if(function_exists('mysql_connect'))
  92  {
  93      $dboptions['mysql'] = array(
  94          'class' => 'DB_MySQL',
  95          'title' => 'MySQL',
  96          'short_title' => 'MySQL',
  97          'structure_file' => 'mysql_db_tables.php',
  98          'population_file' => 'mysql_db_inserts.php'
  99      );
 100  }
 101  
 102  if(function_exists('pg_connect'))
 103  {
 104      $dboptions['pgsql'] = array(
 105          'class' => 'DB_PgSQL',
 106          'title' => 'PostgreSQL',
 107          'short_title' => 'PostgreSQL',
 108          'structure_file' => 'pgsql_db_tables.php',
 109          'population_file' => 'pgsql_db_inserts.php'
 110      );
 111  }
 112  
 113  if(class_exists('PDO'))
 114  {
 115      $supported_dbs = PDO::getAvailableDrivers();
 116      if(in_array('sqlite', $supported_dbs))
 117      {
 118          $dboptions['sqlite'] = array(
 119              'class' => 'DB_SQLite',
 120              'title' => 'SQLite 3',
 121              'short_title' => 'SQLite',
 122              'structure_file' => 'sqlite_db_tables.php',
 123              'population_file' => 'pgsql_db_inserts.php'
 124          );
 125      }
 126  
 127      if (in_array('pgsql', $supported_dbs)) {
 128          $dboptions['pgsql_pdo'] = array(
 129              'class' => 'PostgresPdoDbDriver',
 130              'title' => 'PostgreSQL (PDO)',
 131              'short_title' => 'PostgreSQL (PDO)',
 132              'structure_file' => 'pgsql_db_tables.php',
 133              'population_file' => 'pgsql_db_inserts.php'
 134          );
 135      }
 136  
 137      if (in_array('mysql', $supported_dbs)) {
 138          $dboptions['mysql_pdo'] = array(
 139              'class' => 'MysqlPdoDbDriver',
 140              'title' => 'MySQL (PDO)',
 141              'short_title' => 'MySQL (PDO)',
 142              'structure_file' => 'mysql_db_tables.php',
 143              'population_file' => 'mysql_db_inserts.php'
 144          );
 145      }
 146  }
 147  
 148  if(file_exists('lock') && $mybb->dev_mode != true)
 149  {
 150      $output->print_error($lang->locked);
 151  }
 152  else if($installed == true && empty($mybb->input['action']))
 153  {
 154      $output->print_header($lang->already_installed, "errormsg", 0);
 155      echo $lang->sprintf($lang->mybb_already_installed, $mybb->version);
 156      $output->print_footer();
 157  }
 158  else
 159  {
 160      $output->steps = array(
 161          'intro' => $lang->welcome,
 162          'license' => $lang->license_agreement,
 163          'requirements_check' => $lang->req_check,
 164          'database_info' => $lang->db_config,
 165          'create_tables' => $lang->table_creation,
 166          'populate_tables' => $lang->data_insertion,
 167          'templates' => $lang->theme_install,
 168          'configuration' => $lang->board_config,
 169          'adminuser' => $lang->admin_user,
 170          'final' => $lang->finish_setup,
 171      );
 172  
 173      switch($mybb->get_input('action'))
 174      {
 175          case 'license':
 176              license_agreement();
 177              break;
 178          case 'requirements_check':
 179              requirements_check();
 180              break;
 181          case 'database_info':
 182              database_info();
 183              break;
 184          case 'create_tables':
 185              create_tables();
 186              break;
 187          case 'populate_tables':
 188              populate_tables();
 189              break;
 190          case 'templates':
 191              insert_templates();
 192              break;
 193          case 'configuration':
 194              configure();
 195              break;
 196          case 'adminuser':
 197              create_admin_user();
 198              break;
 199          case 'final':
 200              install_done();
 201              break;
 202          default:
 203              $mybb->input['action'] = 'intro';
 204              intro();
 205              break;
 206      }
 207  }
 208  
 209  /**
 210   * Welcome page
 211   */
 212  function intro()
 213  {
 214      global $output, $mybb, $lang;
 215  
 216      $output->print_header();
 217      if(strpos(strtolower(get_current_location('', '', true)), '/upload/') !== false)
 218      {
 219          echo $lang->sprintf($lang->mybb_incorrect_folder);
 220      }
 221      echo $lang->sprintf($lang->welcome_step, $mybb->version);
 222      $output->print_footer('license');
 223  }
 224  
 225  /**
 226   * Show the license agreement
 227   */
 228  function license_agreement()
 229  {
 230      global $output, $lang, $mybb;
 231  
 232      ob_start();
 233      $output->print_header($lang->license_agreement, 'license');
 234  
 235      if($mybb->get_input('allow_anonymous_info', MyBB::INPUT_INT) == 1)
 236      {
 237          require_once  MYBB_ROOT."inc/functions_serverstats.php";
 238          $build_server_stats = build_server_stats(1, '', $mybb->version_code);
 239  
 240          if($build_server_stats['info_sent_success'] == false)
 241          {
 242              echo $build_server_stats['info_image'];
 243          }
 244      }
 245      ob_end_flush();
 246  
 247      $license = <<<EOF
 248  <pre>
 249                     GNU LESSER GENERAL PUBLIC LICENSE
 250                         Version 3, 29 June 2007
 251  
 252   Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
 253   Everyone is permitted to copy and distribute verbatim copies
 254   of this license document, but changing it is not allowed.
 255  
 256  
 257    This version of the GNU Lesser General Public License incorporates
 258  the terms and conditions of version 3 of the GNU General Public
 259  License, supplemented by the additional permissions listed below.
 260  
 261    0. Additional Definitions.
 262  
 263    As used herein, "this License" refers to version 3 of the GNU Lesser
 264  General Public License, and the "GNU GPL" refers to version 3 of the GNU
 265  General Public License.
 266  
 267    "The Library" refers to a covered work governed by this License,
 268  other than an Application or a Combined Work as defined below.
 269  
 270    An "Application" is any work that makes use of an interface provided
 271  by the Library, but which is not otherwise based on the Library.
 272  Defining a subclass of a class defined by the Library is deemed a mode
 273  of using an interface provided by the Library.
 274  
 275    A "Combined Work" is a work produced by combining or linking an
 276  Application with the Library.  The particular version of the Library
 277  with which the Combined Work was made is also called the "Linked
 278  Version".
 279  
 280    The "Minimal Corresponding Source" for a Combined Work means the
 281  Corresponding Source for the Combined Work, excluding any source code
 282  for portions of the Combined Work that, considered in isolation, are
 283  based on the Application, and not on the Linked Version.
 284  
 285    The "Corresponding Application Code" for a Combined Work means the
 286  object code and/or source code for the Application, including any data
 287  and utility programs needed for reproducing the Combined Work from the
 288  Application, but excluding the System Libraries of the Combined Work.
 289  
 290    1. Exception to Section 3 of the GNU GPL.
 291  
 292    You may convey a covered work under sections 3 and 4 of this License
 293  without being bound by section 3 of the GNU GPL.
 294  
 295    2. Conveying Modified Versions.
 296  
 297    If you modify a copy of the Library, and, in your modifications, a
 298  facility refers to a function or data to be supplied by an Application
 299  that uses the facility (other than as an argument passed when the
 300  facility is invoked), then you may convey a copy of the modified
 301  version:
 302  
 303     a) under this License, provided that you make a good faith effort to
 304     ensure that, in the event an Application does not supply the
 305     function or data, the facility still operates, and performs
 306     whatever part of its purpose remains meaningful, or
 307  
 308     b) under the GNU GPL, with none of the additional permissions of
 309     this License applicable to that copy.
 310  
 311    3. Object Code Incorporating Material from Library Header Files.
 312  
 313    The object code form of an Application may incorporate material from
 314  a header file that is part of the Library.  You may convey such object
 315  code under terms of your choice, provided that, if the incorporated
 316  material is not limited to numerical parameters, data structure
 317  layouts and accessors, or small macros, inline functions and templates
 318  (ten or fewer lines in length), you do both of the following:
 319  
 320     a) Give prominent notice with each copy of the object code that the
 321     Library is used in it and that the Library and its use are
 322     covered by this License.
 323  
 324     b) Accompany the object code with a copy of the GNU GPL and this license
 325     document.
 326  
 327    4. Combined Works.
 328  
 329    You may convey a Combined Work under terms of your choice that,
 330  taken together, effectively do not restrict modification of the
 331  portions of the Library contained in the Combined Work and reverse
 332  engineering for debugging such modifications, if you also do each of
 333  the following:
 334  
 335     a) Give prominent notice with each copy of the Combined Work that
 336     the Library is used in it and that the Library and its use are
 337     covered by this License.
 338  
 339     b) Accompany the Combined Work with a copy of the GNU GPL and this license
 340     document.
 341  
 342     c) For a Combined Work that displays copyright notices during
 343     execution, include the copyright notice for the Library among
 344     these notices, as well as a reference directing the user to the
 345     copies of the GNU GPL and this license document.
 346  
 347     d) Do one of the following:
 348  
 349         0) Convey the Minimal Corresponding Source under the terms of this
 350         License, and the Corresponding Application Code in a form
 351         suitable for, and under terms that permit, the user to
 352         recombine or relink the Application with a modified version of
 353         the Linked Version to produce a modified Combined Work, in the
 354         manner specified by section 6 of the GNU GPL for conveying
 355         Corresponding Source.
 356  
 357         1) Use a suitable shared library mechanism for linking with the
 358         Library.  A suitable mechanism is one that (a) uses at run time
 359         a copy of the Library already present on the user's computer
 360         system, and (b) will operate properly with a modified version
 361         of the Library that is interface-compatible with the Linked
 362         Version.
 363  
 364     e) Provide Installation Information, but only if you would otherwise
 365     be required to provide such information under section 6 of the
 366     GNU GPL, and only to the extent that such information is
 367     necessary to install and execute a modified version of the
 368     Combined Work produced by recombining or relinking the
 369     Application with a modified version of the Linked Version. (If
 370     you use option 4d0, the Installation Information must accompany
 371     the Minimal Corresponding Source and Corresponding Application
 372     Code. If you use option 4d1, you must provide the Installation
 373     Information in the manner specified by section 6 of the GNU GPL
 374     for conveying Corresponding Source.)
 375  
 376    5. Combined Libraries.
 377  
 378    You may place library facilities that are a work based on the
 379  Library side by side in a single library together with other library
 380  facilities that are not Applications and are not covered by this
 381  License, and convey such a combined library under terms of your
 382  choice, if you do both of the following:
 383  
 384     a) Accompany the combined library with a copy of the same work based
 385     on the Library, uncombined with any other library facilities,
 386     conveyed under the terms of this License.
 387  
 388     b) Give prominent notice with the combined library that part of it
 389     is a work based on the Library, and explaining where to find the
 390     accompanying uncombined form of the same work.
 391  
 392    6. Revised Versions of the GNU Lesser General Public License.
 393  
 394    The Free Software Foundation may publish revised and/or new versions
 395  of the GNU Lesser General Public License from time to time. Such new
 396  versions will be similar in spirit to the present version, but may
 397  differ in detail to address new problems or concerns.
 398  
 399    Each version is given a distinguishing version number. If the
 400  Library as you received it specifies that a certain numbered version
 401  of the GNU Lesser General Public License "or any later version"
 402  applies to it, you have the option of following the terms and
 403  conditions either of that published version or of any later version
 404  published by the Free Software Foundation. If the Library as you
 405  received it does not specify a version number of the GNU Lesser
 406  General Public License, you may choose any version of the GNU Lesser
 407  General Public License ever published by the Free Software Foundation.
 408  
 409    If the Library as you received it specifies that a proxy can decide
 410  whether future versions of the GNU Lesser General Public License shall
 411  apply, that proxy's public statement of acceptance of any version is
 412  permanent authorization for you to choose that version for the
 413  Library.
 414  
 415                      GNU GENERAL PUBLIC LICENSE
 416                         Version 3, 29 June 2007
 417  
 418   Copyright (C) 2007 Free Software Foundation, Inc. &lt;http://fsf.org/&gt;
 419   Everyone is permitted to copy and distribute verbatim copies
 420   of this license document, but changing it is not allowed.
 421  
 422                              Preamble
 423  
 424    The GNU General Public License is a free, copyleft license for
 425  software and other kinds of works.
 426  
 427    The licenses for most software and other practical works are designed
 428  to take away your freedom to share and change the works.  By contrast,
 429  the GNU General Public License is intended to guarantee your freedom to
 430  share and change all versions of a program--to make sure it remains free
 431  software for all its users.  We, the Free Software Foundation, use the
 432  GNU General Public License for most of our software; it applies also to
 433  any other work released this way by its authors.  You can apply it to
 434  your programs, too.
 435  
 436    When we speak of free software, we are referring to freedom, not
 437  price.  Our General Public Licenses are designed to make sure that you
 438  have the freedom to distribute copies of free software (and charge for
 439  them if you wish), that you receive source code or can get it if you
 440  want it, that you can change the software or use pieces of it in new
 441  free programs, and that you know you can do these things.
 442  
 443    To protect your rights, we need to prevent others from denying you
 444  these rights or asking you to surrender the rights.  Therefore, you have
 445  certain responsibilities if you distribute copies of the software, or if
 446  you modify it: responsibilities to respect the freedom of others.
 447  
 448    For example, if you distribute copies of such a program, whether
 449  gratis or for a fee, you must pass on to the recipients the same
 450  freedoms that you received.  You must make sure that they, too, receive
 451  or can get the source code.  And you must show them these terms so they
 452  know their rights.
 453  
 454    Developers that use the GNU GPL protect your rights with two steps:
 455  (1) assert copyright on the software, and (2) offer you this License
 456  giving you legal permission to copy, distribute and/or modify it.
 457  
 458    For the developers' and authors' protection, the GPL clearly explains
 459  that there is no warranty for this free software.  For both users' and
 460  authors' sake, the GPL requires that modified versions be marked as
 461  changed, so that their problems will not be attributed erroneously to
 462  authors of previous versions.
 463  
 464    Some devices are designed to deny users access to install or run
 465  modified versions of the software inside them, although the manufacturer
 466  can do so.  This is fundamentally incompatible with the aim of
 467  protecting users' freedom to change the software.  The systematic
 468  pattern of such abuse occurs in the area of products for individuals to
 469  use, which is precisely where it is most unacceptable.  Therefore, we
 470  have designed this version of the GPL to prohibit the practice for those
 471  products.  If such problems arise substantially in other domains, we
 472  stand ready to extend this provision to those domains in future versions
 473  of the GPL, as needed to protect the freedom of users.
 474  
 475    Finally, every program is threatened constantly by software patents.
 476  States should not allow patents to restrict development and use of
 477  software on general-purpose computers, but in those that do, we wish to
 478  avoid the special danger that patents applied to a free program could
 479  make it effectively proprietary.  To prevent this, the GPL assures that
 480  patents cannot be used to render the program non-free.
 481  
 482    The precise terms and conditions for copying, distribution and
 483  modification follow.
 484  
 485                         TERMS AND CONDITIONS
 486  
 487    0. Definitions.
 488  
 489    "This License" refers to version 3 of the GNU General Public License.
 490  
 491    "Copyright" also means copyright-like laws that apply to other kinds of
 492  works, such as semiconductor masks.
 493  
 494    "The Program" refers to any copyrightable work licensed under this
 495  License.  Each licensee is addressed as "you".  "Licensees" and
 496  "recipients" may be individuals or organizations.
 497  
 498    To "modify" a work means to copy from or adapt all or part of the work
 499  in a fashion requiring copyright permission, other than the making of an
 500  exact copy.  The resulting work is called a "modified version" of the
 501  earlier work or a work "based on" the earlier work.
 502  
 503    A "covered work" means either the unmodified Program or a work based
 504  on the Program.
 505  
 506    To "propagate" a work means to do anything with it that, without
 507  permission, would make you directly or secondarily liable for
 508  infringement under applicable copyright law, except executing it on a
 509  computer or modifying a private copy.  Propagation includes copying,
 510  distribution (with or without modification), making available to the
 511  public, and in some countries other activities as well.
 512  
 513    To "convey" a work means any kind of propagation that enables other
 514  parties to make or receive copies.  Mere interaction with a user through
 515  a computer network, with no transfer of a copy, is not conveying.
 516  
 517    An interactive user interface displays "Appropriate Legal Notices"
 518  to the extent that it includes a convenient and prominently visible
 519  feature that (1) displays an appropriate copyright notice, and (2)
 520  tells the user that there is no warranty for the work (except to the
 521  extent that warranties are provided), that licensees may convey the
 522  work under this License, and how to view a copy of this License.  If
 523  the interface presents a list of user commands or options, such as a
 524  menu, a prominent item in the list meets this criterion.
 525  
 526    1. Source Code.
 527  
 528    The "source code" for a work means the preferred form of the work
 529  for making modifications to it.  "Object code" means any non-source
 530  form of a work.
 531  
 532    A "Standard Interface" means an interface that either is an official
 533  standard defined by a recognized standards body, or, in the case of
 534  interfaces specified for a particular programming language, one that
 535  is widely used among developers working in that language.
 536  
 537    The "System Libraries" of an executable work include anything, other
 538  than the work as a whole, that (a) is included in the normal form of
 539  packaging a Major Component, but which is not part of that Major
 540  Component, and (b) serves only to enable use of the work with that
 541  Major Component, or to implement a Standard Interface for which an
 542  implementation is available to the public in source code form.  A
 543  "Major Component", in this context, means a major essential component
 544  (kernel, window system, and so on) of the specific operating system
 545  (if any) on which the executable work runs, or a compiler used to
 546  produce the work, or an object code interpreter used to run it.
 547  
 548    The "Corresponding Source" for a work in object code form means all
 549  the source code needed to generate, install, and (for an executable
 550  work) run the object code and to modify the work, including scripts to
 551  control those activities.  However, it does not include the work's
 552  System Libraries, or general-purpose tools or generally available free
 553  programs which are used unmodified in performing those activities but
 554  which are not part of the work.  For example, Corresponding Source
 555  includes interface definition files associated with source files for
 556  the work, and the source code for shared libraries and dynamically
 557  linked subprograms that the work is specifically designed to require,
 558  such as by intimate data communication or control flow between those
 559  subprograms and other parts of the work.
 560  
 561    The Corresponding Source need not include anything that users
 562  can regenerate automatically from other parts of the Corresponding
 563  Source.
 564  
 565    The Corresponding Source for a work in source code form is that
 566  same work.
 567  
 568    2. Basic Permissions.
 569  
 570    All rights granted under this License are granted for the term of
 571  copyright on the Program, and are irrevocable provided the stated
 572  conditions are met.  This License explicitly affirms your unlimited
 573  permission to run the unmodified Program.  The output from running a
 574  covered work is covered by this License only if the output, given its
 575  content, constitutes a covered work.  This License acknowledges your
 576  rights of fair use or other equivalent, as provided by copyright law.
 577  
 578    You may make, run and propagate covered works that you do not
 579  convey, without conditions so long as your license otherwise remains
 580  in force.  You may convey covered works to others for the sole purpose
 581  of having them make modifications exclusively for you, or provide you
 582  with facilities for running those works, provided that you comply with
 583  the terms of this License in conveying all material for which you do
 584  not control copyright.  Those thus making or running the covered works
 585  for you must do so exclusively on your behalf, under your direction
 586  and control, on terms that prohibit them from making any copies of
 587  your copyrighted material outside their relationship with you.
 588  
 589    Conveying under any other circumstances is permitted solely under
 590  the conditions stated below.  Sublicensing is not allowed; section 10
 591  makes it unnecessary.
 592  
 593    3. Protecting Users' Legal Rights From Anti-Circumvention Law.
 594  
 595    No covered work shall be deemed part of an effective technological
 596  measure under any applicable law fulfilling obligations under article
 597  11 of the WIPO copyright treaty adopted on 20 December 1996, or
 598  similar laws prohibiting or restricting circumvention of such
 599  measures.
 600  
 601    When you convey a covered work, you waive any legal power to forbid
 602  circumvention of technological measures to the extent such circumvention
 603  is effected by exercising rights under this License with respect to
 604  the covered work, and you disclaim any intention to limit operation or
 605  modification of the work as a means of enforcing, against the work's
 606  users, your or third parties' legal rights to forbid circumvention of
 607  technological measures.
 608  
 609    4. Conveying Verbatim Copies.
 610  
 611    You may convey verbatim copies of the Program's source code as you
 612  receive it, in any medium, provided that you conspicuously and
 613  appropriately publish on each copy an appropriate copyright notice;
 614  keep intact all notices stating that this License and any
 615  non-permissive terms added in accord with section 7 apply to the code;
 616  keep intact all notices of the absence of any warranty; and give all
 617  recipients a copy of this License along with the Program.
 618  
 619    You may charge any price or no price for each copy that you convey,
 620  and you may offer support or warranty protection for a fee.
 621  
 622    5. Conveying Modified Source Versions.
 623  
 624    You may convey a work based on the Program, or the modifications to
 625  produce it from the Program, in the form of source code under the
 626  terms of section 4, provided that you also meet all of these conditions:
 627  
 628      a) The work must carry prominent notices stating that you modified
 629      it, and giving a relevant date.
 630  
 631      b) The work must carry prominent notices stating that it is
 632      released under this License and any conditions added under section
 633      7.  This requirement modifies the requirement in section 4 to
 634      "keep intact all notices".
 635  
 636      c) You must license the entire work, as a whole, under this
 637      License to anyone who comes into possession of a copy.  This
 638      License will therefore apply, along with any applicable section 7
 639      additional terms, to the whole of the work, and all its parts,
 640      regardless of how they are packaged.  This License gives no
 641      permission to license the work in any other way, but it does not
 642      invalidate such permission if you have separately received it.
 643  
 644      d) If the work has interactive user interfaces, each must display
 645      Appropriate Legal Notices; however, if the Program has interactive
 646      interfaces that do not display Appropriate Legal Notices, your
 647      work need not make them do so.
 648  
 649    A compilation of a covered work with other separate and independent
 650  works, which are not by their nature extensions of the covered work,
 651  and which are not combined with it such as to form a larger program,
 652  in or on a volume of a storage or distribution medium, is called an
 653  "aggregate" if the compilation and its resulting copyright are not
 654  used to limit the access or legal rights of the compilation's users
 655  beyond what the individual works permit.  Inclusion of a covered work
 656  in an aggregate does not cause this License to apply to the other
 657  parts of the aggregate.
 658  
 659    6. Conveying Non-Source Forms.
 660  
 661    You may convey a covered work in object code form under the terms
 662  of sections 4 and 5, provided that you also convey the
 663  machine-readable Corresponding Source under the terms of this License,
 664  in one of these ways:
 665  
 666      a) Convey the object code in, or embodied in, a physical product
 667      (including a physical distribution medium), accompanied by the
 668      Corresponding Source fixed on a durable physical medium
 669      customarily used for software interchange.
 670  
 671      b) Convey the object code in, or embodied in, a physical product
 672      (including a physical distribution medium), accompanied by a
 673      written offer, valid for at least three years and valid for as
 674      long as you offer spare parts or customer support for that product
 675      model, to give anyone who possesses the object code either (1) a
 676      copy of the Corresponding Source for all the software in the
 677      product that is covered by this License, on a durable physical
 678      medium customarily used for software interchange, for a price no
 679      more than your reasonable cost of physically performing this
 680      conveying of source, or (2) access to copy the
 681      Corresponding Source from a network server at no charge.
 682  
 683      c) Convey individual copies of the object code with a copy of the
 684      written offer to provide the Corresponding Source.  This
 685      alternative is allowed only occasionally and noncommercially, and
 686      only if you received the object code with such an offer, in accord
 687      with subsection 6b.
 688  
 689      d) Convey the object code by offering access from a designated
 690      place (gratis or for a charge), and offer equivalent access to the
 691      Corresponding Source in the same way through the same place at no
 692      further charge.  You need not require recipients to copy the
 693      Corresponding Source along with the object code.  If the place to
 694      copy the object code is a network server, the Corresponding Source
 695      may be on a different server (operated by you or a third party)
 696      that supports equivalent copying facilities, provided you maintain
 697      clear directions next to the object code saying where to find the
 698      Corresponding Source.  Regardless of what server hosts the
 699      Corresponding Source, you remain obligated to ensure that it is
 700      available for as long as needed to satisfy these requirements.
 701  
 702      e) Convey the object code using peer-to-peer transmission, provided
 703      you inform other peers where the object code and Corresponding
 704      Source of the work are being offered to the general public at no
 705      charge under subsection 6d.
 706  
 707    A separable portion of the object code, whose source code is excluded
 708  from the Corresponding Source as a System Library, need not be
 709  included in conveying the object code work.
 710  
 711    A "User Product" is either (1) a "consumer product", which means any
 712  tangible personal property which is normally used for personal, family,
 713  or household purposes, or (2) anything designed or sold for incorporation
 714  into a dwelling.  In determining whether a product is a consumer product,
 715  doubtful cases shall be resolved in favor of coverage.  For a particular
 716  product received by a particular user, "normally used" refers to a
 717  typical or common use of that class of product, regardless of the status
 718  of the particular user or of the way in which the particular user
 719  actually uses, or expects or is expected to use, the product.  A product
 720  is a consumer product regardless of whether the product has substantial
 721  commercial, industrial or non-consumer uses, unless such uses represent
 722  the only significant mode of use of the product.
 723  
 724    "Installation Information" for a User Product means any methods,
 725  procedures, authorization keys, or other information required to install
 726  and execute modified versions of a covered work in that User Product from
 727  a modified version of its Corresponding Source.  The information must
 728  suffice to ensure that the continued functioning of the modified object
 729  code is in no case prevented or interfered with solely because
 730  modification has been made.
 731  
 732    If you convey an object code work under this section in, or with, or
 733  specifically for use in, a User Product, and the conveying occurs as
 734  part of a transaction in which the right of possession and use of the
 735  User Product is transferred to the recipient in perpetuity or for a
 736  fixed term (regardless of how the transaction is characterized), the
 737  Corresponding Source conveyed under this section must be accompanied
 738  by the Installation Information.  But this requirement does not apply
 739  if neither you nor any third party retains the ability to install
 740  modified object code on the User Product (for example, the work has
 741  been installed in ROM).
 742  
 743    The requirement to provide Installation Information does not include a
 744  requirement to continue to provide support service, warranty, or updates
 745  for a work that has been modified or installed by the recipient, or for
 746  the User Product in which it has been modified or installed.  Access to a
 747  network may be denied when the modification itself materially and
 748  adversely affects the operation of the network or violates the rules and
 749  protocols for communication across the network.
 750  
 751    Corresponding Source conveyed, and Installation Information provided,
 752  in accord with this section must be in a format that is publicly
 753  documented (and with an implementation available to the public in
 754  source code form), and must require no special password or key for
 755  unpacking, reading or copying.
 756  
 757    7. Additional Terms.
 758  
 759    "Additional permissions" are terms that supplement the terms of this
 760  License by making exceptions from one or more of its conditions.
 761  Additional permissions that are applicable to the entire Program shall
 762  be treated as though they were included in this License, to the extent
 763  that they are valid under applicable law.  If additional permissions
 764  apply only to part of the Program, that part may be used separately
 765  under those permissions, but the entire Program remains governed by
 766  this License without regard to the additional permissions.
 767  
 768    When you convey a copy of a covered work, you may at your option
 769  remove any additional permissions from that copy, or from any part of
 770  it.  (Additional permissions may be written to require their own
 771  removal in certain cases when you modify the work.)  You may place
 772  additional permissions on material, added by you to a covered work,
 773  for which you have or can give appropriate copyright permission.
 774  
 775    Notwithstanding any other provision of this License, for material you
 776  add to a covered work, you may (if authorized by the copyright holders of
 777  that material) supplement the terms of this License with terms:
 778  
 779      a) Disclaiming warranty or limiting liability differently from the
 780      terms of sections 15 and 16 of this License; or
 781  
 782      b) Requiring preservation of specified reasonable legal notices or
 783      author attributions in that material or in the Appropriate Legal
 784      Notices displayed by works containing it; or
 785  
 786      c) Prohibiting misrepresentation of the origin of that material, or
 787      requiring that modified versions of such material be marked in
 788      reasonable ways as different from the original version; or
 789  
 790      d) Limiting the use for publicity purposes of names of licensors or
 791      authors of the material; or
 792  
 793      e) Declining to grant rights under trademark law for use of some
 794      trade names, trademarks, or service marks; or
 795  
 796      f) Requiring indemnification of licensors and authors of that
 797      material by anyone who conveys the material (or modified versions of
 798      it) with contractual assumptions of liability to the recipient, for
 799      any liability that these contractual assumptions directly impose on
 800      those licensors and authors.
 801  
 802    All other non-permissive additional terms are considered "further
 803  restrictions" within the meaning of section 10.  If the Program as you
 804  received it, or any part of it, contains a notice stating that it is
 805  governed by this License along with a term that is a further
 806  restriction, you may remove that term.  If a license document contains
 807  a further restriction but permits relicensing or conveying under this
 808  License, you may add to a covered work material governed by the terms
 809  of that license document, provided that the further restriction does
 810  not survive such relicensing or conveying.
 811  
 812    If you add terms to a covered work in accord with this section, you
 813  must place, in the relevant source files, a statement of the
 814  additional terms that apply to those files, or a notice indicating
 815  where to find the applicable terms.
 816  
 817    Additional terms, permissive or non-permissive, may be stated in the
 818  form of a separately written license, or stated as exceptions;
 819  the above requirements apply either way.
 820  
 821    8. Termination.
 822  
 823    You may not propagate or modify a covered work except as expressly
 824  provided under this License.  Any attempt otherwise to propagate or
 825  modify it is void, and will automatically terminate your rights under
 826  this License (including any patent licenses granted under the third
 827  paragraph of section 11).
 828  
 829    However, if you cease all violation of this License, then your
 830  license from a particular copyright holder is reinstated (a)
 831  provisionally, unless and until the copyright holder explicitly and
 832  finally terminates your license, and (b) permanently, if the copyright
 833  holder fails to notify you of the violation by some reasonable means
 834  prior to 60 days after the cessation.
 835  
 836    Moreover, your license from a particular copyright holder is
 837  reinstated permanently if the copyright holder notifies you of the
 838  violation by some reasonable means, this is the first time you have
 839  received notice of violation of this License (for any work) from that
 840  copyright holder, and you cure the violation prior to 30 days after
 841  your receipt of the notice.
 842  
 843    Termination of your rights under this section does not terminate the
 844  licenses of parties who have received copies or rights from you under
 845  this License.  If your rights have been terminated and not permanently
 846  reinstated, you do not qualify to receive new licenses for the same
 847  material under section 10.
 848  
 849    9. Acceptance Not Required for Having Copies.
 850  
 851    You are not required to accept this License in order to receive or
 852  run a copy of the Program.  Ancillary propagation of a covered work
 853  occurring solely as a consequence of using peer-to-peer transmission
 854  to receive a copy likewise does not require acceptance.  However,
 855  nothing other than this License grants you permission to propagate or
 856  modify any covered work.  These actions infringe copyright if you do
 857  not accept this License.  Therefore, by modifying or propagating a
 858  covered work, you indicate your acceptance of this License to do so.
 859  
 860    10. Automatic Licensing of Downstream Recipients.
 861  
 862    Each time you convey a covered work, the recipient automatically
 863  receives a license from the original licensors, to run, modify and
 864  propagate that work, subject to this License.  You are not responsible
 865  for enforcing compliance by third parties with this License.
 866  
 867    An "entity transaction" is a transaction transferring control of an
 868  organization, or substantially all assets of one, or subdividing an
 869  organization, or merging organizations.  If propagation of a covered
 870  work results from an entity transaction, each party to that
 871  transaction who receives a copy of the work also receives whatever
 872  licenses to the work the party's predecessor in interest had or could
 873  give under the previous paragraph, plus a right to possession of the
 874  Corresponding Source of the work from the predecessor in interest, if
 875  the predecessor has it or can get it with reasonable efforts.
 876  
 877    You may not impose any further restrictions on the exercise of the
 878  rights granted or affirmed under this License.  For example, you may
 879  not impose a license fee, royalty, or other charge for exercise of
 880  rights granted under this License, and you may not initiate litigation
 881  (including a cross-claim or counterclaim in a lawsuit) alleging that
 882  any patent claim is infringed by making, using, selling, offering for
 883  sale, or importing the Program or any portion of it.
 884  
 885    11. Patents.
 886  
 887    A "contributor" is a copyright holder who authorizes use under this
 888  License of the Program or a work on which the Program is based.  The
 889  work thus licensed is called the contributor's "contributor version".
 890  
 891    A contributor's "essential patent claims" are all patent claims
 892  owned or controlled by the contributor, whether already acquired or
 893  hereafter acquired, that would be infringed by some manner, permitted
 894  by this License, of making, using, or selling its contributor version,
 895  but do not include claims that would be infringed only as a
 896  consequence of further modification of the contributor version.  For
 897  purposes of this definition, "control" includes the right to grant
 898  patent sublicenses in a manner consistent with the requirements of
 899  this License.
 900  
 901    Each contributor grants you a non-exclusive, worldwide, royalty-free
 902  patent license under the contributor's essential patent claims, to
 903  make, use, sell, offer for sale, import and otherwise run, modify and
 904  propagate the contents of its contributor version.
 905  
 906    In the following three paragraphs, a "patent license" is any express
 907  agreement or commitment, however denominated, not to enforce a patent
 908  (such as an express permission to practice a patent or covenant not to
 909  sue for patent infringement).  To "grant" such a patent license to a
 910  party means to make such an agreement or commitment not to enforce a
 911  patent against the party.
 912  
 913    If you convey a covered work, knowingly relying on a patent license,
 914  and the Corresponding Source of the work is not available for anyone
 915  to copy, free of charge and under the terms of this License, through a
 916  publicly available network server or other readily accessible means,
 917  then you must either (1) cause the Corresponding Source to be so
 918  available, or (2) arrange to deprive yourself of the benefit of the
 919  patent license for this particular work, or (3) arrange, in a manner
 920  consistent with the requirements of this License, to extend the patent
 921  license to downstream recipients.  "Knowingly relying" means you have
 922  actual knowledge that, but for the patent license, your conveying the
 923  covered work in a country, or your recipient's use of the covered work
 924  in a country, would infringe one or more identifiable patents in that
 925  country that you have reason to believe are valid.
 926  
 927    If, pursuant to or in connection with a single transaction or
 928  arrangement, you convey, or propagate by procuring conveyance of, a
 929  covered work, and grant a patent license to some of the parties
 930  receiving the covered work authorizing them to use, propagate, modify
 931  or convey a specific copy of the covered work, then the patent license
 932  you grant is automatically extended to all recipients of the covered
 933  work and works based on it.
 934  
 935    A patent license is "discriminatory" if it does not include within
 936  the scope of its coverage, prohibits the exercise of, or is
 937  conditioned on the non-exercise of one or more of the rights that are
 938  specifically granted under this License.  You may not convey a covered
 939  work if you are a party to an arrangement with a third party that is
 940  in the business of distributing software, under which you make payment
 941  to the third party based on the extent of your activity of conveying
 942  the work, and under which the third party grants, to any of the
 943  parties who would receive the covered work from you, a discriminatory
 944  patent license (a) in connection with copies of the covered work
 945  conveyed by you (or copies made from those copies), or (b) primarily
 946  for and in connection with specific products or compilations that
 947  contain the covered work, unless you entered into that arrangement,
 948  or that patent license was granted, prior to 28 March 2007.
 949  
 950    Nothing in this License shall be construed as excluding or limiting
 951  any implied license or other defenses to infringement that may
 952  otherwise be available to you under applicable patent law.
 953  
 954    12. No Surrender of Others' Freedom.
 955  
 956    If conditions are imposed on you (whether by court order, agreement or
 957  otherwise) that contradict the conditions of this License, they do not
 958  excuse you from the conditions of this License.  If you cannot convey a
 959  covered work so as to satisfy simultaneously your obligations under this
 960  License and any other pertinent obligations, then as a consequence you may
 961  not convey it at all.  For example, if you agree to terms that obligate you
 962  to collect a royalty for further conveying from those to whom you convey
 963  the Program, the only way you could satisfy both those terms and this
 964  License would be to refrain entirely from conveying the Program.
 965  
 966    13. Use with the GNU Affero General Public License.
 967  
 968    Notwithstanding any other provision of this License, you have
 969  permission to link or combine any covered work with a work licensed
 970  under version 3 of the GNU Affero General Public License into a single
 971  combined work, and to convey the resulting work.  The terms of this
 972  License will continue to apply to the part which is the covered work,
 973  but the special requirements of the GNU Affero General Public License,
 974  section 13, concerning interaction through a network will apply to the
 975  combination as such.
 976  
 977    14. Revised Versions of this License.
 978  
 979    The Free Software Foundation may publish revised and/or new versions of
 980  the GNU General Public License from time to time.  Such new versions will
 981  be similar in spirit to the present version, but may differ in detail to
 982  address new problems or concerns.
 983  
 984    Each version is given a distinguishing version number.  If the
 985  Program specifies that a certain numbered version of the GNU General
 986  Public License "or any later version" applies to it, you have the
 987  option of following the terms and conditions either of that numbered
 988  version or of any later version published by the Free Software
 989  Foundation.  If the Program does not specify a version number of the
 990  GNU General Public License, you may choose any version ever published
 991  by the Free Software Foundation.
 992  
 993    If the Program specifies that a proxy can decide which future
 994  versions of the GNU General Public License can be used, that proxy's
 995  public statement of acceptance of a version permanently authorizes you
 996  to choose that version for the Program.
 997  
 998    Later license versions may give you additional or different
 999  permissions.  However, no additional obligations are imposed on any
1000  author or copyright holder as a result of your choosing to follow a
1001  later version.
1002  
1003    15. Disclaimer of Warranty.
1004  
1005    THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
1006  APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
1007  HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
1008  OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
1009  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1010  PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
1011  IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
1012  ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
1013  
1014    16. Limitation of Liability.
1015  
1016    IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
1017  WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
1018  THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
1019  GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
1020  USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
1021  DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
1022  PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
1023  EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
1024  SUCH DAMAGES.
1025  
1026    17. Interpretation of Sections 15 and 16.
1027  
1028    If the disclaimer of warranty and limitation of liability provided
1029  above cannot be given local legal effect according to their terms,
1030  reviewing courts shall apply local law that most closely approximates
1031  an absolute waiver of all civil liability in connection with the
1032  Program, unless a warranty or assumption of liability accompanies a
1033  copy of the Program in return for a fee.
1034  
1035                       END OF TERMS AND CONDITIONS
1036  </pre>
1037  EOF;
1038      echo $lang->sprintf($lang->license_step, $license);
1039      $output->print_footer('requirements_check');
1040  }
1041  
1042  /**
1043   * Check our requirements
1044   */
1045  function requirements_check()
1046  {
1047      global $output, $mybb, $dboptions, $lang;
1048  
1049      $mybb->input['action'] = "requirements_check";
1050      $output->print_header($lang->req_check, 'requirements');
1051      echo $lang->req_step_top;
1052      $errors = array();
1053      $showerror = 0;
1054  
1055      if(!file_exists(MYBB_ROOT."/inc/config.php"))
1056      {
1057          if(!@rename(MYBB_ROOT."/inc/config.default.php", MYBB_ROOT."/inc/config.php"))
1058          {
1059              if(!$configwritable)
1060              {
1061                  $errors[] = $lang->sprintf($lang->req_step_error_box, $lang->req_step_error_configdefaultfile);
1062                  $configstatus = $lang->sprintf($lang->req_step_span_fail, $lang->not_writable);
1063                  $showerror = 1;
1064              }
1065          }
1066      }
1067  
1068      // Check PHP Version
1069      if(version_compare(PHP_VERSION, '5.2.0', "<"))
1070      {
1071          $errors[] = $lang->sprintf($lang->req_step_error_box, $lang->sprintf($lang->req_step_error_phpversion, PHP_VERSION));
1072          $phpversion = $lang->sprintf($lang->req_step_span_fail, PHP_VERSION);
1073          $showerror = 1;
1074      }
1075      else
1076      {
1077          $phpversion = $lang->sprintf($lang->req_step_span_pass, PHP_VERSION);
1078      }
1079  
1080      $mboptions = array();
1081  
1082      if(function_exists('mb_detect_encoding'))
1083      {
1084          $mboptions[] = $lang->multi_byte;
1085      }
1086  
1087      if(function_exists('iconv'))
1088      {
1089          $mboptions[] = 'iconv';
1090      }
1091  
1092      // Check Multibyte extensions
1093      if(count($mboptions) < 1)
1094      {
1095          $mbstatus = $lang->sprintf($lang->req_step_span_fail, $lang->none);
1096      }
1097      else
1098      {
1099          $mbstatus = implode(', ', $mboptions);
1100      }
1101  
1102      // Check database engines
1103      if(count($dboptions) < 1)
1104      {
1105          $errors[] = $lang->sprintf($lang->req_step_error_box, $lang->req_step_error_dboptions);
1106          $dbsupportlist = $lang->sprintf($lang->req_step_span_fail, $lang->none);
1107          $showerror = 1;
1108      }
1109      else
1110      {
1111          foreach($dboptions as $dboption)
1112          {
1113              $dbsupportlist[] = $dboption['title'];
1114          }
1115          $dbsupportlist = implode(', ', $dbsupportlist);
1116      }
1117  
1118      // Check XML parser is installed
1119      if(!function_exists('xml_parser_create'))
1120      {
1121          $errors[] = $lang->sprintf($lang->req_step_error_box, $lang->req_step_error_xmlsupport);
1122          $xmlstatus = $lang->sprintf($lang->req_step_span_fail, $lang->not_installed);
1123          $showerror = 1;
1124      }
1125      else
1126      {
1127          $xmlstatus = $lang->sprintf($lang->req_step_span_pass, $lang->installed);
1128      }
1129  
1130      // Check config file is writable
1131      $configwritable = @fopen(MYBB_ROOT.'inc/config.php', 'w');
1132      if(!$configwritable)
1133      {
1134          $errors[] = $lang->sprintf($lang->req_step_error_box, $lang->req_step_error_configfile);
1135          $configstatus = $lang->sprintf($lang->req_step_span_fail, $lang->not_writable);
1136          $showerror = 1;
1137      }
1138      else
1139      {
1140          $configstatus = $lang->sprintf($lang->req_step_span_pass, $lang->writable);
1141          @fclose($configwritable);
1142      }
1143  
1144      // Check settings file is writable
1145      $settingswritable = @fopen(MYBB_ROOT.'inc/settings.php', 'w');
1146      if(!$settingswritable)
1147      {
1148          $errors[] = $lang->sprintf($lang->req_step_error_box, $lang->req_step_error_settingsfile);
1149          $settingsstatus = $lang->sprintf($lang->req_step_span_fail, $lang->not_writable);
1150          $showerror = 1;
1151      }
1152      else
1153      {
1154          $settingsstatus = $lang->sprintf($lang->req_step_span_pass, $lang->writable);
1155          @fclose($settingswritable);
1156      }
1157  
1158      // Check cache directory is writable
1159      $cachewritable = @fopen(MYBB_ROOT.'cache/test.write', 'w');
1160      if(!$cachewritable)
1161      {
1162          $errors[] = $lang->sprintf($lang->req_step_error_box, $lang->req_step_error_cachedir);
1163          $cachestatus = $lang->sprintf($lang->req_step_span_fail, $lang->not_writable);
1164          $showerror = 1;
1165      }
1166      else
1167      {
1168          $cachestatus = $lang->sprintf($lang->req_step_span_pass, $lang->writable);
1169          @fclose($cachewritable);
1170            @my_chmod(MYBB_ROOT.'cache', '0777');
1171            @my_chmod(MYBB_ROOT.'cache/test.write', '0777');
1172          @unlink(MYBB_ROOT.'cache/test.write');
1173      }
1174  
1175      // Check upload directory is writable
1176      $uploadswritable = @fopen(MYBB_ROOT.'uploads/test.write', 'w');
1177      if(!$uploadswritable)
1178      {
1179          $errors[] = $lang->sprintf($lang->req_step_error_box, $lang->req_step_error_uploaddir);
1180          $uploadsstatus = $lang->sprintf($lang->req_step_span_fail, $lang->not_writable);
1181          $showerror = 1;
1182      }
1183      else
1184      {
1185          $uploadsstatus = $lang->sprintf($lang->req_step_span_pass, $lang->writable);
1186          @fclose($uploadswritable);
1187            @my_chmod(MYBB_ROOT.'uploads', '0777');
1188            @my_chmod(MYBB_ROOT.'uploads/test.write', '0777');
1189          @unlink(MYBB_ROOT.'uploads/test.write');
1190      }
1191  
1192      // Check avatar directory is writable
1193      $avatarswritable = @fopen(MYBB_ROOT.'uploads/avatars/test.write', 'w');
1194      if(!$avatarswritable)
1195      {
1196          $errors[] =  $lang->sprintf($lang->req_step_error_box, $lang->req_step_error_avatardir);
1197          $avatarsstatus = $lang->sprintf($lang->req_step_span_fail, $lang->not_writable);
1198          $showerror = 1;
1199      }
1200      else
1201      {
1202          $avatarsstatus = $lang->sprintf($lang->req_step_span_pass, $lang->writable);
1203          @fclose($avatarswritable);
1204          @my_chmod(MYBB_ROOT.'uploads/avatars', '0777');
1205            @my_chmod(MYBB_ROOT.'uploads/avatars/test.write', '0777');
1206          @unlink(MYBB_ROOT.'uploads/avatars/test.write');
1207        }
1208  
1209      // Output requirements page
1210      echo $lang->sprintf($lang->req_step_reqtable, $phpversion, $dbsupportlist, $mbstatus, $xmlstatus, $configstatus, $settingsstatus, $cachestatus, $uploadsstatus, $avatarsstatus);
1211  
1212      if($showerror == 1)
1213      {
1214          $error_list = error_list($errors);
1215          echo $lang->sprintf($lang->req_step_error_tablelist, $error_list);
1216          echo "\n            <input type=\"hidden\" name=\"action\" value=\"{$mybb->input['action']}\" />";
1217          echo "\n                <div id=\"next_button\"><input type=\"submit\" class=\"submit_button\" value=\"{$lang->recheck} &raquo;\" /></div><br style=\"clear: both;\" />\n";
1218          $output->print_footer();
1219      }
1220      else
1221      {
1222          echo $lang->req_step_reqcomplete;
1223          $output->print_footer('database_info');
1224      }
1225  }
1226  
1227  /**
1228   * Which database do we use?
1229   */
1230  function database_info()
1231  {
1232      global $output, $dbinfo, $errors, $mybb, $dboptions, $lang;
1233  
1234      $mybb->input['action'] = 'database_info';
1235      $output->print_header($lang->db_config, 'dbconfig');
1236  
1237      echo "<script type=\"text/javascript\">
1238  		function updateDBSettings()
1239          {
1240              var dbengine = \$(\"#dbengine\").val();
1241              $('.db_settings').each(function()
1242              {
1243                  var element = $(this);
1244                  element.addClass('db_settings');
1245                  if(dbengine+'_settings' == element.attr('id'))
1246                  {
1247                      element.show();
1248                  }
1249                  else
1250                  {
1251                      element.hide();
1252                  }
1253              });
1254          }
1255          $(function()
1256          {
1257              updateDBSettings();
1258          });
1259          </script>";
1260  
1261      // Check for errors from this stage
1262      if(is_array($errors))
1263      {
1264          $error_list = error_list($errors);
1265          echo $lang->sprintf($lang->db_step_error_config, $error_list);
1266      }
1267      else
1268      {
1269          echo $lang->db_step_config_db;
1270      }
1271  
1272      $dbengines = '';
1273  
1274      // Loop through database engines
1275      foreach($dboptions as $dbfile => $dbtype)
1276      {
1277          if($mybb->get_input('dbengine') == $dbfile)
1278          {
1279              $dbengines .= "<option value=\"{$dbfile}\" selected=\"selected\">{$dbtype['title']}</option>";
1280          }
1281          else
1282          {
1283              $dbengines .= "<option value=\"{$dbfile}\">{$dbtype['title']}</option>";
1284          }
1285      }
1286  
1287      $db_info = array();
1288      foreach($dboptions as $dbfile => $dbtype)
1289      {
1290          require_once MYBB_ROOT."inc/db_{$dbfile}.php";
1291          $db = new $dbtype['class'];
1292          $encodings = $db->fetch_db_charsets();
1293          $encoding_select = '';
1294          $mybb->input['config'] = $mybb->get_input('config', MyBB::INPUT_ARRAY);
1295          if(empty($mybb->input['config'][$dbfile]['dbhost']))
1296          {
1297              $mybb->input['config'][$dbfile]['dbhost'] = "localhost";
1298          }
1299          if(empty($mybb->input['config'][$dbfile]['tableprefix']))
1300          {
1301              $mybb->input['config'][$dbfile]['tableprefix'] = "mybb_";
1302          }
1303          if(empty($mybb->input['config'][$dbfile]['dbname']))
1304          {
1305              $mybb->input['config'][$dbfile]['dbname'] = '';
1306          }
1307          if(empty($mybb->input['config'][$dbfile]['dbuser']))
1308          {
1309              $mybb->input['config'][$dbfile]['dbuser'] = '';
1310          }
1311          if(empty($mybb->input['config'][$dbfile]['dbpass']))
1312          {
1313              $mybb->input['config'][$dbfile]['dbpass'] = '';
1314          }
1315          if(empty($mybb->input['config'][$dbfile]['encoding']))
1316          {
1317              $mybb->input['config'][$dbfile]['encoding'] = "utf8";
1318          }
1319  
1320          $class = '';
1321          if(empty($first) && !$mybb->get_input('dbengine'))
1322          {
1323              $mybb->input['dbengine'] = $dbfile;
1324              $first = true;
1325          }
1326          if($dbfile == $mybb->input['dbengine'])
1327          {
1328              $class = "_selected";
1329          }
1330  
1331          $db_info[$dbfile] = "
1332              <tbody id=\"{$dbfile}_settings\" class=\"db_settings db_type{$class}\">
1333                  <tr>
1334                      <th colspan=\"2\" class=\"first last\">{$dbtype['title']} {$lang->database_settings}</th>
1335                  </tr>";
1336  
1337          // SQLite gets some special settings
1338          if($dbfile == 'sqlite')
1339          {
1340              $db_info[$dbfile] .= "
1341                  <tr class=\"alt_row\">
1342                      <td class=\"first\"><label for=\"config_{$dbfile}_dbname\">{$lang->database_path}</label></td>
1343                      <td class=\"last alt_col\"><input type=\"text\" class=\"text_input\" name=\"config[{$dbfile}][dbname]\" id=\"config_{$dbfile}_dbname\" value=\"".htmlspecialchars_uni($mybb->input['config'][$dbfile]['dbname'])."\" /></td>
1344                  </tr>";
1345          }
1346          // Others get db host, username, password etc
1347          else
1348          {
1349              $db_info[$dbfile] .= "
1350                  <tr class=\"alt_row\">
1351                      <td class=\"first\"><label for=\"config_{$dbfile}_dbhost\">{$lang->database_host}</label></td>
1352                      <td class=\"last alt_col\"><input type=\"text\" class=\"text_input\" name=\"config[{$dbfile}][dbhost]\" id=\"config_{$dbfile}_dbhost\" value=\"".htmlspecialchars_uni($mybb->input['config'][$dbfile]['dbhost'])."\" /></td>
1353                  </tr>
1354                  <tr>
1355                      <td class=\"first\"><label for=\"config_{$dbfile}_dbuser\">{$lang->database_user}</label></td>
1356                      <td class=\"last alt_col\"><input type=\"text\" class=\"text_input\" name=\"config[{$dbfile}][dbuser]\" id=\"config_{$dbfile}_dbuser\" value=\"".htmlspecialchars_uni($mybb->input['config'][$dbfile]['dbuser'])."\" /></td>
1357                  </tr>
1358                  <tr class=\"alt_row\">
1359                      <td class=\"first\"><label for=\"config_{$dbfile}_dbpass\">{$lang->database_pass}</label></td>
1360                      <td class=\"last alt_col\"><input type=\"password\" class=\"text_input\" name=\"config[{$dbfile}][dbpass]\" id=\"config_{$dbfile}_dbpass\" value=\"".htmlspecialchars_uni($mybb->input['config'][$dbfile]['dbpass'])."\" /></td>
1361                  </tr>
1362                  <tr class=\"last\">
1363                      <td class=\"first\"><label for=\"config_{$dbfile}_dbname\">{$lang->database_name}</label></td>
1364                      <td class=\"last alt_col\"><input type=\"text\" class=\"text_input\" name=\"config[{$dbfile}][dbname]\" id=\"config_{$dbfile}_dbname\" value=\"".htmlspecialchars_uni($mybb->input['config'][$dbfile]['dbname'])."\" /></td>
1365                  </tr>";
1366          }
1367  
1368          // Now we're up to table settings
1369          $db_info[$dbfile] .= "
1370              <tr>
1371                  <th colspan=\"2\" class=\"first last\">{$dbtype['title']} {$lang->table_settings}</th>
1372              </tr>
1373              <tr class=\"first\">
1374                  <td class=\"first\"><label for=\"config_{$dbfile}_tableprefix\">{$lang->table_prefix}</label></td>
1375                  <td class=\"last alt_col\"><input type=\"text\" class=\"text_input\" name=\"config[{$dbfile}][tableprefix]\" id=\"config_{$dbfile}_tableprefix\" value=\"".htmlspecialchars_uni($mybb->input['config'][$dbfile]['tableprefix'])."\" /></td>
1376              </tr>
1377              ";
1378  
1379          // Encoding selection only if supported
1380          if(is_array($encodings))
1381          {
1382              $select_options = "";
1383              foreach($encodings as $encoding => $title)
1384              {
1385                  if($mybb->input['config'][$dbfile]['encoding'] == $encoding)
1386                  {
1387                      $select_options .= "<option value=\"{$encoding}\" selected=\"selected\">{$title}</option>";
1388                  }
1389                  else
1390                  {
1391                      $select_options .= "<option value=\"{$encoding}\">{$title}</option>";
1392                  }
1393              }
1394              $db_info[$dbfile] .= "
1395                  <tr class=\"last\">
1396                      <td class=\"first\"><label for=\"config_{$dbfile}_encoding\">{$lang->table_encoding}</label></td>
1397                      <td class=\"last alt_col\"><select name=\"config[{$dbfile}][encoding]\" id=\"config_{$dbfile}_encoding\">{$select_options}</select></td>
1398                  </tr>
1399                  </tbody>";
1400          }
1401      }
1402      $dbconfig = implode("", $db_info);
1403  
1404      echo $lang->sprintf($lang->db_step_config_table, $dbengines, $dbconfig);
1405      $output->print_footer('create_tables');
1406  }
1407  
1408  /**
1409   * Create our tables
1410   */
1411  function create_tables()
1412  {
1413      global $output, $dbinfo, $errors, $mybb, $dboptions, $lang;
1414  
1415      $mybb->input['dbengine'] = $mybb->get_input('dbengine');
1416      if(!file_exists(MYBB_ROOT."inc/db_{$mybb->input['dbengine']}.php"))
1417      {
1418          $errors[] = $lang->db_step_error_invalidengine;
1419          database_info();
1420      }
1421  
1422      $mybb->input['config'] = $mybb->get_input('config', MyBB::INPUT_ARRAY);
1423      $config = $mybb->input['config'][$mybb->input['dbengine']];
1424  
1425      if(strstr($mybb->input['dbengine'], "sqlite") !== false)
1426      {
1427          if(strstr($config['dbname'], "./") !== false || strstr($config['dbname'], "../") !== false || empty($config['dbname']))
1428          {
1429              $errors[] = $lang->db_step_error_sqlite_invalid_dbname;
1430              database_info();
1431          }
1432      }
1433  
1434      // Attempt to connect to the db
1435      require_once MYBB_ROOT."inc/db_{$mybb->input['dbengine']}.php";
1436      switch($mybb->input['dbengine'])
1437      {
1438          case "sqlite":
1439              $db = new DB_SQLite;
1440              break;
1441          case "pgsql":
1442              $db = new DB_PgSQL;
1443              break;
1444          case "pgsql_pdo":
1445              $db = new PostgresPdoDbDriver();
1446              break;
1447          case "mysqli":
1448              $db = new DB_MySQLi;
1449              break;
1450          case "mysql_pdo":
1451              $db = new MysqlPdoDbDriver();
1452              break;
1453          default:
1454              $db = new DB_MySQL;
1455      }
1456       $db->error_reporting = 0;
1457  
1458      if(!isset($config['encoding']))
1459      {
1460          $config['encoding'] = null;
1461      }
1462  
1463      $connect_array = array(
1464          "hostname" => $config['dbhost'],
1465          "username" => $config['dbuser'],
1466          "password" => $config['dbpass'],
1467          "database" => $config['dbname'],
1468          "encoding" => $config['encoding']
1469      );
1470  
1471      $connection = $db->connect($connect_array);
1472      if($connection === false)
1473      {
1474          $errors[] = $lang->sprintf($lang->db_step_error_noconnect, htmlspecialchars_uni($config['dbhost']));
1475      }
1476      // double check if the DB exists for MySQL
1477      elseif(method_exists($db, 'select_db') && !$db->select_db($config['dbname']))
1478      {
1479          $errors[] = $lang->sprintf($lang->db_step_error_nodbname, htmlspecialchars_uni($config['dbname']));
1480      }
1481  
1482      // Most DB engines only allow certain characters in the table name. Oracle requires an alphabetic character first.
1483      if((!preg_match("#^[A-Za-z][A-Za-z0-9_]*$#", $config['tableprefix'])) && $config['tableprefix'] != '')
1484      {
1485          $errors[] = $lang->db_step_error_invalid_tableprefix;
1486      }
1487  
1488      // Needs to be smaller then 64 characters total (MySQL Limit).
1489      // This allows 24 characters for the actual table name, which should be sufficient.
1490      if(strlen($config['tableprefix']) > 40)
1491      {
1492          $errors[] = $lang->db_step_error_tableprefix_too_long;
1493      }
1494  
1495      if($connection !== false && ($db->engine == 'mysql' || $db->engine == 'mysqli') && $config['encoding'] == 'utf8mb4' && version_compare($db->get_version(), '5.5.3', '<'))
1496      {
1497          $errors[] = $lang->db_step_error_utf8mb4_error;
1498      }
1499  
1500      if(is_array($errors))
1501      {
1502          database_info();
1503      }
1504  
1505      // Decide if we can use a database encoding or not
1506      if($db->fetch_db_charsets() != false)
1507      {
1508          $db_encoding = "\$config['database']['encoding'] = '".addcslashes($config['encoding'], "'")."';";
1509      }
1510      else
1511      {
1512          $db_encoding = "// \$config['database']['encoding'] = '".addcslashes($config['encoding'], "'")."';";
1513      }
1514  
1515      // Write the configuration file
1516      $configdata = "<?php
1517  /**
1518   * Database configuration
1519   *
1520   * Please see the MyBB Docs for advanced
1521   * database configuration for larger installations
1522   * https://docs.mybb.com/
1523   */
1524  
1525  \$config['database']['type'] = '".addcslashes($mybb->input['dbengine'], "'")."';
1526  \$config['database']['database'] = '".addcslashes($config['dbname'], "'")."';
1527  \$config['database']['table_prefix'] = '".addcslashes($config['tableprefix'], "'")."';
1528  
1529  \$config['database']['hostname'] = '".addcslashes($config['dbhost'], "'")."';
1530  \$config['database']['username'] = '".addcslashes($config['dbuser'], "'")."';
1531  \$config['database']['password'] = '".addcslashes($config['dbpass'], "'")."';
1532  
1533  /**
1534   * Admin CP directory
1535   *  For security reasons, it is recommended you
1536   *  rename your Admin CP directory. You then need
1537   *  to adjust the value below to point to the
1538   *  new directory.
1539   */
1540  
1541  \$config['admin_dir'] = 'admin';
1542  
1543  /**
1544   * Hide all Admin CP links
1545   *  If you wish to hide all Admin CP links
1546   *  on the front end of the board after
1547   *  renaming your Admin CP directory, set this
1548   *  to 1.
1549   */
1550  
1551  \$config['hide_admin_links'] = 0;
1552  
1553  /**
1554   * Data-cache configuration
1555   *  The data cache is a temporary cache
1556   *  of the most commonly accessed data in MyBB.
1557   *  By default, the database is used to store this data.
1558   *
1559   *  If you wish to use the file system (cache/ directory), MemCache (or MemCached), xcache, APC, APCu, eAccelerator or Redis
1560   *  you can change the value below to 'files', 'memcache', 'memcached', 'xcache', 'apc', 'apcu', 'eaccelerator' or 'redis' from 'db'.
1561   */
1562  
1563  \$config['cache_store'] = 'db';
1564  
1565  /**
1566   * Memcache configuration
1567   *  If you are using memcache or memcached as your
1568   *  data-cache, you need to configure the hostname
1569   *  and port of your memcache server below.
1570   *
1571   * If not using memcache, ignore this section.
1572   */
1573  
1574  \$config['memcache']['host'] = 'localhost';
1575  \$config['memcache']['port'] = 11211;
1576  
1577  /**
1578   * Redis configuration
1579   *  If you are using Redis as your data-cache
1580   *  you need to configure the hostname and port
1581   *  of your redis server below. If you want
1582   *  to connect via unix sockets, use the full
1583   *  path to the unix socket as host and leave
1584   *  the port setting unconfigured or false.
1585   */
1586  
1587  \$config['redis']['host'] = 'localhost';
1588  \$config['redis']['port'] = 6379;
1589  
1590  /**
1591   * Super Administrators
1592   *  A comma separated list of user IDs who cannot
1593   *  be edited, deleted or banned in the Admin CP.
1594   *  The administrator permissions for these users
1595   *  cannot be altered either.
1596   */
1597  
1598  \$config['super_admins'] = '1';
1599  
1600  /**
1601   * Database Encoding
1602   *  If you wish to set an encoding for MyBB uncomment
1603   *  the line below (if it isn't already) and change
1604   *  the current value to the mysql charset:
1605   *  http://dev.mysql.com/doc/refman/5.1/en/charset-mysql.html
1606   */
1607  
1608  {$db_encoding}
1609  
1610  /**
1611   * Automatic Log Pruning
1612   *  The MyBB task system can automatically prune
1613   *  various log files created by MyBB.
1614   *  To enable this functionality for the logs below, set the
1615   *  the number of days before each log should be pruned.
1616   *  If you set the value to 0, the logs will not be pruned.
1617   */
1618  
1619  \$config['log_pruning'] = array(
1620      'admin_logs' => 365, // Administrator logs
1621      'mod_logs' => 365, // Moderator logs
1622      'task_logs' => 30, // Scheduled task logs
1623      'mail_logs' => 180, // Mail error logs
1624      'user_mail_logs' => 180, // User mail logs
1625      'promotion_logs' => 180 // Promotion logs
1626  );
1627  
1628  /**
1629   * Disallowed Remote Hosts
1630   *  List of hosts the fetch_remote_file() function will not
1631   *  perform requests to.
1632   *  It is recommended that you enter hosts resolving to the
1633   *  forum server here to prevent Server Side Request
1634   *  Forgery attacks.
1635   */
1636  
1637  \$config['disallowed_remote_hosts'] = array(
1638      'localhost',
1639  );
1640  
1641  /**
1642   * Disallowed Remote Addresses
1643   *  List of IPv4 addresses the fetch_remote_file() function
1644   *  will not perform requests to.
1645   *  It is recommended that you enter addresses resolving to
1646   *  the forum server here to prevent Server Side Request
1647   *  Forgery attacks.
1648   *  Removing all values disables resolving hosts in that
1649   *  function.
1650   */
1651  
1652  \$config['disallowed_remote_addresses'] = array(
1653      '127.0.0.1',
1654      '10.0.0.0/8',
1655      '172.16.0.0/12',
1656      '192.168.0.0/16',
1657  );
1658  
1659  ";
1660  
1661      $file = fopen(MYBB_ROOT.'inc/config.php', 'w');
1662      fwrite($file, $configdata);
1663      fclose($file);
1664  
1665      if(function_exists('opcache_invalidate'))
1666      {
1667          opcache_invalidate(MYBB_ROOT."inc/config.php");
1668      }
1669  
1670      // Error reporting back on
1671       $db->error_reporting = 1;
1672  
1673      $output->print_header($lang->table_creation, 'createtables');
1674      echo $lang->sprintf($lang->tablecreate_step_connected, $dboptions[$mybb->input['dbengine']]['short_title'], $db->get_version());
1675  
1676      if($dboptions[$mybb->input['dbengine']]['structure_file'])
1677      {
1678          $structure_file = $dboptions[$mybb->input['dbengine']]['structure_file'];
1679      }
1680      else
1681      {
1682          $structure_file = 'mysql_db_tables.php';
1683      }
1684  
1685      require_once INSTALL_ROOT."resources/{$structure_file}";
1686      foreach($tables as $val)
1687      {
1688          $val = preg_replace('#mybb_(\S+?)([\s\.,\(]|$)#', $config['tableprefix'].'\\1\\2', $val);
1689          $val = preg_replace('#;$#', $db->build_create_table_collation().";", $val);
1690          preg_match('#CREATE TABLE (\S+)(\s?|\(?)\(#i', $val, $match);
1691          if(!empty($match[1]))
1692          {
1693              $db->drop_table($match[1], false, false);
1694              echo $lang->sprintf($lang->tablecreate_step_created, $match[1]);
1695          }
1696          $db->query($val);
1697          if(!empty($match[1]))
1698          {
1699              echo $lang->done . "<br />\n";
1700          }
1701      }
1702      echo $lang->tablecreate_step_done;
1703      $output->print_footer('populate_tables');
1704  }
1705  
1706  /**
1707   * Insert our default data
1708   */
1709  function populate_tables()
1710  {
1711      global $output, $lang, $dboptions;
1712  
1713      require MYBB_ROOT.'inc/config.php';
1714      $db = db_connection($config);
1715  
1716      $output->print_header($lang->table_population, 'tablepopulate');
1717      echo $lang->sprintf($lang->populate_step_insert);
1718  
1719      if(!empty($dboptions[$db->type]['population_file']))
1720      {
1721          $population_file = $dboptions[$db->type]['population_file'];
1722      }
1723      else
1724      {
1725          $population_file = 'mysql_db_inserts.php';
1726      }
1727  
1728      require_once INSTALL_ROOT."resources/{$population_file}";
1729      foreach($inserts as $val)
1730      {
1731          $val = preg_replace('#mybb_(\S+?)([\s\.,]|$)#', $config['database']['table_prefix'].'\\1\\2', $val);
1732          $db->query($val);
1733      }
1734  
1735      // Update the sequences for PgSQL
1736      if($config['database']['type'] == "pgsql")
1737      {
1738          $db->query("SELECT setval('{$config['database']['table_prefix']}attachtypes_atid_seq', (SELECT max(atid) FROM {$config['database']['table_prefix']}attachtypes));");
1739          $db->query("SELECT setval('{$config['database']['table_prefix']}forums_fid_seq', (SELECT max(fid) FROM {$config['database']['table_prefix']}forums));");
1740          $db->query("SELECT setval('{$config['database']['table_prefix']}helpdocs_hid_seq', (SELECT max(hid) FROM {$config['database']['table_prefix']}helpdocs));");
1741          $db->query("SELECT setval('{$config['database']['table_prefix']}helpsections_sid_seq', (SELECT max(sid) FROM {$config['database']['table_prefix']}helpsections));");
1742          $db->query("SELECT setval('{$config['database']['table_prefix']}icons_iid_seq', (SELECT max(iid) FROM {$config['database']['table_prefix']}icons));");
1743          $db->query("SELECT setval('{$config['database']['table_prefix']}profilefields_fid_seq', (SELECT max(fid) FROM {$config['database']['table_prefix']}profilefields));");
1744          $db->query("SELECT setval('{$config['database']['table_prefix']}smilies_sid_seq', (SELECT max(sid) FROM {$config['database']['table_prefix']}smilies));");
1745          $db->query("SELECT setval('{$config['database']['table_prefix']}spiders_sid_seq', (SELECT max(sid) FROM {$config['database']['table_prefix']}spiders));");
1746          $db->query("SELECT setval('{$config['database']['table_prefix']}templategroups_gid_seq', (SELECT max(gid) FROM {$config['database']['table_prefix']}templategroups));");
1747      }
1748  
1749      echo $lang->populate_step_inserted;
1750      $output->print_footer('templates');
1751  }
1752  
1753  /**
1754   * Install our theme
1755   */
1756  function insert_templates()
1757  {
1758      global $mybb, $output, $cache, $db, $lang;
1759  
1760      require MYBB_ROOT.'inc/config.php';
1761      $db = db_connection($config);
1762  
1763      require_once  MYBB_ROOT.'inc/class_datacache.php';
1764      $cache = new datacache;
1765  
1766      $output->print_header($lang->theme_installation, 'theme');
1767  
1768      echo $lang->theme_step_importing;
1769  
1770      $db->delete_query("themes");
1771      $db->delete_query("templates");
1772      $db->delete_query("themestylesheets");
1773      my_rmdir_recursive(MYBB_ROOT."cache/themes", array(MYBB_ROOT."cache/themes/index.html"));
1774  
1775      $insert_array = array(
1776          'title' => 'Default Templates'
1777      );
1778      $templateset = $db->insert_query("templatesets", $insert_array);
1779  
1780      $contents = @file_get_contents(INSTALL_ROOT.'resources/mybb_theme.xml');
1781      if(!empty($mybb->config['admin_dir']) && file_exists(MYBB_ROOT.$mybb->config['admin_dir']."/inc/functions_themes.php"))
1782      {
1783          require_once MYBB_ROOT.$mybb->config['admin_dir']."/inc/functions.php";
1784          require_once MYBB_ROOT.$mybb->config['admin_dir']."/inc/functions_themes.php";
1785      }
1786      elseif(file_exists(MYBB_ROOT."admin/inc/functions_themes.php"))
1787      {
1788          require_once  MYBB_ROOT."admin/inc/functions.php";
1789          require_once  MYBB_ROOT."admin/inc/functions_themes.php";
1790      }
1791      else
1792      {
1793          $output->print_error("Please make sure your admin directory is uploaded correctly.");
1794      }
1795      $theme_id = import_theme_xml($contents, array("templateset" => -2, "version_compat" => 1));
1796      $tid = build_new_theme("Default", null, $theme_id);
1797  
1798      // Update our properties template set to the correct one
1799      $query = $db->simple_select("themes", "stylesheets, properties", "tid='{$tid}'", array('limit' => 1));
1800  
1801      $theme = $db->fetch_array($query);
1802      $properties = my_unserialize($theme['properties']);
1803      $stylesheets = my_unserialize($theme['stylesheets']);
1804  
1805      $properties['templateset'] = $templateset;
1806      unset($properties['inherited']['templateset']);
1807  
1808      // 1.8: Stylesheet Colors
1809      $contents = @file_get_contents(INSTALL_ROOT.'resources/mybb_theme_colors.xml');
1810  
1811      $parser = create_xml_parser($contents);
1812      $tree = $parser->get_tree();
1813  
1814      if(is_array($tree) && is_array($tree['colors']))
1815      {
1816          if(is_array($tree['colors']['scheme']))
1817          {
1818              foreach($tree['colors']['scheme'] as $tag => $value)
1819              {
1820                  $exp = explode("=", $value['value']);
1821  
1822                  $properties['colors'][$exp[0]] = $exp[1];
1823              }
1824          }
1825  
1826          if(is_array($tree['colors']['stylesheets']))
1827          {
1828              $count = count($properties['disporder']) + 1;
1829              foreach($tree['colors']['stylesheets']['stylesheet'] as $stylesheet)
1830              {
1831                  $new_stylesheet = array(
1832                      "name" => $db->escape_string($stylesheet['attributes']['name']),
1833                      "tid" => $tid,
1834                      "attachedto" => $db->escape_string($stylesheet['attributes']['attachedto']),
1835                      "stylesheet" => $db->escape_string($stylesheet['value']),
1836                      "lastmodified" => TIME_NOW,
1837                      "cachefile" => $db->escape_string($stylesheet['attributes']['name'])
1838                  );
1839  
1840                  $sid = $db->insert_query("themestylesheets", $new_stylesheet);
1841                  $css_url = "css.php?stylesheet={$sid}";
1842  
1843                  $cached = cache_stylesheet($tid, $stylesheet['attributes']['name'], $stylesheet['value']);
1844  
1845                  if($cached)
1846                  {
1847                      $css_url = $cached;
1848                  }
1849  
1850                  // Add to display and stylesheet list
1851                  $properties['disporder'][$stylesheet['attributes']['name']] = $count;
1852                  $stylesheets[$stylesheet['attributes']['attachedto']]['global'][] = $css_url;
1853  
1854                  ++$count;
1855              }
1856          }
1857      }
1858  
1859      $db->update_query("themes", array("def" => 1, "properties" => $db->escape_string(my_serialize($properties)), "stylesheets" => $db->escape_string(my_serialize($stylesheets))), "tid = '{$tid}'");
1860  
1861      echo $lang->theme_step_imported;
1862      $output->print_footer('configuration');
1863  }
1864  
1865  /**
1866   * Default configuration
1867   */
1868  function configure()
1869  {
1870      global $output, $mybb, $errors, $lang;
1871  
1872      $output->print_header($lang->board_config, 'config');
1873  
1874      echo <<<EOF
1875          <script type="text/javascript">
1876  		function warnUser(inp, warn)
1877          {
1878              var parenttr = $('#'+inp.id).closest('tr');
1879              if(inp.value != inp.defaultValue)
1880              {
1881                  if(!parenttr.next('.setting_peeker').length)
1882                  {
1883                      var revertlink = ' <a href="javascript:revertSetting(\''+inp.defaultValue+'\', \'#'+inp.id+'\');">{$lang->config_step_revert}</a>';
1884                      parenttr.removeClass('last').after('<tr class="setting_peeker"><td colspan="2">'+warn+revertlink+'</td></tr>');
1885                  }
1886              } else {
1887                  parenttr.next('.setting_peeker').remove();
1888                  if(parenttr.is(':last-child'))
1889                  {
1890                      parenttr.addClass('last');
1891                  }
1892              }
1893          }
1894  
1895  		function revertSetting(defval, inpid)
1896          {
1897              $(inpid).val(defval);
1898              var parenttr = $(inpid).closest('tr');
1899              parenttr.next('.setting_peeker').remove();
1900              if(parenttr.is(':last-child'))
1901              {
1902                  parenttr.addClass('last');
1903              }
1904          }
1905          </script>
1906  
1907  EOF;
1908  
1909      // If board configuration errors
1910      if(is_array($errors))
1911      {
1912          $error_list = error_list($errors);
1913          echo $lang->sprintf($lang->config_step_error_config, $error_list);
1914  
1915          $bbname = htmlspecialchars_uni($mybb->get_input('bbname'));
1916          $bburl = htmlspecialchars_uni($mybb->get_input('bburl'));
1917          $websitename = htmlspecialchars_uni($mybb->get_input('websitename'));
1918          $websiteurl = htmlspecialchars_uni($mybb->get_input('websiteurl'));
1919          $cookiedomain = htmlspecialchars_uni($mybb->get_input('cookiedomain'));
1920          $cookiepath = htmlspecialchars_uni($mybb->get_input('cookiepath'));
1921          $contactemail =  htmlspecialchars_uni($mybb->get_input('contactemail'));
1922      }
1923      else
1924      {
1925          $bbname = 'Forums';
1926          $cookiedomain = '';
1927          $websitename = 'Your Website';
1928  
1929          $protocol = "http://";
1930          if((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != "off"))
1931          {
1932              $protocol = "https://";
1933          }
1934  
1935          // Attempt auto-detection
1936          if(!empty($_SERVER['HTTP_HOST']))
1937          {
1938              $hostname = $protocol.$_SERVER['HTTP_HOST'];
1939              $cookiedomain = $_SERVER['HTTP_HOST'];
1940          }
1941          elseif(!empty($_SERVER['SERVER_NAME']))
1942          {
1943              $hostname = $protocol.$_SERVER['SERVER_NAME'];
1944              $cookiedomain = $_SERVER['SERVER_NAME'];
1945          }
1946  
1947          if(my_substr($cookiedomain, 0, 4) == "www.")
1948          {
1949              $cookiedomain = substr($cookiedomain, 4);
1950          }
1951  
1952          // IP addresses and hostnames are not valid
1953          if(my_inet_pton($cookiedomain) !== false || strpos($cookiedomain, '.') === false)
1954          {
1955              $cookiedomain = '';
1956          }
1957          else
1958          {
1959              $cookiedomain = ".{$cookiedomain}";
1960          }
1961  
1962          if(!empty($_SERVER['SERVER_PORT']))
1963          {
1964              $port = ":{$_SERVER['SERVER_PORT']}";
1965              $pos = strrpos($cookiedomain, $port);
1966  
1967              if($pos !== false)
1968              {
1969                  $cookiedomain = substr($cookiedomain, 0, $pos);
1970              }
1971  
1972              if($_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443 && !preg_match("#:[0-9]#i", $hostname))
1973              {
1974                  $hostname .= $port;
1975              }
1976          }
1977  
1978          $currentlocation = get_current_location('', '', true);
1979          $noinstall = substr($currentlocation, 0, strrpos($currentlocation, '/install/'));
1980  
1981          $cookiepath = $noinstall.'/';
1982          $bburl = $hostname.$noinstall;
1983          $websiteurl = $hostname.'/';
1984  
1985          if(isset($_SERVER['SERVER_ADMIN']) && filter_var($_SERVER['SERVER_ADMIN'], FILTER_VALIDATE_EMAIL))
1986          {
1987              $contactemail = $_SERVER['SERVER_ADMIN'];
1988          }
1989          else
1990          {
1991              $contactemail = null;
1992          }
1993      }
1994  
1995      echo $lang->sprintf($lang->config_step_table, $bbname, $bburl, $websitename, $websiteurl, $cookiedomain, $cookiepath, $contactemail);
1996      $output->print_footer('adminuser');
1997  }
1998  
1999  /**
2000   * How do we want to name the admin user?
2001   */
2002  function create_admin_user()
2003  {
2004      global $output, $mybb, $errors, $db, $lang;
2005  
2006      $mybb->input['action'] = "adminuser";
2007      // If no errors then check for errors from last step
2008      if(!is_array($errors))
2009      {
2010          if(empty($mybb->input['bburl']))
2011          {
2012              $errors[] = $lang->config_step_error_url;
2013          }
2014          if(empty($mybb->input['bbname']))
2015          {
2016              $errors[] = $lang->config_step_error_name;
2017          }
2018          if(is_array($errors))
2019          {
2020              configure();
2021          }
2022      }
2023      $output->print_header($lang->create_admin, 'admin');
2024  
2025      echo <<<EOF
2026          <script type="text/javascript">
2027  		function comparePass()
2028          {
2029              var parenttr = $('#adminpass2').closest('tr');
2030              var passval = $('#adminpass2').val();
2031              if(passval && passval != $('#adminpass').val())
2032              {
2033                  if(!parenttr.next('.pass_peeker').length)
2034                  {
2035                      parenttr.removeClass('last').after('<tr class="pass_peeker"><td colspan="2">{$lang->admin_step_nomatch}</td></tr>');
2036                  }
2037              } else {
2038                  parenttr.addClass('last').next('.pass_peeker').remove();
2039              }
2040          }
2041          </script>
2042  
2043  EOF;
2044  
2045      if(is_array($errors))
2046      {
2047          $error_list = error_list($errors);
2048          echo $lang->sprintf($lang->admin_step_error_config, $error_list);
2049          $adminuser = $mybb->get_input('adminuser');
2050          $adminemail = $mybb->get_input('adminemail');
2051      }
2052      else
2053      {
2054          require MYBB_ROOT.'inc/config.php';
2055          $db = db_connection($config);
2056  
2057          echo $lang->admin_step_setupsettings;
2058          $adminuser = $adminemail = '';
2059  
2060          $settings = file_get_contents(INSTALL_ROOT.'resources/settings.xml');
2061          $parser = create_xml_parser($settings);
2062          $parser->collapse_dups = 0;
2063          $tree = $parser->get_tree();
2064          $groupcount = $settingcount = 0;
2065  
2066          // Insert all the settings
2067          foreach($tree['settings'][0]['settinggroup'] as $settinggroup)
2068          {
2069              $groupdata = array(
2070                  'name' => $db->escape_string($settinggroup['attributes']['name']),
2071                  'title' => $db->escape_string($settinggroup['attributes']['title']),
2072                  'description' => $db->escape_string($settinggroup['attributes']['description']),
2073                  'disporder' => (int)$settinggroup['attributes']['disporder'],
2074                  'isdefault' => $settinggroup['attributes']['isdefault'],
2075              );
2076              $gid = $db->insert_query('settinggroups', $groupdata);
2077              ++$groupcount;
2078              foreach($settinggroup['setting'] as $setting)
2079              {
2080                  $settingdata = array(
2081                      'name' => $db->escape_string($setting['attributes']['name']),
2082                      'title' => $db->escape_string($setting['title'][0]['value']),
2083                      'description' => $db->escape_string($setting['description'][0]['value']),
2084                      'optionscode' => $db->escape_string($setting['optionscode'][0]['value']),
2085                      'value' => $db->escape_string($setting['settingvalue'][0]['value']),
2086                      'disporder' => (int)$setting['disporder'][0]['value'],
2087                      'gid' => $gid,
2088                      'isdefault' => 1
2089                  );
2090  
2091                  $db->insert_query('settings', $settingdata);
2092                  $settingcount++;
2093              }
2094          }
2095  
2096          if(my_substr($mybb->get_input('bburl'), -1, 1) == '/')
2097          {
2098              $mybb->input['bburl'] = my_substr($mybb->get_input('bburl'), 0, -1);
2099          }
2100  
2101          $db->update_query("settings", array('value' => $db->escape_string($mybb->get_input('bbname'))), "name='bbname'");
2102          $db->update_query("settings", array('value' => $db->escape_string($mybb->get_input('bburl'))), "name='bburl'");
2103          $db->update_query("settings", array('value' => $db->escape_string($mybb->get_input('websitename'))), "name='homename'");
2104          $db->update_query("settings", array('value' => $db->escape_string($mybb->get_input('websiteurl'))), "name='homeurl'");
2105          $db->update_query("settings", array('value' => $db->escape_string($mybb->get_input('cookiedomain'))), "name='cookiedomain'");
2106          $db->update_query("settings", array('value' => $db->escape_string($mybb->get_input('cookiepath'))), "name='cookiepath'");
2107          $db->update_query("settings", array('value' => $db->escape_string($mybb->get_input('contactemail'))), "name='adminemail'");
2108          $db->update_query("settings", array('value' => 'contact.php'), "name='contactlink'");
2109  
2110          write_settings();
2111  
2112          echo $lang->sprintf($lang->admin_step_insertesettings, $settingcount, $groupcount);
2113  
2114          // Save the acp pin
2115          $pin = addslashes($mybb->get_input('pin'));
2116  
2117          $file = @fopen(MYBB_ROOT."inc/config.php", "a");
2118  
2119          @fwrite($file, "/**
2120   * Admin CP Secret PIN
2121   *  If you wish to request a PIN
2122   *  when someone tries to login
2123   *  on your Admin CP, enter it below.
2124   */
2125  
2126  \$config['secret_pin'] = '{$pin}';");
2127  
2128          @fclose($file);
2129  
2130          include_once  MYBB_ROOT."inc/functions_task.php";
2131          $tasks = file_get_contents(INSTALL_ROOT.'resources/tasks.xml');
2132          $parser = create_xml_parser($tasks);
2133          $parser->collapse_dups = 0;
2134          $tree = $parser->get_tree();
2135          $taskcount = 0;
2136  
2137          // Insert scheduled tasks
2138          foreach($tree['tasks'][0]['task'] as $task)
2139          {
2140              $new_task = array(
2141                  'title' => $db->escape_string($task['title'][0]['value']),
2142                  'description' => $db->escape_string($task['description'][0]['value']),
2143                  'file' => $db->escape_string($task['file'][0]['value']),
2144                  'minute' => $db->escape_string($task['minute'][0]['value']),
2145                  'hour' => $db->escape_string($task['hour'][0]['value']),
2146                  'day' => $db->escape_string($task['day'][0]['value']),
2147                  'weekday' => $db->escape_string($task['weekday'][0]['value']),
2148                  'month' => $db->escape_string($task['month'][0]['value']),
2149                  'enabled' => $db->escape_string($task['enabled'][0]['value']),
2150                  'logging' => $db->escape_string($task['logging'][0]['value'])
2151              );
2152  
2153              $new_task['nextrun'] = fetch_next_run($new_task);
2154  
2155              $db->insert_query("tasks", $new_task);
2156              $taskcount++;
2157          }
2158  
2159          // For the version check task, set a random date and hour (so all MyBB installs don't query mybb.com all at the same time)
2160          $update_array = array(
2161              'hour' => rand(0, 23),
2162              'weekday' => rand(0, 6)
2163          );
2164  
2165          $db->update_query("tasks", $update_array, "file = 'versioncheck'");
2166  
2167          echo $lang->sprintf($lang->admin_step_insertedtasks, $taskcount);
2168  
2169          $views = file_get_contents(INSTALL_ROOT.'resources/adminviews.xml');
2170          $parser = create_xml_parser($views);
2171          $parser->collapse_dups = 0;
2172          $tree = $parser->get_tree();
2173          $view_count = 0;
2174  
2175          // Insert admin views
2176          foreach($tree['adminviews'][0]['view'] as $view)
2177          {
2178              $fields = array();
2179              foreach($view['fields'][0]['field'] as $field)
2180              {
2181                  $fields[] = $field['attributes']['name'];
2182              }
2183  
2184              $conditions = array();
2185              if(isset($view['conditions'][0]['condition']) && is_array($view['conditions'][0]['condition']))
2186              {
2187                  foreach($view['conditions'][0]['condition'] as $condition)
2188                  {
2189                      if(!$condition['value']) continue;
2190                      if($condition['attributes']['is_serialized'] == 1)
2191                      {
2192                          $condition['value'] = my_unserialize($condition['value']);
2193                      }
2194                      $conditions[$condition['attributes']['name']] = $condition['value'];
2195                  }
2196              }
2197  
2198              $custom_profile_fields = array();
2199              if(isset($view['custom_profile_fields'][0]['field']) && is_array($view['custom_profile_fields'][0]['field']))
2200              {
2201                  foreach($view['custom_profile_fields'][0]['field'] as $field)
2202                  {
2203                      $custom_profile_fields[] = $field['attributes']['name'];
2204                  }
2205              }
2206  
2207              $new_view = array(
2208                  "uid" => 0,
2209                  "type" => $db->escape_string($view['attributes']['type']),
2210                  "visibility" => (int)$view['attributes']['visibility'],
2211                  "title" => $db->escape_string($view['title'][0]['value']),
2212                  "fields" => $db->escape_string(my_serialize($fields)),
2213                  "conditions" => $db->escape_string(my_serialize($conditions)),
2214                  "custom_profile_fields" => $db->escape_string(my_serialize($custom_profile_fields)),
2215                  "sortby" => $db->escape_string($view['sortby'][0]['value']),
2216                  "sortorder" => $db->escape_string($view['sortorder'][0]['value']),
2217                  "perpage" => (int)$view['perpage'][0]['value'],
2218                  "view_type" => $db->escape_string($view['view_type'][0]['value'])
2219              );
2220              $db->insert_query("adminviews", $new_view);
2221              $view_count++;
2222          }
2223  
2224          echo $lang->sprintf($lang->admin_step_insertedviews, $view_count);
2225  
2226          echo $lang->admin_step_createadmin;
2227      }
2228  
2229      echo $lang->sprintf($lang->admin_step_admintable, $adminuser, $adminemail);
2230      $output->print_footer('final');
2231  }
2232  
2233  /**
2234   * Installation is finished
2235   */
2236  function install_done()
2237  {
2238      global $output, $db, $mybb, $errors, $cache, $lang;
2239  
2240      if(empty($mybb->input['adminuser']))
2241      {
2242          $errors[] = $lang->admin_step_error_nouser;
2243      }
2244      if(empty($mybb->input['adminpass']))
2245      {
2246          $errors[] = $lang->admin_step_error_nopassword;
2247      }
2248      if($mybb->get_input('adminpass') != $mybb->get_input('adminpass2'))
2249      {
2250          $errors[] = $lang->admin_step_error_nomatch;
2251      }
2252      if(empty($mybb->input['adminemail']))
2253      {
2254          $errors[] = $lang->admin_step_error_noemail;
2255      }
2256      if(is_array($errors))
2257      {
2258          create_admin_user();
2259      }
2260  
2261      require MYBB_ROOT.'inc/config.php';
2262      $db = db_connection($config);
2263  
2264      require  MYBB_ROOT.'inc/settings.php';
2265      $mybb->settings = &$settings;
2266  
2267      ob_start();
2268      $output->print_header($lang->finish_setup, 'finish');
2269  
2270      echo $lang->done_step_usergroupsinserted;
2271  
2272      // Insert all of our user groups from the XML file
2273      $usergroup_settings = file_get_contents(INSTALL_ROOT.'resources/usergroups.xml');
2274      $parser = create_xml_parser($usergroup_settings);
2275      $parser->collapse_dups = 0;
2276      $tree = $parser->get_tree();
2277  
2278      $admin_gid = '';
2279      $group_count = 0;
2280      foreach($tree['usergroups'][0]['usergroup'] as $usergroup)
2281      {
2282          // usergroup[cancp][0][value]
2283          $new_group = array();
2284          foreach($usergroup as $key => $value)
2285          {
2286              if(!is_array($value))
2287              {
2288                  continue;
2289              }
2290  
2291              $new_group[$key] = $db->escape_string($value[0]['value']);
2292          }
2293          $db->insert_query("usergroups", $new_group, false);
2294  
2295          // If this group can access the admin CP and we haven't established the admin group - set it (just in case we ever change IDs)
2296          if($new_group['cancp'] == 1 && !$admin_gid)
2297          {
2298              $admin_gid = $usergroup['gid'][0]['value'];
2299          }
2300          $group_count++;
2301      }
2302  
2303      // Restart usergroup sequence with correct # of groups
2304      if($config['database']['type'] == "pgsql")
2305      {
2306          $db->query("SELECT setval('{$config['database']['table_prefix']}usergroups_gid_seq', (SELECT max(gid) FROM {$config['database']['table_prefix']}usergroups));");
2307      }
2308  
2309      echo $lang->done . '</p>';
2310  
2311      echo $lang->done_step_admincreated;
2312      $now = TIME_NOW;
2313      $salt = random_str();
2314      $loginkey = generate_loginkey();
2315      $saltedpw = md5(md5($salt).md5($mybb->get_input('adminpass')));
2316  
2317      $newuser = array(
2318          'username' => $db->escape_string($mybb->get_input('adminuser')),
2319          'password' => $saltedpw,
2320          'salt' => $salt,
2321          'loginkey' => $loginkey,
2322          'email' => $db->escape_string($mybb->get_input('adminemail')),
2323          'usergroup' => $admin_gid, // assigned above
2324          'regdate' => $now,
2325          'lastactive' => $now,
2326          'lastvisit' => $now,
2327          'website' => '',
2328          'icq' => '',
2329          'skype' =>'',
2330          'google' =>'',
2331          'birthday' => '',
2332          'signature' => '',
2333          'allownotices' => 1,
2334          'hideemail' => 0,
2335          'subscriptionmethod' => '0',
2336          'receivepms' => 1,
2337          'pmnotice' => 1,
2338          'pmnotify' => 1,
2339          'buddyrequestspm' => 1,
2340          'buddyrequestsauto' => 0,
2341          'showimages' => 1,
2342          'showvideos' => 1,
2343          'showsigs' => 1,
2344          'showavatars' => 1,
2345          'showquickreply' => 1,
2346          'invisible' => 0,
2347          'style' => '0',
2348          'timezone' => 0,
2349          'dst' => 0,
2350          'threadmode' => '',
2351          'daysprune' => 0,
2352          'regip' => $db->escape_binary(my_inet_pton(get_ip())),
2353          'language' => '',
2354          'showcodebuttons' => 1,
2355          'tpp' => 0,
2356          'ppp' => 0,
2357          'referrer' => 0,
2358          'buddylist' => '',
2359          'ignorelist' => '',
2360          'pmfolders' => "0**$%%$1**$%%$2**$%%$3**$%%$4**",
2361          'notepad' => '',
2362          'showredirect' => 1,
2363          'usernotes' => ''
2364      );
2365      $db->insert_query('users', $newuser);
2366      echo $lang->done . '</p>';
2367  
2368      echo $lang->done_step_adminoptions;
2369      $adminoptions = file_get_contents(INSTALL_ROOT.'resources/adminoptions.xml');
2370      $parser = create_xml_parser($adminoptions);
2371      $parser->collapse_dups = 0;
2372      $tree = $parser->get_tree();
2373      $insertmodule = array();
2374  
2375      $db->delete_query("adminoptions");
2376  
2377      // Insert all the admin permissions
2378      foreach($tree['adminoptions'][0]['user'] as $users)
2379      {
2380          $uid = $users['attributes']['uid'];
2381  
2382          foreach($users['permissions'][0]['module'] as $module)
2383          {
2384              foreach($module['permission'] as $permission)
2385              {
2386                  $insertmodule[$module['attributes']['name']][$permission['attributes']['name']] = $permission['value'];
2387              }
2388          }
2389  
2390          $defaultviews = array();
2391          foreach($users['defaultviews'][0]['view'] as $view)
2392          {
2393              $defaultviews[$view['attributes']['type']] = $view['value'];
2394          }
2395  
2396          $adminoptiondata = array(
2397              'uid' => (int)$uid,
2398              'cpstyle' => '',
2399              'notes' => '',
2400              'permissions' => $db->escape_string(my_serialize($insertmodule)),
2401              'defaultviews' => $db->escape_string(my_serialize($defaultviews))
2402          );
2403  
2404          $insertmodule = array();
2405  
2406          $db->insert_query('adminoptions', $adminoptiondata);
2407      }
2408      echo $lang->done . '</p>';
2409  
2410      // Automatic Login
2411      my_unsetcookie("sid");
2412      my_unsetcookie("mybbuser");
2413      my_setcookie('mybbuser', $uid.'_'.$loginkey, null, true, "lax");
2414      ob_end_flush();
2415  
2416      // Make fulltext columns if supported
2417      if($db->supports_fulltext('threads'))
2418      {
2419          $db->create_fulltext_index('threads', 'subject');
2420      }
2421      if($db->supports_fulltext_boolean('posts'))
2422      {
2423          $db->create_fulltext_index('posts', 'message');
2424      }
2425  
2426      echo $lang->done_step_cachebuilding;
2427      require_once  MYBB_ROOT.'inc/class_datacache.php';
2428      $cache = new datacache;
2429      $cache->update_version();
2430      $cache->update_attachtypes();
2431      $cache->update_smilies();
2432      $cache->update_badwords();
2433      $cache->update_usergroups();
2434      $cache->update_forumpermissions();
2435      $cache->update_stats();
2436      $cache->update_statistics();
2437      $cache->update_forums();
2438      $cache->update_moderators();
2439      $cache->update_usertitles();
2440      $cache->update_reportedcontent();
2441      $cache->update_awaitingactivation();
2442      $cache->update_mycode();
2443      $cache->update_profilefields();
2444      $cache->update_posticons();
2445      $cache->update_spiders();
2446      $cache->update_bannedips();
2447      $cache->update_bannedemails();
2448      $cache->update_birthdays();
2449      $cache->update_groupleaders();
2450      $cache->update_threadprefixes();
2451      $cache->update_forumsdisplay();
2452      $cache->update("plugins", array());
2453      $cache->update("mostonline", array(
2454          'numusers' => 0,
2455          'time' => 0,
2456      ));
2457      $cache->update("internal_settings", array('encryption_key' => random_str(32)));
2458      $cache->update_default_theme();
2459      $cache->update_reportreasons(true);
2460  
2461      $version_history = array();
2462      $dh = opendir(INSTALL_ROOT."resources");
2463      while(($file = readdir($dh)) !== false)
2464      {
2465          if(preg_match("#upgrade([0-9]+).php$#i", $file, $match))
2466          {
2467              $version_history[$match[1]] = $match[1];
2468          }
2469      }
2470      sort($version_history, SORT_NUMERIC);
2471      $cache->update("version_history", $version_history);
2472  
2473      // Schedule an update check so it occurs an hour ago.  Gotta stay up to date!
2474      $update['nextrun'] = TIME_NOW - 3600;
2475      $db->update_query("tasks", $update, "tid='12'");
2476  
2477      $cache->update_update_check();
2478      $cache->update_tasks();
2479  
2480      echo $lang->done . '</p>';
2481  
2482      echo $lang->done_step_success;
2483  
2484      $written = 0;
2485      if(is_writable('./'))
2486      {
2487          $lock = @fopen('./lock', 'w');
2488  
2489          if($lock !== false)
2490          {
2491              $written = @fwrite($lock, '1');
2492              @fclose($lock);
2493  
2494              if($written)
2495              {
2496                  echo $lang->done_step_locked;
2497              }
2498          }
2499      }
2500      if(!$written)
2501      {
2502          echo $lang->done_step_dirdelete;
2503      }
2504      echo $lang->done_whats_next;
2505      $output->print_footer('');
2506  }
2507  
2508  /**
2509   * @param array $config
2510   *
2511   * @return DB_MySQL|DB_MySQLi|DB_PgSQL|DB_SQLite|PostgresPdoDbDriver|MysqlPdoDbDriver
2512   */
2513  function db_connection($config)
2514  {
2515      require_once MYBB_ROOT."inc/db_{$config['database']['type']}.php";
2516      switch($config['database']['type'])
2517      {
2518          case "sqlite":
2519              $db = new DB_SQLite;
2520              break;
2521          case "pgsql":
2522              $db = new DB_PgSQL;
2523              break;
2524          case "pgsql_pdo":
2525              $db = new PostgresPdoDbDriver();
2526              break;
2527          case "mysqli":
2528              $db = new DB_MySQLi;
2529              break;
2530          case "mysql_pdo":
2531              $db = new MysqlPdoDbDriver();
2532              break;
2533          default:
2534              $db = new DB_MySQL;
2535      }
2536  
2537      // Connect to Database
2538      define('TABLE_PREFIX', $config['database']['table_prefix']);
2539  
2540      $db->connect($config['database']);
2541      $db->set_table_prefix(TABLE_PREFIX);
2542      $db->type = $config['database']['type'];
2543  
2544      return $db;
2545  }
2546  
2547  /**
2548   * @param array $array
2549   *
2550   * @return string
2551   */
2552  function error_list($array)
2553  {
2554      $string = "<ul>\n";
2555      foreach($array as $error)
2556      {
2557          $string .= "<li>{$error}</li>\n";
2558      }
2559      $string .= "</ul>\n";
2560      return $string;
2561  }
2562  
2563  /**
2564   * Write our settings to the settings file
2565   */
2566  function write_settings()
2567  {
2568      global $db;
2569  
2570      $settings = '';
2571      $query = $db->simple_select('settings', '*', '', array('order_by' => 'title'));
2572      while($setting = $db->fetch_array($query))
2573      {
2574          $setting['name'] = addcslashes($setting['name'], "\\'");
2575          $setting['value'] = addcslashes($setting['value'], '\\"$');
2576          $settings .= "\$settings['{$setting['name']}'] = \"{$setting['value']}\";\n";
2577      }
2578      if(!empty($settings))
2579      {
2580          $settings = "<?php\n/*********************************\ \n  DO NOT EDIT THIS FILE, PLEASE USE\n  THE SETTINGS EDITOR\n\*********************************/\n\n{$settings}\n";
2581          $file = fopen(MYBB_ROOT."inc/settings.php", "w");
2582          fwrite($file, $settings);
2583          fclose($file);
2584      }
2585  }


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