[ Index ]

PHP Cross Reference of MyBB 1.6.5

title

Body

[close]

/install/ -> index.php (source)

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


Generated: Sun Dec 11 14:16:27 2011 Cross-referenced by PHPXref 0.7.1