forked from p15670423/monkey
Merge pull request #1054 from shreyamalviya/bugfix_pba_file_delete
Fix error when removing uploaded post breach file on config reset
This commit is contained in:
commit
c6fd04e2b6
|
@ -18,7 +18,7 @@ from monkey_island.cc.services.post_breach_files import (
|
|||
__author__ = "VakarisZ"
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
# Front end uses these strings to identify which files to work with (linux of windows)
|
||||
# Front end uses these strings to identify which files to work with (linux or windows)
|
||||
LINUX_PBA_TYPE = "PBAlinux"
|
||||
WINDOWS_PBA_TYPE = "PBAwindows"
|
||||
|
||||
|
@ -58,27 +58,6 @@ class FileUpload(flask_restful.Resource):
|
|||
response = Response(response=filename, status=200, mimetype="text/plain")
|
||||
return response
|
||||
|
||||
@jwt_required
|
||||
def delete(self, file_type):
|
||||
"""
|
||||
Deletes file that has been deleted on the front end
|
||||
:param file_type: Type indicates which file was deleted, linux of windows
|
||||
:return: Empty response
|
||||
"""
|
||||
filename_path = (
|
||||
PBA_LINUX_FILENAME_PATH if file_type == "PBAlinux" else PBA_WINDOWS_FILENAME_PATH
|
||||
)
|
||||
filename = ConfigService.get_config_value(filename_path)
|
||||
file_path = Path(env_singleton.env.get_config().data_dir_abs_path).joinpath(filename)
|
||||
try:
|
||||
if os.path.exists(file_path):
|
||||
os.remove(file_path)
|
||||
ConfigService.set_config_value(filename_path, "")
|
||||
except OSError as e:
|
||||
LOG.error("Can't remove previously uploaded post breach files: %s" % e)
|
||||
|
||||
return {}
|
||||
|
||||
@staticmethod
|
||||
def upload_pba_file(request_, is_linux=True):
|
||||
"""
|
||||
|
@ -96,3 +75,29 @@ class FileUpload(flask_restful.Resource):
|
|||
(PBA_LINUX_FILENAME_PATH if is_linux else PBA_WINDOWS_FILENAME_PATH), filename
|
||||
)
|
||||
return filename
|
||||
|
||||
@jwt_required
|
||||
def delete(self, file_type):
|
||||
"""
|
||||
Deletes file that has been deleted on the front end
|
||||
:param file_type: Type indicates which file was deleted, linux of windows
|
||||
:return: Empty response
|
||||
"""
|
||||
filename_path = (
|
||||
PBA_LINUX_FILENAME_PATH if file_type == "PBAlinux" else PBA_WINDOWS_FILENAME_PATH
|
||||
)
|
||||
filename = ConfigService.get_config_value(filename_path)
|
||||
if filename:
|
||||
file_path = Path(env_singleton.env.get_config().data_dir_abs_path).joinpath(filename)
|
||||
FileUpload._delete_file(file_path)
|
||||
ConfigService.set_config_value(filename_path, "")
|
||||
|
||||
return {}
|
||||
|
||||
@staticmethod
|
||||
def _delete_file(file_path):
|
||||
try:
|
||||
if os.path.exists(file_path):
|
||||
os.remove(file_path)
|
||||
except OSError as e:
|
||||
LOG.error("Couldn't remove previously uploaded post breach files: %s" % e)
|
||||
|
|
Loading…
Reference in New Issue