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