From 8007517225c2929dd915e92c195575b660a52214 Mon Sep 17 00:00:00 2001
From: liyukun <1099438829@qq.com>
Date: Thu, 13 Jan 2022 22:19:28 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E7=BC=BA=E5=B0=91env?=
=?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.gitignore | 2 +-
public/install/.env | 1 +
public/install/index.php | 379 ++++++++++++++++++++-------------------
3 files changed, 200 insertions(+), 182 deletions(-)
create mode 100644 public/install/.env
diff --git a/.gitignore b/.gitignore
index 9f36991..070fb72 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,7 +2,7 @@
/.vscode
*.log
*/.DS_Store
-.env
+/.env
/runtime
/composer.lock
/public/install/install.lock
diff --git a/public/install/.env b/public/install/.env
new file mode 100644
index 0000000..4d65335
--- /dev/null
+++ b/public/install/.env
@@ -0,0 +1 @@
+APP_DEBUG = false
[APP]
DEFAULT_TIMEZONE = Asia/Shanghai
[DATABASE]
TYPE = mysql
HOSTNAME = #DB_HOST#
HOSTPORT = #DB_PORT#
USERNAME = #DB_USER#
PASSWORD = #DB_PWD#
DATABASE = #DB_NAME#
PREFIX = #DB_PREFIX#
CHARSET = utf8
DEBUG = #DB_DEBUG#
[LANG]
default_lang = zh-cn
\ No newline at end of file
diff --git a/public/install/index.php b/public/install/index.php
index 7ee0312..5bffb17 100644
--- a/public/install/index.php
+++ b/public/install/index.php
@@ -1,8 +1,8 @@
phpversion()){
- header("Content-type:text/html;charset=utf-8");
- exit('您的php版本过低,不能安装本软件,请升级到'.PHP_EDITION.'或更高版本再安装,谢谢!');
+if (PHP_EDITION > phpversion()) {
+ header("Content-type:text/html;charset=utf-8");
+ exit('您的php版本过低,不能安装本软件,请升级到' . PHP_EDITION . '或更高版本再安装,谢谢!');
}
define("APEBLOG_VERSION", '20200601');
@@ -29,13 +29,10 @@ error_reporting(E_ALL & ~E_NOTICE);
header('Content-Type: text/html; charset=UTF-8');
define('SITE_DIR', _dir_path(substr(dirname(__FILE__), 0, -8)));//入口文件目录
define('APP_DIR', _dir_path(substr(dirname(__FILE__), 0, -15)));//项目目录
-//define('SITEDIR2', substr(SITEDIR,0,-7));
-//echo SITEDIR;
-//exit;SITE_DIR
//数据库
-$sqlFile = 'ape_blog.sql';
-$configFile = '.env';
-if (!file_exists(SITE_DIR . 'install/' . $sqlFile) || !file_exists(SITE_DIR . 'install/' . $configFile)) {
+$sqlFile = SITE_DIR . 'install/ape_blog.sql';
+$configFile = SITE_DIR . 'install/.env';
+if (!file_exists($sqlFile) || !file_exists($configFile)) {
echo '缺少必要的安装文件!';
exit;
}
@@ -54,7 +51,7 @@ $step = isset($_GET['step']) ? $_GET['step'] : 1;
$scriptName = !empty($_SERVER["REQUEST_URI"]) ? $scriptName = $_SERVER["REQUEST_URI"] : $scriptName = $_SERVER["PHP_SELF"];
$rootpath = @preg_replace("/\/(I|i)nstall\/index\.php(.*)$/", "", $scriptName);
$domain = empty($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'];
-if ((int) $_SERVER['SERVER_PORT'] != 80) {
+if ((int)$_SERVER['SERVER_PORT'] != 80) {
$domain .= ":" . $_SERVER['SERVER_PORT'];
}
$domain = $domain . $rootpath;
@@ -62,13 +59,13 @@ $domain = $domain . $rootpath;
switch ($step) {
case '1':
- include_once ("./templates/step1.php");
+ include_once("./templates/step1.php");
exit();
case '2':
if (phpversion() <= PHP_EDITION) {
- die('本系统需要PHP版本 >= '.PHP_EDITION.'环境,当前PHP版本为:' . phpversion());
+ die('本系统需要PHP版本 >= ' . PHP_EDITION . '环境,当前PHP版本为:' . phpversion());
}
$phpv = @ phpversion();
@@ -112,32 +109,32 @@ switch ($step) {
$session = '√ 不支持';
$err++;
}
- if(function_exists('curl_init')){
- $curl = '[√]支持 ';
- }else{
- $curl = '[×]不支持';
- $err++;
+ if (function_exists('curl_init')) {
+ $curl = '[√]支持 ';
+ } else {
+ $curl = '[×]不支持';
+ $err++;
}
- if(function_exists('bcadd')){
+ if (function_exists('bcadd')) {
$bcmath = '[√]支持 ';
- }else{
+ } else {
$bcmath = '[×]不支持';
$err++;
}
- if(function_exists('openssl_encrypt')){
+ if (function_exists('openssl_encrypt')) {
$openssl = '[√]支持 ';
- }else{
+ } else {
$openssl = '[×]不支持';
$err++;
}
- if(function_exists('finfo_open')){
+ if (function_exists('finfo_open')) {
$finfo_open = '[√]支持 ';
- }else{
+ } else {
$finfo_open = '[×]不支持';
$err++;
}
-
+
$folder = array(
'public/install',
'public/upload',
@@ -145,30 +142,30 @@ switch ($step) {
'.env',
);
//必须开启函数
- if(function_exists('file_put_contents')){
+ if (function_exists('file_put_contents')) {
$file_put_contents = '[√]开启 ';
- }else{
+ } else {
$file_put_contents = '[×]关闭';
$err++;
}
- if(function_exists('imagettftext')){
+ if (function_exists('imagettftext')) {
$imagettftext = '[√]开启 ';
- }else{
+ } else {
$imagettftext = '[×]关闭';
$err++;
}
- include_once ("./templates/step2.php");
+ include_once("./templates/step2.php");
exit();
case '3':
- $dbName = strtolower(trim($_POST['dbName']));
- $_POST['dbport'] = $_POST['dbport'] ? $_POST['dbport'] : '3306';
+ $dbName = strtolower(trim($_POST['dbName']));
+ $_POST['dbport'] = $_POST['dbport'] ? $_POST['dbport'] : '3306';
if ($_GET['testdbpwd']) {
$dbHost = $_POST['dbHost'];
- $conn = @mysqli_connect($dbHost, $_POST['dbUser'], $_POST['dbPwd'],NULL,$_POST['dbport']);
- if (mysqli_connect_errno($conn)){
- die(json_encode(0));
+ $conn = @mysqli_connect($dbHost, $_POST['dbUser'], $_POST['dbPwd'], NULL, $_POST['dbport']);
+ if (mysqli_connect_errno($conn)) {
+ die(json_encode(0));
} else {
// $result = mysqli_query($conn,"SELECT @@global.sql_mode");
// $result = $result->fetch_array();
@@ -178,15 +175,15 @@ switch ($step) {
// if(strstr($result[0],'STRICT_TRANS_TABLES') || strstr($result[0],'STRICT_ALL_TABLES') || strstr($result[0],'TRADITIONAL') || strstr($result[0],'ANSI'))
// exit(json_encode(-1));
// }
- $result = mysqli_query($conn,"select count(table_name) as c from information_schema.`TABLES` where table_schema='$dbName'");
- $result = $result->fetch_array();
- if($result['c'] > 0)
- exit(json_encode(-2));
-
+ $result = mysqli_query($conn, "select count(table_name) as c from information_schema.`TABLES` where table_schema='$dbName'");
+ $result = $result->fetch_array();
+ if ($result['c'] > 0)
+ exit(json_encode(-2));
+
exit(json_encode(1));
}
- }
- include_once ("./templates/step3.php");
+ }
+ include_once("./templates/step3.php");
exit();
@@ -204,17 +201,16 @@ switch ($step) {
$dbPrefix = empty($_POST['dbprefix']) ? 'ape_' : trim($_POST['dbprefix']);
$username = trim($_POST['manager']);
$password = trim($_POST['manager_pwd']);
- $email = trim($_POST['manager_email']);
+ $email = trim($_POST['manager_email']);
if (!function_exists('mysqli_connect')) {
$arr['msg'] = "请安装 mysqli 扩展!";
echo json_encode($arr);
exit;
- }
- ;
- $conn = @mysqli_connect($dbHost, $dbUser, $dbPwd,NULL,$_POST['dbport']);
- if (mysqli_connect_errno($conn)){
- $arr['msg'] = "连接数据库失败!".mysqli_connect_error($conn);
+ };
+ $conn = @mysqli_connect($dbHost, $dbUser, $dbPwd, NULL, $_POST['dbport']);
+ if (mysqli_connect_errno($conn)) {
+ $arr['msg'] = "连接数据库失败!" . mysqli_connect_error($conn);
echo json_encode($arr);
exit;
}
@@ -226,24 +222,24 @@ switch ($step) {
exit;
}
- if (!mysqli_select_db($conn,$dbName)) {
+ if (!mysqli_select_db($conn, $dbName)) {
//创建数据时同时设置编码
- if (!mysqli_query($conn,"CREATE DATABASE IF NOT EXISTS `" . $dbName . "` DEFAULT CHARACTER SET utf8;")) {
+ if (!mysqli_query($conn, "CREATE DATABASE IF NOT EXISTS `" . $dbName . "` DEFAULT CHARACTER SET utf8;")) {
$arr['msg'] = '数据库 ' . $dbName . ' 不存在,也没权限创建新的数据库!';
echo json_encode($arr);
exit;
}
- if ($n==-1) {
+ if ($n == -1) {
$arr['n'] = 0;
$arr['msg'] = "成功创建数据库:{$dbName}
";
echo json_encode($arr);
exit;
}
- mysqli_select_db($conn , $dbName);
+ mysqli_select_db($conn, $dbName);
}
//读取数据文件
- $sqldata = file_get_contents(SITE_DIR . 'install/' . $sqlFile);
+ $sqldata = file_get_contents($sqlFile);
$sqlFormat = sql_split($sqldata, $dbPrefix);
//创建写入sql数据库文件到库中 结束
@@ -255,65 +251,63 @@ switch ($step) {
$sql = trim($sqlFormat[$i]);
if (strstr($sql, 'CREATE TABLE')) {
preg_match('/CREATE TABLE `ape_([^ ]*)`/is', $sql, $matches);
- mysqli_query($conn,"DROP TABLE IF EXISTS `$matches[1]");
- $sql = str_replace('`ape_','`'.$dbPrefix,$sql);//替换表前缀
- $ret = mysqli_query($conn,$sql);
+ mysqli_query($conn, "DROP TABLE IF EXISTS `$matches[1]");
+ $sql = str_replace('`ape_', '`' . $dbPrefix, $sql);//替换表前缀
+ $ret = mysqli_query($conn, $sql);
if ($ret) {
- $message = '