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" %}

-

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

+

{% trans "Git Management" %}

+

{% trans "Attach git to your websites." %}

{% if not installed %} -
+

{{ domainName }} - {% trans "Attach Git" %} @@ -120,7 +120,7 @@

-

{% trans "GIT Successfully attached. Visit:" %} {$ installationURL $}

+

{% trans "GIT Successfully attached, refreshing page in 3 seconds... Visit:" %} {$ installationURL $}

@@ -194,7 +194,7 @@ {% else %} -
+

{{ domainName }} @@ -220,9 +220,9 @@
  • - + - Detach Repo + {% trans 'Detach Repo' %}
  • @@ -231,6 +231,28 @@

    {% trans 'Webhook URL' %}

    {% 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." %}

+
+ +
+
+

@@ -251,7 +273,7 @@
- +
@@ -264,7 +286,7 @@

{% trans "Error message:" %} {$ errorMessage $}

-
+

{% trans "Branch successfully changed." %}

@@ -275,7 +297,7 @@
-
+
diff --git a/websiteFunctions/urls.py b/websiteFunctions/urls.py index 88b0bb1f8..a6f46f6d0 100644 --- a/websiteFunctions/urls.py +++ b/websiteFunctions/urls.py @@ -94,7 +94,8 @@ urlpatterns = [ url(r'^setupGitRepo$', views.setupGitRepo, name='setupGitRepo'), url(r'^(?P([\da-z\.-]+\.[a-z\.]{2,12}|[\d\.]+)([\/:?=&#]{1}[\da-z\.-]+)*[\/\?]?)/gitNotify$', views.gitNotify, name='gitNotify'), - + url(r'^detachRepo$', views.detachRepo, name='detachRepo'), + url(r'^changeBranch$', views.changeBranch, name='changeBranch'), ] \ No newline at end of file diff --git a/websiteFunctions/views.py b/websiteFunctions/views.py index 5f2aa1250..2a7201446 100644 --- a/websiteFunctions/views.py +++ b/websiteFunctions/views.py @@ -2602,4 +2602,78 @@ def gitNotify(request, domain): except KeyError, msg: data_ret = {"pulled":0,"error":str(msg)} json_data = json.dumps(data_ret) - return HttpResponse(json_data) \ No newline at end of file + return HttpResponse(json_data) + + +def detachRepo(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['domainName'] = data['domain'] + + + background = ApplicationInstaller('detach', extraArgs) + background.start() + + time.sleep(2) + + data_ret = {'status': 1, 'error_message': 'None'} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + + + except BaseException, msg: + data_ret = {'status': 0, 'error_message': str(msg)} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + + + except KeyError, msg: + status = {"status":0,"error":str(msg)} + logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[installWordpress]") + return HttpResponse("Not Logged in as admin") + +def changeBranch(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['domainName'] = data['domain'] + extraArgs['githubBranch'] = data['githubBranch'] + + + background = ApplicationInstaller('changeBranch', extraArgs) + background.start() + + time.sleep(2) + + data_ret = {'status': 1, 'error_message': 'None'} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + + + except BaseException, msg: + data_ret = {'status': 0, 'error_message': str(msg)} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + + + except KeyError, msg: + status = {"status":0,"error":str(msg)} + logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[installWordpress]") + return HttpResponse("Not Logged in as admin") \ No newline at end of file