From ebcad8c58706cc99f9896dea52d1626f97a790b3 Mon Sep 17 00:00:00 2001 From: usmannasir <01-134132-158@student.bahria.edu.pk> Date: Sat, 28 Jul 2018 01:25:51 +0500 Subject: [PATCH] Minor bug fixes --- install/install.py | 4 + plogical/applicationInstaller.py | 56 ++++++++ static/websiteFunctions/websiteFunctions.js | 132 +++++++++++++++++- .../websiteFunctions/websiteFunctions.js | 132 +++++++++++++++++- .../templates/websiteFunctions/setupGit.html | 46 ++++-- websiteFunctions/urls.py | 3 +- websiteFunctions/views.py | 76 +++++++++- 7 files changed, 431 insertions(+), 18 deletions(-) diff --git a/install/install.py b/install/install.py index c1fc8a9a6..205f81715 100644 --- a/install/install.py +++ b/install/install.py @@ -2052,6 +2052,10 @@ class preFlightsChecks: cmd = shlex.split(command) subprocess.call(cmd) + command = 'systemctl restart systemd-logind' + cmd = shlex.split(command) + subprocess.call(cmd) + count = 0 diff --git a/plogical/applicationInstaller.py b/plogical/applicationInstaller.py index c60d23f84..c4d4b3581 100644 --- a/plogical/applicationInstaller.py +++ b/plogical/applicationInstaller.py @@ -35,6 +35,10 @@ class ApplicationInstaller(multi.Thread): self.setupGit() elif self.installApp == 'pull': self.gitPull() + elif self.installApp == 'detach': + self.detachRepo() + elif self.installApp == 'changeBranch': + self.changeBranch() except BaseException, msg: logging.writeToFile( str(msg) + ' [ApplicationInstaller.run]') @@ -480,6 +484,36 @@ class ApplicationInstaller(multi.Thread): logging.writeToFile(str(msg)+ " [ApplicationInstaller.gitPull]") return 0 + def detachRepo(self): + try: + domain = self.extraArgs['domainName'] + + command = 'sudo rm -rf /home/' + domain + '/public_html' + subprocess.check_output(shlex.split(command)) + + command = 'sudo mkdir /home/' + domain + '/public_html' + subprocess.check_output(shlex.split(command)) + + website = Websites.objects.get(domain=domain) + externalApp = website.externalApp + + ## + + command = "sudo chown -R " + externalApp + ":" + externalApp + " " + '/home/' + domain + '/public_html' + cmd = shlex.split(command) + subprocess.call(cmd) + + gitPath = '/home/cyberpanel/' + domain + '.git' + + os.remove(gitPath) + + return 0 + + + except BaseException, msg: + logging.writeToFile(str(msg)+ " [ApplicationInstaller.gitPull]") + return 0 + def installJoomla(self): try: @@ -666,3 +700,25 @@ class ApplicationInstaller(multi.Thread): statusFile.writelines(str(msg) + " [404]") statusFile.close() return 0 + + def changeBranch(self): + try: + domainName = self.extraArgs['domainName'] + githubBranch = self.extraArgs['githubBranch'] + + try: + command = 'sudo GIT_SSH_COMMAND="ssh -i /root/.ssh/cyberpanel -o StrictHostKeyChecking=no" git -C /home/' + domainName + '/public_html/ checkout -b' + 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: + return 0 diff --git a/static/websiteFunctions/websiteFunctions.js b/static/websiteFunctions/websiteFunctions.js index 3bf3ce938..fb7887c3d 100644 --- a/static/websiteFunctions/websiteFunctions.js +++ b/static/websiteFunctions/websiteFunctions.js @@ -4235,7 +4235,7 @@ app.controller('installJoomlaCTRL', function($scope, $http, $timeout) { }); -app.controller('setupGit', function($scope, $http, $timeout) { +app.controller('setupGit', function($scope, $http, $timeout, $window) { $scope.installationDetailsForm = false; $scope.installationProgress = true; @@ -4298,6 +4298,7 @@ app.controller('setupGit', function($scope, $http, $timeout) { $scope.installPercentage = "100"; $scope.currentStatus = response.data.currentStatus; $timeout.cancel(); + $timeout(function() { $window.location.reload(); }, 3000); } else{ @@ -4405,7 +4406,6 @@ app.controller('setupGit', function($scope, $http, $timeout) { }; - $scope.goBack = function () { $scope.installationDetailsForm = false; $scope.installationProgress = true; @@ -4418,5 +4418,133 @@ app.controller('setupGit', function($scope, $http, $timeout) { $("#installProgress").css("width", "0%"); }; + /// Detach Repo + + $scope.failedMesg = true; + $scope.successMessage = true; + $scope.couldNotConnect = true; + $scope.gitLoading = true; + $scope.successMessageBranch = true; + + $scope.detachRepo = function(){ + + $scope.failedMesg = true; + $scope.successMessage = true; + $scope.couldNotConnect = true; + $scope.gitLoading = false; + $scope.successMessageBranch = true; + + url = "/websites/detachRepo"; + + var data = { + domain: domain + }; + + var config = { + headers : { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + $scope.gitLoading = true; + + if (response.data.status === 1) + { + $scope.failedMesg = true; + $scope.successMessage = false; + $scope.couldNotConnect = true; + $scope.successMessageBranch = true; + + $timeout(function() { $window.location.reload(); }, 3000); + + } + else{ + + $scope.failedMesg = false; + $scope.successMessage = true; + $scope.couldNotConnect = true; + $scope.successMessageBranch = true; + + $scope.errorMessage = response.data.error_message; + + + } + + + } + function cantLoadInitialDatas(response) { + $scope.failedMesg = true; + $scope.successMessage = true; + $scope.couldNotConnect = false; + $scope.gitLoading = true; + $scope.successMessageBranch = true; + } + + }; + $scope.changeBranch = function(){ + + $scope.failedMesg = true; + $scope.successMessage = true; + $scope.couldNotConnect = true; + $scope.gitLoading = false; + $scope.successMessageBranch = true; + + url = "/websites/changeBranch"; + + var data = { + domain: domain, + githubBranch: $scope.githubBranch + }; + + var config = { + headers : { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + $scope.gitLoading = true; + + if (response.data.status === 1) + { + $scope.failedMesg = true; + $scope.successMessage = true; + $scope.couldNotConnect = true; + $scope.successMessageBranch = false; + + } + else{ + + $scope.failedMesg = false; + $scope.successMessage = true; + $scope.couldNotConnect = true; + $scope.successMessageBranch = true; + + $scope.errorMessage = response.data.error_message; + + + } + + + } + function cantLoadInitialDatas(response) { + $scope.failedMesg = true; + $scope.successMessage = true; + $scope.couldNotConnect = false; + $scope.gitLoading = true; + $scope.successMessageBranch = true; + } + + }; + }); \ No newline at end of file diff --git a/websiteFunctions/static/websiteFunctions/websiteFunctions.js b/websiteFunctions/static/websiteFunctions/websiteFunctions.js index 3bf3ce938..fb7887c3d 100644 --- a/websiteFunctions/static/websiteFunctions/websiteFunctions.js +++ b/websiteFunctions/static/websiteFunctions/websiteFunctions.js @@ -4235,7 +4235,7 @@ app.controller('installJoomlaCTRL', function($scope, $http, $timeout) { }); -app.controller('setupGit', function($scope, $http, $timeout) { +app.controller('setupGit', function($scope, $http, $timeout, $window) { $scope.installationDetailsForm = false; $scope.installationProgress = true; @@ -4298,6 +4298,7 @@ app.controller('setupGit', function($scope, $http, $timeout) { $scope.installPercentage = "100"; $scope.currentStatus = response.data.currentStatus; $timeout.cancel(); + $timeout(function() { $window.location.reload(); }, 3000); } else{ @@ -4405,7 +4406,6 @@ app.controller('setupGit', function($scope, $http, $timeout) { }; - $scope.goBack = function () { $scope.installationDetailsForm = false; $scope.installationProgress = true; @@ -4418,5 +4418,133 @@ app.controller('setupGit', function($scope, $http, $timeout) { $("#installProgress").css("width", "0%"); }; + /// Detach Repo + + $scope.failedMesg = true; + $scope.successMessage = true; + $scope.couldNotConnect = true; + $scope.gitLoading = true; + $scope.successMessageBranch = true; + + $scope.detachRepo = function(){ + + $scope.failedMesg = true; + $scope.successMessage = true; + $scope.couldNotConnect = true; + $scope.gitLoading = false; + $scope.successMessageBranch = true; + + url = "/websites/detachRepo"; + + var data = { + domain: domain + }; + + var config = { + headers : { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + $scope.gitLoading = true; + + if (response.data.status === 1) + { + $scope.failedMesg = true; + $scope.successMessage = false; + $scope.couldNotConnect = true; + $scope.successMessageBranch = true; + + $timeout(function() { $window.location.reload(); }, 3000); + + } + else{ + + $scope.failedMesg = false; + $scope.successMessage = true; + $scope.couldNotConnect = true; + $scope.successMessageBranch = true; + + $scope.errorMessage = response.data.error_message; + + + } + + + } + function cantLoadInitialDatas(response) { + $scope.failedMesg = true; + $scope.successMessage = true; + $scope.couldNotConnect = false; + $scope.gitLoading = true; + $scope.successMessageBranch = true; + } + + }; + $scope.changeBranch = function(){ + + $scope.failedMesg = true; + $scope.successMessage = true; + $scope.couldNotConnect = true; + $scope.gitLoading = false; + $scope.successMessageBranch = true; + + url = "/websites/changeBranch"; + + var data = { + domain: domain, + githubBranch: $scope.githubBranch + }; + + var config = { + headers : { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + $scope.gitLoading = true; + + if (response.data.status === 1) + { + $scope.failedMesg = true; + $scope.successMessage = true; + $scope.couldNotConnect = true; + $scope.successMessageBranch = false; + + } + else{ + + $scope.failedMesg = false; + $scope.successMessage = true; + $scope.couldNotConnect = true; + $scope.successMessageBranch = true; + + $scope.errorMessage = response.data.error_message; + + + } + + + } + function cantLoadInitialDatas(response) { + $scope.failedMesg = true; + $scope.successMessage = true; + $scope.couldNotConnect = false; + $scope.gitLoading = true; + $scope.successMessageBranch = true; + } + + }; + }); \ No newline at end of file diff --git a/websiteFunctions/templates/websiteFunctions/setupGit.html b/websiteFunctions/templates/websiteFunctions/setupGit.html index 2badea094..9b4527864 100644 --- a/websiteFunctions/templates/websiteFunctions/setupGit.html +++ b/websiteFunctions/templates/websiteFunctions/setupGit.html @@ -1,21 +1,21 @@ {% extends "baseTemplate/index.html" %} {% load i18n %} -{% block title %}{% trans "Attach Git - CyberPanel" %}{% endblock %} +{% block title %}{% trans "Git Management - CyberPanel" %}{% endblock %} {% block content %} {% load static %} {% get_current_language as LANGUAGE_CODE %} -
{% trans "Attach git to your website" %}
+{% trans "Attach git to your websites." %}
@@ -120,7 +120,7 @@
{% trans "GIT Successfully attached. Visit:" %} {$ installationURL $}
+{% trans "GIT Successfully attached, refreshing page in 3 seconds... Visit:" %} {$ installationURL $}
@@ -220,9 +220,9 @@
{% trans "Add this URL to Webhooks section of your Git respository, if you've used hostname SSL then replace IP with your hostname. Otherwise use IP and disable SSL check while configuring webhook. This will initiate a pull from your resposity as soon as you commit some changes."%} {{ webhookURL }}
{% trans "Error message:" %} {$ errorMessage $}
+{% trans "Repo successfully detached, refreshing in 3 seconds.." %}
+{% trans "Could not connect to server. Please refresh this page." %}
+{% trans "Error message:" %} {$ errorMessage $}
{% trans "Branch successfully changed." %}