mirror of
https://github.com/aaPanel/aaPanel.git
synced 2026-08-20 22:52:30 +02:00
Since version 7.7.0, we recommend yours update python to 3.12. [+] Using nginx technology to load static files improves access speed [+] Refactor homepage, website, FTP, and database using vue3 [+] Table loading changed to skeleton screen [+] Add Website statistics-v2 professional plug-in [+] Add Home page - top 5 resource occupancy [+] Add protection for Files management (requires Tamper-proof for Enterprise 3.7) [+] Website, FTP, Databases page add program status [+] Add FTP log analysis (only supports Centos) [+] Add password-free login to phpMyAdmin [+] Add Proxy Project in Website (Supported when web service uses Nginx) [+] Add WP Toolkit (Pro version only) [+] Redesigned Docker module [+] Add WP Toolkit Protection [+] Add WP Toolkit Backup and Restore [+] Add WP Toolkit Migrated [+] Add WP Toolkit Clone site (supports new domain and subdomain) [+] Add WP Toolkit Create site from backup of other panel [+] Add WP Toolkit support for Cron automatic backup (only save Local disk) [+] Add WP Toolkit operation log [+] Add Integrity check for WP Toolkit [+] Add WP Toolkit plug-in management and themes management [*] Optimize phpMyAdmin formula access method [*] Optimize Home page PHP display problem [*] Optimize jump to the login interface after the login expires [*] Optimize automatic renewal of SSL at some times [*] Optimize Let's Encrypt to increase application success rate [-] Fix Logs Audit cannot be opened [-] Fix apache URL rewrite issue [-] Fix phpmyadmin installation problem [-] Fix the problem that some servers cannot install software [-] Fix upload file error [-] Fix left menu hiding problem [-] Fix aaPanel Mobile QR code display problem [-] Fix problem that third-party plug-ins are not displayed in the App Store [-] Fix issue where the menu bar is blank when opening new tabs [-] Fixed panel not being accessible in some cases [-] Fix the issue where Curl warning caused the inability to apply for SSL [-] Fix Quota issues for Website, FTP, Databases [-] Fix file interface display problem on mobile terminal
156 lines
4.4 KiB
Python
156 lines
4.4 KiB
Python
# coding: utf-8
|
|
# +-------------------------------------------------------------------
|
|
# | 宝塔Linux面板
|
|
# +-------------------------------------------------------------------
|
|
# | Copyright (c) 2015-2020 宝塔软件(http://www.bt.cn) All rights reserved.
|
|
# +-------------------------------------------------------------------
|
|
# | Author: baozi <
|
|
# | 消息通道邮箱模块(新)
|
|
# +-------------------------------------------------------------------
|
|
|
|
import re
|
|
import json
|
|
import requests
|
|
import traceback
|
|
import socket
|
|
|
|
import requests.packages.urllib3.util.connection as urllib3_cn
|
|
from requests.packages import urllib3
|
|
from typing import Optional, Union
|
|
|
|
from .util import write_push_log, get_test_msg
|
|
|
|
# 关闭警告
|
|
urllib3.disable_warnings()
|
|
|
|
|
|
class DingDingMsg:
|
|
def __init__(self, dingding_data):
|
|
self.id = dingding_data["id"]
|
|
self.config = dingding_data["data"]
|
|
|
|
def send_msg(self, msg: str, title) -> Optional[str]:
|
|
"""
|
|
钉钉发送信息
|
|
@msg 消息正文
|
|
"""
|
|
if not self.config:
|
|
return '未正确配置钉钉信息'
|
|
|
|
# user没有时默认为空
|
|
if "user" not in self.config:
|
|
self.config['user'] = []
|
|
|
|
if "isAtAll" not in self.config:
|
|
self.config['isAtAll'] = []
|
|
|
|
if not isinstance(self.config['url'], str):
|
|
return '钉钉配置错误,请重新配置钉钉机器人'
|
|
|
|
at_info = ''
|
|
for user in self.config['user']:
|
|
if re.match(r"^[0-9]{11}$", str(user)):
|
|
at_info += '@' + user + ' '
|
|
|
|
if at_info:
|
|
msg = msg + '\n\n>' + at_info
|
|
|
|
|
|
|
|
headers = {'Content-Type': 'application/json'}
|
|
data = {
|
|
"msgtype": "markdown",
|
|
"markdown": {
|
|
"title": "服务器通知",
|
|
"text": msg
|
|
},
|
|
"at": {
|
|
"atMobiles": self.config['user'],
|
|
"isAtAll": self.config['isAtAll']
|
|
}
|
|
}
|
|
status = False
|
|
error = None
|
|
try:
|
|
def allowed_gai_family():
|
|
family = socket.AF_INET
|
|
return family
|
|
|
|
allowed_gai_family_lib = urllib3_cn.allowed_gai_family
|
|
urllib3_cn.allowed_gai_family = allowed_gai_family
|
|
|
|
response = requests.post(
|
|
url=self.config["url"],
|
|
data=json.dumps(data),
|
|
verify=False,
|
|
headers=headers,
|
|
timeout=10
|
|
)
|
|
|
|
urllib3_cn.allowed_gai_family = allowed_gai_family_lib
|
|
|
|
if response.json()["errcode"] == 0:
|
|
status = True
|
|
except:
|
|
error = traceback.format_exc()
|
|
status = False
|
|
|
|
write_push_log("钉钉", status, title)
|
|
return error
|
|
|
|
@classmethod
|
|
def check_args(cls, args: dict) -> Union[dict, str]:
|
|
if "url" not in args or "title" not in args:
|
|
return "信息不完整"
|
|
|
|
title = args["title"]
|
|
if len(title) > 15:
|
|
return '备注名称不能超过15个字符'
|
|
|
|
if "user" in args and isinstance(args["user"], list):
|
|
user = args["user"]
|
|
else:
|
|
user = []
|
|
|
|
if "atall" in args and isinstance(args["atall"], bool):
|
|
atall = args["atall"]
|
|
else:
|
|
atall = True
|
|
|
|
data = {
|
|
"url": args["url"],
|
|
"user": user,
|
|
"title": title,
|
|
"isAtAll": atall,
|
|
}
|
|
|
|
test_obj = cls({"data": data, "id": None})
|
|
test_msg = {
|
|
"msg_list": ['>配置状态:<font color=#20a53a>成功</font>\n\n']
|
|
}
|
|
|
|
test_task = get_test_msg("面板消息通道配置提醒")
|
|
|
|
res = test_obj.send_msg(
|
|
test_task.to_dingding_msg(test_msg, test_task.the_push_public_data()),
|
|
"面板消息通道配置提醒"
|
|
)
|
|
if res is None:
|
|
return data
|
|
|
|
return res
|
|
|
|
def test_send_msg(self) -> Optional[str]:
|
|
|
|
test_msg = {
|
|
"msg_list": ['>配置状态:<font color=#20a53a>成功</font>\n\n']
|
|
}
|
|
test_task = get_test_msg("面板消息通道配置提醒")
|
|
res = self.send_msg(
|
|
test_task.to_dingding_msg(test_msg, test_task.the_push_public_data()),
|
|
"面板消息通道配置提醒"
|
|
)
|
|
if res is None:
|
|
return None
|
|
return res
|