Update to v8.7.0

This commit is contained in:
aapanel.com
2026-04-16 18:17:07 +08:00
parent c3f2d7566c
commit ee92fa2dbd
2472 changed files with 33631 additions and 20919 deletions
+57 -60
View File
@@ -9,6 +9,7 @@
# 新告警通道管理模块
# ------------------------------
import json
import glob
import os
import sys
@@ -19,41 +20,49 @@ import public
from mod.base import json_response
from mod.base.push_mod import PushManager, TaskConfig, TaskRecordConfig, TaskTemplateConfig, PushSystem
from mod.base.push_mod import update_mod_push_system, UPDATE_MOD_PUSH_FILE, load_task_template_by_file, \
UPDATE_VERSION_FILE
from mod.base.push_mod import update_mod_push_system, UPDATE_MOD_PUSH_FILE, load_task_template_by_file
from mod.base.msg import update_mod_push_msg
from mod.base.push_mod.rsync_push import load_rsync_template
from mod.base.push_mod.task_manager_push import load_task_manager_template
from mod.base.push_mod.load_push import load_load_template
# 内置模板目录
TEMPLATE_DIR = "/www/server/panel/mod/base/push_mod/templates/"
def update_mod():
# todo 缺少移除弃用模板的操作
template_ver = "8"
try:
with open(UPDATE_VERSION_FILE, 'r') as f:
if f.read() == template_ver:
pl = False
else:
pl = True
except:
pl = True
files = os.path.join(TEMPLATE_DIR, "*_push_template.json")
template_files = sorted(glob.glob(files))
if pl:
# 更新标志pl存在时, 只强制更新以下模板的最新配置, 其他不更新
load_task_template_by_file("/www/server/panel/mod/base/push_mod/site_push_template.json")
load_task_template_by_file("/www/server/panel/mod/base/push_mod/system_push_template.json")
load_task_template_by_file("/www/server/panel/mod/base/push_mod/database_push_template.json")
load_task_template_by_file("/www/server/panel/mod/base/push_mod/domain_blcheck_push_template.json")
with open(UPDATE_VERSION_FILE, "w") as f:
f.write(template_ver)
# 所有内置源模板, 不包括插件, 插件告警模板统一自身处理控制
all_source_ids = set()
for tpl_file in template_files:
if not os.path.isfile(tpl_file) or not tpl_file.endswith(".json"):
continue
try:
tpl_data = json.loads(public.readFile(tpl_file))
for tpl in tpl_data:
# 校验关键字段
if not tpl.get("id") or not tpl.get("load_cls") or not tpl.get("template"):
public.print_log(
f"Template file {tpl_file} missing required fields:"
f" id 模板唯一id / load_cls 模块/ template 前端表单控制"
)
continue
all_source_ids.add(str(tpl["id"]))
except Exception as e:
public.print_log(f"Failed to parse template file {tpl_file}: {e}")
# 启动都加载模板, merge操作
for tpl_file in template_files:
load_task_template_by_file(tpl_file)
# 动态加载模板,仅首次, 使用标志 UPDATE_MOD_PUSH_FILE 便于从其他调用处控制是否更新
if not os.path.exists(UPDATE_MOD_PUSH_FILE):
update_mod_push_msg()
load_rsync_template()
load_task_manager_template()
load_load_template()
update_mod_push_system()
@@ -63,7 +72,6 @@ del update_mod
class main(PushManager):
def get_task_list(self, get=None):
# 通道类型映射,包含模糊匹配规则
channel_map = {
# "wx_account": "wx_account",
@@ -72,18 +80,17 @@ class main(PushManager):
"feishu": "feishu",
"dingding": "dingding",
# "短信": "sms",
"tg": "tg"
"tg": "tg",
"discord": "discord",
}
try:
if get:
# get["status"] = "false"
# get["keyword"] = "shylock"
# 获取状态和关键词参数
status_filter = get.get("status", None)
keyword_filter = get.get("keyword", None)
else:
status_filter = ""
keyword_filter =""
status_filter = ""
keyword_filter = ""
res = TaskConfig().config
# 按创建时间排序
@@ -100,15 +107,17 @@ class main(PushManager):
keyword_filter_lower = keyword_filter.lower()
filtered_res = []
for task in res:
# print("task",task)
task_match = False
if keyword_filter_lower=="Alert when the panel is logged in":
if task['keyword']=="panel_login":
if keyword_filter_lower == "Alert when the panel is logged in":
if task['keyword'] == "panel_login":
task_match = True
if keyword_filter_lower in task["title"].lower() or \
(task["task_data"].get("title") and keyword_filter_lower in task["task_data"]["title"].lower()) or \
(task["time_rule"].get("send_interval") and keyword_filter_lower in str(task["time_rule"]["send_interval"])) or \
(task["number_rule"].get("day_num") and keyword_filter_lower in str(task["number_rule"]["day_num"])):
(task["task_data"].get("title") and keyword_filter_lower in task["task_data"][
"title"].lower()) or \
(task["time_rule"].get("send_interval") and keyword_filter_lower in str(
task["time_rule"]["send_interval"])) or \
(task["number_rule"].get("day_num") and keyword_filter_lower in str(
task["number_rule"]["day_num"])):
task_match = True
else:
for sender_id in task["sender"]:
@@ -116,7 +125,7 @@ class main(PushManager):
sender_title = sender.get("data", {}).get("title", "").lower()
sender_type = sender.get("sender_type", "").lower()
if keyword_filter_lower in sender_title or \
keyword_filter_lower in sender_type:
keyword_filter_lower in sender_type:
task_match = True
break
# 检查关键词是否包含在通道类型的映射键中
@@ -131,12 +140,10 @@ class main(PushManager):
i['view_msg'] = self.get_view_msg_format(i)
return json_response(status=True, data=res)
except:
except Exception as e:
import traceback
# public.print_log(traceback.format_exc())
print(traceback.format_exc())
return json_response(status=True, data=res)
public.print_log(traceback.format_exc())
return json_response(status=True, data=str(e))
def get_sender_info(self):
sender_file = '/www/server/panel/data/mod_push_data/sender.json'
@@ -197,46 +204,37 @@ class main(PushManager):
@staticmethod
def get_task_template_list(get=None):
# todo 弃用表
public.check_table('ssl_domains', """CREATE TABLE IF NOT EXISTS `ssl_domains` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`domain` TEXT,
`dns_id` TEXT,
`type_id` INTEGER,
`endtime` INTEGER,
`ps` TEXT
)
""")
# 增加缓存
# 缓存
cache_key = 'mod_task:get_task_template_list'
cache = public.cache_get(cache_key)
if cache:
return json_response(status=True, data=cache)
res = []
p_sys = PushSystem()
for i in TaskTemplateConfig().config:
if not i['used']:
continue
to = p_sys.get_task_object(i["id"], i["load_cls"])
if not to:
continue
# 以下模板,只允许在安全模块中使用
if i['id'] in ['121','122','123','124']:
if i['id'] in ['121', '122', '123', '124']:
continue
t = to.filter_template(i["template"])
if not t:
continue
i["template"] = t
res.append(i)
# 缓存两分钟
public.cache_set(cache_key, res, 120)
return json_response(status=True, data=res)
res.sort(key=lambda x: x["title"])
# 缓存30s
public.cache_set(cache_key, res, 30)
return json_response(status=True, data=res)
@staticmethod
def get_view_msg_format(task: dict) -> str:
@@ -255,4 +253,3 @@ class main(PushManager):
if res is not None:
return res
return '<span>--</span>'