diff --git a/serverStatus/static/serverStatus/serverStatus.js b/serverStatus/static/serverStatus/serverStatus.js index db70955a0..476cde44d 100755 --- a/serverStatus/static/serverStatus/serverStatus.js +++ b/serverStatus/static/serverStatus/serverStatus.js @@ -3,7 +3,6 @@ */ - /* Java script code to start/stop litespeed */ app.controller('litespeedStatus', function ($scope, $http) { @@ -49,8 +48,7 @@ app.controller('litespeedStatus', function ($scope, $http) { $scope.actionResultBad = true; $scope.serverStatusCouldNotConnect = true; - } - else { + } else { $scope.restartorStopLoading = true; $scope.actionResult = true; @@ -109,8 +107,7 @@ app.controller('litespeedStatus', function ($scope, $http) { $scope.actionResultBad = true; $scope.serverStatusCouldNotConnect = true; - } - else { + } else { $scope.restartorStopLoading = true; $scope.actionResult = true; @@ -174,8 +171,7 @@ app.controller('litespeedStatus', function ($scope, $http) { }); $scope.lsSerial = response.data.lsSerial; $scope.lsexpiration = response.data.lsexpiration; - } - else { + } else { $scope.cpLoading = true; new PNotify({ title: 'Operation Failed!', @@ -229,8 +225,7 @@ app.controller('litespeedStatus', function ($scope, $http) { text: 'License successfully Updated', type: 'success' }); - } - else { + } else { $scope.cpLoading = true; new PNotify({ title: 'Operation Failed!', @@ -292,8 +287,7 @@ app.controller('readCyberCPLogFile', function ($scope, $http) { $scope.logsData = response.data.logsdata; - } - else { + } else { $scope.logFileLoading = true; $scope.logsFeteched = true; @@ -347,8 +341,7 @@ app.controller('readCyberCPLogFile', function ($scope, $http) { $scope.logsData = response.data.logsdata; - } - else { + } else { $scope.logFileLoading = true; $scope.logsFeteched = true; @@ -409,8 +402,7 @@ app.controller('servicesManager', function ($scope, $http) { $scope.olsStart = false; $scope.olsStop = true; $scope.olsMem = Math.round(parseInt(response.data.memUsage.litespeed) / 1048576) + " MB"; - } - else { + } else { $scope.olsStatus = "Stopped"; $scope.olsStats = false; $scope.olsStart = true; @@ -421,8 +413,7 @@ app.controller('servicesManager', function ($scope, $http) { $scope.dockerStatus = "Running"; $scope.dockerStart = false; $scope.dockerStop = true; - } - else { + } else { $scope.dockerStatus = "Stopped"; $scope.dockerStart = true; $scope.dockerStop = false; @@ -435,8 +426,7 @@ app.controller('servicesManager', function ($scope, $http) { $scope.sqlStart = false; $scope.sqlStop = true; $scope.sqlMem = Math.round(parseInt(response.data.memUsage.mysql) / 1048576) + " MB"; - } - else { + } else { $scope.sqlStatus = "Stopped"; $scope.sqlStats = false; $scope.sqlStart = true; @@ -451,8 +441,7 @@ app.controller('servicesManager', function ($scope, $http) { $scope.dnsStart = false; $scope.dnsStop = true; $scope.dnsMem = Math.round(parseInt(response.data.memUsage.powerdns) / 1048576) + " MB"; - } - else { + } else { $scope.dnsStatus = "Stopped"; $scope.dnsStats = false; $scope.dnsStart = true; @@ -467,8 +456,7 @@ app.controller('servicesManager', function ($scope, $http) { $scope.ftpStart = false; $scope.ftpStop = true; $scope.ftpMem = Math.round(parseInt(response.data.memUsage.pureftp) / 1048576) + " MB"; - } - else { + } else { $scope.ftpStatus = "Stopped"; $scope.ftpStats = false; $scope.ftpStart = true; @@ -487,6 +475,7 @@ app.controller('servicesManager', function ($scope, $http) { } } + getServiceStatus(); $scope.serviceAction = function (serviceName, action) { @@ -524,8 +513,7 @@ app.controller('servicesManager', function ($scope, $http) { $scope.actionLoader = false; $scope.btnDisable = false; }, 3000); - } - else { + } else { setTimeout(function () { getServiceStatus(); $scope.ActionSuccessfull = false; @@ -583,8 +571,7 @@ app.controller('lswsSwitch', function ($scope, $http, $timeout, $window) { if (response.data.status === 1) { $scope.installBoxGen = false; getRequestStatus(); - } - else { + } else { new PNotify({ title: 'Operation Failed!', text: response.data.error_message, @@ -626,8 +613,7 @@ app.controller('lswsSwitch', function ($scope, $http, $timeout, $window) { if (response.data.abort === 0) { $scope.requestData = response.data.requestStatus; $timeout(getRequestStatus, 1000); - } - else { + } else { // Notifications $scope.cyberPanelLoading = true; $timeout.cancel(); @@ -720,8 +706,7 @@ app.controller('topProcesses', function ($scope, $http, $timeout) { $scope.zombieProcesses = response.data.zombieProcesses; $timeout($scope.topProcessesStatus, 3000); - } - else { + } else { new PNotify({ title: 'Operation Failed!', text: response.data.error_message, @@ -771,8 +756,111 @@ app.controller('topProcesses', function ($scope, $http, $timeout) { text: 'Process successfully killed.', type: 'success' }); + } else { + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); } - else { + + } + + function cantLoadInitialDatas(response) { + $scope.cyberPanelLoading = true; + new PNotify({ + title: 'Operation Failed!', + text: 'Could not connect to server, please refresh this page', + type: 'error' + }); + } + + }; + +}); + +/// + + +app.controller('listOSPackages', function ($scope, $http, $timeout) { + + $scope.cyberpanelLoading = true; + + $scope.currentPage = 1; + $scope.recordsToShow = 10; + + $scope.fetchPackages = function () { + $scope.cyberpanelLoading = false; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + var data = { + page: $scope.currentPage, + recordsToShow: $scope.recordsToShow + }; + + dataurl = "/serverstatus/fetchPackages"; + + $http.post(dataurl, data, config).then(ListInitialData, cantLoadInitialData); + + function ListInitialData(response) { + $scope.cyberpanelLoading = true; + if (response.data.status === 1) { + $scope.allPackages = JSON.parse(response.data.packages); + $scope.pagination = response.data.pagination; + } 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' + }); + } + + + }; + + $scope.killProcess = function (pid) { + + $scope.cyberPanelLoading = false; + + url = "/serverstatus/killProcess"; + + var data = { + pid: pid + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $scope.cyberPanelLoading = true; + if (response.data.status === 1) { + new PNotify({ + title: 'Success', + text: 'Process successfully killed.', + type: 'success' + }); + } else { new PNotify({ title: 'Operation Failed!', text: response.data.error_message, diff --git a/serverStatus/templates/serverStatus/packageManager.html b/serverStatus/templates/serverStatus/packageManager.html index 021cf834e..a91ac5373 100755 --- a/serverStatus/templates/serverStatus/packageManager.html +++ b/serverStatus/templates/serverStatus/packageManager.html @@ -8,7 +8,7 @@ -
+

{% trans "Package Manager" %}

@@ -22,53 +22,77 @@
-
-

I'm in Section 1.

-
-
-

Howdy, I'm in Section 2.

-
-
-

Howdy, I'm in Section 3.

-

Howdy, I'm in Section 4.

-
-

Howdy, I'm in Section 5.

-
-

Howdy, I'm in Section 6.

+
+ +
+
+
+ +
+
+
+
+ + + + + + + + + + + + + + + + + + +
{% trans "Package" %}{% trans "Description" %}{% trans "Status" %}{% trans "Version" %}
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+

Howdy, I'm in Section 7.

-
-

Howdy, I'm in Section 8.

-
-
-

Howdy, I'm in Section 9.

-
diff --git a/serverStatus/urls.py b/serverStatus/urls.py index 43ffa605b..65c60b533 100755 --- a/serverStatus/urls.py +++ b/serverStatus/urls.py @@ -19,5 +19,6 @@ urlpatterns = [ url(r'^topProcessesStatus$', views.topProcessesStatus, name='topProcessesStatus'), url(r'^killProcess$', views.killProcess, name='killProcess'), url(r'^packageManager$', views.packageManager, name='packageManager'), + url(r'^fetchPackages$', views.fetchPackages, name='fetchPackages'), ] \ No newline at end of file diff --git a/serverStatus/views.py b/serverStatus/views.py index b0fe234b1..08c7b376e 100755 --- a/serverStatus/views.py +++ b/serverStatus/views.py @@ -6,7 +6,7 @@ from django.http import HttpResponse import plogical.CyberCPLogFileWriter as logging from loginSystem.views import loadLoginPage import json -import subprocess +import subprocess, shlex import psutil import socket from plogical.acl import ACLManager @@ -672,4 +672,65 @@ def packageManager(request): except KeyError as msg: logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[packageManager]") - return redirect(loadLoginPage) \ No newline at end of file + return redirect(loadLoginPage) + +def fetchPackages(request): + try: + + userID = request.session['userID'] + currentACL = ACLManager.loadedACL(userID) + + if currentACL['admin'] == 1: + pass + else: + return ACLManager.loadError() + + data = json.loads(request.body) + page = int(data['page']) + recordsToShow = int(data['recordsToShow']) + + packageInformation = '/home/cyberpanel/OSPackages' + f = open(packageInformation, "w") + + if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu: + command = 'dpkg-query -f \'{"status":"${db:Status-Abbrev}","package":"${binary:Package}","version":"${Version}","description":"${binary:Summary}"}\n\' -W' + subprocess.call(shlex.split(command), stdout=f) + + packages = ProcessUtilities.outputExecutioner('cat %s' % (packageInformation)).split('\n') + + if os.path.exists(ProcessUtilities.debugPath): + logging.CyberCPLogFileWriter.writeToFile('All packages: %s' % (str(packages))) + + from s3Backups.s3Backups import S3Backups + + pagination = S3Backups.getPagination(len(packages), recordsToShow) + endPageNumber, finalPageNumber = S3Backups.recordsPointer(page, recordsToShow) + finalPackages = packages[finalPageNumber:endPageNumber] + + json_data = "[" + checker = 0 + + if os.path.exists(ProcessUtilities.debugPath): + logging.CyberCPLogFileWriter.writeToFile('Final packages: %s' % (str(finalPackages))) + + for items in finalPackages: + logging.CyberCPLogFileWriter.writeToFile(items) + try: + if checker == 0: + json_data = json_data + items + checker = 1 + else: + json_data = json_data + ',' + items + except: + logging.CyberCPLogFileWriter.writeToFile(items) + + json_data = json_data + ']' + + data_ret = {'status': 1, 'packages': json_data, 'pagination': pagination} + 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) \ No newline at end of file diff --git a/websiteFunctions/website.py b/websiteFunctions/website.py index 68763d5df..996b9f48d 100755 --- a/websiteFunctions/website.py +++ b/websiteFunctions/website.py @@ -3613,7 +3613,6 @@ StrictHostKeyChecking no else: return ACLManager.loadErrorJson() - logging.CyberCPLogFileWriter.writeToFile('hello world 2') ## Security check