IndexController.class.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <?php
  2. /**
  3. * 洛阳赤炎鹰网络科技有限公司
  4. * https://www.cyyvip.com
  5. * Copyright (c) 2022 赤店商城 All rights reserved.
  6. */
  7. namespace Install\Controller;
  8. use Think\Controller;
  9. use Think\Db;
  10. set_time_limit(0);
  11. /**
  12. * 首页
  13. */
  14. class IndexController extends Controller {
  15. function _initialize(){
  16. if(file_exists_case("../install.lock.php")){
  17. redirect(__ROOT__."/");
  18. }
  19. }
  20. //首页
  21. public function index() {
  22. $this->display(":index");
  23. }
  24. public function step2(){
  25. $data=array();
  26. $data['os']=PHP_OS;
  27. $tmp = function_exists('gd_info') ? gd_info() : array();
  28. $server = $_SERVER["SERVER_SOFTWARE"];
  29. $host = (empty($_SERVER["SERVER_ADDR"]) ? $_SERVER["SERVER_HOST"] : $_SERVER["SERVER_ADDR"]);
  30. $name = $_SERVER["SERVER_NAME"];
  31. $max_execution_time = ini_get('max_execution_time');
  32. $allow_reference = (ini_get('allow_call_time_pass_reference') ? '<font color=green>[√]On</font>' : '<font color=red>[×]Off</font>');
  33. $allow_url_fopen = (ini_get('allow_url_fopen') ? '<font color=green>[√]On</font>' : '<font color=red>[×]Off</font>');
  34. $safe_mode = (ini_get('safe_mode') ? '<font color=red>[×]On</font>' : '<font color=green>[√]Off</font>');
  35. $err = 0;
  36. if (empty($tmp['GD Version'])) {
  37. $gd = '<font color=red>[×]Off</font>';
  38. $err++;
  39. } else {
  40. $gd = '<font color=green>[√]On</font> ' . $tmp['GD Version'];
  41. }
  42. if (extension_loaded('fileinfo')) {
  43. $data['fileinfo'] = '<i class="fa fa-check correct"></i> 已开启';
  44. } else {
  45. $data['fileinfo'] = '<i class="fa fa-remove error"></i> 未开启';
  46. $err++;
  47. }
  48. if (extension_loaded('SimpleXML')) {
  49. $data['SimpleXML'] = '<i class="fa fa-check correct"></i> 已开启';
  50. } else {
  51. $data['SimpleXML'] = '<i class="fa fa-remove error"></i> 未开启';
  52. $err++;
  53. }
  54. if (self::php_version()) {
  55. $data['phpversion'] = '<i class="fa fa-check correct"></i> ' . @ phpversion();
  56. } else {
  57. $data['phpversion'] = '<i class="fa fa-remove error"></i> ' . @ phpversion();
  58. $err++;
  59. }
  60. if (class_exists('pdo')) {
  61. $data['pdo'] = '<i class="fa fa-check correct"></i> 已开启';
  62. } else {
  63. $data['pdo'] = '<i class="fa fa-remove error"></i> 未开启';
  64. $err++;
  65. }
  66. if (extension_loaded('pdo_mysql')) {
  67. $data['pdo_mysql'] = '<i class="fa fa-check correct"></i> 已开启';
  68. } else {
  69. $data['pdo_mysql'] = '<i class="fa fa-remove error"></i> 未开启';
  70. $err++;
  71. }
  72. if (ini_get('file_uploads')) {
  73. $data['upload_size'] = '<i class="fa fa-check correct"></i> ' . ini_get('upload_max_filesize');
  74. } else {
  75. $data['upload_size'] = '<i class="fa fa-remove error"></i> 禁止上传';
  76. }
  77. if (function_exists('session_start')) {
  78. $data['session'] = '<i class="fa fa-check correct"></i> 支持';
  79. } else {
  80. $data['session'] = '<i class="fa fa-remove error"></i> 不支持';
  81. $err++;
  82. }
  83. if (function_exists('curl_init')) {
  84. $data['curl_init'] = '<i class="fa fa-check correct"></i> 支持';
  85. } else {
  86. $data['curl_init'] = '<i class="fa fa-remove error"></i> 不支持';
  87. $err++;
  88. }
  89. if (function_exists('openssl_decrypt')) {
  90. $data['php_openssl'] = '<i class="fa fa-check correct"></i> 支持';
  91. } else {
  92. $data['php_openssl'] = '<i class="fa fa-remove error"></i> 不支持';
  93. $err++;
  94. }
  95. $folders = array(
  96. '../',//根目录
  97. '../config/',
  98. '../runtime/',
  99. '../web/',
  100. );
  101. $new_folders=array();
  102. foreach($folders as $dir){
  103. $Testdir = "./".$dir;
  104. sp_dir_create($Testdir);
  105. if(sp_testwrite($Testdir)){
  106. $new_folders[$dir]['w']=true;
  107. }else{
  108. $new_folders[$dir]['w']=false;
  109. $err++;
  110. }
  111. if(is_readable($Testdir)){
  112. $new_folders[$dir]['r']=true;
  113. }else{
  114. $new_folders[$dir]['r']=false;
  115. $err++;
  116. }
  117. }
  118. $data['folders']=$new_folders;
  119. $data['err']=$err;
  120. $this->assign($data);
  121. $this->display(":step2");
  122. }
  123. public function step3(){
  124. $this->display(":step3");
  125. }
  126. public function step4(){
  127. if(IS_POST){
  128. //创建数据库
  129. $dbconfig['DB_TYPE']="mysql";
  130. $dbconfig['DB_HOST']=I('post.dbhost');
  131. $dbconfig['DB_USER']=I('post.dbuser');
  132. $dbconfig['DB_PWD']=I('post.dbpw');
  133. $db = Db::getInstance($dbconfig);
  134. $dbname=strtolower(I('post.dbname'));
  135. $sql = "CREATE DATABASE IF NOT EXISTS `{$dbname}` DEFAULT CHARACTER SET utf8mb4";
  136. $db->execute($sql) || $this->error($db->getError());
  137. $this->display(":step4");
  138. //创建数据表
  139. $dbconfig['DB_NAME']=$dbname;
  140. $dbconfig['DB_PREFIX']=trim(I('post.dbprefix'));
  141. $db = Db::getInstance($dbconfig);
  142. $table_prefix=I("post.dbprefix");
  143. sp_execute_sql($db, "sql.sql", $table_prefix);
  144. //生成网站配置文件
  145. sp_create_config($dbconfig);
  146. session("_install_step",4);
  147. sleep(1);
  148. $this->redirect("step5");
  149. }else{
  150. exit;
  151. }
  152. }
  153. public function step5(){
  154. if(session("_install_step")==4){
  155. @touch('../install.lock.php');
  156. $this->display(":step5");
  157. }else{
  158. $this->error("非法安装!");
  159. }
  160. }
  161. public function testdbpwd(){
  162. if(IS_POST){
  163. $dbconfig=I("POST.");
  164. $dbconfig['DB_TYPE']="mysql";
  165. $db = Db::getInstance($dbconfig);
  166. try{
  167. $db->query("show databases;");
  168. }catch (\Exception $e){
  169. die("");
  170. }
  171. exit("1");
  172. }else{
  173. exit("need post!");
  174. }
  175. }
  176. /**
  177. * 判断当前环境php版本是否大于大于等于指定的一个版本
  178. * @param string $version
  179. * @return boolean
  180. */
  181. public static function php_version( $version = '7.4.0' ) {
  182. $php_version = @ phpversion();
  183. // =0表示版本为7.4.0 =1表示大于7.4.0 =-1表示小于7.4.0
  184. $is_pass = strnatcasecmp( $php_version, $version ) >= 0 ? true : false;
  185. return $is_pass;
  186. }
  187. }