mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-10 23:36:11 +01:00
fix issue with design on n8n page
This commit is contained in:
@@ -162,6 +162,71 @@ def restartContainer(request):
|
|||||||
container.restart()
|
container.restart()
|
||||||
return HttpResponse(json.dumps({'status': 1}))
|
return HttpResponse(json.dumps({'status': 1}))
|
||||||
|
|
||||||
|
return HttpResponse('Not allowed')
|
||||||
|
except Exception as e:
|
||||||
|
return HttpResponse(json.dumps({
|
||||||
|
'status': 0,
|
||||||
|
'error_message': str(e)
|
||||||
|
}))
|
||||||
|
|
||||||
|
@csrf_exempt
|
||||||
|
@require_login
|
||||||
|
def n8n_container_operation(request):
|
||||||
|
try:
|
||||||
|
if request.method == 'POST':
|
||||||
|
userID = request.session['userID']
|
||||||
|
currentACL = ACLManager.loadedACL(userID)
|
||||||
|
admin = Administrator.objects.get(pk=userID)
|
||||||
|
|
||||||
|
data = json.loads(request.body)
|
||||||
|
container_id = data.get('container_id')
|
||||||
|
operation = data.get('operation')
|
||||||
|
|
||||||
|
# Get the container
|
||||||
|
docker_manager = DockerManager()
|
||||||
|
container = docker_manager.get_container(container_id)
|
||||||
|
|
||||||
|
if not container:
|
||||||
|
return HttpResponse(json.dumps({
|
||||||
|
'status': 0,
|
||||||
|
'error_message': 'Container not found'
|
||||||
|
}))
|
||||||
|
|
||||||
|
# Handle different operations
|
||||||
|
if operation == 'create_backup':
|
||||||
|
# For now, just return mock data to test UI functionality
|
||||||
|
backup_options = data.get('options', {})
|
||||||
|
include_credentials = backup_options.get('includeCredentials', True)
|
||||||
|
include_executions = backup_options.get('includeExecutions', False)
|
||||||
|
|
||||||
|
# In a real implementation, you would call the n8n API to create a backup
|
||||||
|
# For now, simulate a successful backup
|
||||||
|
|
||||||
|
return HttpResponse(json.dumps({
|
||||||
|
'status': 1,
|
||||||
|
'message': 'Backup simulation successful. In a production environment, this would download a backup file.',
|
||||||
|
# In real implementation, you would provide a download URL
|
||||||
|
# 'download_url': '/path/to/download/backup.json'
|
||||||
|
}))
|
||||||
|
|
||||||
|
elif operation == 'restore_backup':
|
||||||
|
# For now, just return mock data to test UI functionality
|
||||||
|
backup_data = data.get('backup_data')
|
||||||
|
|
||||||
|
# In a real implementation, you would call the n8n API to restore from backup
|
||||||
|
# For now, simulate a successful restore
|
||||||
|
|
||||||
|
return HttpResponse(json.dumps({
|
||||||
|
'status': 1,
|
||||||
|
'message': 'Restore simulation successful.'
|
||||||
|
}))
|
||||||
|
|
||||||
|
else:
|
||||||
|
return HttpResponse(json.dumps({
|
||||||
|
'status': 0,
|
||||||
|
'error_message': f'Unknown operation: {operation}'
|
||||||
|
}))
|
||||||
|
|
||||||
return HttpResponse('Not allowed')
|
return HttpResponse('Not allowed')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return HttpResponse(json.dumps({
|
return HttpResponse(json.dumps({
|
||||||
|
|||||||
@@ -348,37 +348,31 @@ app.controller('ListDockersitecontainer', function ($scope, $http) {
|
|||||||
|
|
||||||
// Backup and Restore Functions
|
// Backup and Restore Functions
|
||||||
|
|
||||||
// Initialize backup options
|
// Function to initialize backup options for a container
|
||||||
$scope.initBackupOptions = function(container) {
|
$scope.initBackupOptions = function(container) {
|
||||||
|
// Initialize backup options if not present
|
||||||
if (!container.backupOptions) {
|
if (!container.backupOptions) {
|
||||||
container.backupOptions = {
|
container.backupOptions = {
|
||||||
includeCredentials: true,
|
includeCredentials: true,
|
||||||
includeExecutions: false
|
includeExecutions: false
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!container.scheduledBackup) {
|
|
||||||
container.scheduledBackup = {
|
|
||||||
frequency: 'disabled',
|
|
||||||
retention: 30
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Create a backup
|
// Function to create a backup
|
||||||
$scope.createBackup = function(container) {
|
$scope.createBackup = function(container) {
|
||||||
|
// Initialize options if not already done
|
||||||
|
$scope.initBackupOptions(container);
|
||||||
|
|
||||||
$scope.cyberpanelLoading = false;
|
$scope.cyberpanelLoading = false;
|
||||||
$('#cyberpanelLoading').show();
|
$('#cyberpanelLoading').show();
|
||||||
|
|
||||||
// Initialize backup options if they don't exist
|
var url = "/docker/n8n_container_operation";
|
||||||
$scope.initBackupOptions(container);
|
|
||||||
|
|
||||||
var url = "/websites/n8n/create_backup";
|
|
||||||
|
|
||||||
var data = {
|
var data = {
|
||||||
'container_id': container.id,
|
'container_id': container.id,
|
||||||
'include_credentials': container.backupOptions.includeCredentials,
|
'operation': 'create_backup',
|
||||||
'include_executions': container.backupOptions.includeExecutions
|
'options': container.backupOptions
|
||||||
};
|
};
|
||||||
|
|
||||||
var config = {
|
var config = {
|
||||||
@@ -387,74 +381,74 @@ app.controller('ListDockersitecontainer', function ($scope, $http) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
$http.post(url, data, config).then(function(response) {
|
$http.post(url, data, config).then(
|
||||||
$scope.cyberpanelLoading = true;
|
function(response) {
|
||||||
$('#cyberpanelLoading').hide();
|
$scope.cyberpanelLoading = true;
|
||||||
|
$('#cyberpanelLoading').hide();
|
||||||
if (response.data.status === 1) {
|
|
||||||
// Download the backup file
|
|
||||||
var backupData = response.data.backup;
|
|
||||||
var fileName = 'n8n-backup-' + new Date().toISOString().slice(0, 10) + '.json';
|
|
||||||
|
|
||||||
// Create a download link
|
if (response.data.status === 1) {
|
||||||
var a = document.createElement('a');
|
new PNotify({
|
||||||
var blob = new Blob([JSON.stringify(backupData)], {type: 'application/json'});
|
title: 'Success!',
|
||||||
var url = window.URL.createObjectURL(blob);
|
text: 'Backup created successfully. ' + (response.data.message || ''),
|
||||||
a.href = url;
|
type: 'success'
|
||||||
a.download = fileName;
|
});
|
||||||
a.click();
|
|
||||||
window.URL.revokeObjectURL(url);
|
// Add download link if provided
|
||||||
|
if (response.data.download_url) {
|
||||||
|
window.location.href = response.data.download_url;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
new PNotify({
|
||||||
|
title: 'Operation Failed!',
|
||||||
|
text: response.data.error_message || 'Failed to create backup. Please try again.',
|
||||||
|
type: 'error'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
function(error) {
|
||||||
|
$scope.cyberpanelLoading = true;
|
||||||
|
$('#cyberpanelLoading').hide();
|
||||||
|
|
||||||
new PNotify({
|
|
||||||
title: 'Success!',
|
|
||||||
text: 'Backup created and downloaded successfully.',
|
|
||||||
type: 'success'
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
new PNotify({
|
new PNotify({
|
||||||
title: 'Operation Failed!',
|
title: 'Operation Failed!',
|
||||||
text: response.data.error_message,
|
text: 'Connection error while creating backup.',
|
||||||
type: 'error'
|
type: 'error'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.error("Error creating backup:", error);
|
||||||
}
|
}
|
||||||
}, function(response) {
|
);
|
||||||
$scope.cyberpanelLoading = true;
|
|
||||||
$('#cyberpanelLoading').hide();
|
|
||||||
|
|
||||||
new PNotify({
|
|
||||||
title: 'Operation Failed!',
|
|
||||||
text: 'Connection disrupted, refresh the page.',
|
|
||||||
type: 'error'
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Restore from a backup
|
// Function to restore from a backup
|
||||||
$scope.restoreFromBackup = function(container) {
|
$scope.restoreFromBackup = function(container) {
|
||||||
// Check if a file has been selected
|
|
||||||
var fileInput = document.getElementById('backupFile');
|
var fileInput = document.getElementById('backupFile');
|
||||||
|
|
||||||
if (!fileInput.files || fileInput.files.length === 0) {
|
if (!fileInput.files || fileInput.files.length === 0) {
|
||||||
new PNotify({
|
new PNotify({
|
||||||
title: 'Error!',
|
title: 'Warning!',
|
||||||
text: 'Please select a backup file to restore.',
|
text: 'Please select a backup file first.',
|
||||||
type: 'error'
|
type: 'warning'
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var file = fileInput.files[0];
|
||||||
|
var reader = new FileReader();
|
||||||
|
|
||||||
$scope.cyberpanelLoading = false;
|
$scope.cyberpanelLoading = false;
|
||||||
$('#cyberpanelLoading').show();
|
$('#cyberpanelLoading').show();
|
||||||
|
|
||||||
// Read the backup file
|
|
||||||
var reader = new FileReader();
|
|
||||||
reader.onload = function(e) {
|
reader.onload = function(e) {
|
||||||
try {
|
try {
|
||||||
|
// Try to parse the file as JSON to verify it's a valid backup
|
||||||
var backupData = JSON.parse(e.target.result);
|
var backupData = JSON.parse(e.target.result);
|
||||||
|
|
||||||
var url = "/websites/n8n/restore_backup";
|
var url = "/docker/n8n_container_operation";
|
||||||
|
|
||||||
var data = {
|
var data = {
|
||||||
'container_id': container.id,
|
'container_id': container.id,
|
||||||
|
'operation': 'restore_backup',
|
||||||
'backup_data': backupData
|
'backup_data': backupData
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -464,49 +458,73 @@ app.controller('ListDockersitecontainer', function ($scope, $http) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
$http.post(url, data, config).then(function(response) {
|
$http.post(url, data, config).then(
|
||||||
$scope.cyberpanelLoading = true;
|
function(response) {
|
||||||
$('#cyberpanelLoading').hide();
|
$scope.cyberpanelLoading = true;
|
||||||
|
$('#cyberpanelLoading').hide();
|
||||||
if (response.data.status === 1) {
|
|
||||||
new PNotify({
|
if (response.data.status === 1) {
|
||||||
title: 'Success!',
|
new PNotify({
|
||||||
text: 'Backup restored successfully.',
|
title: 'Success!',
|
||||||
type: 'success'
|
text: 'Backup restored successfully.',
|
||||||
});
|
type: 'success'
|
||||||
|
});
|
||||||
|
|
||||||
|
// Refresh workflows and credentials after restore
|
||||||
|
if (typeof $scope.refreshWorkflows === 'function') {
|
||||||
|
$scope.refreshWorkflows(container);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof $scope.refreshCredentials === 'function') {
|
||||||
|
$scope.refreshCredentials(container);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
new PNotify({
|
||||||
|
title: 'Operation Failed!',
|
||||||
|
text: response.data.error_message || 'Failed to restore backup.',
|
||||||
|
type: 'error'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
function(error) {
|
||||||
|
$scope.cyberpanelLoading = true;
|
||||||
|
$('#cyberpanelLoading').hide();
|
||||||
|
|
||||||
// Refresh workflows after restore
|
|
||||||
$scope.refreshWorkflows(container);
|
|
||||||
} else {
|
|
||||||
new PNotify({
|
new PNotify({
|
||||||
title: 'Operation Failed!',
|
title: 'Operation Failed!',
|
||||||
text: response.data.error_message,
|
text: 'Connection error while restoring backup.',
|
||||||
type: 'error'
|
type: 'error'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.error("Error restoring backup:", error);
|
||||||
}
|
}
|
||||||
}, function(response) {
|
);
|
||||||
$scope.cyberpanelLoading = true;
|
} catch (e) {
|
||||||
$('#cyberpanelLoading').hide();
|
|
||||||
|
|
||||||
new PNotify({
|
|
||||||
title: 'Operation Failed!',
|
|
||||||
text: 'Connection disrupted, refresh the page.',
|
|
||||||
type: 'error'
|
|
||||||
});
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
$scope.cyberpanelLoading = true;
|
$scope.cyberpanelLoading = true;
|
||||||
$('#cyberpanelLoading').hide();
|
$('#cyberpanelLoading').hide();
|
||||||
|
|
||||||
new PNotify({
|
new PNotify({
|
||||||
title: 'Error!',
|
title: 'Invalid Backup File',
|
||||||
text: 'Invalid backup file format: ' + error.message,
|
text: 'The selected file is not a valid backup file.',
|
||||||
type: 'error'
|
type: 'error'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.error("Error parsing backup file:", e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
reader.readAsText(fileInput.files[0]);
|
reader.onerror = function() {
|
||||||
|
$scope.cyberpanelLoading = true;
|
||||||
|
$('#cyberpanelLoading').hide();
|
||||||
|
|
||||||
|
new PNotify({
|
||||||
|
title: 'Operation Failed!',
|
||||||
|
text: 'Error reading the backup file.',
|
||||||
|
type: 'error'
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
reader.readAsText(file);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Save backup schedule
|
// Save backup schedule
|
||||||
|
|||||||
@@ -773,7 +773,7 @@
|
|||||||
<i class="fa fa-history"></i>
|
<i class="fa fa-history"></i>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
from django.urls import path
|
from django.urls import path
|
||||||
from . import views
|
from . import views
|
||||||
|
from websiteFunctions.dockerviews import startContainer, stopContainer, restartContainer, n8n_container_operation
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', views.loadWebsitesHome, name='loadWebsitesHome'),
|
path('', views.loadWebsitesHome, name='loadWebsitesHome'),
|
||||||
@@ -180,9 +181,10 @@ urlpatterns = [
|
|||||||
path('fetchDockersite', views.fetchDockersite, name='fetchDockersite'),
|
path('fetchDockersite', views.fetchDockersite, name='fetchDockersite'),
|
||||||
|
|
||||||
# Docker Container Actions
|
# Docker Container Actions
|
||||||
path('docker/startContainer', views.startContainer, name='startContainer'),
|
path('docker/startContainer', startContainer, name='startContainer'),
|
||||||
path('docker/stopContainer', views.stopContainer, name='stopContainer'),
|
path('docker/stopContainer', stopContainer, name='stopContainer'),
|
||||||
path('docker/restartContainer', views.restartContainer, name='restartContainer'),
|
path('docker/restartContainer', restartContainer, name='restartContainer'),
|
||||||
|
path('docker/n8n_container_operation', n8n_container_operation, name='n8n_container_operation'),
|
||||||
|
|
||||||
# SSH Configs
|
# SSH Configs
|
||||||
path('getSSHConfigs', views.getSSHConfigs, name='getSSHConfigs'),
|
path('getSSHConfigs', views.getSSHConfigs, name='getSSHConfigs'),
|
||||||
|
|||||||
Reference in New Issue
Block a user