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'.
master
Alejandro Sirgo Rica 2024-05-09 11:25:58 +02:00
parent dd77bc380e
commit 30562a9af5
1 changed files with 9 additions and 2 deletions

View File

@ -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')}")