diff --git a/plugins/webhook/index.py b/plugins/webhook/index.py index 9d92ee009..473f3bbfe 100755 --- a/plugins/webhook/index.py +++ b/plugins/webhook/index.py @@ -152,9 +152,15 @@ def getLog(): logPath = args['path'] - content = mw.getLastLine(logPath, 100) + content = mw.getLastLine(logPath, 500) return mw.returnJson(True, 'ok', content) +def getLogCb(args): + # print(args) + logPath = args['path'] + content = mw.getLastLine(logPath, 3000) + return mw.returnData(True, 'ok', content) + def runShellArgs(args): data = getCfg() @@ -190,7 +196,11 @@ def getRunShellCmd(): if 'params' in args: param = args['params'] param = re.sub("\"", '', param) - cmd = "bash {} {}".format(shellFile, param) + + cmd = "" + cmd += "git config --global credential.helper store\n" + cmd += "git config --global pull.rebase false\n" + cmd += "bash {} {}".format(shellFile, param) return mw.returnJson(True, 'ok', cmd) diff --git a/plugins/webhook/js/webhook.js b/plugins/webhook/js/webhook.js index 72111a09f..dc3a30192 100755 --- a/plugins/webhook/js/webhook.js +++ b/plugins/webhook/js/webhook.js @@ -78,6 +78,30 @@ function whPostCallbak(method, version, args,callback){ },'json'); } +function whPostCallbakN(method, version, args,callback){ + 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) { + if (!data.status){ + layer.msg(data.msg,{icon:0,time:2000,shade: [0.3, '#000']}); + return; + } + + if(typeof(callback) == 'function'){ + callback(data); + } + },'json'); +} + function getFileName(file){ var list = file.split('/'); var f = list[list.length-1]; @@ -275,6 +299,23 @@ function getLogsTimer(path,success,error){ }); } +function getLogsTimerCb(path,success,error){ + whPostCallbakN('getLogCb', "", {"path":path}, function(rdata){ + var rdata = 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({ @@ -290,7 +331,7 @@ function getLogs(path){ $('[name="site_logs"]').scrollTop($('[name="site_logs"]')[0].scrollHeight); logs_timer = setInterval(function(){ - getLogsTimer(path,function(){ + getLogsTimerCb(path,function(){ },function(){ layer.msg(rdata.msg,{icon:2}); diff --git a/plugins/webhook/tpl/git.tpl b/plugins/webhook/tpl/git.tpl index e7f6776d0..7a04d73be 100644 --- a/plugins/webhook/tpl/git.tpl +++ b/plugins/webhook/tpl/git.tpl @@ -3,6 +3,7 @@ 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 diff --git a/web/utils/ssh/ssh_local.py b/web/utils/ssh/ssh_local.py index 48e4e663e..13d2795a5 100644 --- a/web/utils/ssh/ssh_local.py +++ b/web/utils/ssh/ssh_local.py @@ -34,6 +34,7 @@ class ssh_local(object): __log_type = 'SSH终端' __ssh = None + __lock = False # lock _instance_lock = threading.Lock() @@ -61,6 +62,10 @@ class ssh_local(object): def connectSsh(self): + if self.__lock : + return False + self.__lock = True + import paramiko ssh = paramiko.SSHClient() mw.createSshInfo() @@ -68,6 +73,8 @@ class ssh_local(object): port = mw.getSSHPort() try: + ssh.connect('127.0.0.1', 22, timeout=5) + except Exception as e: ssh.connect('127.0.0.1', port, timeout=5) except Exception as e: ssh.connect('localhost', port, timeout=5) @@ -78,6 +85,8 @@ class ssh_local(object): shell = ssh.invoke_shell(term='xterm', width=83, height=21) shell.setblocking(0) + + self.__lock = False return shell def send(self): @@ -108,13 +117,16 @@ class ssh_local(object): if not self.__ssh: self.__ssh = self.connectSsh() - if self.__ssh.exit_status_ready(): - self.__ssh = self.connectSsh() + if self.__ssh: + if self.__ssh.exit_status_ready(): + self.__ssh = self.connectSsh() - self.__ssh.send(info) - try: - time.sleep(0.005) - recv = self.__ssh.recv(8192) - return self.wsSend(recv) - except Exception as ex: - return self.wsSend('') + self.__ssh.send(info) + try: + time.sleep(0.005) + recv = self.__ssh.recv(8192) + return self.wsSend(recv) + except Exception as ex: + return self.wsSend('') + else: + return self.wsSend("连接中...\r\n") \ No newline at end of file diff --git a/web/utils/ssh/ssh_terminal.py b/web/utils/ssh/ssh_terminal.py index e683e60c0..32c8b99e6 100644 --- a/web/utils/ssh/ssh_terminal.py +++ b/web/utils/ssh/ssh_terminal.py @@ -175,7 +175,13 @@ class ssh_terminal(object): else: return self.connectBySocket(sid) + __lock = False + def connectLocalSsh(self, sid): + if self.__lock : + return False + self.__lock = True + mw.createSshInfo() self.__ps = paramiko.SSHClient() self.__ps.set_missing_host_key_policy(paramiko.AutoAddPolicy()) @@ -217,9 +223,14 @@ class ssh_terminal(object): mw.writeLog(self.__log_type, '成功登录到SSH服务器 [{}:{}]'.format( self.__host, self.__port)) self.debug('local-ssh:通道已构建') + + self.__lock = False return self.returnMsg(True, '连接成功!') def connectBySocket(self, sid): + if self.__lock : + return False + self.__lock = True if not self.__host: return self.returnMsg(False, '错误的连接地址') if not self.__user: @@ -328,6 +339,7 @@ class ssh_terminal(object): mw.writeLog(self.__log_type, '成功登录到SSH服务器 [{}:{}]'.format( self.__host, self.__port)) self.debug('通道已构建') + self.__lock = False return self.returnMsg(True, '连接成功.') def getSshInfo(self, file):