From 30562a9af524da8cbd08592b74d788ce3a9405e1 Mon Sep 17 00:00:00 2001 From: Alejandro Sirgo Rica Date: Thu, 9 May 2024 11:25:58 +0200 Subject: views: prevent image restore on invalid partition types Add partition type info to the form data. Check if the user is trying to restore on an invalid partition type and report an error if that's the case. The invalid types are 'EMPTY', 'LINUX-SWAP', 'CACHE', 'EFI' and 'WIN-RECOV'. --- ogcp/views.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/ogcp/views.py b/ogcp/views.py index 131686c..3bbd933 100644 --- a/ogcp/views.py +++ b/ogcp/views.py @@ -735,7 +735,14 @@ def action_image_restore(): form = ImageRestoreForm(request.form) if request.method == 'POST': ips = form.ips.data.split(' ') - disk, partition = form.partition.data.split(' ') + disk, partition, part_code = form.partition.data.split(' ') + + part_type = PART_TYPE_CODES.get(int(part_code), 'UNKNOWN') + invalid_part_types = ['EMPTY', 'LINUX-SWAP', 'CACHE', 'EFI', 'WIN-RECOV'] + if part_type in invalid_part_types: + flash(_(f'Cannot restore image on partition type {part_type}'), category='error') + return redirect(url_for('commands')) + image_id = form.image.data server = get_server_from_clients(ips) r = server.get('/images') @@ -829,7 +836,7 @@ def action_image_restore(): return redirect(url_for('commands')) form.partition.choices = [ - (f"{disk_id} {part_id}", + (f"{disk_id} {part_id} {part_code}", f"Disk {disk_id} | Partition {part_id} " f"| {PART_TYPE_CODES.get(part_code, 'UNKNOWN')} " f"{FS_CODES.get(filesystem, 'UNKNOWN')}") -- cgit v1.2.3-18-g5258