PageRenderTime 50ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/install/doinstall.php

https://bitbucket.org/GlitchMr/abxd
PHP | 155 lines | 142 code | 13 blank | 0 comment | 6 complexity | 33f3fa544de08691aa0d81e0a70e80cf MD5 | raw file
  1. <?php
  2. chdir("../");
  3. function cdate($format, $date = 0)
  4. {
  5. global $loguser;
  6. if($date == 0)
  7. $date = gmmktime();
  8. $hours = (int)($loguser['timezone']/3600);
  9. $minutes = floor(abs($loguser['timezone']/60)%60);
  10. $plusOrMinus = $hours < 0 ? "" : "+";
  11. $timeOffset = $plusOrMinus.$hours." hours, ".$minutes." minutes";
  12. return gmdate($format, strtotime($timeOffset, $date));
  13. }
  14. include("lib/mysqlfunctions.php");
  15. $overallTidy = 0;
  16. function insError($text) {
  17. 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>.";
  18. die();
  19. }
  20. ob_start();
  21. if(file_exists("lib/database.php"))
  22. insError("ERROR: Board is already installed. Please delete /lib/database.php to run installation again.");
  23. print "Starting ABXD installation.<br />";
  24. print "Writing database configuration file&hellip;<br />";
  25. if(isset($_POST['dbserv']))
  26. {
  27. $dbserv = $_POST['dbserv'];
  28. $dbuser = $_POST['dbuser'];
  29. $dbpass = $_POST['dbpass'];
  30. $dbname = $_POST['dbname'];
  31. }
  32. else
  33. include("lib/database.php");
  34. $dblink = @new mysqli($dbserv, $dbuser, $dbpass);
  35. if ($dblink->connect_error) {
  36. insError(
  37. "Could not connect to the MySQL server. Are you sure you entered
  38. the right things in the SQL credentials page?<br />
  39. The following info was supplied:<br />
  40. Server: ".$dbserv."<br />
  41. Username: ".$dbuser."<br />
  42. Password: (not shown)<br />
  43. Database: ".$dbname."<br />
  44. SQL error: ".$dblink->connect_error);
  45. }
  46. if (!$dblink->select_db($dbname)) {
  47. insError(
  48. "Could not select the database. Try creating it. <br>
  49. (The installer doesn't create it automatically for you)");
  50. }
  51. $dbcfg = @fopen("lib/database.php", "w+")
  52. or insError(
  53. "Could not open the database configuration file (lib/database.php) for writing.<br>
  54. Make sure that PHP has access to this file.");
  55. fwrite($dbcfg, "<?php\n");
  56. fwrite($dbcfg, "// AcmlmBoard XD support - Database settings\n\n");
  57. fwrite($dbcfg, "\$dbserv = \"".$dbserv."\";\n");
  58. fwrite($dbcfg, "\$dbuser = \"".$dbuser."\";\n");
  59. fwrite($dbcfg, "\$dbpass = \"".$dbpass."\";\n");
  60. fwrite($dbcfg, "\$dbname = \"".$dbname."\";\n");
  61. fwrite($dbcfg, "\n?>");
  62. fclose($dbcfg);
  63. include("lib/mysql.php");
  64. $shakeIt = false;
  65. if(!is_file("lib/salt.php"))
  66. $shakeIt = true;
  67. else
  68. {
  69. include("lib/salt.php");
  70. if(!isset($salt))
  71. $shakeIt = true;
  72. }
  73. if($shakeIt)
  74. {
  75. print "Generating security salt&hellip;<br />";
  76. $cset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPRQSTUVWXYZ0123456789";
  77. $salt = "";
  78. $chct = strlen($cset) - 1;
  79. while (strlen($salt) < 16)
  80. $salt .= $cset[mt_rand(0, $chct)];
  81. $sltf = @fopen("lib/salt.php", "w+")
  82. or insError(
  83. "Could not open \"lib/salt.php\" for writing. <br>
  84. This has been checked for earlier, so if you see this error now,
  85. something very strange is going on.");
  86. fwrite($sltf, "<?php \$salt = \"".$salt."\" ?>");
  87. fclose($sltf);
  88. }
  89. else
  90. print "NOT generating security salt. (Already present)<br />";
  91. print "Creating or updating tables&hellip;<br />";
  92. Upgrade();
  93. print "Adding bare neccesities&hellip;<br />";
  94. $misc = Query("select * from misc");
  95. if(NumRows($misc) == 0)
  96. 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.');");
  97. Query("UPDATE `misc` SET `version` = 222");
  98. print "Importing smilies&hellip;<br />";
  99. $smilies = Query("select * from smilies");
  100. if(NumRows($smilies) == 0)
  101. Import("install/smilies.sql");
  102. if(isset($_POST['addbase']))
  103. {
  104. print "Creating starting fora&hellip;<br />";
  105. Import("install/installDefaults.sql");
  106. }
  107. $output = ob_get_clean();
  108. //Finished!
  109. if ($existingSettings)
  110. print "<h3>Board update successful.</h3><br /><br />
  111. <a href=\"../index.php\">Go back to the board</a>";
  112. else
  113. print "
  114. <h3>Installation successful</h3>
  115. <p>
  116. Your board has been successfully set up. You can view the installation output below if you want.<br />
  117. <button onclick=\"$('#installOutput').toggle();\">Show installation output</button><br />
  118. <div id=\"installOutput\" style=\"display: none;\">".$output."</div>
  119. </p>
  120. <p>
  121. <a href=\".\">Go to the board</a> &mdash; everything should be set up and ready to go.<br />
  122. <a href=\"?page=register\">Register the first user</a> &mdash; the first registered user will be root.
  123. </p>
  124. ";
  125. ?>