From 6c8e3ce29cb2deb0cf08495ee6eebe3424bab433 Mon Sep 17 00:00:00 2001 From: Boris Zhao Date: Mon, 16 Dec 2024 17:41:46 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E6=9B=B4=E6=96=B0.gitignore?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 忽略macOS的`.DS_Store`文件 忽略Dev Container和VSCode配置 --- .gitignore | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 7e400f6c..fd83ab9e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ .idea/ setup/install.lock -!plugins/wmzz_debug \ No newline at end of file +!plugins/wmzz_debug +.DS_Store +.devcontainer +.vscode From 3a36907cfe487349d20fc15313d0f7ef3bfaf993 Mon Sep 17 00:00:00 2001 From: Boris Zhao Date: Mon, 16 Dec 2024 17:45:16 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E6=94=AF=E6=8C=81=E9=80=9A=E8=BF=87SSL?= =?UTF-8?q?=E8=BF=9E=E6=8E=A5MySQL=E6=95=B0=E6=8D=AE=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.php | 4 +++- lib/class.S.php | 4 ++-- lib/class.mysql.php | 12 +++++++++--- lib/class.mysqli.php | 20 ++++++++++++++++---- lib/mysql_autoload.php | 2 +- setup/install.php | 9 +++++++++ 6 files changed, 40 insertions(+), 11 deletions(-) diff --git a/config.php b/config.php index 98f3d6e0..dbf0b6fe 100644 --- a/config.php +++ b/config.php @@ -1,4 +1,4 @@ -getMessage()); } diff --git a/lib/class.mysql.php b/lib/class.mysql.php index 5a6f95d0..c62dd101 100644 --- a/lib/class.mysql.php +++ b/lib/class.mysql.php @@ -41,15 +41,21 @@ class wmysql * @param string $name 数据库名 * @param bool $long 是否开启长连接 */ - public function __construct($host, $user, $pw, $name, $long = false) + public function __construct($host, $user, $pw, $name, $long = false, $useSsl = false) { if (!function_exists('mysql_connect')) { throw new Exception('服务器PHP不支持MySql数据库'); } + + $flag = 0; + if ($useSsl) { + $flag = $flag & MYSQL_CLIENT_SSL; + } + if ($long) { - $this->conn = @mysql_pconnect($host, $user, $pw); + $this->conn = @mysql_pconnect($host, $user, $pw, $flag); } else { - $this->conn = @mysql_connect($host, $user, $pw); + $this->conn = @mysql_connect($host, $user, $pw, client_flags: $flag); } if (!$this->conn) { switch ($this->geterrno()) { diff --git a/lib/class.mysqli.php b/lib/class.mysqli.php index 2d2a50a9..da0e4f88 100644 --- a/lib/class.mysqli.php +++ b/lib/class.mysqli.php @@ -41,24 +41,36 @@ class wmysql * @param string $name 数据库名 * @param bool $long 是否开启长连接 */ - public function __construct($host, $user, $pw, $name, $long = false) + public function __construct($host, $user, $pw, $name, $long = false, $useSsl = false) { if (!class_exists('mysqli')) { throw new Exception('服务器不支持MySqli类'); } $coninfo = strpos($host, ':'); + + $mysqli = mysqli_init(); + if ($useSsl) { + $mysqli->ssl_set(null, null, "/etc/ssl/certs/ca-certificates.crt", "/etc/ssl/certs", null); + } + + $connected = false; if ($coninfo === false) { if ($long) { $host = 'p:' . $host; } - @$this->conn = new mysqli($host, $user, $pw, $name); + $connected = $mysqli->real_connect($host, $user, $pw, $name); } else { if ($long) { - @$this->conn = new mysqli('p:' . substr($host, 0, $coninfo), $user, $pw, $name, substr($host, $coninfo + 1)); + $connected = $mysqli->real_connect('p:' . substr($host, 0, $coninfo), $user, $pw, $name, substr($host, $coninfo + 1)); } else { - @$this->conn = new mysqli(substr($host, 0, $coninfo), $user, $pw, $name, substr($host, $coninfo + 1)); + $connected = $mysqli->real_connect(substr($host, 0, $coninfo), $user, $pw, $name, substr($host, $coninfo + 1)); } } + + if (!$connected) { + throw new Exception("连接数据库失败,原因:{$mysqli->error}"); + } + @$this->conn = $mysqli; if ($this->conn->connect_error) { switch ($this->conn->connect_errno) { diff --git a/lib/mysql_autoload.php b/lib/mysql_autoload.php index 12929f50..9173ffa6 100644 --- a/lib/mysql_autoload.php +++ b/lib/mysql_autoload.php @@ -22,4 +22,4 @@ require SYSTEM_ROOT . '/lib/class.mysql.php'; } require SYSTEM_ROOT . '/lib/class.S.php'; -$m = new S(DB_HOST, DB_USER, DB_PASSWD, DB_NAME, LONGSQL); //以后直接使用$m->函数()即可操作数据库 +$m = new S(DB_HOST, DB_USER, DB_PASSWD, DB_NAME, LONGSQL, DB_SSL); //以后直接使用$m->函数()即可操作数据库 diff --git a/setup/install.php b/setup/install.php index a4453281..de4cfddc 100644 --- a/setup/install.php +++ b/setup/install.php @@ -76,6 +76,8 @@ define(\'DB_PASSWD\',\'******\'); //MySQL 数据库名称 define(\'DB_NAME\',\'******\'); +//MySQL 启用SSL连接,如需启用请将值改为1 +define(\'DB_SSL\', 0); ////////////////////////////以下选项使用任何数据库都需填写//////////////////////////// //数据库前缀,建议保持默认 @@ -133,8 +135,10 @@ echo '
数据库密码

'; echo '
数据库名称

'; echo '
数据表前缀

'; + echo '
数据库开启SSL

'; echo ''; echo ''; + echo ''; } else { echo '
提示 1:如果您已经手动写好了 config.php ,请选择 [ 自动获得数据库配置信息 ] 为
'; echo '提示 2:如果程序并未写入数据库 [ 安装完成后进入首页提示 Table XX doesn\'t exist ] 请选择强制手动导入 SQL

'; @@ -145,6 +149,7 @@ echo '
数据库密码

'; echo '
数据库名称

'; echo '
数据表前缀

'; + echo '
数据库开启SSL

'; echo ''; } echo '

站点创始人信息


'; @@ -171,6 +176,8 @@ define('DB_PASSWD', $_POST['dbpw']); define('DB_NAME', $_POST['dbname']); define('DB_PREFIX', $_POST['dbprefix']); + $dbSsl = $_POST['dbSsl']; + define('DB_SSL', $dbSsl == "1" ? true : false); } $sql = str_ireplace('{VAR-PREFIX}', DB_PREFIX, file_get_contents(SYSTEM_ROOT2 . '/install.template.sql')); $sql = str_ireplace('{VAR-DB}', DB_NAME, $sql); @@ -222,6 +229,8 @@ define(\'DB_PASSWD\',\'' . DB_PASSWD . '\'); //MySQL 数据库名称 define(\'DB_NAME\',\'' . DB_NAME . '\'); +//MySQL 启用SSL连接,如需启用请将值改为true +define(\'DB_SSL\',' . DB_SSL .'); ////////////////////////////以下选项使用任何数据库都需填写//////////////////////////// //数据库前缀,建议保持默认 From 991f0df6de1fa477dc5d18fe627e4fb4d506bd89 Mon Sep 17 00:00:00 2001 From: Boris Zhao Date: Mon, 16 Dec 2024 17:47:06 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E7=A7=BB=E9=99=A4`config.php`=E4=B8=AD?= =?UTF-8?q?=E5=A4=9A=E4=BD=99=E7=9A=84=E7=A9=BA=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.php b/config.php index dbf0b6fe..3c3fd5f0 100644 --- a/config.php +++ b/config.php @@ -1,4 +1,4 @@ - Date: Tue, 17 Dec 2024 22:28:33 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E5=9C=A8=E5=90=AF=E7=94=A8SSL=E6=97=B6?= =?UTF-8?q?=E7=9B=B4=E6=8E=A5=E6=8C=87=E5=AE=9Aflag=20`MYSQLI=5FCLIENT=5FS?= =?UTF-8?q?SL`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/class.mysqli.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/class.mysqli.php b/lib/class.mysqli.php index da0e4f88..2160b488 100644 --- a/lib/class.mysqli.php +++ b/lib/class.mysqli.php @@ -48,9 +48,10 @@ public function __construct($host, $user, $pw, $name, $long = false, $useSsl = f } $coninfo = strpos($host, ':'); + $flags = 0; $mysqli = mysqli_init(); if ($useSsl) { - $mysqli->ssl_set(null, null, "/etc/ssl/certs/ca-certificates.crt", "/etc/ssl/certs", null); + $flags = $flags | MYSQLI_CLIENT_SSL; } $connected = false; @@ -58,12 +59,12 @@ public function __construct($host, $user, $pw, $name, $long = false, $useSsl = f if ($long) { $host = 'p:' . $host; } - $connected = $mysqli->real_connect($host, $user, $pw, $name); + $connected = $mysqli->real_connect($host, $user, $pw, $name, flags: $flags); } else { if ($long) { - $connected = $mysqli->real_connect('p:' . substr($host, 0, $coninfo), $user, $pw, $name, substr($host, $coninfo + 1)); + $connected = $mysqli->real_connect('p:' . substr($host, 0, $coninfo), $user, $pw, $name, substr($host, $coninfo + 1), flags: $flags); } else { - $connected = $mysqli->real_connect(substr($host, 0, $coninfo), $user, $pw, $name, substr($host, $coninfo + 1)); + $connected = $mysqli->real_connect(substr($host, 0, $coninfo), $user, $pw, $name, substr($host, $coninfo + 1), flags: $flags); } } From f556bc898cc92fb833c6cb1e6f8d8515ddef6b10 Mon Sep 17 00:00:00 2001 From: Boris Zhao Date: Tue, 17 Dec 2024 23:11:09 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E4=BF=AE=E6=AD=A3`config.php`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 更正`DB_SSL`开启方式的描述 - 设定`DB_SSL`默认值为0 --- config.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config.php b/config.php index 3c3fd5f0..0cae1509 100644 --- a/config.php +++ b/config.php @@ -11,8 +11,8 @@ define('DB_PASSWD', ''); //MySQL 数据库名称 define('DB_NAME', 'tiebacloud'); -//MySQL 启用SSL连接,如需启用请将值改为true -define('DB_SSL',1); +//MySQL 启用SSL连接,如需启用请将值改为1 +define('DB_SSL',0); ////////////////////////////以下选项使用任何数据库都需填写//////////////////////////// //数据库前缀,建议保持默认 From 40e0aac96c3cf94a30b5f81c6aa9cf361af4082b Mon Sep 17 00:00:00 2001 From: Boris Zhao Date: Wed, 18 Dec 2024 21:01:40 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=E7=BB=9F=E4=B8=80=E4=BD=BF=E7=94=A81?= =?UTF-8?q?=E5=92=8C0=E4=BB=A3=E8=A1=A8true/false?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- setup/install.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/setup/install.php b/setup/install.php index de4cfddc..3f43a2c2 100644 --- a/setup/install.php +++ b/setup/install.php @@ -176,8 +176,7 @@ define('DB_PASSWD', $_POST['dbpw']); define('DB_NAME', $_POST['dbname']); define('DB_PREFIX', $_POST['dbprefix']); - $dbSsl = $_POST['dbSsl']; - define('DB_SSL', $dbSsl == "1" ? true : false); + define('DB_SSL', $_POST['dbSsl']); } $sql = str_ireplace('{VAR-PREFIX}', DB_PREFIX, file_get_contents(SYSTEM_ROOT2 . '/install.template.sql')); $sql = str_ireplace('{VAR-DB}', DB_NAME, $sql); @@ -229,7 +228,7 @@ define(\'DB_PASSWD\',\'' . DB_PASSWD . '\'); //MySQL 数据库名称 define(\'DB_NAME\',\'' . DB_NAME . '\'); -//MySQL 启用SSL连接,如需启用请将值改为true +//MySQL 启用SSL连接,如需启用请将值改为1 define(\'DB_SSL\',' . DB_SSL .'); ////////////////////////////以下选项使用任何数据库都需填写//////////////////////////// From 2f2308bea34c78d5ebfe6dd9af6306da6cd3886d Mon Sep 17 00:00:00 2001 From: n0099 Date: Fri, 20 Dec 2024 17:09:53 +0000 Subject: [PATCH 7/7] =?UTF-8?q?=E7=BB=9F=E4=B8=80=E5=91=BD=E5=90=8D?= =?UTF-8?q?=E5=A4=A7=E5=B0=8F=E5=86=99=EF=BC=9A`useSSL`=20`dbssl`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.php | 2 +- lib/class.S.php | 4 ++-- lib/class.mysql.php | 2 +- lib/class.mysqli.php | 2 +- setup/install.php | 8 ++++---- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/config.php b/config.php index 0cae1509..9dd695c5 100644 --- a/config.php +++ b/config.php @@ -12,7 +12,7 @@ //MySQL 数据库名称 define('DB_NAME', 'tiebacloud'); //MySQL 启用SSL连接,如需启用请将值改为1 -define('DB_SSL',0); +define('DB_SSL', 0); ////////////////////////////以下选项使用任何数据库都需填写//////////////////////////// //数据库前缀,建议保持默认 diff --git a/lib/class.S.php b/lib/class.S.php index 01428875..2eae9564 100644 --- a/lib/class.S.php +++ b/lib/class.S.php @@ -15,10 +15,10 @@ class S extends wmysql * @param string $name 数据库名 * @param bool $long 是否开启长连接 */ - public function __construct($host, $user, $pw, $name, $long = false, $useSsl = false) + public function __construct($host, $user, $pw, $name, $long = false, $useSSL = false) { try { - parent::__construct($host, $user, $pw, $name, $long, $useSsl); + parent::__construct($host, $user, $pw, $name, $long, $useSSL); } catch (Exception $ex) { msg($ex->getMessage()); } diff --git a/lib/class.mysql.php b/lib/class.mysql.php index c62dd101..1e601a21 100644 --- a/lib/class.mysql.php +++ b/lib/class.mysql.php @@ -41,7 +41,7 @@ class wmysql * @param string $name 数据库名 * @param bool $long 是否开启长连接 */ - public function __construct($host, $user, $pw, $name, $long = false, $useSsl = false) + public function __construct($host, $user, $pw, $name, $long = false, $useSSL = false) { if (!function_exists('mysql_connect')) { throw new Exception('服务器PHP不支持MySql数据库'); diff --git a/lib/class.mysqli.php b/lib/class.mysqli.php index 2160b488..2f4ee3cb 100644 --- a/lib/class.mysqli.php +++ b/lib/class.mysqli.php @@ -41,7 +41,7 @@ class wmysql * @param string $name 数据库名 * @param bool $long 是否开启长连接 */ - public function __construct($host, $user, $pw, $name, $long = false, $useSsl = false) + public function __construct($host, $user, $pw, $name, $long = false, $useSSL = false) { if (!class_exists('mysqli')) { throw new Exception('服务器不支持MySqli类'); diff --git a/setup/install.php b/setup/install.php index 3f43a2c2..8652bdaa 100644 --- a/setup/install.php +++ b/setup/install.php @@ -135,10 +135,10 @@ echo '
数据库密码

'; echo '
数据库名称

'; echo '
数据表前缀

'; - echo '
数据库开启SSL

'; + echo '
数据库开启SSL

'; echo ''; echo ''; - echo ''; + echo ''; } else { echo '
提示 1:如果您已经手动写好了 config.php ,请选择 [ 自动获得数据库配置信息 ] 为
'; echo '提示 2:如果程序并未写入数据库 [ 安装完成后进入首页提示 Table XX doesn\'t exist ] 请选择强制手动导入 SQL

'; @@ -149,7 +149,7 @@ echo '
数据库密码

'; echo '
数据库名称

'; echo '
数据表前缀

'; - echo '
数据库开启SSL

'; + echo '
数据库开启SSL

'; echo ''; } echo '

站点创始人信息


'; @@ -176,7 +176,7 @@ define('DB_PASSWD', $_POST['dbpw']); define('DB_NAME', $_POST['dbname']); define('DB_PREFIX', $_POST['dbprefix']); - define('DB_SSL', $_POST['dbSsl']); + define('DB_SSL', $_POST['dbssl']); } $sql = str_ireplace('{VAR-PREFIX}', DB_PREFIX, file_get_contents(SYSTEM_ROOT2 . '/install.template.sql')); $sql = str_ireplace('{VAR-DB}', DB_NAME, $sql);