model.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786
  1. <?php
  2. /** 安装界面需要的各种模块 */
  3. class installModel
  4. {
  5. private $host;
  6. private $name;
  7. private $user;
  8. private $encoding;
  9. private $password;
  10. private $port;
  11. private $prefix;
  12. private $successTable = [];
  13. /**
  14. * @var bool
  15. */
  16. private $allowNext = true;
  17. /**
  18. * @var PDO|string
  19. */
  20. private $dbh = null;
  21. /**
  22. * @var bool
  23. */
  24. private $clearDB = false;
  25. /**
  26. * Notes: php版本
  27. * @author luzg(2020/8/25 9:56)
  28. * @return string
  29. */
  30. public function getPhpVersion()
  31. {
  32. return PHP_VERSION;
  33. }
  34. /**
  35. * Notes: 当前版本是否符合
  36. * @author luzg(2020/8/25 9:57)
  37. * @return string
  38. */
  39. public function checkPHP()
  40. {
  41. return $result = version_compare(PHP_VERSION, '8.0.0') >= 0 ? 'ok' : 'fail';
  42. }
  43. /**
  44. * Notes: 是否有PDO
  45. * @author luzg(2020/8/25 9:57)
  46. * @return string
  47. */
  48. public function checkPDO()
  49. {
  50. return $result = extension_loaded('pdo') ? 'ok' : 'fail';
  51. }
  52. /**
  53. * Notes: 是否有PDO::MySQL
  54. * @author luzg(2020/8/25 9:58)
  55. * @return string
  56. */
  57. public function checkPDOMySQL()
  58. {
  59. return $result = extension_loaded('pdo_mysql') ? 'ok' : 'fail';
  60. }
  61. /**
  62. * Notes: 是否支持JSON
  63. * @author luzg(2020/8/25 9:58)
  64. * @return string
  65. */
  66. public function checkJSON()
  67. {
  68. return $result = extension_loaded('json') ? 'ok' : 'fail';
  69. }
  70. /**
  71. * Notes: 是否支持openssl
  72. * @author luzg(2020/8/25 9:58)
  73. * @return string
  74. */
  75. public function checkOpenssl()
  76. {
  77. return $result = extension_loaded('openssl') ? 'ok' : 'fail';
  78. }
  79. /**
  80. * Notes: 是否支持mbstring
  81. * @author luzg(2020/8/25 9:58)
  82. * @return string
  83. */
  84. public function checkMbstring()
  85. {
  86. return $result = extension_loaded('mbstring') ? 'ok' : 'fail';
  87. }
  88. /**
  89. * Notes: 是否支持zlib
  90. * @author luzg(2020/8/25 9:59)
  91. * @return string
  92. */
  93. public function checkZlib()
  94. {
  95. return $result = extension_loaded('zlib') ? 'ok' : 'fail';
  96. }
  97. /**
  98. * Notes: 是否支持curl
  99. * @author luzg(2020/8/25 9:59)
  100. * @return string
  101. */
  102. public function checkCurl()
  103. {
  104. return $result = extension_loaded('curl') ? 'ok' : 'fail';
  105. }
  106. /**
  107. * Notes: 检查GD2扩展
  108. * @author luzg(2020/8/26 9:59)
  109. * @return string
  110. */
  111. public function checkGd2()
  112. {
  113. return $result = extension_loaded('gd') ? 'ok' : 'fail';
  114. }
  115. /**
  116. * Notes: 检查Dom扩展
  117. * @author luzg(2020/8/26 9:59)
  118. * @return string
  119. */
  120. public function checkDom()
  121. {
  122. return $result = extension_loaded('dom') ? 'ok' : 'fail';
  123. }
  124. /**
  125. * Notes: 是否支持filter
  126. * @author luzg(2020/8/25 9:59)
  127. * @return string
  128. */
  129. public function checkFilter()
  130. {
  131. return $result = extension_loaded('filter') ? 'ok' : 'fail';
  132. }
  133. /**
  134. * Notes: 是否支持iconv
  135. * @author luzg(2020/8/25 9:59)
  136. * @return string
  137. */
  138. public function checkIconv()
  139. {
  140. return $result = extension_loaded('iconv') ? 'ok' : 'fail';
  141. }
  142. /**
  143. * Notes: 检查fileinfo扩展
  144. * @author 段誉(2021/6/28 11:03)
  145. * @return string
  146. */
  147. public function checkFileInfo()
  148. {
  149. return $result = extension_loaded('fileinfo') ? 'ok' : 'fail';
  150. }
  151. /**
  152. * Notes: 取得临时目录路径
  153. * @author luzg(2020/8/25 10:05)
  154. * @return array
  155. */
  156. public function getTmpRoot()
  157. {
  158. $path = $this->getAppRoot() . '/runtime';
  159. return [
  160. 'path' => $path,
  161. 'exists' => is_dir($path),
  162. 'writable' => is_writable($path),
  163. ];
  164. }
  165. /**
  166. * Notes: 检查临时路径
  167. * @author luzg(2020/8/25 10:06)
  168. * @return string
  169. */
  170. public function checkTmpRoot()
  171. {
  172. $tmpRoot = $this->getTmpRoot()['path'];
  173. return $result = (is_dir($tmpRoot) and is_writable($tmpRoot)) ? 'ok' : 'fail';
  174. }
  175. /**
  176. * Notes: SESSION路径是否可写
  177. * @author luzg(2020/8/25 10:06)
  178. * @return mixed
  179. */
  180. public function getSessionSavePath()
  181. {
  182. $sessionSavePath = preg_replace("/\d;/", '', session_save_path());
  183. return [
  184. 'path' => $sessionSavePath,
  185. 'exists' => is_dir($sessionSavePath),
  186. 'writable' => is_writable($sessionSavePath),
  187. ];
  188. }
  189. /**
  190. * Notes: 检查session路径可写状态
  191. * @author luzg(2020/8/25 10:13)
  192. * @return string
  193. */
  194. public function checkSessionSavePath()
  195. {
  196. $sessionSavePath = preg_replace("/\d;/", '', session_save_path());
  197. $result = (is_dir($sessionSavePath) and is_writable($sessionSavePath)) ? 'ok' : 'fail';
  198. if ($result == 'fail') return $result;
  199. file_put_contents($sessionSavePath . '/zentaotest', 'zentao');
  200. $sessionContent = file_get_contents($sessionSavePath . '/zentaotest');
  201. if ($sessionContent == 'zentao') {
  202. unlink($sessionSavePath . '/zentaotest');
  203. return 'ok';
  204. }
  205. return 'fail';
  206. }
  207. /**
  208. * Notes: 取得data目录是否可选
  209. * @author luzg(2020/8/25 10:58)
  210. * @return array
  211. */
  212. public function getDataRoot()
  213. {
  214. $path = $this->getAppRoot();
  215. return [
  216. 'path' => $path . 'www' . DS . 'data',
  217. 'exists' => is_dir($path),
  218. 'writable' => is_writable($path),
  219. ];
  220. }
  221. /**
  222. * Notes: 取得root路径
  223. * @author luzg(2020/8/25 11:02)
  224. * @return string
  225. */
  226. public function checkDataRoot()
  227. {
  228. $dataRoot = $this->getAppRoot() . 'www' . DS . 'data';
  229. return $result = (is_dir($dataRoot) and is_writable($dataRoot)) ? 'ok' : 'fail';
  230. }
  231. /**
  232. * Notes: 取得php.ini信息
  233. * @author luzg(2020/8/25 11:03)
  234. * @return string
  235. */
  236. public function getIniInfo()
  237. {
  238. $iniInfo = '';
  239. ob_start();
  240. phpinfo(1);
  241. $lines = explode("\n", strip_tags(ob_get_contents()));
  242. ob_end_clean();
  243. foreach ($lines as $line) if (strpos($line, 'ini') !== false) $iniInfo .= $line . "\n";
  244. return $iniInfo;
  245. }
  246. /**
  247. * Notes: 创建安装锁定文件
  248. * @author luzg(2020/8/28 11:32)
  249. * @return bool
  250. */
  251. public function mkLockFile()
  252. {
  253. return touch($this->getAppRoot() . '/config/install.lock');
  254. }
  255. /**
  256. * Notes: 检查之前是否有安装
  257. * @author luzg(2020/8/28 11:36)
  258. */
  259. public function appIsInstalled()
  260. {
  261. return file_exists($this->getAppRoot() . '/config/install.lock');
  262. }
  263. /**
  264. * Notes: 取得配置信息
  265. * @author luzg(2020/8/25 11:05)
  266. * @param string $dbName 数据库名称
  267. * @param array $connectionInfo 连接信息
  268. * @return stdclass
  269. * @throws Exception
  270. */
  271. public function checkConfig($dbName, $connectionInfo)
  272. {
  273. $return = new stdclass();
  274. $return->result = 'ok';
  275. /* Connect to database. */
  276. $this->setDBParam($connectionInfo);
  277. $this->dbh = $this->connectDB();
  278. if (strpos($dbName, '.') !== false) {
  279. $return->result = 'fail';
  280. $return->error = '没有发现数据库信息';
  281. return $return;
  282. }
  283. if ( !is_object($this->dbh)) {
  284. $return->result = 'fail';
  285. $return->error = '安装错误,请检查连接信息:'.mb_strcut($this->dbh,0,30).'...';
  286. echo $this->dbh;
  287. return $return;
  288. }
  289. /* Get mysql version. */
  290. $version = $this->getMysqlVersion();
  291. /* check mysql sql_model */
  292. // if(!$this->checkSqlMode($version)) {
  293. // $return->result = 'fail';
  294. // $return->error = '请在mysql配置文件修改sql-mode添加NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
  295. // return $return;
  296. // }
  297. /* If database no exits, try create it. */
  298. if ( !$this->dbExists()) {
  299. if ( !$this->createDB($version)) {
  300. $return->result = 'fail';
  301. $return->error = '创建数据库错误';
  302. return $return;
  303. }
  304. } elseif ($this->tableExits() and $this->clearDB == false) {
  305. $return->result = 'fail';
  306. $return->error = '数据表已存在,您之前可能已安装本系统,如需继续安装请选择新的数据库。';
  307. return $return;
  308. } elseif ($this->dbExists() and $this->clearDB == true) {
  309. if (!$this->dropDb($connectionInfo['name'])) {
  310. $return->result = 'fail';
  311. $return->error = '数据表已经存在,删除已存在库错误,请手动清除';
  312. return $return;
  313. } else {
  314. if ( !$this->createDB($version)) {
  315. $return->result = 'fail';
  316. $return->error = '创建数据库错误!';
  317. return $return;
  318. }
  319. }
  320. }
  321. /* Create tables. */
  322. if ( !$this->createTable($version, $connectionInfo)) {
  323. $return->result = 'fail';
  324. $return->error = '创建表格失败';
  325. return $return;
  326. }
  327. return $return;
  328. }
  329. /**
  330. * Notes: 设置数据库相关信息
  331. * @author luzg(2020/8/25 11:17)
  332. * @param $post
  333. */
  334. public function setDBParam($post)
  335. {
  336. $this->host = $post['host'];
  337. $this->name = $post['name'];
  338. $this->user = $post['user'];
  339. $this->encoding = 'utf8mb4';
  340. $this->password = $post['password'];
  341. $this->port = $post['port'];
  342. $this->prefix = $post['prefix'];
  343. $this->clearDB = $post['clear_db'] == 'on';
  344. }
  345. /**
  346. * Notes: 连接数据库
  347. * @author luzg(2020/8/25 11:56)
  348. * @return PDO|string
  349. */
  350. public function connectDB()
  351. {
  352. $dsn = "mysql:host={$this->host}; port={$this->port}";
  353. try {
  354. $dbh = new PDO($dsn, $this->user, $this->password);
  355. $dbh->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
  356. $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  357. $dbh->exec("SET NAMES {$this->encoding}");
  358. $dbh->exec("SET NAMES {$this->encoding}");
  359. try{
  360. $dbh->exec("SET GLOBAL sql_mode='STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';");
  361. }catch (Exception $e){
  362. }
  363. return $dbh;
  364. } catch (PDOException $exception) {
  365. return $exception->getMessage();
  366. }
  367. }
  368. /**
  369. * Notes: 检查数据库是否存在
  370. * @author luzg(2020/8/25 11:56)
  371. * @return mixed
  372. */
  373. public function dbExists()
  374. {
  375. $sql = "SHOW DATABASES like '{$this->name}'";
  376. return $this->dbh->query($sql)->fetch();
  377. }
  378. /**
  379. * Notes: 检查表是否存在
  380. * @author luzg(2020/8/25 11:56)
  381. * @return mixed
  382. */
  383. public function tableExits()
  384. {
  385. $configTable = sprintf("'%s'", $this->prefix . TESTING_TABLE);
  386. $sql = "SHOW TABLES FROM {$this->name} like $configTable";
  387. return $this->dbh->query($sql)->fetch();
  388. }
  389. /**
  390. * Notes: 获取mysql版本号
  391. * @author luzg(2020/8/25 11:56)
  392. * @return false|string
  393. */
  394. public function getMysqlVersion()
  395. {
  396. $sql = "SELECT VERSION() AS version";
  397. $result = $this->dbh->query($sql)->fetch();
  398. return substr($result->version, 0, 3);
  399. }
  400. /**
  401. * @notes 检测数据库sql_mode
  402. * @param $version
  403. * @return bool
  404. * @author 段誉
  405. * @date 2021/8/27 17:17
  406. */
  407. public function checkSqlMode($version)
  408. {
  409. $sql = "SELECT @@global.sql_mode";
  410. $result = $this->dbh->query($sql)->fetch();
  411. $result = (array)$result;
  412. if ($version >= 5.7 && $version < 8.0) {
  413. if ((strpos($result['@@global.sql_mode'],'NO_AUTO_CREATE_USER') !== false)
  414. && (strpos($result['@@global.sql_mode'],'NO_ENGINE_SUBSTITUTION') !== false)) {
  415. return true;
  416. }
  417. return false;
  418. }
  419. return true;
  420. }
  421. /**
  422. * Notes: 创建数据库
  423. * @author luzg(2020/8/25 11:57)
  424. * @param $version
  425. * @return mixed
  426. */
  427. public function createDB($version)
  428. {
  429. $sql = "CREATE DATABASE `{$this->name}`";
  430. if ($version > 4.1) $sql .= " DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci";
  431. return $this->dbh->query($sql);
  432. }
  433. /**
  434. * Notes: 创建表
  435. * @author luzg(2020/8/25 11:57)
  436. * @param $version
  437. * @param $post
  438. * @return bool
  439. * @throws Exception
  440. */
  441. public function createTable($version, $post)
  442. {
  443. $dbFile = $this->getInstallRoot() . '/db/like.sql';
  444. //file_put_contents($dbFile, $this->initAccount($post), FILE_APPEND);
  445. $content = str_replace(";\r\n", ";\n", file_get_contents($dbFile));
  446. $tables = explode(";\n", $content);
  447. $tables[] = $this->initAccount($post);
  448. $installTime = microtime(true) * 10000;
  449. foreach ($tables as $table) {
  450. $table = trim($table);
  451. if (empty($table)) continue;
  452. if (strpos($table, 'CREATE') !== false and $version <= 4.1) {
  453. $table = str_replace('DEFAULT CHARSET=utf8', '', $table);
  454. }
  455. // elseif (strpos($table, 'DROP') !== false and $this->clearDB != false) {
  456. // $table = str_replace('--', '', $table);
  457. // }
  458. /* Skip sql that is note. */
  459. if (strpos($table, '--') === 0) continue;
  460. $table = str_replace('`la_', $this->name . '.`la_', $table);
  461. $table = str_replace('`la_', '`' . $this->prefix, $table);
  462. if (strpos($table, 'CREATE') !== false) {
  463. $tableName = explode('`', $table)[1];
  464. $installTime += random_int(3000, 7000);
  465. $this->successTable[] = [$tableName, date('Y-m-d H:i:s', $installTime / 10000)];
  466. }
  467. // if (strpos($table, "INSERT INTO ") !== false) {
  468. // $table = str_replace('INSERT INTO ', 'INSERT INTO ' .$this->name .'.', $table);
  469. // }
  470. try {
  471. if ( !$this->dbh->query($table)) return false;
  472. } catch (Exception $e) {
  473. echo 'error sql: ' . $table . "<br>";
  474. echo $e->getMessage() . "<br>";
  475. return false;
  476. }
  477. }
  478. return true;
  479. }
  480. /**
  481. * Notes: 删除数据库
  482. * @param $db
  483. * @return false|PDOStatement
  484. */
  485. public function dropDb($db)
  486. {
  487. $sql = "drop database {$db};";
  488. return $this->dbh->query($sql);
  489. }
  490. /**
  491. * Notes: 取得安装成功的表列表
  492. * @author luzg(2020/8/26 18:28)
  493. * @return array
  494. */
  495. public function getSuccessTable()
  496. {
  497. return $this->successTable;
  498. }
  499. /**
  500. * Notes: 创建演示数据
  501. * @author luzg(2020/8/25 11:58)
  502. * @return bool
  503. */
  504. public function importDemoData()
  505. {
  506. $demoDataFile = 'ys.sql';
  507. $demoDataFile = $this->getInstallRoot() . '/db/' . $demoDataFile;
  508. if (!is_file($demoDataFile)) {
  509. echo "<br>";
  510. echo 'no file:' .$demoDataFile;
  511. return false;
  512. }
  513. $content = str_replace(";\r\n", ";\n", file_get_contents($demoDataFile));
  514. $insertTables = explode(";\n", $content);
  515. foreach ($insertTables as $table) {
  516. $table = trim($table);
  517. if (empty($table)) continue;
  518. $table = str_replace('`la_', $this->name . '.`la_', $table);
  519. $table = str_replace('`la_', '`' .$this->prefix, $table);
  520. if ( !$this->dbh->query($table)) return false;
  521. }
  522. // 移动图片资源
  523. $this->cpFiles($this->getInstallRoot().'/uploads', $this->getAppRoot().'/public/uploads');
  524. return true;
  525. }
  526. /**
  527. * 将一个文件夹下的所有文件及文件夹
  528. * 复制到另一个文件夹里(保持原有结构)
  529. *
  530. * @param <string> $rootFrom 源文件夹地址(最好为绝对路径)
  531. * @param <string> $rootTo 目的文件夹地址(最好为绝对路径)
  532. */
  533. function cpFiles($rootFrom, $rootTo){
  534. $handle = opendir($rootFrom);
  535. while (false !== ($file = readdir($handle))) {
  536. //DIRECTORY_SEPARATOR 为系统的文件夹名称的分隔符 例如:windos为'/'; linux为'/'
  537. $fileFrom = $rootFrom . DIRECTORY_SEPARATOR . $file;
  538. $fileTo = $rootTo . DIRECTORY_SEPARATOR . $file;
  539. if ($file == '.' || $file == '..') {
  540. continue;
  541. }
  542. if (is_dir($fileFrom)) {
  543. if (!is_dir($fileTo)) { //目标目录不存在则创建
  544. mkdir($fileTo, 0777);
  545. }
  546. $this->cpFiles($fileFrom, $fileTo);
  547. } else {
  548. if (!file_exists($fileTo)) {
  549. @copy($fileFrom, $fileTo);
  550. if (strstr($fileTo, "access_token.txt")) {
  551. chmod($fileTo, 0777);
  552. }
  553. }
  554. }
  555. }
  556. }
  557. /**
  558. * Notes: 当前应用程序的相对路径
  559. * @author luzg(2020/8/25 10:55)
  560. * @return string
  561. */
  562. public function getAppRoot()
  563. {
  564. return realpath($this->getInstallRoot() . '/../../');
  565. }
  566. /**
  567. * Notes: 获取安装目录
  568. * @author luzg(2020/8/26 16:15)
  569. * @return string
  570. */
  571. public function getInstallRoot()
  572. {
  573. return INSTALL_ROOT;
  574. }
  575. /**
  576. * Notes: 目录的容量
  577. * @author luzg(2020/8/25 15:21)
  578. * @param $dir
  579. * @return string
  580. */
  581. public function freeDiskSpace($dir)
  582. {
  583. // M
  584. $freeDiskSpace = disk_free_space(realpath(__DIR__)) / 1024 / 1024;
  585. // G
  586. if ($freeDiskSpace > 1024) {
  587. return number_format($freeDiskSpace / 1024, 2) . 'G';
  588. }
  589. return number_format($freeDiskSpace, 2) . 'M';
  590. }
  591. /**
  592. * Notes: 获取状态标志
  593. * @author luzg(2020/8/25 16:10)
  594. * @param $statusSingle
  595. * @return string
  596. */
  597. public function correctOrFail($statusSingle)
  598. {
  599. if ($statusSingle == 'ok')
  600. return '<td class="layui-icon green">&#xe605;</td>';
  601. $this->allowNext = false;
  602. return '<td class="layui-icon wrong">&#x1006;</td>';
  603. }
  604. /**
  605. * Notes: 是否允许下一步
  606. * @author luzg(2020/8/25 17:29)
  607. * @return bool
  608. */
  609. public function getAllowNext()
  610. {
  611. return $this->allowNext;
  612. }
  613. /**
  614. * Notes: 检查session auto start
  615. * @author luzg(2020/8/25 16:55)
  616. * @return string
  617. */
  618. public function checkSessionAutoStart()
  619. {
  620. return $result = ini_get('session.auto_start') == '0' ? 'ok' : 'fail';
  621. }
  622. /**
  623. * Notes: 检查auto tags
  624. * @author luzg(2020/8/25 16:55)
  625. * @return string
  626. */
  627. public function checkAutoTags()
  628. {
  629. return $result = ini_get('session.auto_start') == '0' ? 'ok' : 'fail';
  630. }
  631. /**
  632. * Notes: 检查目录是否可写
  633. * @param $dir
  634. * @return string
  635. */
  636. public function checkDirWrite($dir='')
  637. {
  638. $route = $this->getAppRoot().'/'.$dir;
  639. return $result = is_writable($route) ? 'ok' : 'fail';
  640. }
  641. /**
  642. * Notes: 检查目录是否可写
  643. * @param $dir
  644. * @return string
  645. */
  646. public function checkSuperiorDirWrite($dir='')
  647. {
  648. $route = $this->getAppRoot().'/'.$dir;
  649. return $result = is_writable($route) ? 'ok' : 'fail';
  650. }
  651. /**
  652. * Notes: 初始化管理账号
  653. * @param $post
  654. * @return string
  655. */
  656. public function initAccount($post)
  657. {
  658. $time = time();
  659. $salt = substr(md5($time . $post['admin_user']), 0, 4);//随机4位密码盐
  660. global $uniqueSalt;
  661. $uniqueSalt = $salt;
  662. $password = $this->createPassword($post['admin_password'], $salt);
  663. // 超级管理员
  664. $sql = "INSERT INTO `la_admin`(`id`, `root`, `name`, `avatar`, `account`, `password`, `login_time`, `login_ip`, `multipoint_login`, `disable`, `create_time`, `update_time`, `delete_time`) VALUES (1, 1, '{$post['admin_user']}', '', '{$post['admin_user']}', '{$password}','{$time}', '', 1, 0, '{$time}', '{$time}', NULL);";
  665. // 超级管理员关联部门
  666. $sql .= "INSERT INTO `la_admin_dept` (`admin_id`, `dept_id`) VALUES (1, 1);";
  667. return $sql;
  668. }
  669. /**
  670. * Notes: 生成密码密文
  671. * @param $pwd
  672. * @param $salt
  673. * @return string
  674. */
  675. public function createPassword($pwd, $salt)
  676. {
  677. return md5($salt . md5($pwd . $salt));
  678. }
  679. /**
  680. * @notes 恢复admin,mobile index文件
  681. * @author 段誉
  682. * @date 2021/9/16 15:51
  683. */
  684. public function restoreIndexLock()
  685. {
  686. $this->checkIndexFile($this->getAppRoot().'/public/mobile');
  687. $this->checkIndexFile($this->getAppRoot().'/public/admin');
  688. }
  689. public function checkIndexFile($path)
  690. {
  691. if(file_exists($path.'/index_lock.html')) {
  692. // 删除提示文件
  693. unlink($path.'/index.html');
  694. // 恢复原入口
  695. rename($path.'/index_lock.html', $path.'/index.html');
  696. }
  697. }
  698. }