diff --git a/monkey/monkey_island/cc/resources/pba_file_download.py b/monkey/monkey_island/cc/resources/pba_file_download.py index 5a616a0fc..4fe05c98f 100644 --- a/monkey/monkey_island/cc/resources/pba_file_download.py +++ b/monkey/monkey_island/cc/resources/pba_file_download.py @@ -1,7 +1,7 @@ import flask_restful from flask import send_from_directory -from monkey_island.cc.services.post_breach_files import UPLOADS_DIR_NAME +from monkey_island.cc.services.post_breach_files import ABS_UPLOAD_PATH __author__ = 'VakarisZ' @@ -13,4 +13,4 @@ class PBAFileDownload(flask_restful.Resource): # Used by monkey. can't secure. def get(self, path): - return send_from_directory(UPLOADS_DIR_NAME, path) + return send_from_directory(ABS_UPLOAD_PATH, path) diff --git a/monkey/monkey_island/cc/resources/pba_file_upload.py b/monkey/monkey_island/cc/resources/pba_file_upload.py index 9f7b22246..5f75eaaa1 100644 --- a/monkey/monkey_island/cc/resources/pba_file_upload.py +++ b/monkey/monkey_island/cc/resources/pba_file_upload.py @@ -9,8 +9,7 @@ from werkzeug.utils import secure_filename from monkey_island.cc.resources.auth.auth import jwt_required from monkey_island.cc.services.config import ConfigService from monkey_island.cc.services.post_breach_files import ( - PBA_LINUX_FILENAME_PATH, PBA_UPLOAD_PATH, PBA_WINDOWS_FILENAME_PATH, - UPLOADS_DIR) + ABS_UPLOAD_PATH, PBA_LINUX_FILENAME_PATH, PBA_WINDOWS_FILENAME_PATH) __author__ = 'VakarisZ' @@ -19,9 +18,6 @@ LOG = logging.getLogger(__name__) LINUX_PBA_TYPE = 'PBAlinux' WINDOWS_PBA_TYPE = 'PBAwindows' -# This path is used by flask, which means that local directory is different from UPLOADS_DIR -FLASK_UPLOAD_PATH = PBA_UPLOAD_PATH[-1] - class FileUpload(flask_restful.Resource): """ @@ -29,7 +25,7 @@ class FileUpload(flask_restful.Resource): """ def __init__(self): # Create all directories on the way if they don't exist - UPLOADS_DIR.mkdir(parents=True, exist_ok=True) + ABS_UPLOAD_PATH.mkdir(parents=True, exist_ok=True) @jwt_required def get(self, file_type): @@ -43,7 +39,7 @@ class FileUpload(flask_restful.Resource): filename = ConfigService.get_config_value(copy.deepcopy(PBA_LINUX_FILENAME_PATH)) else: filename = ConfigService.get_config_value(copy.deepcopy(PBA_WINDOWS_FILENAME_PATH)) - return send_from_directory(FLASK_UPLOAD_PATH, filename) + return send_from_directory(ABS_UPLOAD_PATH, filename) @jwt_required def post(self, file_type): @@ -68,7 +64,7 @@ class FileUpload(flask_restful.Resource): """ filename_path = PBA_LINUX_FILENAME_PATH if file_type == 'PBAlinux' else PBA_WINDOWS_FILENAME_PATH filename = ConfigService.get_config_value(filename_path) - file_path = UPLOADS_DIR.joinpath(filename) + file_path = ABS_UPLOAD_PATH.joinpath(filename) try: if os.path.exists(file_path): os.remove(file_path) @@ -87,7 +83,7 @@ class FileUpload(flask_restful.Resource): :return: filename string """ filename = secure_filename(request_.files['filepond'].filename) - file_path = UPLOADS_DIR.joinpath(filename).absolute() + file_path = ABS_UPLOAD_PATH.joinpath(filename).absolute() request_.files['filepond'].save(str(file_path)) ConfigService.set_config_value((PBA_LINUX_FILENAME_PATH if is_linux else PBA_WINDOWS_FILENAME_PATH), filename) return filename diff --git a/monkey/monkey_island/cc/services/post_breach_files.py b/monkey/monkey_island/cc/services/post_breach_files.py index 20064f4c4..2bb310e14 100644 --- a/monkey/monkey_island/cc/services/post_breach_files.py +++ b/monkey/monkey_island/cc/services/post_breach_files.py @@ -6,14 +6,17 @@ import monkey_island.cc.services.config __author__ = "VakarisZ" +from monkey_island.cc.consts import MONKEY_ISLAND_ABS_PATH + logger = logging.getLogger(__name__) # Where to find file names in config PBA_WINDOWS_FILENAME_PATH = ['monkey', 'post_breach', 'PBA_windows_filename'] PBA_LINUX_FILENAME_PATH = ['monkey', 'post_breach', 'PBA_linux_filename'] UPLOADS_DIR_NAME = 'userUploads' -PBA_UPLOAD_PATH = ['monkey_island', 'cc', UPLOADS_DIR_NAME] -UPLOADS_DIR = Path(*PBA_UPLOAD_PATH) + + +ABS_UPLOAD_PATH = Path(MONKEY_ISLAND_ABS_PATH, 'cc', UPLOADS_DIR_NAME) def remove_PBA_files(): @@ -27,7 +30,7 @@ def remove_PBA_files(): def remove_file(file_name): - file_path = os.path.join(UPLOADS_DIR, file_name) + file_path = os.path.join(ABS_UPLOAD_PATH, file_name) try: if os.path.exists(file_path): os.remove(file_path)