mirror of https://github.com/tp4a/teleport
temp.
parent
333c244379
commit
f5392091f9
|
@ -1,6 +1,8 @@
|
|||
"use strict";
|
||||
|
||||
$app.on_init = function () {
|
||||
$app.on_init = function (cb_stack) {
|
||||
console.log($app.options);
|
||||
|
||||
$app.dom = {
|
||||
|
||||
// 邮件系统设置
|
||||
|
@ -24,175 +26,256 @@ $app.on_init = function () {
|
|||
}
|
||||
};
|
||||
|
||||
// $app.dom.tmp_oath_secret.text($app.page_options.tmp_oath_secret);
|
||||
$app.smtp = $app.create_config_smtp();
|
||||
cb_stack.add($app.smtp.init);
|
||||
|
||||
//=========================================
|
||||
// 邮件系统配置相关
|
||||
//=========================================
|
||||
$app.update_mail_info = function (smtp_info) {
|
||||
var not_set = '<span class="error">未设置</span>';
|
||||
if (0 === smtp_info.server.length)
|
||||
$app.dom.mail.smtp_server.html(not_set);
|
||||
else
|
||||
$app.dom.mail.smtp_server.html(smtp_info.server);
|
||||
// $app.update_mail_info = function (smtp) {
|
||||
// if (0 === smtp.server.length) {
|
||||
// var not_set = '<span class="error">未设置</span>';
|
||||
// $app.dom.mail.smtp_server.html(not_set);
|
||||
// $app.dom.mail.smtp_port.html(not_set);
|
||||
// $app.dom.mail.smtp_ssl.html(not_set);
|
||||
// $app.dom.mail.smtp_sender.html(not_set);
|
||||
// } else {
|
||||
// $app.dom.mail.smtp_server.html(smtp.server);
|
||||
// $app.dom.mail.smtp_port.html(smtp.port);
|
||||
// $app.dom.mail.smtp_sender.html(smtp.sender);
|
||||
//
|
||||
// if (smtp.ssl)
|
||||
// $app.dom.mail.smtp_ssl.html('是');
|
||||
// else
|
||||
// $app.dom.mail.smtp_ssl.html('否');
|
||||
// }
|
||||
// };
|
||||
//
|
||||
// $app.update_mail_info($app.options.sys_cfg.smtp);
|
||||
|
||||
if (-1 === smtp_info.port)
|
||||
$app.dom.mail.smtp_port.html(not_set);
|
||||
else
|
||||
$app.dom.mail.smtp_port.html(smtp_info.port);
|
||||
// $app.dom.mail.btn_edit_mail_config.click(function () {
|
||||
// var smtp = $app.options.sys_cfg.smtp;
|
||||
//
|
||||
// $app.dom.mail.edit_smtp_server.val(smtp.server);
|
||||
//
|
||||
// $app.dom.mail.edit_smtp_port.val(smtp.port);
|
||||
//
|
||||
// if (!smtp.ssl)
|
||||
// $app.dom.mail.edit_smtp_ssl.removeClass('tp-selected');
|
||||
// else
|
||||
// $app.dom.mail.edit_smtp_ssl.removeClass('tp-selected').addClass('tp-selected');
|
||||
//
|
||||
// $app.dom.mail.edit_smtp_sender.val(smtp.sender);
|
||||
// $app.dom.mail.edit_smtp_password.val('');
|
||||
//
|
||||
// $app.dom.mail.dlg_edit_mail_config.modal();
|
||||
// });
|
||||
// $app.dom.mail.btn_edit_mail_config.trigger('click');
|
||||
// $app.dom.mail.edit_smtp_ssl.click(function () {
|
||||
// if ($app.dom.mail.edit_smtp_ssl.hasClass('tp-selected'))
|
||||
// $app.dom.mail.edit_smtp_ssl.removeClass('tp-selected');
|
||||
// else
|
||||
// $app.dom.mail.edit_smtp_ssl.addClass('tp-selected');
|
||||
// });
|
||||
// $app.dom.mail.btn_send_test_mail.click($app._on_btn_send_test_mail);
|
||||
// $app.dom.mail.btn_save_mail_config.click($app._on_btn_save_mail_config);
|
||||
|
||||
if (-1 === smtp_info.ssl)
|
||||
$app.dom.mail.smtp_ssl.html(not_set);
|
||||
else if (0 === smtp_info.ssl)
|
||||
$app.dom.mail.smtp_ssl.html('否');
|
||||
else
|
||||
$app.dom.mail.smtp_ssl.html('是');
|
||||
cb_stack.exec();
|
||||
};
|
||||
|
||||
if (0 === smtp_info.sender.length)
|
||||
$app.dom.mail.smtp_sender.html(not_set);
|
||||
else
|
||||
$app.dom.mail.smtp_sender.html(smtp_info.sender);
|
||||
$app.create_config_smtp = function () {
|
||||
var _smtp = {};
|
||||
|
||||
_smtp.dom = {
|
||||
server: $('#smtp-server-info'),
|
||||
port: $('#smtp-port-info'),
|
||||
ssl: $('#smtp-ssl-info'),
|
||||
sender: $('#smtp-sender-info'),
|
||||
btn_edit: $('#btn-edit-mail-config'),
|
||||
|
||||
dlg_edit: $('#dlg-edit-mail-config'),
|
||||
input_server: $('#edit-smtp-server'),
|
||||
input_port: $('#edit-smtp-port'),
|
||||
input_ssl: $('#edit-smtp-ssl'),
|
||||
input_sender: $('#edit-smtp-sender'),
|
||||
input_password: $('#edit-smtp-password'),
|
||||
input_recipient: $('#edit-smtp-test-recipient'),
|
||||
btn_send: $('#btn-send-test-mail'),
|
||||
msg_send: $('#msg-send-test-mail'),
|
||||
btn_save: $('#btn-save-mail-config')
|
||||
};
|
||||
|
||||
$app.update_mail_info($app.options.sys_cfg.smtp);
|
||||
_smtp.init = function (cb_stack) {
|
||||
_smtp.update_dom($app.options.sys_cfg.smtp);
|
||||
|
||||
$app.dom.mail.btn_edit_mail_config.click(function () {
|
||||
var smtp_info = $app.options.sys_cfg.smtp;
|
||||
_smtp.dom.btn_edit.click(function () {
|
||||
_smtp.on_edit();
|
||||
});
|
||||
_smtp.dom.btn_send.click(function () {
|
||||
_smtp.on_btn_send();
|
||||
});
|
||||
_smtp.dom.btn_save.click(function () {
|
||||
_smtp.on_btn_save();
|
||||
});
|
||||
_smtp.dom.input_ssl.click(function () {
|
||||
if ($(this).hasClass('tp-selected'))
|
||||
$(this).removeClass('tp-selected');
|
||||
else
|
||||
$(this).addClass('tp-selected');
|
||||
});
|
||||
|
||||
$app.dom.mail.edit_smtp_server.val(smtp_info.server);
|
||||
cb_stack.exec();
|
||||
};
|
||||
|
||||
if(smtp_info.port === -1)
|
||||
$app.dom.mail.edit_smtp_port.val('');
|
||||
else
|
||||
$app.dom.mail.edit_smtp_port.val(smtp_info.port);
|
||||
|
||||
if (-1 === smtp_info.ssl || 0 === smtp_info.ssl)
|
||||
$app.dom.mail.edit_smtp_ssl.removeClass('tp-selected');
|
||||
else
|
||||
$app.dom.mail.edit_smtp_ssl.removeClass('tp-selected').addClass('tp-selected');
|
||||
|
||||
$app.dom.mail.edit_smtp_sender.val(smtp_info.sender);
|
||||
$app.dom.mail.edit_smtp_password.val('');
|
||||
|
||||
$app.dom.mail.dlg_edit_mail_config.modal();
|
||||
});
|
||||
// $app.dom.mail.btn_edit_mail_config.trigger('click');
|
||||
$app.dom.mail.edit_smtp_ssl.click(function () {
|
||||
if ($app.dom.mail.edit_smtp_ssl.hasClass('tp-selected'))
|
||||
$app.dom.mail.edit_smtp_ssl.removeClass('tp-selected');
|
||||
else
|
||||
$app.dom.mail.edit_smtp_ssl.addClass('tp-selected');
|
||||
});
|
||||
$app.dom.mail.btn_send_test_mail.click($app._on_btn_send_test_mail);
|
||||
$app.dom.mail.btn_save_mail_config.click($app._on_btn_save_mail_config);
|
||||
};
|
||||
|
||||
$app._edit_mail_config_check = function (_server, _port, _sender, _password) {
|
||||
if(_server.length === 0) {
|
||||
$app.dom.mail.edit_smtp_server.focus();
|
||||
$tp.notify_error('请填写SMTP服务器地址!');
|
||||
return false;
|
||||
}
|
||||
if(_port.length === 0) {
|
||||
$app.dom.mail.edit_smtp_port.focus();
|
||||
$tp.notify_error('请填写SMTP服务器端口!');
|
||||
return false;
|
||||
}
|
||||
if(_sender.length === 0) {
|
||||
$app.dom.mail.edit_smtp_sender.focus();
|
||||
$tp.notify_error('请填写发件人邮箱!');
|
||||
return false;
|
||||
}
|
||||
if(_password.length === 0) {
|
||||
$app.dom.mail.edit_smtp_password.focus();
|
||||
$tp.notify_error('请填写发件人邮箱密码!');
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
$app._on_btn_send_test_mail = function () {
|
||||
var _server = $app.dom.mail.edit_smtp_server.val();
|
||||
var _port = $app.dom.mail.edit_smtp_port.val();
|
||||
var _sender = $app.dom.mail.edit_smtp_sender.val();
|
||||
var _password = $app.dom.mail.edit_smtp_password.val();
|
||||
var _recipient = $app.dom.mail.edit_smtp_test_recipient.val();
|
||||
var _ssl = ($app.dom.mail.edit_smtp_ssl.hasClass('tp-selected')) ? 1 : 0;
|
||||
|
||||
if(!$app._edit_mail_config_check(_server, _port, _sender, _password))
|
||||
return;
|
||||
if(_recipient.length === 0) {
|
||||
$app.dom.mail.edit_smtp_test_recipient.focus();
|
||||
$tp.notify_error('请填写测试收件人邮箱!');
|
||||
return;
|
||||
}
|
||||
|
||||
$app.dom.mail.btn_send_test_mail.attr('disabled', 'disabled');
|
||||
|
||||
$tp.ajax_post_json('/system/send-test-mail',
|
||||
{
|
||||
smtp_server: _server,
|
||||
smtp_port: _port,
|
||||
smtp_ssl: _ssl,
|
||||
smtp_sender: _sender,
|
||||
smtp_password: _password,
|
||||
smtp_recipient: _recipient
|
||||
},
|
||||
function (ret) {
|
||||
$app.dom.mail.btn_send_test_mail.removeAttr('disabled');
|
||||
if (ret.code === TPE_OK) {
|
||||
$app.dom.mail.msg_send_test_mail.slideDown('fast');
|
||||
} else {
|
||||
$tp.notify_error(tp_error_msg(ret.code, ret.message));
|
||||
}
|
||||
},
|
||||
function () {
|
||||
$app.dom.mail.btn_send_test_mail.removeAttr('disabled');
|
||||
$tp.notify_error('网路故障,无法连接到服务器!');
|
||||
},
|
||||
15000
|
||||
);
|
||||
};
|
||||
|
||||
$app._on_btn_save_mail_config = function () {
|
||||
var _server = $app.dom.mail.edit_smtp_server.val();
|
||||
var _port = $app.dom.mail.edit_smtp_port.val();
|
||||
var _sender = $app.dom.mail.edit_smtp_sender.val();
|
||||
var _password = $app.dom.mail.edit_smtp_password.val();
|
||||
var _ssl = ($app.dom.mail.edit_smtp_ssl.hasClass('tp-selected')) ? 1 : 0;
|
||||
|
||||
if(!$app._edit_mail_config_check(_server, _port, _sender, _password))
|
||||
return;
|
||||
|
||||
$app.dom.mail.btn_save_mail_config.attr('disabled', 'disabled');
|
||||
$tp.ajax_post_json('/system/save-smtp-config',
|
||||
{
|
||||
smtp_server: _server,
|
||||
smtp_port: _port,
|
||||
smtp_ssl: _ssl,
|
||||
smtp_sender: _sender,
|
||||
smtp_password: _password
|
||||
},
|
||||
function (ret) {
|
||||
$app.dom.mail.btn_save_mail_config.removeAttr('disabled');
|
||||
if (ret.code === TPE_OK) {
|
||||
$app.dom.mail.edit_smtp_password.val('');
|
||||
// 更新一下界面上显示的配置信息
|
||||
$app.options.sys_cfg.smtp.server = _server;
|
||||
$app.options.sys_cfg.smtp.port = _port;
|
||||
$app.options.sys_cfg.smtp.ssl = _ssl;
|
||||
$app.options.sys_cfg.smtp.sender = _sender;
|
||||
$app.update_mail_info($app.options.sys_cfg.smtp);
|
||||
|
||||
$app.dom.mail.dlg_edit_mail_config.modal('hide');
|
||||
} else {
|
||||
$tp.notify_error(tp_error_msg(ret.code, ret.message));
|
||||
}
|
||||
},
|
||||
function () {
|
||||
$app.dom.mail.btn_save_mail_config.removeAttr('disabled');
|
||||
$tp.notify_error('网路故障,无法连接到服务器!');
|
||||
_smtp.update_dom = function (smtp) {
|
||||
if (0 === smtp.server.length) {
|
||||
var not_set = '<span class="error">未设置</span>';
|
||||
_smtp.dom.server.html(not_set);
|
||||
_smtp.dom.port.html(not_set);
|
||||
_smtp.dom.ssl.html(not_set);
|
||||
_smtp.dom.sender.html(not_set);
|
||||
} else {
|
||||
_smtp.dom.server.html(smtp.server);
|
||||
_smtp.dom.port.html(smtp.port);
|
||||
_smtp.dom.sender.html(smtp.sender);
|
||||
_smtp.dom.ssl.html(smtp.ssl ? '是' : '否');
|
||||
//
|
||||
// if (smtp.ssl)
|
||||
// _smtp.dom.ssl.html('是');
|
||||
// else
|
||||
// _smtp.dom.ssl.html('否');
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
_smtp.on_edit = function () {
|
||||
var smtp = $app.options.sys_cfg.smtp;
|
||||
|
||||
_smtp.dom.input_server.val(smtp.server);
|
||||
|
||||
_smtp.dom.input_port.val(smtp.port);
|
||||
|
||||
if (!smtp.ssl)
|
||||
_smtp.dom.input_ssl.removeClass('tp-selected');
|
||||
else
|
||||
_smtp.dom.input_ssl.removeClass('tp-selected').addClass('tp-selected');
|
||||
|
||||
_smtp.dom.input_sender.val(smtp.sender);
|
||||
_smtp.dom.input_password.val('');
|
||||
|
||||
_smtp.dom.dlg_edit.modal();
|
||||
};
|
||||
|
||||
_smtp._check_input = function (_server, _port, _sender, _password) {
|
||||
if (_server.length === 0) {
|
||||
_smtp.dom.input_server.focus();
|
||||
$tp.notify_error('请填写SMTP服务器地址!');
|
||||
return false;
|
||||
}
|
||||
if (_port.length === 0) {
|
||||
_smtp.dom.input_port.focus();
|
||||
$tp.notify_error('请填写SMTP服务器端口!');
|
||||
return false;
|
||||
}
|
||||
if (_sender.length === 0) {
|
||||
_smtp.dom.input_sender.focus();
|
||||
$tp.notify_error('请填写发件人邮箱!');
|
||||
return false;
|
||||
}
|
||||
if (_password.length === 0) {
|
||||
_smtp.dom.input_password.focus();
|
||||
$tp.notify_error('请填写发件人邮箱密码!');
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
_smtp.on_btn_send = function () {
|
||||
var _server = _smtp.dom.input_server.val();
|
||||
var _port = _smtp.dom.input_port.val();
|
||||
var _sender = _smtp.dom.input_sender.val();
|
||||
var _password = _smtp.dom.input_password.val();
|
||||
var _recipient = _smtp.dom.input_recipient.val();
|
||||
var _ssl = _smtp.dom.input_ssl.hasClass('tp-selected');
|
||||
|
||||
if (!_smtp._check_input(_server, _port, _sender, _password))
|
||||
return;
|
||||
if (_recipient.length === 0) {
|
||||
_smtp.dom.input_recipient.focus();
|
||||
$tp.notify_error('请填写测试收件人邮箱!');
|
||||
return;
|
||||
}
|
||||
|
||||
_smtp.dom.btn_send.attr('disabled', 'disabled');
|
||||
|
||||
$tp.ajax_post_json('/system/send-test-mail',
|
||||
{
|
||||
server: _server,
|
||||
port: _port,
|
||||
ssl: _ssl,
|
||||
sender: _sender,
|
||||
password: _password,
|
||||
recipient: _recipient
|
||||
},
|
||||
function (ret) {
|
||||
_smtp.dom.btn_send.removeAttr('disabled');
|
||||
if (ret.code === TPE_OK) {
|
||||
_smtp.dom.msg_send.slideDown('fast');
|
||||
} else {
|
||||
$tp.notify_error(tp_error_msg(ret.code, ret.message));
|
||||
}
|
||||
},
|
||||
function () {
|
||||
_smtp.dom.btn_send.removeAttr('disabled');
|
||||
$tp.notify_error('网路故障,无法连接到服务器!');
|
||||
},
|
||||
15000
|
||||
);
|
||||
};
|
||||
|
||||
_smtp.on_btn_save = function () {
|
||||
var _server = _smtp.dom.input_server.val();
|
||||
var _port = _smtp.dom.input_port.val();
|
||||
var _sender = _smtp.dom.input_sender.val();
|
||||
var _password = _smtp.dom.input_password.val();
|
||||
var _ssl = _smtp.dom.input_ssl.hasClass('tp-selected');
|
||||
|
||||
if (!_smtp._check_input(_server, _port, _sender, _password))
|
||||
return;
|
||||
|
||||
_smtp.dom.btn_save.attr('disabled', 'disabled');
|
||||
$tp.ajax_post_json('/system/save-cfg-smtp',
|
||||
{
|
||||
server: _server,
|
||||
port: _port,
|
||||
ssl: _ssl,
|
||||
sender: _sender,
|
||||
password: _password
|
||||
},
|
||||
function (ret) {
|
||||
_smtp.dom.btn_save.removeAttr('disabled');
|
||||
if (ret.code === TPE_OK) {
|
||||
_smtp.dom.input_password.val('');
|
||||
// 更新一下界面上显示的配置信息
|
||||
$app.options.sys_cfg.smtp.server = _server;
|
||||
$app.options.sys_cfg.smtp.port = _port;
|
||||
$app.options.sys_cfg.smtp.ssl = _ssl;
|
||||
$app.options.sys_cfg.smtp.sender = _sender;
|
||||
_smtp.update_dom($app.options.sys_cfg.smtp);
|
||||
|
||||
_smtp.dom.dlg_edit.modal('hide');
|
||||
} else {
|
||||
$tp.notify_error(tp_error_msg(ret.code, ret.message));
|
||||
}
|
||||
},
|
||||
function () {
|
||||
_smtp.dom.btn_save.removeAttr('disabled');
|
||||
$tp.notify_error('网路故障,无法连接到服务器!');
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
return _smtp;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -2,10 +2,11 @@
|
|||
|
||||
import configparser
|
||||
import os
|
||||
import json
|
||||
|
||||
from app.const import *
|
||||
from .logger import log
|
||||
from .utils import AttrDict, tp_make_dir
|
||||
from .utils import AttrDict, tp_convert_to_attr_dict, tp_make_dir
|
||||
|
||||
__all__ = ['get_cfg']
|
||||
|
||||
|
@ -451,79 +452,93 @@ class AppConfig(BaseAppConfig):
|
|||
def update_sys(self, conf_data):
|
||||
self.sys = AttrDict()
|
||||
self.sys.loaded = False
|
||||
self.sys_smtp_password = ''
|
||||
|
||||
if conf_data is None:
|
||||
log.w('system default config info is empty.\n')
|
||||
return True
|
||||
|
||||
# =====================================
|
||||
# 密码策略相关
|
||||
# =====================================
|
||||
# conf_data['password'] = '{"find":false,"strong":true}'
|
||||
try:
|
||||
# =====================================
|
||||
# 密码策略相关
|
||||
# =====================================
|
||||
self.sys.password = AttrDict()
|
||||
_password = json.loads(conf_data['password'])
|
||||
except:
|
||||
log.w('invalid password config, use default.\n')
|
||||
_password = {}
|
||||
|
||||
self.sys.password = tp_convert_to_attr_dict(_password)
|
||||
if not self.sys.password.is_exists('find'):
|
||||
self.sys.password.find = True
|
||||
if not self.sys.password.is_exists('strong'):
|
||||
self.sys.password.strong = True
|
||||
self.sys.password.timeout = 30 # 30 days
|
||||
if 'password_find' in conf_data:
|
||||
self.sys.password.find = conf_data['password_find']
|
||||
if 'password_strong' in conf_data:
|
||||
self.sys.password.strong = conf_data['password_strong']
|
||||
if 'password_timeout' in conf_data:
|
||||
self.sys.password.timeout = int(conf_data['password_timeout'])
|
||||
if not self.sys.password.is_exists('timeout'):
|
||||
self.sys.password.timeout = 30
|
||||
|
||||
# =====================================
|
||||
# 登录相关
|
||||
# =====================================
|
||||
self.sys.login = AttrDict()
|
||||
# =====================================
|
||||
# 登录相关
|
||||
# =====================================
|
||||
try:
|
||||
_login = json.loads(conf_data['login'])
|
||||
except:
|
||||
log.w('invalid login config, use default.\n')
|
||||
_login = {}
|
||||
|
||||
self.sys.login = tp_convert_to_attr_dict(_login)
|
||||
if not self.sys.login.is_exists('session_timeout'):
|
||||
self.sys.login.session_timeout = 30
|
||||
if not self.sys.login.is_exists('retry'):
|
||||
self.sys.login.retry = 0
|
||||
if not self.sys.login.is_exists('lock_timeout'):
|
||||
self.sys.login.lock_timeout = 30 # 30 min
|
||||
if not self.sys.login.is_exists('auth'):
|
||||
self.sys.login.auth = TP_LOGIN_AUTH_USERNAME_PASSWORD | TP_LOGIN_AUTH_USERNAME_PASSWORD_CAPTCHA | TP_LOGIN_AUTH_USERNAME_OATH
|
||||
if 'login_session_timeout' in conf_data:
|
||||
self.sys.login.session_timeout = int(conf_data['login_session_timeout'])
|
||||
if 'login_retry' in conf_data:
|
||||
self.sys.login.retry = int(conf_data['login_retry'])
|
||||
if 'login_lock_timeout' in conf_data:
|
||||
self.sys.login.lock_timeout = int(conf_data['login_lock_timeout'])
|
||||
if 'login_auth' in conf_data:
|
||||
self.sys.login.auth = int(conf_data['login_auth'])
|
||||
# print('==login==', json.dumps(self.sys.login, separators=(',', ':')))
|
||||
|
||||
# =====================================
|
||||
# SMTP相关
|
||||
# =====================================
|
||||
self.sys.smtp = AttrDict()
|
||||
self.sys.smtp.server = ""
|
||||
# =====================================
|
||||
# SMTP相关
|
||||
# =====================================
|
||||
self.sys_smtp_password = ''
|
||||
try:
|
||||
_smtp = json.loads(conf_data['smtp'])
|
||||
except:
|
||||
log.w('invalid smtp config, use default.\n')
|
||||
_smtp = {}
|
||||
|
||||
self.sys.smtp = tp_convert_to_attr_dict(_smtp)
|
||||
if not self.sys.smtp.is_exists('server'):
|
||||
self.sys.smtp.server = ''
|
||||
if not self.sys.smtp.is_exists('port'):
|
||||
self.sys.smtp.port = 25
|
||||
if not self.sys.smtp.is_exists('ssl'):
|
||||
self.sys.smtp.ssl = False
|
||||
self.sys.smtp.sender = ""
|
||||
if 'smtp_server' in conf_data:
|
||||
self.sys.smtp.server = conf_data['smtp_server']
|
||||
if 'smtp_port' in conf_data:
|
||||
self.sys.smtp.port = int(conf_data['smtp_port'])
|
||||
if 'smtp_ssl' in conf_data:
|
||||
self.sys.smtp.ssl = int(conf_data['smtp_ssl'])
|
||||
if 'smtp_sender' in conf_data:
|
||||
self.sys.smtp.sender = conf_data['smtp_sender']
|
||||
if 'smtp_password' in conf_data:
|
||||
self.sys_smtp_password = conf_data['smtp_password']
|
||||
if not self.sys.smtp.is_exists('sender'):
|
||||
self.sys.smtp.sender = ''
|
||||
if self.sys.smtp.is_exists('password'):
|
||||
self.sys_smtp_password = self.sys.smtp.password
|
||||
self.sys.smtp.password = '********'
|
||||
# del self.sys.smtp.password
|
||||
|
||||
# =====================================
|
||||
# 存储相关
|
||||
# =====================================
|
||||
self.sys.storage = AttrDict()
|
||||
self.sys.storage.log = 0
|
||||
self.sys.storage.record = 0
|
||||
if 'storage_log' in conf_data:
|
||||
self.sys.storage.log = int(conf_data['storage_log'])
|
||||
if 'storage_record' in conf_data:
|
||||
self.sys.storage.record = int(conf_data['storage_record'])
|
||||
# =====================================
|
||||
# 存储相关
|
||||
# =====================================
|
||||
try:
|
||||
_storage = json.loads(conf_data['storage'])
|
||||
except:
|
||||
log.w('invalid storage config, use default.\n')
|
||||
_storage = {}
|
||||
|
||||
self.sys.loaded = True
|
||||
self.sys.storage = tp_convert_to_attr_dict(_storage)
|
||||
if not self.sys.storage.is_exists('keep_log'):
|
||||
self.sys.storage.keep_log = 0
|
||||
if not self.sys.storage.is_exists('keep_record'):
|
||||
self.sys.storage.keep_record = 0
|
||||
|
||||
except IndexError:
|
||||
log.e('invalid system default config.\n')
|
||||
return False
|
||||
self.sys.loaded = True
|
||||
|
||||
# except IndexError:
|
||||
# log.e('invalid system default config.\n')
|
||||
# return False
|
||||
|
||||
return True
|
||||
|
||||
|
|
|
@ -25,6 +25,25 @@ class AttrDict(dict):
|
|||
def __setattr__(self, name, val):
|
||||
self[name] = val
|
||||
|
||||
def is_exists(self, name):
|
||||
try:
|
||||
self.__getattr__(name)
|
||||
return True
|
||||
except AttributeError:
|
||||
return False
|
||||
|
||||
|
||||
def tp_convert_to_attr_dict(d):
|
||||
if type(d) is not dict:
|
||||
return None
|
||||
ret = AttrDict()
|
||||
for k in d:
|
||||
if type(d[k]) is dict:
|
||||
ret[k] = tp_convert_to_attr_dict(d[k])
|
||||
else:
|
||||
ret[k] = d[k]
|
||||
return ret
|
||||
|
||||
|
||||
def tp_make_dir(path):
|
||||
"""
|
||||
|
|
|
@ -220,7 +220,7 @@ controllers = [
|
|||
# - [json] 系统配置-发送测试邮件
|
||||
(r'/system/send-test-mail', system.DoSendTestMailHandler),
|
||||
# - [json] 系统配置-保存邮件系统配置
|
||||
(r'/system/save-smtp-config', system.DoSaveSmtpConfigHandler),
|
||||
(r'/system/save-cfg-smtp', system.DoSaveCfgSmtpHandler),
|
||||
|
||||
# - [json] 获取服务器时间
|
||||
(r'/system/get-time', system.DoGetTimeHandler),
|
||||
|
|
|
@ -198,12 +198,12 @@ class DoSendTestMailHandler(TPBaseJsonHandler):
|
|||
return self.write_json(TPE_JSON_FORMAT)
|
||||
|
||||
try:
|
||||
_server = args['smtp_server']
|
||||
_port = int(args['smtp_port'])
|
||||
_ssl = args['smtp_ssl']
|
||||
_sender = args['smtp_sender']
|
||||
_password = args['smtp_password']
|
||||
_recipient = args['smtp_recipient']
|
||||
_server = args['server']
|
||||
_port = int(args['port'])
|
||||
_ssl = args['ssl']
|
||||
_sender = args['sender']
|
||||
_password = args['password']
|
||||
_recipient = args['recipient']
|
||||
except:
|
||||
return self.write_json(TPE_PARAM)
|
||||
|
||||
|
@ -222,7 +222,7 @@ class DoSendTestMailHandler(TPBaseJsonHandler):
|
|||
self.write_json(code, message=msg)
|
||||
|
||||
|
||||
class DoSaveSmtpConfigHandler(TPBaseJsonHandler):
|
||||
class DoSaveCfgSmtpHandler(TPBaseJsonHandler):
|
||||
def post(self):
|
||||
ret = self.check_privilege(TP_PRIVILEGE_SYS_CONFIG)
|
||||
if ret != TPE_OK:
|
||||
|
@ -237,11 +237,11 @@ class DoSaveSmtpConfigHandler(TPBaseJsonHandler):
|
|||
return self.write_json(TPE_JSON_FORMAT)
|
||||
|
||||
try:
|
||||
_server = args['smtp_server']
|
||||
_port = int(args['smtp_port'])
|
||||
_ssl = args['smtp_ssl']
|
||||
_sender = args['smtp_sender']
|
||||
_password = args['smtp_password']
|
||||
_server = args['server']
|
||||
_port = int(args['port'])
|
||||
_ssl = args['ssl']
|
||||
_sender = args['sender']
|
||||
_password = args['password']
|
||||
except:
|
||||
return self.write_json(TPE_PARAM)
|
||||
|
||||
|
|
Loading…
Reference in New Issue