Guest User

RISE

a guest
Feb 2nd, 2018
1,400
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.78 KB | None | 0 0
  1. <?php
  2.  
  3. ini_set('max_execution_time', 300); //300 seconds
  4.  
  5. if (isset($_POST)) {
  6. $host = $_POST["host"];
  7. $dbuser = $_POST["dbuser"];
  8. $dbpassword = $_POST["dbpassword"];
  9. $dbname = $_POST["dbname"];
  10.  
  11. $first_name = $_POST["first_name"];
  12. $last_name = $_POST["last_name"];
  13. $email = $_POST["email"];
  14. $login_password = $_POST["password"] ? $_POST["password"] : "";
  15.  
  16. $purchase_code = $_POST["purchase_code"];
  17.  
  18. //check required fields
  19. if (!($host && $dbuser && $dbname && $first_name && $last_name && $email && $login_password)) {
  20. echo json_encode(array("success" => false, "message" => "Please input all fields."));
  21. exit();
  22. }
  23.  
  24.  
  25. //check for valid email
  26. if (filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
  27. echo json_encode(array("success" => false, "message" => "Please input a valid email."));
  28. exit();
  29. }
  30.  
  31.  
  32.  
  33. //check for valid database connection
  34. $mysqli = @new mysqli($host, $dbuser, $dbpassword, $dbname);
  35.  
  36. if (mysqli_connect_errno()) {
  37. echo json_encode(array("success" => false, "message" => $mysqli->connect_error));
  38. exit();
  39. }
  40.  
  41.  
  42. //all input seems to be ok. check required fiels
  43. if (!is_file('database.sql')) {
  44. echo json_encode(array("success" => false, "message" => "The database.sql file could not found in install folder!"));
  45. exit();
  46. }
  47.  
  48.  
  49.  
  50.  
  51.  
  52. /*
  53. * check the db config file
  54. * if db already configured, we'll assume that the installation has completed
  55. */
  56.  
  57.  
  58. $db_file_path = "../application/config/database.php";
  59. $db_file = file_get_contents($db_file_path);
  60. $is_installed = strpos($db_file, "enter_hostname");
  61.  
  62. if (!$is_installed) {
  63. echo json_encode(array("success" => false, "message" => "Seems this app is already installed! You can't reinstall it again."));
  64. exit();
  65. }
  66.  
  67.  
  68. //start installation
  69.  
  70. $sql = file_get_contents("database.sql");
  71.  
  72.  
  73. //set admin information to database
  74. $now = date("Y-m-d H:i:s");
  75.  
  76. $sql = str_replace('admin_first_name', $first_name, $sql);
  77. $sql = str_replace('admin_last_name', $last_name, $sql);
  78. $sql = str_replace('admin_email', $email, $sql);
  79. $sql = str_replace('admin_password', md5($login_password), $sql);
  80. $sql = str_replace('admin_created_at', $now, $sql);
  81. $sql = str_replace('ITEM-PURCHASE-CODE', $purchase_code, $sql);
  82.  
  83. //create tables in datbase
  84.  
  85. $mysqli->multi_query($sql);
  86. do {
  87.  
  88. } while (mysqli_more_results($mysqli) && mysqli_next_result($mysqli));
  89.  
  90.  
  91. $mysqli->close();
  92. // database created
  93. // set the database config file
  94.  
  95. $db_file = str_replace('enter_hostname', $host, $db_file);
  96. $db_file = str_replace('enter_db_username', $dbuser, $db_file);
  97. $db_file = str_replace('enter_db_password', $dbpassword, $db_file);
  98. $db_file = str_replace('enter_database_name', $dbname, $db_file);
  99.  
  100. file_put_contents($db_file_path, $db_file);
  101.  
  102.  
  103. // set random enter_encryption_key
  104.  
  105. $config_file_path = "../application/config/config.php";
  106. $encryption_key = substr(md5(rand()), 0, 15);
  107. $config_file = file_get_contents($config_file_path);
  108. $config_file = str_replace('enter_encryption_key', $encryption_key, $config_file);
  109.  
  110. file_put_contents($config_file_path, $config_file);
  111.  
  112.  
  113. // set the environment = production
  114.  
  115. $index_file_path = "../index.php";
  116.  
  117. $index_file = file_get_contents($index_file_path);
  118. $index_file = preg_replace('/pre_installation/', 'production', $index_file, 1); //replace the first occurence of 'pre_installation'
  119.  
  120. file_put_contents($index_file_path, $index_file);
  121.  
  122.  
  123. echo json_encode(array("success" => true, "message" => "Installation successfull."));
  124. exit();
  125. }
Add Comment
Please, Sign In to add comment