From 5d104c30d186aa7d4662cad5b403cc74d5e6c331 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 21 Feb 2019 17:19:04 +0500 Subject: [PATCH] bug fix for git private repos --- CyberCP/secMiddleware.py | 2 ++ plogical/applicationInstaller.py | 26 ++++++++++++-------------- plogical/website.py | 22 ++++++++++++++++++++-- 3 files changed, 34 insertions(+), 16 deletions(-) diff --git a/CyberCP/secMiddleware.py b/CyberCP/secMiddleware.py index 12fcf7aa0..5183a9569 100644 --- a/CyberCP/secMiddleware.py +++ b/CyberCP/secMiddleware.py @@ -13,6 +13,8 @@ class secMiddleware: #logging.writeToFile(request.body) data = json.loads(request.body) for key, value in data.iteritems(): + if request.path.find('gitNotify') > -1: + break if type(value) == str or type(value) == unicode: pass else: diff --git a/plogical/applicationInstaller.py b/plogical/applicationInstaller.py index 7845c9400..29c99ee68 100644 --- a/plogical/applicationInstaller.py +++ b/plogical/applicationInstaller.py @@ -547,6 +547,8 @@ class ApplicationInstaller(multi.Thread): externalApp = website.externalApp finalPath = "/home/" + domainName + "/public_html/" + + ## Security Check if finalPath.find("..") > -1: @@ -575,8 +577,7 @@ class ApplicationInstaller(multi.Thread): statusFile.close() try: - - command = 'sudo git clone https://' + defaultProvider +'.com/' + username + '/' + reponame + ' -b ' + branch + ' ' + finalPath + command = 'sudo git clone --depth 1 --no-single-branch git@' + defaultProvider +'.com:' + username + '/' + reponame + '.git -b ' + branch + ' ' + finalPath subprocess.check_output(shlex.split(command)) except subprocess.CalledProcessError, msg: statusFile = open(tempStatusPath, 'w') @@ -870,7 +871,6 @@ class ApplicationInstaller(multi.Thread): githubBranch = self.extraArgs['githubBranch'] admin = self.extraArgs['admin'] - try: website = Websites.objects.get(domain=domainName) finalPath = "/home/" + domainName + "/public_html/" @@ -879,18 +879,16 @@ class ApplicationInstaller(multi.Thread): finalPath = childDomain.path try: - command = 'sudo GIT_SSH_COMMAND="ssh -i /root/.ssh/cyberpanel -o StrictHostKeyChecking=no" git -C ' + finalPath + ' checkout -b ' + githubBranch + command = 'sudo git --git-dir=' + finalPath + '/.git checkout -b ' + githubBranch subprocess.check_output(shlex.split(command)) - - except subprocess.CalledProcessError, msg: - logging.writeToFile('Failed to change branch: ' + str(msg)) - return 0 - - ## - - + except: + try: + command = 'sudo git --git-dir=' + finalPath + '/.git checkout ' + githubBranch + subprocess.check_output(shlex.split(command)) + except subprocess.CalledProcessError, msg: + logging.writeToFile('Failed to change branch: ' + str(msg)) + return 0 return 0 - - except BaseException, msg: + logging.writeToFile('Failed to change branch: ' + str(msg)) return 0 diff --git a/plogical/website.py b/plogical/website.py index f7a7a1156..0a87e3adc 100644 --- a/plogical/website.py +++ b/plogical/website.py @@ -1758,10 +1758,28 @@ class WebsiteManager: return render(request, 'websiteFunctions/setupGit.html', {'domainName': self.domain, 'installed': 1, 'webhookURL': webhookURL}) else: - command = "sudo ssh-keygen -f /root/.ssh/" + self.domain + " -t rsa -N ''" + + command = "sudo ssh-keygen -f /root/.ssh/git -t rsa -N ''" ProcessUtilities.executioner(command) - command = 'sudo cat /root/.ssh/' + self.domain + '.pub' + ### + + configContent = """Host github.com + IdentityFile /root/.ssh/git +""" + + path = "/home/cyberpanel/config" + writeToFile = open(path, 'w') + writeToFile.writelines(configContent) + writeToFile.close() + + command = 'sudo mv ' + path + ' /root/.ssh/config' + ProcessUtilities.executioner(command) + + command = 'sudo chown root:root /root/.ssh/config' + ProcessUtilities.executioner(command) + + command = 'sudo cat /root/.ssh/git.pub' deploymentKey = subprocess.check_output(shlex.split(command)).strip('\n') return render(request, 'websiteFunctions/setupGit.html',