install.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?PHP
  2. error_reporting(E_ALL);
  3. ini_set('display_errors', '1');
  4. date_default_timezone_set("America/Denver"); //Leave me alone.
  5. if (isset($_GET['back']))
  6. $back=true;
  7. else
  8. $back=false;
  9. session_start();
  10. if (!isset($_SESSION['stage']))
  11. $_SESSION['stage']=0;
  12. else
  13. if($back)
  14. $_SESSION['stage']--;
  15. else
  16. $_SESSION['stage']++;
  17. if ($_SESSION['stage'] < 0) $_SESSION['stage']++;
  18. $stage = $_SESSION['stage'];
  19. if (!isset($_SESSION['server'])) $_SESSION['server'] = "";
  20. if (!isset($_SESSION['database'])) $_SESSION['database'] = "";
  21. if (!isset($_SESSION['username'])) $_SESSION['username'] = "";
  22. if (!isset($_SESSION['password'])) $_SESSION['password'] = "";
  23. if (!isset($_SESSION['hostname'])) $_SESSION['hostname'] = "";
  24. ?>
  25. <html>
  26. <head>
  27. <title>OmnomIRC Installer</title>
  28. </head>
  29. <body>
  30. OmnomIRC installer<br/>
  31. <form action="install.php" method="post">
  32. <?PHP
  33. switch($stage)
  34. {
  35. case 0://Welcome
  36. echo "Welcome to OmnomIRC! This is the installer. To use OmnomIRC, you must have a PHP install and a MySQL server.<br/>";
  37. echo '<input type="submit" value="Next"/>';
  38. break;
  39. case 1://I am bender, please insert data
  40. echo 'I need a few pieces of information from you to set up OmnomIRC.<br/>';
  41. if (isset($_SESSION['error']))
  42. {
  43. echo ($_SESSION['error']);
  44. unset($_SESSION['error']);
  45. }
  46. echo 'SQL Info:<br/>
  47. <table>
  48. <tr><td>
  49. <label for="server">Server:</label>
  50. </td><td>
  51. <input type="text" name="server" id="server" value="'.$_SESSION['server'].'"/><br/>
  52. </td></tr><tr><td>
  53. <label for="database">Database:</label>
  54. </td><td>
  55. <input type="text" name="database" id="database" value="'.$_SESSION['database'].'"/><br/>
  56. </td></tr><tr><td>
  57. <label for="username">Username:</label>
  58. </td><td>
  59. <input type="text" name="username" id="username" value="'.$_SESSION['username'].'"/><br/>
  60. </td></tr><tr><td>
  61. <label for="password">Password:</label>
  62. </td><td>
  63. <input type="password" name="password" id="password"/>
  64. </td></tr><tr><td>
  65. <label for="hostname">Hostname (the one OmnomIRC is on):</label>
  66. </td><td>
  67. <input type="text" name="hostname" id="hostname" value="'.$_SESSION['hostname'].'"/><br/>
  68. </td></tr>
  69. </table>';
  70. echo '<br/><input type="button" value="Back" onclick="window.location=\'install.php?back=1\';"/>';
  71. echo '<input type="submit" value="Next"/>';
  72. break;
  73. case 2://Confirmation
  74. if ($_POST['server']=="") $_SESSION['error'] = '<span style="color:#F00">Please enter a server</span><br/>';
  75. if ($_POST['database']=="") $_SESSION['error'] = $_SESSION['error'] . '<span style="color:#F00">Please enter a database</span><br/>';
  76. if ($_POST['username']=="") $_SESSION['error'] = $_SESSION['error'] . '<span style="color:#F00">Please enter a username</span><br/>';
  77. if ($_POST['password']=="") $_SESSION['error'] = $_SESSION['error'] . '<span style="color:#F00">Please enter a password</span><br/>';
  78. if ($_POST['hostname']=="") $_SESSION['error'] = $_SESSION['error'] . '<span style="color:#F00">Please enter a hostname</dpan><br/>';
  79. $_SESSION['server'] = $_POST['server'];
  80. $_SESSION['database'] = $_POST['database'];
  81. $_SESSION['username'] = $_POST['username'];
  82. $_SESSION['password'] = $_POST['password'];
  83. $_SESSION['hostname'] = $_POST['hostname'];
  84. if (isset($_SESSION['error']))
  85. {
  86. $_SESSION['stage'] = 0;
  87. echo '<script type="text/javascript">window.location.reload(true);</script>';
  88. break;
  89. }
  90. $sql_connection=mysql_connect($_POST['server'],$_POST['username'],$_POST['password']);
  91. if (!$sql_connection)
  92. $_SESSION['error'] = $_SESSION['error'] . '<span style="color:#F00">Could not connect to server. Please check your input again.</span><br/>';
  93. if (isset($_SESSION['error']))
  94. {
  95. $_SESSION['stage'] = 0;
  96. echo '<script type="text/javascript">window.location.reload(true);</script>';
  97. }
  98. if (mysql_select_db($_POST['database'],$sql_connection))
  99. echo '<span style="font-size;18pt;color:#AA0">WARNING</span><br/><span style="color:#AA0">Database ' . $_POST['database'] . ' already exists! If you continue, all data in it will be lost!<br/>Click back to enter a new database name</span><br/>';
  100. echo '<span style="color:#0A0">Your data checks out! Hit next to install.</span>';
  101. echo '<br/><input type="button" value="Back" onclick="window.location=\'install.php?back=1\';"/>';
  102. echo '<input type="submit" value="Next"/>';
  103. break;
  104. case 3://Success
  105. $randKey = rand(100,9999).'-'.Rand(10000,999999);
  106. $randKey = md5($randKey);
  107. $randKey = base64_encode($randKey);
  108. $randKey = md5($randKey);
  109. $config = '<?PHP
  110. $sql_server="'.$_SESSION['server'].'";
  111. $sql_db="'.$_SESSION['database'].'";
  112. $sql_user="'.$_SESSION['username'].'";
  113. $sql_password="'.$_SESSION['password'].'";
  114. $signature_key="'.$randKey.'";
  115. ?>';
  116. if (file_put_contents("config.php",$config))
  117. echo "Config written<br/>";
  118. else
  119. echo "I could not write to the config file. Please check permissions and try again.<br/>";
  120. $jsconfig = 'HOSTNAME="'.$_SESSION['hostname'].'";';
  121. if (file_put_contents("config.js",$jsconfig))
  122. echo "JS Config written<br/>";
  123. else
  124. echo "Could not write JS config. Please check permissions and try again.<br/>";
  125. $sql_connection=mysql_connect($_SESSION['server'],$_SESSION['username'],$_SESSION['password']);
  126. if (!mysql_query("DROP DATABASE IF EXISTS " . $_SESSION['database'],$sql_connection))
  127. echo "I could not drop the database. Do you have permission?<br/>";
  128. if (!mysql_query("CREATE DATABASE " . $_SESSION['database'],$sql_connection))
  129. echo "I could not drop the database. Do you have permission?<br/>";
  130. if (!mysql_select_db($_SESSION['database'],$sql_connection))
  131. echo "I could not select the database. Did it create properly?<br/>";
  132. $sql = file("dbinfo.sql");
  133. foreach ($sql as $line)
  134. if (!mysql_query($line,$sql_connection))
  135. echo "I could not import the data. Has anything else failed?<br/>";
  136. echo "Finished!<br/>For security purposes, it is highly reccomended that you now delete the install.php file out of the folder when done.";
  137. break;
  138. default://wat
  139. $_SESSION['stage']=-1;
  140. echo "Something went wrong. Please try again.";
  141. break;
  142. }
  143. ?>
  144. </form>
  145. </body>
  146. </html>