Compare commits

...
170 Commits
Author SHA1 Message Date
Mr Chen 909d818caa Merge pull request #936 from ramondelee/patch-2
Update freetype_new.sh
2026-09-09 01:44:12 +08:00
ramondelee 355ceebbd7 Update freetype_new.sh
修复freetype下载失败问题
2026-09-08 21:12:36 +08:00
Mr Chen 93b5d8b8b4 Merge pull request #935 from ramondelee/patch-1
Update freetype_old.sh
2026-09-08 12:02:10 +08:00
ramondelee be461a15a9 Update freetype_old.sh
修复freetype下载失败问题
2026-09-07 22:23:11 +08:00
Mr Chen 19fc0fdc51 Merge pull request #934 from midoks/dev
常规更新
2026-08-26 18:16:57 +08:00
dami c1fd4fa24c Update __init__.py 2026-08-26 18:15:43 +08:00
dami 7239b22759 update 2026-08-16 00:14:39 +08:00
dami f5fa94ae95 Update update.sh 2026-08-08 10:09:28 +08:00
Mr Chen b679ea035d Merge pull request #933 from midoks/dev
常规优化
2026-07-22 13:05:42 +08:00
dami 49bbca8faa Update index.py 2026-07-22 13:03:46 +08:00
dami 8b86cd5e63 up 2026-07-22 13:00:43 +08:00
dami 698e3ffd81 update 2026-07-22 12:55:33 +08:00
Mr Chen c2284dcee5 Merge pull request #932 from midoks/dev
兼容Ubuntu 26.04 LTS
2026-07-21 20:43:06 +08:00
dami b68c9edc3e Update index.py 2026-07-21 20:37:12 +08:00
dami 650365997a Update index.py 2026-07-21 20:36:34 +08:00
dami 3279404595 Update info.json 2026-07-21 20:35:41 +08:00
dami d32a94dccf Update install.sh 2026-07-21 20:34:44 +08:00
dami 80d846f247 Update install.sh 2026-07-21 20:31:08 +08:00
dami eadcbe336d Update install.sh 2026-07-21 20:26:57 +08:00
dami 474d0f075f Update install.sh 2026-07-21 20:26:33 +08:00
dami 2d6a41e19f Update install.sh 2026-07-21 12:03:36 +08:00
dami 1f24944417 Update caddy.service.tpl 2026-07-21 11:51:42 +08:00
dami 4ab3409e54 Update index.py 2026-07-21 11:43:14 +08:00
dami c3ad146303 update 2026-07-21 11:38:30 +08:00
dami 745cd304fb Update install.sh 2026-07-21 00:33:05 +08:00
dami e6efefd1fd Update install.sh 2026-07-21 00:11:57 +08:00
dami 1350404c58 Update install.sh 2026-07-21 00:10:03 +08:00
dami 9cdd2274fa Update install.sh 2026-07-21 00:08:53 +08:00
dami cc204ad721 Update install.sh 2026-07-21 00:00:26 +08:00
dami 8eb1614b31 Update install.sh 2026-07-20 23:50:41 +08:00
dami 9c2e9627ec update 2026-07-20 23:48:18 +08:00
dami 87123c526a update 2026-07-20 23:45:15 +08:00
dami 7c3ebc6e35 Update ubuntu.sh 2026-07-20 23:42:08 +08:00
dami 6c5bf63424 Update ubuntu.sh 2026-07-20 23:38:00 +08:00
dami 13fd47e7d4 Update ubuntu.sh 2026-07-20 23:36:38 +08:00
dami fc1321584a Update ubuntu.sh 2026-07-20 23:36:25 +08:00
dami bab3ae16d3 Update ubuntu.sh 2026-07-20 23:33:35 +08:00
dami ab8498e519 Update ubuntu.sh 2026-07-20 23:33:13 +08:00
dami 0e480c7ad8 update 2026-07-20 23:29:01 +08:00
dami 7ed8558ff0 Update ubuntu.sh 2026-07-20 23:22:35 +08:00
dami 4ed2f0caa9 update 2026-07-20 23:19:31 +08:00
dami f275eabe1b Update file.py 2026-07-20 23:08:01 +08:00
dami fe13ab1e5f Update file.py 2026-07-20 23:07:46 +08:00
dami 6ed045cf94 update 2026-07-20 22:41:10 +08:00
dami ef333ff142 update 2026-07-20 22:23:37 +08:00
dami dac2f5240f Update install.sh 2026-07-20 22:18:45 +08:00
dami cebfc2fc91 update 2026-07-20 22:17:22 +08:00
dami 1da865c1b2 Update install.sh 2026-07-20 16:46:29 +08:00
dami 2abdaaa7ce Update install.sh 2026-07-20 16:45:08 +08:00
dami c62142cf6b Update requirements.txt 2026-07-20 16:04:57 +08:00
dami 7c1820b6cd update 2026-07-20 15:59:27 +08:00
dami a24af95d24 Update install.sh 2026-07-20 15:39:32 +08:00
dami 1326c282c8 Update requirements.txt 2026-07-20 15:33:13 +08:00
dami b7e84749f1 Update debian.sh 2026-07-20 15:26:10 +08:00
dami 8a65158540 Update db.py 2026-07-20 15:21:46 +08:00
dami a576c521a2 Update ubuntu.sh 2026-07-20 15:17:24 +08:00
dami 736a387a71 Update ubuntu.sh 2026-07-20 15:15:23 +08:00
dami 090205c372 update 2026-07-20 13:41:03 +08:00
dami fda0bddc8f Update db.py 2026-07-20 13:26:23 +08:00
dami 292b18468d Update db.py 2026-07-20 13:24:57 +08:00
dami 47aab245fc Update panel_task.py 2026-07-20 12:42:24 +08:00
dami 39bd601825 Update mw.py 2026-07-20 12:32:39 +08:00
dami b744adeb13 Update monitor.py 2026-07-20 11:46:30 +08:00
dami 7b70f9fc99 Merge branch 'master' into dev 2026-07-19 22:06:00 +08:00
Mr Chen 0723f751b3 Merge pull request #930 from midoks/dependabot/pip/python-engineio-4.13.2
Bump python-engineio from 4.3.2 to 4.13.2
2026-07-19 22:05:47 +08:00
dami 1fd8617a12 Update push_notice_msg.py 2026-07-17 23:21:19 +08:00
dependabot[bot] 2fec8fcef4 Bump python-engineio from 4.3.2 to 4.13.2
Bumps [python-engineio](https://github.com/miguelgrinberg/python-engineio) from 4.3.2 to 4.13.2.
- [Release notes](https://github.com/miguelgrinberg/python-engineio/releases)
- [Changelog](https://github.com/miguelgrinberg/python-engineio/blob/main/CHANGES.md)
- [Commits](https://github.com/miguelgrinberg/python-engineio/compare/v4.3.2...v4.13.2)

---
updated-dependencies:
- dependency-name: python-engineio
  dependency-version: 4.13.2
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-07-14 21:18:01 +00:00
Mr Chen 51a48afa71 Merge pull request #929 from ccbkkb/patch-1
Fix return statement for unban IP function
2026-07-13 13:12:38 +08:00
ccbkkb 76919faca7 Fix return statement for unban IP function 2026-07-13 10:50:19 +08:00
Mr Chen 9bcbeaf1a5 Merge pull request #928 from midoks/dev
常规更新
2026-07-09 17:11:23 +08:00
dami d0de121721 Update update.sh 2026-07-09 15:14:16 +08:00
dami 957e2db3d0 Update update.sh 2026-07-09 15:06:33 +08:00
dami fb0be5549d Update update.sh 2026-07-09 15:04:40 +08:00
dami 8a9132d557 Update update.sh 2026-07-09 14:52:08 +08:00
dami 04d10435c2 Update update.sh 2026-07-09 14:51:29 +08:00
dami 92543e10fa Update update.sh 2026-07-09 14:46:38 +08:00
dami cd427dcbf3 Update update.sh 2026-07-09 14:46:26 +08:00
Mr Chen ddb5e0285b Merge pull request #927 from midoks/dev
常规更新
2026-07-09 14:24:08 +08:00
dami 75610a4559 Update crontab.js 2026-07-09 14:22:26 +08:00
dami b8f7a45f61 Update push_notice_msg.py 2026-07-09 12:58:16 +08:00
Mr Chen 37d5ce719e Merge pull request #926 from midoks/dev
常规更新
2026-07-08 16:47:46 +08:00
dami ef9053aa7e Update webstats_index.py 2026-07-08 16:47:05 +08:00
dami 018fcb7afb Update index.py 2026-07-08 16:46:45 +08:00
dami 5cc9a67152 Update mw.py 2026-07-07 23:54:17 +08:00
dami 54895f1d0a Update mw.py 2026-07-07 23:38:29 +08:00
dami 91dfecf882 up 2026-07-07 23:36:34 +08:00
dami 2f09e227d1 Update tool_migrate.py 2026-07-07 23:12:23 +08:00
dami 5d0463836e Update mw.py 2026-07-07 23:11:02 +08:00
Mr Chen fb6499cb35 Merge pull request #925 from midoks/dev
常规更新
2026-07-07 02:35:02 +08:00
dami 0bbfb58e67 Update index.py 2026-07-07 02:32:34 +08:00
Mr Chen fcd780a7d3 Merge pull request #924 from midoks/dev
常规更新
2026-07-07 02:19:41 +08:00
dami 4f4d1e7580 Update webstats_common.lua 2026-07-07 02:15:57 +08:00
dami 6e2a8e0a12 up 2026-07-07 02:12:09 +08:00
dami 817b4b36c7 Update webstats.conf 2026-07-07 02:06:03 +08:00
Mr Chen 0ba89cbb9e Merge pull request #923 from midoks/dev
常规更新
2026-07-06 21:13:07 +08:00
dami 4e3e7864be Update tool_migrate.py 2026-07-06 21:02:13 +08:00
dami 6f51eaa298 update 2026-07-06 20:59:32 +08:00
dami 39bd87e868 Update tool_migrate.py 2026-07-06 20:54:00 +08:00
dami 18443aab60 Update tool_migrate.py 2026-07-06 20:49:20 +08:00
dami b88ea7aa3c update 2026-07-06 20:32:36 +08:00
dami 6a6f6e6062 Update tool_migrate.py 2026-07-06 20:27:17 +08:00
dami 5839dbcd6b Update tool_migrate.py 2026-07-06 20:05:10 +08:00
dami b46f45569e Update tool_migrate.py 2026-07-06 20:01:23 +08:00
dami 5cdc5af8cd Update tool_migrate.py 2026-07-06 19:50:13 +08:00
dami 4f38a9f3ff Update tool_migrate.py 2026-07-06 19:49:58 +08:00
dami 9c83695187 Create tool_migrate.py 2026-07-06 19:44:14 +08:00
dami f9be534101 update 2026-07-06 19:24:36 +08:00
dami 58ab48ac15 Update webstats_common.lua 2026-07-06 19:11:48 +08:00
dami f34e93192d Update webstats_common.lua 2026-07-06 19:10:17 +08:00
dami 31106f2b13 Update webstats_common.lua 2026-07-06 19:03:27 +08:00
dami 468cc54cf5 Update webstats_common.lua 2026-07-06 18:55:25 +08:00
dami 728a38c55c Update webstats_log.lua 2026-07-06 18:35:05 +08:00
Mr Chen b2b23b0e3b Merge pull request #922 from midoks/dev
常规更新
2026-07-05 15:51:08 +08:00
dami 167dd11548 Update webstats_log.lua 2026-07-05 15:47:23 +08:00
dami 03fdbf2604 Merge branch 'master' into dev 2026-07-05 15:43:18 +08:00
dami edbdec8370 Update init.sql 2026-07-05 15:42:44 +08:00
dami 8f1c9f9471 up 2026-07-05 15:38:54 +08:00
dami d35d16943d up 2026-07-05 15:34:56 +08:00
dami 3ac4270dee Update stats.js 2026-07-05 15:30:16 +08:00
dami 90777e08ff update 2026-07-05 15:28:56 +08:00
dami b47d1262ac Update push_notice_msg.py 2026-07-05 15:11:57 +08:00
dami e28081a7c5 Update stats.js 2026-07-05 15:04:05 +08:00
dami 5f7d6c1488 Create webstats_common.lua.bk1.txt 2026-07-05 14:46:32 +08:00
dami 59385e11be Merge branch 'master' into dev 2026-07-05 14:21:28 +08:00
Mr Chen a668d88791 Merge pull request #921 from midoks/dev
常规更新
2026-07-05 14:13:11 +08:00
dami e62bd7c5a6 Update webstats_log.lua 2026-07-05 14:07:31 +08:00
dami 1ad3d2f187 Update webstats_log.lua 2026-07-05 13:41:19 +08:00
dami bf06af14ed Update webstats_log.lua 2026-07-05 13:24:37 +08:00
Mr Chen 805c96f260 Merge pull request #920 from midoks/dev
常规更新
2026-07-05 12:33:28 +08:00
dami 8ccba2f6d5 Update webstats_log.lua 2026-07-05 04:08:00 +08:00
dami 2e9f01d3ee Update webstats_log.lua 2026-07-05 04:05:19 +08:00
dami d1dcdd4f25 Update webstats_common.lua 2026-07-05 03:58:34 +08:00
dami 60958d1403 Update webstats_common.lua 2026-07-05 03:56:13 +08:00
dami 5530b14f36 Update webstats_common.lua 2026-07-05 03:36:39 +08:00
dami 64c9942ee1 Update webstats_common.lua 2026-07-05 03:36:26 +08:00
dami bc1437dac4 Update webstats_init_worker.lua 2026-07-05 03:27:35 +08:00
dami 1d9576e838 Update webstats_log.lua 2026-07-05 03:27:11 +08:00
dami 8b275a5df4 Update webstats_log.lua 2026-07-05 03:18:14 +08:00
dami 40d9334dcf Update index.py 2026-07-05 02:45:28 +08:00
dami 98c0242819 Update index.py 2026-07-05 02:39:23 +08:00
dami a2fb03f9b8 Update index.py 2026-07-05 02:31:20 +08:00
dami 98815ac5c3 update 2026-07-05 02:29:29 +08:00
dami 073dd20c96 update 2026-07-05 01:16:02 +08:00
dami 23af9085a9 update 2026-07-05 00:51:14 +08:00
dami bcaec6b6ee Update install.sh 2026-07-04 23:42:10 +08:00
dami 4063bea922 Update webstats_common.lua 2026-07-04 23:02:54 +08:00
dami 9f864b3407 Update webstats_common.lua 2026-07-04 22:56:49 +08:00
dami 01ac598e39 Update webstats_common.lua 2026-07-04 22:43:20 +08:00
dami 77a0d3af36 Update webstats_common.lua 2026-07-04 22:35:03 +08:00
dami 8d34bbea47 Update webstats_common.lua 2026-07-04 22:33:43 +08:00
dami be18e98001 Update webstats_common.lua 2026-07-04 22:23:56 +08:00
dami 754e0f98f9 Update webstats_common.lua 2026-07-04 22:23:43 +08:00
dami 07f893b6a1 Update webstats_common.lua 2026-07-04 22:21:17 +08:00
Mr Chen c1497ec44e Merge pull request #919 from midoks/dev
常规更新
2026-07-03 12:05:30 +08:00
dami 55d4784fe2 Update webstats_common.lua 2026-07-02 14:30:04 +08:00
dami f26e8bc520 update 2026-07-02 14:22:10 +08:00
dami 7b5f1a4253 up 2026-07-02 14:12:32 +08:00
dami 1058fb7e1f Update webstats_log.lua 2026-07-02 14:01:50 +08:00
dami 0f1b95cdfc up 2026-07-02 13:54:31 +08:00
dami 8ea16fcd85 Update webstats_common.lua 2026-07-02 13:32:22 +08:00
dami b4b9496980 Update webstats_common.lua 2026-07-02 13:15:12 +08:00
dami 8dfd26361f Update webstats_common.lua 2026-07-02 13:06:32 +08:00
dami cb5bd32b86 Update webstats_common.lua 2026-07-02 13:02:31 +08:00
dami 2584330d40 update 2026-07-02 12:52:05 +08:00
dami ebe6333ac9 up 2026-07-02 12:50:35 +08:00
dami 534892280e up 2026-07-02 12:45:28 +08:00
dami df05cf69cf Update tool_migrate.py 2026-07-02 12:27:43 +08:00
dami 2f782cf6a2 Update db.py 2026-07-02 12:26:19 +08:00
dami 6f483c17e6 Create tool_migrate_bak.py 2026-07-02 11:42:13 +08:00
dami e64610a2dc Update mw.py 2026-06-30 20:18:46 +08:00
100 changed files with 5360 additions and 1561 deletions
+1
View File
@@ -80,6 +80,7 @@ def runPanelTask():
# 站点过期检查
siteEdateCheck()
# echo "True" > /www/server/mdserver-web/logs/panel_task.lock
lock_file = mw.getTriggerTaskLockFile()
try:
if os.path.exists(lock_file):
+1 -1
View File
@@ -14,7 +14,7 @@ sysName=`uname`
action=$1
type=$2
VERSION=2.4.66
VERSION=2.4.68
apacheDir=${serverPath}/source/apache
Install_App()
+1 -1
View File
@@ -109,7 +109,7 @@ def initDreplace():
caddy_file = getConf()
if not os.path.exists(caddy_file):
caddy_file_tpl = getConfTpl()
content = mw.readFile(systemServiceTpl)
content = mw.readFile(caddy_file_tpl)
content = content.replace('{$SERVER_PATH}', service_path)
mw.writeFile(caddy_file, content)
+3 -3
View File
@@ -20,9 +20,9 @@ After=network.target network-online.target
Requires=network-online.target
[Service]
Type=notify
User=caddy
Group=caddy
Type=simple
User=www
Group=www
ExecStart={$SERVER_PATH}/caddy/bin/caddy run --environ --config {$SERVER_PATH}/caddy/Caddyfile
ExecReload={$SERVER_PATH}/caddy/bin/caddy reload --config {$SERVER_PATH}/caddy/Caddyfile --force
TimeoutStopSec=5s
+1 -1
View File
@@ -3,7 +3,7 @@ PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin:/opt/hom
export PATH
# cd /Users/midoks/Desktop/mwdev/server/mdserver-web/plugins/caddy && bash install.sh install 1.21.4
# cd /www/server/mdserver-web/plugins/caddy && bash install.sh install 1.21.4
# cd /www/server/mdserver-web/plugins/caddy && bash install.sh install 2.11
# cd /www/server/mdserver-web/plugins/caddy && bash install.sh install 1.29.2
# cd /www/server/mdserver-web/plugins/caddy && bash install.sh upgrade 1.29.2
+1
View File
@@ -30,6 +30,7 @@ case $(uname -m) in
x86_64) ARCH_NAME="amd64" ;;
arm) ARCH_NAME="arm64" ;;
arm64) ARCH_NAME="arm64" ;;
aarch64) ARCH_NAME="arm64" ;;
esac
VERSION=2.11.2
+1 -1
View File
@@ -328,7 +328,7 @@ def setBlackIp():
mw.execShell('fail2ban-client -vvv set {jail} unbanip {ip}'.format(jail=d, ip=ip))
mw.writeFile(getBlackFile(), json.dumps([]))
return nw.returnJson(True, "禁止IP成功")
return mw.returnJson(True, "禁止IP成功")
# 检查IP格式
for ip in add_ip_list:
+6
View File
@@ -6,6 +6,7 @@ export PATH
# cd /Users/midoks/Desktop/mwdev/server/mdserver-web/plugins/mongodb && /bin/bash install.sh install 7.0
# cd /www/server/mdserver-web/plugins/mongodb && /bin/bash install.sh install 7.0
# cd /www/server/mdserver-web/plugins/mongodb && /bin/bash install.sh install 8.0
# cd /www/server/mdserver-web/plugins/mongodb && /bin/bash install.sh install 3.0
# cd /www/server/mdserver-web && python3 /www/server/mdserver-web/plugins/mongodb/index.py start
@@ -75,6 +76,11 @@ Install_app()
if [ -f $shell_file ];then
bash -x $shell_file
if [ "$?" != "0" ];then
echo '不支持...'
exit 1
fi
else
echo '不支持...'
exit 1
+6 -1
View File
@@ -11,6 +11,11 @@ serverPath=$(dirname "$rootPath")
VERSION=3.0.15
SYS_ARCH=`arch`
if [ "$SYS_ARCH" != "x86_64" ];then
echo "no support"
exit 0
fi
SYS_VERSION_ID=`cat /etc/*-release | grep VERSION_ID | awk -F = '{print $2}' | awk -F "\"" '{print $2}'`
SYS_NAME=${SYS_VERSION_ID/./}
SYS_NAME_LEN=`echo "$SYS_NAME" | wc -L`
@@ -60,7 +65,7 @@ if [ ! -d $MG_DIR/${FILE_NAME} ];then
cd $MG_DIR && tar -zxvf ${FILE_NAME_TGZ}
fi
if [ ! -d $serverPath/mongodb/bin ];then
if [ ! -f $serverPath/mongodb/bin/mongod ];then
mkdir -p $serverPath/mongodb
cd $MG_DIR/${FILE_NAME} && cp -rf ./bin $serverPath/mongodb
fi
+7 -1
View File
@@ -11,6 +11,12 @@ serverPath=$(dirname "$rootPath")
# https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.0.15.tgz
VERSION=3.0.15
SYS_ARCH=`arch`
if [ "$SYS_ARCH" != "x86_64" ];then
echo "no support"
exit 0
fi
SYS_VERSION_ID=`cat /etc/*-release | grep VERSION_ID | awk -F = '{print $2}' | awk -F "\"" '{print $2}'`
SYS_NAME=${SYS_VERSION_ID/./}
@@ -39,7 +45,7 @@ if [ ! -d $MG_DIR/${FILE_NAME_TGZ} ];then
cd $MG_DIR && tar -zxvf ${FILE_NAME_TGZ}
fi
if [ ! -d $serverPath/mongodb/bin ];then
if [ ! -f $serverPath/mongodb/bin/mongod ];then
mkdir -p $serverPath/mongodb
cd $MG_DIR/${FILE_NAME} && cp -rf ./bin $serverPath/mongodb
fi
+1 -1
View File
@@ -23,7 +23,7 @@ if [ ! -d $MG_DIR/mongodb-macos-x86_64-${VERSION} ];then
cd $MG_DIR && tar -zxvf mongodb-macos-x86_64-${VERSION}.tgz
fi
if [ ! -d $serverPath/mongodb/bin ];then
if [ ! -f $serverPath/mongodb/bin/mongod ];then
mkdir -p $serverPath/mongodb
cd $MG_DIR/mongodb-macos-x86_64-${VERSION} && cp -rf ./bin $serverPath/mongodb
fi
+6 -1
View File
@@ -11,6 +11,11 @@ serverPath=$(dirname "$rootPath")
VERSION=3.0.15
SYS_ARCH=`arch`
if [ "$SYS_ARCH" != "x86_64" ];then
echo "no support"
exit 0
fi
SYS_VERSION_ID=`cat /etc/*-release | grep VERSION_ID | awk -F = '{print $2}' | awk -F "\"" '{print $2}' | awk -F . '{print $1}'`
SYS_NAME="15"
@@ -40,7 +45,7 @@ if [ ! -d $MG_DIR/${FILE_NAME} ];then
cd $MG_DIR && tar -zxvf ${FILE_NAME_TGZ}
fi
if [ ! -d $serverPath/mongodb/bin ];then
if [ ! -f $serverPath/mongodb/bin/mongod ];then
mkdir -p $serverPath/mongodb
cd $MG_DIR/${FILE_NAME} && cp -rf ./bin $serverPath/mongodb
fi
+1 -1
View File
@@ -36,7 +36,7 @@ if [ ! -d $MG_DIR/${FILE_NAME} ];then
cd $MG_DIR && tar -zxvf ${FILE_NAME_TGZ}
fi
if [ ! -d $serverPath/mongodb/bin ];then
if [ ! -f $serverPath/mongodb/bin/mongod ];then
mkdir -p $serverPath/mongodb
cd $MG_DIR/${FILE_NAME} && cp -rf ./bin $serverPath/mongodb
fi
+6 -1
View File
@@ -11,6 +11,11 @@ serverPath=$(dirname "$rootPath")
VERSION=3.0.15
SYS_ARCH=`arch`
if [ "$SYS_ARCH" != "x86_64" ];then
echo "no support"
exit 1
fi
SYS_VERSION_ID=`cat /etc/*-release | grep VERSION_ID | awk -F = '{print $2}' | awk -F "\"" '{print $2}'`
SYS_NAME=${SYS_VERSION_ID/./}
# https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu2004-4.4.23.tgz
@@ -38,7 +43,7 @@ if [ ! -d $MG_DIR/${FILE_NAME} ];then
cd $MG_DIR && tar -zxvf ${FILE_NAME_TGZ}
fi
if [ ! -d $serverPath/mongodb/bin ];then
if [ ! -f $serverPath/mongodb/bin/mongod ];then
mkdir -p $serverPath/mongodb
cd $MG_DIR/${FILE_NAME} && cp -rf ./bin $serverPath/mongodb
fi
+1 -1
View File
@@ -60,7 +60,7 @@ if [ ! -d $MG_DIR/${FILE_NAME} ];then
cd $MG_DIR && tar -zxvf ${FILE_NAME_TGZ}
fi
if [ ! -d $serverPath/mongodb/bin ];then
if [ ! -f $serverPath/mongodb/bin/mongod ];then
mkdir -p $serverPath/mongodb
cd $MG_DIR/${FILE_NAME} && cp -rf ./bin $serverPath/mongodb
fi
+1 -1
View File
@@ -37,7 +37,7 @@ if [ ! -d $MG_DIR/${FILE_NAME_TGZ} ];then
cd $MG_DIR && tar -zxvf ${FILE_NAME_TGZ}
fi
if [ ! -d $serverPath/mongodb/bin ];then
if [ ! -f $serverPath/mongodb/bin/mongod ];then
mkdir -p $serverPath/mongodb
cd $MG_DIR/${FILE_NAME} && cp -rf ./bin $serverPath/mongodb
fi
+1 -1
View File
@@ -22,7 +22,7 @@ if [ ! -d $MG_DIR/mongodb-macos-x86_64-${VERSION} ];then
cd $MG_DIR && tar -zxvf mongodb-macos-x86_64-${VERSION}.tgz
fi
if [ ! -d $serverPath/mongodb/bin ];then
if [ ! -f $serverPath/mongodb/bin/mongod ];then
mkdir -p $serverPath/mongodb
cd $MG_DIR/mongodb-macos-x86_64-${VERSION} && cp -rf ./bin $serverPath/mongodb
fi
+1 -1
View File
@@ -40,7 +40,7 @@ if [ ! -d $MG_DIR/${FILE_NAME} ];then
cd $MG_DIR && tar -zxvf ${FILE_NAME_TGZ}
fi
if [ ! -d $serverPath/mongodb/bin ];then
if [ ! -f $serverPath/mongodb/bin/mongod ];then
mkdir -p $serverPath/mongodb
cd $MG_DIR/${FILE_NAME} && cp -rf ./bin $serverPath/mongodb
fi
+1 -1
View File
@@ -36,7 +36,7 @@ if [ ! -d $MG_DIR/${FILE_NAME} ];then
cd $MG_DIR && tar -zxvf ${FILE_NAME_TGZ}
fi
if [ ! -d $serverPath/mongodb/bin ];then
if [ ! -f $serverPath/mongodb/bin/mongod ];then
mkdir -p $serverPath/mongodb
cd $MG_DIR/${FILE_NAME} && cp -rf ./bin $serverPath/mongodb
fi
+1 -1
View File
@@ -38,7 +38,7 @@ if [ ! -d $MG_DIR/${FILE_NAME} ];then
cd $MG_DIR && tar -zxvf ${FILE_NAME_TGZ}
fi
if [ ! -d $serverPath/mongodb/bin ];then
if [ ! -f $serverPath/mongodb/bin/mongod ];then
mkdir -p $serverPath/mongodb
cd $MG_DIR/${FILE_NAME} && cp -rf ./bin $serverPath/mongodb
fi
+1 -1
View File
@@ -47,7 +47,7 @@ if [ ! -d $MG_DIR/${FILE_NAME} ];then
cd $MG_DIR && tar -zxvf ${FILE_NAME_TGZ}
fi
if [ ! -d $serverPath/mongodb/bin ];then
if [ ! -f $serverPath/mongodb/bin/mongod ];then
mkdir -p $serverPath/mongodb
cd $MG_DIR/${FILE_NAME} && cp -rf ./bin $serverPath/mongodb
fi
+1 -1
View File
@@ -37,7 +37,7 @@ if [ ! -d $MG_DIR/${FILE_NAME_TGZ} ];then
cd $MG_DIR && tar -zxvf ${FILE_NAME_TGZ}
fi
if [ ! -d $serverPath/mongodb/bin ];then
if [ ! -f $serverPath/mongodb/bin/mongod ];then
mkdir -p $serverPath/mongodb
cd $MG_DIR/${FILE_NAME} && cp -rf ./bin $serverPath/mongodb
fi
+1 -1
View File
@@ -22,7 +22,7 @@ if [ ! -d $MG_DIR/mongodb-macos-x86_64-${VERSION} ];then
cd $MG_DIR && tar -zxvf mongodb-macos-x86_64-${VERSION}.tgz
fi
if [ ! -d $serverPath/mongodb/bin ];then
if [ ! -f $serverPath/mongodb/bin/mongod ];then
mkdir -p $serverPath/mongodb
cd $MG_DIR/mongodb-macos-x86_64-${VERSION} && cp -rf ./bin $serverPath/mongodb
fi
+1 -1
View File
@@ -40,7 +40,7 @@ if [ ! -d $MG_DIR/${FILE_NAME} ];then
cd $MG_DIR && tar -zxvf ${FILE_NAME_TGZ}
fi
if [ ! -d $serverPath/mongodb/bin ];then
if [ ! -f $serverPath/mongodb/bin/mongod ];then
mkdir -p $serverPath/mongodb
cd $MG_DIR/${FILE_NAME} && cp -rf ./bin $serverPath/mongodb
fi
+1 -1
View File
@@ -38,7 +38,7 @@ if [ ! -d $MG_DIR/${FILE_NAME} ];then
cd $MG_DIR && tar -zxvf ${FILE_NAME_TGZ}
fi
if [ ! -d $serverPath/mongodb/bin ];then
if [ ! -f $serverPath/mongodb/bin/mongod ];then
mkdir -p $serverPath/mongodb
cd $MG_DIR/${FILE_NAME} && cp -rf ./bin $serverPath/mongodb
fi
+1 -1
View File
@@ -53,7 +53,7 @@ if [ ! -d $MG_DIR/${FILE_NAME} ];then
cd $MG_DIR && tar -zxvf ${FILE_NAME_TGZ}
fi
if [ ! -d $serverPath/mongodb/bin ];then
if [ ! -f $serverPath/mongodb/bin/mongod ];then
mkdir -p $serverPath/mongodb
cd $MG_DIR/${FILE_NAME} && cp -rf ./bin $serverPath/mongodb
fi
+1 -1
View File
@@ -37,7 +37,7 @@ if [ ! -d $MG_DIR/${FILE_NAME_TGZ} ];then
cd $MG_DIR && tar -zxvf ${FILE_NAME_TGZ}
fi
if [ ! -d $serverPath/mongodb/bin ];then
if [ ! -f $serverPath/mongodb/bin/mongod ];then
mkdir -p $serverPath/mongodb
cd $MG_DIR/${FILE_NAME} && cp -rf ./bin $serverPath/mongodb
fi
+1 -1
View File
@@ -22,7 +22,7 @@ if [ ! -d $MG_DIR/mongodb-macos-x86_64-${VERSION} ];then
cd $MG_DIR && tar -zxvf mongodb-macos-x86_64-${VERSION}.tgz
fi
if [ ! -d $serverPath/mongodb/bin ];then
if [ ! -f $serverPath/mongodb/bin/mongod ];then
mkdir -p $serverPath/mongodb
cd $MG_DIR/mongodb-macos-x86_64-${VERSION} && cp -rf ./bin $serverPath/mongodb
fi
+1 -1
View File
@@ -40,7 +40,7 @@ if [ ! -d $MG_DIR/${FILE_NAME} ];then
cd $MG_DIR && tar -zxvf ${FILE_NAME_TGZ}
fi
if [ ! -d $serverPath/mongodb/bin ];then
if [ ! -f $serverPath/mongodb/bin/mongod ];then
mkdir -p $serverPath/mongodb
cd $MG_DIR/${FILE_NAME} && cp -rf ./bin $serverPath/mongodb
fi
+1 -1
View File
@@ -38,7 +38,7 @@ if [ ! -d $MG_DIR/${FILE_NAME} ];then
cd $MG_DIR && tar -zxvf ${FILE_NAME_TGZ}
fi
if [ ! -d $serverPath/mongodb/bin ];then
if [ ! -f $serverPath/mongodb/bin/mongod ];then
mkdir -p $serverPath/mongodb
cd $MG_DIR/${FILE_NAME} && cp -rf ./bin $serverPath/mongodb
fi
+1 -1
View File
@@ -53,7 +53,7 @@ if [ ! -d $MG_DIR/${FILE_NAME} ];then
cd $MG_DIR && tar -zxvf ${FILE_NAME_TGZ}
fi
if [ ! -d $serverPath/mongodb/bin ];then
if [ ! -f $serverPath/mongodb/bin/mongod ];then
mkdir -p $serverPath/mongodb
cd $MG_DIR/${FILE_NAME} && cp -rf ./bin $serverPath/mongodb
fi
+1 -1
View File
@@ -42,7 +42,7 @@ if [ ! -d $MG_DIR/${FILE_NAME_TGZ} ];then
cd $MG_DIR && tar -zxvf ${FILE_NAME_TGZ}
fi
if [ ! -d $serverPath/mongodb/bin ];then
if [ ! -f $serverPath/mongodb/bin/mongod ];then
mkdir -p $serverPath/mongodb
cd $MG_DIR/${FILE_NAME} && cp -rf ./bin $serverPath/mongodb
fi
+1 -1
View File
@@ -53,7 +53,7 @@ if [ ! -d $MG_DIR/${FILE_NAME} ];then
cd $MG_DIR && tar -zxvf ${FILE_NAME_TGZ}
fi
if [ ! -d $serverPath/mongodb/bin ];then
if [ ! -f $serverPath/mongodb/bin/mongod ];then
mkdir -p $serverPath/mongodb
cd $MG_DIR/${FILE_NAME} && cp -rf ./bin $serverPath/mongodb
fi
+1 -1
View File
@@ -23,7 +23,7 @@ if [ ! -d $MG_DIR/mongodb-macos-x86_64-${VERSION} ];then
cd $MG_DIR && tar -zxvf mongodb-macos-x86_64-${VERSION}.tgz
fi
if [ ! -d $serverPath/mongodb/bin ];then
if [ ! -f $serverPath/mongodb/bin/mongod ];then
mkdir -p $serverPath/mongodb
cd $MG_DIR/mongodb-macos-x86_64-${VERSION} && cp -rf ./bin $serverPath/mongodb
fi
+1 -1
View File
@@ -40,7 +40,7 @@ if [ ! -d $MG_DIR/${FILE_NAME} ];then
cd $MG_DIR && tar -zxvf ${FILE_NAME_TGZ}
fi
if [ ! -d $serverPath/mongodb/bin ];then
if [ ! -f $serverPath/mongodb/bin/mongod ];then
mkdir -p $serverPath/mongodb
cd $MG_DIR/${FILE_NAME} && cp -rf ./bin $serverPath/mongodb
fi
+2 -1
View File
@@ -14,6 +14,7 @@ SYS_ARCH=`arch`
SYS_VERSION_ID=`cat /etc/*-release | grep VERSION_ID | awk -F = '{print $2}' | awk -F "\"" '{print $2}'`
SYS_NAME=${SYS_VERSION_ID/./}
# https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu2004-4.4.23.tgz
# https://fastdl.mongodb.org/linux/mongodb-linux-aarch64-ubuntu2204-7.0.37.tgz
if [ "$SYS_NAME" -gt "2204" ];then
SYS_NAME="2204"
@@ -38,7 +39,7 @@ if [ ! -d $MG_DIR/${FILE_NAME} ];then
cd $MG_DIR && tar -zxvf ${FILE_NAME_TGZ}
fi
if [ ! -d $serverPath/mongodb/bin ];then
if [ ! -f $serverPath/mongodb/bin/mongod ];then
mkdir -p $serverPath/mongodb
cd $MG_DIR/${FILE_NAME} && cp -rf ./bin $serverPath/mongodb
fi
+1 -1
View File
@@ -53,7 +53,7 @@ if [ ! -d $MG_DIR/${FILE_NAME} ];then
cd $MG_DIR && tar -zxvf ${FILE_NAME_TGZ}
fi
if [ ! -d $serverPath/mongodb/bin ];then
if [ ! -f $serverPath/mongodb/bin/mongod ];then
mkdir -p $serverPath/mongodb
cd $MG_DIR/${FILE_NAME} && cp -rf ./bin $serverPath/mongodb
fi
+1 -1
View File
@@ -31,7 +31,7 @@ if [ ! -d $MG_DIR/${FILE_NAME_TGZ} ];then
cd $MG_DIR && tar -zxvf ${FILE_NAME_TGZ}
fi
if [ ! -d $serverPath/mongodb/bin ];then
if [ ! -f $serverPath/mongodb/bin/mongod ];then
mkdir -p $serverPath/mongodb
cd $MG_DIR/${FILE_NAME} && cp -rf ./bin $serverPath/mongodb
fi
+1 -1
View File
@@ -53,7 +53,7 @@ if [ ! -d $MG_DIR/${FILE_NAME} ];then
cd $MG_DIR && tar -zxvf ${FILE_NAME_TGZ}
fi
if [ ! -d $serverPath/mongodb/bin ];then
if [ ! -f $serverPath/mongodb/bin/mongod ];then
mkdir -p $serverPath/mongodb
cd $MG_DIR/${FILE_NAME} && cp -rf ./bin $serverPath/mongodb
fi
+1 -1
View File
@@ -30,7 +30,7 @@ if [ ! -d $MG_DIR/${FILE_NAME} ];then
cd $MG_DIR && tar -zxvf ${FILE_NAME_TGZ}
fi
if [ ! -d $serverPath/mongodb/bin ];then
if [ ! -f $serverPath/mongodb/bin/mongod ];then
mkdir -p $serverPath/mongodb
cd $MG_DIR/${FILE_NAME} && cp -rf ./bin $serverPath/mongodb
fi
+1 -1
View File
@@ -40,7 +40,7 @@ if [ ! -d $MG_DIR/${FILE_NAME} ];then
cd $MG_DIR && tar -zxvf ${FILE_NAME_TGZ}
fi
if [ ! -d $serverPath/mongodb/bin ];then
if [ ! -f $serverPath/mongodb/bin/mongod ];then
mkdir -p $serverPath/mongodb
cd $MG_DIR/${FILE_NAME} && cp -rf ./bin $serverPath/mongodb
fi
+6 -1
View File
@@ -15,6 +15,10 @@ SYS_VERSION_ID=`cat /etc/*-release | grep VERSION_ID | awk -F = '{print $2}' | a
SYS_NAME=${SYS_VERSION_ID/./}
# https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu2004-4.4.23.tgz
if [ "$SYS_NAME" -gt "2404" ];then
SYS_NAME="2404"
fi
if [ "$SYS_NAME" -lt "2004" ];then
SYS_NAME="2004"
fi
@@ -42,7 +46,7 @@ if [ ! -d $MG_DIR/${FILE_NAME} ];then
cd $MG_DIR && tar -zxvf ${FILE_NAME_TGZ}
fi
if [ ! -d $serverPath/mongodb/bin ];then
if [ ! -f $serverPath/mongodb/bin/mongod ];then
mkdir -p $serverPath/mongodb
cd $MG_DIR/${FILE_NAME} && cp -rf ./bin $serverPath/mongodb
fi
@@ -72,6 +76,7 @@ cd ${MG_DIR} && rm -rf ${MG_DIR}/${TOOL_FILE_NAME}
# https://fastdl.mongodb.org/tools/db/mongodb-database-tools-ubuntu2204-x86_64-100.9.4.tgz
#--------------- mongodb database install ------------------ #
TOOL_VERSION=100.9.4
SYS_NAME=2204
TOOL_FILE_NAME=mongodb-database-tools-ubuntu${SYS_NAME}-x86_64-${TOOL_VERSION}
if [ "aarch64" == ${SYS_ARCH} ];then
TOOL_FILE_NAME=mongodb-database-tools-ubuntu${SYS_NAME}-arm64-${TOOL_VERSION}
+1 -1
View File
@@ -53,7 +53,7 @@ if [ ! -d $MG_DIR/${FILE_NAME} ];then
cd $MG_DIR && tar -zxvf ${FILE_NAME_TGZ}
fi
if [ ! -d $serverPath/mongodb/bin ];then
if [ ! -f $serverPath/mongodb/bin/mongod ];then
mkdir -p $serverPath/mongodb
cd $MG_DIR/${FILE_NAME} && cp -rf ./bin $serverPath/mongodb
fi
+1 -1
View File
@@ -31,7 +31,7 @@ if [ ! -d $MG_DIR/${FILE_NAME_TGZ} ];then
cd $MG_DIR && tar -zxvf ${FILE_NAME_TGZ}
fi
if [ ! -d $serverPath/mongodb/bin ];then
if [ ! -f $serverPath/mongodb/bin/mongod ];then
mkdir -p $serverPath/mongodb
cd $MG_DIR/${FILE_NAME} && cp -rf ./bin $serverPath/mongodb
fi
+1 -1
View File
@@ -53,7 +53,7 @@ if [ ! -d $MG_DIR/${FILE_NAME} ];then
cd $MG_DIR && tar -zxvf ${FILE_NAME_TGZ}
fi
if [ ! -d $serverPath/mongodb/bin ];then
if [ ! -f $serverPath/mongodb/bin/mongod ];then
mkdir -p $serverPath/mongodb
cd $MG_DIR/${FILE_NAME} && cp -rf ./bin $serverPath/mongodb
fi
+1 -1
View File
@@ -30,7 +30,7 @@ if [ ! -d $MG_DIR/${FILE_NAME} ];then
cd $MG_DIR && tar -zxvf ${FILE_NAME_TGZ}
fi
if [ ! -d $serverPath/mongodb/bin ];then
if [ ! -f $serverPath/mongodb/bin/mongod ];then
mkdir -p $serverPath/mongodb
cd $MG_DIR/${FILE_NAME} && cp -rf ./bin $serverPath/mongodb
fi
+1 -1
View File
@@ -40,7 +40,7 @@ if [ ! -d $MG_DIR/${FILE_NAME} ];then
cd $MG_DIR && tar -zxvf ${FILE_NAME_TGZ}
fi
if [ ! -d $serverPath/mongodb/bin ];then
if [ ! -f $serverPath/mongodb/bin/mongod ];then
mkdir -p $serverPath/mongodb
cd $MG_DIR/${FILE_NAME} && cp -rf ./bin $serverPath/mongodb
fi
+6 -1
View File
@@ -15,6 +15,10 @@ SYS_VERSION_ID=`cat /etc/*-release | grep VERSION_ID | awk -F = '{print $2}' | a
SYS_NAME=${SYS_VERSION_ID/./}
# https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu2004-4.4.23.tgz
if [ "$SYS_NAME" -gt "2404" ];then
SYS_NAME="2404"
fi
if [ "$SYS_NAME" -lt "2004" ];then
SYS_NAME="2004"
fi
@@ -42,7 +46,7 @@ if [ ! -d $MG_DIR/${FILE_NAME} ];then
cd $MG_DIR && tar -zxvf ${FILE_NAME_TGZ}
fi
if [ ! -d $serverPath/mongodb/bin ];then
if [ ! -f $serverPath/mongodb/bin/mongod ];then
mkdir -p $serverPath/mongodb
cd $MG_DIR/${FILE_NAME} && cp -rf ./bin $serverPath/mongodb
fi
@@ -72,6 +76,7 @@ cd ${MG_DIR} && rm -rf ${MG_DIR}/${TOOL_FILE_NAME}
# https://fastdl.mongodb.org/tools/db/mongodb-database-tools-ubuntu2204-x86_64-100.9.4.tgz
#--------------- mongodb database install ------------------ #
TOOL_VERSION=100.9.4
SYS_NAME=2204
TOOL_FILE_NAME=mongodb-database-tools-ubuntu${SYS_NAME}-x86_64-${TOOL_VERSION}
if [ "aarch64" == ${SYS_ARCH} ];then
TOOL_FILE_NAME=mongodb-database-tools-ubuntu${SYS_NAME}-arm64-${TOOL_VERSION}
+2 -2
View File
@@ -4,8 +4,8 @@
"name": "mosquitto",
"title": "mosquitto",
"shell": "install.sh",
"versions":["2.0.18"],
"updates":["2.0.18"],
"versions":["2.0.18", "2.1.2"],
"updates":["2.0.18", "2.1.2"],
"tip": "soft",
"checks": "server/mosquitto",
"path": "server/mosquitto",
+3 -1
View File
@@ -48,7 +48,9 @@ Install_App()
mkdir -p $serverPath/mosquitto
if [ ! -d $serverPath/mosquitto/bin ];then
cd mosquitto-${VERSION} && ${INSTALL_CMD} CMakeLists.txt -DCMAKE_INSTALL_PREFIX=$serverPath/mosquitto && make install
cd mosquitto-${VERSION} && ${INSTALL_CMD} CMakeLists.txt \
-DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
-DCMAKE_INSTALL_PREFIX=$serverPath/mosquitto && make install
fi
if [ -d $serverPath/mosquitto ];then
+29 -10
View File
@@ -69,25 +69,44 @@ fi
VERSION_ID=`cat /etc/*-release | grep 'VERSION_ID' | awk -F = '{print $2}' | awk -F "\"" '{print $2}'`
# 针对ubuntu24进行优化
if [[ "$OSNAME" == "ubuntu" ]] && [[ "$VERSION_ID" =~ "24" ]]; then
# 针对ubuntu24,26进行优化
if [[ "$OSNAME" == "ubuntu" ]] && [[ "$VERSION_ID" =~ ^(24|26)$ ]]; then
cur_dir=`pwd`
cd /usr/lib/x86_64-linux-gnu
if [ ! -f libaio.so.1 ];then
ln -s libaio.so.1t64.0.2 libaio.so.1
if [ -d /usr/lib/x86_64-linux-gnu ];then
cd /usr/lib/x86_64-linux-gnu
if [ ! -f libaio.so.1 ];then
ln -s libaio.so.1t64.0.2 libaio.so.1
fi
if [ ! -f libncurses.so.6 ];then
ln -s libncursesw.so.6.4 libncurses.so.6
fi
fi
if [ ! -f libncurses.so.6 ];then
ln -s libncursesw.so.6.4 libncurses.so.6
if [ -d /usr/lib/aarch64-linux-gnu ];then
cd /usr/lib/aarch64-linux-gnu
if [ ! -f libaio.so.1 ];then
ln -s libaio.so.1t64.0.2 libaio.so.1
fi
fi
cd $cur_dir
fi
if [[ "$OSNAME" == "debian" ]] && [[ "$VERSION_ID" =~ "13" ]]; then
cur_dir=`pwd`
cd /usr/lib/x86_64-linux-gnu
if [ ! -f libaio.so.1 ];then
ln -s libaio.so.1t64.0.2 libaio.so.1
if [ -d /usr/lib/x86_64-linux-gnu ];then
cd /usr/lib/x86_64-linux-gnu
if [ ! -f libaio.so.1 ];then
ln -s libaio.so.1t64.0.2 libaio.so.1
fi
fi
if [ -d /usr/lib/aarch64-linux-gnu ];then
cd /usr/lib/aarch64-linux-gnu
if [ ! -f libaio.so.1 ];then
ln -s libaio.so.1t64.0.2 libaio.so.1
fi
fi
cd $cur_dir
fi
+1 -1
View File
@@ -12,7 +12,7 @@
"path": "server/mysql/VERSION",
"todo_versions":["5.6","5.7","8.0","8.2"],
"versions":["5.5", "5.6", "5.7","8.0","8.2","8.3","8.4","9.0","9.1","9.2","9.3","9.4","9.7"],
"updates":["5.5.62","5.6.50", "5.7.32","8.0.34","8.2.0","8.3.0","9.0.1","9.1.0","9.2.0","9.3.0","9.4.0","9.7.0"],
"updates":["5.5.62","5.6.50", "5.7.32","8.0.46","8.2.0","8.3.0","9.0.1","9.1.0","9.2.0","9.3.0","9.4.0","9.7.0"],
"shell":"install.sh",
"checks":"server/mysql",
"path":"server/mysql",
+25 -2
View File
@@ -131,6 +131,16 @@ Install_mysql()
cd ${rootPath}/plugins/mysql/lib && /bin/bash rpcgen.sh
INSTALL_CMD=cmake
# check cmake version
CMAKE_VERSION=`cmake -version | grep version | awk '{print $3}' | awk -F '.' '{print $1}'`
if [ "$CMAKE_VERSION" -eq "2" ];then
mkdir -p /var/log/mariadb
touch /var/log/mariadb/mariadb.log
INSTALL_CMD=cmake3
fi
if [ ! -f ${mysqlDir}/mysql-boost-${VERSION}.tar.gz ];then
wget --no-check-certificate -O ${mysqlDir}/mysql-boost-${VERSION}.tar.gz --tries=3 https://cdn.mysql.com/archives/mysql-5.7/mysql-boost-${VERSION}.tar.gz
fi
@@ -180,8 +190,12 @@ Install_mysql()
OPTIONS="-DWITH_SSL=${serverPath}/lib/openssl11"
fi
# -DCMAKE_EXE_LINKER_FLAGS="-ltirpc" \
# -DCMAKE_C_FLAGS="-I/usr/include/tirpc" \
# -DCMAKE_CXX_FLAGS="-I/usr/include/tirpc" \
if [ ! -d $serverPath/mysql ];then
cd ${mysqlDir}/mysql-${VERSION} && cmake \
cd ${mysqlDir}/mysql-${VERSION} && ${INSTALL_CMD} \
-DCMAKE_INSTALL_PREFIX=$serverPath/mysql \
-DMYSQL_USER=mysql \
-DMYSQL_TCP_PORT=3306 \
@@ -195,10 +209,19 @@ Install_mysql()
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
-DDOWNLOAD_BOOST=1 \
-DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
-DWITH_CRYPT=system \
-DWITH_SSL=system \
-DWITH_ZLIB=system \
-DWITH_EMBEDDED_SERVER=OFF \
-DHAVE_GETHOSTBYNAME_R_6_ARG=1 \
-DHAVE_GETHOSTBYNAME_R=1 \
-DWITHOUT_TOKUDB=1 \
-DWITHOUT_ROCKSDB=1 \
$OPTIONS \
-DCMAKE_C_COMPILER=${WHERE_DIR_GCC} \
-DCMAKE_CXX_COMPILER=${WHERE_DIR_GPP} \
-DWITH_BOOST=${mysqlDir}/mysql-${VERSION}/boost/
-DWITH_BOOST=${mysqlDir}/mysql-${VERSION}/boost/boost_1_59_0
make -j${cpuCore} && make install && make clean
if [ -d $serverPath/mysql ];then
+2 -2
View File
@@ -54,7 +54,7 @@ fi
VERSION_ID=`cat /etc/*-release | grep VERSION_ID | awk -F = '{print $2}' | awk -F "\"" '{print $2}'`
VERSION=8.0.37
VERSION=8.0.46
Install_mysql()
{
mkdir -p ${mysqlDir}
@@ -102,7 +102,7 @@ Install_mysql()
fi
#检测文件是否损坏.
md5_mysql_ok=e0cb61cbf6e1144c452368c4535ae931
md5_mysql_ok=6707beb0d46a9e08a19aa596329ca79d
if [ -f ${mysqlDir}/mysql-boost-${VERSION}.tar.gz ];then
md5_mysql=`md5sum ${mysqlDir}/mysql-boost-${VERSION}.tar.gz | awk '{print $1}'`
if [ "${md5_mysql_ok}" == "${md5_mysql}" ]; then
+2 -2
View File
@@ -54,7 +54,7 @@ fi
VERSION_ID=`cat /etc/*-release | grep VERSION_ID | awk -F = '{print $2}' | awk -F "\"" '{print $2}'`
VERSION=8.4.2
VERSION=8.4.10
# https://dev.mysql.com/get/Downloads/MySQL-8.4/mysql-${VERSION}.tar.gz
# https://cdn.mysql.com//Downloads/MySQL-8.4/mysql-boost-${VERSION}.tar.gz
Install_mysql()
@@ -104,7 +104,7 @@ Install_mysql()
fi
#检测文件是否损坏.
md5_mysql_ok=a632063fdb1c7de2c5db47e1f66191cd
md5_mysql_ok=db1e11216dd83423a9374999367d77e4
if [ -f ${mysqlDir}/mysql-${VERSION}.tar.gz ];then
md5_mysql=`md5sum ${mysqlDir}/mysql-${VERSION}.tar.gz | awk '{print $1}'`
if [ "${md5_mysql_ok}" == "${md5_mysql}" ]; then
+2 -2
View File
@@ -54,7 +54,7 @@ fi
VERSION_ID=`cat /etc/*-release | grep VERSION_ID | awk -F = '{print $2}' | awk -F "\"" '{print $2}'`
VERSION=9.7.0
VERSION=9.7.1
# https://dev.mysql.com/get/Downloads/MySQL-9.4/mysql-${VERSION}.tar.gz
# https://cdn.mysql.com/archives/mysql-9.4/mysql-9.4.0.tar.gz
Install_mysql()
@@ -104,7 +104,7 @@ Install_mysql()
fi
#检测文件是否损坏.
md5_mysql_ok=c770f276fb84019be6fbe0a57b32efbc
md5_mysql_ok=5d2f4c9568a0e01d20dc5442c772de9f
if [ -f ${mysqlDir}/mysql-${VERSION}.tar.gz ];then
md5_mysql=`md5sum ${mysqlDir}/mysql-${VERSION}.tar.gz | awk '{print $1}'`
if [ "${md5_mysql_ok}" == "${md5_mysql}" ]; then
+14 -3
View File
@@ -15,9 +15,16 @@ echo "最新版本是: $LATEST_VERSION"
NUMBER_LATEST_VERSION=${LATEST_VERSION:1}
echo "最新[NUMBER]是: $NUMBER_LATEST_VERSION"
INSTALL_VERSION=`cat /www/server/nezha/version.pl`
# INSTALL_VERSION=`cat /www/server/nezha/version.pl`
# echo "安装的版本: $INSTALL_VERSION"
INSTALL_VERSION=`/www/server/nezha/dashboard/app -v`
echo "安装的版本: $INSTALL_VERSION"
if [ -d /www/server/nezha ];then
echo "$INSTALL_VERSION" > /www/server/nezha/version.pl
fi
if [ "$INSTALL_VERSION" == "$NUMBER_LATEST_VERSION" ];then
echo "已经是最新!!!"
exit
@@ -89,7 +96,8 @@ if [ ! -d $TARGET_DIR ]; then
mkdir -p $TARGET_DIR
fi
cd $TARGET_DIR && rm -rf app
cd $TARGET_DIR && rm -rf app.bak
cd $TARGET_DIR && mv app app.bak
unzip $DOWNLOAD_FILE -d $TARGET_DIR
echo "TARGET_DIR:"$TARGET_DIR
if [ ! -f $TARGET_DIR/app ];then
@@ -100,6 +108,9 @@ systemctl restart nezha-dashboard
echo $DOWNLOAD_URL
if [ -d /www/server/nezha ];then
echo "$NUMBER_LATEST_VERSION" > /www/server/nezha/version.pl
echo "$INSTALL_VERSION" > /www/server/nezha/version.pl
fi
# 删除下载
rm -rf $DOWNLOAD_FILE
echo "ok"
+1
View File
@@ -3,6 +3,7 @@
<div class='plugin_version'></div>
<div class="bt-w-menu">
<p class="bgw" onclick="pluginService('ollama',$('.plugin_version').attr('version'));">服务</p>
<p onclick="ollama.ai_model_list();">模型列表</p>
<p onclick="pluginInitD('ollama',$('.plugin_version').attr('version'));">自启动</p>
<p onclick="ollama.readme();">说明</p>
</div>
+29
View File
@@ -208,6 +208,35 @@ class App:
mw.execShell('systemctl disable '+self.getPluginName())
return 'ok'
def get_ai_model_list(self):
cmd = 'ollama list'
data = mw.execShell(cmd)
result = []
if data and data[0]:
lines = data[0].strip().split('\n')
for i, line in enumerate(lines):
if i < 1:
continue
line = line.strip()
if not line:
continue
parts = line.split()
if len(parts) >= 4:
name = parts[0]
model_id = parts[1]
size = parts[2] + ' ' + parts[3]
modified = ' '.join(parts[4:])
result.append({
'name': name,
'id': model_id,
'size': size,
'modified': modified
})
import json
return json.dumps(result)
if __name__ == "__main__":
+2
View File
@@ -7,6 +7,8 @@ rootPath=$(dirname "$curPath")
rootPath=$(dirname "$rootPath")
serverPath=$(dirname "$rootPath")
# cd /www/server/mdserver-web && source /www/server/mdserver-web/bin/activate && python3 /www/server/mdserver-web/plugins/ollama/index.py get_ai_model_list 1.0
action=$1
type=$2
+30 -8
View File
@@ -31,14 +31,6 @@ var ollama = {
}
var ret_data = $.parseJSON(res.data);
console.log("send:",ret_data);
// if (!ret_data.status){
// layer.msg(ret_data.msg,{icon:2,time:2000});
// return;
// }
// console.log("send2:",ret_data);
if(typeof(callback) == 'function'){
callback(ret_data);
}
@@ -83,6 +75,36 @@ var ollama = {
},'json');
},
ai_model_list:function(){
this.send({
"tips":"加载中...",
"method": 'get_ai_model_list',
"success": function(data){
var html = '<div class="divtable mtb15">';
html += '<table class="table table-hover">';
html += '<thead><tr><th>NAME</th><th>ID</th><th>SIZE</th><th>MODIFIED</th></tr></thead>';
html += '<tbody>';
if (data && data.length > 0) {
for (var i = 0; i < data.length; i++) {
var item = data[i];
html += '<tr>';
html += '<td>' + (item.name || '') + '</td>';
html += '<td>' + (item.id || '') + '</td>';
html += '<td>' + (item.size || '') + '</td>';
html += '<td>' + (item.modified || '') + '</td>';
html += '</tr>';
}
} else {
html += '<tr><td colspan="4" class="text-center c7">暂无模型</td></tr>';
}
html += '</tbody></table></div>';
$('.soft-man-con').html(html);
},
})
},
readme:function (){
var readme = '<ul class="help-info-text c7">';
readme += '<li>常用命令说明:</li>';
+2
View File
@@ -281,6 +281,7 @@ def status():
return 'start'
# ps -ef|grep nginx|awk '{print $2}'|xargs kill
def restyOp(method):
file = initDreplace()
@@ -292,6 +293,7 @@ def restyOp(method):
current_os = mw.getOs()
if current_os == "darwin":
# print(file + ' ' + method)
data = mw.execShell(file + ' ' + method)
if data[1] == '':
return 'ok'
+2
View File
@@ -49,10 +49,12 @@ case "$1" in
mPID=`cat $PIDFILE`
isStart=`ps ax | awk '{ print $1 }' | grep -e "^${mPID}$"`
if [ "$isStart" = '' ];then
ps -ef|grep nginx|grep -v grep |awk '{print $2}'| xargs kill
echo "$NAME is not running."
exit 1
fi
else
ps -ef|grep nginx|grep -v grep |awk '{print $2}'| xargs kill
echo "$NAME is not running."
exit 1
fi
+2 -2
View File
@@ -17,7 +17,7 @@ if [ ! -d ${SERVER_ROOT}/freetype ];then
cd $SOURCE_ROOT
if [ ! -f $SOURCE_ROOT/freetype-2.12.1.tar.gz ];then
wget -O freetype-2.12.1.tar.gz --no-check-certificate https://download.savannah.gnu.org/releases/freetype/freetype-2.12.1.tar.gz -T 5
wget -O freetype-2.12.1.tar.gz --no-check-certificate https://download-mirror.savannah.gnu.org/releases/freetype/freetype-2.12.1.tar.gz -T 5
fi
if [ ! -d $SOURCE_ROOT/freetype-2.12.1 ];then
@@ -32,4 +32,4 @@ if [ ! -d ${SERVER_ROOT}/freetype ];then
#rm -rf freetype-2.12.1.tar.gz
cd $SOURCE_ROOT && rm -rf $SOURCE_ROOT/freetype-2.12.1
fi
fi
+2 -2
View File
@@ -17,7 +17,7 @@ if [ ! -d ${SERVER_ROOT}/freetype_old ];then
cd $SOURCE_ROOT
if [ ! -f $SOURCE_ROOT/freetype-2.8.1.tar.gz ];then
wget -O freetype-2.8.1.tar.gz --no-check-certificate https://download.savannah.gnu.org/releases/freetype/freetype-2.8.1.tar.gz -T 5
wget -O freetype-2.8.1.tar.gz --no-check-certificate https://download-mirror.savannah.gnu.org/releases/freetype/freetype-2.8.1.tar.gz -T 5
fi
if [ ! -d $SOURCE_ROOT/freetype-2.8.1 ];then
@@ -31,4 +31,4 @@ if [ ! -d ${SERVER_ROOT}/freetype_old ];then
cd $SOURCE_ROOT && rm -rf freetype-2.8.1
cd $SOURCE_ROOT && rm -rf $SOURCE_ROOT/freetype-2.8.1
#rm -rf freetype-2.7.1.tar.gz
fi
fi
+2 -2
View File
@@ -9,9 +9,9 @@ serverPath=$(dirname "$rootPath")
sourcePath=${serverPath}/source
sysName=`uname`
version=8.3.31
version=8.3.33
PHP_VER=83
md5_file_ok=66410cee07f4b2baeb0843140bb2a2b52ef930b5cf9b3d6e6d158b33aae8fa37
md5_file_ok=e293ed620cec74651bb4a071317892a478aa6840fab22db45c72d77cd42f9676
Install_php()
{
#------------------------ install start ------------------------------------#
+2 -2
View File
@@ -9,9 +9,9 @@ serverPath=$(dirname "$rootPath")
sourcePath=${serverPath}/source
sysName=`uname`
version=8.4.22
version=8.4.24
PHP_VER=84
md5_file_ok=696c0f6ad92e94c59059c1eb6e300842b8d050934226efcdf00f2a413cb083cf
md5_file_ok=e127be09a8506f4327c5cfa78a614b00d210714484ec215ce0011b4a03c00731
Install_php()
{
#------------------------ install start ------------------------------------#
+2 -2
View File
@@ -9,9 +9,9 @@ serverPath=$(dirname "$rootPath")
sourcePath=${serverPath}/source
sysName=`uname`
version=8.5.7
version=8.5.9
PHP_VER=85
md5_file_ok=01ba2ed1c2658dacf91bebc8be6a4885f69b811c7993831fc48e26107ab29985
md5_file_ok=0db7855f25bcd0ab1d592cdb35e284d6f6a5d2ae0f6f621122e364cc39b708f4
Install_php()
{
#------------------------ install start ------------------------------------#
+1
View File
@@ -7,6 +7,7 @@ rootPath=$(dirname "$curPath")
rootPath=$(dirname "$rootPath")
serverPath=$(dirname "$rootPath")
# cd /www/server/mdserver-web/plugins/pureftp && bash install.sh install 1.0.49
if [ -f ${rootPath}/bin/activate ];then
source ${rootPath}/bin/activate
+28 -2
View File
@@ -44,21 +44,47 @@ VERSION=$2
# echo $VERSION
if [ "$VERSION" == "3.1.1" ];then
if [ "$sysArch" != "x86_64" ];then
echo "no support"
exit 1
fi
VERSION_NUM=${VERSION}-612d99f
elif [ "$VERSION" == "3.2.1" ]; then
if [ "$sysArch" != "x86_64" ];then
echo "no support"
exit 1
fi
VERSION_NUM=${VERSION}-f152e0b
elif [ "$VERSION" == "3.3.1" ]; then
if [ "$sysArch" != "x86_64" ];then
echo "no support"
exit 1
fi
VERSION_NUM=${VERSION}-b72d67b
elif [ "$VERSION" == "3.4.1" ]; then
if [ "$sysArch" != "x86_64" ];then
echo "no support"
exit 1
fi
VERSION_NUM=${VERSION}-efbcc65
elif [ "$VERSION" == "3.5.1" ]; then
if [ "$sysArch" != "x86_64" ];then
echo "no support"
exit 1
fi
VERSION_NUM=${VERSION}-82c60cb
elif [ "$VERSION" == "3.6.1" ]; then
if [ "$sysArch" != "x86_64" ];then
echo "no support"
exit 1
fi
VERSION_NUM=${VERSION}-c9dbeda
elif [ "$VERSION" == "3.7.1" ]; then
VERSION_NUM=${VERSION}-da9f8a4
elif [ "$VERSION" == "3.8.1" ]; then
VERSION_NUM=${VERSION}-d25e0bb
elif [ "$VERSION" == "3.9.1" ]; then
VERSION_NUM=${VERSION}-141d2ea
fi
# echo $VERSION_NUM
@@ -116,8 +142,8 @@ Install_sphinx()
cd ${SPHINX_DIR} && tar -zxvf ${FILE_TGZ}
if [ "$?" == "0" ];then
mkdir -p $SPHINX_DIR
cp -rf ${SPHINX_DIR}/sphinx-${VERSION}/ $serverPath/sphinx/bin
mkdir -p $serverPath/sphinx/bin
cp -rf ${SPHINX_DIR}/sphinx-${VERSION}/* $serverPath/sphinx/bin
fi
if [ -d $serverPath/sphinx ];then
@@ -54,8 +54,7 @@ def send_msg(bot, tag='ad', trigger_time=300):
mw.writeFile(lock_file, json.dumps(lock_data))
# 信号只在一个周期内执行一次|end
# 实名认证/过人脸🕵️‍♀️各种账号处理✅ | 30/m| next,6/30 | @nngzs
# 18+资源采集| 4/m | next,7/14 | @liuxingyu123
# 实名认证/过人脸🕵️‍♀️各种账号处理✅ | 30/m| next,12/30 | @nngzs
# 98影视采集| 21/m | next,11/21 | @liuxingyu123
keyboard = [
@@ -65,11 +64,7 @@ def send_msg(bot, tag='ad', trigger_time=300):
],
[
types.InlineKeyboardButton(
text="18+资源采集", url='https://ckzy1.com')
],
[
types.InlineKeyboardButton(
text="实名认证/过人脸🕵️‍♀️各种账号处理✅", url='https://t.me/niuniu234')
text="实名认证/过人脸🕵️‍♀️各种账号处理✅", url='https://t.me/zhanzhangyewu')
],
[
types.InlineKeyboardButton(
+259
View File
@@ -0,0 +1,259 @@
# coding:utf-8
import sys
import io
import os
import time
import json
import fcntl
web_dir = os.getcwd() + "/web"
if os.path.exists(web_dir):
sys.path.append(web_dir)
os.chdir(web_dir)
import core.mw as mw
from utils.crontab import crontab as MwCrontab
app_debug = False
if mw.isAppleSystem():
app_debug = True
def getPluginName():
return 'webstats'
def getPluginDir():
return mw.getPluginDir() + '/' + getPluginName()
def getServerDir():
return mw.getServerDir() + '/' + getPluginName()
def getConf():
conf = getServerDir() + "/lua/config.json"
return conf
def getGlobalConf():
conf = getConf()
content = mw.readFile(conf)
result = json.loads(content)
return result
def pSqliteDb(dbname='web_logs', site_name='unset', fn="logs"):
db_dir = getServerDir() + '/logs/' + site_name
if not os.path.exists(db_dir):
mw.execShell('mkdir -p ' + db_dir)
name = fn
file = db_dir + '/' + name + '.db'
if not os.path.exists(file):
conn = mw.M(dbname).dbPos(db_dir, name)
sql = mw.readFile(getPluginDir() + '/conf/init.sql')
sql_list = sql.split(';')
for index in range(len(sql_list)):
conn.execute(sql_list[index], ())
else:
conn = mw.M(dbname).dbPos(db_dir, name)
conn.execute("PRAGMA synchronous = 0", ())
conn.execute("PRAGMA page_size = 4096", ())
conn.execute("PRAGMA journal_mode = wal", ())
conn.autoTextFactory()
return conn
def migrateSiteHotLogs(site_name, query_date):
start_time = time.time()
print(f"[{site_name}] 开始迁移日志...")
migrating_flag = getServerDir() + "/logs/%s/migrating" % site_name
hot_db = getServerDir() + "/logs/%s/logs.db" % site_name
hot_db_tmp = getServerDir() + "/logs/%s/logs_tmp.db" % site_name
history_logs_db = getServerDir() + "/logs/%s/history_logs.db" % site_name
if not os.path.exists(hot_db):
print(f"[{site_name}] 热日志数据库不存在,跳过")
return mw.returnMsg(True, f"{site_name} logs not exist, skip")
# 检查是否正在迁移
if os.path.exists(migrating_flag):
print(f"[{site_name}] 正在迁移中,跳过")
return mw.returnMsg(True, f"{site_name} is migrating, skip")
todayTime = time.strftime('%Y-%m-%d 00:00:00', time.localtime())
todayUt = int(time.mktime(time.strptime(
todayTime, "%Y-%m-%d %H:%M:%S")))
# 1. 备份到临时文件(copy 期间短暂互斥,完成后立即解除)
try:
import shutil
print(f"[{site_name}] 备份 {hot_db} -> {hot_db_tmp} ...")
mw.writeFile(migrating_flag, "yes")
time.sleep(0.5)
shutil.copy(hot_db, hot_db_tmp)
if not os.path.exists(hot_db_tmp):
return mw.returnMsg(False, f"{site_name} migrating fail, copy tmp file!")
except Exception as e:
return mw.returnMsg(False, f"{site_name} migrating fail: {e}")
finally:
if os.path.exists(migrating_flag):
os.remove(migrating_flag)
# 2. 从临时备份中迁移热日志数据到历史日志(读 logs_tmp,不阻塞 live 写入)
try:
logs_conn = pSqliteDb('web_log', site_name, 'logs_tmp')
history_logs_conn = pSqliteDb('web_log', site_name, 'history_logs')
hot_db_columns = logs_conn.originExecute(
"PRAGMA table_info([web_logs])")
_columns = [c[1] for c in hot_db_columns if c[1] != "id"]
columns_str = ",".join(_columns)
placeholders = ",".join(["?"] * len(_columns))
logs_sql = f"select {columns_str} from web_logs where time<{todayUt}"
selector = logs_conn.originExecute(logs_sql)
# 批量插入配置
batch_size = 10000
batch_count = 0
total_count = 0
insert_sql = f"insert into web_logs({columns_str}) values({placeholders})"
while True:
logs = selector.fetchmany(batch_size)
if not logs:
break
batch_count += 1
total_count += len(logs)
# 使用原生 executemany 批量插入
history_logs_conn.executemany(insert_sql, logs)
history_logs_conn.commit()
if batch_count % 10 == 0:
elapsed = time.time() - start_time
print(f"[{site_name}] 已迁移 {total_count} 条记录, 耗时 {elapsed:.2f}s")
print(f"[{site_name}] 共迁移 {total_count} 条记录")
# 清理历史数据
gcfg = getGlobalConf()
save_day = gcfg['global']["save_day"]
print(f"[{site_name}] 删除 {save_day} 天前的历史数据...")
time_now = time.localtime()
save_timestamp = time.mktime((time_now.tm_year, time_now.tm_mon, time_now.tm_mday - save_day, 0, 0, 0, 0, 0, 0))
delete_sql = f"delete from web_logs where time <= {save_timestamp}"
history_logs_conn.execute(delete_sql)
history_logs_conn.commit()
history_logs_conn.execute("VACUUM;")
history_logs_conn.commit()
except Exception as e:
if os.path.exists(hot_db_tmp):
os.remove(hot_db_tmp)
print(f"[{site_name}] logs to history error: {e}")
return mw.returnMsg(False, f"{site_name} logs migrate error: {e}")
# 3. 删除已迁移的数据并清理统计(仅 DELETE/VACUUM 期间互斥)
try:
mw.writeFile(migrating_flag, "yes")
time.sleep(0.5)
hot_db_conn = pSqliteDb('web_logs', site_name)
# 分批删除热日志
del_hot_log = f"delete from web_logs where time<{todayUt}"
print(f"[{site_name}] 删除已迁移的热日志...")
hot_db_conn.execute(del_hot_log)
# 删除过期统计数据
print(f"[{site_name}] 删除180天前的统计数据...")
save_time_key = time.strftime(
'%Y%m%d00', time.localtime(time.time() - 180 * 86400))
del_request_stat_sql = f"delete from request_stat where time<={save_time_key}"
hot_db_conn.execute(del_request_stat_sql)
hot_db_conn.execute(f"delete from spider_stat where time<={save_time_key}")
hot_db_conn.execute(f"delete from client_stat where time<={save_time_key}")
hot_db_conn.execute(f"delete from referer_stat where time<={save_time_key}")
hot_db_conn.commit()
print(f"[{site_name}] 压缩热数据库...")
hot_db_conn.execute("VACUUM;")
hot_db_conn.commit()
except Exception as e:
print(f"[{site_name}] delete hot logs error: {e}")
finally:
if os.path.exists(migrating_flag):
os.remove(migrating_flag)
if os.path.exists(hot_db_tmp):
os.remove(hot_db_tmp)
elapsed = time.time() - start_time
print(f"[{site_name}] 日志迁移完成,耗时 {elapsed:.2f}s")
if not mw.isAppleSystem():
mw.execShell("chown -R www:www " + getServerDir())
return mw.returnMsg(True, f"{site_name} logs migrate ok")
def migrateHotLogs(query_date="today"):
# 使用文件锁防止并发迁移
lock_file = getServerDir() + "/logs/migrate_hot_logs.lock"
lock_fd = None
try:
lock_fd = open(lock_file, 'w')
fcntl.flock(lock_fd.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB)
print("开始迁移热日志...")
sites = mw.M('sites').field('name').order("add_time").select()
unset_site = {"name": "unset"}
sites.append(unset_site)
total_sites = len(sites)
success_count = 0
fail_count = 0
for i, site_info in enumerate(sites):
site_name = site_info["name"]
print(f"\n[{i+1}/{total_sites}] 处理站点: {site_name}")
migrate_res = migrateSiteHotLogs(site_name, query_date)
if migrate_res["status"]:
success_count += 1
else:
fail_count += 1
print(f"[{site_name}] 迁移失败: {migrate_res['msg']}")
print(f"\n迁移完成! 成功: {success_count}, 失败: {fail_count}")
return mw.returnMsg(True, f"logs migrate ok, success: {success_count}, fail: {fail_count}")
except BlockingIOError:
print("正在迁移中,跳过")
return mw.returnMsg(True, "正在迁移中,跳过")
except Exception as e:
print(f"migrateHotLogs error: {e}")
return mw.returnMsg(False, f"migrateHotLogs error: {e}")
finally:
if lock_fd:
try:
fcntl.flock(lock_fd.fileno(), fcntl.LOCK_UN)
lock_fd.close()
if os.path.exists(lock_file):
os.remove(lock_file)
except:
pass
+209
View File
@@ -0,0 +1,209 @@
# coding:utf-8
import sys
import io
import os
import time
import json
web_dir = os.getcwd() + "/web"
if os.path.exists(web_dir):
sys.path.append(web_dir)
os.chdir(web_dir)
import core.mw as mw
from utils.crontab import crontab as MwCrontab
app_debug = False
if mw.isAppleSystem():
app_debug = True
def getPluginName():
return 'webstats'
def getPluginDir():
return mw.getPluginDir() + '/' + getPluginName()
def getServerDir():
return mw.getServerDir() + '/' + getPluginName()
def getConf():
conf = getServerDir() + "/lua/config.json"
return conf
def getGlobalConf():
conf = getConf()
content = mw.readFile(conf)
result = json.loads(content)
return result
def pSqliteDb(dbname='web_logs', site_name='unset', fn="logs"):
db_dir = getServerDir() + '/logs/' + site_name
if not os.path.exists(db_dir):
mw.execShell('mkdir -p ' + db_dir)
name = fn
file = db_dir + '/' + name + '.db'
if not os.path.exists(file):
conn = mw.M(dbname).dbPos(db_dir, name)
sql = mw.readFile(getPluginDir() + '/conf/init.sql')
sql_list = sql.split(';')
for index in range(len(sql_list)):
conn.execute(sql_list[index], ())
else:
conn = mw.M(dbname).dbPos(db_dir, name)
conn.execute("PRAGMA synchronous = 0", ())
conn.execute("PRAGMA page_size = 4096", ())
conn.execute("PRAGMA journal_mode = wal", ())
conn.autoTextFactory()
# conn.text_factory = lambda x: str(x, encoding="utf-8", errors='ignore')
# conn.text_factory = lambda x: unicode(x, "utf-8", "ignore")
return conn
def migrateSiteHotLogs(site_name, query_date):
print(site_name, query_date)
migrating_flag = getServerDir() + "/logs/%s/migrating" % site_name
hot_db = getServerDir() + "/logs/%s/logs.db" % site_name
hot_db_tmp = getServerDir() + "/logs/%s/logs_tmp.db" % site_name
history_logs_db = getServerDir() + "/logs/%s/history_logs.db" % site_name
# 1. copy to tmp file
try:
import shutil
print("coping {} to {} ...".format(hot_db, hot_db_tmp))
mw.writeFile(migrating_flag, "yes")
time.sleep(3)
shutil.copy(hot_db, hot_db_tmp)
if not os.path.exists(hot_db_tmp):
return mw.returnMsg(False, "migrating fail, copy tmp file!")
except:
return mw.returnMsg(False, "{} migrating fail.".format(site_name))
finally:
if os.path.exists(migrating_flag):
os.remove(migrating_flag)
# 2. 从临时备份中迁移热日志数据到历史日志
print("begin tmp to hot log data ...")
try:
print("history file: {}".format(history_logs_db))
logs_conn = pSqliteDb('web_log', site_name, 'logs_tmp')
history_logs_conn = pSqliteDb('web_log', site_name, 'history_logs')
hot_db_columns = logs_conn.originExecute(
"PRAGMA table_info([web_logs])")
_columns = ",".join([c[1] for c in hot_db_columns if c[1] != "id"])
query_start = 0
todayTime = time.strftime('%Y-%m-%d 00:00:00', time.localtime())
todayUt = int(time.mktime(time.strptime(
todayTime, "%Y-%m-%d %H:%M:%S")))
logs_sql = "select {} from web_logs where time<{}".format(
_columns, todayUt)
selector = logs_conn.originExecute(logs_sql)
log = selector.fetchone()
while log:
params = ""
for field in log:
if params:
params += ","
if field is None:
field = "\'\'"
elif type(field) == str:
field = "\'" + field.replace("\'", "\"") + "\'"
params += str(field)
insert_sql = "insert into web_logs(" + \
_columns + ") values(" + params + ")"
history_logs_conn.execute(insert_sql)
log = selector.fetchone()
print("sorting historical data, this action takes a long time...")
history_logs_conn.execute("VACUUM;")
gcfg = getGlobalConf()
save_day = gcfg['global']["save_day"]
print("delete historical data {} days ago...".format(save_day))
time_now = time.localtime()
save_timestamp = time.mktime((time_now.tm_year, time_now.tm_mon, time_now.tm_mday - save_day, 0, 0, 0, 0, 0, 0))
delete_sql = "delete from web_logs where time <= {}".format(
save_timestamp)
print('delete history_logs')
print(delete_sql)
history_logs_conn.execute(delete_sql)
history_logs_conn.commit()
# 3. delete merged data and clean up statistics
print("delete merged thermal data...")
mw.writeFile(migrating_flag, "yes")
hot_db_conn = pSqliteDb('web_logs', site_name)
del_hot_log = "delete from web_logs where time<{}".format(todayUt)
print(del_hot_log)
r = hot_db_conn.execute(del_hot_log)
print("delete:", r)
print("deleting statistics over 180 days...")
save_time_key = time.strftime(
'%Y%m%d00', time.localtime(time.time() - 180 * 86400))
del_request_stat_sql = "delete from request_stat where time<={}".format(
save_time_key)
hot_db_conn.execute(del_request_stat_sql)
hot_db_conn.execute(
"delete from spider_stat where time<={}".format(save_time_key))
hot_db_conn.execute(
"delete from client_stat where time<={}".format(save_time_key))
hot_db_conn.execute(
"delete from referer_stat where time<={}".format(save_time_key))
hot_db_conn.commit()
print("clean up the hot database...")
hot_db_conn.execute("VACUUM;")
hot_db_conn.commit()
if os.path.exists(migrating_flag):
os.remove(migrating_flag)
except Exception as e:
if site_name:
print("{} logs to history error:{}".format(site_name, e))
else:
print("logs to history error:{}".format(e))
finally:
if os.path.exists(hot_db_tmp):
os.remove(hot_db_tmp)
print("{} logs migrate ok.".format(site_name))
if not mw.isAppleSystem():
mw.execShell("chown -R www:www " + getServerDir())
mw.opWeb('restart')
return mw.returnMsg(True, "{} logs migrate ok".format(site_name))
def migrateHotLogs(query_date="today"):
print("begin migrate hot logs")
sites = mw.M('sites').field('name').order("add_time").select()
unset_site = {"name": "unset"}
sites.append(unset_site)
# migrateSiteHotLogs('t1.cn', query_date)
for site_info in sites:
# print(site_info['name'])
site_name = site_info["name"]
migrate_res = migrateSiteHotLogs(site_name, query_date)
if not migrate_res["status"]:
print(migrate_res["msg"])
print("end migrate hot logs")
+3
View File
@@ -0,0 +1,3 @@
lua_shared_dict mw_total 100m;
lua_need_request_body off;
include {$SERVER_APP}/lua/webstats_log.lua;
File diff suppressed because it is too large Load Diff
+667
View File
@@ -0,0 +1,667 @@
log_by_lua_block {
local cpath = "{$SERVER_APP}/lua/"
if not package.cpath:find(cpath) then
package.cpath = cpath .. "?.so;" .. package.cpath
end
if not package.path:find(cpath) then
package.path = cpath .. "?.lua;" .. package.path
end
local ver = '0.2.4'
local debug_mode = true
local __C = require "webstats_common"
local C = __C:getInstance()
-- cache start ---
local cache = ngx.shared.mw_total
local function cache_set(server_name, id ,key, val)
local line_kv = "log_kv_"..server_name..'_'..id.."_"..key
-- cache:set(line_kv, val)
cache:set(line_kv, val)
end
local function cache_clear(server_name, id, key)
local line_kv = "log_kv_"..server_name..'_'..id.."_"..key
cache:delete(line_kv)
end
local function cache_get(server_name, id, key)
local line_kv = "log_kv_"..server_name..'_'..id.."_"..key
local value = cache:get(line_kv)
return value
end
-- cache end ---
-- domain config is import
local db = nil
local json = require "cjson"
local sqlite3 = require "lsqlite3"
local config = require "webstats_config"
local sites = require "webstats_sites"
-- string.gsub(C:get_sn(ngx.var.server_name),'_','.')
local server_name = C:get_sn(ngx.var.server_name)
C:setConfData(config, sites)
local auto_config = C:setInputSn(server_name)
local request_header = ngx.req.get_headers()
local method = ngx.req.get_method()
local excluded = false
local day = os.date("%d")
local number_day = tonumber(day)
local day_column = "day"..number_day
local flow_column = "flow"..number_day
local spider_column = "spider_flow"..number_day
--- default common var end ---
local function init_var()
return true
end
--------------------- exclude_func start --------------------------
local function load_global_exclude_ip()
local load_key = "global_exclude_ip_load"
-- update global exclude ip
local global_exclude_ip = auto_config["exclude_ip"]
if global_exclude_ip then
for i, _ip in pairs(global_exclude_ip)
do
-- global
-- D("set global exclude ip: ".._ip)
if not cache:get("global_exclude_ip_".._ip) then
cache:set("global_exclude_ip_".._ip, true)
end
end
end
-- set tag
cache:set(load_key, true)
end
local function load_exclude_ip(input_server_name)
local load_key = input_server_name .. "_exclude_ip_load"
local site_config = config[input_server_name]
local site_exclude_ip = nil
if site_config then
site_exclude_ip = site_config["exclude_ip"]
end
-- update server_name exclude ip
if site_exclude_ip then
for i, _ip in pairs(site_exclude_ip)
do
cache:set(input_server_name .. "_exclude_ip_".._ip, true)
end
end
-- set tag
cache:set(load_key, true)
return true
end
local function filter_status()
if not auto_config['exclude_status'] then return false end
local the_status = tostring(ngx.status)
for _,v in ipairs(auto_config['exclude_status'])
do
if the_status == v then
return true
end
end
return false
end
local function exclude_extension()
if not ngx.var.uri then return false end
if not auto_config['exclude_extension'] then return false end
for _,v in ipairs(auto_config['exclude_extension'])
do
if ngx.re.find(ngx.var.uri,"[.]"..v.."$",'ijo') then
return true
end
end
return false
end
local function exclude_url()
if not ngx.var.uri then return false end
if not ngx.var.request_uri then return false end
if not auto_config['exclude_url'] then return false end
local the_uri = string.sub(ngx.var.request_uri, 2)
local url_conf = auto_config["exclude_url"]
for i,conf in ipairs(url_conf)
do
local mode = conf["mode"]
local url = conf["url"]
if mode == "regular" then
if ngx.re.find(the_uri, url, "ijo") then
return true
end
else
if the_uri == url then
return true
end
end
end
return false
end
local function exclude_ip(input_server_name, ip)
-- 排除IP匹配,分网站单独的配置和全局配置两种方式
local site_config = config[input_server_name]
local server_exclude_ips = nil
local check_server_exclude_ip = false
if site_config then
server_exclude_ips = site_config["exclude_ip"]
if not server_exclude_ips then
return false
end
for k, _ip in pairs(server_exclude_ips)
do
check_server_exclude_ip = true
break
end
end
-- D("server[" ..input_server_name.."]check exclude ip : "..tostring(check_server_exclude_ip))
if check_server_exclude_ip then
if cache:get(input_server_name .. "_exclude_ip_"..ip) then
-- D("-Exclude server ip:"..ip)
return true
end
else
if cache:get("global_exclude_ip_"..ip) then
-- D("*Excluded global ip:"..ip)
return true
end
end
return false
end
--------------------- exclude_func end ---------------------------
local function cache_logs_old(server_name)
-- make new id
local new_id = C:get_last_id(server_name)
local excluded = false
local ip = C:get_client_ip()
excluded = filter_status() or exclude_extension() or exclude_url() or exclude_ip(server_name, ip)
local ip_list = request_header["x-forwarded-for"]
if ip and not ip_list then
ip_list = ip
end
local remote_addr = ngx.var.remote_addr
if not string.find(ip_list, remote_addr) then
if remote_addr then
ip_list = ip_list .. "," .. remote_addr
end
end
-- local request_time = ngx.var.request_time
local request_time = C:get_request_time()
local client_port = ngx.var.remote_port
local real_server_name = ngx.var.server_name
local uri = ngx.var.uri
local status_code = ngx.status
local protocol = ngx.var.server_protocol
local request_uri = ngx.var.request_uri
local time_key = C:get_store_key()
local method = method
local body_length = C:get_length()
local domain = C:get_domain()
local referer = ngx.var.http_referer
local kv = {
id=new_id,
time_key=time_key,
time=ngx.time(),
ip=ip,
domain=domain,
server_name=server_name,
real_server_name=real_server_name,
method=method,
status_code=status_code,
uri=uri,
request_uri=request_uri,
body_length=body_length,
referer=referer,
user_agent=request_header['user-agent'],
protocol=protocol,
is_spider=0,
request_time=request_time,
excluded=excluded,
request_headers='',
ip_list=ip_list,
client_port=client_port
}
local request_stat_fields = "req=req+1,length=length+"..body_length
local spider_stat_fields = "x"
local client_stat_fields = "x"
if not excluded then
if status_code == 500 or (method=="POST" and config["record_post_args"] == true) or (status_code==403 and config["record_get_403_args"] == true) then
local data = ""
local ok, err = pcall(function() data = C:get_http_origin() end)
if ok and not err then
kv["request_headers"] = data
end
end
if ngx.re.find("500,501,502,503,504,505,506,507,509,510,400,401,402,403,404,405,406,407,408,409,410,411,412,413,414,415,416,417,418,421,422,423,424,425,426,449,451,499", tostring(status_code), "jo") then
local field = "status_"..status_code
request_stat_fields = request_stat_fields .. ","..field.."="..field.."+1"
end
local lower_method = string.lower(method)
if ngx.re.find("get,post,put,patch,delete", lower_method, "ijo") then
local field = "http_"..lower_method
request_stat_fields = request_stat_fields .. ","..field.."="..field.."+1"
end
local ipc = 0
local pvc = 0
local uvc = 0
local is_spider, request_spider, spider_index = C:match_spider(kv['user_agent'])
if not is_spider then
client_stat_fields = C:match_client(kv['user_agent'])
if not client_stat_fields or #client_stat_fields == 0 then
client_stat_fields = request_stat_fields..",other=other+1"
end
pvc, uvc = C:statistics_request(ip, is_spider,body_length)
ipc = C:statistics_ipc(server_name,ip)
else
kv["is_spider"] = spider_index
local field = "spider"
spider_stat_fields = request_spider.."="..request_spider.."+"..1
request_stat_fields = request_stat_fields .. ","..field.."="..field.."+"..1
end
if ipc > 0 then
request_stat_fields = request_stat_fields..",ip=ip+1"
end
if uvc > 0 then
request_stat_fields = request_stat_fields..",uv=uv+1"
end
if pvc > 0 then
request_stat_fields = request_stat_fields..",pv=pv+1"
end
end
local stat_fields = request_stat_fields..";"..client_stat_fields..";"..spider_stat_fields
cache_set(server_name, new_id, "stat_fields", stat_fields)
cache_set(server_name, new_id, "log_kv", json.encode(kv))
end
local function cache_logs(input_sn)
-- make new id
local new_id = C:get_last_id(input_sn)
local excluded = false
local ip = C:get_client_ip()
excluded = filter_status() or exclude_extension() or exclude_url() or exclude_ip(input_sn, ip)
local ip_list = request_header["x-forwarded-for"]
if ip and not ip_list then
ip_list = ip
end
local remote_addr = ngx.var.remote_addr
-- 修复反向代理代过来的数据
if "table" == type(ip_list) then
ip_list = json.encode(ip_list)
end
if not string.find(ip_list, remote_addr) then
if remote_addr then
ip_list = ip_list .. "," .. remote_addr
end
end
-- local request_time = ngx.var.request_time
local request_time = C:get_request_time()
local client_port = ngx.var.remote_port
local real_server_name = input_sn
local uri = tostring(ngx.var.uri)
local status_code = ngx.status
local protocol = ngx.var.server_protocol
local request_uri = ngx.var.request_uri
local time_key = C:get_store_key()
local method = method
local body_length = C:get_length()
local domain = C:get_domain()
local referer = ngx.var.http_referer
local kv = {
id=new_id,
time_key=time_key,
time=ngx.time(),
ip=ip,
domain=domain,
server_name=input_sn,
real_server_name=real_server_name,
method=method,
status_code=status_code,
uri=uri,
request_uri=request_uri,
body_length=body_length,
referer=referer,
user_agent=request_header['user-agent'],
protocol=protocol,
is_spider=0,
request_time=request_time,
excluded=excluded,
request_headers='',
ip_list=ip_list,
client_port=client_port
}
-- C:D(json.encode(kv))
local request_stat_fields = {req=1,length=body_length}
local spider_stat_fields = {}
local client_stat_fields = {}
if not excluded then
if status_code == 500 or (method=="POST" and config['global']["record_post_args"] == true) or (status_code==403 and config['global']["record_get_403_args"] == true) then
local data = ""
local ok, err = pcall(function() data = C:get_http_origin() end)
if ok and not err then
kv["request_headers"] = data
else
C:D("debug request_headers error:"..tostring(err))
end
end
if ngx.re.find("500,501,502,503,504,505,506,507,509,510,400,401,402,403,404,405,406,407,408,409,410,411,412,413,414,415,416,417,418,421,422,423,424,425,426,449,451,499", tostring(status_code), "jo") then
local field = "status_"..status_code
request_stat_fields[field] = 1
end
-- D("method:"..method)
local lower_method = string.lower(method)
if ngx.re.find("get,post,put,patch,delete", lower_method, "ijo") then
local field = "http_"..lower_method
request_stat_fields[field] = 1
end
local ipc = 0
local pvc = 0
local uvc = 0
local is_spider, request_spider, spider_index = C:match_spider(kv['user_agent'])
if not is_spider then
client_stat_fields = C:match_client_arr(kv['user_agent'])
pvc, uvc = C:statistics_request(ip, is_spider,body_length)
ipc = C:statistics_ipc(input_sn,ip)
else
kv["is_spider"] = spider_index
local field = "spider"
spider_stat_fields[request_spider] = 1
request_stat_fields[field] = 1
end
if ipc > 0 then
request_stat_fields["ip"] = 1
end
if uvc > 0 then
request_stat_fields["uv"] = 1
end
if pvc > 0 then
request_stat_fields["pv"] = 1
end
end
local stat_fields = {
request_stat_fields=request_stat_fields,
client_stat_fields=client_stat_fields,
spider_stat_fields=spider_stat_fields,
}
local data = {
server_name=input_sn,
stat_fields=stat_fields,
log_kv=kv,
}
local push_data = json.encode(data)
-- C:D(json.encode(push_data))
local key = C:getTotalKey()
ngx.shared.mw_total:rpush(key, push_data)
end
local function store_logs_line(db, stmt, input_server_name, lineno)
local logvalue = cache_get(input_server_name, lineno, "log_kv")
if not logvalue then return false end
local logline = json.decode(logvalue)
local time = logline["time"]
local id = logline["id"]
local protocol = logline["protocol"]
local client_port = logline["client_port"]
local status_code = logline["status_code"]
local uri = logline["uri"]
local request_uri = logline["request_uri"]
local method = logline["method"]
local body_length = logline["body_length"]
local referer = logline["referer"]
local ip = logline["ip"]
local ip_list = logline["ip_list"]
local request_time = logline["request_time"]
local is_spider = logline["is_spider"]
local domain = logline["domain"]
local server_name = logline["server_name"]
local user_agent = logline["user_agent"]
local request_headers = logline["request_headers"]
local excluded = logline["excluded"]
local request_stat_fields = nil
local client_stat_fields = nil
local spider_stat_fields = nil
local stat_fields = cache_get(input_server_name, id, "stat_fields")
if stat_fields == nil then
-- D("Log stat fields is nil.")
-- D("Logdata:"..logvalue)
else
stat_fields = C:split(stat_fields, ";")
request_stat_fields = stat_fields[1]
client_stat_fields = stat_fields[2]
spider_stat_fields = stat_fields[3]
if "x" == client_stat_fields then
client_stat_fields = nil
end
if "x" == spider_stat_fields then
spider_stat_fields = nil
end
end
local time_key = logline["time_key"]
if not excluded then
stmt:bind_names{
time=time,
ip=ip,
domain=domain,
server_name=server_name,
method=method,
status_code=status_code,
uri=request_uri,
body_length=body_length,
referer=referer,
user_agent=user_agent,
protocol=protocol,
request_time=request_time,
is_spider=is_spider,
request_headers=request_headers,
ip_list=ip_list,
client_port=client_port,
}
local res, err = stmt:step()
if tostring(res) == "5" then
-- D("step res:"..tostring(res))
-- D("step err:"..tostring(err))
-- D("the step database connection is busy, so it will be stored later.")
return false
end
stmt:reset()
-- D("store_logs_line ok")
C:update_stat( db, "client_stat", time_key, client_stat_fields)
C:update_stat( db, "spider_stat", time_key, spider_stat_fields)
-- C:D("stat ok")
-- only count non spider requests
local ok, err = C:statistics_uri(db, request_uri, ngx.md5(request_uri), body_length)
local ok, err = C:statistics_ip(db, ip, body_length)
end
C:update_stat( db, "request_stat", time_key, request_stat_fields)
return true
end
local function store_logs(input_sn)
if C:is_migrating(input_sn) == true then
-- D("migrating...")
return
end
local last_insert_id_key = input_sn.."_last_id"
local store_start_id_key = input_sn.."_store_start"
local last_id = cache:get(last_insert_id_key)
local store_start = cache:get(store_start_id_key)
if store_start == nil then
store_start = 1
end
local store_end = last_id
if store_end == nil then
store_end = 1
end
local worker_id = ngx.worker.id()
if C:is_working(input_sn) then
-- D("other workers are being stored, please store later.")
-- cache:delete(flush_data_key)
return true
end
C:lock_working(input_sn)
local log_dir = "{$SERVER_APP}/logs"
local db_path = log_dir .. '/' .. input_sn .. "/logs.db"
local db, err = sqlite3.open(db_path)
if tostring(err) ~= 'nil' then
C:D("sqlite3 open error:"..tostring(err))
return true
end
db:exec([[PRAGMA synchronous = 0]])
db:exec([[PRAGMA page_size = 4096]])
db:exec([[PRAGMA journal_mode = wal]])
db:exec([[PRAGMA journal_size_limit = 1073741824]])
local stmt2 = nil
if db ~= nil then
stmt2 = db:prepare[[INSERT INTO web_logs(
time, ip, domain, server_name, method, status_code, uri, body_length,
referer, user_agent, protocol, request_time, is_spider, request_headers, ip_list, client_port)
VALUES(:time, :ip, :domain, :server_name, :method, :status_code, :uri,
:body_length, :referer, :user_agent, :protocol, :request_time, :is_spider,
:request_headers, :ip_list, :client_port)]]
end
if db == nil or stmt2 == nil then
-- D("web data db error")
-- cache:set(storing_key, false)
if db and db:isopen() then
db:close()
end
return true
end
status, errorString = db:exec([[BEGIN TRANSACTION]])
C:clean_stats(db, input_sn)
if store_end >= store_start then
for i=store_start, store_end, 1 do
-- D("store_start:"..store_start..":store_end:".. store_end)
if store_logs_line(db, stmt2, input_sn, i) then
cache_clear(input_sn, i, "log_kv")
cache_clear(input_sn, i, "stat_fields")
end
end
end
local res, err = stmt2:finalize()
if tostring(res) == "5" then
C:D("Finalize res:"..tostring(res)..",Finalize err:"..tostring(err))
end
local now_date = os.date("*t")
local save_day = config['global']["save_day"]
local save_date_timestamp = os.time{year=now_date.year,
month=now_date.month, day=now_date.day-save_day, hour=0}
-- delete expire data
db:exec("DELETE FROM web_logs WHERE time<"..tostring(save_date_timestamp))
local res, err = db:execute([[COMMIT]])
if db and db:isopen() then
db:close()
end
cache:set(store_start_id_key, store_end+1)
C:unlock_working(input_sn)
end
local function run_app()
-- C:D("------------ debug start ------------")
init_var()
load_global_exclude_ip()
load_exclude_ip(server_name)
cache_logs(server_name)
-- C:cron()
-- cache_logs_old(server_name)
-- store_logs(server_name)
-- C:D("------------ debug end -------------")
end
local function run_app_ok()
if not debug_mode then return run_app() end
local presult, err = pcall( function() run_app() end)
if not presult then
C:D("debug error on :"..tostring(err))
return true
end
end
return run_app_ok()
}
+3 -1
View File
@@ -7,6 +7,7 @@ PRAGMA journal_size_limit = 1073741824;
CREATE TABLE IF NOT EXISTS `web_logs` (
`time` INTEGER,
`ip` TEXT,
`scheme` TEXT,
`domain` TEXT,
`server_name` TEXT,
`method` TEXT,
@@ -32,7 +33,8 @@ CREATE INDEX status_code_idx ON web_logs (`status_code`);
CREATE INDEX request_time_idx ON web_logs (`request_time`);
CREATE INDEX is_spider_idx ON web_logs (`is_spider`);
CREATE INDEX body_length_idx ON web_logs (`body_length`);
CREATE INDEX all_union_idx ON web_logs(`status_code`, `time`, `ip`, `domain`, `server_name`, `method`, `is_spider`, `protocol`, `request_headers`, `ip_list`, `client_port`, `body_length`, `user_agent`, `referer`, `request_time`, `uri`);
CREATE INDEX scheme_idx ON web_logs (`scheme`);
CREATE INDEX all_union_idx ON web_logs(`status_code`, `time`, `ip`, `scheme`, `domain`, `server_name`, `method`, `is_spider`, `protocol`, `request_headers`, `ip_list`, `client_port`, `body_length`, `user_agent`, `referer`, `request_time`, `uri`);
CREATE TABLE IF NOT EXISTS `client_stat`(
+3 -2
View File
@@ -1,3 +1,4 @@
lua_shared_dict mw_total 100m;
lua_shared_dict webstats_queue 128m;
lua_shared_dict webstats_cache 512m;
lua_need_request_body off;
include {$SERVER_APP}/lua/webstats_log.lua;
log_by_lua_file {$SERVER_APP}/lua/webstats_log.lua;
+52 -5
View File
@@ -226,6 +226,14 @@ def makeSiteConfig():
return data
def contentReplace(content):
root_dir = mw.getServerDir()
service_path = root_dir + "/webstats"
content = content.replace('{$SERVER_APP}', service_path)
content = content.replace('{$ROOT_PATH}', root_dir)
return content
def initDreplace():
service_path = getServerDir()
@@ -236,8 +244,7 @@ def initDreplace():
path_tpl = getPluginDir() + '/conf/webstats.conf'
if not os.path.exists(path):
content = mw.readFile(path_tpl)
content = content.replace('{$SERVER_APP}', service_path)
content = content.replace('{$ROOT_PATH}', mw.getServerDir())
content = contentReplace(content)
mw.writeFile(path, content)
# 已经安装的
@@ -285,6 +292,7 @@ def start():
import tool_task
tool_task.createBgTask()
makeOpDstRunLua()
# issues:326
luaRestart()
return 'ok'
@@ -299,6 +307,7 @@ def stop():
tool_task.removeBgTask()
luaRestart()
makeOpDstStopLua()
return 'ok'
@@ -320,11 +329,48 @@ def reload():
loadLuaFileReload(fl)
loadDebugLogFile()
makeOpDstRunLua()
luaRestart()
# 配置重写
path = luaConf()
path_tpl = getPluginDir() + '/conf/webstats.conf'
content = mw.readFile(path_tpl)
content = contentReplace(content)
mw.writeFile(path, content)
return 'ok'
def makeOpDstRunLua(conf_reload=False):
root_worker_dir = mw.getServerDir() + '/web_conf/nginx/lua/init_worker_by_lua_file'
path = getServerDir()
path_tpl = getPluginDir()
worker_dst = root_worker_dir + "/webstats_init_worker.lua"
if not os.path.exists(worker_dst) or conf_reload:
worker_dst_tpl = path_tpl + "/lua/webstats_init_worker.lua"
content = mw.readFile(worker_dst_tpl)
content = contentReplace(content)
mw.writeFile(worker_dst, content)
mw.opLuaMakeAll()
return True
def makeOpDstStopLua():
root_worker_dir = mw.getServerDir() + '/web_conf/nginx/lua/init_worker_by_lua_file'
path = getServerDir()
path_tpl = getPluginDir()
worker_dst = root_worker_dir + "/webstats_init_worker.lua"
if os.path.exists(worker_dst):
os.remove(worker_dst)
mw.opLuaMakeAll()
return True
def getGlobalConf():
conf = getConf()
content = mw.readFile(conf)
@@ -709,7 +755,7 @@ def attacHistoryLogHack(conn, site_name, query_date='today'):
def getLogsList():
args = getArgs()
check = checkArgs(args, ['page', 'page_size','site', 'method',
'status_code', 'spider_type', 'request_time', 'query_date', 'search_uri'])
'status_code', 'spider_type', 'request_time','query_date', 'search_uri'])
if not check[0]:
return check[1]
@@ -727,12 +773,13 @@ def getLogsList():
referer = args['referer']
referer_url = args['referer_url']
ip = args['ip']
# scheme = args['scheme']
setDefaultSite(domain)
limit = str(page_size) + ' offset ' + str(page_size * (page - 1))
conn = pSqliteDb('web_logs', domain)
field = 'time,ip,domain,server_name,method,is_spider,protocol,status_code,request_headers,ip_list,client_port,body_length,user_agent,referer,request_time,uri,body_length'
field = 'time,scheme,ip,domain,server_name,method,is_spider,protocol,status_code,request_headers,ip_list,client_port,body_length,user_agent,referer,request_time,uri,body_length'
condition = ''
conn = conn.field(field)
conn = conn.where("1=1", ())
@@ -852,7 +899,7 @@ def getLogsErrorList():
limit = str(page_size) + ' offset ' + str(page_size * (page - 1))
conn = pSqliteDb('web_logs', domain)
field = 'time,ip,domain,server_name,method,protocol,status_code,ip_list,client_port,body_length,user_agent,referer,request_time,uri,body_length'
field = 'time,scheme,ip,domain,server_name,method,protocol,status_code,ip_list,client_port,body_length,user_agent,referer,request_time,uri,body_length'
conn = conn.field(field)
conn = conn.where("1=1", ())
+2 -1
View File
@@ -90,9 +90,10 @@ Install_App()
BREW_DIR=`which brew`
BREW_DIR=${BREW_DIR/\/bin\/brew/}
echo "BREW_DIR:"${BREW_DIR}
LIB_SQLITE_DIR=/opt/homebrew/opt/sqlite
find_cfg=`cat Makefile | grep 'SQLITE_DIR'`
if [ "$find_cfg" == "" ];then
LIB_SQLITE_DIR=`brew info sqlite | grep ${BREW_DIR}/Cellar/sqlite | cut -d \ -f 1 | awk 'END {print}'`
# LIB_SQLITE_DIR=`brew info sqlite | grep /opt/homebrew/opt/sqlite | cut -d \ -f 1 | awk 'END {print}'`
echo "LIB_SQLITE_DIR:"${LIB_SQLITE_DIR}
sed -i $BAK "s#\$(ROCKSPEC)#\$(ROCKSPEC) SQLITE_DIR=${LIB_SQLITE_DIR}#g" Makefile
fi
+12 -5
View File
@@ -2058,6 +2058,9 @@ function wsTableErrorLogRequest(page){
$(".tablescroll .details").click(function(){
var index = $(this).attr('data-id');
var res = data[index];
var url = res.scheme+"://"+res.domain+res.uri;
var url_html = "<a class='btlink' href='"+url+"' target='_blank'>"+url+"</a>";
layer.open({
type: 1,
title: "【"+res.domain + "】详情信息",
@@ -2072,8 +2075,8 @@ function wsTableErrorLogRequest(page){
</tbody></table></div>\
<div><b style="margin-left:10px">协议</b></div>\
<div class="lib-con mt10"><div class="divpre">' + res.protocol + '</div></div>\
<div><b style="margin-left:10px">URL</b></div>\
<div class="lib-con mt10"><div class="divpre">' + $('<div ></div>').text(res.uri).html() + '</div></div>\
<div><b style="margin-left:10px">URL地址</b></div>\
<div class="lib-con mt10"><div class="divpre">' + url_html + '</div></div>\
<div><b style="margin-left:10px">完整IP列表</b></div>\
<div class="lib-con mt10"><div class="divpre" style="max-height: 66px;">' + $('<div ></div>').text(res.ip_list).html() + '</div></div>\
<div><b style="margin-left:10px">来路</b></div>\
@@ -2314,6 +2317,10 @@ function wsTableLogRequest(page){
$(".tablescroll .details").click(function(){
var index = $(this).attr('data-id');
var res = data[index];
var url = res.scheme+"://"+res.domain+res.uri;
var url_html = "<a class='btlink' href='"+url+"' target='_blank'>"+url+"</a>";
// console.log(url_html);
// console.log(res);
layer.open({
type: 1,
title: "【"+res.domain + "】详情信息",
@@ -2328,10 +2335,10 @@ function wsTableLogRequest(page){
</tbody></table></div>\
<div><b style="margin-left:10px">协议</b></div>\
<div class="lib-con mt10"><div class="divpre">' + res.protocol + '</div></div>\
<div><b style="margin-left:10px">URL</b></div>\
<div class="lib-con mt10"><div class="divpre">' + $('<div></div>').text(res.uri).html() + '</div></div>\
<div><b style="margin-left:10px">URL地址</b></div>\
<div class="lib-con mt10"><div class="divpre">' + (url_html) + '</div></div>\
<div><b style="margin-left:10px">完整IP列表</b></div>\
<div class="lib-con mt10"><div class="divpre" style="max-height: 66px;">' + $('<div ></div>').text(res.ip_list).html() + '</div></div>\
<div class="lib-con mt10"><div class="divpre" style="max-height: 66px;">' + $('<div></div>').text(res.ip_list).html() + '</div></div>\
<div><b style="margin-left:10px">来路</b></div>\
<div class="lib-con mt10"><div class="divpre">' + $('<div></div>').text(res.referer == null ?'None':res.referer).html() + '</div></div>\
<div><b style="margin-left:10px">User-Agent</b></div>\
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,14 @@
-- -- 添加 Lua 模块搜索路径
local cpath = "{$SERVER_APP}/lua/"
if not package.cpath:find(cpath) then
package.cpath = cpath .. "?.so;" .. package.cpath
end
if not package.path:find(cpath) then
package.path = cpath .. "?.lua;" .. package.path
end
local app_dir = "{$SERVER_APP}"
local __C = require "webstats_common"
local C = __C:getInstance()
C:setAppDir(app_dir)
C:start_cron()
+272 -633
View File
@@ -1,667 +1,306 @@
log_by_lua_block {
--[[
webstats_log.lua - WebStats 日志采集模块
=========================================
本模块在 Nginx 的 log_by_lua_file 阶段执行,负责:
- 采集请求日志数据
- 过滤不需要统计的请求
- 识别爬虫和客户端类型
- 计算 PV/UV/IP 等指标
- 将日志数据发送到共享内存队列
执行时机:每次请求完成后(log_by_lua_file 阶段)
注意:log_by_lua* 上下文中部分 API 不可用,需使用 ngx.var.* 变量替代
]]
local cpath = "{$SERVER_APP}/lua/"
if not package.cpath:find(cpath) then
package.cpath = cpath .. "?.so;" .. package.cpath
-- -- 添加 Lua 模块搜索路径
local cpath = "{$SERVER_APP}/lua/"
if not package.cpath:find(cpath) then
package.cpath = cpath .. "?.so;" .. package.cpath
end
if not package.path:find(cpath) then
package.path = cpath .. "?.lua;" .. package.path
end
-- 调试模式开关
local debug_mode = true
local app_dir = "{$SERVER_APP}"
local function run_app()
local __C = require "webstats_common"
local C = __C:getInstance()
C:setAppDir(app_dir)
local json = require "cjson"
local config = require "webstats_config"
local sites = require "webstats_sites"
local server_name = C:get_sn(ngx.var.server_name)
local host = ngx.var.host
local http_host = ngx.var.http_host
if http_host then
local port_start = string.find(http_host, ":", 1, true)
if port_start then
local port = string.sub(http_host, port_start + 1)
host = host .. ":" .. port
end
end
if not package.path:find(cpath) then
package.path = cpath .. "?.lua;" .. package.path
end
local ver = '0.2.4'
local debug_mode = true
C:setConfData(config, sites)
local auto_config = C:setInputSn(server_name)
local __C = require "webstats_common"
local C = __C:getInstance()
-- 在 log_by_lua* 上下文中使用 ngx.var 替代不可用的 API
local method = ngx.var.request_method
local user_agent = ngx.var.http_user_agent
local x_forwarded_for = ngx.var.http_x_forwarded_for
local referer = ngx.var.http_referer
-- cache start ---
local cache = ngx.shared.mw_total
local function cache_set(server_name, id ,key, val)
local line_kv = "log_kv_"..server_name..'_'..id.."_"..key
-- cache:set(line_kv, val)
cache:set(line_kv, val)
end
local cache = ngx.shared.webstats_cache
local queue = ngx.shared.webstats_queue
local total_key = "log_kv_total"
local function cache_clear(server_name, id, key)
local line_kv = "log_kv_"..server_name..'_'..id.."_"..key
cache:delete(line_kv)
end
local status_codes_to_log = {
["400"] = true, ["401"] = true, ["402"] = true, ["403"] = true, ["404"] = true,
["405"] = true, ["406"] = true, ["407"] = true, ["408"] = true, ["409"] = true,
["410"] = true, ["411"] = true, ["412"] = true, ["413"] = true, ["414"] = true,
["415"] = true, ["416"] = true, ["417"] = true, ["418"] = true, ["421"] = true,
["422"] = true, ["423"] = true, ["424"] = true, ["425"] = true, ["426"] = true,
["449"] = true, ["451"] = true, ["499"] = true, ["500"] = true, ["501"] = true,
["502"] = true, ["503"] = true, ["504"] = true, ["505"] = true, ["506"] = true,
["507"] = true, ["509"] = true, ["510"] = true
}
local function cache_get(server_name, id, key)
local line_kv = "log_kv_"..server_name..'_'..id.."_"..key
local value = cache:get(line_kv)
return value
end
local http_methods = {["get"] = true, ["post"] = true, ["put"] = true, ["patch"] = true, ["delete"] = true}
local function load_global_exclude_ip()
local load_key = "global_exclude_ip_load"
local global_exclude_ip = auto_config["exclude_ip"]
if global_exclude_ip then
for _, _ip in pairs(global_exclude_ip) do
if not cache:get("global_exclude_ip_" .. _ip) then
cache:set("global_exclude_ip_" .. _ip, true)
end
end
end
cache:set(load_key, true)
end
-- cache end ---
local function load_exclude_ip(input_server_name)
local load_key = input_server_name .. "_exclude_ip_load"
local site_config = config[input_server_name]
-- domain config is import
local db = nil
local json = require "cjson"
local sqlite3 = require "lsqlite3"
local config = require "webstats_config"
local sites = require "webstats_sites"
local site_exclude_ip = nil
if site_config then
site_exclude_ip = site_config["exclude_ip"]
end
-- string.gsub(C:get_sn(ngx.var.server_name),'_','.')
local server_name = C:get_sn(ngx.var.server_name)
if site_exclude_ip then
for _, _ip in pairs(site_exclude_ip) do
cache:set(input_server_name .. "_exclude_ip_" .. _ip, true)
end
end
cache:set(load_key, true)
return true
end
C:setConfData(config, sites)
local function filter_status()
if not auto_config['exclude_status'] then return false end
local the_status = tostring(ngx.status)
for _, v in ipairs(auto_config['exclude_status']) do
if the_status == v then
return true
end
end
return false
end
local auto_config = C:setInputSn(server_name)
local function exclude_extension()
local uri = ngx.var.uri
if not uri then return false end
local exclude_ext = auto_config['exclude_extension']
if not exclude_ext then return false end
local lower_uri = string.lower(uri)
for _, ext in ipairs(exclude_ext) do
if string.find(lower_uri, "." .. ext .. "$", 1, true) then
return true
end
end
return false
end
local request_header = ngx.req.get_headers()
local method = ngx.req.get_method()
local excluded = false
local function exclude_url()
local request_uri = ngx.var.request_uri
if not request_uri then return false end
local url_conf = auto_config['exclude_url']
if not url_conf then return false end
local the_uri = string.sub(request_uri, 2)
for _, conf in ipairs(url_conf) do
local mode = conf["mode"]
local url = conf["url"]
if mode == "regular" then
if ngx.re.find(the_uri, url, "ijo") then
return true
end
else
if the_uri == url then
return true
end
end
end
return false
end
local day = os.date("%d")
local number_day = tonumber(day)
local day_column = "day"..number_day
local flow_column = "flow"..number_day
local spider_column = "spider_flow"..number_day
--- default common var end ---
local function exclude_ip(input_server_name, ip)
local site_config = config[input_server_name]
if site_config then
local server_exclude_ips = site_config["exclude_ip"]
if server_exclude_ips then
for _, _ip in pairs(server_exclude_ips) do
if cache:get(input_server_name .. "_exclude_ip_" .. ip) then
return true
end
break
end
end
end
return cache:get("global_exclude_ip_" .. ip) ~= nil
end
local function init_var()
return true
end
local function cache_logs(input_sn)
local new_id = C:get_last_id(input_sn)
local ip = C:get_client_ip()
local excluded = filter_status() or exclude_extension() or exclude_url() or exclude_ip(input_sn, ip)
--------------------- exclude_func start --------------------------
local function load_global_exclude_ip()
local load_key = "global_exclude_ip_load"
-- update global exclude ip
local global_exclude_ip = auto_config["exclude_ip"]
if global_exclude_ip then
for i, _ip in pairs(global_exclude_ip)
do
-- global
-- D("set global exclude ip: ".._ip)
if not cache:get("global_exclude_ip_".._ip) then
cache:set("global_exclude_ip_".._ip, true)
end
end
end
-- set tag
cache:set(load_key, true)
end
local ip_list = x_forwarded_for
if ip and not ip_list then
ip_list = ip
end
local function load_exclude_ip(input_server_name)
local load_key = input_server_name .. "_exclude_ip_load"
local site_config = config[input_server_name]
local site_exclude_ip = nil
if site_config then
site_exclude_ip = site_config["exclude_ip"]
end
-- update server_name exclude ip
if site_exclude_ip then
for i, _ip in pairs(site_exclude_ip)
do
cache:set(input_server_name .. "_exclude_ip_".._ip, true)
end
end
-- set tag
cache:set(load_key, true)
return true
end
local function filter_status()
if not auto_config['exclude_status'] then return false end
local the_status = tostring(ngx.status)
for _,v in ipairs(auto_config['exclude_status'])
do
if the_status == v then
return true
end
end
return false
end
local function exclude_extension()
if not ngx.var.uri then return false end
if not auto_config['exclude_extension'] then return false end
for _,v in ipairs(auto_config['exclude_extension'])
do
if ngx.re.find(ngx.var.uri,"[.]"..v.."$",'ijo') then
return true
end
end
return false
end
local function exclude_url()
if not ngx.var.uri then return false end
if not ngx.var.request_uri then return false end
if not auto_config['exclude_url'] then return false end
local the_uri = string.sub(ngx.var.request_uri, 2)
local url_conf = auto_config["exclude_url"]
for i,conf in ipairs(url_conf)
do
local mode = conf["mode"]
local url = conf["url"]
if mode == "regular" then
if ngx.re.find(the_uri, url, "ijo") then
return true
end
else
if the_uri == url then
return true
end
end
end
return false
end
local function exclude_ip(input_server_name, ip)
-- 排除IP匹配,分网站单独的配置和全局配置两种方式
local site_config = config[input_server_name]
local server_exclude_ips = nil
local check_server_exclude_ip = false
if site_config then
server_exclude_ips = site_config["exclude_ip"]
if not server_exclude_ips then
return false
end
for k, _ip in pairs(server_exclude_ips)
do
check_server_exclude_ip = true
break
end
end
-- D("server[" ..input_server_name.."]check exclude ip : "..tostring(check_server_exclude_ip))
if check_server_exclude_ip then
if cache:get(input_server_name .. "_exclude_ip_"..ip) then
-- D("-Exclude server ip:"..ip)
return true
end
else
if cache:get("global_exclude_ip_"..ip) then
-- D("*Excluded global ip:"..ip)
return true
end
end
return false
end
--------------------- exclude_func end ---------------------------
local function cache_logs_old(server_name)
-- make new id
local new_id = C:get_last_id(server_name)
local excluded = false
local ip = C:get_client_ip()
excluded = filter_status() or exclude_extension() or exclude_url() or exclude_ip(server_name, ip)
local ip_list = request_header["x-forwarded-for"]
if ip and not ip_list then
ip_list = ip
end
local remote_addr = ngx.var.remote_addr
if not string.find(ip_list, remote_addr) then
if remote_addr then
ip_list = ip_list .. "," .. remote_addr
end
end
-- local request_time = ngx.var.request_time
local request_time = C:get_request_time()
local client_port = ngx.var.remote_port
local real_server_name = ngx.var.server_name
local uri = ngx.var.uri
local status_code = ngx.status
local protocol = ngx.var.server_protocol
local request_uri = ngx.var.request_uri
local time_key = C:get_store_key()
local method = method
local body_length = C:get_length()
local domain = C:get_domain()
local referer = ngx.var.http_referer
local kv = {
id=new_id,
time_key=time_key,
time=ngx.time(),
ip=ip,
domain=domain,
server_name=server_name,
real_server_name=real_server_name,
method=method,
status_code=status_code,
uri=uri,
request_uri=request_uri,
body_length=body_length,
referer=referer,
user_agent=request_header['user-agent'],
protocol=protocol,
is_spider=0,
request_time=request_time,
excluded=excluded,
request_headers='',
ip_list=ip_list,
client_port=client_port
}
local request_stat_fields = "req=req+1,length=length+"..body_length
local spider_stat_fields = "x"
local client_stat_fields = "x"
if not excluded then
if status_code == 500 or (method=="POST" and config["record_post_args"] == true) or (status_code==403 and config["record_get_403_args"] == true) then
local data = ""
local ok, err = pcall(function() data = C:get_http_origin() end)
if ok and not err then
kv["request_headers"] = data
end
end
if ngx.re.find("500,501,502,503,504,505,506,507,509,510,400,401,402,403,404,405,406,407,408,409,410,411,412,413,414,415,416,417,418,421,422,423,424,425,426,449,451,499", tostring(status_code), "jo") then
local field = "status_"..status_code
request_stat_fields = request_stat_fields .. ","..field.."="..field.."+1"
end
local lower_method = string.lower(method)
if ngx.re.find("get,post,put,patch,delete", lower_method, "ijo") then
local field = "http_"..lower_method
request_stat_fields = request_stat_fields .. ","..field.."="..field.."+1"
end
local ipc = 0
local pvc = 0
local uvc = 0
local is_spider, request_spider, spider_index = C:match_spider(kv['user_agent'])
if not is_spider then
client_stat_fields = C:match_client(kv['user_agent'])
if not client_stat_fields or #client_stat_fields == 0 then
client_stat_fields = request_stat_fields..",other=other+1"
end
pvc, uvc = C:statistics_request(ip, is_spider,body_length)
ipc = C:statistics_ipc(server_name,ip)
else
kv["is_spider"] = spider_index
local field = "spider"
spider_stat_fields = request_spider.."="..request_spider.."+"..1
request_stat_fields = request_stat_fields .. ","..field.."="..field.."+"..1
end
if ipc > 0 then
request_stat_fields = request_stat_fields..",ip=ip+1"
end
if uvc > 0 then
request_stat_fields = request_stat_fields..",uv=uv+1"
end
if pvc > 0 then
request_stat_fields = request_stat_fields..",pv=pv+1"
end
end
local stat_fields = request_stat_fields..";"..client_stat_fields..";"..spider_stat_fields
cache_set(server_name, new_id, "stat_fields", stat_fields)
cache_set(server_name, new_id, "log_kv", json.encode(kv))
end
local function cache_logs(input_sn)
-- make new id
local new_id = C:get_last_id(input_sn)
local excluded = false
local ip = C:get_client_ip()
excluded = filter_status() or exclude_extension() or exclude_url() or exclude_ip(input_sn, ip)
local ip_list = request_header["x-forwarded-for"]
if ip and not ip_list then
ip_list = ip
end
local remote_addr = ngx.var.remote_addr
-- 修复反向代理代过来的数据
if "table" == type(ip_list) then
local remote_addr = ngx.var.remote_addr
if "table" == type(ip_list) then
ip_list = json.encode(ip_list)
end
if not string.find(ip_list, remote_addr) then
if remote_addr then
ip_list = ip_list .. "," .. remote_addr
end
end
if remote_addr and not string.find(ip_list, remote_addr, 1, true) then
ip_list = ip_list .. "," .. remote_addr
end
-- local request_time = ngx.var.request_time
local request_time = C:get_request_time()
local client_port = ngx.var.remote_port
local real_server_name = input_sn
local uri = tostring(ngx.var.uri)
local status_code = ngx.status
local protocol = ngx.var.server_protocol
local request_uri = ngx.var.request_uri
local time_key = C:get_store_key()
local method = method
local body_length = C:get_length()
local domain = C:get_domain()
local referer = ngx.var.http_referer
local request_time = C:get_request_time()
local client_port = ngx.var.remote_port
local uri = tostring(ngx.var.uri)
local status_code = ngx.status
local protocol = ngx.var.server_protocol
local request_uri = ngx.var.request_uri
local body_length = C:get_length()
local domain = host or "unknown"
local forwarded_proto = ngx.var.http_x_forwarded_proto or ngx.var.http_x_forwarded_protocol or ngx.var.http_x_scheme or ""
local http_protocol = forwarded_proto ~= "" and string.lower(forwarded_proto) or (ngx.var.scheme or "http")
local kv = {
id=new_id,
time_key=time_key,
time=ngx.time(),
ip=ip,
domain=domain,
server_name=input_sn,
real_server_name=real_server_name,
method=method,
status_code=status_code,
uri=uri,
request_uri=request_uri,
body_length=body_length,
referer=referer,
user_agent=request_header['user-agent'],
protocol=protocol,
is_spider=0,
request_time=request_time,
excluded=excluded,
request_headers='',
ip_list=ip_list,
client_port=client_port
}
local kv = {
id = new_id,
time_key = os.date("%Y%m%d%H", ngx.time()),
time = ngx.time(),
ip = ip,
scheme = http_protocol,
domain = domain,
server_name = input_sn,
real_server_name = input_sn,
method = method,
status_code = status_code,
uri = uri,
request_uri = request_uri,
body_length = body_length,
referer = referer,
user_agent = user_agent,
protocol = protocol,
is_spider = 0,
request_time = request_time,
excluded = excluded,
request_headers = '',
ip_list = ip_list,
client_port = client_port
}
-- C:D(json.encode(kv))
local request_stat_fields = {req=1,length=body_length}
local request_stat_fields = {req = 1, length = body_length}
local spider_stat_fields = {}
local client_stat_fields = {}
local spider_stat_fields = {}
local client_stat_fields = {}
if not excluded then
if status_code == 500 or (method == "POST" and config['global']["record_post_args"] == true) or (status_code == 403 and config['global']["record_get_403_args"] == true) then
kv["request_headers"] = json.encode({
user_agent = user_agent,
referer = referer,
host = host
})
end
if not excluded then
if status_code == 500 or (method=="POST" and config['global']["record_post_args"] == true) or (status_code==403 and config['global']["record_get_403_args"] == true) then
local data = ""
local ok, err = pcall(function() data = C:get_http_origin() end)
if ok and not err then
kv["request_headers"] = data
else
C:D("debug request_headers error:"..tostring(err))
end
end
if status_codes_to_log[tostring(status_code)] then
request_stat_fields["status_" .. status_code] = 1
end
if ngx.re.find("500,501,502,503,504,505,506,507,509,510,400,401,402,403,404,405,406,407,408,409,410,411,412,413,414,415,416,417,418,421,422,423,424,425,426,449,451,499", tostring(status_code), "jo") then
local field = "status_"..status_code
request_stat_fields[field] = 1
end
local lower_method = method and string.lower(method) or ""
if lower_method ~= "" and http_methods[lower_method] then
request_stat_fields["http_" .. lower_method] = 1
end
-- D("method:"..method)
local lower_method = string.lower(method)
if ngx.re.find("get,post,put,patch,delete", lower_method, "ijo") then
local field = "http_"..lower_method
request_stat_fields[field] = 1
end
local is_spider, request_spider, spider_index = C:match_spider(user_agent)
if not is_spider then
client_stat_fields = C:match_client_arr(user_agent)
local pvc, uvc = C:statistics_request(ip, is_spider, body_length)
local ipc = C:statistics_ipc(input_sn, ip)
if ipc > 0 then request_stat_fields["ip"] = 1 end
if uvc > 0 then request_stat_fields["uv"] = 1 end
if pvc > 0 then request_stat_fields["pv"] = 1 end
else
kv["is_spider"] = spider_index
spider_stat_fields[request_spider] = 1
request_stat_fields["spider"] = 1
end
end
local data = {
server_name = input_sn,
stat_fields = {
request_stat_fields = request_stat_fields,
client_stat_fields = client_stat_fields,
spider_stat_fields = spider_stat_fields,
},
log_kv = kv,
}
local ipc = 0
local pvc = 0
local uvc = 0
local len, err, forcible = queue:rpush(total_key, json.encode(data))
if not len then
C:D("webstats rpush failed: " .. tostring(err or "unknown")
.. ", forcible=" .. tostring(forcible) .. ", queue=" .. total_key
.. ", queue_free=" .. tostring(queue:free_space())
.. ", cache_free=" .. tostring(cache:free_space()))
end
end
local is_spider, request_spider, spider_index = C:match_spider(kv['user_agent'])
if not is_spider then
-- C:D("webstats_log run_app start, server_name=" .. tostring(server_name))
-- C:D(tostring(total_key) ..":" .. tostring(ngx.shared.webstats_queue:llen(total_key)))
load_global_exclude_ip()
load_exclude_ip(server_name)
cache_logs(server_name)
-- C:D("webstats_log run_app end")
end
client_stat_fields = C:match_client_arr(kv['user_agent'])
pvc, uvc = C:statistics_request(ip, is_spider,body_length)
ipc = C:statistics_ipc(input_sn,ip)
else
kv["is_spider"] = spider_index
local field = "spider"
spider_stat_fields[request_spider] = 1
request_stat_fields[field] = 1
end
if ipc > 0 then
request_stat_fields["ip"] = 1
end
if uvc > 0 then
request_stat_fields["uv"] = 1
end
if pvc > 0 then
request_stat_fields["pv"] = 1
end
end
local stat_fields = {
request_stat_fields=request_stat_fields,
client_stat_fields=client_stat_fields,
spider_stat_fields=spider_stat_fields,
}
local data = {
server_name=input_sn,
stat_fields=stat_fields,
log_kv=kv,
}
local push_data = json.encode(data)
-- C:D(json.encode(push_data))
local key = C:getTotalKey()
ngx.shared.mw_total:rpush(key, push_data)
end
local function store_logs_line(db, stmt, input_server_name, lineno)
local logvalue = cache_get(input_server_name, lineno, "log_kv")
if not logvalue then return false end
local logline = json.decode(logvalue)
local time = logline["time"]
local id = logline["id"]
local protocol = logline["protocol"]
local client_port = logline["client_port"]
local status_code = logline["status_code"]
local uri = logline["uri"]
local request_uri = logline["request_uri"]
local method = logline["method"]
local body_length = logline["body_length"]
local referer = logline["referer"]
local ip = logline["ip"]
local ip_list = logline["ip_list"]
local request_time = logline["request_time"]
local is_spider = logline["is_spider"]
local domain = logline["domain"]
local server_name = logline["server_name"]
local user_agent = logline["user_agent"]
local request_headers = logline["request_headers"]
local excluded = logline["excluded"]
local request_stat_fields = nil
local client_stat_fields = nil
local spider_stat_fields = nil
local stat_fields = cache_get(input_server_name, id, "stat_fields")
if stat_fields == nil then
-- D("Log stat fields is nil.")
-- D("Logdata:"..logvalue)
else
stat_fields = C:split(stat_fields, ";")
request_stat_fields = stat_fields[1]
client_stat_fields = stat_fields[2]
spider_stat_fields = stat_fields[3]
if "x" == client_stat_fields then
client_stat_fields = nil
end
if "x" == spider_stat_fields then
spider_stat_fields = nil
end
end
local time_key = logline["time_key"]
if not excluded then
stmt:bind_names{
time=time,
ip=ip,
domain=domain,
server_name=server_name,
method=method,
status_code=status_code,
uri=request_uri,
body_length=body_length,
referer=referer,
user_agent=user_agent,
protocol=protocol,
request_time=request_time,
is_spider=is_spider,
request_headers=request_headers,
ip_list=ip_list,
client_port=client_port,
}
local res, err = stmt:step()
if tostring(res) == "5" then
-- D("step res:"..tostring(res))
-- D("step err:"..tostring(err))
-- D("the step database connection is busy, so it will be stored later.")
return false
end
stmt:reset()
-- D("store_logs_line ok")
C:update_stat( db, "client_stat", time_key, client_stat_fields)
C:update_stat( db, "spider_stat", time_key, spider_stat_fields)
-- C:D("stat ok")
-- only count non spider requests
local ok, err = C:statistics_uri(db, request_uri, ngx.md5(request_uri), body_length)
local ok, err = C:statistics_ip(db, ip, body_length)
end
C:update_stat( db, "request_stat", time_key, request_stat_fields)
return true
end
local function store_logs(input_sn)
if C:is_migrating(input_sn) == true then
-- D("migrating...")
return
end
local last_insert_id_key = input_sn.."_last_id"
local store_start_id_key = input_sn.."_store_start"
local last_id = cache:get(last_insert_id_key)
local store_start = cache:get(store_start_id_key)
if store_start == nil then
store_start = 1
end
local store_end = last_id
if store_end == nil then
store_end = 1
end
local worker_id = ngx.worker.id()
if C:is_working(input_sn) then
-- D("other workers are being stored, please store later.")
-- cache:delete(flush_data_key)
return true
end
C:lock_working(input_sn)
local log_dir = "{$SERVER_APP}/logs"
local db_path = log_dir .. '/' .. input_sn .. "/logs.db"
local db, err = sqlite3.open(db_path)
if tostring(err) ~= 'nil' then
C:D("sqlite3 open error:"..tostring(err))
return true
end
db:exec([[PRAGMA synchronous = 0]])
db:exec([[PRAGMA page_size = 4096]])
db:exec([[PRAGMA journal_mode = wal]])
db:exec([[PRAGMA journal_size_limit = 1073741824]])
local stmt2 = nil
if db ~= nil then
stmt2 = db:prepare[[INSERT INTO web_logs(
time, ip, domain, server_name, method, status_code, uri, body_length,
referer, user_agent, protocol, request_time, is_spider, request_headers, ip_list, client_port)
VALUES(:time, :ip, :domain, :server_name, :method, :status_code, :uri,
:body_length, :referer, :user_agent, :protocol, :request_time, :is_spider,
:request_headers, :ip_list, :client_port)]]
end
if db == nil or stmt2 == nil then
-- D("web data db error")
-- cache:set(storing_key, false)
if db and db:isopen() then
db:close()
end
return true
end
status, errorString = db:exec([[BEGIN TRANSACTION]])
C:clean_stats(db, input_sn)
if store_end >= store_start then
for i=store_start, store_end, 1 do
-- D("store_start:"..store_start..":store_end:".. store_end)
if store_logs_line(db, stmt2, input_sn, i) then
cache_clear(input_sn, i, "log_kv")
cache_clear(input_sn, i, "stat_fields")
end
end
end
local res, err = stmt2:finalize()
if tostring(res) == "5" then
C:D("Finalize res:"..tostring(res)..",Finalize err:"..tostring(err))
end
local now_date = os.date("*t")
local save_day = config['global']["save_day"]
local save_date_timestamp = os.time{year=now_date.year,
month=now_date.month, day=now_date.day-save_day, hour=0}
-- delete expire data
db:exec("DELETE FROM web_logs WHERE time<"..tostring(save_date_timestamp))
local res, err = db:execute([[COMMIT]])
if db and db:isopen() then
db:close()
end
cache:set(store_start_id_key, store_end+1)
C:unlock_working(input_sn)
end
local function run_app()
-- C:D("------------ debug start ------------")
init_var()
load_global_exclude_ip()
load_exclude_ip(server_name)
cache_logs(server_name)
-- C:cron()
-- cache_logs_old(server_name)
-- store_logs(server_name)
-- C:D("------------ debug end -------------")
end
local function run_app_ok()
if not debug_mode then return run_app() end
local presult, err = pcall( function() run_app() end)
if not presult then
C:D("debug error on :"..tostring(err))
return true
end
end
return run_app_ok()
}
local function run_app_ok()
-- if not debug_mode then return run_app() end
local presult, err = pcall(function() run_app() end)
if not presult then
C:D("debug error on :" .. tostring(err))
return true
end
end
return run_app_ok()
+153 -88
View File
@@ -5,6 +5,8 @@ import io
import os
import time
import json
import fcntl
import shutil
web_dir = os.getcwd() + "/web"
if os.path.exists(web_dir):
@@ -42,9 +44,7 @@ def getGlobalConf():
result = json.loads(content)
return result
def pSqliteDb(dbname='web_logs', site_name='unset', fn="logs"):
db_dir = getServerDir() + '/logs/' + site_name
if not os.path.exists(db_dir):
mw.execShell('mkdir -p ' + db_dir)
@@ -67,143 +67,208 @@ def pSqliteDb(dbname='web_logs', site_name='unset', fn="logs"):
conn.autoTextFactory()
# conn.text_factory = lambda x: str(x, encoding="utf-8", errors='ignore')
# conn.text_factory = lambda x: unicode(x, "utf-8", "ignore")
return conn
def batch_delete(conn, table, where_clause, batch_size=5000, pause_sec=0.05):
"""分批删除,缩短单次持锁时间,WAL 模式下可与 OpenResty 并发写入。"""
total = 0
while True:
sql = (
f"DELETE FROM {table} WHERE rowid IN "
f"(SELECT rowid FROM {table} WHERE {where_clause} LIMIT {batch_size})"
)
affected = conn.execute(sql)
if not isinstance(affected, int) or affected == 0:
break
total += affected
if pause_sec > 0:
time.sleep(pause_sec)
return total
def migrateSiteHotLogs(site_name, query_date):
print(site_name, query_date)
start_time = time.time()
print(f"[{site_name}] 开始迁移日志...")
migrating_flag = getServerDir() + "/logs/%s/migrating" % site_name
hot_db = getServerDir() + "/logs/%s/logs.db" % site_name
hot_db_tmp = getServerDir() + "/logs/%s/logs_tmp.db" % site_name
history_logs_db = getServerDir() + "/logs/%s/history_logs.db" % site_name
# 1. copy to tmp file
if not os.path.exists(hot_db):
print(f"[{site_name}] 热日志数据库不存在,跳过")
return mw.returnMsg(True, f"{site_name} logs not exist, skip")
# 检查是否正在迁移
if os.path.exists(migrating_flag):
print(f"[{site_name}] 正在迁移中,跳过")
return mw.returnMsg(True, f"{site_name} is migrating, skip")
todayTime = time.strftime('%Y-%m-%d 00:00:00', time.localtime())
todayUt = int(time.mktime(time.strptime(
todayTime, "%Y-%m-%d %H:%M:%S")))
# 1. 备份到临时文件(copy 期间短暂互斥,完成后立即解除)
try:
import shutil
print("coping {} to {} ...".format(hot_db, hot_db_tmp))
print(f"[{site_name}] 备份 {hot_db} -> {hot_db_tmp} ...")
mw.writeFile(migrating_flag, "yes")
time.sleep(3)
time.sleep(0.5)
copy_start = time.time()
# import shutil
shutil.copy(hot_db, hot_db_tmp)
# mw.fastCopy(hot_db, hot_db_tmp, 256 * 1024)
# mw.sendfile(hot_db,hot_db_tmp)
print(f"[{site_name}] 备份完成,耗时 {time.time() - copy_start:.2f}s")
if not os.path.exists(hot_db_tmp):
return mw.returnMsg(False, "migrating fail, copy tmp file!")
except:
return mw.returnMsg(False, "{} migrating fail.".format(site_name))
return mw.returnMsg(False, f"{site_name} migrating fail, copy tmp file!")
except Exception as e:
return mw.returnMsg(False, f"{site_name} migrating fail: {e}")
finally:
if os.path.exists(migrating_flag):
os.remove(migrating_flag)
# 2. 从临时备份中迁移热日志数据到历史日志
print("begin tmp to hot log data ...")
# 2. 从临时备份中迁移热日志数据到历史日志(读 logs_tmp,不阻塞 live 写入)
try:
print("history file: {}".format(history_logs_db))
logs_conn = pSqliteDb('web_log', site_name, 'logs_tmp')
history_logs_conn = pSqliteDb('web_log', site_name, 'history_logs')
hot_db_columns = logs_conn.originExecute(
"PRAGMA table_info([web_logs])")
_columns = ",".join([c[1] for c in hot_db_columns if c[1] != "id"])
query_start = 0
todayTime = time.strftime('%Y-%m-%d 00:00:00', time.localtime())
todayUt = int(time.mktime(time.strptime(
todayTime, "%Y-%m-%d %H:%M:%S")))
_columns = [c[1] for c in hot_db_columns if c[1] != "id"]
columns_str = ",".join(_columns)
placeholders = ",".join(["?"] * len(_columns))
logs_sql = "select {} from web_logs where time<{}".format(
_columns, todayUt)
logs_sql = f"select {columns_str} from web_logs where time<{todayUt}"
selector = logs_conn.originExecute(logs_sql)
log = selector.fetchone()
while log:
params = ""
for field in log:
if params:
params += ","
if field is None:
field = "\'\'"
elif type(field) == str:
field = "\'" + field.replace("\'", "\"") + "\'"
params += str(field)
insert_sql = "insert into web_logs(" + \
_columns + ") values(" + params + ")"
history_logs_conn.execute(insert_sql)
log = selector.fetchone()
print("sorting historical data, this action takes a long time...")
history_logs_conn.execute("VACUUM;")
# 批量插入配置
batch_size = 10000
batch_count = 0
total_count = 0
insert_sql = f"insert into web_logs({columns_str}) values({placeholders})"
while True:
logs = selector.fetchmany(batch_size)
if not logs:
break
batch_count += 1
total_count += len(logs)
# 使用原生 executemany 批量插入
history_logs_conn.executemany(insert_sql, logs)
history_logs_conn.commit()
if batch_count % 10 == 0:
elapsed = time.time() - start_time
print(f"[{site_name}] 已迁移 {total_count} 条记录, 耗时 {elapsed:.2f}s")
print(f"[{site_name}] 共迁移 {total_count} 条记录")
# 清理历史数据
gcfg = getGlobalConf()
save_day = gcfg['global']["save_day"]
print("delete historical data {} days ago...".format(save_day))
print(f"[{site_name}] 删除 {save_day} 天前的历史数据...")
time_now = time.localtime()
save_timestamp = time.mktime((time_now.tm_year, time_now.tm_mon, time_now.tm_mday - save_day, 0, 0, 0, 0, 0, 0))
delete_sql = "delete from web_logs where time <= {}".format(
save_timestamp)
print('delete history_logs')
print(delete_sql)
delete_sql = f"delete from web_logs where time <= {save_timestamp}"
history_logs_conn.execute(delete_sql)
history_logs_conn.commit()
# 3. delete merged data and clean up statistics
print("delete merged thermal data...")
mw.writeFile(migrating_flag, "yes")
history_logs_conn.execute("VACUUM;")
history_logs_conn.commit()
except Exception as e:
if os.path.exists(hot_db_tmp):
os.remove(hot_db_tmp)
print(f"[{site_name}] logs to history error: {e}")
return mw.returnMsg(False, f"{site_name} logs migrate error: {e}")
# 3. 分批删除已迁移的热日志并清理统计(不设 migrating 锁,不阻塞 OpenResty 写入)
try:
hot_db_conn = pSqliteDb('web_logs', site_name)
del_hot_log = "delete from web_logs where time<{}".format(todayUt)
print(del_hot_log)
r = hot_db_conn.execute(del_hot_log)
print("delete:", r)
print("deleting statistics over 180 days...")
hot_db_conn.execute("PRAGMA busy_timeout = 30000")
print(f"[{site_name}] 分批删除已迁移的热日志...")
deleted = batch_delete(hot_db_conn, 'web_logs', f"time<{todayUt}")
print(f"[{site_name}] 已删除 {deleted} 条热日志")
print(f"[{site_name}] 分批删除180天前的统计数据...")
save_time_key = time.strftime(
'%Y%m%d00', time.localtime(time.time() - 180 * 86400))
stat_where = f"time<='{save_time_key}'"
for stat_table in ('request_stat', 'spider_stat', 'client_stat', 'referer_stat'):
stat_deleted = batch_delete(hot_db_conn, stat_table, stat_where)
print(f"[{site_name}] {stat_table} 已删除 {stat_deleted} 条")
del_request_stat_sql = "delete from request_stat where time<={}".format(
save_time_key)
hot_db_conn.execute(del_request_stat_sql)
print(f"[{site_name}] 执行 WAL checkpoint...")
hot_db_conn.execute("PRAGMA wal_checkpoint(TRUNCATE)")
hot_db_conn.execute(
"delete from spider_stat where time<={}".format(save_time_key))
hot_db_conn.execute(
"delete from client_stat where time<={}".format(save_time_key))
hot_db_conn.execute(
"delete from referer_stat where time<={}".format(save_time_key))
hot_db_conn.commit()
print("clean up the hot database...")
hot_db_conn.execute("VACUUM;")
hot_db_conn.commit()
if os.path.exists(migrating_flag):
os.remove(migrating_flag)
except Exception as e:
if site_name:
print("{} logs to history error:{}".format(site_name, e))
else:
print("logs to history error:{}".format(e))
print(f"[{site_name}] delete hot logs error: {e}")
finally:
if os.path.exists(hot_db_tmp):
os.remove(hot_db_tmp)
if os.path.exists(hot_db_tmp+"-shm"):
os.remove(hot_db_tmp+"-shm")
if os.path.exists(hot_db_tmp+"-wal"):
os.remove(hot_db_tmp+"-wal")
print("{} logs migrate ok.".format(site_name))
elapsed = time.time() - start_time
print(f"[{site_name}] 日志迁移完成,耗时 {elapsed:.2f}s")
if not mw.isAppleSystem():
mw.execShell("chown -R www:www " + getServerDir())
mw.opWeb('restart')
return mw.returnMsg(True, "{} logs migrate ok".format(site_name))
return mw.returnMsg(True, f"{site_name} logs migrate ok")
def migrateHotLogs(query_date="today"):
print("begin migrate hot logs")
sites = mw.M('sites').field('name').order("add_time").select()
unset_site = {"name": "unset"}
sites.append(unset_site)
# 使用文件锁防止并发迁移
lock_file = getServerDir() + "/logs/migrate_hot_logs.lock"
lock_fd = None
# migrateSiteHotLogs('t1.cn', query_date)
try:
lock_fd = open(lock_file, 'w')
fcntl.flock(lock_fd.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB)
for site_info in sites:
# print(site_info['name'])
site_name = site_info["name"]
migrate_res = migrateSiteHotLogs(site_name, query_date)
if not migrate_res["status"]:
print(migrate_res["msg"])
print("end migrate hot logs")
print("开始迁移热日志...")
sites = mw.M('sites').field('name').order("add_time").select()
unset_site = {"name": "unset"}
sites.append(unset_site)
total_sites = len(sites)
success_count = 0
fail_count = 0
for i, site_info in enumerate(sites):
site_name = site_info["name"]
print(f"\n[{i+1}/{total_sites}] 处理站点: {site_name}")
migrate_res = migrateSiteHotLogs(site_name, query_date)
if migrate_res["status"]:
success_count += 1
else:
fail_count += 1
print(f"[{site_name}] 迁移失败: {migrate_res['msg']}")
print(f"\n迁移完成! 成功: {success_count}, 失败: {fail_count}")
return mw.returnMsg(True, f"logs migrate ok, success: {success_count}, fail: {fail_count}")
except BlockingIOError:
print("正在迁移中,跳过")
return mw.returnMsg(True, "正在迁移中,跳过")
except Exception as e:
print(f"migrateHotLogs error: {e}")
return mw.returnMsg(False, f"migrateHotLogs error: {e}")
finally:
if lock_fd:
try:
fcntl.flock(lock_fd.fileno(), fcntl.LOCK_UN)
lock_fd.close()
if os.path.exists(lock_file):
os.remove(lock_file)
except:
pass
+4 -3
View File
@@ -711,7 +711,7 @@ def get_logs_list(args):
start_time = time.time()
check = checkArgs(args, ['page', 'page_size','site', 'method',
'status_code', 'spider_type', 'request_time', 'request_size', 'query_date', 'search_uri'])
'status_code', 'spider_type', 'request_time','request_size', 'query_date', 'search_uri'])
if not check[0]:
return check[1]
@@ -729,12 +729,13 @@ def get_logs_list(args):
referer = args['referer']
referer_url = args['referer_url']
ip = args['ip']
# scheme = args['scheme']
setDefaultSite(domain)
limit = str(page_size) + ' offset ' + str(page_size * (page - 1))
conn = pSqliteDb('web_logs', domain)
field = 'time,ip,domain,server_name,method,is_spider,protocol,status_code,request_headers,ip_list,client_port,body_length,user_agent,referer,request_time,uri'
field = 'time,scheme,ip,domain,server_name,method,is_spider,protocol,status_code,request_headers,ip_list,client_port,body_length,user_agent,referer,request_time,uri'
condition = ''
conn = conn.field(field)
conn = conn.where("1=1", ())
@@ -857,7 +858,7 @@ def getLogsErrorList():
limit = str(page_size) + ' offset ' + str(page_size * (page - 1))
conn = pSqliteDb('web_logs', domain)
field = 'time,ip,domain,server_name,method,protocol,status_code,ip_list,client_port,body_length,user_agent,referer,request_time,uri'
field = 'time,scheme,ip,domain,server_name,method,protocol,status_code,ip_list,client_port,body_length,user_agent,referer,request_time,uri'
conn = conn.field(field)
conn = conn.where("1=1", ())
+3 -2
View File
@@ -22,7 +22,7 @@ Flask-SQLAlchemy>=2.5.1
pyOpenSSL>=26.0.0
cryptography>=48.0.1
configparser==5.2.0
python-engineio>=4.3.2
python-engineio>=4.13.2
python-socketio>=4.2.0
flask-socketio>=5.2.0
flask-sockets>=0.2.1
@@ -51,4 +51,5 @@ zstd
zstandard
geoip2
psycopg2-binary
docker
docker
telnetlib3
+6 -1
View File
@@ -213,10 +213,15 @@ apt install -y libwebp-dev
apt install -y lzma lzma-dev
apt install -y libunwind-dev
apt install -y libpcre3 libpcre3-dev
apt install -y libpcre2
apt install -y libpcre2-dev
apt install -y libpcre3
apt install -y libpcre3-dev
apt install -y openssl
apt install -y libssl-dev
apt install -y libargon2-dev
apt install -y libnuma-dev
apt install -y libpam0g-dev
apt install -y libmemcached-dev
apt install -y libsasl2-dev
+6 -1
View File
@@ -151,10 +151,15 @@ apt install -y libwebp-dev
apt install -y lzma lzma-dev
apt install -y libunwind-dev
apt install -y libpcre3 libpcre3-dev
apt install -y libpcre2
apt install -y libpcre2-dev
apt install -y libpcre3
apt install -y libpcre3-dev
apt install -y openssl
apt install -y libssl-dev
apt install -y libargon2-dev
apt install -y libnuma-dev
apt install -y libpam0g-dev
apt install -y libmemcached-dev
apt install -y libsasl2-dev
+1 -1
View File
@@ -19,7 +19,7 @@ psutil==5.9.1
chardet==3.0.4
flask-sqlalchemy==2.3.2
configparser==5.2.0
python-engineio==4.3.2
python-engineio==4.13.2
python-socketio>=4.2.0
flask-socketio==5.2.0
flask-sockets==0.2.1
+1 -1
View File
@@ -19,7 +19,7 @@ psutil==5.9.1
chardet==3.0.4
flask-sqlalchemy==2.3.2
configparser==5.2.0
python-engineio==4.3.2
python-engineio==4.13.2
python-socketio>=4.2.0
flask-socketio==5.2.0
flask-sockets==0.2.1
+1 -1
View File
@@ -19,7 +19,7 @@ psutil==5.9.1
chardet==3.0.4
flask-sqlalchemy==2.3.2
configparser==5.2.0
python-engineio==4.3.2
python-engineio==4.13.2
python-socketio>=4.2.0
flask-socketio==5.2.0
flask-sockets==0.2.1
+1 -1
View File
@@ -19,7 +19,7 @@ psutil==5.9.1
chardet==3.0.4
flask-sqlalchemy==2.3.2
configparser==5.2.0
python-engineio==4.3.2
python-engineio==4.13.2
python-socketio>=4.2.0
flask-socketio==5.2.0
flask-sockets==0.2.1
+2 -2
View File
@@ -53,8 +53,8 @@ app.config["COMPRESS_MIN_SIZE"] = 500 # 最小压缩大小
Compress(app)
# 缓存配置
cache = Cache(config={'CACHE_TYPE': 'simple'})
cache.init_app(app, config={'CACHE_TYPE': 'simple'})
cache = Cache(config={'CACHE_TYPE': 'SimpleCache'})
cache.init_app(app, config={'CACHE_TYPE': 'SimpleCache'})
# 静态文件配置
app.static_folder = "../static"
+21 -4
View File
@@ -42,17 +42,30 @@ class Sql():
__debug = False
def __init__(self):
self.__DB_FILE = getPanelDir()+'/data/panel.db'
self.__DB_FILE = mw.getPanelDir()+'/data/panel.db'
# self.__DB_FILE = mw.getPanelDataDir()+'/panel.db'
def __getConn(self):
# 取数据库对象
try:
if self.__DB_CONN == None:
self.__DB_CONN = sqlite3.connect(self.__DB_FILE)
self.__DB_CONN.text_factory = str
except Exception as ex:
print(getTracebackInfo())
return "error: " + str(ex)
raise
def close(self):
# 关闭数据库连接
if self.__DB_CONN is not None:
try:
self.__DB_CONN.close()
self.__DB_CONN = None
except Exception as ex:
pass
def __del__(self):
# 对象销毁时自动关闭连接
self.close()
def changeTextFactoryToBytes(self):
self.__DB_CONN.text_factory = bytes
@@ -335,9 +348,13 @@ class Sql():
except Exception as ex:
return "error: " + str(ex)
def commit(self):
def executemany(self, sql, args):
self.__DB_CONN.executemany(sql, args)
self.__close()
def commit(self):
self.__DB_CONN.commit()
self.__close()
def save(self, keys, param):
# 更新数据
+36 -1
View File
@@ -25,6 +25,7 @@ import subprocess
import glob
import base64
import re
import shutil
from random import Random
@@ -201,6 +202,10 @@ def getCommonFile():
}
return data
def getSysTTL():
f = "/proc/sys/net/ipv4/ip_default_ttl"
return readFile(f).strip()
def checkCert(certPath='ssl/certificate.pem'):
# 验证证书
openssl = '/usr/bin/openssl'
@@ -314,6 +319,35 @@ def toSize(size, middle='') -> str:
s = u
return str(round(size, 2)) + middle + u
def fastCopy(src, dst, buffer_size=256 * 1024): # 128MB 缓冲区
with open(src, 'rb') as fsrc:
with open(dst, 'wb') as fdst:
shutil.copyfileobj(fsrc, fdst, length=buffer_size)
# linux高效复制
def sendfile(src, dst):
if isAppleSystem():
try:
shutil.copyfile(src, dst)
return True
except Exception as e:
return False
try:
with open(src, 'rb') as fsrc, open(dst, 'wb') as fdst:
filesize = os.fstat(fsrc.fileno()).st_size
sent = os.sendfile(fdst.fileno(), fsrc.fileno(), 0, filesize)
if sent != filesize:
shutil.copyfile(src, dst)
return True
except (OSError, AttributeError) as e:
try:
shutil.copyfile(src, dst)
return True
except Exception as e2:
return False
def returnData(status, msg, data=None):
if data is None:
return {'status': status, 'msg': msg}
@@ -1418,7 +1452,8 @@ def getTriggerTaskLockFile():
def triggerTask():
lock_file = getTriggerTaskLockFile()
writeFile(lock_file, 'True')
t = writeFile(lock_file, 'True')
return t
def restartTask():
initd = getPanelDir() + '/scripts/init.d/mw'
+17 -9
View File
@@ -41,12 +41,10 @@ function getLogs(id){
title:"任务执行日志",
area: ['60%','500px'],
shadeClose:false,
btn:["清空","关闭"],
btn:['清空', "关闭", '刷新', '关闭自动刷新', '开启自动刷新'],
closeBtn:1,
end: function(){
if (reqTimer){
clearInterval(reqTimer);
}
},
content:'<div class="setchmod bt-form" style="padding:5px;">'
+'<pre id="crontab_log" style="overflow: auto; border: 0px none; line-height:23px;padding: 5px; margin: 0px; white-space: pre-wrap; height: 395px; background-color: rgb(51,51,51);color:#f1f1f1;border-radius:0px;font-family:"></pre>'
@@ -57,16 +55,26 @@ function getLogs(id){
+'</div>',
success:function(index,layer_index){
requestLogs(layer_index);
reqTimer = setInterval(function(){
requestLogs(layer_index);
},3000);
},
yes:function(index){
yes:function(index,layer_index){
clearInterval(reqTimer);
closeLogs(id);
layer.close(index);
},
btn3:function(index,layer_index){
requestLogs(layer_index);
return false;
},
btn4:function(index,layer_index){
clearInterval(reqTimer);
return false;
},
btn5:function(index,layer_index){
reqTimer = setInterval(function(){
requestLogs(layer_index);
},3000);
return false;
}
});
}
+4 -1
View File
@@ -147,7 +147,7 @@ def uncompress(sfile, dfile, path):
if suffix_gz == tar_gz:
extension = suffix_gz
if not extension in ['tar.gz', 'gz', 'zip', 'rar', '7z', 'xz','bz2']:
if not extension in ['tar.gz', 'tgz', 'gz', 'zip', 'rar', '7z', 'xz','bz2']:
return mw.returnData(False, '现在仅支持gz,zip,rar,7z,xz,bz2格式解压!')
if extension == 'rar' and not mw.checkBinExist('rar'):
@@ -165,6 +165,9 @@ def uncompress(sfile, dfile, path):
elif extension == 'tar.gz':
cmd += "&& tar -zxvf " + sfile + " -C " + dfile + " > " + tmps + " 2>&1 &"
mw.execShell(cmd)
elif extension == 'tgz':
cmd += "&& tar -zxvf " + sfile + " -C " + dfile + " > " + tmps + " 2>&1 &"
mw.execShell(cmd)
elif extension == 'gz':
cmd += "&& gunzip -k " + sfile + " > " + tmps + " 2>&1 &"
mw.execShell(cmd)
+16 -3
View File
@@ -73,11 +73,20 @@ class monitor:
return True
def getMonitorDay(self):
monitor_day = mw.M('option').field('name').where('name=?',('monitor_day',)).getField('value')
return int(monitor_day)
db = mw.M('option')
monitor_day = db.field('name').where('name=?',('monitor_day',)).getField('value')
db.close()
if monitor_day is None or monitor_day == '':
return 30
try:
return int(monitor_day)
except (ValueError, TypeError):
return 30
def isOnlyNetIoStats(self):
monitor_only_netio = mw.M('option').field('name').where('name=?',('monitor_only_netio',)).getField('value')
db = mw.M('option')
monitor_only_netio = db.field('name').where('name=?',('monitor_only_netio',)).getField('value')
db.close()
if monitor_only_netio == 'open':
return True
return False
@@ -165,18 +174,21 @@ class monitor:
cmd_objm = mw.M('cpuio').dbPos(mw.getPanelDataDir(),'system')
cmd_objm.add('pro,mem,addtime', cpu_mem_data)
cmd_objm.where("addtime<?", (deltime,)).delete()
cmd_objm.close()
# 网络数据入库
netio_data = (netio['up'] / 5, netio['down'] / 5, netio['upTotal'], netio['downTotal'], netio['downPackets'], netio['upPackets'], addtime)
network_objm = mw.M('network').dbPos(mw.getPanelDataDir(),'system')
network_objm.add('up,down,total_up,total_down,down_packets,up_packets,addtime', netio_data)
network_objm.where("addtime<?", (deltime,)).delete()
network_objm.close()
# 磁盘数据入库
disk_data = (diskio['read_count'], diskio['write_count'], diskio['read_bytes'], diskio['write_bytes'], diskio['read_time'], diskio['write_time'], addtime)
disk_objm = mw.M('diskio').dbPos(mw.getPanelDataDir(),'system')
disk_objm.add('read_count,write_count,read_bytes,write_bytes,read_time,write_time,addtime', disk_data)
disk_objm.where("addtime<?", (deltime,)).delete()
disk_objm.close()
# 负载数据入库
load_data = self.getLoadAverage()
@@ -186,6 +198,7 @@ class monitor:
load_objm = mw.M('load_average').dbPos(mw.getPanelDataDir(),'system')
load_objm.add('pro,one,five,fifteen,addtime', (lpro, load_data['one'], load_data['five'], load_data['fifteen'], addtime))
load_objm.where("addtime<?", (deltime,)).delete()
load_objm.close()
return True