One Hat Cyber Team
  • Dir : ~/www/server/panel/BTPanel/static/vite/oldjs/
  • Edit File: firewall.js
    \
    \ \ \ \
    \
    ', success:function (layers,indexs){ $('.btn-copy-sshkey').on('click',function(){ bt.pub.copy_pass($('#ssh_text_key').val()); }) $('.btn-download-sshkey').on('click',function(){ window.open('/ssh_security?action=download_key') }) $('.btn-rebuild-sshkey').on('click',function(){ bt_tools.send({ url:'/ssh_security?action=set_sshkey', data:{ ssh:'yes', type:'ed25519' } },function (res){ bt_tools.send({ url:'/ssh_security?action=get_key' },function (rdata){ if(!rdata.msg) return layer.msg(lan.security.ssh.key_view_msg); $('#ssh_text_key').val(rdata.msg); if(res.status) bt_tools.msg({ msg: lan.security.ssh.get_key_msg, status: true }); _this.getSeniorSshInfo(); }) }, lan.security.ssh.get_key); }) } }) }, lan.security.ssh.get_key_req); }, /** * @description 设置SSH登录告警 */ setSshLoginAlarmView:function(){ var that = this; layer.open({ title: lan.security.ssh.alarm_title, area: '1010px', type: 1, closeBtn: 2, content: '\
    \
    \

    ' + lan.security.ssh.alarm_set + '

    \

    ' + lan.security.ssh.ip_white + '

    \
    \
    \
    \
    \
    \
    \
    \ \ \ \ \ \ \ \ \ \ \ \ \
    ' + lan.security.ssh.login_info + '' + lan.security.ssh.time + '
    ' + lan.site.data_empty + '
    \
    \
    \
    \
      \
    • \
    \
    \
    \
    \
    \ \ \
    \
    \
    \
      \
    • ' + lan.security.ssh.ip_white_tips + '
    • \
    \
    \
    \
    \
    ', success: function ($layer, indexs) { // layer var _that = this; // 切换菜单 $layer.find('.bt-w-menu p').click(function () { var index = $(this).index(); $(this).addClass('bgw').siblings('.bgw').removeClass('bgw'); $layer.find('.content_box').addClass('hide'); $layer.find('.content_box').eq(index).removeClass('hide'); switch (index) { // 登录日志 case 0: _that.renderAlarm(); _that.renderLogsTable(1, false); break; // IP白名单 case 1: _that.renderWhiteIpTable() break; } }); // 设置告警通知 $('.news-channel .bt-form-new').on('change', 'input[type="checkbox"]', function () { var $this = $(this); var name = $this.attr('name'); var checked = $this.is(':checked'); var action = checked ? 'set_login_send' : 'clear_login_send' bt_tools.send({ url: '/ssh_security?action=' + action, data:{ type: name } }, function (rdata) { bt_tools.msg(rdata); if (rdata.status) { if (checked) { $('.news-channel .bt-form-new input[type="checkbox"]').prop('checked', false); $this.prop('checked', true); } that.getSshLoginAlarmInfo(); } else { $this.prop('checked', !checked); } }, { verify: false, load: lan.security.ssh.login_send }); }); // 登录日志分页操作 $('#login_logs_table .page').on('click', 'a', function (e) { e.stopPropagation(); e.preventDefault(); var page = $(this) .attr('href') .match(/p=([0-9]*)/)[1]; _that.renderLogsTable(page); }); // 添加ip $('.addAddressIp').click(function () { var address = $('[name="ipAddress"]'); var ip = address.val(); address.val(''); if (!ip) { bt_tools.msg({ msg: lan.security.ssh.ip_white_input, status: false }); return; } bt_tools.send({ url:'/ssh_security?action=add_return_ip', data:{ ip: ip } }, function (rdata) { bt_tools.msg(rdata); _that.renderWhiteIpTable(); }, lan.security.ssh.add_return_ip); }); $layer.find('.bt-w-menu p').eq(0).click(); }, // 生成告警 renderAlarm: function () { // 获取告警列表 bt_tools.send({ url: '/ssh_security?action=get_msg_push_list', }, function (alarms) { // 获取选中告警 bt_tools.send({ url: '/ssh_security?action=get_login_send', }, function (send) { var html = ''; var tits = []; // 当前选中的告警key var cKey = send.msg; // 渲染生成告警列表 $.each(alarms, function (key, item) { if (item.name === 'sms') return; var checked = cKey === item.name ? 'checked="checked"' : ''; html += '\
    \
    Send to ' + item.title + '
    \
    \ \ \
    \
    '; tits.push(item.title); }); $('.news-channel .bt-form-new').html(html); $('.news-channel .help-info-text li').eq(0).text('Only one of the above options can be enabled simultaneously'); }); }, lan.security.ssh.get_msg_push_list); }, // 生成日志表格 renderLogsTable: function (p, load) { p = p || 1; load = load !== undefined ? load : true; if (load) var loadT = bt_tools.load(lan.security.ssh.get_logs); bt_tools.send({ url: '/ssh_security?action=get_logs', data: { p: p, p_size: 8, } }, function (rdata) { if (load) loadT.close(); var html = ''; if (rdata.data) { for (var i = 0; i < rdata.data.length; i++) { var item = rdata.data[i]; html += '' + item.log + '' + item.addtime + ''; } } html = html || '' + lan.site.data_empty + ''; $('#login_logs_table table tbody').html(html); $('#login_logs_table .page').html(rdata.page || ''); }); }, // 生成IP白名单表格 renderWhiteIpTable: function () { var _that = this; if (this.ipTable) { this.ipTable.$refresh_table_list(); return; } this.ipTable = bt_tools.table({ el: '#whiteIpTable', url: '/ssh_security?action=return_ip', autoHeight: true, height: '425px', default: lan.security.ssh.return_ip_default, dataFilter: function (data) { return { data: data.msg }; }, column: [ { title: 'IP', template: function (item) { return ''+ item + ''; } }, { title: lan.public.operate, type: 'group', width: 150, align: 'right', group: [ { title: lan.public.del, event: function (row, index) { bt_tools.send({ url: '/ssh_security?action=del_return_ip', data: { ip: row } },function (rdata){ bt_tools.msg(rdata) _that.renderWhiteIpTable(); }, lan.security.ssh.del_return_ip); } } ] } ] }); } }); } } // 入侵防御 var intrusion = { init: function () { $('.state-content').hide(); bt.soft.get_soft_find('bt_security', function (rdata) { // 判断插件未安装 && 插件是否过期 if (!rdata.setup && rdata.endtime > -1) { $('.buyIntrusion').hide(); } // 判断插件已安装 && 插件是否过期 if ((rdata.setup && rdata.endtime > -1)) { $('.state-content').show(); $('.state-content .intrusion-header').show(); $('#intrusion .installSoft').hide(); $('#intrusion .tab-nav-border, #intrusion .tab-nav-con').show(); $('#intrusion .tab-nav-border span').eq(0).trigger('click'); } else { $('.state-content').hide(); $('#intrusion .installSoft').show(); $('#intrusion .tab-nav-border,#intrusion .tab-nav-con').hide(); if (rdata.endtime > -1) { $('.purchaseIntrusion').hide(); }else{ $('.installIntrusion').hide(); } } }); }, event: function () { var that = this; // 切换系统防火墙菜单事件 $('#intrusion').on('click', '.tab-nav-border span', function () { var index = $(this).index(); that.cutSshTab(index); }); $('#isIntrusion').unbind('click').on('click', function () { var status = $(this).prop('checked'); that.setIntrusionSwitch(status); }); $('.installSoft .thumbnail-tab li').on('click',function(){ var index = $(this).index(); $(this).addClass('on').siblings().removeClass('on'); $('.installSoft .thumbnail-item').eq(index).addClass('show').siblings().removeClass('show'); }); $('.installIntrusion').on('click', function (){ bt.soft.install('bt_security', function (rdata) { location.reload(); }); }); $('.purchaseIntrusion').on('click', function () { bt.soft.updata_ltd(true); }); }, /** * @description 切换SSH管理页面 */ cutSshTab:function (index){ switch (index){ case 0: this.overviewList(); break; case 1: this.processWhiteList(); break; case 2: this.interceptLog(); break; case 3: this.operationLog(); break; } }, /** * @description 设置防入侵开关 */ setIntrusionSwitch:function (status){ bt_tools.send({ url:'/plugin?action=a&name=bt_security&s='+ (status?'start_bt_security':'stop_bt_security'), },function(rdata){ bt_tools.msg(rdata); }, lan.security.intrusion.switch_req); }, /** * @description 概览列表 */ overviewList:function () { var _that = this; return bt_tools.table({ el: '#antiOverviewList', url: '/plugin?action=a&name=bt_security&s=get_total_all', load: lan.security.intrusion.overview_req, default: lan.security.intrusion.overview_default, // 数据为空时的默认提示 autoHeight: true, height: '450px', dataFilter: function (data) { $('#isIntrusion').prop('checked', data.open); $('.totlaDays').html(data.totla_times).css(data.totla_times ? { 'color': '#d9534f', 'font-weight': 'bold' } : {}); $('.totlaTimes').html(data.totla_days).css(data.totla_days ? { 'color': '#d9534f', 'font-weight': 'bold' } : {}); return { data: data.system_user }; }, column: [ {title: lan.security.intrusion.user, fid: '0'}, {title: lan.security.intrusion.total,align: 'center', template:function (row){ var total = row[4].totla; return ''+ total + ''; }}, {title: lan.security.intrusion.today, align: 'center', template:function (row){ var today = row[4].day_totla; return ''+ today + ''; }}, { title: lan.security.intrusion.protection, fid:'3', type: 'switch', event: function (row, index, ev, key, that) { bt_tools.send({ url:'/plugin?action=a&name=bt_security&s='+(row[3]?'stop_user_security':'start_user_security'), data:{ user: row[0] } },function (rdata){ bt_tools.msg(rdata); that.$refresh_table_list(); }, function (rdata) { bt_tools.msg(rdata); $(ev.currentTarget).prop('checked', row[3]); }, lan.security.intrusion.protection_req); } }, { title: lan.security.intrusion.log, fid:'5', type: 'switch', event: function (row, index, ev, key, that) { bt_tools.send({ url:'/plugin?action=a&name=bt_security&s='+(row[5]?'stop_user_log':'start_user_log'), data:{ uid:row[1] } },function (rdata){ bt_tools.msg(rdata); that.$refresh_table_list(); }, lan.security.intrusion.log_req); } }, {title: lan.security.intrusion.remark, fid:'6'}, { title: lan.public.operate, type: 'group', width: 150, align: 'right', group: [{ title: lan.security.intrusion.logs, event: function (row, index) { _that.getCmdLogs(row) } }] } ] }) }, /** * @description 获取命令日志 * @param {Object} row 当前行数据 */ getCmdLogs:function (row){ var that = this; bt_tools.send({ url:'/plugin?action=a&name=bt_security&s=get_logs_list', data:{ user:row[0] } },function (rdata){ if(rdata.length > 0){ that.openLogsView(rdata,row[0]); }else{ layer.msg(lan.security.intrusion.no_logs, { icon: 6 }); } }) }, /** * @description 打开日志视图 */ openLogsView:function (arr,user){ var that = this; layer.open({ type: 1, title: "["+ user +"] - " + lan.security.intrusion.logs_title, area: ['840px', '570px'], closeBtn: 2, shadeClose: false, content: '
    \
    \
    ' + lan.security.intrusion.select_date + ':
    \
    \
    '+ arr[0] +'
    \
    \
    \
    \
    \
    \
    \
    \
    ', success:function(layers,index){ var _html = ''; for(var i = 0;i'+ arr[i] +''; } $('.logs-list-box .logs-input-list').html(_html); $('.logs-list-box .logs-inputs').on('click',function(e){ if(!$(this).parent().hasClass('active')){ $(this).parent().addClass('active'); }else{ $(this).parent().removeClass('active'); } $(document).unbind('click').click(function(e){ $('.logs-unselect').removeClass('active'); $(this).unbind('click'); }); e.stopPropagation(); e.preventDefault(); }); $('.logs-input-list dd').on('click',function(e){ var _val = $(this).attr('logs-data'); $(this).addClass('logs_checked').siblings().removeClass('logs_checked'); $(this).parent().attr('data-val',_val); $(this).parent().prev().find('.logs-inputs-tips').html(_val); that.renderLogsTable({ page:1, day:_val, user:user}); }); $('.logs-page').unbind().on('click','a.nextPage',function(e){ var _page = parseInt($(this).attr('data-page')); var _day = $('.logs-input-list dd').attr('logs-data'); that.renderLogsTable({ page:_page, day:_day, user:user}); }); $('.logs-input-list dd:eq(0)').click(); } }) }, /** * @description 渲染日志视图 * @param {object} data 日志数据 */ renderLogsTable:function (data){ var _that = this, table = $('#logsTable'), dataTable = table.data('table'); table.empty(); return bt_tools.table({ el: '#logsTable', url: '/plugin?action=a&name=bt_security&s=get_user_log', load: lan.security.intrusion.logs_req, default: lan.security.intrusion.logs_default, // 数据为空时的默认提示 autoHeight: true, column: [ {title: lan.security.intrusion.user, template:function (row) { return ''+ data.user +'' }}, {title: lan.security.intrusion.user, fid: 'cwd'}, {title: lan.security.intrusion.command_executed, fid: 'cmd'}, {title: lan.security.intrusion.command_path, fid: 'filename'}, {title: lan.security.intrusion.time,align:'right', template: function (row) { return ''+ bt.format_data(row.timestamp) +''; }} ], beforeRequest: function (param) { return $.extend(param,{ p:data.page, day:data.day, user:data.user, num:11}); }, success: function (rdata) { $('.logs-page').html(firewall.renderLogsPages(10,data.page,rdata.data.length)); } }); }, /** * @description 进程白名单 */ processWhiteList:function (){ var _that = this; return bt_tools.table({ el: '#antiProcessWhiteList', url: '/plugin?action=a&name=bt_security&s=porcess_set_up_log', load: lan.security.intrusion.whitelist_req, default: lan.security.intrusion.whitelist_default, // 数据为空时的默认提示 autoHeight: true, dataFilter: function (data) { return {data:data}; }, tootls: [ { // 按钮组 type: 'group', list: [{ title: lan.security.intrusion.add_whitelist, active: true, event: function (ev) { bt.open({ title: lan.security.intrusion.add_whitelist, area:'430px', btn: [lan.public.confirm, lan.public.cancel], content:'
    \
    \ ' + lan.security.intrusion.process_name + '\
    \
    \
    \ ', yes:function (){ var cmd = $('[name="cmd"]').val(); bt_tools.send({ url: '/plugin?action=a&name=bt_security&s=add_porcess_log', data: { cmd:cmd } },function (rdata){ bt_tools.msg(rdata); _that.processWhiteList() }) } }) } }] }, // { // 批量操作 // type: 'batch', //batch_btn // disabledSelectValue: '请选择需要批量操作的站点!', // selectList: [{ // title: "删除项目", // url: '/project/nodejs/remove_project', // param: function (row) { // return { data: JSON.stringify({ project_name: row.name }) } // }, // refresh: true, // callback: function (that) { // // } // } // ], // }, ], column: [ { title: lan.security.intrusion.process_whitelist, template: function (row) { return ''+ row + ''; } }, { title: lan.public.operate, type: 'group', width: 150, align: 'right', group: [{ title: lan.public.del, event: function (row, index) { console.log(arguments); bt.confirm({ title: lan.security.intrusion.del_whitelist_title + ' ['+ row +']', msg: lan.security.intrusion.del_whitelist_msg }, function () { bt_tools.send({ url:'/plugin?action=a&name=bt_security&s=del_porcess_log', data:{ cmd: row } },function (rdata){ _that.processWhiteList() bt_tools.msg(rdata) }) }) } }] } ] }) }, /** * @description 拦截日志 */ interceptLog:function (){ var _that = this; return bt_tools.table({ el: '#antiInterceptLog', url: '/plugin?action=a&name=bt_security&s=get_log_send', load: lan.security.intrusion.intercept_logs_req, default: lan.security.intrusion.intercept_logs_default, // 数据为空时的默认提示 autoHeight: true, dataFilter: function (res) { return { data: res.data }; }, column: [ {title: lan.security.intrusion.intercept_content, template:function (row){ return ''+ row.log + ''; }}, {title: lan.security.intrusion.trigger_time, width:'170px', align: 'right', template:function (row){ return ''+ row.addtime + ''; }} ] }) }, /** * @description 操作日志 */ operationLog:function (){ var _that = this; return bt_tools.table({ el: '#antiOperationLog', url: '/plugin?action=a&name=bt_security&s=get_log', load: lan.security.intrusion.operation_logs_req, default: lan.security.intrusion.operation_logs_default, // 数据为空时的默认提示 autoHeight: true, tootls:[{ //分页显示 type: 'page', jump: true, //是否支持跳转分页,默认禁用 }], column: [ {title: lan.public.operate, template:function (row){ return ''+ row.log + ''; }}, {title: lan.security.intrusion.date, fid:'addtime', width:'170px'}, ] }) } } // 系统加固 var system = { ipTable: null, init: function () { $('.state-content').show(); $('.state-content .system-header').show(); bt.soft.get_soft_find('syssafe', function (rdata) { // 判断插件未安装 && 插件是否过期 if (!rdata.setup && rdata.endtime > -1) { $('.buySystem').hide(); } // 判断插件已安装 && 插件是否过期 if ((rdata.setup && rdata.endtime > -1)) { $('#system .tab-nav-border, #system .tab-nav-con').show(); $('#system .installSoft').hide(); $('#system .tab-nav-border span').eq(0).trigger('click'); } else { $('#system .tab-nav-border, #system .tab-nav-con').hide(); $('#system .installSoft').show(); $('.state-content').hide(); if (rdata.endtime > - 1) { $('.purchaseSystem').hide(); } else { $('.installSystem').hide(); } } }); }, /** * @description SSH管理列表 */ event: function () { var that = this; // 切换系统防火墙菜单事件 $('#system').on('click', '.tab-nav-border span', function () { var index = $(this).index(); that.cutSshTab(index); }); // 系统加固开关 $('#isReinforcement').unbind('change').change(function () { var $this = $(this) bt_tools.send({ url: '/plugin?name=syssafe&action=a&s=set_open', }, function (rdata) { bt_tools.msg(rdata); }, function (rdata) { bt_tools.msg(rdata); var checked = $this.prop('checked'); $this.prop('checked', !checked); }, lan.security.system.switch_req); }); // 添加封锁ip地址 $('.system_add_ip').click(function () { var $ip = $('input[name="system_address"]') var ip = $ip.val().trim(); if (!ip) { $ip.focus(); return layer.msg(lan.security.system.add_ip_val1, { icon: 2 }); } if (!bt.check_ip(ip)) { $ip.focus(); return layer.msg(lan.security.system.add_ip_val2, { icon: 2 }); } bt_tools.send({ url: '/plugin?name=syssafe&action=a&s=add_ssh_limit', data: { ip: ip } }, function (rdata) { bt_tools.msg(rdata); if (rdata.status) $ip.val(''); that.getBlockIp(); }, lan.security.system.add_ip_req); }); $('#system .installSoft .thumbnail-tab li').unbind('click').on('click',function(){ var index = $(this).index() $(this).addClass('on').siblings().removeClass('on') $('#system .installSoft .thumbnail-item').eq(index).addClass('show').siblings().removeClass('show') }); $('.installSystem ').unbind('click').on('click',function (){ bt.soft.install('syssafe',function (rdata) { location.reload(); }); }); $('.purchaseSystem').unbind('click').on('click',function (){ bt.soft.updata_ltd(true); }); }, /** * @description 切换SSH管理页面 */ cutSshTab:function (index){ switch (index){ case 0: this.reinforceSystem(); break; case 1: this.reinforceBlockIp(); break; case 2: this.reinforceLog(); break; } }, /** * @description 渲染系统加固配置 */ renderSafeConfig:function (){ if (s_key === 'process') { system_reinforcement.process_config() return; } if (s_key === 'ssh') { system_reinforcement.ssh_config() return; } bt_tools.send({ url: '/plugin?name=syssafe&action=a&s=get_safe_config', data: { s_key: s_key } },function (rdata){ var chattrs = { "a": "追加", "i": "只读" } var states = { true: "已保护", false:"未保护" } var tbody = ''; for (var i = 0; i < rdata.paths.length; i++) { tbody += '\ ' + rdata.paths[i].path + '\ ' + chattrs[rdata.paths[i].chattr] + '\ ' + (rdata.paths[i].s_mode === rdata.paths[i].d_mode ? rdata.paths[i].s_mode:(rdata.paths[i].s_mode + ' >> ' + rdata.paths[i].d_mode)) + '\ ' + states[rdata.paths[i].state] + '\ 删除\ ' } if (system_reinforcement.message_box_noe) { layer.close(system_reinforcement.message_box_noe); system_reinforcement.message_box_noe = null; } system_reinforcement.message_box_noe = layer.open({ type: 1, title: "配置【" + rdata.name + "】", area: ['700px', '550px'], closeBtn: 2, shadeClose: false, content: '
    \
    \ \ \ \ \
    \
    \
    \ \ \ \ \ \ \ \ \ \ \ '+ tbody+'\
    路径模式权限状态操作
    \
    \
    \ \
    ', success:function (){ } }) },'获取系统加固配置'); }, /** * @description 防护配置 */ reinforceSystem:function (){ var _that = this; return bt_tools.table({ el: '#reinforceSystem', url: '/plugin?name=syssafe&action=a&s=get_safe_status', load: lan.security.system.protection_req, default: lan.security.system.protection_default, // 数据为空时的默认提示 autoHeight: true, dataFilter: function (data) { $('#isReinforcement').prop('checked', data.open); return { data: data.list }; }, column: [ {title: lan.security.system.name, fid:'name'}, {title: lan.security.system.desc, fid:'ps'}, { title: lan.security.system.status, fid:'open', type: 'switch', event: function (row, index, ev, key, that) { bt_tools.send({ url:'/plugin?action=a&name=syssafe&s=set_safe_status', data:{ s_key: row.key } },function (rdata){ bt_tools.msg(rdata); that.$refresh_table_list(); }, function (rdata) { bt_tools.msg(rdata); $(ev.currentTarget).prop('checked', row[3]); }, lan.security.system.change_status_req); } }, { title: lan.public.operate, type: 'group', width: 150, align: 'right', group: [{ title: lan.public.set, event: function (row, index) { switch (row.key) { case 'ssh': _that.renderReinforceSSHView(row); break; case 'process': _that.renderReinforceAbnormalProcess(row); break; default: _that.renderReinforceSystemView(row); break; } } }] } ] }) }, /** * @description 渲染防护配置 服务加固、环境变量加固、用户加固、关键目录加固、计划任务加固 */ renderReinforceSystemView:function (row){ var that = this; bt_tools.open({ title: lan.security.system.config + " [" + row.name + "]", area: ['700px', '600px'], btn:false, content:'
    \
    \ \
    ', success:function (){ that.reinforceSystemFind(row.key); } }) }, /** * @description 渲染指定系统加固配置列表信息 * @param {String} s_key 系统加固配置key */ reinforceSystemFind: function (s_key) { var _that = this; var chattrs = { "a": lan.security.system.append, "i": lan.security.system.read } return bt_tools.table({ el: '#ReinforceSystemTable', url: '/plugin?name=syssafe&action=a&s=get_safe_config', default: lan.security.system.config_defualt, // 数据为空时的默认提示 height: 350, beforeRequest: function (data) { return $.extend(data, { s_key: s_key }); }, dataFilter: function (data) { return { data: data.paths }; }, column: [ {title: lan.security.system.path, fid:'path'}, {title: lan.security.system.model, fid:'chattr', template: function (row) { return ''+ chattrs[row.chattr] +''; }}, {title: lan.security.system.permissions, fid:'ps', template: function (row) { return ''+ (row.s_mode === row.d_mode?row.s_mode:(row.s_mode + ' >> ' + row.d_mode)) +''; }}, {title: lan.security.system.status, fid:'state', template: function (row) { return ''+ (row.state?lan.security.system.protected:lan.security.system.unprotected) +''; }}, { title: lan.public.operate, type: 'group', width: 150, align: 'right', group: [{ title: lan.public.del, event: function (row, index, ev, id, that) { bt_tools.send({ url: '/plugin?name=syssafe&action=a&s=remove_safe_path', data: { s_key: s_key, path: row.path } }, function (rdata) { bt_tools.msg(rdata); that.$refresh_table_list(); }, lan.security.system.del_config_req); } }] } ], tootls:[{ // 按钮组 type: 'group', list: [{ title: lan.security.system.add_config_btn, active: true, event: function (ev, that) { _that.reinforceAddProtectFile(s_key, that); } }] }] }) }, /** * @description 渲染添加保护文件/目录 * @param {String} s_key 系统加固配置key */ reinforceAddProtectFile: function (s_key, table) { bt_tools.open({ title: lan.security.system.add_config_btn, area: '480px', btn: [lan.public.confirm, lan.public.cancel], skin:'addProtectFile', content: { class: 'pd20', form: [ { label: lan.security.system.path, group:{ type: 'text', name: 'path', width: '250px', icon: { type: 'glyphicon-folder-open', event: function (ev) { }, select: 'dir' }, placeholder: lan.security.system.path_input, } }, { label: lan.security.system.model, group:{ type: 'select', name: 'chattr', width: '250px', list: [ { title: lan.security.system.read, value: 'i' }, { title: lan.security.system.append, value: 'a' }, ] } }, { label: lan.security.system.permissions, group: { type: 'text', name: 'd_mode', width: '250px', placeholder: lan.security.system.permissions_input, } } ] }, yes: function (form, indexs) { if (form.path === '') return layer.msg(lan.security.system.path_val1, { icon: 2 }); if (form.chattr === '') return layer.msg(lan.security.system.model_val1, { icon: 2 }); if (form.d_mode === '') return layer.msg(lan.security.system.permissions_input, { icon: 2 }); form.s_key = s_key; bt_tools.send({ url: '/plugin?name=syssafe&action=a&s=add_safe_path', data: form }, function (rdata) { bt_tools.msg(rdata); layer.close(indexs); table.$refresh_table_list(); }, lan.security.system.add_config_req); } }) }, /** * @description 渲染配置SSH加固策略 * @param {object} row 表格单行数据 */ renderReinforceSSHView: function (row) { bt_tools.open({ title: lan.security.system.config + ' [' + row.name + ']', area: ['700px'], btn:false, content:'
    \
    \ ' + lan.security.system.ssh_view1 + '\ ' + lan.security.system.ssh_view2 + '\ ' + lan.security.system.ssh_view3 + '\ ' + lan.security.system.ssh_view4 + '\ \
    \ \
    ', success: function () { bt_tools.send({ url: '/plugin?name=syssafe&action=a&s=get_ssh_config', }, function (rdata) { $('input[name="s_cycle"]').val(rdata.cycle); $('input[name="s_limit"]').val(rdata.limit); $('input[name="s_limit_count"]').val(rdata.limit_count); }); // 保存配置 $('#saveSshConfig').click(function () { var data = { cycle: $("input[name='s_cycle']").val(), limit: $("input[name='s_limit']").val(), limit_count: $("input[name='s_limit_count']").val() } if (data.cycle === '') return layer.msg(lan.security.system.ssh_view5, { icon: 2 }); if (data.limit === '') return layer.msg(lan.security.system.ssh_view6, { icon: 2 }); if (data.limit_count === '') return layer.msg(lan.security.system.ssh_view7, { icon: 2 }); bt_tools.send({ url: '/plugin?name=syssafe&action=a&s=save_ssh_config', data: data }, function (rdata) { bt_tools.msg(rdata); }, lan.security.system.ssh_view8); }) } }) }, /** * @description 渲染异常进程监控配置 * @param {object} row 表格单行数据 */ renderReinforceAbnormalProcess: function (row) { var that = this; bt_tools.open({ title: lan.security.system.config + ' [' + row.name + ']', area: ['700px', '600px'], btn:false, content:'
    \
    \ \
    ', success: function () { bt_tools.table({ el: '#AbnormalProcessTable', url: '/plugin?name=syssafe&action=a&s=get_process_white', height: 343, dataFilter: function (rdata) { var data = [] $.each(rdata, function (index, item) { data.push({ name: item }) }) return { data: data } }, column: [ { title: lan.security.system.process_name, fid: 'name' }, { title: lan.public.operate, type: 'group', width: 150, align: 'right', group: [{ title: lan.public.del, event: function (row, index, ev, id, that) { bt_tools.send({ url: '/plugin?name=syssafe&action=a&s=remove_process_white', data: { process_name: row.name } }, function (rdata) { bt_tools.msg(rdata); that.$refresh_table_list(); }, lan.security.system.del_process_req); } }] } ], tootls:[{ // 按钮组 type: 'group', list: [{ title: lan.security.system.add_process_btn, active: true, event: function (ev, that) { bt_tools.open({ title: lan.security.system.add_process_btn, area: '450px', btn: [lan.public.save, lan.public.cancel], skin:'addProtectFile', content: { class: 'pd20', form: [ { label: lan.security.system.process_name, group:{ type: 'text', name: 'process_name', width: '250px', placeholder: lan.security.system.process_name_input, } } ] }, yes: function (form, indexs) { if (form.process_name === '') return layer.msg(lan.security.system.process_name_input, { icon: 2 }); bt_tools.send({ url: '/plugin?name=syssafe&action=a&s=add_process_white', data: form }, function (rdata) { bt_tools.msg(rdata); layer.close(indexs); that.$refresh_table_list(); }, lan.security.system.add_config_req) } }) } }] }] }) } }) }, /** * @description 封锁IP */ reinforceBlockIp: function () { var _that = this; var table = bt_tools.table({ el: '#reinforceBlockIp', url: '/plugin?name=syssafe&action=a&s=get_ssh_limit_info', default: lan.security.system.ip_list_default, // 数据为空时的默认提示 autoHeight: true, dataFilter: function (data) { return {data:data}; }, column: [ {title: lan.security.system.ip, fid: 'address'}, {title: lan.security.system.unblock_time, fid:'end', width: 300, template:function (row){ return ''+ (row.end ? bt.format_data(row.end) : lan.security.system.manually_unblock) + ''; }}, { title: lan.public.operate, type: 'group', width: 150, align: 'right', group: [{ title: lan.security.system.unblock_now, event: function (row, index) { bt_tools.send({ url: '/plugin?name=syssafe&action=a&s=remove_ssh_limit', data: { ip: row.address } }, function (rdata) { bt_tools.msg(rdata); _that.getBlockIp(); }, lan.security.system.unblock_now_req); } }] } ] }); this.ipTable = table return table }, /** * @description 表格重新生成封锁IP */ getBlockIp: function () { if (this.ipTable) this.ipTable.$refresh_table_list() }, /** * @description 操作日志 */ reinforceLog:function (){ var _that = this; $('#reinforceLog').empty() return bt_tools.table({ el: '#reinforceLog', url: '/data?action=getData', default: lan.security.system.operate_logs_default, // 数据为空时的默认提示 autoHeight: true, beforeRequest: function (param) { return $.extend(param,{ search: 'System hardening', table:'logs', order:'id desc'}); }, tootls: [ { //分页显示 type: 'page', numberStatus: true, // 是否支持分页数量选择,默认禁用 jump: true, //是否支持跳转分页,默认禁用 } ], column: [ { title: lan.security.system.date, fid: 'addtime' }, { title: lan.security.system.detail, fid: 'log' }, ], }) } } // 日志审计 var logAudit = { data:{}, init: function () { this.getLogFiles(); $('#logAudit .logAuditTab').empty(); $('#logAudit').height($(window).height() - 180) }, /** * @description SSH管理列表 */ event:function (){ var that = this; $(window).unbind('resize').on('resize', function () { if ($('.logAuditTabContent').is(':hidden')) return; var height = $(window).height() - 180; $('#logAudit').height(height); $('#logAuditTable .divtable').css('max-height', height - 150); }); $('.logAuditTab').unbind('click').on('click', '.logAuditItem',function (){ var data = $(this).data(), list = []; $.each(data.list, function (key, val){ list.push(val.log_file) }); $(this).addClass('active').siblings().removeClass('active'); that.getSysLogs({log_name: data.log_file, list: list, p:1}); }); $('#logAuditPages').unbind('click').on('click', 'a', function (){ var page = $(this).data('page'); that.getSysLogs({log_name: that.data.log_name, list: that.data.list, p: page}); return false; }); }, /** * @description 获取日志审计类型 */ getLogFiles: function () { var that = this; bt_tools.send({ url: '/safe/syslog/get_sys_logfiles' }, function (rdata) { if(rdata.hasOwnProperty('status') ){ if(!rdata.status && rdata.msg === 'Sorry, this feature is only available for Pro users!') { $('.logAuditTabContent').hide(); $('#logAudit .daily-thumbnail').show(); $('#logAudit').css('height', 'auto'); return false; } } var initData = rdata[0], list = [] $.each(rdata, function (i, v) { var logSize = 0; $.each(v.list,function (key, val){ logSize += val.size; }) $('#logAudit .logAuditTab').append($('
    ' + v.name + ' - '+ v.title +'('+ ToSize(v.size + logSize) +')
    ').data(v)) }) $('#logAudit .logAuditTab .logAuditItem:eq(0)').trigger('click') }, { load: lan.security.logs.get_logfiles, verify: false }) }, /** * @description 获取日志审计类型列表 */ getSysLogs: function (param) { var that = this; var page = param.p || 1; that.data = { log_name: param.log_name, list: param.list, limit: 20, p: page } bt_tools.send({ url: '/safe/syslog/get_sys_log', data: {data:JSON.stringify(that.data)} }, function (rdata) { if(typeof rdata[0] === 'string'){ $('#logAuditPre').show().siblings().hide() that.renderLogsAuditCommand(rdata) }else{ $('#logAuditTable,#logAuditPages').show() $('#logAuditPre').hide() that.renderLogsAuditTable({ p:page }, rdata) } }, { load: lan.security.logs.get_sys_logs, verify: false }) }, /** * @description 渲染日志审计命令 * @param {Object} rdata 参数 */ renderLogsAuditCommand: function (rdata) { var logAuditLogs = $('#logAuditPre'); var str = rdata.join('\r').replace(//g,'>').replace(/"/g,'"'); logAuditLogs.html('
    ' + str + '
    '); logAuditLogs.find('pre').scrollTop(9999999999999).css({height: $(window).height() - 180}) }, /** * @description 渲染日志审计表格 * @param {object} param 参数 */ renderLogsAuditTable: function (param, rdata){ var that = this; var column = [], data = rdata[0] ? rdata[0] : { 'Time': '--', 'Role': '--', 'Event': '--' }, i = 0; $.each(data, function (key) { // console.log(key === '时间',i) column.push({ title: key, fid: key,width: (key === 'Time' && i === 0) ? '200px' : (key === 'Time'?'300px':'') }) i++; }) $('#logAuditTable').empty() return bt_tools.table({ el: '#logAuditTable', url:'/safe/syslog/get_sys_log', default: lan.security.logs.logs_default, // 数据为空时的默认提示 column: column, dataFilter: function (data) { if(typeof data.status === "boolean" && !data.status){ $('.logAuditTabContent').hide().next().show(); return { data: [] } } if(typeof data[0] === 'string'){ $('#logAuditPre').show().siblings().hide() that.renderLogsAuditCommand(rdata) }else{ $('#logAuditTable,#logAuditPages').show() $('#logAuditPre').hide() return {data:data} } }, beforeRequest: function (param) { delete param.data return {data:JSON.stringify($.extend(that.data,param))} }, tootls: [{ // 按钮组 type: 'group', list: [{ title: lan.security.logs.refresh, active: true, event: function (ev) { that.getSysLogs(that.data) } }] },{ // 搜索内容 type: 'search', width: '300px', placeholder: lan.security.logs.search, searchParam: 'search', //搜索请求字段,默认为 search },{ type:'page', number:20 }], success:function (config){ $('#logAuditTable .divtable').css('max-height', $(window).height() - 280) } }) } } // 面板日志 var logs = { init: function () { $('#logsBody .tab-nav-border span').eq(0).trigger('click'); }, /** * @description 事件绑定 */ event:function (){ var that = this; $('#logsBody').unbind('click').on('click','.tab-nav-border span',function(){ var index = $(this).index(); that.cutLogsTab(index); }); $(window).unbind('resize').resize(function (){ $('#runningLog .crontab-log').height((window.innerHeight - 310) +'px') }); }, /** * @description 切换日志菜单 * @param {number} index 索引 */ cutLogsTab:function(index){ switch (index) { case 0: this.operationLogTable() break; case 1: this.runningLog() break; } }, /** * @description 日志表格 */ operationLogTable:function(){ var that = this; return bt_tools.table({ el: '#operationLog', url: '/data?action=getData', default: lan.security.logs.operate_default, // 数据为空时的默认提示 autoHeight: true, beforeRequest: function (data) { return $.extend(data, {table: 'logs',order: 'id desc'}) }, tootls: [ { // 按钮组 type: 'group', list: [{ title: lan.security.logs.refresh, active:true, event: function (ev, _that) { _that.$refresh_table_list(true) } },{ title: lan.security.logs.clear, event: function (ev) { bt.firewall.clear_logs(function(){ that.operationLogTable() }); } }] }, { // 搜索内容 type: 'search', placeholder: lan.security.logs.operate_search, searchParam: 'search', //搜索请求字段,默认为 search }, { //分页显示 type: 'page', numberStatus: true, // 是否支持分页数量选择,默认禁用 jump: true, //是否支持跳转分页,默认禁用 }], column: [ {title: lan.security.logs.user, fid: 'username', width: 80}, {title: lan.security.logs.type, fid: 'type', width: 150}, {title: lan.security.logs.details,fid: 'log'}, {title: lan.security.logs.time, fid: 'addtime', width:150} ] }) }, /** * @description 运行日志 */ runningLog:function (){ var that = this; bt_tools.send({ url:'/config?action=get_panel_error_logs' },function (rdata){ $('#runningLog').html('
    \ \ \
    '+ (rdata.msg || lan.security.logs.no_logs) +'
    \
    '); $('.refreshRunLogs').click(function (){ that.runningLog(); }) $('.clearRunningLog').click(function (){ that.clearRunningLog(); }) $('#runningLog .crontab-log').height((window.innerHeight - 310) +'px') var div = document.getElementsByClassName('crontab-log')[0] div.scrollTop = div.scrollHeight; }, lan.security.logs.get_logs_req); }, /** * @description 清除日志 */ clearRunningLog:function (){ var that = this; bt.confirm({ title: lan.security.logs.clear_logs_title, msg: lan.security.logs.clear_logs_msg, },function (){ bt_tools.send({ url:'/config?action=clean_panel_error_logs' },function (rdata){ bt.msg(rdata) that.runningLog() }, lan.security.logs.clear_logs_req) }) } } firewall.init();