/install/doinstall.php
PHP | 155 lines | 142 code | 13 blank | 0 comment | 6 complexity | 33f3fa544de08691aa0d81e0a70e80cf MD5 | raw file
- <?php
-
- chdir("../");
-
- function cdate($format, $date = 0)
- {
- global $loguser;
- if($date == 0)
- $date = gmmktime();
- $hours = (int)($loguser['timezone']/3600);
- $minutes = floor(abs($loguser['timezone']/60)%60);
- $plusOrMinus = $hours < 0 ? "" : "+";
- $timeOffset = $plusOrMinus.$hours." hours, ".$minutes." minutes";
- return gmdate($format, strtotime($timeOffset, $date));
- }
-
-
- include("lib/mysqlfunctions.php");
- $overallTidy = 0;
-
- function insError($text) {
- print $text."<br /><strong onload=\"reenableControls();\">Installation error occoured.</strong> <button onclick=\"reenableControls(); page = 2; setStep(2);\">Go back</button> to the previous pages and correct the errors, then <button onclick=\"doInstall();\">click here</button>.";
- die();
- }
-
- ob_start();
-
- if(file_exists("lib/database.php"))
- insError("ERROR: Board is already installed. Please delete /lib/database.php to run installation again.");
-
- print "Starting ABXD installation.<br />";
- print "Writing database configuration file…<br />";
-
- if(isset($_POST['dbserv']))
- {
- $dbserv = $_POST['dbserv'];
- $dbuser = $_POST['dbuser'];
- $dbpass = $_POST['dbpass'];
- $dbname = $_POST['dbname'];
- }
- else
- include("lib/database.php");
-
- $dblink = @new mysqli($dbserv, $dbuser, $dbpass);
-
- if ($dblink->connect_error) {
- insError(
- "Could not connect to the MySQL server. Are you sure you entered
- the right things in the SQL credentials page?<br />
- The following info was supplied:<br />
- Server: ".$dbserv."<br />
- Username: ".$dbuser."<br />
- Password: (not shown)<br />
- Database: ".$dbname."<br />
- SQL error: ".$dblink->connect_error);
- }
-
- if (!$dblink->select_db($dbname)) {
- insError(
- "Could not select the database. Try creating it. <br>
- (The installer doesn't create it automatically for you)");
- }
-
- $dbcfg = @fopen("lib/database.php", "w+")
- or insError(
- "Could not open the database configuration file (lib/database.php) for writing.<br>
- Make sure that PHP has access to this file.");
-
- fwrite($dbcfg, "<?php\n");
- fwrite($dbcfg, "// AcmlmBoard XD support - Database settings\n\n");
- fwrite($dbcfg, "\$dbserv = \"".$dbserv."\";\n");
- fwrite($dbcfg, "\$dbuser = \"".$dbuser."\";\n");
- fwrite($dbcfg, "\$dbpass = \"".$dbpass."\";\n");
- fwrite($dbcfg, "\$dbname = \"".$dbname."\";\n");
- fwrite($dbcfg, "\n?>");
- fclose($dbcfg);
-
- include("lib/mysql.php");
-
- $shakeIt = false;
- if(!is_file("lib/salt.php"))
- $shakeIt = true;
- else
- {
- include("lib/salt.php");
- if(!isset($salt))
- $shakeIt = true;
- }
-
- if($shakeIt)
- {
- print "Generating security salt…<br />";
- $cset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPRQSTUVWXYZ0123456789";
- $salt = "";
- $chct = strlen($cset) - 1;
- while (strlen($salt) < 16)
- $salt .= $cset[mt_rand(0, $chct)];
-
- $sltf = @fopen("lib/salt.php", "w+")
- or insError(
- "Could not open \"lib/salt.php\" for writing. <br>
- This has been checked for earlier, so if you see this error now,
- something very strange is going on.");
-
- fwrite($sltf, "<?php \$salt = \"".$salt."\" ?>");
- fclose($sltf);
- }
- else
- print "NOT generating security salt. (Already present)<br />";
-
-
- print "Creating or updating tables…<br />";
- Upgrade();
-
- print "Adding bare neccesities…<br />";
- $misc = Query("select * from misc");
- if(NumRows($misc) == 0)
- Query("INSERT INTO `misc` (`views`, `hotcount`, `porabox`, `poratitle`, `milestone`, `maxuserstext`) VALUES (0, 30, '<a href=\"http://github.org/Dirbaio/ABXD\">ABXD repository on GitHub </a><br /><br />Then, <a href=\"editpora.php\">edit this panel</a>.', 'Points of Required Attention', 'Nothing yet.', 'Nobody yet.');");
-
- Query("UPDATE `misc` SET `version` = 222");
-
- print "Importing smilies…<br />";
-
- $smilies = Query("select * from smilies");
- if(NumRows($smilies) == 0)
- Import("install/smilies.sql");
-
- if(isset($_POST['addbase']))
- {
- print "Creating starting fora…<br />";
- Import("install/installDefaults.sql");
- }
-
- $output = ob_get_clean();
-
- //Finished!
-
- if ($existingSettings)
- print "<h3>Board update successful.</h3><br /><br />
- <a href=\"../index.php\">Go back to the board</a>";
- else
- print "
- <h3>Installation successful</h3>
- <p>
- Your board has been successfully set up. You can view the installation output below if you want.<br />
- <button onclick=\"$('#installOutput').toggle();\">Show installation output</button><br />
- <div id=\"installOutput\" style=\"display: none;\">".$output."</div>
- </p>
- <p>
- <a href=\".\">Go to the board</a> — everything should be set up and ready to go.<br />
- <a href=\"?page=register\">Register the first user</a> — the first registered user will be root.
- </p>
- ";
-
- ?>