PageRenderTime 55ms CodeModel.GetById 33ms RepoModel.GetById 1ms app.codeStats 0ms

/install.php

https://bitbucket.org/wildanm/orangehrm
PHP | 254 lines | 176 code | 57 blank | 21 comment | 40 complexity | 07e3e6fb114591125371f1901f9783c9 MD5 | raw file
Possible License(s): CC-BY-SA-3.0, AGPL-3.0, BSD-3-Clause, AGPL-1.0, GPL-2.0, LGPL-2.1, LGPL-3.0
  1. <?php
  2. /**
  3. * OrangeHRM is a comprehensive Human Resource Management (HRM) System that captures
  4. * all the essential functionalities required for any enterprise.
  5. * Copyright (C) 2006 OrangeHRM Inc., http://www.orangehrm.com
  6. *
  7. * OrangeHRM is free software; you can redistribute it and/or modify it under the terms of
  8. * the GNU General Public License as published by the Free Software Foundation; either
  9. * version 2 of the License, or (at your option) any later version.
  10. *
  11. * OrangeHRM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  12. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. * See the GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along with this program;
  16. * if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  17. * Boston, MA 02110-1301, USA
  18. *
  19. */
  20. function sockComm($postArr) {
  21. $host = 'www.orangehrm.com';
  22. $method = 'POST';
  23. $path = '/registration/registerAcceptor.php';
  24. $data = "userName=".$postArr['userName']
  25. ."&userEmail=".$postArr['userEmail']
  26. ."&userComments=".$postArr['userComments']
  27. ."&firstName=".$postArr['firstName']
  28. ."&company=".$postArr['company']
  29. ."&updates=".(isset($postArr['chkUpdates']) ? '1' : '0');
  30. $fp = @fsockopen($host, 80);
  31. if(!$fp)
  32. return false;
  33. fputs($fp, "POST $path HTTP/1.1\r\n");
  34. fputs($fp, "Host: $host\r\n");
  35. fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
  36. fputs($fp, "Content-length: " . strlen($data) . "\r\n");
  37. fputs($fp, "User-Agent: ".$_SERVER['HTTP_USER_AGENT']."\r\n");
  38. fputs($fp, "Connection: close\r\n\r\n");
  39. fputs($fp, $data);
  40. $resp = '';
  41. while (!feof($fp)) {
  42. $resp .= fgets($fp,128);
  43. }
  44. fclose($fp);
  45. if(strpos($resp, 'SUCCESSFUL') === false)
  46. return false;
  47. return true;
  48. }
  49. function back($currScreen) {
  50. for ($i=0; $i < 2; $i++) {
  51. switch ($currScreen) {
  52. default :
  53. case 0 : unset($_SESSION['WELCOME']); break;
  54. case 1 : unset($_SESSION['LICENSE']); break;
  55. case 2 : unset($_SESSION['DBCONFIG']); break;
  56. case 3 : unset($_SESSION['SYSCHECK']); break;
  57. case 4 : unset($_SESSION['DEFUSER']); break;
  58. case 5 : unset($_SESSION['CONFDONE']); break;
  59. case 6 : $_SESSION['UNISTALL'] = true;
  60. unset($_SESSION['CONFDONE']);
  61. unset($_SESSION['INSTALLING']);
  62. break;
  63. case 7 : return false; break;
  64. }
  65. $currScreen--;
  66. }
  67. return true;
  68. }
  69. define('ROOT_PATH', dirname(__FILE__));
  70. if(!isset($_SESSION['SID']))
  71. session_start();
  72. clearstatcache();
  73. if (is_file(ROOT_PATH . '/lib/confs/Conf.php') && !isset($_SESSION['INSTALLING'])) {
  74. header('Location: ./index.php');
  75. exit ();
  76. }
  77. if (isset($_SESSION['error'])) {
  78. unset($_SESSION['error']);
  79. }
  80. /* This $_SESSION['cMethod'] is used to determine wheter to use an existing database or a new one */
  81. $_SESSION['cMethod'] = 'new';
  82. if (isset($_POST['cMethod'])) {
  83. $_SESSION['cMethod'] = $_POST['cMethod'];
  84. }
  85. if(isset($_POST['actionResponse']))
  86. switch($_POST['actionResponse']) {
  87. case 'WELCOMEOK' : $_SESSION['WELCOME'] = 'OK'; break;
  88. case 'LICENSEOK' : $_SESSION['LICENSE'] = 'OK'; break;
  89. case 'SYSCHECKOK' : $_SESSION['SYSCHECK'] = 'OK'; break;
  90. case 'DBINFO' : $uname = "";
  91. $passw = "";
  92. if (isset( $_POST['dbUserName'] )) {
  93. $uname = trim($_POST['dbUserName']);
  94. }
  95. if (isset( $_POST['dbPassword'] )) {
  96. $passw = trim($_POST['dbPassword']);
  97. }
  98. $dbInfo = array( 'dbHostName' => trim($_POST['dbHostName']),
  99. 'dbHostPort' => trim($_POST['dbHostPort']),
  100. 'dbHostPortModifier' => trim($_POST['dbHostPortModifier']),
  101. 'dbName' => trim($_POST['dbName']),
  102. 'dbUserName' => $uname,
  103. 'dbPassword' => $passw);
  104. if(!isset($_POST['chkSameUser'])) {
  105. $dbInfo['dbOHRMUserName'] = trim($_POST['dbOHRMUserName']);
  106. $dbInfo['dbOHRMPassword'] = trim($_POST['dbOHRMPassword']);
  107. }
  108. if ($_POST['dbCreateMethod'] == 'existing') {
  109. $dbInfo['dbUserName'] = trim($_POST['dbOHRMUserName']);
  110. $dbInfo['dbPassword'] = trim($_POST['dbOHRMPassword']);
  111. }
  112. $_SESSION['dbCreateMethod'] = $_POST['dbCreateMethod'];
  113. $_SESSION['dbInfo'] = $dbInfo;
  114. if(@mysql_connect($dbInfo['dbHostName'].':'.$dbInfo['dbHostPort'], $dbInfo['dbUserName'], $dbInfo['dbPassword'])) {
  115. $mysqlHost = mysql_get_server_info();
  116. if(intval(substr($mysqlHost,0,1)) < 4 || substr($mysqlHost,0,3) === '4.0')
  117. $error = 'WRONGDBVER';
  118. elseif($_POST['dbCreateMethod'] == 'new' && mysql_select_db($dbInfo['dbName']))
  119. $error = 'DBEXISTS';
  120. elseif($_POST['dbCreateMethod'] == 'new' && !isset($_POST['chkSameUser'])) {
  121. mysql_select_db('mysql');
  122. $rset = mysql_query("SELECT USER FROM user WHERE USER = '" .$dbInfo['dbOHRMUserName'] . "'");
  123. if(mysql_num_rows($rset) > 0)
  124. $error = 'DBUSEREXISTS';
  125. else $_SESSION['DBCONFIG'] = 'OK';
  126. } else $_SESSION['DBCONFIG'] = 'OK';
  127. } else $error = 'WRONGDBINFO';
  128. $errorMsg = mysql_error();
  129. $mysqlErrNo = mysql_errno();
  130. /* For Data Encryption: Begins */
  131. $_SESSION['ENCRYPTION'] = "Inactive";
  132. if (isset($_POST['chkEncryption'])) {
  133. $filePath = 'lib/confs/cryptokeys/key.ohrm';
  134. if (is_writable('lib/confs/cryptokeys')) {
  135. $cryptKey = '';
  136. for($i = 0; $i < 4; $i++) {
  137. $cryptKey .= md5(rand(10000000, 99999999));
  138. }
  139. $cryptKey = str_shuffle($cryptKey);
  140. $handle = fopen($filePath, 'w');
  141. if ($handle) {
  142. fwrite($handle, $cryptKey, 128);
  143. $_SESSION['ENCRYPTION'] = "Active";
  144. } else {
  145. $_SESSION['ENCRYPTION'] = "Failed";
  146. }
  147. fclose($handle);
  148. } else {
  149. $_SESSION['ENCRYPTION'] = "Failed";
  150. }
  151. }
  152. /* For Data Encryption: Ends */
  153. break;
  154. case 'DEFUSERINFO' :
  155. $_SESSION['defUser']['AdminUserName'] = trim($_POST['OHRMAdminUserName']);
  156. $_SESSION['defUser']['AdminPassword'] = trim($_POST['OHRMAdminPassword']);
  157. $_SESSION['DEFUSER'] = 'OK';
  158. break;
  159. case 'CANCEL' : session_destroy();
  160. header("Location: ./install.php");
  161. exit(0);
  162. break;
  163. case 'BACK' : back($_POST['txtScreen']);
  164. break;
  165. case 'CONFIRMED' : $_SESSION['INSTALLING'] = 0;
  166. break;
  167. case 'REGISTER' : $_SESSION['CONFDONE'] = 'OK';
  168. break;
  169. case 'REGINFO' : $reqAccept = sockComm($_POST);
  170. break;
  171. case 'NOREG' : $reqAccept = sockComm($_POST);
  172. case 'LOGIN' : session_destroy();
  173. setcookie('PHPSESSID', '', time()-3600, '/');
  174. header("Location: ./");
  175. exit(0);
  176. break;
  177. }
  178. if (isset($error)) {
  179. $_SESSION['error'] = $error;
  180. }
  181. if (isset($mysqlErrNo)) {
  182. $_SESSION['mysqlErrNo'] = $mysqlErrNo;
  183. }
  184. if (isset($errorMsg)) {
  185. $_SESSION['errorMsg'] = $errorMsg;
  186. }
  187. if (isset($reqAccept)) {
  188. $_SESSION['reqAccept'] = $reqAccept;
  189. }
  190. if (isset($_SESSION['INSTALLING']) && !isset($_SESSION['UNISTALL'])) {
  191. include(ROOT_PATH.'/installer/applicationSetup.php');
  192. }
  193. if (isset($_SESSION['UNISTALL'])) {
  194. include(ROOT_PATH.'/installer/cleanUp.php');
  195. }
  196. header('Location: ./installer/installerUI.php');
  197. ?>