[ Index ]

PHP Cross Reference of MyBB 1.8.38

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      '0.0.0.0',
1654      '127.0.0.0/8',
1655      '10.0.0.0/8',
1656      '172.16.0.0/12',
1657      '192.168.0.0/16',
1658  );
1659  
1660  ";
1661  
1662      $file = fopen(MYBB_ROOT.'inc/config.php', 'w');
1663      fwrite($file, $configdata);
1664      fclose($file);
1665  
1666      if(function_exists('opcache_invalidate'))
1667      {
1668          opcache_invalidate(MYBB_ROOT."inc/config.php");
1669      }
1670  
1671      // Error reporting back on
1672       $db->error_reporting = 1;
1673  
1674      $output->print_header($lang->table_creation, 'createtables');
1675      echo $lang->sprintf($lang->tablecreate_step_connected, $dboptions[$mybb->input['dbengine']]['short_title'], $db->get_version());
1676  
1677      if($dboptions[$mybb->input['dbengine']]['structure_file'])
1678      {
1679          $structure_file = $dboptions[$mybb->input['dbengine']]['structure_file'];
1680      }
1681      else
1682      {
1683          $structure_file = 'mysql_db_tables.php';
1684      }
1685  
1686      require_once INSTALL_ROOT."resources/{$structure_file}";
1687      foreach($tables as $val)
1688      {
1689          $val = preg_replace('#mybb_(\S+?)([\s\.,\(]|$)#', $config['tableprefix'].'\\1\\2', $val);
1690          $val = preg_replace('#;$#', $db->build_create_table_collation().";", $val);
1691          preg_match('#CREATE TABLE (\S+)(\s?|\(?)\(#i', $val, $match);
1692          if(!empty($match[1]))
1693          {
1694              $db->drop_table($match[1], false, false);
1695              echo $lang->sprintf($lang->tablecreate_step_created, $match[1]);
1696          }
1697          $db->query($val);
1698          if(!empty($match[1]))
1699          {
1700              echo $lang->done . "<br />\n";
1701          }
1702      }
1703      echo $lang->tablecreate_step_done;
1704      $output->print_footer('populate_tables');
1705  }
1706  
1707  /**
1708   * Insert our default data
1709   */
1710  function populate_tables()
1711  {
1712      global $output, $lang, $dboptions;
1713  
1714      require MYBB_ROOT.'inc/config.php';
1715      $db = db_connection($config);
1716  
1717      $output->print_header($lang->table_population, 'tablepopulate');
1718      echo $lang->sprintf($lang->populate_step_insert);
1719  
1720      if(!empty($dboptions[$db->type]['population_file']))
1721      {
1722          $population_file = $dboptions[$db->type]['population_file'];
1723      }
1724      else
1725      {
1726          $population_file = 'mysql_db_inserts.php';
1727      }
1728  
1729      require_once INSTALL_ROOT."resources/{$population_file}";
1730      foreach($inserts as $val)
1731      {
1732          $val = preg_replace('#mybb_(\S+?)([\s\.,]|$)#', $config['database']['table_prefix'].'\\1\\2', $val);
1733          $db->query($val);
1734      }
1735  
1736      // Update the sequences for PgSQL
1737      if($config['database']['type'] == "pgsql")
1738      {
1739          $db->query("SELECT setval('{$config['database']['table_prefix']}attachtypes_atid_seq', (SELECT max(atid) FROM {$config['database']['table_prefix']}attachtypes));");
1740          $db->query("SELECT setval('{$config['database']['table_prefix']}forums_fid_seq', (SELECT max(fid) FROM {$config['database']['table_prefix']}forums));");
1741          $db->query("SELECT setval('{$config['database']['table_prefix']}helpdocs_hid_seq', (SELECT max(hid) FROM {$config['database']['table_prefix']}helpdocs));");
1742          $db->query("SELECT setval('{$config['database']['table_prefix']}helpsections_sid_seq', (SELECT max(sid) FROM {$config['database']['table_prefix']}helpsections));");
1743          $db->query("SELECT setval('{$config['database']['table_prefix']}icons_iid_seq', (SELECT max(iid) FROM {$config['database']['table_prefix']}icons));");
1744          $db->query("SELECT setval('{$config['database']['table_prefix']}profilefields_fid_seq', (SELECT max(fid) FROM {$config['database']['table_prefix']}profilefields));");
1745          $db->query("SELECT setval('{$config['database']['table_prefix']}smilies_sid_seq', (SELECT max(sid) FROM {$config['database']['table_prefix']}smilies));");
1746          $db->query("SELECT setval('{$config['database']['table_prefix']}spiders_sid_seq', (SELECT max(sid) FROM {$config['database']['table_prefix']}spiders));");
1747          $db->query("SELECT setval('{$config['database']['table_prefix']}templategroups_gid_seq', (SELECT max(gid) FROM {$config['database']['table_prefix']}templategroups));");
1748      }
1749  
1750      echo $lang->populate_step_inserted;
1751      $output->print_footer('templates');
1752  }
1753  
1754  /**
1755   * Install our theme
1756   */
1757  function insert_templates()
1758  {
1759      global $mybb, $output, $cache, $db, $lang;
1760  
1761      require MYBB_ROOT.'inc/config.php';
1762      $db = db_connection($config);
1763  
1764      require_once  MYBB_ROOT.'inc/class_datacache.php';
1765      $cache = new datacache;
1766  
1767      $output->print_header($lang->theme_installation, 'theme');
1768  
1769      echo $lang->theme_step_importing;
1770  
1771      $db->delete_query("themes");
1772      $db->delete_query("templates");
1773      $db->delete_query("themestylesheets");
1774      my_rmdir_recursive(MYBB_ROOT."cache/themes", array(MYBB_ROOT."cache/themes/index.html"));
1775  
1776      $insert_array = array(
1777          'title' => 'Default Templates'
1778      );
1779      $templateset = $db->insert_query("templatesets", $insert_array);
1780  
1781      $contents = @file_get_contents(INSTALL_ROOT.'resources/mybb_theme.xml');
1782      if(!empty($mybb->config['admin_dir']) && file_exists(MYBB_ROOT.$mybb->config['admin_dir']."/inc/functions_themes.php"))
1783      {
1784          require_once MYBB_ROOT.$mybb->config['admin_dir']."/inc/functions.php";
1785          require_once MYBB_ROOT.$mybb->config['admin_dir']."/inc/functions_themes.php";
1786      }
1787      elseif(file_exists(MYBB_ROOT."admin/inc/functions_themes.php"))
1788      {
1789          require_once  MYBB_ROOT."admin/inc/functions.php";
1790          require_once  MYBB_ROOT."admin/inc/functions_themes.php";
1791      }
1792      else
1793      {
1794          $output->print_error("Please make sure your admin directory is uploaded correctly.");
1795      }
1796      $theme_id = import_theme_xml($contents, array("templateset" => -2, "version_compat" => 1));
1797      $tid = build_new_theme("Default", null, $theme_id);
1798  
1799      // Update our properties template set to the correct one
1800      $query = $db->simple_select("themes", "stylesheets, properties", "tid='{$tid}'", array('limit' => 1));
1801  
1802      $theme = $db->fetch_array($query);
1803      $properties = my_unserialize($theme['properties']);
1804      $stylesheets = my_unserialize($theme['stylesheets']);
1805  
1806      $properties['templateset'] = $templateset;
1807      unset($properties['inherited']['templateset']);
1808  
1809      // 1.8: Stylesheet Colors
1810      $contents = @file_get_contents(INSTALL_ROOT.'resources/mybb_theme_colors.xml');
1811  
1812      $parser = create_xml_parser($contents);
1813      $tree = $parser->get_tree();
1814  
1815      if(is_array($tree) && is_array($tree['colors']))
1816      {
1817          if(is_array($tree['colors']['scheme']))
1818          {
1819              foreach($tree['colors']['scheme'] as $tag => $value)
1820              {
1821                  $exp = explode("=", $value['value']);
1822  
1823                  $properties['colors'][$exp[0]] = $exp[1];
1824              }
1825          }
1826  
1827          if(is_array($tree['colors']['stylesheets']))
1828          {
1829              $count = count($properties['disporder']) + 1;
1830              foreach($tree['colors']['stylesheets']['stylesheet'] as $stylesheet)
1831              {
1832                  $new_stylesheet = array(
1833                      "name" => $db->escape_string($stylesheet['attributes']['name']),
1834                      "tid" => $tid,
1835                      "attachedto" => $db->escape_string($stylesheet['attributes']['attachedto']),
1836                      "stylesheet" => $db->escape_string($stylesheet['value']),
1837                      "lastmodified" => TIME_NOW,
1838                      "cachefile" => $db->escape_string($stylesheet['attributes']['name'])
1839                  );
1840  
1841                  $sid = $db->insert_query("themestylesheets", $new_stylesheet);
1842                  $css_url = "css.php?stylesheet={$sid}";
1843  
1844                  $cached = cache_stylesheet($tid, $stylesheet['attributes']['name'], $stylesheet['value']);
1845  
1846                  if($cached)
1847                  {
1848                      $css_url = $cached;
1849                  }
1850  
1851                  // Add to display and stylesheet list
1852                  $properties['disporder'][$stylesheet['attributes']['name']] = $count;
1853                  $stylesheets[$stylesheet['attributes']['attachedto']]['global'][] = $css_url;
1854  
1855                  ++$count;
1856              }
1857          }
1858      }
1859  
1860      $db->update_query("themes", array("def" => 1, "properties" => $db->escape_string(my_serialize($properties)), "stylesheets" => $db->escape_string(my_serialize($stylesheets))), "tid = '{$tid}'");
1861  
1862      echo $lang->theme_step_imported;
1863      $output->print_footer('configuration');
1864  }
1865  
1866  /**
1867   * Default configuration
1868   */
1869  function configure()
1870  {
1871      global $output, $mybb, $errors, $lang;
1872  
1873      $output->print_header($lang->board_config, 'config');
1874  
1875      echo <<<EOF
1876          <script type="text/javascript">
1877  		function warnUser(inp, warn)
1878          {
1879              var parenttr = $('#'+inp.id).closest('tr');
1880              if(inp.value != inp.defaultValue)
1881              {
1882                  if(!parenttr.next('.setting_peeker').length)
1883                  {
1884                      var revertlink = ' <a href="javascript:revertSetting(\''+inp.defaultValue+'\', \'#'+inp.id+'\');">{$lang->config_step_revert}</a>';
1885                      parenttr.removeClass('last').after('<tr class="setting_peeker"><td colspan="2">'+warn+revertlink+'</td></tr>');
1886                  }
1887              } else {
1888                  parenttr.next('.setting_peeker').remove();
1889                  if(parenttr.is(':last-child'))
1890                  {
1891                      parenttr.addClass('last');
1892                  }
1893              }
1894          }
1895  
1896  		function revertSetting(defval, inpid)
1897          {
1898              $(inpid).val(defval);
1899              var parenttr = $(inpid).closest('tr');
1900              parenttr.next('.setting_peeker').remove();
1901              if(parenttr.is(':last-child'))
1902              {
1903                  parenttr.addClass('last');
1904              }
1905          }
1906          </script>
1907  
1908  EOF;
1909  
1910      // If board configuration errors
1911      if(is_array($errors))
1912      {
1913          $error_list = error_list($errors);
1914          echo $lang->sprintf($lang->config_step_error_config, $error_list);
1915  
1916          $bbname = htmlspecialchars_uni($mybb->get_input('bbname'));
1917          $bburl = htmlspecialchars_uni($mybb->get_input('bburl'));
1918          $websitename = htmlspecialchars_uni($mybb->get_input('websitename'));
1919          $websiteurl = htmlspecialchars_uni($mybb->get_input('websiteurl'));
1920          $cookiedomain = htmlspecialchars_uni($mybb->get_input('cookiedomain'));
1921          $cookiepath = htmlspecialchars_uni($mybb->get_input('cookiepath'));
1922          $contactemail =  htmlspecialchars_uni($mybb->get_input('contactemail'));
1923      }
1924      else
1925      {
1926          $bbname = 'Forums';
1927          $cookiedomain = '';
1928          $websitename = 'Your Website';
1929  
1930          $protocol = "http://";
1931          if((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != "off"))
1932          {
1933              $protocol = "https://";
1934          }
1935  
1936          // Attempt auto-detection
1937          if(!empty($_SERVER['HTTP_HOST']))
1938          {
1939              $hostname = $protocol.$_SERVER['HTTP_HOST'];
1940              $cookiedomain = $_SERVER['HTTP_HOST'];
1941          }
1942          elseif(!empty($_SERVER['SERVER_NAME']))
1943          {
1944              $hostname = $protocol.$_SERVER['SERVER_NAME'];
1945              $cookiedomain = $_SERVER['SERVER_NAME'];
1946          }
1947  
1948          if(my_substr($cookiedomain, 0, 4) == "www.")
1949          {
1950              $cookiedomain = substr($cookiedomain, 4);
1951          }
1952  
1953          // IP addresses and hostnames are not valid
1954          if(my_inet_pton($cookiedomain) !== false || strpos($cookiedomain, '.') === false)
1955          {
1956              $cookiedomain = '';
1957          }
1958          else
1959          {
1960              $cookiedomain = ".{$cookiedomain}";
1961          }
1962  
1963          if(!empty($_SERVER['SERVER_PORT']))
1964          {
1965              $port = ":{$_SERVER['SERVER_PORT']}";
1966              $pos = strrpos($cookiedomain, $port);
1967  
1968              if($pos !== false)
1969              {
1970                  $cookiedomain = substr($cookiedomain, 0, $pos);
1971              }
1972  
1973              if($_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443 && !preg_match("#:[0-9]#i", $hostname))
1974              {
1975                  $hostname .= $port;
1976              }
1977          }
1978  
1979          $currentlocation = get_current_location('', '', true);
1980          $noinstall = substr($currentlocation, 0, strrpos($currentlocation, '/install/'));
1981  
1982          $cookiepath = $noinstall.'/';
1983          $bburl = $hostname.$noinstall;
1984          $websiteurl = $hostname.'/';
1985  
1986          if(isset($_SERVER['SERVER_ADMIN']) && filter_var($_SERVER['SERVER_ADMIN'], FILTER_VALIDATE_EMAIL))
1987          {
1988              $contactemail = $_SERVER['SERVER_ADMIN'];
1989          }
1990          else
1991          {
1992              $contactemail = null;
1993          }
1994      }
1995  
1996      echo $lang->sprintf($lang->config_step_table, $bbname, $bburl, $websitename, $websiteurl, $cookiedomain, $cookiepath, $contactemail);
1997      $output->print_footer('adminuser');
1998  }
1999  
2000  /**
2001   * How do we want to name the admin user?
2002   */
2003  function create_admin_user()
2004  {
2005      global $output, $mybb, $errors, $db, $lang;
2006  
2007      $mybb->input['action'] = "adminuser";
2008      // If no errors then check for errors from last step
2009      if(!is_array($errors))
2010      {
2011          if(empty($mybb->input['bburl']))
2012          {
2013              $errors[] = $lang->config_step_error_url;
2014          }
2015          if(empty($mybb->input['bbname']))
2016          {
2017              $errors[] = $lang->config_step_error_name;
2018          }
2019          if(is_array($errors))
2020          {
2021              configure();
2022          }
2023      }
2024      $output->print_header($lang->create_admin, 'admin');
2025  
2026      echo <<<EOF
2027          <script type="text/javascript">
2028  		function comparePass()
2029          {
2030              var parenttr = $('#adminpass2').closest('tr');
2031              var passval = $('#adminpass2').val();
2032              if(passval && passval != $('#adminpass').val())
2033              {
2034                  if(!parenttr.next('.pass_peeker').length)
2035                  {
2036                      parenttr.removeClass('last').after('<tr class="pass_peeker"><td colspan="2">{$lang->admin_step_nomatch}</td></tr>');
2037                  }
2038              } else {
2039                  parenttr.addClass('last').next('.pass_peeker').remove();
2040              }
2041          }
2042          </script>
2043  
2044  EOF;
2045  
2046      if(is_array($errors))
2047      {
2048          $error_list = error_list($errors);
2049          echo $lang->sprintf($lang->admin_step_error_config, $error_list);
2050          $adminuser = $mybb->get_input('adminuser');
2051          $adminemail = $mybb->get_input('adminemail');
2052      }
2053      else
2054      {
2055          require MYBB_ROOT.'inc/config.php';
2056          $db = db_connection($config);
2057  
2058          echo $lang->admin_step_setupsettings;
2059          $adminuser = $adminemail = '';
2060  
2061          $settings = file_get_contents(INSTALL_ROOT.'resources/settings.xml');
2062          $parser = create_xml_parser($settings);
2063          $parser->collapse_dups = 0;
2064          $tree = $parser->get_tree();
2065          $groupcount = $settingcount = 0;
2066  
2067          // Insert all the settings
2068          foreach($tree['settings'][0]['settinggroup'] as $settinggroup)
2069          {
2070              $groupdata = array(
2071                  'name' => $db->escape_string($settinggroup['attributes']['name']),
2072                  'title' => $db->escape_string($settinggroup['attributes']['title']),
2073                  'description' => $db->escape_string($settinggroup['attributes']['description']),
2074                  'disporder' => (int)$settinggroup['attributes']['disporder'],
2075                  'isdefault' => $settinggroup['attributes']['isdefault'],
2076              );
2077              $gid = $db->insert_query('settinggroups', $groupdata);
2078              ++$groupcount;
2079              foreach($settinggroup['setting'] as $setting)
2080              {
2081                  $settingdata = array(
2082                      'name' => $db->escape_string($setting['attributes']['name']),
2083                      'title' => $db->escape_string($setting['title'][0]['value']),
2084                      'description' => $db->escape_string($setting['description'][0]['value']),
2085                      'optionscode' => $db->escape_string($setting['optionscode'][0]['value']),
2086                      'value' => $db->escape_string($setting['settingvalue'][0]['value']),
2087                      'disporder' => (int)$setting['disporder'][0]['value'],
2088                      'gid' => $gid,
2089                      'isdefault' => 1
2090                  );
2091  
2092                  $db->insert_query('settings', $settingdata);
2093                  $settingcount++;
2094              }
2095          }
2096  
2097          if(my_substr($mybb->get_input('bburl'), -1, 1) == '/')
2098          {
2099              $mybb->input['bburl'] = my_substr($mybb->get_input('bburl'), 0, -1);
2100          }
2101  
2102          $db->update_query("settings", array('value' => $db->escape_string($mybb->get_input('bbname'))), "name='bbname'");
2103          $db->update_query("settings", array('value' => $db->escape_string($mybb->get_input('bburl'))), "name='bburl'");
2104          $db->update_query("settings", array('value' => $db->escape_string($mybb->get_input('websitename'))), "name='homename'");
2105          $db->update_query("settings", array('value' => $db->escape_string($mybb->get_input('websiteurl'))), "name='homeurl'");
2106          $db->update_query("settings", array('value' => $db->escape_string($mybb->get_input('cookiedomain'))), "name='cookiedomain'");
2107          $db->update_query("settings", array('value' => $db->escape_string($mybb->get_input('cookiepath'))), "name='cookiepath'");
2108          $db->update_query("settings", array('value' => $db->escape_string($mybb->get_input('contactemail'))), "name='adminemail'");
2109          $db->update_query("settings", array('value' => 'contact.php'), "name='contactlink'");
2110  
2111          write_settings();
2112  
2113          echo $lang->sprintf($lang->admin_step_insertesettings, $settingcount, $groupcount);
2114  
2115          // Save the acp pin
2116          $pin = addslashes($mybb->get_input('pin'));
2117  
2118          $file = @fopen(MYBB_ROOT."inc/config.php", "a");
2119  
2120          @fwrite($file, "/**
2121   * Admin CP Secret PIN
2122   *  If you wish to request a PIN
2123   *  when someone tries to login
2124   *  on your Admin CP, enter it below.
2125   */
2126  
2127  \$config['secret_pin'] = '{$pin}';");
2128  
2129          @fclose($file);
2130  
2131          include_once  MYBB_ROOT."inc/functions_task.php";
2132          $tasks = file_get_contents(INSTALL_ROOT.'resources/tasks.xml');
2133          $parser = create_xml_parser($tasks);
2134          $parser->collapse_dups = 0;
2135          $tree = $parser->get_tree();
2136          $taskcount = 0;
2137  
2138          // Insert scheduled tasks
2139          foreach($tree['tasks'][0]['task'] as $task)
2140          {
2141              $new_task = array(
2142                  'title' => $db->escape_string($task['title'][0]['value']),
2143                  'description' => $db->escape_string($task['description'][0]['value']),
2144                  'file' => $db->escape_string($task['file'][0]['value']),
2145                  'minute' => $db->escape_string($task['minute'][0]['value']),
2146                  'hour' => $db->escape_string($task['hour'][0]['value']),
2147                  'day' => $db->escape_string($task['day'][0]['value']),
2148                  'weekday' => $db->escape_string($task['weekday'][0]['value']),
2149                  'month' => $db->escape_string($task['month'][0]['value']),
2150                  'enabled' => $db->escape_string($task['enabled'][0]['value']),
2151                  'logging' => $db->escape_string($task['logging'][0]['value'])
2152              );
2153  
2154              $new_task['nextrun'] = fetch_next_run($new_task);
2155  
2156              $db->insert_query("tasks", $new_task);
2157              $taskcount++;
2158          }
2159  
2160          // 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)
2161          $update_array = array(
2162              'hour' => rand(0, 23),
2163              'weekday' => rand(0, 6)
2164          );
2165  
2166          $db->update_query("tasks", $update_array, "file = 'versioncheck'");
2167  
2168          echo $lang->sprintf($lang->admin_step_insertedtasks, $taskcount);
2169  
2170          $views = file_get_contents(INSTALL_ROOT.'resources/adminviews.xml');
2171          $parser = create_xml_parser($views);
2172          $parser->collapse_dups = 0;
2173          $tree = $parser->get_tree();
2174          $view_count = 0;
2175  
2176          // Insert admin views
2177          foreach($tree['adminviews'][0]['view'] as $view)
2178          {
2179              $fields = array();
2180              foreach($view['fields'][0]['field'] as $field)
2181              {
2182                  $fields[] = $field['attributes']['name'];
2183              }
2184  
2185              $conditions = array();
2186              if(isset($view['conditions'][0]['condition']) && is_array($view['conditions'][0]['condition']))
2187              {
2188                  foreach($view['conditions'][0]['condition'] as $condition)
2189                  {
2190                      if(!$condition['value']) continue;
2191                      if($condition['attributes']['is_serialized'] == 1)
2192                      {
2193                          $condition['value'] = my_unserialize($condition['value']);
2194                      }
2195                      $conditions[$condition['attributes']['name']] = $condition['value'];
2196                  }
2197              }
2198  
2199              $custom_profile_fields = array();
2200              if(isset($view['custom_profile_fields'][0]['field']) && is_array($view['custom_profile_fields'][0]['field']))
2201              {
2202                  foreach($view['custom_profile_fields'][0]['field'] as $field)
2203                  {
2204                      $custom_profile_fields[] = $field['attributes']['name'];
2205                  }
2206              }
2207  
2208              $new_view = array(
2209                  "uid" => 0,
2210                  "type" => $db->escape_string($view['attributes']['type']),
2211                  "visibility" => (int)$view['attributes']['visibility'],
2212                  "title" => $db->escape_string($view['title'][0]['value']),
2213                  "fields" => $db->escape_string(my_serialize($fields)),
2214                  "conditions" => $db->escape_string(my_serialize($conditions)),
2215                  "custom_profile_fields" => $db->escape_string(my_serialize($custom_profile_fields)),
2216                  "sortby" => $db->escape_string($view['sortby'][0]['value']),
2217                  "sortorder" => $db->escape_string($view['sortorder'][0]['value']),
2218                  "perpage" => (int)$view['perpage'][0]['value'],
2219                  "view_type" => $db->escape_string($view['view_type'][0]['value'])
2220              );
2221              $db->insert_query("adminviews", $new_view);
2222              $view_count++;
2223          }
2224  
2225          echo $lang->sprintf($lang->admin_step_insertedviews, $view_count);
2226  
2227          echo $lang->admin_step_createadmin;
2228      }
2229  
2230      echo $lang->sprintf($lang->admin_step_admintable, $adminuser, $adminemail);
2231      $output->print_footer('final');
2232  }
2233  
2234  /**
2235   * Installation is finished
2236   */
2237  function install_done()
2238  {
2239      global $output, $db, $mybb, $errors, $cache, $lang;
2240  
2241      if(empty($mybb->input['adminuser']))
2242      {
2243          $errors[] = $lang->admin_step_error_nouser;
2244      }
2245      if(empty($mybb->input['adminpass']))
2246      {
2247          $errors[] = $lang->admin_step_error_nopassword;
2248      }
2249      if($mybb->get_input('adminpass') != $mybb->get_input('adminpass2'))
2250      {
2251          $errors[] = $lang->admin_step_error_nomatch;
2252      }
2253      if(empty($mybb->input['adminemail']))
2254      {
2255          $errors[] = $lang->admin_step_error_noemail;
2256      }
2257      if(is_array($errors))
2258      {
2259          create_admin_user();
2260      }
2261  
2262      require MYBB_ROOT.'inc/config.php';
2263      $db = db_connection($config);
2264  
2265      require  MYBB_ROOT.'inc/settings.php';
2266      $mybb->settings = &$settings;
2267  
2268      ob_start();
2269      $output->print_header($lang->finish_setup, 'finish');
2270  
2271      echo $lang->done_step_usergroupsinserted;
2272  
2273      // Insert all of our user groups from the XML file
2274      $usergroup_settings = file_get_contents(INSTALL_ROOT.'resources/usergroups.xml');
2275      $parser = create_xml_parser($usergroup_settings);
2276      $parser->collapse_dups = 0;
2277      $tree = $parser->get_tree();
2278  
2279      $admin_gid = '';
2280      $group_count = 0;
2281      foreach($tree['usergroups'][0]['usergroup'] as $usergroup)
2282      {
2283          // usergroup[cancp][0][value]
2284          $new_group = array();
2285          foreach($usergroup as $key => $value)
2286          {
2287              if(!is_array($value))
2288              {
2289                  continue;
2290              }
2291  
2292              $new_group[$key] = $db->escape_string($value[0]['value']);
2293          }
2294          $db->insert_query("usergroups", $new_group, false);
2295  
2296          // 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)
2297          if($new_group['cancp'] == 1 && !$admin_gid)
2298          {
2299              $admin_gid = $usergroup['gid'][0]['value'];
2300          }
2301          $group_count++;
2302      }
2303  
2304      // Restart usergroup sequence with correct # of groups
2305      if($config['database']['type'] == "pgsql")
2306      {
2307          $db->query("SELECT setval('{$config['database']['table_prefix']}usergroups_gid_seq', (SELECT max(gid) FROM {$config['database']['table_prefix']}usergroups));");
2308      }
2309  
2310      echo $lang->done . '</p>';
2311  
2312      echo $lang->done_step_admincreated;
2313      $now = TIME_NOW;
2314      $salt = random_str();
2315      $loginkey = generate_loginkey();
2316      $saltedpw = md5(md5($salt).md5($mybb->get_input('adminpass')));
2317  
2318      $newuser = array(
2319          'username' => $db->escape_string($mybb->get_input('adminuser')),
2320          'password' => $saltedpw,
2321          'salt' => $salt,
2322          'loginkey' => $loginkey,
2323          'email' => $db->escape_string($mybb->get_input('adminemail')),
2324          'usergroup' => $admin_gid, // assigned above
2325          'regdate' => $now,
2326          'lastactive' => $now,
2327          'lastvisit' => $now,
2328          'website' => '',
2329          'icq' => '',
2330          'skype' =>'',
2331          'google' =>'',
2332          'birthday' => '',
2333          'signature' => '',
2334          'allownotices' => 1,
2335          'hideemail' => 0,
2336          'subscriptionmethod' => '0',
2337          'receivepms' => 1,
2338          'pmnotice' => 1,
2339          'pmnotify' => 1,
2340          'buddyrequestspm' => 1,
2341          'buddyrequestsauto' => 0,
2342          'showimages' => 1,
2343          'showvideos' => 1,
2344          'showsigs' => 1,
2345          'showavatars' => 1,
2346          'showquickreply' => 1,
2347          'invisible' => 0,
2348          'style' => '0',
2349          'timezone' => 0,
2350          'dst' => 0,
2351          'threadmode' => '',
2352          'daysprune' => 0,
2353          'regip' => $db->escape_binary(my_inet_pton(get_ip())),
2354          'language' => '',
2355          'showcodebuttons' => 1,
2356          'tpp' => 0,
2357          'ppp' => 0,
2358          'referrer' => 0,
2359          'buddylist' => '',
2360          'ignorelist' => '',
2361          'pmfolders' => "0**$%%$1**$%%$2**$%%$3**$%%$4**",
2362          'notepad' => '',
2363          'showredirect' => 1,
2364          'usernotes' => ''
2365      );
2366      $db->insert_query('users', $newuser);
2367      echo $lang->done . '</p>';
2368  
2369      echo $lang->done_step_adminoptions;
2370      $adminoptions = file_get_contents(INSTALL_ROOT.'resources/adminoptions.xml');
2371      $parser = create_xml_parser($adminoptions);
2372      $parser->collapse_dups = 0;
2373      $tree = $parser->get_tree();
2374      $insertmodule = array();
2375  
2376      $db->delete_query("adminoptions");
2377  
2378      // Insert all the admin permissions
2379      foreach($tree['adminoptions'][0]['user'] as $users)
2380      {
2381          $uid = $users['attributes']['uid'];
2382  
2383          foreach($users['permissions'][0]['module'] as $module)
2384          {
2385              foreach($module['permission'] as $permission)
2386              {
2387                  $insertmodule[$module['attributes']['name']][$permission['attributes']['name']] = $permission['value'];
2388              }
2389          }
2390  
2391          $defaultviews = array();
2392          foreach($users['defaultviews'][0]['view'] as $view)
2393          {
2394              $defaultviews[$view['attributes']['type']] = $view['value'];
2395          }
2396  
2397          $adminoptiondata = array(
2398              'uid' => (int)$uid,
2399              'cpstyle' => '',
2400              'notes' => '',
2401              'permissions' => $db->escape_string(my_serialize($insertmodule)),
2402              'defaultviews' => $db->escape_string(my_serialize($defaultviews))
2403          );
2404  
2405          $insertmodule = array();
2406  
2407          $db->insert_query('adminoptions', $adminoptiondata);
2408      }
2409      echo $lang->done . '</p>';
2410  
2411      // Automatic Login
2412      my_unsetcookie("sid");
2413      my_unsetcookie("mybbuser");
2414      my_setcookie('mybbuser', $uid.'_'.$loginkey, null, true, "lax");
2415      ob_end_flush();
2416  
2417      // Make fulltext columns if supported
2418      if($db->supports_fulltext('threads'))
2419      {
2420          $db->create_fulltext_index('threads', 'subject');
2421      }
2422      if($db->supports_fulltext_boolean('posts'))
2423      {
2424          $db->create_fulltext_index('posts', 'message');
2425      }
2426  
2427      echo $lang->done_step_cachebuilding;
2428      require_once  MYBB_ROOT.'inc/class_datacache.php';
2429      $cache = new datacache;
2430      $cache->update_version();
2431      $cache->update_attachtypes();
2432      $cache->update_smilies();
2433      $cache->update_badwords();
2434      $cache->update_usergroups();
2435      $cache->update_forumpermissions();
2436      $cache->update_stats();
2437      $cache->update_statistics();
2438      $cache->update_forums();
2439      $cache->update_moderators();
2440      $cache->update_usertitles();
2441      $cache->update_reportedcontent();
2442      $cache->update_awaitingactivation();
2443      $cache->update_mycode();
2444      $cache->update_profilefields();
2445      $cache->update_posticons();
2446      $cache->update_spiders();
2447      $cache->update_bannedips();
2448      $cache->update_bannedemails();
2449      $cache->update_birthdays();
2450      $cache->update_groupleaders();
2451      $cache->update_threadprefixes();
2452      $cache->update_forumsdisplay();
2453      $cache->update("plugins", array());
2454      $cache->update("mostonline", array(
2455          'numusers' => 0,
2456          'time' => 0,
2457      ));
2458      $cache->update("internal_settings", array('encryption_key' => random_str(32)));
2459      $cache->update_default_theme();
2460      $cache->update_reportreasons(true);
2461  
2462      $version_history = array();
2463      $dh = opendir(INSTALL_ROOT."resources");
2464      while(($file = readdir($dh)) !== false)
2465      {
2466          if(preg_match("#upgrade([0-9]+).php$#i", $file, $match))
2467          {
2468              $version_history[$match[1]] = $match[1];
2469          }
2470      }
2471      sort($version_history, SORT_NUMERIC);
2472      $cache->update("version_history", $version_history);
2473  
2474      // Schedule an update check so it occurs an hour ago.  Gotta stay up to date!
2475      $update['nextrun'] = TIME_NOW - 3600;
2476      $db->update_query("tasks", $update, "tid='12'");
2477  
2478      $cache->update_update_check();
2479      $cache->update_tasks();
2480  
2481      echo $lang->done . '</p>';
2482  
2483      echo $lang->done_step_success;
2484  
2485      $written = 0;
2486      if(is_writable('./'))
2487      {
2488          $lock = @fopen('./lock', 'w');
2489  
2490          if($lock !== false)
2491          {
2492              $written = @fwrite($lock, '1');
2493              @fclose($lock);
2494  
2495              if($written)
2496              {
2497                  echo $lang->done_step_locked;
2498              }
2499          }
2500      }
2501      if(!$written)
2502      {
2503          echo $lang->done_step_dirdelete;
2504      }
2505      echo $lang->done_whats_next;
2506      $output->print_footer('');
2507  }
2508  
2509  /**
2510   * @param array $config
2511   *
2512   * @return DB_MySQL|DB_MySQLi|DB_PgSQL|DB_SQLite|PostgresPdoDbDriver|MysqlPdoDbDriver
2513   */
2514  function db_connection($config)
2515  {
2516      require_once MYBB_ROOT."inc/db_{$config['database']['type']}.php";
2517      switch($config['database']['type'])
2518      {
2519          case "sqlite":
2520              $db = new DB_SQLite;
2521              break;
2522          case "pgsql":
2523              $db = new DB_PgSQL;
2524              break;
2525          case "pgsql_pdo":
2526              $db = new PostgresPdoDbDriver();
2527              break;
2528          case "mysqli":
2529              $db = new DB_MySQLi;
2530              break;
2531          case "mysql_pdo":
2532              $db = new MysqlPdoDbDriver();
2533              break;
2534          default:
2535              $db = new DB_MySQL;
2536      }
2537  
2538      // Connect to Database
2539      define('TABLE_PREFIX', $config['database']['table_prefix']);
2540  
2541      $db->connect($config['database']);
2542      $db->set_table_prefix(TABLE_PREFIX);
2543      $db->type = $config['database']['type'];
2544  
2545      return $db;
2546  }
2547  
2548  /**
2549   * @param array $array
2550   *
2551   * @return string
2552   */
2553  function error_list($array)
2554  {
2555      $string = "<ul>\n";
2556      foreach($array as $error)
2557      {
2558          $string .= "<li>{$error}</li>\n";
2559      }
2560      $string .= "</ul>\n";
2561      return $string;
2562  }
2563  
2564  /**
2565   * Write our settings to the settings file
2566   */
2567  function write_settings()
2568  {
2569      global $db;
2570  
2571      $settings = '';
2572      $query = $db->simple_select('settings', '*', '', array('order_by' => 'title'));
2573      while($setting = $db->fetch_array($query))
2574      {
2575          $setting['name'] = addcslashes($setting['name'], "\\'");
2576          $setting['value'] = addcslashes($setting['value'], '\\"$');
2577          $settings .= "\$settings['{$setting['name']}'] = \"{$setting['value']}\";\n";
2578      }
2579      if(!empty($settings))
2580      {
2581          $settings = "<?php\n/*********************************\ \n  DO NOT EDIT THIS FILE, PLEASE USE\n  THE SETTINGS EDITOR\n\*********************************/\n\n{$settings}\n";
2582          $file = fopen(MYBB_ROOT."inc/settings.php", "w");
2583          fwrite($file, $settings);
2584          fclose($file);
2585      }
2586  }


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