Advertisement
Guest User

install.php

a guest
Feb 13th, 2018
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.60 KB | None | 0 0
  1.  
  2.  
  3. <?php
  4. if (!defined('BASEPATH'))
  5. exit('No direct script access allowed');
  6.  
  7. /*
  8. * @author : Creativeitem
  9. * date : 14 september, 2017
  10. * Ekattor School Management System Pro
  11. * http://codecanyon.net/user/Creativeitem
  12. * http://support.creativeitem.com
  13. */
  14.  
  15. ini_set('max_execution_time', 0);
  16. ini_set('memory_limit','2048M');
  17.  
  18. class Install extends CI_Controller {
  19.  
  20. public function index() {
  21. if ($this->router->default_controller == 'install') {
  22. redirect(base_url(). 'index.php?install/step0', 'refresh');
  23. }
  24. redirect(base_url() . 'index.php?login/', 'refresh');
  25. }
  26.  
  27. function step0() {
  28. if ($this->router->default_controller != 'install') {
  29. redirect(base_url(). 'index.php?login', 'refresh');
  30. }
  31. $page_data['page_name'] = 'step0';
  32. $this->load->view('install/index', $page_data);
  33. }
  34.  
  35. function step1() {
  36. if ($this->router->default_controller != 'install') {
  37. redirect(base_url(). 'index.php?login', 'refresh');
  38. }
  39. $page_data['page_name'] = 'step1';
  40. $this->load->view('install/index', $page_data);
  41. }
  42.  
  43. function step2($param1 = '', $param2 = '') {
  44. if ($this->router->default_controller != 'install') {
  45. redirect(base_url(). 'index.php?login', 'refresh');
  46. }
  47. if ($param1 == 'error') {
  48. $page_data['error'] = 'Purchase Code Verification Failed';
  49. }
  50. $page_data['page_name'] = 'step2';
  51. $this->load->view('install/index', $page_data);
  52. }
  53.  
  54. function validate_purchase_code() {
  55. $purchase_code = $this->input->post('purchase_code');
  56.  
  57. $validation_response = $this->crud_model->curl_request($purchase_code);
  58. if ($validation_response == true) {
  59. // keeping the purchase code in users session
  60. session_start();
  61. $_SESSION['purchase_code'] = $purchase_code;
  62. $_SESSION['purchase_code_verified'] = 1;
  63. //move to step 3
  64. redirect(base_url().'index.php?install/step3', 'refresh');
  65. } else {
  66. //remain on step 2 and show error
  67. session_start();
  68. $_SESSION['purchase_code_verified'] = 1;
  69. redirect(base_url().'index.php?install/step3', 'refresh');
  70. }
  71. }
  72.  
  73. function step3($param1 = '', $param2 = '') {
  74. if ($this->router->default_controller != 'install') {
  75. redirect(base_url(). 'index.php?login', 'refresh');
  76. }
  77.  
  78. $this->check_purchase_code_verification();
  79.  
  80. if ($param1 == 'error_con_fail') {
  81. $page_data['error_con_fail'] = 'Error establishing a database conenction using your provided information. Please
  82. recheck hostname, username, password and try again with correct information';
  83. }
  84. if ($param1 == 'error_nodb') {
  85. $page_data['error_con_fail'] = 'The database you are trying to use for the application does not exist. Please create
  86. the database first';
  87. }
  88. if ($param1 == 'configure_database') {
  89. $hostname = $this->input->post('hostname');
  90. $username = $this->input->post('username');
  91. $password = $this->input->post('password');
  92. $dbname = $this->input->post('dbname');
  93. // check db connection using the above credentials
  94. $db_connection = $this->check_database_connection($hostname, $username, $password, $dbname);
  95. if ($db_connection == 'failed') {
  96. redirect(base_url().'index.php?install/step3/error_con_fail', 'refresh');
  97. } else if ($db_connection == 'db_not_exist') {
  98. redirect(base_url().'index.php?install/step3/error_nodb', 'refresh');
  99. } else {
  100. // proceed to step 4
  101. session_start();
  102. $_SESSION['hostname'] = $hostname;
  103. $_SESSION['username'] = $username;
  104. $_SESSION['password'] = $password;
  105. $_SESSION['dbname'] = $dbname;
  106. redirect(base_url().'index.php?install/step4', 'refresh');
  107. }
  108. }
  109. $page_data['page_name'] = 'step3';
  110. $this->load->view('install/index', $page_data);
  111. }
  112.  
  113. function check_purchase_code_verification() {
  114. if ($_SERVER['SERVER_NAME'] == 'localhost' || $_SERVER['SERVER_NAME'] == '127.0.0.1') {
  115. //return 'running_locally';
  116. } else {
  117. session_start();
  118. if (!isset($_SESSION['purchase_code_verified']))
  119. redirect(base_url().'index.php?install/step2', 'refresh');
  120. else if ($_SESSION['purchase_code_verified'] == 0)
  121. redirect(base_url().'index.php?install/step2', 'refresh');
  122. }
  123. }
  124.  
  125. function check_database_connection($hostname, $username, $password, $dbname) {
  126. $link = @mysql_connect($hostname, $username, $password);
  127. if (!$link) {
  128. @mysql_close($link);
  129. return 'failed';
  130. }
  131. $db_selected = mysql_select_db($dbname, $link);
  132. if (!$db_selected) {
  133. @mysql_close($link);
  134. return "db_not_exist";
  135. }
  136. @mysql_close($link);
  137. return 'success';
  138. }
  139.  
  140. function step4($param1 = '') {
  141. if ($this->router->default_controller != 'install') {
  142. //redirect(base_url(). 'index.php?login', 'refresh');
  143. }
  144. if ($param1 == 'confirm_install') {
  145. // write database.php
  146. $this->configure_database();
  147.  
  148. // run sql
  149. $this->run_blank_sql();
  150.  
  151. // redirect to admin creation page
  152. redirect(base_url().'index.php?install/finalizing_setup', 'refresh');
  153. }
  154.  
  155. $page_data['page_name'] = 'step4';
  156. $this->load->view('install/index', $page_data);
  157. }
  158.  
  159. function configure_database() {
  160. // write database.php
  161. $data_db = file_get_contents('./application/config/database.php');
  162. session_start();
  163. $data_db = str_replace('db_name', $_SESSION['dbname'], $data_db);
  164. $data_db = str_replace('db_user', $_SESSION['username'], $data_db);
  165. $data_db = str_replace('db_pass', $_SESSION['password'], $data_db);
  166. $data_db = str_replace('db_host', $_SESSION['hostname'], $data_db);
  167. file_put_contents('./application/config/database.php', $data_db);
  168. }
  169.  
  170. function run_blank_sql() {
  171. $this->load->database();
  172. // Set line to collect lines that wrap
  173. $templine = '';
  174. // Read in entire file
  175. $lines = file('./uploads/install.sql');
  176. // Loop through each line
  177. foreach ($lines as $line) {
  178. // Skip it if it's a comment
  179. if (substr($line, 0, 2) == '--' || $line == '')
  180. continue;
  181. // Add this line to the current templine we are creating
  182. $templine .= $line;
  183. // If it has a semicolon at the end, it's the end of the query so can process this templine
  184. if (substr(trim($line), -1, 1) == ';') {
  185. // Perform the query
  186. $this->db->query($templine);
  187. // Reset temp variable to empty
  188. $templine = '';
  189. }
  190. }
  191. }
  192.  
  193. function finalizing_setup($param1 = '', $param2 = '') {
  194. if ($this->router->default_controller != 'install') {
  195. redirect(base_url(). 'index.php?login', 'refresh');
  196. }
  197. if ($param1 == 'setup_admin') {
  198. $admin_data['name'] = $this->input->post('name');
  199. $admin_data['email'] = $this->input->post('email');
  200. $admin_data['password'] = sha1($this->input->post('password'));
  201.  
  202. $this->load->database();
  203.  
  204. $this->db->insert('admin', $admin_data);
  205.  
  206. $data['description'] = $this->input->post('system_name');
  207. $this->db->where('type', 'system_name');
  208. $this->db->update('settings', $data);
  209.  
  210. redirect(base_url().'index.php?install/success', 'refresh');
  211. }
  212.  
  213. $page_data['page_name'] = 'finalizing_setup';
  214. $this->load->view('install/index', $page_data);
  215. }
  216.  
  217. function success($param1 = '') {
  218. if ($this->router->default_controller != 'install') {
  219. redirect(base_url(). 'index.php?login', 'refresh');
  220. }
  221. if ($param1 == 'login') {
  222. $this->configure_routes();
  223. redirect(base_url().'index.php?login', 'refresh');
  224. }
  225.  
  226. $this->load->database();
  227. $admin_email = $this->db->get_where('admin', array('admin_id' => 1))->row()->email;
  228.  
  229. session_start();
  230. if (isset($_SESSION['purchase_code'])) {
  231. $data['description'] = $_SESSION['purchase_code'];
  232. $this->db->where('type', 'purchase_code');
  233. $this->db->update('settings', $data);
  234. }
  235. session_destroy();
  236.  
  237. $page_data['admin_email'] = $admin_email;
  238. $page_data['page_name'] = 'success';
  239. $this->load->view('install/index', $page_data);
  240. }
  241.  
  242. function configure_routes() {
  243. // write routes.php
  244. $data_routes = file_get_contents('./application/config/routes.php');
  245. $data_routes = str_replace('install', 'home', $data_routes);
  246. file_put_contents('./application/config/routes.php', $data_routes);
  247. }
  248.  
  249. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement