diff --git a/web/admin/setting/__init__.py b/web/admin/setting/__init__.py index adfb25a3e..c516d49bf 100644 --- a/web/admin/setting/__init__.py +++ b/web/admin/setting/__init__.py @@ -12,6 +12,7 @@ from .setting import * from .temp_login import * from .timezone import * from .secondary_verifiy import * +from .notify_email import * diff --git a/web/admin/setting/notify_email.py b/web/admin/setting/notify_email.py new file mode 100644 index 000000000..26437672e --- /dev/null +++ b/web/admin/setting/notify_email.py @@ -0,0 +1,79 @@ +# coding:utf-8 + +# --------------------------------------------------------------------------------- +# MW-Linux面板 +# --------------------------------------------------------------------------------- +# copyright (c) 2018-∞(https://github.com/midoks/mdserver-web) All rights reserved. +# --------------------------------------------------------------------------------- +# Author: midoks +# --------------------------------------------------------------------------------- + +import re +import json +import os +import time + +from flask import Blueprint, render_template +from flask import request + +from admin import session +from admin.user_login_check import panel_login_required + +import core.mw as mw +import utils.config as utils_config + +from .setting import blueprint +import thisdb + +# 获取邮件信息 +@blueprint.route('/get_notify_email', endpoint='get_notify_email', methods=['POST']) +@panel_login_required +def get_notify_email(): + notify_email = thisdb.getOptionByJson('notify_email', default={'open':False}, type='notify') + + decrypt_data = mw.deDoubleCrypt('email', notify_email['cfg']) + notify_email['email'] = json.loads(decrypt_data) + return mw.returnData(True,'ok',notify_email) + + +# 设置邮件信息 +@blueprint.route('/set_notify_email', endpoint='set_notify_email', methods=['POST']) +@panel_login_required +def set_notify_email(): + tag = request.form.get('tag', '').strip() + data = request.form.get('data', '').strip() + + crypt_data = mw.enDoubleCrypt(tag, data) + + notify_email = thisdb.getOptionByJson('notify_email', default={'open':False}, type='notify') + notify_email['cfg'] = crypt_data + + thisdb.setOption('notify_email', json.dumps(notify_email), type='notify') + return mw.returnData(True,'设置成功') + + +# 设置邮件测试 +@blueprint.route('/set_notify_email_test', endpoint='set_notify_email_test', methods=['POST']) +@panel_login_required +def set_notify_email_test(): + return mw.returnData(True,'设置成功') + + +# 切换邮件开关 +@blueprint.route('/set_notify_email_enable', endpoint='set_notify_email_enable', methods=['POST']) +@panel_login_required +def set_notify_email_enable(): + tag = request.form.get('tag', '').strip() + data = request.form.get('data', '').strip() + + notify_email = thisdb.getOptionByJson('notify_email', default={'open':False}, type='notify') + + if notify_email['open']: + op_action = '关闭' + notify_email['open'] = False + else: + op_action = '开启' + notify_email['open'] = True + + thisdb.setOption('notify_email', json.dumps(notify_email), type='notify') + return mw.returnData(True, op_action+'成功') \ No newline at end of file diff --git a/web/admin/setup/option.py b/web/admin/setup/option.py index 9a433961e..8a3439d0d 100644 --- a/web/admin/setup/option.py +++ b/web/admin/setup/option.py @@ -57,5 +57,9 @@ def init_option(): thisdb.setOption('backup_path', mw.getFatherDir()+'/backup') # 默认站点目录 thisdb.setOption('site_path', mw.getFatherDir()+'/wwwroot') + + + # 邮件通知 + thisdb.setOption('notify_email', json.dumps({'open':False}), type='notify') return True \ No newline at end of file diff --git a/web/static/app/config.js b/web/static/app/config.js index 542437619..c8594eaff 100755 --- a/web/static/app/config.js +++ b/web/static/app/config.js @@ -543,7 +543,7 @@ function setPanelSSL(){ function setNotifyApi(tag, obj){ var enable = $(obj).prop("checked"); // console.log(tag,obj,enable); - $.post('/setting/set_notify_enable', {'tag':tag, 'enable':enable},function(rdata){ + $.post('/setting/set_notify_email_enable', {'tag':tag, 'enable':enable},function(rdata){ showMsg(rdata.msg, function(){ if (rdata.status){} } ,{icon:rdata.status?1:2}, 1000); @@ -637,7 +637,7 @@ function getTgbot(){ function getEmailCfg(){ var loadT = layer.msg('正在获取邮件配置信息...',{icon:16,time:0,shade: [0.3, '#000']}); - $.post('/setting/get_notify',{},function(data){ + $.post('/setting/get_notify_email',{},function(data){ layer.close(loadT); var smtp_host = 'smtp.163.com'; @@ -651,14 +651,13 @@ function getEmailCfg(){ 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']; + smtp_host = data['data']['email']['smtp_host']; + smtp_port = data['data']['email']['smtp_port']; + username = data['data']['email']['username']; + password = data['data']['email']['password']; + to_mail_addr = data['data']['email']['to_mail_addr']; - - var smtp_ssl = data['data']['email']['data']['smtp_ssl']; + var smtp_ssl = data['data']['email']['smtp_ssl']; if (smtp_ssl == 'ssl'){ smtp_ssl_no = ''; smtp_ssl_yes = 'checked'; @@ -742,13 +741,13 @@ function getEmailCfg(){ return false; } - $.post('/config/set_notify',{'tag':'email', 'data':JSON.stringify(pdata)},function(rdata){ + $.post('/setting/set_notify_email',{'tag':'email', 'data':JSON.stringify(pdata)},function(rdata){ showMsg(rdata.msg, function(){ if (rdata.status){ layer.close(index); } },{icon:rdata.status?1:2},2000); - }); + },'json'); }, btn3:function(index){ @@ -791,17 +790,17 @@ function getEmailCfg(){ layer.msg('验证测试不能为空!', {icon:2}); return false; } - $.post('/config/set_notify_test',{'tag':'email', 'data':JSON.stringify(pdata)},function(rdata){ + $.post('/setting/set_notify_email_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); - }); + },'json'); return false; } }); - }); + },'json'); } function getPanelSSL(){ diff --git a/web/templates/default/setting.html b/web/templates/default/setting.html index 588d1eeb0..1e908c07d 100755 --- a/web/templates/default/setting.html +++ b/web/templates/default/setting.html @@ -172,7 +172,7 @@

邮件通知 - + 邮件通知 diff --git a/web/utils/config.py b/web/utils/config.py index 89ffabb85..5d6737b2d 100644 --- a/web/utils/config.py +++ b/web/utils/config.py @@ -78,5 +78,9 @@ def getGlobalVar(): data['hook_menu'] = thisdb.getOptionByJson('hook_menu',type='hook',default=[]) data['hook_global_static'] = thisdb.getOptionByJson('hook_global_static',type='hook',default=[]) + + + # 邮件通知设置 + data['notify_email'] = thisdb.getOptionByJson('notify_email', default={'open':False}, type='notify') return data \ No newline at end of file