From f0e1c2afc857d4bb8cf358bdc4eb584ceea0fa36 Mon Sep 17 00:00:00 2001 From: Apex Liu Date: Sun, 5 Nov 2017 15:08:26 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E8=AE=BE=E7=BD=AE-=E5=AD=98?= =?UTF-8?q?=E5=82=A8=E8=AE=BE=E7=BD=AE=E5=8A=9F=E8=83=BD=E5=AE=8C=E6=88=90?= =?UTF-8?q?=EF=BC=8C=E5=AD=98=E5=82=A8=E7=A9=BA=E9=97=B4=E6=B8=85=E7=90=86?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E5=AE=8C=E6=88=90=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../www/teleport/static/js/system/config.js | 168 +++++++++- server/www/teleport/view/system/config.mako | 302 ++++++++++-------- .../www/teleport/webroot/app/base/configs.py | 4 + .../webroot/app/controller/__init__.py | 6 +- .../teleport/webroot/app/controller/record.py | 238 -------------- .../teleport/webroot/app/controller/system.py | 122 ++++--- .../www/teleport/webroot/app/model/record.py | 175 +++++++--- 7 files changed, 538 insertions(+), 477 deletions(-) delete mode 100644 server/www/teleport/webroot/app/controller/record.py diff --git a/server/www/teleport/static/js/system/config.js b/server/www/teleport/static/js/system/config.js index 77c75d8..05aedd7 100644 --- a/server/www/teleport/static/js/system/config.js +++ b/server/www/teleport/static/js/system/config.js @@ -3,18 +3,39 @@ $app.on_init = function (cb_stack) { console.log($app.options); - //========================================= - // 邮件系统配置相关 - //========================================= + $app.dlg_result = $app.create_dlg_result(); + // cb_stack.add($app.dlg_result.init); + $app.smtp = $app.create_config_smtp(); cb_stack.add($app.smtp.init); $app.sec = $app.create_config_sec(); cb_stack.add($app.sec.init); + $app.storage = $app.create_config_storage(); + cb_stack.add($app.storage.init); + cb_stack.exec(); }; +$app.create_dlg_result = function () { + var _dlg = {}; + + _dlg.dom = { + dlg: $('#dlg-result'), + title: $('#dlg-result-title'), + msg: $('#dlg-result-msg') + }; + + _dlg.show = function(title, msg) { + _dlg.dom.title.text(title); + _dlg.dom.msg.html(msg); + _dlg.dom.dlg.modal(); + }; + + return _dlg; +}; + $app.create_config_smtp = function () { var _smtp = {}; @@ -25,7 +46,7 @@ $app.create_config_smtp = function () { sender: $('#smtp-sender-info'), btn_edit: $('#btn-edit-mail-config'), - dlg_edit: $('#dlg-edit-mail-config'), + dlg_edit: $('#dlg-edit-smtp-config'), input_server: $('#edit-smtp-server'), input_port: $('#edit-smtp-port'), input_ssl: $('#edit-smtp-ssl'), @@ -361,3 +382,142 @@ $app.create_config_sec = function () { return _sec; }; + +$app.create_config_storage = function () { + var _sto = {}; + + _sto.dom = { + storage_size: $('#storage-size'), + btn_save: $('#btn-save-storage-config'), + btn_cleanup: $('#btn-clear-storage'), + + input_keep_log: $('#storage-keep-log'), + input_keep_record: $('#storage-keep-record'), + select_cleanup_hour: $('#select-cleanup-storage-hour'), + select_cleanup_minute: $('#select-cleanup-storage-minute') + }; + + _sto.init = function (cb_stack) { + // 当前会话录像存储空间:总 123.35GB,可用空间 85.17GB。 + var _info = []; + if (!$app.options.core_cfg.detected) { + _sto.dom.storage_size.removeClass().addClass('alert alert-danger'); + _info.push('未能连接到核心服务,无法获取存储空间信息!'); + } else { + _sto.dom.storage_size.removeClass().addClass('alert alert-info'); + _info.push('

会话录像存储路径:' + $app.options.core_cfg.replay_path + '

'); + _info.push('

会话录像存储空间:总 ' + tp_size2str($app.options.total_size, 2) + ',' + '可用 ' + tp_size2str($app.options.free_size, 2) + '。

'); + } + _sto.dom.storage_size.html(_info.join('')); + + _sto.update_dom($app.options.sys_cfg.storage); + + _sto.dom.btn_save.click(function () { + _sto.on_btn_save(); + }); + _sto.dom.btn_cleanup.click(function () { + _sto.on_btn_cleanup(); + }); + + cb_stack.exec(); + }; + + _sto.update_dom = function (storage) { + _sto.dom.input_keep_log.val(storage.keep_log); + _sto.dom.input_keep_record.val(storage.keep_record); + _sto.dom.select_cleanup_hour.val(storage.cleanup_hour); + _sto.dom.select_cleanup_minute.val(storage.cleanup_minute); + }; + + _sto.on_btn_save = function () { + var _keep_log = parseInt(_sto.dom.input_keep_log.val()); + var _keep_record = parseInt(_sto.dom.input_keep_record.val()); + + var _cleanup_hour = parseInt(_sto.dom.select_cleanup_hour.val()); + var _cleanup_minute = parseInt(_sto.dom.select_cleanup_minute.val()); + + if (!(_keep_log === 0 || (_keep_log >= 30 && _keep_log <= 180))) { + $tp.notify_error('日志保留时间超出范围!'); + _sto.dom.input_keep_log.focus(); + return; + } + if (!(_keep_record === 0 || (_keep_record >= 30 && _keep_record <= 180))) { + $tp.notify_error('会话录像保留时间超出范围!'); + _sto.dom.input_keep_record.focus(); + return; + } + + _sto.dom.btn_save.attr('disabled', 'disabled'); + $tp.ajax_post_json('/system/save-cfg', + { + storage: { + keep_log: _keep_log, + keep_record: _keep_record, + cleanup_hour: _cleanup_hour, + cleanup_minute: _cleanup_minute + } + }, + function (ret) { + _sto.dom.btn_save.removeAttr('disabled'); + if (ret.code === TPE_OK) { + $tp.notify_success('存储设置更新成功!'); + + // 更新一下界面上显示的配置信息 + $app.options.sys_cfg.storage.keep_log = _keep_log; + $app.options.sys_cfg.storage.keep_record = _keep_record; + $app.options.sys_cfg.storage.cleanup_hour = _cleanup_hour; + $app.options.sys_cfg.storage.cleanup_minute = _cleanup_minute; + + _sto.update_dom($app.options.sys_cfg.storage); + } else { + $tp.notify_error('存储设置更新失败:' + tp_error_msg(ret.code, ret.message)); + } + }, + function () { + _sto.dom.btn_save.removeAttr('disabled'); + $tp.notify_error('网路故障,存储设置更新失败!'); + } + ); + }; + + _sto.on_btn_cleanup = function () { + var _keep_log = parseInt(_sto.dom.input_keep_log.val()); + var _keep_record = parseInt(_sto.dom.input_keep_record.val()); + + if($app.options.sys_cfg.storage.keep_log !== _keep_log || $app.options.sys_cfg.storage.keep_record !== _keep_record) { + $tp.notify_error('您已经修改了设置,请先保存设置,再进行清理!'); + return; + } + if($app.options.sys_cfg.storage.keep_log === 0 && $app.options.sys_cfg.storage.keep_record === 0) { + $tp.notify_error('根据设置,没有需要清理的内容!'); + return; + } + + _sto.dom.btn_cleanup.attr('disabled', 'disabled'); + $tp.ajax_post_json('/system/cleanup-storage', {}, + function (ret) { + _sto.dom.btn_cleanup.removeAttr('disabled'); + if (ret.code === TPE_OK) { + console.log(ret); + $tp.notify_success('清理存储空间成功!'); + + var msg = []; + for(var i = 0; i < ret.data.length; ++i) { + msg.push('

'+ret.data[i]+'

'); + } + + $app.dlg_result.show('清理存储空间', msg.join('')); + } else { + $tp.notify_error('清理存储空间失败:' + tp_error_msg(ret.code, ret.message)); + } + }, + function () { + _sto.dom.btn_cleanup.removeAttr('disabled'); + $tp.notify_error('网路故障,清理存储空间失败!'); + }, + 120000 + ); + }; + + return _sto; +}; diff --git a/server/www/teleport/view/system/config.mako b/server/www/teleport/view/system/config.mako index 0157781..b0cda74 100644 --- a/server/www/teleport/view/system/config.mako +++ b/server/www/teleport/view/system/config.mako @@ -20,7 +20,7 @@
  • 安全
  • 邮件系统
  • 存储
  • -##
  • 备份
  • + ##
  • 备份
  • @@ -137,7 +137,7 @@
    -
    当前会话录像存储空间:总 123.35GB,可用空间 85.17GB。
    +
    -
    @@ -171,46 +171,46 @@
    系统日志
    时间点 - + + + + + + + + + + + + + + + + + + + + + + + + 时 - + + + + + + + + + + + + 每天在指定时间点清理存储。 @@ -219,122 +219,122 @@
    - +

    -## + ##
    -##
    -##
    备份功能尚未实现
    -## -## -## -## -## -## -## -## -## -## -## -## -## -## -## -## -## -## -## -## -## -## -## -## -## -## -## -## -## -## -## -## -## -## -##
    数据库备份
    备份范围 -##
    包括系统日志
    -##
    -##
    包括报警日志
    -##
    -##
    包括运维记录
    -##
    自动备份 -##
    在指定时间点自动备份数据库
    -##
    备份时间点 -## -## 时 -## -## 分 -## 每天在指定时间点备份数据库。 -##
    备份保留时长 -## 1~7。超过设定时间的备份将自动删除,默认为7天。 -##
    -## 下载自动备份文件 -##
    -##
    -## -## -## -##
    + ##
    + ##
    备份功能尚未实现
    + ## + ## + ## + ## + ## + ## + ## + ## + ## + ## + ## + ## + ## + ## + ## + ## + ## + ## + ## + ## + ## + ## + ## + ## + ## + ## + ## + ## + ## + ## + ## + ## + ## + ## + ##
    数据库备份
    备份范围 + ##
    包括系统日志
    + ##
    + ##
    包括报警日志
    + ##
    + ##
    包括运维记录
    + ##
    自动备份 + ##
    在指定时间点自动备份数据库
    + ##
    备份时间点 + ## + ## 时 + ## + ## 分 + ## 每天在指定时间点备份数据库。 + ##
    备份保留时长 + ## 1~7。超过设定时间的备份将自动删除,默认为7天。 + ##
    + ## 下载自动备份文件 + ##
    + ##
    + ## + ## + ## + ##
    <%block name="extend_content"> - -