From d126db1fe94e7826ebad970619ece383e7f7e9f7 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Sat, 7 Mar 2015 13:52:40 +0100 Subject: [PATCH] The upload interfaces allow user to choose an image type --- gns3server/handlers/upload_handler.py | 8 ++++++-- gns3server/templates/upload.html | 7 ++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/gns3server/handlers/upload_handler.py b/gns3server/handlers/upload_handler.py index 0df82392..2ca5eb1e 100644 --- a/gns3server/handlers/upload_handler.py +++ b/gns3server/handlers/upload_handler.py @@ -55,9 +55,13 @@ class UploadHandler: response.redirect("/upload") return - destination_path = os.path.join(UploadHandler.image_directory(), data["file"].filename) + if data["type"] not in ["IOU", "QEMU", "IOS"]: + raise HTTPForbidden("You are not authorized to upload this kind of image {}".format(data["type"])) + + destination_dir = os.path.join(UploadHandler.image_directory(), data["type"]) + destination_path = os.path.join(destination_dir, data["file"].filename) try: - os.makedirs(UploadHandler.image_directory(), exist_ok=True) + os.makedirs(destination_dir, exist_ok=True) with open(destination_path, "wb+") as f: chunk = data["file"].file.read() f.write(chunk) diff --git a/gns3server/templates/upload.html b/gns3server/templates/upload.html index 0cd9fbcc..1b230474 100644 --- a/gns3server/templates/upload.html +++ b/gns3server/templates/upload.html @@ -2,7 +2,12 @@ {% block body %}

Select & Upload an image for GNS3

- File: + File:
+ Image type: