diff --git a/CTFd/config.py b/CTFd/config.py index 2672eae2..269ed70e 100644 --- a/CTFd/config.py +++ b/CTFd/config.py @@ -85,7 +85,7 @@ class Config(object): The default destination is the CTFd/uploads folder. If you need Amazon S3 files you can use the CTFd S3 plugin: https://github.com/ColdHeat/CTFd-S3-plugin ''' - UPLOAD_FOLDER = os.path.normpath('uploads') + UPLOAD_FOLDER = os.path.join(os.path.dirname(__file__), 'uploads') ''' diff --git a/CTFd/utils.py b/CTFd/utils.py index 4cf7906e..2ae9591f 100644 --- a/CTFd/utils.py +++ b/CTFd/utils.py @@ -790,3 +790,25 @@ def import_ctf(backup, segments=None, erase=False): table.insert(entry) else: continue + + ## Extracting files + files = [f for f in backup.namelist() if f.startswith('uploads/')] + upload_folder = app.config.get('UPLOAD_FOLDER') + for f in files: + filename = f.split(os.sep, 1) + + if len(filename) < 2: ## just an empty uploads directory (e.g. uploads/) + continue + + filename = filename[1] ## Get the second entry in the list (the actual filename) + full_path = os.path.join(upload_folder, filename) + dirname = os.path.dirname(full_path) + + ## Create any parent directories for the file + if not os.path.exists(dirname): + os.makedirs(dirname) + + source = backup.open(f) + target = file(full_path, "wb") + with source, target: + shutil.copyfileobj(source, target) \ No newline at end of file