From 530d5a01898654b28b30ebb283db9a2971e85936 Mon Sep 17 00:00:00 2001 From: Usman Nasir Date: Sat, 2 May 2020 17:51:01 +0500 Subject: [PATCH] bug fix: topProcessesStatus --- .../static/serverStatus/serverStatus.js | 2 + .../serverStatus/packageManager.html | 7 + serverStatus/views.py | 45 ++++- static/databases/databases.js | 6 +- static/ftp/ftp.js | 6 +- static/mailServer/mailServer.js | 6 +- static/serverStatus/serverStatus.js | 154 ++++++++++++++---- static/userManagment/userManagment.js | 6 +- version.txt | 2 +- 9 files changed, 181 insertions(+), 53 deletions(-) mode change 100755 => 100644 static/databases/databases.js diff --git a/serverStatus/static/serverStatus/serverStatus.js b/serverStatus/static/serverStatus/serverStatus.js index 476cde44d..5dca427db 100755 --- a/serverStatus/static/serverStatus/serverStatus.js +++ b/serverStatus/static/serverStatus/serverStatus.js @@ -812,6 +812,8 @@ app.controller('listOSPackages', function ($scope, $http, $timeout) { if (response.data.status === 1) { $scope.allPackages = JSON.parse(response.data.packages); $scope.pagination = response.data.pagination; + $scope.fetchedPackages = response.data.fetchedPackages; + $scope.totalPackages = response.data.totalPackages; } else { new PNotify({ title: 'Error!', diff --git a/serverStatus/templates/serverStatus/packageManager.html b/serverStatus/templates/serverStatus/packageManager.html index a91ac5373..c9d7afe9d 100755 --- a/serverStatus/templates/serverStatus/packageManager.html +++ b/serverStatus/templates/serverStatus/packageManager.html @@ -33,6 +33,12 @@

Howdy, I'm in Section 4.

+ Total Packages: {$ totalPackages $} + Fetched Packages: {$ fetchedPackages $}
10 +
diff --git a/serverStatus/views.py b/serverStatus/views.py index 2fe1c11a2..d7e605c40 100755 --- a/serverStatus/views.py +++ b/serverStatus/views.py @@ -579,17 +579,45 @@ def topProcessesStatus(request): data['Softirqs'] = loadNow[13] + '%' ## Memory - data['totalMemory'] = str(int(float(memory[3]) / 1024)) + 'MB' - data['freeMemory'] = str(int(float(memory[5]) / 1024)) + 'MB' - data['usedMemory'] = str(int(float(memory[7]) / 1024)) + 'MB' - data['buffCache'] = str(int(float(memory[9]) / 1024)) + 'MB' + + if memory[3].find('+') > -1: + memoryFinal = memory[3].split('+')[0] + else: + memoryFinal = memory[3] + + data['totalMemory'] = str(int(float(memoryFinal) / 1024)) + 'MB' + + ## + + if memory[5].find('free') > -1: + data['freeMemory'] = str(int(float(memory[4]) / 1024)) + 'MB' + else: + data['freeMemory'] = str(int(float(memory[5]) / 1024)) + 'MB' + + ## + + if memory[7].find('used') > -1: + data['usedMemory'] = str(int(float(memory[6]) / 1024)) + 'MB' + else: + data['usedMemory'] = str(int(float(memory[7]) / 1024)) + 'MB' + + if memory[9].find('buff') > -1: + data['buffCache'] = str(int(float(memory[8]) / 1024)) + 'MB' + else: + data['buffCache'] = str(int(float(memory[9]) / 1024)) + 'MB' ## Swap + data['swapTotalMemory'] = str(int(float(swap[2]) / 1024)) + 'MB' data['swapFreeMemory'] = str(int(float(swap[4]) / 1024)) + 'MB' data['swapUsedMemory'] = str(int(float(swap[6]) / 1024)) + 'MB' - data['swapBuffCache'] = str(int(float(swap[8]) / 1024)) + 'MB' + + if swap[8].find('+') > -1: + finalBuffCache = swap[8].split('+')[0] + data['swapBuffCache'] = str(int(float(finalBuffCache) / 1024)) + 'MB' + else: + data['swapBuffCache'] = str(int(float(swap[8]) / 1024)) + 'MB' ## Processes @@ -686,7 +714,7 @@ def fetchPackages(request): return ACLManager.loadError() data = json.loads(request.body) - page = int(data['page'].rstrip('\n')) + page = int(str(data['page']).rstrip('\n')) recordsToShow = int(data['recordsToShow']) packageInformation = '/home/cyberpanel/OSPackages' @@ -704,12 +732,12 @@ def fetchPackages(request): from s3Backups.s3Backups import S3Backups pagination = S3Backups.getPagination(len(packages), recordsToShow) - logging.CyberCPLogFileWriter.writeToFile(str(pagination)) endPageNumber, finalPageNumber = S3Backups.recordsPointer(page, recordsToShow) finalPackages = packages[finalPageNumber:endPageNumber] json_data = "[" checker = 0 + counter = 0 # if os.path.exists(ProcessUtilities.debugPath): # logging.CyberCPLogFileWriter.writeToFile('Final packages: %s' % (str(finalPackages))) @@ -717,6 +745,7 @@ def fetchPackages(request): for items in finalPackages: items = re.sub(r'("[\s\w]*)"([\s\w])*"([\s\w]*)',r"\1\2\3", items) try: + counter = counter + 1 if checker == 0: json_data = json_data + items checker = 1 @@ -727,7 +756,7 @@ def fetchPackages(request): json_data = json_data + ']' - data_ret = {'status': 1, 'packages': json_data, 'pagination': pagination} + data_ret = {'status': 1, 'packages': json_data, 'pagination': pagination, 'fetchedPackages': counter, 'totalPackages': len(packages)} json_data = json.dumps(data_ret) return HttpResponse(json_data) diff --git a/static/databases/databases.js b/static/databases/databases.js old mode 100755 new mode 100644 index e13d25977..d1e91175b --- a/static/databases/databases.js +++ b/static/databases/databases.js @@ -106,7 +106,7 @@ app.controller('createDatabase', function ($scope, $http) { $scope.generatePassword = function () { $scope.generatedPasswordView = false; - $scope.dbPassword = randomPassword(12); + $scope.dbPassword = randomPassword(16); }; $scope.usePassword = function () { @@ -447,7 +447,7 @@ app.controller('listDBs', function ($scope, $http) { $scope.generatePassword = function () { $scope.generatedPasswordView = false; - $scope.dbPassword = randomPassword(12); + $scope.dbPassword = randomPassword(16); }; $scope.usePassword = function () { @@ -493,4 +493,4 @@ app.controller('phpMyAdmin', function ($scope, $http, $window) { } setupPHPMYAdminSession(); -}); \ No newline at end of file +}); diff --git a/static/ftp/ftp.js b/static/ftp/ftp.js index 679a8b5f7..a80377e6b 100644 --- a/static/ftp/ftp.js +++ b/static/ftp/ftp.js @@ -113,7 +113,7 @@ app.controller('createFTPAccount', function ($scope, $http) { $scope.generatePassword = function () { $scope.generatedPasswordView = false; - $scope.ftpPassword = randomPassword(12); + $scope.ftpPassword = randomPassword(16); }; $scope.usePassword = function () { @@ -451,11 +451,11 @@ app.controller('listFTPAccounts', function ($scope, $http) { $scope.generatePassword = function () { $scope.generatedPasswordView = false; - $scope.ftpPassword = randomPassword(12); + $scope.ftpPassword = randomPassword(16); }; $scope.usePassword = function () { $scope.generatedPasswordView = true; }; -}); \ No newline at end of file +}); diff --git a/static/mailServer/mailServer.js b/static/mailServer/mailServer.js index f50b36a45..3bf1db1c3 100644 --- a/static/mailServer/mailServer.js +++ b/static/mailServer/mailServer.js @@ -110,7 +110,7 @@ app.controller('createEmailAccount', function ($scope, $http) { $scope.generatePassword = function () { $scope.generatedPasswordView = false; - $scope.emailPassword = randomPassword(12); + $scope.emailPassword = randomPassword(16); }; $scope.usePassword = function () { @@ -465,7 +465,7 @@ app.controller('changeEmailPassword', function ($scope, $http) { $scope.generatePassword = function () { $scope.generatedPasswordView = false; - $scope.emailPassword = randomPassword(12); + $scope.emailPassword = randomPassword(16); }; $scope.usePassword = function () { @@ -1291,4 +1291,4 @@ app.controller('listEmails', function ($scope, $http) { }); -/* Java script code for List Emails Ends here */ \ No newline at end of file +/* Java script code for List Emails Ends here */ diff --git a/static/serverStatus/serverStatus.js b/static/serverStatus/serverStatus.js index db70955a0..5dca427db 100644 --- a/static/serverStatus/serverStatus.js +++ b/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,113 @@ 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; + $scope.fetchedPackages = response.data.fetchedPackages; + $scope.totalPackages = response.data.totalPackages; + } 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/static/userManagment/userManagment.js b/static/userManagment/userManagment.js index 39cbf5d6d..73eaed9a5 100644 --- a/static/userManagment/userManagment.js +++ b/static/userManagment/userManagment.js @@ -113,7 +113,7 @@ app.controller('createUserCtr', function ($scope, $http) { $scope.generatePassword = function () { $scope.generatedPasswordView = false; - $scope.password = randomPassword(12); + $scope.password = randomPassword(16); }; $scope.usePassword = function () { @@ -342,7 +342,7 @@ app.controller('modifyUser', function ($scope, $http) { $scope.generatePassword = function () { $scope.generatedPasswordView = false; - $scope.password = randomPassword(12); + $scope.password = randomPassword(16); }; $scope.usePassword = function () { @@ -1744,4 +1744,4 @@ app.controller('listTableUsers', function ($scope, $http) { }); -/* Java script code to list table users */ \ No newline at end of file +/* Java script code to list table users */ diff --git a/version.txt b/version.txt index ca1e53142..c085faed0 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -{"version":"2.0","build":0} \ No newline at end of file +{"version":"2.0","build":1} \ No newline at end of file