diff --git a/plugins/op_waf/index.py b/plugins/op_waf/index.py index 962488dbe..31de0d03d 100755 --- a/plugins/op_waf/index.py +++ b/plugins/op_waf/index.py @@ -371,8 +371,8 @@ def removeIpWhite(): content = public.readFile(path) content = json.loads(content) - v = content[int(index)] - content.remove(v) + k = content[int(index)] + content.remove(k) cjson = public.getJson(content) public.writeFile(path, cjson) @@ -448,15 +448,9 @@ def saveScanRule(): if not data[0]: return data[1] - conf = getRuleJsonPath('scan_black') - content = public.readFile(conf) - cobj = json.loads(content) - - cobj['retry'] = args - - cjson = public.getJson(cobj) - public.writeFile(conf, cjson) - + path = getRuleJsonPath('scan_black') + cjson = public.getJson(args) + public.writeFile(path, cjson) return public.returnJson(True, '设置成功!', []) @@ -550,6 +544,25 @@ def removeSiteCdnHeader(): public.writeFile(path, cjson) return public.returnJson(True, '删除成功!') +def outputData(): + args = getArgs() + data = checkArgs(args, ['s_Name']) + if not data[0]: + return data[1] + + path = getRuleJsonPath(args['s_Name']) + content = public.readFile(path) + return public.returnJson(True, 'ok', content) + +def importData(): + args = getArgs() + data = checkArgs(args, ['s_Name', 'pdata']) + if not data[0]: + return data[1] + + path = getRuleJsonPath(args['s_Name']) + public.writeFile(path, args['pdata']) + return public.returnJson(True, '设置成功!') def getLogsList(): args = getArgs() @@ -709,6 +722,10 @@ if __name__ == "__main__": print getLogsList() elif func == 'get_safe_logs': print getSafeLogs() + elif func == 'output_data': + print outputData() + elif func == 'import_data': + print importData() elif func == 'waf_srceen': print getWafSrceen() elif func == 'waf_conf': diff --git a/plugins/op_waf/js/op_waf.js b/plugins/op_waf/js/op_waf.js index 02b9cb768..9fbf8f729 100755 --- a/plugins/op_waf/js/op_waf.js +++ b/plugins/op_waf/js/op_waf.js @@ -496,6 +496,87 @@ function removeIpWhite(index) { }); } + +function funDownload(content, filename) { + // 创建隐藏的可下载链接 + var eleLink = document.createElement('a'); + eleLink.download = filename; + eleLink.style.display = 'none'; + // 字符内容转变成blob地址 + var blob = new Blob([content]); + eleLink.href = URL.createObjectURL(blob); + // 触发点击 + document.body.appendChild(eleLink); + eleLink.click(); + // 然后移除 + document.body.removeChild(eleLink); +} + +function outputLayer(rdata, name, type) { + window.Load_layer = layer.open({ + type: 1, + title: type ? "导出数据" : "导入数据", + area: ['400px', '370px'], + shadeClose: false, + content: '
' + + '
' + + '
' + + '' + + '
导入格式如下:' + + (name == 'ip_white' || name == 'ip_black' ? "[[[127, 0, 0, 1],[127, 0, 0, 255]]]" : "[\"^/test\",\"^/web\"]") + + '
' + + '
' + + '
' + + '
' + + (type ? '' : '') + + '
' + + '
' + }); + var lead_error = CodeMirror.fromTextArea(document.getElementById("lead_data"), { + mode: 'html', + matchBrackets: true, + matchtags: true, + autoMatchParens: true + }); + setTimeout(function () { + $('.btn_save').on('click', function () { + importData(name, lead_error.getValue()); + }) + $('.btn_save_to').on('click', function () { + funDownload(lead_error.getValue(), name + '.json'); + }); + $('#focus_tips').on('click', function () { + $('.placeholder').hide(); + }); + }, 100); +} + + +//导出数据 +function outputData(name, callback) { + var loadT = layer.msg('正在导出数据..', { icon: 16, time: 0 }); + + owPost('output_data', { s_Name: name } , function(data){ + var tmp = $.parseJSON(data.data); + var rdata = $.parseJSON(tmp.data); + if (callback) callback(rdata,res); + outputLayer(rdata, name, true); + }); +} + +//导入数据 +function importData(name, pdata, callback) { + owPost('import_data', { s_Name: name, pdata: pdata } , function(data){ + var rdata = $.parseJSON(data.data); + if (callback) callback(); + layer.msg(rdata.msg, { icon: rdata.status ? 1 : 2 }); + }); +} + +function fileInput(name) { + outputLayer('', name, false); +} + //IP白名单 function ipWhite(type) { if (type == undefined) { @@ -525,8 +606,8 @@ function ipWhite(type) { \ \
\ - \ - \ + \ + \
\