Skip to content

Commit

Permalink
Merge pull request #400 from midoks/dev
Browse files Browse the repository at this point in the history
0.13.5
  • Loading branch information
midoks authored Mar 30, 2023
2 parents fe5843b + 22133f1 commit e1820ad
Show file tree
Hide file tree
Showing 9 changed files with 329 additions and 31 deletions.
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,10 @@ docker run -itd --name mw-server --privileged=true -p 7200:7200 -p 80:80 -p 443:
```


### 版本更新 0.13.4
### 版本更新 0.13.5

无重大更新

* 国内安装不在依赖gitee。
* tgbot优化。
* 添加邮件通知功能。
* 修复初始安装脚本。

### JSDelivr安装地址

Expand Down
9 changes: 8 additions & 1 deletion class/core/config_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

class config_api:

__version = '0.13.4'
__version = '0.13.5'
__api_addr = 'data/api.json'

def __init__(self):
Expand Down Expand Up @@ -788,6 +788,13 @@ def setNotifyTestApi(self):
return mw.returnData(True, '验证成功')
return mw.returnData(False, '验证失败')

if tag == 'email':
t = json.loads(tag_data)
test_bool = mw.emailNotifyTest(t)
if test_bool:
return mw.returnData(True, '验证成功')
return mw.returnData(False, '验证失败')

return mw.returnData(False, '暂时未支持该验证')

def setNotifyEnableApi(self):
Expand Down
37 changes: 36 additions & 1 deletion class/core/mw.py
Original file line number Diff line number Diff line change
Expand Up @@ -1697,7 +1697,7 @@ def getNotifyData(is_parse=False):
data = json.loads(notify_data)

if is_parse:
tag_list = ['tgbot']
tag_list = ['tgbot', 'email']
for t in tag_list:
if t in data and 'cfg' in data[t]:
data[t]['data'] = json.loads(deDoubleCrypt(t, data[t]['cfg']))
Expand Down Expand Up @@ -1759,6 +1759,34 @@ def tgbotNotifyTest(app_token, chat_id):
return tgbotNotifyHttpPost(app_token, chat_id, msg)


def emailNotifyMessage(data):
'''
邮件通知
'''
sys.path.append(os.getcwd() + "/class/plugin")
import memail
try:
if data['smtp_ssl'] == 'ssl':
memail.sendSSL(data['smtp_host'], data['smtp_port'],
data['username'], data['password'],
data['to_mail_addr'], data['subject'], data['content'])
else:
memail.send(data['smtp_host'], data['smtp_port'],
data['username'], data['password'],
data['to_mail_addr'], data['subject'], data['content'])
return True
except Exception as e:
print(getTracebackInfo())
return False


def emailNotifyTest(data):
print(data)
data['subject'] = 'MW通知测试'
data['content'] = data['mail_test']
return emailNotifyMessage(data)


def notifyMessageTry(msg, stype='common', trigger_time=300, is_write_log=True):

lock_file = getPanelTmp() + '/notify_lock.json'
Expand Down Expand Up @@ -1796,6 +1824,13 @@ def notifyMessageTry(msg, stype='common', trigger_time=300, is_write_log=True):
else:
do_notify = tgbotNotifyMessage(
t['app_token'], t['chat_id'], msg)

if 'email' in data and 'enable' in data['email']:
if data['email']['enable']:
t = data['email']['data']
t['subject'] = 'MW通知'
t['content'] = msg
do_notify = emailNotifyMessage(t)
return do_notify


Expand Down
43 changes: 43 additions & 0 deletions class/plugin/memail.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# coding: utf-8

import smtplib

from email import encoders
from email.header import Header
from email.mime.text import MIMEText
from email.utils import parseaddr, formataddr


def _format_addr(s):
name, addr = parseaddr(s)
return formataddr((Header(name, 'utf-8').encode(), addr))


def send(smtp_host, smtp_port, username, password, to_mail, subject, content):

smtp = smtplib.SMTP()
smtp.connect(smtp_host, port=smtp_port)
smtp.login(user=username, password=password)

msg = MIMEText(content, 'plain', 'utf-8')
msg['From'] = _format_addr(username)
msg['To'] = _format_addr(to_mail)
msg['Subject'] = Header(subject, 'utf-8').encode()

smtp.sendmail(from_addr=username, to_addrs=to_mail, msg=msg.as_string())
return True


def sendSSL(smtp_host, smtp_port, username, password, to_mail, subject, content):

smtp = smtplib.SMTP_SSL(smtp_host, port=smtp_port)
smtp.login(user=username, password=password)

msg = MIMEText(content, 'plain', 'utf-8')
msg['From'] = _format_addr(username)
msg['To'] = _format_addr(to_mail)
msg['Subject'] = Header(subject, 'utf-8').encode()

smtp.sendmail(from_addr=username, to_addrs=to_mail, msg=msg.as_string())
smtp.quit()
return True
7 changes: 6 additions & 1 deletion plugins/tgbot/startup/extend/push_notice_msg.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,9 @@ def send_msg(bot, tag='ad', trigger_time=300):


def run(bot):
send_msg(bot, 'tmp_msg', 180)
try:
send_msg(bot, 'notice_msg', 180)
except Exception as e:
writeLog('-----push_notice_msg error start -------')
print(mw.getTracebackInfo())
writeLog('-----push_notice_msg error start -------')
193 changes: 192 additions & 1 deletion route/static/app/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ function getTgbot(){
layer.open({
type: 1,
area: "500px",
title: '配置TgBot配置',
title: 'TgBot配置',
closeBtn: 1,
shift: 5,
btn:["确定","关闭","验证"],
Expand All @@ -401,6 +401,17 @@ function getTgbot(){
var pdata = {};
pdata['app_token'] = $('input[name="app_token"]').val();
pdata['chat_id'] = $('input[name="chat_id"]').val();

if (pdata['app_token'] == ''){
layer.msg('app_token不能为空!', {icon:2});
return false;
}

if (pdata['chat_id'] == ''){
layer.msg('chat_id不能为空!', {icon:2});
return false;
}

$.post('/config/set_notify',{'tag':'tgbot', 'data':JSON.stringify(pdata)},function(rdata){
showMsg(rdata.msg, function(){
if (rdata.status){
Expand All @@ -414,6 +425,17 @@ function getTgbot(){
var pdata = {};
pdata['app_token'] = $('input[name="app_token"]').val();
pdata['chat_id'] = $('input[name="chat_id"]').val();

if (pdata['app_token'] == ''){
layer.msg('app_token不能为空!', {icon:2});
return false;
}

if (pdata['chat_id'] == ''){
layer.msg('chat_id不能为空!', {icon:2});
return false;
}

$.post('/config/set_notify_test',{'tag':'tgbot', 'data':JSON.stringify(pdata)},function(rdata){
showMsg(rdata.msg, function(){
if (rdata.status){
Expand All @@ -427,6 +449,175 @@ function getTgbot(){
});
}

function getEmailCfg(){
var loadT = layer.msg('正在获取邮件配置信息...',{icon:16,time:0,shade: [0.3, '#000']});
$.post('/config/get_notify',{},function(data){
layer.close(loadT);

var smtp_host = 'smtp.163.com';
var smtp_port = '25';
var username = 'admin';
var password = '';
var to_mail_addr = '';

var smtp_ssl_no = 'checked';
var smtp_ssl_yes = '';

if (data.status){
if (typeof(data['data']['email']) !='undefined'){
smtp_host = data['data']['email']['data']['smtp_host'];
smtp_port = data['data']['email']['data']['smtp_port'];
username = data['data']['email']['data']['username'];
password = data['data']['email']['data']['password'];
to_mail_addr = data['data']['email']['data']['to_mail_addr'];


var smtp_ssl = data['data']['email']['data']['smtp_ssl'];
if (smtp_ssl == 'ssl'){
smtp_ssl_no = '';
smtp_ssl_yes = 'checked';
}
}
}

layer.open({
type: 1,
area: "500px",
title: '邮件配置',
closeBtn: 1,
shift: 5,
btn:["确定","关闭","验证"],
shadeClose: false,
content: "<div class='bt-form pd20'>\
<div class='line'>\
<span class='tname'>SMTP服务器</span>\
<div class='info-r'><input class='bt-input-text' type='text' name='smtp_host' value='"+smtp_host+"' style='width:100%'/></div>\
</div>\
<div class='line'>\
<span class='tname'>SMTP安全</span>\
<div class='info-r checkbox'>\
<label><input name='smtp_ssl' type='radio' value='' style='margin-right: 4px;' "+smtp_ssl_no+">None</label>\
<label><input name='smtp_ssl' type='radio' value='ssl' style='margin-right: 4px;' "+smtp_ssl_yes+">SSL</label>\
</div>\
</div>\
<div class='line'>\
<span class='tname'>SMTP端口</span>\
<div class='info-r'><input class='bt-input-text' type='text' name='smtp_port' value='"+smtp_port+"' style='width:100%' /></div>\
</div>\
<div class='line'>\
<span class='tname'>用户名</span>\
<div class='info-r'><input class='bt-input-text' type='text' name='username' value='"+username+"' style='width:100%' autocomplete='off'/></div>\
</div>\
<div class='line'>\
<span class='tname'>授权码</span>\
<div class='info-r'><input class='bt-input-text' type='password' name='password' value='"+password+"' style='width:100%' autocomplete='off'/></div>\
</div>\
<div class='line'>\
<span class='tname'>发送地址</span>\
<div class='info-r'><input class='bt-input-text' type='text' name='to_mail_addr' value='"+to_mail_addr+"' style='width:100%' autocomplete='off'/></div>\
</div>\
<div class='line'>\
<span class='tname'>验证测试</span>\
<div class='info-r'>\
<textarea class='bt-input-text' name='mail_test' style='width:100%; height: 80px; line-height: 20px; padding: 5px 8px;'>验证测试</textarea></div>\
</div>\
</div>",
yes:function(index){
var pdata = {};
pdata['smtp_host'] = $('input[name="smtp_host"]').val();
pdata['smtp_port'] = $('input[name="smtp_port"]').val();
pdata['smtp_ssl'] = $('input[name="smtp_ssl"]:checked').val();
pdata['username'] = $('input[name="username"]').val();
pdata['password'] = $('input[name="password"]').val();
pdata['to_mail_addr'] = $('input[name="to_mail_addr"]').val();

if (pdata['smtp_host'] == ''){
layer.msg('SMTP服务器不能为空!', {icon:2});
return false;
}

if (pdata['smtp_port'] == ''){
layer.msg('SMTP端口不能为空!', {icon:2});
return false;
}

if (pdata['username'] == ''){
layer.msg('用户名不能为空!', {icon:2});
return false;
}

if (pdata['password'] == ''){
layer.msg('授权码不能为空!', {icon:2});
return false;
}

if (pdata['to_mail_addr'] == ''){
layer.msg('发送地址不能为空!', {icon:2});
return false;
}

$.post('/config/set_notify',{'tag':'email', 'data':JSON.stringify(pdata)},function(rdata){
showMsg(rdata.msg, function(){
if (rdata.status){
layer.close(index);
}
},{icon:rdata.status?1:2},2000);
});
},

btn3:function(index){
var pdata = {};
pdata['smtp_host'] = $('input[name="smtp_host"]').val();
pdata['smtp_port'] = $('input[name="smtp_port"]').val();
pdata['smtp_ssl'] = $('input[name="smtp_ssl"]:checked').val();
pdata['username'] = $('input[name="username"]').val();
pdata['password'] = $('input[name="password"]').val();
pdata['to_mail_addr'] = $('input[name="to_mail_addr"]').val();
pdata['mail_test'] = $('textarea[name="mail_test"]').val();


if (pdata['smtp_host'] == ''){
layer.msg('SMTP服务器不能为空!', {icon:2});
return false;
}

if (pdata['smtp_port'] == ''){
layer.msg('SMTP端口不能为空!', {icon:2});
return false;
}

if (pdata['username'] == ''){
layer.msg('用户名不能为空!', {icon:2});
return false;
}

if (pdata['password'] == ''){
layer.msg('授权码不能为空!', {icon:2});
return false;
}

if (pdata['to_mail_addr'] == ''){
layer.msg('发送地址不能为空!', {icon:2});
return false;
}

if (pdata['mail_test'] == ''){
layer.msg('验证测试不能为空!', {icon:2});
return false;
}
$.post('/config/set_notify_test',{'tag':'email', 'data':JSON.stringify(pdata)},function(rdata){
showMsg(rdata.msg, function(){
if (rdata.status){
layer.close(index);
}
},{icon:rdata.status?1:2},2000);
});
return false;
}
});
});
}

function getPanelSSL(){
var loadT = layer.msg('正在获取证书信息...',{icon:16,time:0,shade: [0.3, '#000']});
$.post('/config/get_panel_ssl',{},function(cert){
Expand Down
Loading

0 comments on commit e1820ad

Please sign in to comment.