PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/module/install/control.php

https://github.com/easysoft/zentaopms
PHP | 287 lines | 189 code | 31 blank | 67 comment | 38 complexity | 71f7b72cee94fd6ee9853037ba9fc35e MD5 | raw file
  1. <?php
  2. /**
  3. * The control file of install currentModule of ZenTaoPMS.
  4. *
  5. * @copyright Copyright 2009-2015 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
  6. * @license ZPL(http://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
  7. * @author Chunsheng Wang <chunsheng@cnezsoft.com>
  8. * @package install
  9. * @version $Id: control.php 4297 2013-01-27 07:51:45Z wwccss $
  10. * @link http://www.zentao.net
  11. */
  12. class install extends control
  13. {
  14. /**
  15. * Construct function.
  16. *
  17. * @access public
  18. * @return void
  19. */
  20. public function __construct()
  21. {
  22. if(!defined('IN_INSTALL')) helper::end();
  23. parent::__construct();
  24. $this->app->loadLang('user');
  25. $this->app->loadLang('admin');
  26. $this->config->webRoot = getWebRoot();
  27. }
  28. /**
  29. * Index page of install module.
  30. *
  31. * @access public
  32. * @return void
  33. */
  34. public function index()
  35. {
  36. if(!isset($this->config->installed) or !$this->config->installed) $this->session->set('installing', true);
  37. $this->view->title = $this->lang->install->welcome;
  38. if(!isset($this->view->versionName)) $this->view->versionName = $this->config->version; // If the versionName variable has been defined in the max version, it cannot be defined here to avoid being overwritten.
  39. $this->display();
  40. }
  41. /**
  42. * Checking agree license.
  43. *
  44. * @access public
  45. * @return void
  46. */
  47. public function license()
  48. {
  49. $this->view->title = $this->lang->install->welcome;
  50. $this->view->license = $this->install->getLicense();
  51. $this->display();
  52. }
  53. /**
  54. * Check the system.
  55. *
  56. * @access public
  57. * @return void
  58. */
  59. public function step1()
  60. {
  61. $this->view->title = $this->lang->install->checking;
  62. $this->view->phpVersion = $this->install->getPhpVersion();
  63. $this->view->phpResult = $this->install->checkPHP();
  64. $this->view->pdoResult = $this->install->checkPDO();
  65. $this->view->pdoMySQLResult = $this->install->checkPDOMySQL();
  66. $this->view->jsonResult = $this->install->checkJSON();
  67. $this->view->opensslResult = $this->install->checkOpenssl();
  68. $this->view->mbstringResult = $this->install->checkMbstring();
  69. $this->view->zlibResult = $this->install->checkZlib();
  70. $this->view->curlResult = $this->install->checkCurl();
  71. $this->view->filterResult = $this->install->checkFilter();
  72. $this->view->iconvResult = $this->install->checkIconv();
  73. $this->view->tmpRootInfo = $this->install->getTmpRoot();
  74. $this->view->tmpRootResult = $this->install->checkTmpRoot();
  75. $this->view->dataRootInfo = $this->install->getDataRoot();
  76. $this->view->dataRootResult = $this->install->checkDataRoot();
  77. $this->view->iniInfo = $this->install->getIniInfo();
  78. $checkSession = ini_get('session.save_handler') == 'files';
  79. $this->view->sessionResult = 'ok';
  80. $this->view->checkSession = $checkSession;
  81. if($checkSession)
  82. {
  83. $sessionResult = $this->install->checkSessionSavePath();
  84. $sessionInfo = $this->install->getSessionSavePath();
  85. if($sessionInfo['path'] == '') $sessionResult = 'ok';
  86. $this->view->sessionResult = $sessionResult;
  87. $this->view->sessionInfo = $sessionInfo;
  88. }
  89. $notice = '';
  90. if($this->config->framework->filterCSRF)
  91. {
  92. $httpType = (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == 'on') ? 'https' : 'http';
  93. if(isset($_SERVER['HTTP_X_FORWARDED_PROTO']) and strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) == 'https') $httpType = 'https';
  94. if(isset($_SERVER['REQUEST_SCHEME']) and strtolower($_SERVER['REQUEST_SCHEME']) == 'https') $httpType = 'https';
  95. $httpHost = zget($_SERVER, 'HTTP_HOST', '');
  96. if(empty($httpHost) or strpos($this->server->http_referer, "$httpType://$httpHost") !== 0) $notice = $this->lang->install->CSRFNotice;
  97. }
  98. $this->view->notice = $notice;
  99. $this->display();
  100. }
  101. /**
  102. * Set configs.
  103. *
  104. * @access public
  105. * @return void
  106. */
  107. public function step2()
  108. {
  109. $dbHost = $dbPort = $dbName = $dbUser = $dbPassword = '';
  110. /* Get mysql env in docker container. */
  111. if(getenv('MYSQL_HOST')) $dbHost = getenv('MYSQL_HOST');
  112. if(getenv('MYSQL_PORT')) $dbPort = getenv('MYSQL_PORT');
  113. if(getenv('MYSQL_DB')) $dbName = getenv('MYSQL_DB');
  114. if(getenv('MYSQL_USER')) $dbUser = getenv('MYSQL_USER');
  115. if(getenv('MYSQL_PASSWORD')) $dbPassword = getenv('MYSQL_PASSWORD');
  116. $this->view->title = $this->lang->install->setConfig;
  117. $this->view->dbHost = $dbHost ? $dbHost : '127.0.0.1';
  118. $this->view->dbPort = $dbPort ? $dbPort : '3306';
  119. $this->view->dbName = $dbName ? $dbName : 'zentao';
  120. $this->view->dbUser = $dbUser ? $dbUser : 'root';
  121. $this->view->dbPassword = $dbPassword ? $dbPassword : '';
  122. $this->display();
  123. }
  124. /**
  125. * Create the config file.
  126. *
  127. * @access public
  128. * @return void
  129. */
  130. public function step3()
  131. {
  132. if(!empty($_POST))
  133. {
  134. $return = $this->install->checkConfig();
  135. if($return->result == 'ok')
  136. {
  137. /* Set the session save path when the session save path is null. */
  138. $customSession = false;
  139. $checkSession = ini_get('session.save_handler') == 'files';
  140. if($checkSession)
  141. {
  142. if(!session_save_path())
  143. {
  144. /* Restart the session because the session save path is null when start the session last time. */
  145. session_write_close();
  146. $tmpRootInfo = $this->install->getTmpRoot();
  147. $sessionSavePath = $tmpRootInfo['path'] . 'session';
  148. if(!is_dir($sessionSavePath)) mkdir($sessionSavePath, 0777, true);
  149. session_save_path($sessionSavePath);
  150. $customSession = true;
  151. $sessionResult = $this->install->checkSessionSavePath();
  152. if($sessionResult == 'fail') chmod($sessionSavePath, 0777);
  153. session_start();
  154. $this->session->set('installing', true);
  155. }
  156. }
  157. $this->view = (object)$_POST;
  158. $this->view->app = $this->app;
  159. $this->view->lang = $this->lang;
  160. $this->view->config = $this->config;
  161. $this->view->title = $this->lang->install->saveConfig;
  162. $this->view->customSession = $customSession;
  163. $this->display();
  164. }
  165. else
  166. {
  167. $this->view->title = $this->lang->install->saveConfig;
  168. $this->view->error = $return->error;
  169. $this->display();
  170. }
  171. }
  172. else
  173. {
  174. $this->locate($this->createLink('install'));
  175. }
  176. }
  177. /**
  178. * Set system mode.
  179. *
  180. * @access public
  181. * @return void
  182. */
  183. public function step4()
  184. {
  185. if(!empty($_POST))
  186. {
  187. $this->loadModel('setting')->setItem('system.common.global.mode', $this->post->mode); // Update mode.
  188. return print(js::locate(inlink('step5'), 'parent'));
  189. }
  190. if(!isset($this->config->installed) or !$this->config->installed)
  191. {
  192. $this->view->error = $this->lang->install->errorNotSaveConfig;
  193. $this->display();
  194. }
  195. else
  196. {
  197. $this->app->loadLang('upgrade');
  198. $this->view->title = $this->lang->install->introduction;
  199. $this->display();
  200. }
  201. }
  202. /**
  203. * Create company, admin.
  204. *
  205. * @access public
  206. * @return void
  207. */
  208. public function step5()
  209. {
  210. if(!empty($_POST))
  211. {
  212. $this->install->grantPriv();
  213. if(dao::isError()) return print(js::error(dao::getError()));
  214. $this->install->updateLang();
  215. if(dao::isError()) return print(js::error(dao::getError()));
  216. if($this->post->importDemoData) $this->install->importDemoData();
  217. if(dao::isError()) return print(js::alert($this->lang->install->errorImportDemoData));
  218. $this->loadModel('setting');
  219. $this->setting->updateVersion($this->config->version);
  220. $this->setting->setSN();
  221. $this->setting->setItem('system.common.global.flow', $this->post->flow);
  222. $this->setting->setItem('system.common.safe.mode', '1');
  223. $this->setting->setItem('system.common.safe.changeWeak', '1');
  224. $this->setting->setItem('system.common.global.cron', 1);
  225. if(strpos($this->app->getClientLang(), 'zh') === 0) $this->loadModel('api')->createDemoData($this->lang->api->zentaoAPI, 'http://' . $_SERVER['HTTP_HOST'] . $this->app->config->webRoot . 'api.php/v1', '16.0');
  226. return print(js::locate(inlink('step6'), 'parent'));
  227. }
  228. $this->app->loadLang('upgrade');
  229. $this->view->title = $this->lang->install->getPriv;
  230. if(!isset($this->config->installed) or !$this->config->installed)
  231. {
  232. $this->view->error = $this->lang->install->errorNotSaveConfig;
  233. $this->display();
  234. }
  235. else
  236. {
  237. $this->display();
  238. }
  239. }
  240. /**
  241. * Join zentao community or login pms.
  242. *
  243. * @access public
  244. * @return void
  245. */
  246. public function step6()
  247. {
  248. $installFileDeleted = unlink($this->app->getAppRoot() . 'www/install.php');
  249. $this->view->installFileDeleted = $installFileDeleted;
  250. $this->view->title = $this->lang->install->success;
  251. $this->display();
  252. unlink($this->app->getAppRoot() . 'www/upgrade.php');
  253. unset($_SESSION['installing']);
  254. session_destroy();
  255. }
  256. }