Skip to content
This repository was archived by the owner on Jun 6, 2024. It is now read-only.

Commit f0a02b7

Browse files
committed
fix unable to install; add errtype 5
1 parent 55ed303 commit f0a02b7

File tree

3 files changed

+53
-44
lines changed

3 files changed

+53
-44
lines changed

api.php

Lines changed: 50 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,68 @@
1212
*/
1313
session_start();
1414
define('init', true);
15+
require('./common/functions.php');
16+
$method = (!empty($_GET["m"])) ? $_GET["m"] : "";
17+
if ($method === "CheckMySQLConnect") {
18+
if (file_exists('config.php')) {
19+
// 如果已经安装过一次,必须管理员登录
20+
$is_login = (empty($_SESSION["admin_login"])) ? false : $_SESSION["admin_login"];
21+
if (!$is_login) { // 未登录
22+
EchoInfo(-3, array("msg" => "请刷新页面后重新登录"));
23+
}
24+
}
25+
error_reporting(0);
26+
// 检查数据库连接是否正常
27+
$servername = htmlspecialchars((!empty($_POST["servername"])) ? $_POST["servername"] : "", ENT_QUOTES);
28+
$username = htmlspecialchars((!empty($_POST["username"])) ? $_POST["username"] : "", ENT_QUOTES);
29+
$DBPassword = htmlspecialchars((!empty($_POST["DBPassword"])) ? $_POST["DBPassword"] : "", ENT_QUOTES);
30+
$dbname = htmlspecialchars((!empty($_POST["dbname"])) ? $_POST["dbname"] : "", ENT_QUOTES);
31+
$dbtable = htmlspecialchars((!empty($_POST["dbtable"])) ? $_POST["dbtable"] : "", ENT_QUOTES);
32+
if (!function_exists('mysqli_connect')) {
33+
EchoInfo(-2, array("msg" => "<br/>您未安装或未启用 mysqli 扩展,<br/>不能使用数据库功能。<br/>请自行关闭数据库功能。"));
34+
}
35+
$conn = mysqli_connect($servername, $username, $DBPassword);
36+
$GLOBALS['conn'] = $conn;
37+
// Check connection
38+
if (!$conn) {
39+
EchoInfo(-1, array("msg" => mysqli_connect_error()));
40+
} else {
41+
// 连接成功,检查数据库是否存在
42+
$sql = "SELECT * FROM information_schema.SCHEMATA WHERE SCHEMA_NAME = '$dbname';"; // 查询是否有此数据库
43+
$mysql_query = mysqli_query($conn, $sql);
44+
if (mysqli_fetch_assoc($mysql_query)) {
45+
// 存在数据库
46+
EchoInfo(0, array("msg" => "数据库连接成功,存在 $dbname 数据库"));
47+
} else {
48+
// 不存在数据库,需创建
49+
$sql = "CREATE DATABASE `$dbname` character set utf8;"; // 查询是否有此数据库
50+
$mysql_query = mysqli_query($conn, $sql);
51+
if ($mysql_query) {
52+
// 创建成功
53+
EchoInfo(0, array("msg" => "成功连接并创建数据库 $dbname"));
54+
} else {
55+
// 创建失败
56+
EchoInfo(-1, array("msg" => "数据库连接成功,但创建数据库失败。<br />请手动创建 $dbname 数据库后再次检查连接。<br />"));
57+
}
58+
}
59+
}
60+
die();
61+
}
62+
1563
if (!file_exists('./common/invalidCheck.php')) {
1664
http_response_code(503);
1765
header('Content-Type: text/plain; charset=utf-8');
1866
header('Refresh: 5;url=https://github.com/yuantuo666/baiduwp-php');
1967
die("HTTP 503 服务不可用!\r\n缺少相关配置和定义文件!无法正常运行程序!\r\n请重新 Clone 项目并进入此页面安装!\r\n将在五秒内跳转到 GitHub 储存库!");
2068
}
2169
require('./common/invalidCheck.php');
22-
$method = (!empty($_GET["m"])) ? $_GET["m"] : ""; // 下一步判断是否引用config.php需用到
2370
// 导入配置和函数
24-
if ($method != "CheckMySQLConnect") { // 如果是使用检查连接,还没有配置好文件,不能引用
25-
require('config.php');
26-
}
27-
require('./common/functions.php');
71+
require('./config.php');
2872
// 通用响应头
2973
header('Content-Type: text/html; charset=utf-8');
3074
header('X-UA-Compatible: IE=edge,chrome=1');
3175
// 隐藏错误代码,保护信息安全
32-
if ($method != "CheckMySQLConnect" and DEBUG) {
76+
if (DEBUG) {
3377
error_reporting(E_ALL);
3478
} else {
3579
error_reporting(0); // 关闭错误报告
@@ -286,42 +330,6 @@
286330
EchoInfo(-1, array("msg" => "未开启数据库功能"));
287331
}
288332
break;
289-
case "CheckMySQLConnect":
290-
// 检查数据库连接是否正常
291-
$servername = htmlspecialchars((!empty($_POST["servername"])) ? $_POST["servername"] : "", ENT_QUOTES);
292-
$username = htmlspecialchars((!empty($_POST["username"])) ? $_POST["username"] : "", ENT_QUOTES);
293-
$DBPassword = htmlspecialchars((!empty($_POST["DBPassword"])) ? $_POST["DBPassword"] : "", ENT_QUOTES);
294-
$dbname = htmlspecialchars((!empty($_POST["dbname"])) ? $_POST["dbname"] : "", ENT_QUOTES);
295-
$dbtable = htmlspecialchars((!empty($_POST["dbtable"])) ? $_POST["dbtable"] : "", ENT_QUOTES);
296-
if (!function_exists('mysqli_connect')) {
297-
EchoInfo(-2, array("msg" => "<br/>您未安装或未启用 mysqli 扩展,<br/>不能使用数据库功能。<br/>请自行关闭数据库功能。"));
298-
}
299-
$conn = mysqli_connect($servername, $username, $DBPassword);
300-
$GLOBALS['conn'] = $conn;
301-
// Check connection
302-
if (!$conn) {
303-
EchoInfo(-1, array("msg" => mysqli_connect_error()));
304-
} else {
305-
// 连接成功,检查数据库是否存在
306-
$sql = "SELECT * FROM information_schema.SCHEMATA WHERE SCHEMA_NAME = '$dbname';"; // 查询是否有此数据库
307-
$mysql_query = mysqli_query($conn, $sql);
308-
if (mysqli_fetch_assoc($mysql_query)) {
309-
// 存在数据库
310-
EchoInfo(0, array("msg" => "数据库连接成功,存在 $dbname 数据库"));
311-
} else {
312-
// 不存在数据库,需创建
313-
$sql = "CREATE DATABASE `$dbname` character set utf8;"; // 查询是否有此数据库
314-
$mysql_query = mysqli_query($conn, $sql);
315-
if ($mysql_query) {
316-
// 创建成功
317-
EchoInfo(0, array("msg" => "成功连接并创建数据库 $dbname"));
318-
} else {
319-
// 创建失败
320-
EchoInfo(-1, array("msg" => "数据库连接成功,但创建数据库失败。<br />请手动创建 $dbname 数据库后再次检查连接。<br />"));
321-
}
322-
}
323-
}
324-
break;
325333
case "CheckUpdate":
326334
$includePreRelease = false; // 定义和获取是否包含预发行,是否强制检查
327335
$enforce = false;

common/functions.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* @link https://space.bilibili.com/88197958
1313
*
1414
*/
15-
require_once("./common/invalidCheck.php");
15+
if (!init) require_once("./common/invalidCheck.php");
1616

1717
// main
1818
function setCurl(&$ch, array $header)
@@ -140,7 +140,7 @@ function GetSign(string $surl = "", string $share_id = "", string $uk = "")
140140
$timestamp = $result["data"]["timestamp"];
141141
return [0, $sign, $timestamp];
142142
} else {
143-
return [-1, $result["show_msg"] ?? ""];
143+
return [-1, $result["show_msg"] ?? "", ""];
144144
}
145145
}
146146
function FileInfo(string $filename, float $size, string $md5, int $server_ctime)

common/list.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"mispw_9" => "提取码错误",
4242
"mispwd-9" => "提取码错误",
4343
"mis_2" => "不存在此目录",
44+
5 => "不存在此分享链接或提取码错误",
4445
3 => "此链接分享内容可能因为涉及侵权、色情、反动、低俗等信息,无法访问!",
4546
0 => "啊哦,你来晚了,分享的文件已经被删除了,下次要早点哟。",
4647
10 => "啊哦,来晚了,该分享文件已过期",

0 commit comments

Comments
 (0)