From 126c191be22b84c9f26609a5843dd3a23af03e0a Mon Sep 17 00:00:00 2001 From: Usman Nasir Date: Mon, 4 May 2020 13:36:27 +0500 Subject: [PATCH] add package upgrade for ubuntu --- firewall/static/firewall/firewall.js | 2 - plogical/applicationInstaller.py | 35 ++++++ .../static/serverStatus/serverStatus.js | 89 ++++++++++++++- .../serverStatus/packageManager.html | 101 +++++++++++++++++- serverStatus/urls.py | 1 + serverStatus/views.py | 39 +++++++ 6 files changed, 260 insertions(+), 7 deletions(-) diff --git a/firewall/static/firewall/firewall.js b/firewall/static/firewall/firewall.js index a0acd1f53..eaa372adb 100755 --- a/firewall/static/firewall/firewall.js +++ b/firewall/static/firewall/firewall.js @@ -2171,8 +2171,6 @@ app.controller('installImunify', function ($scope, $http, $timeout, $window) { text: 'Could not connect to server, please refresh this page', type: 'error' }); - - } } diff --git a/plogical/applicationInstaller.py b/plogical/applicationInstaller.py index 57b3909ed..5063926d3 100755 --- a/plogical/applicationInstaller.py +++ b/plogical/applicationInstaller.py @@ -33,6 +33,7 @@ class ApplicationInstaller(multi.Thread): def run(self): try: + if self.installApp == 'wordpress': self.installWordPress() elif self.installApp == 'joomla': @@ -51,10 +52,44 @@ class ApplicationInstaller(multi.Thread): self.installMagento() elif self.installApp == 'convertDomainToSite': self.convertDomainToSite() + elif self.installApp == 'updatePackage': + self.updatePackage() except BaseException as msg: logging.writeToFile(str(msg) + ' [ApplicationInstaller.run]') + def updatePackage(self): + try: + + package = self.extraArgs['package'] + + from serverStatus.serverStatusUtil import ServerStatusUtil + + f = open(ServerStatusUtil.lswsInstallStatusPath, 'a') + + if package == 'all': + command = 'apt-get update -y' + f.write(ProcessUtilities.outputExecutioner(command)) + + f.flush() + + command = 'apt-get upgrade -y' + f.write(ProcessUtilities.outputExecutioner(command)) + else: + command = 'apt-get install --only-upgrade %s -y' % (package) + f.write(ProcessUtilities.outputExecutioner(command)) + + f.close() + + logging.statusWriter(ServerStatusUtil.lswsInstallStatusPath, + 'Package(s) upgraded successfully. [200]', + 1) + + except BaseException as msg: + from serverStatus.serverStatusUtil import ServerStatusUtil + logging.statusWriter(ServerStatusUtil.lswsInstallStatusPath, 'Failed. Error: %s. [404]' % (str(msg)), 1) + return 0 + def convertDomainToSite(self): try: diff --git a/serverStatus/static/serverStatus/serverStatus.js b/serverStatus/static/serverStatus/serverStatus.js index 7ab77b3d1..40689c2f7 100755 --- a/serverStatus/static/serverStatus/serverStatus.js +++ b/serverStatus/static/serverStatus/serverStatus.js @@ -836,9 +836,9 @@ app.controller('listOSPackages', function ($scope, $http, $timeout) { }; $scope.fetchPackages('upgrade'); - $scope.fetchPackageDetails = function (package) { + $scope.fetchPackageDetails = function (packageFetch) { $scope.cyberpanelLoading = false; - $scope.package = package; + $scope.package = packageFetch; var config = { headers: { @@ -847,7 +847,7 @@ app.controller('listOSPackages', function ($scope, $http, $timeout) { }; var data = { - package: package + package: packageFetch }; dataurl = "/serverstatus/fetchPackageDetails"; @@ -878,4 +878,87 @@ app.controller('listOSPackages', function ($scope, $http, $timeout) { }; + $scope.updatePackage = function (packageToUpgrade = 'all') { + $scope.cyberpanelLoading = false; + $scope.package = packageToUpgrade; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + var data = { + package: packageToUpgrade + }; + + dataurl = "/serverstatus/updatePackage"; + + $http.post(dataurl, data, config).then(ListInitialData, cantLoadInitialData); + + function ListInitialData(response) { + $scope.cyberpanelLoading = true; + if (response.data.status === 1) { + getRequestStatus(); + } else { + new PNotify({ + title: 'Error!', + text: response.data.error_message, + type: 'error' + }); + } + } + function cantLoadInitialData(response) { + $scope.cyberpanelLoading = true; + new PNotify({ + title: 'Operation Failed!', + text: 'Could not connect to server, please refresh this page', + type: 'error' + }); + } + + + }; + + function getRequestStatus() { + + $scope.cyberpanelLoading = false; + + url = "/serverstatus/switchTOLSWSStatus"; + + var data = {}; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + if (response.data.abort === 0) { + $scope.requestData = response.data.requestStatus; + $timeout(getRequestStatus, 1000); + } else { + // Notifications + $timeout.cancel(); + $scope.cyberpanelLoading = true; + $scope.requestData = response.data.requestStatus; + } + } + + function cantLoadInitialDatas(response) { + $scope.cyberpanelLoading = true; + new PNotify({ + title: 'Operation Failed!', + text: 'Could not connect to server, please refresh this page', + type: 'error' + }); + } + + } + }); \ No newline at end of file diff --git a/serverStatus/templates/serverStatus/packageManager.html b/serverStatus/templates/serverStatus/packageManager.html index c94bd995b..7cea53791 100755 --- a/serverStatus/templates/serverStatus/packageManager.html +++ b/serverStatus/templates/serverStatus/packageManager.html @@ -37,6 +37,57 @@ Fetched Packages: {$ fetchedPackages $} + + Update All + + +
- Upgrade + title="">Update + + + diff --git a/serverStatus/urls.py b/serverStatus/urls.py index 3b554822c..91242fc0b 100755 --- a/serverStatus/urls.py +++ b/serverStatus/urls.py @@ -21,5 +21,6 @@ urlpatterns = [ url(r'^packageManager$', views.packageManager, name='packageManager'), url(r'^fetchPackages$', views.fetchPackages, name='fetchPackages'), url(r'^fetchPackageDetails$', views.fetchPackageDetails, name='fetchPackageDetails'), + url(r'^updatePackage$', views.updatePackage, name='updatePackage'), ] \ No newline at end of file diff --git a/serverStatus/views.py b/serverStatus/views.py index e63f6f4ba..77744e94e 100755 --- a/serverStatus/views.py +++ b/serverStatus/views.py @@ -817,6 +817,45 @@ def fetchPackageDetails(request): json_data = json.dumps(data_ret) return HttpResponse(json_data) + except BaseException as msg: + data_ret = {'status': 0, 'error_message': str(msg)} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + +def updatePackage(request): + try: + + userID = request.session['userID'] + currentACL = ACLManager.loadedACL(userID) + + if currentACL['admin'] == 1: + pass + else: + return ACLManager.loadError() + + data = json.loads(request.body) + package = data['package'] + + from serverStatus.serverStatusUtil import ServerStatusUtil + + logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath, + 'Starting package(s) upgrade..', + 1) + + extraArgs = {} + extraArgs['package'] = package + + from plogical.applicationInstaller import ApplicationInstaller + + background = ApplicationInstaller('updatePackage', extraArgs) + background.start() + + time.sleep(2) + + data_ret = {'status': 1} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + except BaseException as msg: data_ret = {'status': 0, 'error_message': str(msg)} json_data = json.dumps(data_ret)