From c705c282d1114c121b45ad7c3e3a4d095332126e Mon Sep 17 00:00:00 2001 From: ramondelee <62197872+ramondelee@users.noreply.github.com> Date: Tue, 16 Sep 2025 22:23:49 +0800 Subject: [PATCH 1/7] Update site.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 按ACME官方推荐配置更新huaweicloud和cloudflare的DNS-API配置,cloudflare更改为账户ID和可配置权限token。 --- web/utils/site.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web/utils/site.py b/web/utils/site.py index 8c3de2240..a21e1a987 100644 --- a/web/utils/site.py +++ b/web/utils/site.py @@ -1994,8 +1994,8 @@ location ^~ {from} {\n\ dnsapi_option = [ {"name":"none", "title":'手动解析', 'key':'', 'help':''}, {"name":"dns_ali", "title":'Aliyun', 'key':'Ali_Key:Ali_Secret', 'help':'阿里云控制台》用户头像》accesskeys按指引获取AccessKey/SecretKey'}, - {"name":"dns_huaweicloud", "title":'华为云', 'key':'HUAWEICLOUD_Username:HUAWEICLOUD_Password:HUAWEICLOUD_DomainName:HUAWEICLOUD_ProjectID:HUAWEICLOUD_AccessKey:HUAWEICLOUD_SecretKey'}, - {"name":"dns_cf", "title":'cloudflare', 'key':'CF_Key:CF_Email', 'help':'CloudFlare后台获取Global API Key'}, + {"name":"dns_huaweicloud", "title":'华为云', 'key':'HUAWEICLOUD_Username:HUAWEICLOUD_Password:HUAWEICLOUD_DomainName'}, + {"name":"dns_cf", "title":'Cloudflare', 'key':'CF_Token:CF_Account_ID', 'help':'CloudFlare后台获取Global API Key'}, {"name":"dns_dp", "title":'dnspod/国内', 'key':'DP_Id:DP_Key','help':'DnsPod后台》用户中心》安全设置,开启API Token'}, {"name":"dns_dpi", "title":'dnspod/国际', 'key':'DPI_Id:DPI_Key','help':'DnsPod后台》用户中心》安全设置,开启API Token'}, {"name":"dns_tencent", "title":"腾讯云DNS", 'key':'Tencent_SecretId:Tencent_SecretKey', 'help':'腾讯云后台获取通行证'}, From e7212ed506c314620161350709e5203d00a057fd Mon Sep 17 00:00:00 2001 From: dami Date: Wed, 17 Sep 2025 02:22:17 +0800 Subject: [PATCH 2/7] Update site.py --- web/utils/site.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/utils/site.py b/web/utils/site.py index 8c3de2240..335e11995 100644 --- a/web/utils/site.py +++ b/web/utils/site.py @@ -1995,7 +1995,7 @@ location ^~ {from} {\n\ {"name":"none", "title":'手动解析', 'key':'', 'help':''}, {"name":"dns_ali", "title":'Aliyun', 'key':'Ali_Key:Ali_Secret', 'help':'阿里云控制台》用户头像》accesskeys按指引获取AccessKey/SecretKey'}, {"name":"dns_huaweicloud", "title":'华为云', 'key':'HUAWEICLOUD_Username:HUAWEICLOUD_Password:HUAWEICLOUD_DomainName:HUAWEICLOUD_ProjectID:HUAWEICLOUD_AccessKey:HUAWEICLOUD_SecretKey'}, - {"name":"dns_cf", "title":'cloudflare', 'key':'CF_Key:CF_Email', 'help':'CloudFlare后台获取Global API Key'}, + {"name":"dns_cf", "title":'cloudflare', 'key':'CF_Key:CF_Email:CF_Token:CF_Account_ID:CF_Zone_ID', 'help':'CloudFlare后台获取Global API Key'}, {"name":"dns_dp", "title":'dnspod/国内', 'key':'DP_Id:DP_Key','help':'DnsPod后台》用户中心》安全设置,开启API Token'}, {"name":"dns_dpi", "title":'dnspod/国际', 'key':'DPI_Id:DPI_Key','help':'DnsPod后台》用户中心》安全设置,开启API Token'}, {"name":"dns_tencent", "title":"腾讯云DNS", 'key':'Tencent_SecretId:Tencent_SecretKey', 'help':'腾讯云后台获取通行证'}, From e1e24a33505e19f2f9725523393415bf4fc14b32 Mon Sep 17 00:00:00 2001 From: dami Date: Wed, 17 Sep 2025 12:38:14 +0800 Subject: [PATCH 3/7] Update index.html --- plugins/openresty/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/openresty/index.html b/plugins/openresty/index.html index ab2ec7ac1..8b7a409df 100755 --- a/plugins/openresty/index.html +++ b/plugins/openresty/index.html @@ -8,7 +8,7 @@

负载状态

性能调整

错误日志

-

其它功能

+

维护功能

From c9dc118af6362cff290c2bbf1eeedea860027891 Mon Sep 17 00:00:00 2001 From: dami Date: Wed, 17 Sep 2025 12:44:37 +0800 Subject: [PATCH 4/7] =?UTF-8?q?mongodb=E7=BB=B4=E6=8A=A4=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/mongodb/check.sh | 42 ++++++++++++ plugins/mongodb/index.html | 1 + plugins/mongodb/index.py | 20 ++++++ plugins/mongodb/js/mongodb.js | 22 ++++++ plugins/mongodb/tool_task.py | 124 ++++++++++++++++++++++++++++++++++ 5 files changed, 209 insertions(+) create mode 100644 plugins/mongodb/check.sh create mode 100644 plugins/mongodb/tool_task.py diff --git a/plugins/mongodb/check.sh b/plugins/mongodb/check.sh new file mode 100644 index 000000000..6013e230c --- /dev/null +++ b/plugins/mongodb/check.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +# MongoDB 监控脚本 +# 功能:检查 MongoDB 是否运行,如果停止则自动重启 + +# MongoDB 服务名称(根据你的系统配置调整) +SERVICE_NAME="mongod" + +# 检查 MongoDB 状态函数 +check_mongodb() { + # 检查 MongoDB 进程是否在运行 + if pgrep -x "$SERVICE_NAME" > /dev/null; then + echo "$(date): MongoDB 正在运行" + return 0 + else + echo "$(date): MongoDB 已停止" + return 1 + fi +} + +# 重启 MongoDB 函数 +restart_mongodb() { + echo "$(date): 尝试重启 MongoDB..." + + # 根据你的系统选择适当的命令 + # 对于使用 systemd 的系统(如 Ubuntu 16.04+, CentOS 7+) + if systemctl restart "$SERVICE_NAME"; then + echo "$(date): MongoDB 重启成功" + return 0 + else + echo "$(date): MongoDB 重启失败" + return 1 + fi + + # 对于使用 init.d 的系统 + # service mongod restart +} + +if ! check_mongodb; then + echo "$(date): 检测到 MongoDB 停止运行" + restart_mongodb +fi diff --git a/plugins/mongodb/index.html b/plugins/mongodb/index.html index 46f25956f..3d930fab4 100755 --- a/plugins/mongodb/index.html +++ b/plugins/mongodb/index.html @@ -63,6 +63,7 @@

负载状态

复制状态

日志

+

维护功能

相关说明

diff --git a/plugins/mongodb/index.py b/plugins/mongodb/index.py index 4480ba02b..c6b74c6f8 100755 --- a/plugins/mongodb/index.py +++ b/plugins/mongodb/index.py @@ -1524,6 +1524,22 @@ def runLog(): return f return getServerDir() + '/logs.pl' +def cronAddCheck(): + try: + import tool_task + tool_task.createBgTask() + return mw.returnJson(True, '添加检查任务成功') + except Exception as e: + return mw.returnJson(False, '添加检查任务失败:'+str(e)) + +def cronDelCheck(): + try: + import tool_task + tool_task.removeBgTask() + return mw.returnJson(True, '删除检查任务成功') + except Exception as e: + return mw.returnJson(False, '删除检查任务失败:'+str(e)) + def installPreInspectionDebainCheck(sysId,version): if version == '8.0': @@ -1666,5 +1682,9 @@ if __name__ == "__main__": print(test()) elif func == 'test_data': print(testData()) + elif func == 'cron_add_check': + print(cronAddCheck()) + elif func == 'cron_del_check': + print(cronDelCheck()) else: print('error') diff --git a/plugins/mongodb/js/mongodb.js b/plugins/mongodb/js/mongodb.js index 8617d6d7a..1bf3be284 100644 --- a/plugins/mongodb/js/mongodb.js +++ b/plugins/mongodb/js/mongodb.js @@ -1241,6 +1241,28 @@ function importDbExternal(file,name){ }); } +function otherFunc(){ + var con = '

\ + \ + \ +

'; + $(".soft-man-con").html(con); +} + +function cronAddCheck(){ + mgPost('cron_add_check', {}, function(data){ + var rdata = $.parseJSON(data.data); + layer.msg(rdata.msg, { icon: rdata.status ? 1 : 2 }); + }); +} + +function cronDelCheck(){ + mgPost('cron_del_check', {}, function(data){ + var rdata = $.parseJSON(data.data); + layer.msg(rdata.msg, { icon: rdata.status ? 1 : 2 }); + }); +} + function mgdbReadme(){ var readme = '
    '; readme += '
  • 认证同步说明
  • '; diff --git a/plugins/mongodb/tool_task.py b/plugins/mongodb/tool_task.py new file mode 100644 index 000000000..159749654 --- /dev/null +++ b/plugins/mongodb/tool_task.py @@ -0,0 +1,124 @@ +# 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 'mongodb' + + +def getPluginDir(): + return mw.getPluginDir() + '/' + getPluginName() + + +def getServerDir(): + return mw.getServerDir() + '/' + getPluginName() + + +def getTaskConf(): + conf = getServerDir() + "/task_config.json" + return conf + + +def getConfigData(): + conf = getTaskConf() + if os.path.exists(conf): + return json.loads(mw.readFile(getTaskConf())) + return { + "task_id": -1, + "period": "minute-n", + "where1": "1", + "hour": "0", + "minute": "0", + } + + +def createBgTask(): + removeBgTask() + createBgTaskByName(getPluginName()) + + +def createBgTaskByName(name): + args = getConfigData() + _name = "[MongoDB]检查任务" + res = mw.M("crontab").field("id, name").where("name=?", (_name,)).find() + if res: + return True + + if "task_id" in args and args["task_id"] > 0: + res = mw.M("crontab").field("id, name").where( + "id=?", (args["task_id"],)).find() + if res and res["id"] == args["task_id"]: + print("计划任务已经存在!") + return True + + mw_dir = mw.getPanelDir() + cmd = ''' +mw_dir=%s +rname=%s +plugin_path=%s +script_path=%s +''' % (mw_dir, name, getServerDir(), getPluginDir()) + cmd += 'echo "python3 $script_path/check.sh"' + "\n" + cmd += 'cd $mw_dir && bash $script_path/check.sh' + "\n" + + params = { + 'name': _name, + 'type': args['period'], + 'week': "", + 'where1': args['where1'], + 'hour': args['hour'], + 'minute': args['minute'], + 'save': "", + 'backup_to': "", + 'stype': "toShell", + 'sname': '', + 'sbody': cmd, + 'url_address': '', + } + + task_id = MwCrontab.instance().add(params) + if task_id > 0: + args["task_id"] = task_id + args["name"] = name + mw.writeFile(getTaskConf(), json.dumps(args)) + + +def removeBgTask(): + cfg = getConfigData() + if "task_id" in cfg and cfg["task_id"] > 0: + res = mw.M("crontab").field("id, name").where( + "id=?", (cfg["task_id"],)).find() + if res and res["id"] == cfg["task_id"]: + data = MwCrontab.instance().delete(cfg["task_id"]) + if data["status"]: + cfg["task_id"] = -1 + mw.writeFile(getTaskConf(), json.dumps(cfg)) + return True + return False + + +if __name__ == "__main__": + if len(sys.argv) > 1: + action = sys.argv[1] + if action == "remove": + removeBgTask() + elif action == "add": + createBgTask() From 331e33ec70c8b1e18c3a75269615be30c047ba71 Mon Sep 17 00:00:00 2001 From: dami Date: Wed, 17 Sep 2025 12:46:19 +0800 Subject: [PATCH 5/7] update --- plugins/mongodb/tool_task.py | 2 +- plugins/openresty/tool_task.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/mongodb/tool_task.py b/plugins/mongodb/tool_task.py index 159749654..d7a769640 100644 --- a/plugins/mongodb/tool_task.py +++ b/plugins/mongodb/tool_task.py @@ -76,7 +76,7 @@ rname=%s plugin_path=%s script_path=%s ''' % (mw_dir, name, getServerDir(), getPluginDir()) - cmd += 'echo "python3 $script_path/check.sh"' + "\n" + cmd += 'echo "bash $script_path/check.sh"' + "\n" cmd += 'cd $mw_dir && bash $script_path/check.sh' + "\n" params = { diff --git a/plugins/openresty/tool_task.py b/plugins/openresty/tool_task.py index bc1cb3a85..6029ad9ee 100644 --- a/plugins/openresty/tool_task.py +++ b/plugins/openresty/tool_task.py @@ -76,7 +76,7 @@ rname=%s plugin_path=%s script_path=%s ''' % (mw_dir, name, getServerDir(), getPluginDir()) - cmd += 'echo "python3 $script_path/check.sh"' + "\n" + cmd += 'echo "bash $script_path/check.sh"' + "\n" cmd += 'cd $mw_dir && bash $script_path/check.sh' + "\n" params = { From a700267ee6822b9e35284a61eebc901f251b8339 Mon Sep 17 00:00:00 2001 From: dami Date: Wed, 17 Sep 2025 12:47:44 +0800 Subject: [PATCH 6/7] Update mongodb.js --- plugins/mongodb/js/mongodb.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/mongodb/js/mongodb.js b/plugins/mongodb/js/mongodb.js index 1bf3be284..526372bd4 100644 --- a/plugins/mongodb/js/mongodb.js +++ b/plugins/mongodb/js/mongodb.js @@ -1250,14 +1250,14 @@ function otherFunc(){ } function cronAddCheck(){ - mgPost('cron_add_check', {}, function(data){ + mgPost('cron_add_check', '', {}, function(data){ var rdata = $.parseJSON(data.data); layer.msg(rdata.msg, { icon: rdata.status ? 1 : 2 }); }); } function cronDelCheck(){ - mgPost('cron_del_check', {}, function(data){ + mgPost('cron_del_check', '', {}, function(data){ var rdata = $.parseJSON(data.data); layer.msg(rdata.msg, { icon: rdata.status ? 1 : 2 }); }); From 057f05a88a54738ce092ec004728ab6cb94be602 Mon Sep 17 00:00:00 2001 From: dami Date: Wed, 17 Sep 2025 12:49:30 +0800 Subject: [PATCH 7/7] Update check.sh --- plugins/mongodb/check.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/mongodb/check.sh b/plugins/mongodb/check.sh index 6013e230c..e94441c2a 100644 --- a/plugins/mongodb/check.sh +++ b/plugins/mongodb/check.sh @@ -24,7 +24,7 @@ restart_mongodb() { # 根据你的系统选择适当的命令 # 对于使用 systemd 的系统(如 Ubuntu 16.04+, CentOS 7+) - if systemctl restart "$SERVICE_NAME"; then + if systemctl restart "mongodb"; then echo "$(date): MongoDB 重启成功" return 0 else