pull/340/head
midoks 2 years ago
parent ed82dd3c12
commit 39d76f5621
  1. 18
      plugins/webhook/index.py
  2. 72
      plugins/webhook/js/webhook.js

@ -122,7 +122,7 @@ def getLog():
logPath = args['path'] logPath = args['path']
content = mw.getLastLine(logPath, 100) content = mw.getLastLine(logPath, 16)
return mw.returnJson(True, 'ok', content) return mw.returnJson(True, 'ok', content)
@ -132,11 +132,16 @@ def runShellArgs(args):
if data[i]['access_key'] == args['access_key']: if data[i]['access_key'] == args['access_key']:
script_dir = getServerDir() + "/scripts" script_dir = getServerDir() + "/scripts"
shellFile = script_dir + '/' + args['access_key'] shellFile = script_dir + '/' + args['access_key']
param = '' param = args['params']
if hasattr(args, 'param'): if param == '':
param = args['param'] param = 'no-parameters'
os.system("bash {} \"{}\" >> {}.log &".format(
shellFile, param.replace('"', r'\"'), shellFile)) param = re.sub("\"", '', param)
cmd = "bash {} {} >> {}.log 2>&1 &".format(
shellFile, param, shellFile)
# print(cmd)
os.system(cmd)
data[i]['count'] += 1 data[i]['count'] += 1
data[i]['uptime'] = int(time.time()) data[i]['uptime'] = int(time.time())
mw.writeFile(getCfgFilePath(), json.dumps(data)) mw.writeFile(getCfgFilePath(), json.dumps(data))
@ -150,6 +155,7 @@ def runShell():
if not check_arg[0]: if not check_arg[0]:
return check_arg[1] return check_arg[1]
args['params'] = 'panel-test'
return runShellArgs(args) return runShellArgs(args)

@ -26,6 +26,32 @@ function whPost(method, args,callback){
},'json'); },'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){ function whPostCallbak(method, version, args,callback){
var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 }); var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 });
@ -153,39 +179,57 @@ function showWebHookCode(url,code){
<div class="line help">\ <div class="line help">\
<b>WebHook使用方法:</b><br>\ <b>WebHook使用方法:</b><br>\
GET/POST:<br>\ GET/POST:<br>\
'+window.location.protocol + "//" + window.location.hostname + (window.location.port ? ':' + window.location.port: '')+'/hook?access_key='+code+'&amp;param=aaa<br>\ '+window.location.protocol + "//" + window.location.hostname + (window.location.port ? ':' + window.location.port: '')+'/hook?access_key='+code+'&amp;params=aaa<br>\
@param access_key string HOOK密钥<br>\ @param access_key string HOOK密钥<br>\
@param param string 自定义参数在hook脚本中使用$1接收<br>\ @param params string 自定义参数在hook脚本中使用$1接收| 多个参数 "1 2" -> $1为1, $2为2<br>\
</div>\ </div>\
</div>' </div>'
}) })
} }
//查看日志 function getLogsTimer(path,success,error){
function getLogs(path){ whPostNoMessage('get_log', {"path":path}, function(rdata){
whPost('get_log', {"path":path}, function(rdata){
var rdata = $.parseJSON(rdata.data); var rdata = $.parseJSON(rdata.data);
if (!rdata.status){ if (!rdata.status){
layer.msg(rdata.msg,{icon:2}); if (typeof(error) == 'function'){
error();
}
return;
} }
layer.open({ $('[name="site_logs"]').text(rdata.data);
if (typeof(success) == 'function'){
success();
}
});
}
//查看日志
function getLogs(path){
logs_web = layer.open({
type:1, type:1,
title:'任务执行日志', title:'任务执行日志',
area: ['600px','400px'], area: ['600px','400px'],
shadeClose:false, shadeClose:false,
closeBtn:2, closeBtn:2,
content:'<div class="bt-logs" style="font-size:0;">\ content:'<div class="bt-logs" style="font-size:0;">\
<textarea class="bt-input-text mr20 site_logs pd10" name="site_logs" style="width:100%;line-height:22px;white-space: pre-line;font-size:12px;height:358px;border: none;" readonly="readonly">'+ (rdata.data || '当前没有日志.') +'</textarea>\ <textarea class="bt-input-text mr20 site_logs pd10" name="site_logs" style="width:100%;line-height:22px;white-space: pre-line;font-size:12px;height:358px;border: none;" readonly="readonly">正在获取中...</textarea>\
</div>', </div>',
success:function(){ success:function(){
$('[name="site_logs"]').scrollTop($('[name="site_logs"]')[0].scrollHeight) $('[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);
}
}); });
} }
@ -220,5 +264,3 @@ function deleteHook(key, title){
}); });
} }

Loading…
Cancel
Save