Guest User

Untitled

a guest
Apr 1st, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.44 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Installation Script</title>
  5. </head>
  6. <?php
  7. $step = (isset($_GET['step']) && $_GET['step'] != '') ? $_GET['step'] : '';
  8. switch($step){
  9. case '1':
  10. step_1();
  11. break;
  12. case '2':
  13. step_2();
  14. break;
  15. case '3':
  16. step_3();
  17. break;
  18. case '4':
  19. step_4();
  20. break;
  21. default:
  22. step_1();
  23. }
  24. ?>
  25. <body>
  26.  
  27. <?php
  28. function step_1(){
  29. if($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['agree'])){
  30. header('Location: install.php?step=2');
  31. exit;
  32. }
  33. if($_SERVER['REQUEST_METHOD'] == 'POST' && !isset($_POST['agree'])){
  34. echo "You must agree to the license.";
  35. }
  36. ?>
  37. <p>Our LICENSE will go here.</p>
  38. <form action="install.php?step=1" method="post">
  39. <p>
  40. I agree to the license
  41. <input type="checkbox" name="agree" />
  42. </p>
  43. <input type="submit" value="Continue" />
  44. </form>
  45. <?php
  46. }
  47.  
  48. function step_2(){
  49. if($_SERVER['REQUEST_METHOD'] == 'POST' && $_POST['pre_error'] ==''){
  50. header('Location: install.php?step=3');
  51. exit;
  52. }
  53. if($_SERVER['REQUEST_METHOD'] == 'POST' && $_POST['pre_error'] != '')
  54. echo $_POST['pre_error'];
  55.  
  56. if (phpversion() < '5.0') {
  57. $pre_error = 'You need to use PHP5 or above for our site!<br />';
  58. }
  59. if (ini_get('session.auto_start')) {
  60. $pre_error .= 'Our site will not work with session.auto_start enabled!<br />';
  61. }
  62. if (!extension_loaded('mysql')) {
  63. $pre_error .= 'MySQL extension needs to be loaded for our site to work!<br />';
  64. }
  65. if (!extension_loaded('gd')) {
  66. $pre_error .= 'GD extension needs to be loaded for our site to work!<br />';
  67. }
  68. if (!is_writable('config.php')) {
  69. $pre_error .= 'config.php needs to be writable for our site to be installed!';
  70. }
  71. ?>
  72. <table width="100%">
  73. <tr>
  74. <td>PHP Version:</td>
  75. <td><?php echo phpversion(); ?></td>
  76. <td>5.0+</td>
  77. <td><?php echo (phpversion() >= '5.0') ? 'Ok' : 'Not Ok'; ?></td>
  78. </tr>
  79. <tr>
  80. <td>Session Auto Start:</td>
  81. <td><?php echo (ini_get('session_auto_start')) ? 'On' : 'Off'; ?></td>
  82. <td>Off</td>
  83. <td><?php echo (!ini_get('session_auto_start')) ? 'Ok' : 'Not Ok'; ?></td>
  84. </tr>
  85. <tr>
  86. <td>MySQL:</td>
  87. <td><?php echo extension_loaded('mysql') ? 'On' : 'Off'; ?></td>
  88. <td>On</td>
  89. <td><?php echo extension_loaded('mysql') ? 'Ok' : 'Not Ok'; ?></td>
  90. </tr>
  91. <tr>
  92. <td>GD:</td>
  93. <td><?php echo extension_loaded('gd') ? 'On' : 'Off'; ?></td>
  94. <td>On</td>
  95. <td><?php echo extension_loaded('gd') ? 'Ok' : 'Not Ok'; ?></td>
  96. </tr>
  97. <tr>
  98. <td>config.php</td>
  99. <td><?php echo is_writable('config.php') ? 'Writable' : 'Unwritable'; ?></td>
  100. <td>Writable</td>
  101. <td><?php echo is_writable('config.php') ? 'Ok' : 'Not Ok'; ?></td>
  102. </tr>
  103. </table>
  104. <form action="install.php?step=2" method="post">
  105. <input type="hidden" name="pre_error" id="pre_error" value="<?php echo $pre_error;?>" />
  106. <input type="submit" name="continue" value="Continue" />
  107. </form>
  108. <?php
  109. }
  110.  
  111. function step_3(){
  112. if (isset($_POST['submit']) && $_POST['submit']=="Install!") {
  113. $database_host=isset($_POST['database_host'])?$_POST['database_host']:"";
  114. $database_name=isset($_POST['database_name'])?$_POST['database_name']:"";
  115. $database_username=isset($_POST['database_username'])?$_POST['database_username']:"";
  116. $database_password=isset($_POST['database_password'])?$_POST['database_password']:"";
  117. $admin_name=isset($_POST['admin_name'])?$_POST['admin_name']:"";
  118. $admin_password=isset($_POST['admin_password'])?$_POST['admin_password']:"";
  119.  
  120. if (empty($admin_name) || empty($admin_password) || empty($database_host) || empty($database_username) || empty($database_name)) {
  121. echo "All fields are required! Please re-enter.<br />";
  122. } else {
  123. $connection = mysql_connect($database_host, $database_username, $database_password);
  124. mysql_select_db($database_name, $connection);
  125.  
  126. $file ='data.sql';
  127. if ($sql = file($file)) {
  128. $query = '';
  129. foreach($sql as $line) {
  130. $tsl = trim($line);
  131. if (($sql != '') && (substr($tsl, 0, 2) != "--") && (substr($tsl, 0, 1) != '#')) {
  132. $query .= $line;
  133.  
  134. if (preg_match('/;s*$/', $line)) {
  135.  
  136. mysql_query($query, $connection);
  137. $err = mysql_error();
  138. if (!empty($err))
  139. break;
  140. $query = '';
  141. }
  142. }
  143. }
  144. @mysql_query("INSERT INTO admin SET admin_name='".$admin_name."', admin_password = md5('" . $admin_password . "')");
  145. mysql_close($connection);
  146. }
  147. $f=fopen("config.php","w");
  148. $database_inf="<?php
  149. define('DATABASE_HOST', '".$database_host."');
  150. define('DATABASE_NAME', '".$database_name."');
  151. define('DATABASE_USERNAME', '".$database_username."');
  152. define('DATABASE_PASSWORD', '".$database_password."');
  153. define('ADMIN_NAME', '".$admin_name."');
  154. define('ADMIN_PASSWORD', '".$admin_password."');
  155. ?>";
  156. if (fwrite($f,$database_inf)>0){
  157. fclose($f);
  158. }
  159. header("Location: install.php?step=4");
  160. }
  161. }
  162. ?>
  163. <form method="post" action="install.php?step=3">
  164. <p>
  165. <input type="text" name="database_host" value='localhost' size="30">
  166. <label for="database_host">Database Host</label>
  167. </p>
  168. <p>
  169. <input type="text" name="database_name" size="30" value="<?php echo $database_name; ?>">
  170. <label for="database_name">Database Name</label>
  171. </p>
  172. <p>
  173. <input type="text" name="database_username" size="30" value="<?php echo $database_username; ?>">
  174. <label for="database_username">Database Username</label>
  175. </p>
  176. <p>
  177. <input type="text" name="database_password" size="30" value="<?php echo $database_password; ?>">
  178. <label for="database_password">Database Password</label>
  179. </p>
  180. <br/>
  181. <p>
  182. <input type="text" name="admin_name" size="30" value="<?php echo $username; ?>">
  183. <label for="username">Admin Login</label>
  184. </p>
  185. <p>
  186. <input name="admin_password" type="text" size="30" maxlength="15" value="<?php echo $password; ?>">
  187. <label for="password">Admin Password</label>
  188. </p>
  189. <p>
  190. <input type="submit" name="submit" value="Install!">
  191. </p>
  192. </form>
  193. <?php
  194. }
  195.  
  196. CREATE TABLE IF NOT EXISTS `admin` (
  197. `admin_id` int(11) NOT NULL AUTO_INCREMENT,
  198. `admin_name` varchar(50) NOT NULL,
  199. `admin_password` varchar(50) NOT NULL,
  200. PRIMARY KEY (`admin_id`)
  201. ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
  202.  
  203. function step_4(){
  204. ?>
  205. <p><a href="http://localhost/installsample/">Site home page</a></p>
  206. <p><a href="http://localhost/installsample/admin">Admin page</a></p>
  207. <?php
  208. }
  209. ?>
  210.  
  211. <!DOCTYPE html>
  212. <html>
  213. <head>
  214. <title>Installation Script</title>
  215. </head>
  216. <body>
  217. <?php
  218. require 'config.php';
  219. if (!defined('DATABASE_NAME')) {
  220. header('Location: install.php');
  221. exit;
  222. }
  223. ?>
  224. <p>This is our site.</p>
  225. </body>
  226. </html>
Add Comment
Please, Sign In to add comment