Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
webman-blog
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
魏洲
webman-blog
Commits
425b3aee
Commit
425b3aee
authored
May 16, 2022
by
wolfcode
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
15dcf008
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
113 additions
and
39 deletions
+113
-39
.gitignore
.gitignore
+1
-0
Handler.php
app/common/exception/Handler.php
+24
-0
functions.php
app/functions.php
+21
-0
InstallCheck.php
app/middleware/InstallCheck.php
+65
-38
exception.php
config/exception.php
+1
-1
sqldata.sql
extend/sqldata.sql
+1
-0
No files found.
.gitignore
View file @
425b3aee
...
...
@@ -3,3 +3,4 @@
/tests/.phpunit.result.cache
/public/upload
/vendor/workerman/workerman.log
/extend/install.lock
app/common/exception/Handler.php
0 → 100644
View file @
425b3aee
<?php
namespace
app\common\exception
;
use
Webman\Http\Request
;
use
Webman\Http\Response
;
use
Throwable
;
use
Webman\Exception\ExceptionHandler
;
class
Handler
extends
ExceptionHandler
{
public
$dontReport
=
[];
public
function
report
(
Throwable
$exception
)
{
parent
::
report
(
$exception
);
}
public
function
render
(
Request
$request
,
Throwable
$exception
)
:
Response
{
return
parent
::
render
(
$request
,
$exception
);
}
}
\ No newline at end of file
app/functions.php
View file @
425b3aee
...
...
@@ -7,6 +7,27 @@ function adminPasswordAuth(string $password, string $salt): string
return
password_hash
(
$password
.
$salt
,
PASSWORD_BCRYPT
);
}
function
sql_split
(
$sql
)
:
array
{
$sql
=
preg_replace
(
"/TYPE=(InnoDB|MyISAM|MEMORY)( DEFAULT CHARSET=[^; ]+)?/"
,
"ENGINE=
\\
1 DEFAULT CHARSET=utf8mb4"
,
$sql
);
$sql
=
str_replace
(
"
\r
"
,
"
\n
"
,
$sql
);
$ret
=
array
();
$num
=
0
;
$quirkiest
=
explode
(
";
\n
"
,
trim
(
$sql
));
unset
(
$sql
);
foreach
(
$quirkiest
as
$query
)
{
$ret
[
$num
]
=
''
;
$queries
=
explode
(
"
\n
"
,
trim
(
$query
));
$queries
=
array_filter
(
$queries
);
foreach
(
$queries
as
$query
)
{
$str1
=
substr
(
$query
,
0
,
1
);
if
(
$str1
!=
'#'
&&
$str1
!=
'-'
)
$ret
[
$num
]
.=
$query
;
}
$num
++
;
}
return
$ret
;
}
if
(
!
function_exists
(
'sysConfig'
))
{
function
sysConfig
(
$type
,
$name
=
null
,
$default
=
''
)
...
...
app/middleware/InstallCheck.php
View file @
425b3aee
...
...
@@ -15,44 +15,71 @@ class InstallCheck implements MiddlewareInterface
{
public
function
process
(
Request
$request
,
callable
$handler
)
:
Response
{
$base_path
=
base_path
()
.
DIRECTORY_SEPARATOR
.
'extend'
.
DIRECTORY_SEPARATOR
;
$lock_file
=
$base_path
.
'install.lock'
;
$sql_data
=
$base_path
.
'm_blog.sql'
;
if
(
!
file_exists
(
$lock_file
))
{
$dbHost
=
env
(
'db_host'
);
$dbUser
=
env
(
'db_username'
);
$dbPwd
=
env
(
'db_password'
);
$dbPort
=
env
(
'db_port'
);
$dbCharset
=
env
(
'db_charset'
);
$dbName
=
env
(
'db_database'
);
try
{
$conn
=
mysqli_connect
(
$dbHost
,
$dbUser
,
$dbPwd
,
null
,
$dbPort
);
mysqli_query
(
$conn
,
"SET NAMES
{
$dbCharset
}
"
);
if
(
!
mysqli_select_db
(
$conn
,
$dbName
))
{
if
(
!
mysqli_query
(
$conn
,
"CREATE DATABASE IF NOT EXISTS `
{
$dbName
}
` DEFAULT CHARACTER SET
{
$dbCharset
}
;"
))
{
$errorMsg
=
"数据库
{
$dbName
}
不存在,也没权限创建新的数据库!"
;
mysqli_close
(
$conn
);
return
response
(
$errorMsg
,
400
);
}
}
if
(
file_exists
(
$sql_data
))
{
$sql
=
file_get_contents
(
$sql_data
);
if
(
!
mysqli_select_db
(
$conn
,
$dbName
))
{
$errorMsg
=
"数据表
{
$dbName
}
不存在!"
;
return
response
(
$errorMsg
,
400
);
}
$exp
=
array_filter
(
explode
(
'INSERT INTO'
,
(
$sql
)));
foreach
(
$exp
as
$key
=>
$value
)
{
$query_sql
=
'INSERT INTO '
.
htmlspecialchars_decode
(
$value
);
$result
=
mysqli_query
(
$conn
,
$query_sql
);
}
mysqli_close
(
$conn
);
}
}
catch
(
\Exception
$e
)
{
$errorMsg
=
"连接 MySQL 失败: "
.
mysqli_connect_error
()
.
$e
->
getMessage
();
return
response
(
$errorMsg
,
400
);
}
}
return
$handler
(
$request
);
// $base_path = base_path() . DIRECTORY_SEPARATOR . 'extend' . DIRECTORY_SEPARATOR;
// $lock_file = $base_path . 'install.lock';
// if (file_exists($lock_file)) {
// return $handler($request);
// }
// if (version_compare(PHP_VERSION, '7.1.0', '<')) {
// $errorMsg = "PHP版本需要7.4或者以上,推荐8.1+";
// return response($errorMsg, 400);
// }
// $db_base_data = $base_path . 'database.sql';
// $sql_data = $base_path . 'my_blog.sql';
// if (file_exists($db_base_data) === false) {
// $errorMsg = "数据库基础获取异常,请确认{$db_base_data}文件是否存在";
// return response($errorMsg, 400);
// }
// if (file_exists($sql_data) === false) {
// $errorMsg = "数据库基础获取异常,请确认{$sql_data}文件是否存在";
// return response($errorMsg, 400);
// }
// $dbHost = env('db_host');
// $dbUser = env('db_username');
// $dbPwd = env('db_password');
// $dbPort = env('db_port');
// $dbCharset = env('db_charset');
// $dbName = env('db_database');
// try {
// $conn = mysqli_connect($dbHost, $dbUser, $dbPwd, null, $dbPort);
// mysqli_query($conn, "SET NAMES {$dbCharset}");
// $initDb = mysqli_select_db($conn, $dbName);
// if (!$initDb) {
// if (!mysqli_query($conn, "CREATE DATABASE IF NOT EXISTS `{$dbName}` DEFAULT CHARACTER SET {$dbCharset};")) {
// $errorMsg = "数据库{$dbName} 不存在,也没权限创建新的数据库!";
// mysqli_close($conn);
// return response($errorMsg, 400);
// }
// }
// // 先建表
// $db_data = file_get_contents($db_base_data);
// $sqlFormat = sql_split($db_data);
// $counts = count($sqlFormat);
// mysqli_select_db($conn, $dbName);
// for ($index = 0; $index < $counts; $index++) {
// $sql = trim($sqlFormat[$index]);
// if (strstr($sql, 'CREATE TABLE')) {
// mysqli_query($conn, $sql);
// }
// $index++;
// }
// @touch($base_path . 'install.lock');
// // $sql = file_get_contents($sql_data);
// // if (!mysqli_select_db($conn, $dbName)) {
// // $errorMsg = "数据表{$dbName}不存在!";
// // return response($errorMsg, 400);
// // }
// // $exp = array_filter(explode('INSERT INTO', ($sql)));
// // foreach ($exp as $value) {
// // $query_sql = 'INSERT INTO ' . htmlspecialchars_decode($value);
// // mysqli_query($conn, $query_sql);
// // }
// return $handler($request);
// } catch (\Exception $e) {
// $errorMsg = "连接 MySQL 失败: " . mysqli_connect_error() . $e->getMessage();
// return response($errorMsg, 400);
// }
}
}
\ No newline at end of file
config/exception.php
View file @
425b3aee
...
...
@@ -13,5 +13,5 @@
*/
return
[
''
=>
support\exception\Handler
::
class
,
''
=>
app\common\exception\Handler
::
class
];
\ No newline at end of file
extend/sqldata.sql
View file @
425b3aee
INSERT
INTO
`article`
VALUES
(
2
,
'白马王子'
,
'啊发生的发生的分
\n
阿萨德发撒旦发射点发射点发射得分
\n
阿萨德发生地方'
,
1
,
'/upload/20220506
\\
1651852534FglIUK.jpg'
,
'啊发生的发生的分
\n
<div>阿萨德发撒旦发射点发射点发射得分</div>
\n
<div>阿萨德发生地方</div>'
,
'2022-05-08'
,
0
,
1
,
0
,
'2022-05-08 15:55:46'
,
NULL
);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment