From 0af429778815659ae2c34c8dd652f7bebff77d4d Mon Sep 17 00:00:00 2001 From: usmannasir <01-134132-158@student.bahria.edu.pk> Date: Thu, 26 Jul 2018 04:11:10 +0500 Subject: [PATCH] Attach GIT repositories to websites! --- README.md | 8 +- plogical/applicationInstaller.py | 156 ++++++++++++++++ plogical/sslUtilities.py | 2 - plogical/upgrade.py | 7 + static/images/icons/git-logo.png | Bin 0 -> 1879 bytes static/websiteFunctions/websiteFunctions.js | 165 ++++++++++++++++- .../static/images/icons/git-logo.png | Bin 0 -> 1879 bytes .../websiteFunctions/websiteFunctions.js | 165 ++++++++++++++++- .../templates/websiteFunctions/setupGit.html | 171 ++++++++++++++++++ .../templates/websiteFunctions/website.html | 12 ++ websiteFunctions/urls.py | 5 + websiteFunctions/views.py | 64 ++++++- 12 files changed, 743 insertions(+), 12 deletions(-) create mode 100644 static/images/icons/git-logo.png create mode 100644 websiteFunctions/static/images/icons/git-logo.png create mode 100644 websiteFunctions/templates/websiteFunctions/setupGit.html diff --git a/README.md b/README.md index ebe4719f7..11b3c2ecf 100644 --- a/README.md +++ b/README.md @@ -23,17 +23,13 @@ Webhosting control panel that uses OpenLiteSpeed as web server. * PHP 5.6 * PHP 7.0 * PHP 7.1 - +* PHP 7.2 # Installation Instructions ``` -wget http://cyberpanel.net/install.tar.gz -tar zxf install.tar.gz -cd install -chmod +x install.py -python install.py [IP Address] +sh <(curl https://cyberpanel.net/install.sh || wget -O - https://cyberpanel.net/install.sh) ``` # Resources diff --git a/plogical/applicationInstaller.py b/plogical/applicationInstaller.py index f4b189b76..4e0ea33ff 100644 --- a/plogical/applicationInstaller.py +++ b/plogical/applicationInstaller.py @@ -31,6 +31,8 @@ class ApplicationInstaller(multi.Thread): self.installWordPress() elif self.installApp == 'joomla': self.installJoomla() + elif self.installApp == 'git': + self.setupGit() except BaseException, msg: logging.writeToFile( str(msg) + ' [ApplicationInstaller.run]') @@ -50,6 +52,18 @@ class ApplicationInstaller(multi.Thread): except BaseException, msg: logging.writeToFile( str(msg) + ' [ApplicationInstaller.installWPCLI]') + def installGit(self, tempStatusPath): + try: + + command = 'sudo yum -y install http://repo.iotti.biz/CentOS/7/noarch/lux-release-7-1.noarch.rpm' + subprocess.call(shlex.split(command)) + + command = 'sudo yum install git -y' + subprocess.call(shlex.split(command)) + + except BaseException, msg: + logging.writeToFile( str(msg) + ' [ApplicationInstaller.installGit]') + def installWordPress(self): try: @@ -292,6 +306,148 @@ class ApplicationInstaller(multi.Thread): return 0 + def setupGit(self): + try: + admin = self.extraArgs['admin'] + domainName = self.extraArgs['domainName'] + username = self.extraArgs['username'] + reponame = self.extraArgs['reponame'] + branch = self.extraArgs['branch'] + tempStatusPath = self.extraArgs['tempStatusPath'] + + statusFile = open(tempStatusPath, 'w') + statusFile.writelines('Checking if GIT installed..,0') + statusFile.close() + + finalPath = "/home/" + domainName + "/public_html/" + + + ### Check git + + try: + command = 'sudo /usr/local/bin/git --help' + res = subprocess.call(shlex.split(command)) + + if res == 1: + statusFile = open(tempStatusPath, 'w') + statusFile.writelines('Installing GIT..,0') + statusFile.close() + self.installGit(tempStatusPath) + statusFile = open(tempStatusPath, 'w') + statusFile.writelines('GIT successfully installed,40') + statusFile.close() + except subprocess.CalledProcessError: + statusFile = open(tempStatusPath, 'w') + statusFile.writelines('Installing GIT..,0') + statusFile.close() + self.installGit(tempStatusPath) + statusFile = open(tempStatusPath, 'w') + statusFile.writelines('GIT successfully installed.,40') + statusFile.close() + + ## Open Status File + + statusFile = open(tempStatusPath, 'w') + statusFile.writelines('Setting up directories..,40') + statusFile.close() + + try: + website = ChildDomains.objects.get(domain=domainName) + externalApp = website.master.externalApp + + if admin.type != 1: + if website.master.admin != admin: + statusFile = open(tempStatusPath, 'w') + statusFile.writelines("You do not own this website." + " [404]") + statusFile.close() + return 0 + + except: + website = Websites.objects.get(domain=domainName) + externalApp = website.externalApp + + if admin.type != 1: + if website.admin != admin: + statusFile = open(tempStatusPath, 'w') + statusFile.writelines("You do not own this website." + " [404]") + statusFile.close() + return 0 + + ## Security Check + + if finalPath.find("..") > -1: + statusFile = open(tempStatusPath, 'w') + statusFile.writelines("Specified path must be inside virtual host home." + " [404]") + statusFile.close() + return 0 + + FNULL = open(os.devnull, 'w') + + if not os.path.exists(finalPath): + command = 'sudo mkdir -p ' + finalPath + subprocess.call(shlex.split(command)) + + ## checking for directories/files + + dirFiles = os.listdir(finalPath) + + if len(dirFiles) == 1: + if dirFiles[0] == ".well-known": + pass + else: + statusFile = open(tempStatusPath, 'w') + statusFile.writelines("Target directory should be empty before installation, otherwise data loss could occur." + " [404]") + statusFile.close() + return 0 + elif len(dirFiles) == 0: + pass + else: + statusFile = open(tempStatusPath, 'w') + statusFile.writelines( + "Target directory should be empty before installation, otherwise data loss could occur." + " [404]") + statusFile.close() + return 0 + + #### + + statusFile = open(tempStatusPath, 'w') + statusFile.writelines('Cloning the repo..,40') + statusFile.close() + + try: + + command = 'sudo GIT_SSH_COMMAND="ssh -i /root/.ssh/cyberpanel -o StrictHostKeyChecking=no" /usr/local/bin/git clone ' \ + '--depth 1 --no-single-branch git@github.com:' + username + '/' + reponame + '.git -b ' + branch + ' ' + finalPath + subprocess.call(shlex.split(command)) + + except subprocess.CalledProcessError, msg: + statusFile = open(tempStatusPath, 'w') + statusFile.writelines('Failed to clone repository. [404]') + statusFile.close() + return 0 + + ## + + command = "sudo chown -R " + externalApp + ":" + externalApp + " " + finalPath + cmd = shlex.split(command) + res = subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT) + + vhost.addRewriteRules(domainName) + installUtilities.reStartLiteSpeed() + + statusFile = open(tempStatusPath, 'w') + statusFile.writelines("Successfully Installed. [200]") + statusFile.close() + return 0 + + + except BaseException, msg: + statusFile = open(tempStatusPath, 'w') + statusFile.writelines(str(msg) + " [404]") + statusFile.close() + return 0 + + def installJoomla(self): try: diff --git a/plogical/sslUtilities.py b/plogical/sslUtilities.py index 2f222c246..84062460c 100644 --- a/plogical/sslUtilities.py +++ b/plogical/sslUtilities.py @@ -196,8 +196,6 @@ class sslUtilities: logging.CyberCPLogFileWriter.writeToFile('Failed to obtain SSL, issuing self-signed SSL for: ' + virtualHostName) return 0 - logging.CyberCPLogFileWriter.writeToFile(command) - pathToStoreSSL = sslUtilities.Server_root + "/conf/vhosts/" + "SSL-" + virtualHostName if not os.path.exists(pathToStoreSSL): diff --git a/plogical/upgrade.py b/plogical/upgrade.py index 88e32e3d6..d53785f84 100644 --- a/plogical/upgrade.py +++ b/plogical/upgrade.py @@ -253,6 +253,7 @@ WantedBy=multi-user.target""" if count == 3: Upgrade.stdOut( "Failed to setup CLI! [setupCLI]") + break else: Upgrade.stdOut("CLI setup successfull!") break @@ -314,14 +315,20 @@ WantedBy=multi-user.target""" os.chdir("/usr/local") + + ## Current Version Version = version.objects.get(pk=1) + ## versionNumbring = Upgrade.downloadLink() + if os.path.exists('/usr/local/CyberPanel.' + versionNumbring): + os.remove('/usr/local/CyberPanel.' + versionNumbring) + if float(Version.currentVersion) < 1.6: Upgrade.stdOut('Upgrades works for version 1.6 onwards.') os._exit(0) diff --git a/static/images/icons/git-logo.png b/static/images/icons/git-logo.png new file mode 100644 index 0000000000000000000000000000000000000000..72dee99e18369a90ef2fd74ce3bd31cbfc196ca2 GIT binary patch literal 1879 zcmZ`)2{e>z82*?BjZji#Zjx;2Vn)^>*S=?LL}mWZ(vWmJlk?RG6gg={UhPO{V; zgF%JMrEsINq=itlToU)we`bz*&$;J(|Mxx5`##V6zTbcTIg@NhG#A21VgLX_mKG)? zcp9ud0w}m&sY`edj}5+tHiiJyqzNul(2z@eS&(c1I3W)J{VV`WFhqX~Km-neDKY?r z900^=`HhG40N^Fq9ds~-f>qG63fSuwq^%qZK?esn{Qzy89RY~3ouldEWbbi`zzR@_ z6oddOxtQDZA;$$HkA7f811T49F&u*%grh>rodg*JsRs4jdqKf^8KkS6E>O&^hKvV| za6t_1a7QS2=SC2Kc#*!`6hdK&I{>sJL2d-TD5!@T<&7dvufDjOWkYevt66 z`!Cl*>=MrR+Qzr_zuZfk6@97lsS$0<*l?*dQslyJo@7~tkDCVlx<(Hk?s?RFmg4ru zGO0$L7U8n9lId*c19QdzEt^Pn2PV=KqHG;PJFJHvviLofeR6 zq*=Iz!JpmW+QVa{m=_I${Na{1ru^glJGKgIn&U!50YFJunix8`w3cKqdXNmo+Eh!E zsf@!6r>qSBLO&PF*I5kf0(qyZzB_kJZAc?l{p{O;HEoe${xAE#oLs3tn>&X8AhjuN zVYuPz)wv@%JzXf)c?ZLV)5fpAF*2RYCA;?qCiE@0&|dWx2_(`jOzyhumcGDSw2jwO zk(_MAB4Lso1q4dy+KIsB+`>nzh4ku?s~$BZJdh4~I#mqDFAn%s4=AB!f7NPKu`|HL z%SId+;NvU!O{BPF+NghjzGm2-WIt)wszKi^b(X<{K0Ue@UuMoo-~zjOhDslIcbXFo zctW$=mEG%)Dr=@}Y71)B=aJJ*7hmMNoK?sIlZrUHFq*GiK%wo5nLX99R{L(sRy)&U z8b0?sZ^%V{m8uAfu96n`mNcw76v0B!vR>J_;J zEO|z{f_Qyz(XG53sZl+>6$`O z`h9t8$}!35OU}4mbBvN`f4jqafe>Hoa*3@PAi+P@O*d1LzN<7E1uidXYOV-i7L)C&)E{6 zDOOA1ufl6Z*~{<9uNBNL>m1 z3j%WCrY_;$lyEA+E0hWkpoYV1E9113)ifONIt08rK|_5XPK|)WO=v&5^e@BlU~hk) znEy9qQbX|2uw$)*eXvh>6eW}jqN1Wy{DT6*yeKrPN^q!e-mIP^6ah<9qDiF@`Sd?1 C?s(<^ literal 0 HcmV?d00001 diff --git a/static/websiteFunctions/websiteFunctions.js b/static/websiteFunctions/websiteFunctions.js index 8a4172522..44702490b 100644 --- a/static/websiteFunctions/websiteFunctions.js +++ b/static/websiteFunctions/websiteFunctions.js @@ -458,6 +458,7 @@ app.controller('websitePages', function($scope,$http) { $scope.fileManagerURL = "/filemanager/"+$("#domainNamePage").text(); $scope.wordPressInstallURL = $("#domainNamePage").text() + "/wordpressInstall"; $scope.joomlaInstallURL = $("#domainNamePage").text() + "/joomlaInstall"; + $scope.setupGit = $("#domainNamePage").text() + "/setupGit"; $scope.domainAliasURL = "/websites/"+$("#domainNamePage").text()+"/domainAlias"; $scope.previewUrl = "/preview/"+$("#domainNamePage").text()+"/"; @@ -4048,7 +4049,7 @@ app.controller('installJoomlaCTRL', function($scope, $http, $timeout) { $scope.wpInstallLoading = true; $scope.goBackDisable = true; - $scope.databasePrefix = 'jm_' + $scope.databasePrefix = 'jm_'; var statusFile; var domain = $("#domainNamePage").text(); @@ -4226,6 +4227,168 @@ app.controller('installJoomlaCTRL', function($scope, $http, $timeout) { + } + + }; + + +}); + + +app.controller('setupGit', function($scope, $http, $timeout) { + + $scope.installationDetailsForm = false; + $scope.installationProgress = true; + $scope.installationFailed = true; + $scope.installationSuccessfull = true; + $scope.couldNotConnect = true; + $scope.gitLoading = true; + $scope.githubBranch = 'master'; + $scope.installProg = true; + + var statusFile; + var domain = $("#domainNamePage").text(); + + function getInstallStatus(){ + + url = "/websites/installWordpressStatus"; + + var data = { + statusFile: statusFile, + domainName: domain + }; + + var config = { + headers : { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + + $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + + if(response.data.abort === 1){ + + if(response.data.installStatus === 1){ + + $scope.installationDetailsForm = true; + $scope.installationProgress = false; + $scope.installationFailed = true; + $scope.installationSuccessfull = false; + $scope.couldNotConnect = true; + $scope.gitLoading = true; + $scope.goBackDisable = false; + + $scope.installationURL = domain; + + $("#installProgress").css("width", "100%"); + $scope.installPercentage = "100"; + $scope.currentStatus = response.data.currentStatus; + $timeout.cancel(); + + } + else{ + + $scope.installationDetailsForm = true; + $scope.installationProgress = false; + $scope.installationFailed = false; + $scope.installationSuccessfull = true; + $scope.couldNotConnect = true; + $scope.gitLoading = true; + $scope.goBackDisable = false; + + $scope.errorMessage = response.data.error_message; + + $("#installProgress").css("width", "0%"); + $scope.installPercentage = "0"; + + } + + } + else{ + $("#installProgress").css("width", response.data.installationProgress + "%"); + $scope.installPercentage = response.data.installationProgress; + $scope.currentStatus = response.data.currentStatus; + + $timeout(getInstallStatus,1000); + + + + } + + } + function cantLoadInitialDatas(response) { + + $scope.canNotFetch = true; + $scope.couldNotConnect = false; + + + } + + + } + + $scope.attachRepo = function(){ + + $scope.installationDetailsForm = true; + $scope.installationProgress = false; + $scope.installationFailed = true; + $scope.installationSuccessfull = true; + $scope.couldNotConnect = true; + $scope.gitLoading = false; + $scope.installProg = false; + + $scope.currentStatus = "Starting installation.."; + + url = "/websites/setupGitRepo"; + + var data = { + domain: domain, + username: $scope.githubUserName, + reponame: $scope.githubRepo, + branch: $scope.githubBranch + }; + + var config = { + headers : { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + if (response.data.installStatus === 1) + { + statusFile = response.data.tempStatusPath; + getInstallStatus(); + } + else{ + + $scope.installationDetailsForm = true; + $scope.installationProgress = false; + $scope.installationFailed = false; + $scope.installationSuccessfull = true; + $scope.couldNotConnect = true; + $scope.gitLoading = true; + + $scope.errorMessage = response.data.error_message; + + } + + + } + function cantLoadInitialDatas(response) { + + + } }; diff --git a/websiteFunctions/static/images/icons/git-logo.png b/websiteFunctions/static/images/icons/git-logo.png new file mode 100644 index 0000000000000000000000000000000000000000..72dee99e18369a90ef2fd74ce3bd31cbfc196ca2 GIT binary patch literal 1879 zcmZ`)2{e>z82*?BjZji#Zjx;2Vn)^>*S=?LL}mWZ(vWmJlk?RG6gg={UhPO{V; zgF%JMrEsINq=itlToU)we`bz*&$;J(|Mxx5`##V6zTbcTIg@NhG#A21VgLX_mKG)? zcp9ud0w}m&sY`edj}5+tHiiJyqzNul(2z@eS&(c1I3W)J{VV`WFhqX~Km-neDKY?r z900^=`HhG40N^Fq9ds~-f>qG63fSuwq^%qZK?esn{Qzy89RY~3ouldEWbbi`zzR@_ z6oddOxtQDZA;$$HkA7f811T49F&u*%grh>rodg*JsRs4jdqKf^8KkS6E>O&^hKvV| za6t_1a7QS2=SC2Kc#*!`6hdK&I{>sJL2d-TD5!@T<&7dvufDjOWkYevt66 z`!Cl*>=MrR+Qzr_zuZfk6@97lsS$0<*l?*dQslyJo@7~tkDCVlx<(Hk?s?RFmg4ru zGO0$L7U8n9lId*c19QdzEt^Pn2PV=KqHG;PJFJHvviLofeR6 zq*=Iz!JpmW+QVa{m=_I${Na{1ru^glJGKgIn&U!50YFJunix8`w3cKqdXNmo+Eh!E zsf@!6r>qSBLO&PF*I5kf0(qyZzB_kJZAc?l{p{O;HEoe${xAE#oLs3tn>&X8AhjuN zVYuPz)wv@%JzXf)c?ZLV)5fpAF*2RYCA;?qCiE@0&|dWx2_(`jOzyhumcGDSw2jwO zk(_MAB4Lso1q4dy+KIsB+`>nzh4ku?s~$BZJdh4~I#mqDFAn%s4=AB!f7NPKu`|HL z%SId+;NvU!O{BPF+NghjzGm2-WIt)wszKi^b(X<{K0Ue@UuMoo-~zjOhDslIcbXFo zctW$=mEG%)Dr=@}Y71)B=aJJ*7hmMNoK?sIlZrUHFq*GiK%wo5nLX99R{L(sRy)&U z8b0?sZ^%V{m8uAfu96n`mNcw76v0B!vR>J_;J zEO|z{f_Qyz(XG53sZl+>6$`O z`h9t8$}!35OU}4mbBvN`f4jqafe>Hoa*3@PAi+P@O*d1LzN<7E1uidXYOV-i7L)C&)E{6 zDOOA1ufl6Z*~{<9uNBNL>m1 z3j%WCrY_;$lyEA+E0hWkpoYV1E9113)ifONIt08rK|_5XPK|)WO=v&5^e@BlU~hk) znEy9qQbX|2uw$)*eXvh>6eW}jqN1Wy{DT6*yeKrPN^q!e-mIP^6ah<9qDiF@`Sd?1 C?s(<^ literal 0 HcmV?d00001 diff --git a/websiteFunctions/static/websiteFunctions/websiteFunctions.js b/websiteFunctions/static/websiteFunctions/websiteFunctions.js index 8a4172522..44702490b 100644 --- a/websiteFunctions/static/websiteFunctions/websiteFunctions.js +++ b/websiteFunctions/static/websiteFunctions/websiteFunctions.js @@ -458,6 +458,7 @@ app.controller('websitePages', function($scope,$http) { $scope.fileManagerURL = "/filemanager/"+$("#domainNamePage").text(); $scope.wordPressInstallURL = $("#domainNamePage").text() + "/wordpressInstall"; $scope.joomlaInstallURL = $("#domainNamePage").text() + "/joomlaInstall"; + $scope.setupGit = $("#domainNamePage").text() + "/setupGit"; $scope.domainAliasURL = "/websites/"+$("#domainNamePage").text()+"/domainAlias"; $scope.previewUrl = "/preview/"+$("#domainNamePage").text()+"/"; @@ -4048,7 +4049,7 @@ app.controller('installJoomlaCTRL', function($scope, $http, $timeout) { $scope.wpInstallLoading = true; $scope.goBackDisable = true; - $scope.databasePrefix = 'jm_' + $scope.databasePrefix = 'jm_'; var statusFile; var domain = $("#domainNamePage").text(); @@ -4226,6 +4227,168 @@ app.controller('installJoomlaCTRL', function($scope, $http, $timeout) { + } + + }; + + +}); + + +app.controller('setupGit', function($scope, $http, $timeout) { + + $scope.installationDetailsForm = false; + $scope.installationProgress = true; + $scope.installationFailed = true; + $scope.installationSuccessfull = true; + $scope.couldNotConnect = true; + $scope.gitLoading = true; + $scope.githubBranch = 'master'; + $scope.installProg = true; + + var statusFile; + var domain = $("#domainNamePage").text(); + + function getInstallStatus(){ + + url = "/websites/installWordpressStatus"; + + var data = { + statusFile: statusFile, + domainName: domain + }; + + var config = { + headers : { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + + $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + + if(response.data.abort === 1){ + + if(response.data.installStatus === 1){ + + $scope.installationDetailsForm = true; + $scope.installationProgress = false; + $scope.installationFailed = true; + $scope.installationSuccessfull = false; + $scope.couldNotConnect = true; + $scope.gitLoading = true; + $scope.goBackDisable = false; + + $scope.installationURL = domain; + + $("#installProgress").css("width", "100%"); + $scope.installPercentage = "100"; + $scope.currentStatus = response.data.currentStatus; + $timeout.cancel(); + + } + else{ + + $scope.installationDetailsForm = true; + $scope.installationProgress = false; + $scope.installationFailed = false; + $scope.installationSuccessfull = true; + $scope.couldNotConnect = true; + $scope.gitLoading = true; + $scope.goBackDisable = false; + + $scope.errorMessage = response.data.error_message; + + $("#installProgress").css("width", "0%"); + $scope.installPercentage = "0"; + + } + + } + else{ + $("#installProgress").css("width", response.data.installationProgress + "%"); + $scope.installPercentage = response.data.installationProgress; + $scope.currentStatus = response.data.currentStatus; + + $timeout(getInstallStatus,1000); + + + + } + + } + function cantLoadInitialDatas(response) { + + $scope.canNotFetch = true; + $scope.couldNotConnect = false; + + + } + + + } + + $scope.attachRepo = function(){ + + $scope.installationDetailsForm = true; + $scope.installationProgress = false; + $scope.installationFailed = true; + $scope.installationSuccessfull = true; + $scope.couldNotConnect = true; + $scope.gitLoading = false; + $scope.installProg = false; + + $scope.currentStatus = "Starting installation.."; + + url = "/websites/setupGitRepo"; + + var data = { + domain: domain, + username: $scope.githubUserName, + reponame: $scope.githubRepo, + branch: $scope.githubBranch + }; + + var config = { + headers : { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + if (response.data.installStatus === 1) + { + statusFile = response.data.tempStatusPath; + getInstallStatus(); + } + else{ + + $scope.installationDetailsForm = true; + $scope.installationProgress = false; + $scope.installationFailed = false; + $scope.installationSuccessfull = true; + $scope.couldNotConnect = true; + $scope.gitLoading = true; + + $scope.errorMessage = response.data.error_message; + + } + + + } + function cantLoadInitialDatas(response) { + + + } }; diff --git a/websiteFunctions/templates/websiteFunctions/setupGit.html b/websiteFunctions/templates/websiteFunctions/setupGit.html new file mode 100644 index 000000000..aeca2bddf --- /dev/null +++ b/websiteFunctions/templates/websiteFunctions/setupGit.html @@ -0,0 +1,171 @@ +{% extends "baseTemplate/index.html" %} +{% load i18n %} +{% block title %}{% trans "Attach Git - CyberPanel" %}{% endblock %} +{% block content %} + +{% load static %} +{% get_current_language as LANGUAGE_CODE %} + + +
+
+

{% trans "Attach Git" %}

+

{% trans "Attach git to your website" %}

+
+ +
+
+

+ {{ domainName }} - {% trans "Attach Git" %} +

+
+ + + +
+
+
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ + +
+ +
+ +
+ +
+ + +
+ +
+ + +
+
+ +
+ +
+ +
+

{$ currentStatus $}

+
+ +
+
+ 70% Complete +
+
+ +
+

{% trans "Installation failed. Error message:" %} {$ errorMessage $}

+
+ +
+

{% trans "Installation successful. Visit:" %} {$ installationURL $}

+
+ + + +
+

{% trans "Could not connect to server. Please refresh this page." %}

+
+ +
+
+ + +
+ +
+
+ + +
+ +
+ + + +
+ +
+ + + + + + + + + + + + +
{% trans "Deployment Key" %}
+
+
+ +
+
+
+
+
+ + + + + +
+ + + +
+
+
+
+
+ + +
+ +{% endblock %} \ No newline at end of file diff --git a/websiteFunctions/templates/websiteFunctions/website.html b/websiteFunctions/templates/websiteFunctions/website.html index 9fc47aa8d..93450ece2 100644 --- a/websiteFunctions/templates/websiteFunctions/website.html +++ b/websiteFunctions/templates/websiteFunctions/website.html @@ -962,6 +962,18 @@ + + +
diff --git a/websiteFunctions/urls.py b/websiteFunctions/urls.py index 6ef871236..8224482ab 100644 --- a/websiteFunctions/urls.py +++ b/websiteFunctions/urls.py @@ -89,4 +89,9 @@ urlpatterns = [ url(r'^(?P([\da-z\.-]+\.[a-z\.]{2,12}|[\d\.]+)([\/:?=&#]{1}[\da-z\.-]+)*[\/\?]?)/joomlaInstall$', views.joomlaInstall, name='joomlaInstall'), + ## Git + url(r'^(?P([\da-z\.-]+\.[a-z\.]{2,12}|[\d\.]+)([\/:?=&#]{1}[\da-z\.-]+)*[\/\?]?)/setupGit$', views.setupGit, name='setupGit'), + url(r'^setupGitRepo$', views.setupGitRepo, name='setupGitRepo'), + + ] \ No newline at end of file diff --git a/websiteFunctions/views.py b/websiteFunctions/views.py index 928959c99..41af79784 100644 --- a/websiteFunctions/views.py +++ b/websiteFunctions/views.py @@ -2282,7 +2282,6 @@ def installWordpress(request): logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[installWordpress]") return HttpResponse("Not Logged in as admin") - def installWordpressStatus(request): try: val = request.session['userID'] @@ -2333,7 +2332,6 @@ def installWordpressStatus(request): return HttpResponse(json_data) - def joomlaInstall(request, domain): try: val = request.session['userID'] @@ -2500,4 +2498,66 @@ def installJoomla(request): except KeyError, msg: status = {"installStatus":0,"error":str(msg)} logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[installJoomla]") + return HttpResponse("Not Logged in as admin") + + +def setupGit(request, domain): + try: + val = request.session['userID'] + admin = Administrator.objects.get(pk=val) + try: + if admin.type != 1: + website = Websites.objects.get(domain=domain) + if website.admin != admin: + raise BaseException('You do not own this website.') + + command = 'sudo cat /root/.ssh/cyberpanel.pub' + deploymentKey = subprocess.check_output(shlex.split(command)).strip('\n') + + return render(request, 'websiteFunctions/setupGit.html', {'domainName' : domain, 'deploymentKey': deploymentKey}) + except BaseException, msg: + logging.CyberCPLogFileWriter.writeToFile(str(msg)) + return HttpResponse(str(msg)) + except KeyError: + return redirect(loadLoginPage) + +def setupGitRepo(request): + try: + val = request.session['userID'] + admin = Administrator.objects.get(pk=val) + + if request.method == 'POST': + try: + data = json.loads(request.body) + + mailUtilities.checkHome() + + extraArgs = {} + extraArgs['admin'] = admin + extraArgs['domainName'] = data['domain'] + extraArgs['username'] = data['username'] + extraArgs['reponame'] = data['reponame'] + extraArgs['branch'] = data['branch'] + extraArgs['tempStatusPath'] = "/home/cyberpanel/" + str(randint(1000, 9999)) + + + background = ApplicationInstaller('git', extraArgs) + background.start() + + time.sleep(2) + + data_ret = {'installStatus': 1, 'error_message': 'None', 'tempStatusPath': extraArgs['tempStatusPath']} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + + + except BaseException, msg: + data_ret = {'installStatus': 0, 'error_message': str(msg)} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + + + except KeyError, msg: + status = {"installStatus":0,"error":str(msg)} + logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[installWordpress]") return HttpResponse("Not Logged in as admin") \ No newline at end of file