function whPost(method, args,callback){ var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 }); var req_data = {}; req_data['name'] = 'webhook'; req_data['func'] = method; if (typeof(args) == 'string'){ req_data['args'] = JSON.stringify(toArrayObject(args)); } else { req_data['args'] = JSON.stringify(args); } $.post('/plugins/run', req_data, function(data) { layer.close(loadT); if (!data.status){ //错误展示10S layer.msg(data.msg,{icon:0,time:2000,shade: [10, '#000']}); return; } if(typeof(callback) == 'function'){ callback(data); } },'json'); } function whPostNoMessage(method, args,callback){ var req_data = {}; req_data['name'] = 'webhook'; req_data['func'] = method; if (typeof(args) == 'string'){ req_data['args'] = JSON.stringify(toArrayObject(args)); } else { req_data['args'] = JSON.stringify(args); } $.post('/plugins/run', req_data, function(data) {; if (!data.status){ //错误展示10S layer.msg(data.msg,{icon:0,time:2000,shade: [10, '#000']}); return; } if(typeof(callback) == 'function'){ callback(data); } },'json'); } function whPostCallbak(method, version, args,callback){ var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 }); var req_data = {}; req_data['name'] = 'webhook'; req_data['func'] = method; args['version'] = version; if (typeof(args) == 'string'){ req_data['args'] = JSON.stringify(toArrayObject(args)); } else { req_data['args'] = JSON.stringify(args); } $.post('/plugins/callback', req_data, function(data) { layer.close(loadT); if (!data.status){ layer.msg(data.msg,{icon:0,time:2000,shade: [0.3, '#000']}); return; } if(typeof(callback) == 'function'){ callback(data); } },'json'); } var whEditor = null; //添加 function addHook(){ layer.open({ type: 1, area: '600px', title: '添加Hook', closeBtn: 1, shift: 5, shadeClose: false, btn:['提交','关闭'], content: "
\
\ 名称\
\
\
\ 执行脚本\
\ \
\
\
", success:function(){ $("#hook_shell").empty().text(''); $(".CodeMirror").remove(); whEditor = CodeMirror.fromTextArea(document.getElementById("hook_shell"), { extraKeys: { "Ctrl-Space": "autocomplete", "Ctrl-F": "findPersistent", "Ctrl-H": "replaceAll", "Ctrl-S": function() {} }, lineNumbers: true, matchBrackets:true, mode:"sh", }); $(".CodeMirror-scroll").css({"height":"300px","margin":0,"padding":0}); whEditor.focus(); }, yes:function(indexs){ var loadT = layer.msg("提交中...",{icon:16,time:0}); var data = { title: $("#hook_title").val(), shell: whEditor.getValue(), } whPost('add_hook', data, function(rdata){ var rdata = $.parseJSON(rdata.data); if (!rdata.status){ layer.msg(rdata.msg,{icon:2}); return; } layer.close(indexs); showMsg(rdata.msg, function(){ getHookList(); }, {icon:1}, 2000); }); } }); } //获取列表 function getHookList(){ whPost('get_list', {}, function(rdata){ var rdata = $.parseJSON(rdata.data); var zbody = ''; var mlist = rdata.data.list; var script_dir = rdata.data.script_dir; for(var i=0;i'+mlist[i].title+'' +''+getLocalTime(mlist[i].addtime)+'' +''+getLocalTime(mlist[i].uptime)+'' +''+mlist[i].count+'' +'查看密钥' +'测试 | ' +'编辑 | ' +'日志 | ' +'删除' +'' } $("#zipBody").html(zbody); }); } //查看密钥 function showWebHookCode(url,code){ layer.open({ type:1, title:'查看密钥', area: '600px', shadeClose:false, closeBtn:2, content:'
\
密钥
\
\ WebHook使用方法:
\ GET/POST:
\ '+window.location.protocol + "//" + window.location.hostname + (window.location.port ? ':' + window.location.port: '')+'/hook?access_key='+code+'&params=aaa
\ @param access_key string HOOK密钥
\ @param params string 自定义参数(在hook脚本中使用$1接收)| 多个参数 "1 2" -> $1为1, $2为2
\
\
' }) } function getLogsTimer(path,success,error){ whPostNoMessage('get_log', {"path":path}, function(rdata){ var rdata = $.parseJSON(rdata.data); if (!rdata.status){ if (typeof(error) == 'function'){ error(); } return; } $('[name="site_logs"]').text(rdata.data); if (typeof(success) == 'function'){ success(); } }); } //查看日志 function getLogs(path){ logs_web = layer.open({ type:1, title:'任务执行日志', area: ['600px','400px'], shadeClose:false, closeBtn:2, content:'
\ \
', success:function(){ $('[name="site_logs"]').scrollTop($('[name="site_logs"]')[0].scrollHeight); logs_timer = setInterval(function(){ getLogsTimer(path,function(){ },function(){ layer.msg(rdata.msg,{icon:2}); layer.close(logs_web); }); },1000); }, cancel:function(){ clearInterval(logs_timer); } }); } //运行 function runHook(key){ whPost('run_shell', {"access_key":key}, function(rdata){ var rdata = $.parseJSON(rdata.data); if (!rdata.status){ layer.msg(rdata.msg,{icon:2}); } showMsg(rdata.msg,function(){ getHookList(); },{icon:1},2000); }); } //删除 function deleteHook(key, title){ layer.confirm('删除Hook-['+ title +']',{ title:'是否删除Hook-['+ title +']任务,是否继续' },function(){ whPost('del_hook', {"access_key":key}, function(rdata){ var rdata = $.parseJSON(rdata.data); if (!rdata.status){ layer.msg(rdata.msg,{icon:2}); } showMsg(rdata.msg,function(){ getHookList(); },{icon:1},2000); }); }); }