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