diff --git a/databases/static/databases/databases.js b/databases/static/databases/databases.js index 0c5bbb12e..0eb8469fb 100644 --- a/databases/static/databases/databases.js +++ b/databases/static/databases/databases.js @@ -683,7 +683,11 @@ app.controller('phpMyAdmin', function ($scope, $http, $window) { app.controller('Mysqlmanager', function ($scope, $http, $compile, $window, $timeout) { $scope.cyberPanelLoading = false; - $scope.mysql_status = 'test' + $scope.mysql_status = 'test'; + $scope.uptime = '—'; + $scope.connections = '—'; + $scope.Slow_queries = '—'; + $scope.processes = []; $scope.getstatus = function () { @@ -706,12 +710,27 @@ app.controller('Mysqlmanager', function ($scope, $http, $compile, $window, $time function ListInitialDatas(response) { $scope.cyberPanelLoading = false; - if (response.data.status === 1) { - $scope.uptime = response.data.uptime; - $scope.connections = response.data.connections; - $scope.Slow_queries = response.data.Slow_queries; - $scope.processes = JSON.parse(response.data.processes); - $timeout($scope.showStatus, 3000); + var data = response.data; + if (typeof data === 'string') { + try { + data = JSON.parse(data); + } catch (e) { + new PNotify({ title: 'Error!', text: 'Invalid response from server.', type: 'error' }); + return; + } + } + if (data && data.status === 1) { + $scope.uptime = data.uptime || '—'; + $scope.connections = data.connections != null ? data.connections : '—'; + $scope.Slow_queries = data.Slow_queries != null ? data.Slow_queries : '—'; + try { + $scope.processes = typeof data.processes === 'string' ? JSON.parse(data.processes || '[]') : (data.processes || []); + } catch (e) { + $scope.processes = []; + } + if (typeof $scope.showStatus === 'function') { + $timeout($scope.showStatus, 3000); + } new PNotify({ title: 'Success', @@ -721,7 +740,7 @@ app.controller('Mysqlmanager', function ($scope, $http, $compile, $window, $time } else { new PNotify({ title: 'Error!', - text: response.data.error_message, + text: (data && data.error_message) || 'Could not load MySQL status.', type: 'error' }); } @@ -730,15 +749,25 @@ app.controller('Mysqlmanager', function ($scope, $http, $compile, $window, $time function cantLoadInitialDatas(response) { $scope.cyberPanelLoading = false; + var msg = (response.data && response.data.error_message) || (response.statusText || 'Cannot load MySQL status.'); new PNotify({ title: 'Error!', - text: "cannot load", + text: msg, type: 'error' }); } } + $scope.refreshProcesses = function () { + var icon = document.querySelector('.refresh-btn i'); + if (icon) { + icon.style.animation = 'spin 1s linear'; + setTimeout(function () { icon.style.animation = ''; }, 1000); + } + $scope.getstatus(); + }; + $scope.getstatus(); }); diff --git a/databases/templates/databases/mysqlmanager.html b/databases/templates/databases/mysqlmanager.html index d88200dcd..9ebac5523 100644 --- a/databases/templates/databases/mysqlmanager.html +++ b/databases/templates/databases/mysqlmanager.html @@ -667,23 +667,4 @@ - - {% endblock %} diff --git a/databases/views.py b/databases/views.py index 4b473f9e1..e32f96371 100644 --- a/databases/views.py +++ b/databases/views.py @@ -390,17 +390,18 @@ def UpgradeMySQL(request): def getMysqlstatus(request): try: userID = request.session['userID'] - finalData = mysqlUtilities.showStatus() - currentACL = ACLManager.loadedACL(userID) - if currentACL['admin'] == 1: - pass - else: + if currentACL['admin'] != 1: return ACLManager.loadErrorJson('FilemanagerAdmin', 0) - finalData = json.dumps(finalData) - return HttpResponse(finalData) + finalData = mysqlUtilities.showStatus() + if finalData == 0: + finalData = {'status': 0, 'error_message': 'Could not connect to MySQL or fetch status.'} + else: + finalData.setdefault('status', 1) + body = json.dumps(finalData) + return HttpResponse(body, content_type='application/json') except KeyError: return redirect(loadLoginPage) diff --git a/plogical/mysqlUtilities.py b/plogical/mysqlUtilities.py index 123c96189..28756e8d1 100644 --- a/plogical/mysqlUtilities.py +++ b/plogical/mysqlUtilities.py @@ -547,30 +547,31 @@ password=%s checker = 0 for items in result: - if len(str(items[1])) == 0: + # SHOW PROCESSLIST: Id, User, Host, db, Command, Time, State, Info [, Progress] + if items[3] is None or len(str(items[3])) == 0: database = 'NULL' else: - database = items[1] + database = items[3] - if len(str(items[6])) == 0: - state = 'NULL' - else: + if len(items) > 6 and items[6] is not None and len(str(items[6])) > 0: state = items[6] - - if len(str(items[7])) == '': - info = 'NULL' else: + state = 'NULL' + + if len(items) > 7 and items[7] is not None and len(str(items[7])) > 0: info = items[7] + else: + info = 'NULL' dic = { 'id': items[0], 'user': items[1], 'database': database, - 'command': items[4], - 'time': items[5], + 'command': items[4] if len(items) > 4 else '', + 'time': items[5] if len(items) > 5 else 0, 'state': state, 'info': info, - 'progress': items[8], + 'progress': items[8] if len(items) > 8 else 0, } if checker == 0: