mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2026-02-17 03:56:48 +01:00
MySQL Manager: fix empty status/processes, error messages, deploy-safe
This commit is contained in:
@@ -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();
|
||||
});
|
||||
|
||||
|
||||
@@ -667,23 +667,4 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Add refresh functionality if not already present
|
||||
if (typeof app !== 'undefined') {
|
||||
app.controller('Mysqlmanager', function($scope, $http, $interval) {
|
||||
// Existing controller code...
|
||||
|
||||
$scope.refreshProcesses = function() {
|
||||
// Trigger a refresh of the processes
|
||||
var icon = document.querySelector('.refresh-btn i');
|
||||
icon.style.animation = 'spin 1s linear';
|
||||
setTimeout(function() {
|
||||
icon.style.animation = '';
|
||||
}, 1000);
|
||||
// The actual refresh logic should be implemented in the controller
|
||||
};
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user