Install.php 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Description: 安装
  4. // +----------------------------------------------------------------------
  5. // | Author: Michael_xu | gengxiaoxu@5kcrm.com
  6. // +----------------------------------------------------------------------
  7. namespace app\admin\controller;
  8. use think\Controller;
  9. use think\Exception;
  10. use think\Request;
  11. use think\Db;
  12. use Env;
  13. class Install extends Controller
  14. {
  15. // private $count = 100;
  16. // private $now = 0;
  17. public function _initialize()
  18. {
  19. /*防止跨域*/
  20. header('Access-Control-Allow-Origin: '.$_SERVER['HTTP_ORIGIN']);
  21. header('Access-Control-Allow-Credentials: true');
  22. header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS');
  23. header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, authKey, sessionId");
  24. $param = Request::instance()->param();
  25. $this->param = $param;
  26. // $request = request();
  27. // $m = strtolower($request->module());
  28. // $c = strtolower($request->controller());
  29. // $a = strtolower($request->action());
  30. //
  31. // if (!in_array($a, array('upgrade','upgradeprocess','checkversion')) && file_exists(CONF_PATH . "install.lock")) {
  32. // echo "<meta http-equiv='content-type' content='text/html; charset=UTF-8'> <script>alert('请勿重复安装!');location.href='".$_SERVER["HTTP_HOST"]."';</script>";
  33. // die();
  34. // }
  35. }
  36. private $upgrade_site = "http://message.72crm.com/";
  37. /**
  38. * [index 安装步骤]
  39. * @author Michael_xu
  40. * @param
  41. */
  42. public function index()
  43. {
  44. $protocol = strpos(strtolower($_SERVER['HTTP_REFERER']), 'https') === false ? 'http' : 'https';
  45. if (strpos(request()->url(), "index.php") === false) {
  46. $url = $protocol. "://" .$_SERVER["HTTP_HOST"] . "/index.php" . request()->url();
  47. header("Location:" . $url);
  48. }
  49. if (file_exists(CONF_PATH . "install.lock")) {
  50. echo "<meta http-equiv='content-type' content='text/html; charset=UTF-8'> <script>alert('请勿重复安装!');location.href='".$protocol."://".$_SERVER["HTTP_HOST"]."';</script>";
  51. die();
  52. }
  53. if (!file_exists(getcwd() . "/public/sql/5kcrm.sql")) {
  54. echo "<meta http-equiv='content-type' content='text/html; charset=UTF-8'> <script>alert('缺少必要的数据库文件!');location.href='".$protocol."://".$_SERVER["HTTP_HOST"]."';</script>";
  55. die();
  56. }
  57. return $this->fetch('index');
  58. }
  59. public function step1()
  60. {
  61. if (strpos(request()->url(), "index.php") === false) {
  62. $protocol = strpos(strtolower($_SERVER['HTTP_REFERER']), 'https') === false ? 'http' : 'https';
  63. $url = $protocol. "://" .$_SERVER["HTTP_HOST"] . "/index.php" . request()->url();
  64. header("Location:" . $url);
  65. }
  66. session('install_error',null);
  67. $data = [];
  68. $data['env'] = self::checkNnv();
  69. $data['dir'] = self::checkDir();
  70. $data['version'] = $this->version();
  71. $this->assign('data',$data);
  72. return $this->fetch('step1');
  73. }
  74. //版本
  75. public function version()
  76. {
  77. $res = include(CONF_PATH.'version.php');
  78. return $res ? : array('VERSION' => '11.0.0','RELEASE' => '20210219');
  79. }
  80. public function step2(){
  81. if (session('install_error')){
  82. echo "<meta http-equiv='content-type' content='text/html; charset=UTF-8'> <script>alert('环境检测未通过,不能进行下一步操作!');location.href='".$_SERVER["HTTP_REFERER"]."';</script>";
  83. die();
  84. }
  85. if (strpos(request()->url(), "index.php") === false) {
  86. $protocol = strpos(strtolower($_SERVER['HTTP_REFERER']), 'https') === false ? 'http' : 'https';
  87. $url = $protocol. "://" .$_SERVER["HTTP_HOST"] . "/index.php" . request()->url();
  88. header("Location:" . $url);
  89. }
  90. $data['os'] = PHP_OS;
  91. $data['php'] = phpversion();
  92. $data['version'] = $this->version();
  93. $this->assign('envir_data',$data);
  94. return $this->fetch();
  95. }
  96. public function step3(){
  97. return $this->fetch();
  98. }
  99. public function step4(){
  100. if (session('install_error')){
  101. return resultArray(['error' => '环境检测未通过,不能进行下一步操作!']);
  102. }
  103. if (file_exists(CONF_PATH . "install.lock")) {
  104. return resultArray(['error' => '请勿重复安装!']);
  105. }
  106. if (!file_exists(getcwd() . "/public/sql/5kcrm.sql")) {
  107. return resultArray(['error' => '缺少必要的数据库文件!']);
  108. }
  109. $temp = $this->param;
  110. $param = $temp['form'];
  111. $db_config['type'] = 'mysql';
  112. $db_config['hostname'] = $param['databaseUrl'];
  113. $db_config['hostport'] = $param['databasePort'];
  114. $db_config['database'] = $param['databaseName'];
  115. $db_config['username'] = $param['databaseUser'];
  116. $db_config['password'] = $param['databasePwd'];
  117. $db_config['prefix'] = '5kcrm_';
  118. // $db_config['prefix'] = $param['databaseTable'];
  119. $username = $param['root'];
  120. $password = $param['pwd'];
  121. $wkcode = $param['wkcode'];
  122. if (empty($db_config['hostname'])) {
  123. return resultArray(['error' => '请填写数据库主机!']);
  124. }
  125. if (empty($db_config['hostport'])) {
  126. return resultArray(['error' => '请填写数据库端口!']);
  127. }
  128. if (preg_match('/[^0-9]/', $db_config['hostport'])) {
  129. return resultArray(['error' => '数据库端口只能是数字!']);
  130. }
  131. if (empty($db_config['database'])) {
  132. return resultArray(['error' => '请填写数据库名!']);
  133. }
  134. if (empty($db_config['username'])) {
  135. return resultArray(['error' => '请填写数据库用户名!']);
  136. }
  137. if (empty($db_config['password'])) {
  138. return resultArray(['error' => '请填写数据库密码!']);
  139. }
  140. if (empty($db_config['prefix'])) {
  141. return resultArray(['error' => '请填写表前缀!']);
  142. }
  143. if (preg_match('/[^a-z0-9_]/i', $db_config['prefix'])) {
  144. return resultArray(['error' => '表前缀只能包含数字、字母和下划线!']);
  145. }
  146. if (empty($username)) {
  147. return resultArray(['error' => '请填写管理员用户名!']);
  148. }
  149. if (empty($wkcode)) {
  150. return resultArray(['error' => '请填写序列号!']);
  151. }
  152. $resCheckData = checkWkCode($wkcode);
  153. if (!$resCheckData) {
  154. return resultArray(['error' => '序列号错误!']);
  155. }
  156. // $resData = object_to_array(json_decode($resCheckData));
  157. // if ($resData['date'] != date('Y-m-d')) {
  158. // return resultArray(['error' => '序列号已失效,请前往悟空官网个人中心获取最新数据!']);
  159. // }
  160. if (empty($password)) {
  161. return resultArray(['error' => '请填写管理员密码!']);
  162. }
  163. session('install_count','');
  164. session('install_now','');
  165. $database = $db_config['database'];
  166. unset($db_config['database']);
  167. $connect = Db::connect($db_config);
  168. // 检测数据库连接
  169. try{
  170. $ret = $connect->execute('select version()');
  171. }catch(\Exception $e){
  172. return resultArray(['error' => '数据库连接失败,请检查数据库配置4!']);
  173. }
  174. $check = $connect->execute("SELECT * FROM information_schema.schemata WHERE schema_name='".$database."'");
  175. if (!$check && !$connect->execute("CREATE DATABASE IF NOT EXISTS `".$database."` default collate utf8_general_ci ")) {
  176. return resultArray(['error' => '没有找到您填写的数据库名且无法创建!请检查连接账号是否有创建数据库的权限!']);
  177. }
  178. $db_config['database'] = $database;
  179. self::mkDatabase($db_config);
  180. self::mkLicense($wkcode);
  181. $C_Patch = substr($_SERVER['SCRIPT_FILENAME'],0,-10);
  182. $sql = file_get_contents( $C_Patch.'/public/sql/5kcrm1.sql');
  183. $sqlList = parse_sql($sql, 0, ['5kcrm_' => $db_config['prefix']]);
  184. if ($sqlList) {
  185. $sqlList = array_filter($sqlList);
  186. $install_count = count($sqlList);
  187. session('install_count',$install_count);
  188. foreach ($sqlList as $k=>$v) {
  189. $install_now = $k+1;
  190. session('install_now',$install_now);
  191. try {
  192. $temp_sql = $v.';';
  193. Db::connect($db_config)->query($temp_sql);
  194. } catch(\Exception $e) {
  195. // return resultArray(['error' => '请启用InnoDB数据引擎,并检查数据库是否有DROP和CREATE权限']);
  196. return resultArray(['error' => '数据库sql安装出错,请操作数据库手动导入sql文件']);
  197. }
  198. }
  199. }
  200. // $salt = substr(md5(time()),0,4);
  201. // $password = user_md5(trim($password), $salt, $username);
  202. // //插入信息
  203. // Db::connect($db_config)->query("insert into ".$db_config['prefix']."admin_user (username, password, salt, img, thumb_img, realname, create_time, num, email, mobile, sex, status, structure_id, post, parent_id, type, authkey, authkey_time ) values ( '".$username."', '".$password."', '".$salt."', '', '', '管理员', ".time().", '', '', '".$username."', '', 1, 1, 'CEO', 0, 1, '', 0 )");
  204. // Db::connect($db_config)->query("insert into ".$db_config['prefix']."hrm_user_det (user_id, join_time, type, status, userstatus, create_time, update_time, mobile, sex, age, job_num, idtype, idnum, birth_time, nation, internship, done_time, parroll_id, email, political, location, leave_time ) values ( 1, ".time().", 1, 1, 2, ".time().", ".time().", '".$username."', '', 0, '', 0, '', '', 0, 0, 0, 0, '', '', '', 0 )");
  205. // touch(CONF_PATH . "install.lock");
  206. return resultArray(['data'=>'安装成功']);
  207. }
  208. public function step7(){
  209. $temp = $this->param;
  210. $param = $temp['form'];
  211. $db_config['type'] = 'mysql';
  212. $db_config['hostname'] = $param['databaseUrl'];
  213. $db_config['hostport'] = $param['databasePort'];
  214. $db_config['database'] = $param['databaseName'];
  215. $db_config['username'] = $param['databaseUser'];
  216. $db_config['password'] = $param['databasePwd'];
  217. $db_config['prefix'] = '5kcrm_';
  218. $C_Patch = substr($_SERVER['SCRIPT_FILENAME'],0,-10);
  219. $sql = file_get_contents( $C_Patch.'/public/sql/5kcrm2.sql');
  220. $sqlList = parse_sql($sql, 0, ['5kcrm_' => $db_config['prefix']]);
  221. if ($sqlList) {
  222. $sqlList = array_filter($sqlList);
  223. $install_count = count($sqlList);
  224. session('install_count',$install_count);
  225. foreach ($sqlList as $k=>$v) {
  226. $install_now = $k+1;
  227. session('install_now',$install_now);
  228. try {
  229. $temp_sql = $v.';';
  230. Db::connect($db_config)->query($temp_sql);
  231. } catch(\Exception $e) {
  232. // return resultArray(['error' => '请启用InnoDB数据引擎,并检查数据库是否有DROP和CREATE权限']);
  233. return resultArray(['error' => '数据库sql安装出错,请操作数据库手动导入sql文件']);
  234. }
  235. }
  236. }
  237. return resultArray(['data'=>'安装成功']);
  238. }
  239. public function step8(){
  240. $temp = $this->param;
  241. $param = $temp['form'];
  242. $db_config['type'] = 'mysql';
  243. $db_config['hostname'] = $param['databaseUrl'];
  244. $db_config['hostport'] = $param['databasePort'];
  245. $db_config['database'] = $param['databaseName'];
  246. $db_config['username'] = $param['databaseUser'];
  247. $db_config['password'] = $param['databasePwd'];
  248. $db_config['prefix'] = '5kcrm_';
  249. $C_Patch = substr($_SERVER['SCRIPT_FILENAME'],0,-10);
  250. $sql = file_get_contents( $C_Patch.'/public/sql/5kcrm3.sql');
  251. $sqlList = parse_sql($sql, 0, ['5kcrm_' => $db_config['prefix']]);
  252. if ($sqlList) {
  253. $sqlList = array_filter($sqlList);
  254. $install_count = count($sqlList);
  255. session('install_count',$install_count);
  256. foreach ($sqlList as $k=>$v) {
  257. $install_now = $k+1;
  258. session('install_now',$install_now);
  259. try {
  260. $temp_sql = $v.';';
  261. Db::connect($db_config)->query($temp_sql);
  262. } catch(\Exception $e) {
  263. // return resultArray(['error' => '请启用InnoDB数据引擎,并检查数据库是否有DROP和CREATE权限']);
  264. return resultArray(['error' => '数据库sql安装出错,请操作数据库手动导入sql文件']);
  265. }
  266. }
  267. }
  268. $username = $param['root'];
  269. $password = $param['pwd'];
  270. $salt = substr(md5(time()),0,4);
  271. $password = user_md5(trim($password), $salt, $username);
  272. // //插入信息
  273. Db::connect($db_config)->query("insert into ".$db_config['prefix']."admin_user (username, password, salt, img, thumb_img, realname, create_time, num, email, mobile, sex, status, structure_id, post, parent_id, type, authkey, authkey_time ) values ( '".$username."', '".$password."', '".$salt."', '', '', '管理员', ".time().", '', '', '".$username."', '', 1, 1, 'CEO', 0, 1, '', 0 )");
  274. Db::connect($db_config)->query("insert into ".$db_config['prefix']."hrm_user_det (user_id, join_time, type, status, userstatus, create_time, update_time, mobile, sex, age, job_num, idtype, idnum, birth_time, nation, internship, done_time, parroll_id, email, political, location, leave_time ) values ( 1, ".time().", 1, 1, 2, ".time().", ".time().", '".$username."', '', 0, '', 0, '', '', 0, 0, 0, 0, '', '', '', 0 )");
  275. touch(CONF_PATH . "install.lock");
  276. return resultArray(['data'=>'安装成功']);
  277. }
  278. public function step10(){
  279. $temp = $this->param;
  280. $param = $temp['form'];
  281. $db_config['type'] = 'mysql';
  282. $db_config['hostname'] = $param['databaseUrl'];
  283. $db_config['hostport'] = $param['databasePort'];
  284. $db_config['database'] = $param['databaseName'];
  285. $db_config['username'] = $param['databaseUser'];
  286. $db_config['password'] = $param['databasePwd'];
  287. $db_config['prefix'] = '5kcrm_';
  288. $C_Patch = substr($_SERVER['SCRIPT_FILENAME'],0,-10);
  289. $sql = file_get_contents( $C_Patch.'/public/sql/5kcrm4.sql');
  290. $sqlList = parse_sql($sql, 0, ['5kcrm_' => $db_config['prefix']]);
  291. if ($sqlList) {
  292. $sqlList = array_filter($sqlList);
  293. $install_count = count($sqlList);
  294. session('install_count',$install_count);
  295. foreach ($sqlList as $k=>$v) {
  296. $install_now = $k+1;
  297. session('install_now',$install_now);
  298. try {
  299. $temp_sql = $v.';';
  300. Db::connect($db_config)->query($temp_sql);
  301. } catch(\Exception $e) {
  302. // return resultArray(['error' => '请启用InnoDB数据引擎,并检查数据库是否有DROP和CREATE权限']);
  303. return resultArray(['error' => '数据库sql安装出错,请操作数据库手动导入sql文件']);
  304. }
  305. }
  306. }
  307. return resultArray(['data'=>'安装成功']);
  308. }
  309. public function step11(){
  310. $temp = $this->param;
  311. $param = $temp['form'];
  312. $db_config['type'] = 'mysql';
  313. $db_config['hostname'] = $param['databaseUrl'];
  314. $db_config['hostport'] = $param['databasePort'];
  315. $db_config['database'] = $param['databaseName'];
  316. $db_config['username'] = $param['databaseUser'];
  317. $db_config['password'] = $param['databasePwd'];
  318. $db_config['prefix'] = '5kcrm_';
  319. $C_Patch = substr($_SERVER['SCRIPT_FILENAME'],0,-10);
  320. $sql = file_get_contents( $C_Patch.'/public/sql/5kcrm5.sql');
  321. $sqlList = parse_sql($sql, 0, ['5kcrm_' => $db_config['prefix']]);
  322. if ($sqlList) {
  323. $sqlList = array_filter($sqlList);
  324. $install_count = count($sqlList);
  325. session('install_count',$install_count);
  326. foreach ($sqlList as $k=>$v) {
  327. $install_now = $k+1;
  328. session('install_now',$install_now);
  329. try {
  330. $temp_sql = $v.';';
  331. Db::connect($db_config)->query($temp_sql);
  332. } catch(\Exception $e) {
  333. // return resultArray(['error' => '请启用InnoDB数据引擎,并检查数据库是否有DROP和CREATE权限']);
  334. return resultArray(['error' => '数据库sql安装出错,请操作数据库手动导入sql文件']);
  335. }
  336. }
  337. }
  338. return resultArray(['data'=>'安装成功']);
  339. }
  340. /**
  341. * sql多文件执行
  342. * @param $sqlList
  343. * @param $db_config
  344. * @return \think\response\Json
  345. */
  346. public function sqlData($sqlList,$db_config){
  347. try {
  348. $install_count = count($sqlList);
  349. session('install_count',$install_count);
  350. $res_count=ceil($install_count);
  351. for($i=0;$i<=$res_count;$i++){
  352. $page = $i>0?$i*100+1 :1;
  353. $excelData = array_slice($sqlList, $page ,100);
  354. if($excelData){
  355. foreach($excelData as $k=>$v){
  356. $install_now = $k+1;
  357. session('install_now',$install_now);
  358. $temp_sql = $v.';';
  359. Db::connect($db_config)->query($temp_sql);
  360. // return resultArray(['error' => '请启用InnoDB数据引擎,并检查数据库是否有DROP和CREATE权限']);
  361. return resultArray(['error' => '数据库sql安装出错,请操作数据库手动导入sql文件']);
  362. }
  363. }
  364. }
  365. Db::commit();
  366. }catch (\Exception $e){
  367. Db::rollback();
  368. return resultArray(['error'=>$e->getMessage()]);
  369. }
  370. }
  371. /**
  372. * 安装成功界面
  373. *
  374. * @author fnqi
  375. * @date 2021-03-11
  376. * @return mixed
  377. */
  378. public function step5()
  379. {
  380. return $this->fetch();
  381. }
  382. /**
  383. * 安装超时界面
  384. *
  385. * @author fanqi
  386. * @date 2021-03-11
  387. * @return mixed
  388. */
  389. public function step6()
  390. {
  391. return $this->fetch();
  392. }
  393. //ajax 进度条
  394. public function progress()
  395. {
  396. $data['length'] = session('install_count');
  397. $data['now'] = session('install_now');
  398. return resultArray(['data'=>$data]);
  399. }
  400. //添加database.php文件
  401. private function mkDatabase(array $data)
  402. {
  403. $code = <<<INFO
  404. <?php
  405. return [
  406. // 数据库类型
  407. 'type' => 'mysql',
  408. // 服务器地址
  409. 'hostname' => '{$data['hostname']}',
  410. // 数据库名
  411. 'database' => '{$data['database']}',
  412. // 用户名
  413. 'username' => '{$data['username']}',
  414. // 密码
  415. 'password' => '{$data['password']}',
  416. // 端口
  417. 'hostport' => '{$data['hostport']}',
  418. // 连接dsn
  419. 'dsn' => '',
  420. // 数据库连接参数
  421. 'params' => [],
  422. // 数据库编码默认采用utf8
  423. 'charset' => 'utf8',
  424. // 数据库表前缀
  425. 'prefix' => '{$data['prefix']}',
  426. // 数据库调试模式
  427. 'debug' => true,
  428. // 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器)
  429. 'deploy' => 0,
  430. // 数据库读写是否分离 主从式有效
  431. 'rw_separate' => false,
  432. // 读写分离后 主服务器数量
  433. 'master_num' => 1,
  434. // 指定从服务器序号
  435. 'slave_no' => '',
  436. // 自动读取主库数据
  437. 'read_master' => false,
  438. // 是否严格检查字段是否存在
  439. 'fields_strict' => true,
  440. // 数据集返回类型
  441. 'resultset_type' => 'array',
  442. ];
  443. INFO;
  444. file_put_contents( CONF_PATH.'database.php', $code);
  445. // 判断写入是否成功
  446. $config = include CONF_PATH.'database.php';
  447. if (empty($config['database']) || $config['database'] != $data['database']) {
  448. return resultArray(['error' => '[config/database.php]数据库配置写入失败!']);
  449. }
  450. return true;
  451. }
  452. //检查目录权限
  453. public function check_dir_iswritable($dir_path){
  454. $dir_path=str_replace( '\\','/',$dir_path);
  455. $is_writale=1;
  456. if (!is_dir($dir_path)) {
  457. $is_writale=0;
  458. return $is_writale;
  459. } else {
  460. $file_hd=@fopen($dir_path.'/test.txt','w');
  461. if (!$file_hd) {
  462. @fclose($file_hd);
  463. @unlink($dir_path.'/test.txt');
  464. $is_writale=0;
  465. return $is_writale;
  466. }
  467. $dir_hd = opendir($dir_path);
  468. while (false !== ($file=readdir($dir_hd))) {
  469. if ($file != "." && $file != "..") {
  470. if (is_file($dir_path.'/'.$file)) {
  471. //文件不可写,直接返回
  472. if (!is_writable($dir_path.'/'.$file)) {
  473. return 0;
  474. }
  475. } else {
  476. $file_hd2=@fopen($dir_path.'/'.$file.'/test.txt','w');
  477. if (!$file_hd2) {
  478. @fclose($file_hd2);
  479. @unlink($dir_path.'/'.$file.'/test.txt');
  480. $is_writale=0;
  481. return $is_writale;
  482. }
  483. //递归
  484. $is_writale=check_dir_iswritable($dir_path.'/'.$file);
  485. }
  486. }
  487. }
  488. }
  489. return $is_writale;
  490. }
  491. /**
  492. * [checkVersion 检查升级]
  493. * @author Michael_xu
  494. * @param
  495. */
  496. public function checkVersion(){
  497. $version = Config::load('version');
  498. $info = sendRequest($this->upgrade_site.'index.php?m=version&a=checkVersion', $version['VERSION']);
  499. if ($info){
  500. return resultArray(['data' => $info]);
  501. } else {
  502. return resultArray(['error' => '检查新版本出错!']);
  503. }
  504. }
  505. /**
  506. * 环境检测
  507. * @return array
  508. */
  509. private function checkNnv()
  510. {
  511. $items = [
  512. 'os' => ['操作系统', PHP_OS, '类Unix', 'ok'],
  513. 'php' => ['PHP版本', PHP_VERSION, '7.3 ( <em style="color: #888; font-size: 12px;">>= 7.0</em> )', 'ok','性能更佳'],
  514. 'gd' => ['gd', '开启', '开启', 'ok'],
  515. 'openssl' => ['openssl', '开启', '开启', 'ok'],
  516. 'pdo' => ['pdo', '开启', '开启', 'ok'],
  517. ];
  518. // linux系统下需要posix扩展
  519. if (in_array(PHP_OS, ['Linux', 'centos', 'Centos', 'ubuntu', 'Ubuntu'])) {
  520. $items['posix'] = ['posix', '开启', '开启', 'ok'];
  521. }
  522. session('install_error','');
  523. if (substr($items['php'][1],0,3) < '7.0') {
  524. $items['php'][3] = 'error';
  525. session('install_error', true);
  526. }
  527. if (!extension_loaded('gd')) {
  528. $items['gd'][1] = '未开启';
  529. $items['gd'][3] = 'error';
  530. session('install_error', true);
  531. }
  532. if (!extension_loaded('openssl')) {
  533. $items['openssl'][1] = '未开启';
  534. $items['openssl'][3] = 'error';
  535. session('install_error', true);
  536. }
  537. if (!extension_loaded('pdo')) {
  538. $items['pdo'][1] = '未开启';
  539. $items['pdo'][3] = 'error';
  540. session('install_error', true);
  541. }
  542. // linux系统下检查是否加载了posix扩展
  543. if (in_array(PHP_OS, ['Linux', 'centos', 'Centos', 'ubuntu', 'Ubuntu']) && !extension_loaded('posix')) {
  544. $items['posix'][1] = '未开启';
  545. $items['posix'][3] = 'error';
  546. session('install_error', true);
  547. }
  548. return $items;
  549. }
  550. /**
  551. * 目录权限检查
  552. * @return array
  553. */
  554. private function checkDir()
  555. {
  556. $items = [
  557. ['dir', $this->root_path.'application', 'application', '读写', '读写', 'ok'],
  558. ['dir', $this->root_path.'extend', 'extend', '读写', '读写', 'ok'],
  559. ['dir', $this->root_path.'runtime', './temp', '读写', '读写', 'ok'],
  560. ['dir', $this->root_path.'public', './upload', '读写', '读写', 'ok'],
  561. ['file', $this->root_path.'config', 'config', '读写', '读写', 'ok'],
  562. ];
  563. foreach ($items as &$v) {
  564. if ($v[0] == 'dir') {// 文件夹
  565. if (!is_writable($v[1])) {
  566. if (is_dir($v[1])) {
  567. $v[4] = '不可写';
  568. $v[5] = 'no';
  569. } else {
  570. $v[4] = '不存在';
  571. $v[5] = 'no';
  572. }
  573. session('install_error', true);
  574. }
  575. } else {// 文件
  576. if (!is_writable($v[1])) {
  577. $v[4] = '不可写';
  578. $v[5] = 'no';
  579. session('install_error', true);
  580. }
  581. }
  582. }
  583. return $items;
  584. }
  585. /**
  586. * 验证序列号
  587. * @param
  588. * @return
  589. */
  590. public function checkCodeOld($username) {
  591. $encryption = md5($username);
  592. $substr = substr($username, strlen($username)-6);
  593. $subArr = str_split($substr, 1);
  594. $code = '';
  595. for ($i = 0; $i <= 5; $i++) {
  596. $code .= $encryption[$subArr[$i]];
  597. }
  598. return $code;
  599. }
  600. //写入license文件
  601. private function mkLicense($wkcode)
  602. {
  603. file_put_contents( CONF_PATH.'license.dat', $wkcode);
  604. // 判断写入是否成功
  605. // $config = include CONF_PATH.'license.dat';
  606. // if (empty($config)) {
  607. // return resultArray(['error' => 'license配置写入失败!']);
  608. // }
  609. return true;
  610. }
  611. }