mirror of
https://github.com/aaPanel/aaPanel.git
synced 2026-08-17 21:25:47 +02:00
2.The page is displayed when the adjustment panel is wrong 3.App store add common plug-in display 4.Adjust the sessionid name to a non-fixed name 5.Panel CSRF defense mechanism covers panel websocket communication 6.Adjust the font size of the panel list 7.Adjust the panel pop-up window (add a close button to cancel the automatic closing time) 8.Optimize the front/back end of the file manager 9.Add the entrance of the MailServer Rspamd 10.Refactor the debug module 11.Other known bug fixes
195 lines
6.2 KiB
Python
195 lines
6.2 KiB
Python
#coding: utf-8
|
|
# +-------------------------------------------------------------------
|
|
# | 宝塔Linux面板
|
|
# +-------------------------------------------------------------------
|
|
# | Copyright (c) 2015-2099 宝塔软件(http://bt.cn) All rights reserved.
|
|
# +-------------------------------------------------------------------
|
|
# | Author: hwliang <2020-05-18>
|
|
# +-------------------------------------------------------------------
|
|
|
|
# +-------------------------------------------------------------------
|
|
# | 消息提醒
|
|
# +-------------------------------------------------------------------
|
|
import os,sys,time
|
|
import public,json
|
|
if os.environ.get('BT_TASK') != '1':
|
|
from BTPanel import cache
|
|
else:
|
|
import cachelib
|
|
cache = cachelib.SimpleCache()
|
|
|
|
class panelMessage:
|
|
os = 'linux'
|
|
|
|
def __init__(self):
|
|
if not public.M('sqlite_master').where('type=? AND name=? AND sql LIKE ?', ('table', 'messages','%retry_num%')).count():
|
|
public.M('messages').execute("alter TABLE messages add send integer DEFAULT 0",())
|
|
public.M('messages').execute("alter TABLE messages add retry_num integer DEFAULT 0",())
|
|
pass
|
|
|
|
|
|
def set_send_status(self, id, data):
|
|
'''
|
|
@name 设置消息发送状态
|
|
@author cjxin <2021-04-12>
|
|
@param args dict_obj{
|
|
id: 消息标识,
|
|
data
|
|
}
|
|
@return dict
|
|
'''
|
|
|
|
public.M('messages').where('id=?',id).update(data)
|
|
return public.returnMsg(True,'设置成功!')
|
|
|
|
|
|
"""
|
|
获取官网推送消息,一小时获取一次
|
|
"""
|
|
def get_cloud_messages(self,args):
|
|
#ret = cache.get('get_cloud_messages')
|
|
#if ret: return public.returnMsg(True,'同步成功1!')
|
|
data = {}
|
|
data['version'] = public.version()
|
|
data['os'] = self.os
|
|
sUrl = public.GetConfigValue('home') + '/api/wpanel/get_messages'
|
|
import http_requests
|
|
http_requests.DEFAULT_TYPE = 'src'
|
|
info = http_requests.post(sUrl,data).json()
|
|
# info = json.loads(public.httpPost(sUrl,data))
|
|
for x in info:
|
|
count = public.M('messages').where('level=? and msg=?',(x['level'],x['msg'],)).count()
|
|
if count: continue
|
|
|
|
pdata = {
|
|
"level":x['level'],
|
|
"msg":x['msg'],
|
|
"state":1,
|
|
"expire":int(time.time()) + (int(x['expire']) * 86400),
|
|
"addtime": int(time.time())
|
|
}
|
|
public.M('messages').insert(pdata)
|
|
#cache.set('get_cloud_messages',3600)
|
|
return public.returnMsg(True,'同步成功!')
|
|
|
|
def get_messages(self,args = None):
|
|
'''
|
|
@name 获取消息列表
|
|
@author hwliang <2020-05-18>
|
|
@return list
|
|
'''
|
|
self.get_cloud_messages(args)
|
|
data = public.M('messages').where('state=? and expire>?',(1,int(time.time()))).order("id desc").select()
|
|
return data
|
|
|
|
def get_messages_all(self,args = None):
|
|
'''
|
|
@name 获取所有消息列表
|
|
@author hwliang <2020-05-18>
|
|
@return list
|
|
'''
|
|
self.get_cloud_messages(args)
|
|
data = public.M('messages').order("id desc").select()
|
|
return data
|
|
|
|
def get_message_find(self,args = None,id = None):
|
|
'''
|
|
@name 获取指定消息
|
|
@author hwliang <2020-05-18>
|
|
@param args dict_obj{
|
|
id: 消息标识
|
|
}
|
|
@return dict
|
|
'''
|
|
if args:
|
|
id = int(args.id)
|
|
data = public.M('messages').where('id=?',id).find()
|
|
return data
|
|
|
|
|
|
def create_message(self,args = None,level=None,msg=None,expire=None):
|
|
'''
|
|
@name 创建新的消息
|
|
@author hwliang <2020-05-18>
|
|
@param args dict_obj{
|
|
level: 消息级别(info/warning/danger/error),
|
|
msg: 消息内容
|
|
expire: 过期时间
|
|
}
|
|
@return dict
|
|
'''
|
|
if args:
|
|
level = args.level
|
|
msg = args.msg
|
|
expire = args.expire
|
|
pdata = {
|
|
"level":level,
|
|
"msg":msg,
|
|
"state":1,
|
|
"expire":int(time.time()) + (int(expire) * 86400),
|
|
"addtime": int(time.time())
|
|
}
|
|
|
|
public.M('messages').insert(pdata)
|
|
return public.returnMsg(True,'Created successfully!')
|
|
|
|
def status_message(self,args = None,id = None,state = None):
|
|
'''
|
|
@name 设置消息状态
|
|
@author hwliang <2020-05-18>
|
|
@param args dict_obj{
|
|
id: 消息标识,
|
|
state: 消息状态(0.已忽略, 1.正常)
|
|
}
|
|
@return dict
|
|
'''
|
|
if args:
|
|
id = int(args.id)
|
|
state = int(args.state)
|
|
public.M('messages').where('id=?',id).setField('state',state)
|
|
return public.returnMsg(True,'Set up successfully!')
|
|
|
|
|
|
def remove_message(self,args = None,id = None):
|
|
'''
|
|
@name 删除指定消息
|
|
@author hwliang <2020-05-18>
|
|
@param args dict_obj{
|
|
id: 消息标识
|
|
}
|
|
@return dict
|
|
'''
|
|
if args:
|
|
id = int(args.id)
|
|
public.M('messages').where('id=?',id).delete()
|
|
return public.returnMsg(True,'Successfully deleted!')
|
|
|
|
def remove_message_level(self,level):
|
|
'''
|
|
@name 删除指定消息
|
|
@author hwliang <2020-05-18>
|
|
@param level string(指定级别或标识)
|
|
@return bool
|
|
'''
|
|
public.M('messages').where('(level=? or level=? or level=? or level=?) and state=?',(level,level+'15',level+'7',level+'3',1)).delete()
|
|
return True
|
|
|
|
def remove_message_all(self):
|
|
public.M('messages').where('state=?',(1,)).delete()
|
|
return True
|
|
|
|
def is_level(self,level):
|
|
'''
|
|
@name 指定消息是否忽略
|
|
@author hwliang <2020-05-18>
|
|
@param level string(指定级别或标识)
|
|
@return bool
|
|
'''
|
|
if public.M('messages').where('level=? and state=?',(level,0)).count():
|
|
return False
|
|
else:
|
|
return True
|
|
|
|
|
|
|