summaryrefslogtreecommitdiffstats
path: root/ogcp/views.py
diff options
context:
space:
mode:
authorAlejandro Sirgo Rica <asirgo@soleta.eu>2024-05-09 11:25:58 +0200
committerAlejandro Sirgo Rica <asirgo@soleta.eu>2024-05-09 12:00:58 +0200
commit30562a9af524da8cbd08592b74d788ce3a9405e1 (patch)
tree21e7daf23707c25b6550ed7e2c45966ac0cb47c6 /ogcp/views.py
parentdd77bc380e5ce0c5d9cb34e236a61837aea66261 (diff)
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'.
Diffstat (limited to 'ogcp/views.py')
-rw-r--r--ogcp/views.py11
1 files 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')}")