diff --git a/plugins/webhook/index.py b/plugins/webhook/index.py index 61d65721f..03cd23ca4 100755 --- a/plugins/webhook/index.py +++ b/plugins/webhook/index.py @@ -97,7 +97,10 @@ def addHook(): hook = {} hook['title'] = args['title'] - hook['access_key'] = mw.getRandomString(48) + if hook['title'] == '': + return mw.returnJson(False, '名称不能为空!') + + hook['access_key'] = mw.md5(hook['title']) hook['count'] = 0 hook['addtime'] = int(time.time()) hook['uptime'] = 0 @@ -191,6 +194,39 @@ def delHook(): mw.writeFile(jsonFile, json.dumps(newdata)) return mw.returnJson(True, '删除成功!') + +def contentReplace(content): + service_path = mw.getServerDir() + content = content.replace('{$ROOT_PATH}', mw.getFatherDir()) + return content + + +def configTpl(): + path = getPluginDir() + '/tpl' + pathFile = os.listdir(path) + tmp = [] + for one in pathFile: + file = path + '/' + one + tmp.append(file) + return mw.getJson(tmp) + +def readConfigTpl(): + args = getArgs() + data = checkArgs(args, ['file', 'title']) + if not data[0]: + return data[1] + + if args['title'] == '': + return mw.returnJson(False, '名称不能为空!') + + content = mw.readFile(args['file']) + content = contentReplace(content) + + content = content.replace('{$REPO}', args['title']) + content = content.replace('{$REPO_NAME}', mw.md5(args['title'])) + + return mw.returnJson(True, 'ok', content) + if __name__ == "__main__": func = sys.argv[1] if func == 'status': @@ -205,5 +241,9 @@ if __name__ == "__main__": print(delHook()) elif func == 'get_log': print(getLog()) + elif func == 'config_tpl': + print(configTpl()) + elif func == 'read_config_tpl': + print(readConfigTpl()) else: print('error') diff --git a/plugins/webhook/js/webhook.js b/plugins/webhook/js/webhook.js index 231219989..97daf5854 100755 --- a/plugins/webhook/js/webhook.js +++ b/plugins/webhook/js/webhook.js @@ -26,7 +26,6 @@ function whPost(method, args,callback){ },'json'); } - function whPostNoMessage(method, args,callback){ var req_data = {}; @@ -79,29 +78,43 @@ function whPostCallbak(method, version, args,callback){ },'json'); } +function getFileName(file){ + var list = file.split('/'); + var f = list[list.length-1]; + return f; +} + var whEditor = null; //添加 function addHook(){ layer.open({ type: 1, - area: '600px', + area: '650px', title: '添加Hook', - closeBtn: 1, + closeBtn: 2, shift: 5, shadeClose: false, btn:['提交','关闭'], content: "
\
\ - 名称\ -
\ + 名称\ +
\
\
\ - 执行脚本\ -
\ - \ + 执行脚本\ +
\ + \ +
\ +
\ +
\ + 模板选择\ +
\ + \ +
\
\ -
\
", success:function(){ @@ -121,6 +134,51 @@ function addHook(){ $(".CodeMirror-scroll").css({"height":"300px","margin":0,"padding":0}); whEditor.focus(); + + + whPostNoMessage('config_tpl','', function(data){ + var rdata = $.parseJSON(data.data); + for (var i = 0; i < rdata.length; i++) { + $('#hook_tpl').append(''); + } + + $('#hook_tpl').change(function(){ + var selected = $(this).val(); + if (selected == '0') { + return; + } + + var title = $('#hook_title').val(); + var loadT = layer.msg('配置模版获取中...',{icon:16,time:0,shade: [0.3, '#000']}); + whPostNoMessage('read_config_tpl', {file:selected,title:title}, function(data){ + layer.close(loadT); + var rdata = $.parseJSON(data.data); + if (!rdata.status){ + layer.msg(rdata.msg,{icon:0,time:2000,shade: [5, '#000']}); + return; + } + + $("#hook_shell").empty().text(rdata.data); + $(".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}); diff --git a/plugins/webhook/tpl/git.tpl b/plugins/webhook/tpl/git.tpl new file mode 100644 index 000000000..40d8f937b --- /dev/null +++ b/plugins/webhook/tpl/git.tpl @@ -0,0 +1,21 @@ +echo "" > {$ROOT_PATH}/server/webhook/scripts/{$REPO_NAME}.log + +export HOME=/tmp +date "+%Y-%m-%d %H:%M:%S" + +git config --global credential.helper store +git config --global pull.rebase false + + +if [ -d {$ROOT_PATH}/gitcode/{$REPO} ];then + cd {$ROOT_PATH}/gitcode/{$REPO} && sudo git pull +else + git clone http://0.0.0.0:6660/xx/{$REPO} +fi + + +rsync -vauP '--exclude=.*' {$ROOT_PATH}/gitcode/{$REPO}/ {$ROOT_PATH}/wwwroot/{$REPO} +chown -R www:www {$ROOT_PATH}/wwwroot/{$REPO} + + +