mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-07 05:45:59 +01:00
front end for n8n version
This commit is contained in:
@@ -162,58 +162,6 @@ def restartContainer(request):
|
||||
container.restart()
|
||||
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 executeCommand(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')
|
||||
command = data.get('command')
|
||||
site_name = data.get('name')
|
||||
|
||||
# Verify Docker site ownership
|
||||
try:
|
||||
docker_site = DockerSites.objects.get(SiteName=site_name)
|
||||
if currentACL['admin'] != 1 and docker_site.admin != admin and docker_site.admin.owner != admin.pk:
|
||||
return HttpResponse(json.dumps({
|
||||
'status': 0,
|
||||
'error_message': 'Not authorized to access this container'
|
||||
}))
|
||||
except DockerSites.DoesNotExist:
|
||||
return HttpResponse(json.dumps({
|
||||
'status': 0,
|
||||
'error_message': 'Docker site not found'
|
||||
}))
|
||||
|
||||
docker_manager = DockerManager()
|
||||
container = docker_manager.get_container(container_id)
|
||||
|
||||
if not container:
|
||||
return HttpResponse(json.dumps({
|
||||
'status': 0,
|
||||
'error_message': 'Container not found'
|
||||
}))
|
||||
|
||||
# Execute the command
|
||||
result = container.exec_run(command)
|
||||
|
||||
return HttpResponse(json.dumps({
|
||||
'status': 1,
|
||||
'output': result.output.decode('utf-8')
|
||||
}))
|
||||
|
||||
return HttpResponse('Not allowed')
|
||||
except Exception as e:
|
||||
return HttpResponse(json.dumps({
|
||||
|
||||
Reference in New Issue
Block a user