forked from p15670423/monkey
island: Consolidate duplicate delete post breach file functionality
This commit is contained in:
parent
71029cb7f9
commit
5742e85ff5
|
@ -1,6 +1,5 @@
|
||||||
import copy
|
import copy
|
||||||
import logging
|
import logging
|
||||||
import os
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import flask_restful
|
import flask_restful
|
||||||
|
@ -84,16 +83,7 @@ class FileUpload(flask_restful.Resource):
|
||||||
)
|
)
|
||||||
filename = ConfigService.get_config_value(filename_path)
|
filename = ConfigService.get_config_value(filename_path)
|
||||||
if filename:
|
if filename:
|
||||||
file_path = Path(PostBreachFilesService.get_custom_pba_directory()).joinpath(filename)
|
PostBreachFilesService.remove_file(filename)
|
||||||
FileUpload._delete_file(file_path)
|
|
||||||
ConfigService.set_config_value(filename_path, "")
|
ConfigService.set_config_value(filename_path, "")
|
||||||
|
|
||||||
return {}
|
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)
|
|
||||||
|
|
|
@ -36,12 +36,12 @@ class PostBreachFilesService:
|
||||||
PBA_LINUX_FILENAME_PATH
|
PBA_LINUX_FILENAME_PATH
|
||||||
)
|
)
|
||||||
if linux_filename:
|
if linux_filename:
|
||||||
PostBreachFilesService._remove_file(linux_filename)
|
PostBreachFilesService.remove_file(linux_filename)
|
||||||
if windows_filename:
|
if windows_filename:
|
||||||
PostBreachFilesService._remove_file(windows_filename)
|
PostBreachFilesService.remove_file(windows_filename)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _remove_file(file_name):
|
def remove_file(file_name):
|
||||||
file_path = os.path.join(PostBreachFilesService.get_custom_pba_directory(), file_name)
|
file_path = os.path.join(PostBreachFilesService.get_custom_pba_directory(), file_name)
|
||||||
try:
|
try:
|
||||||
if os.path.exists(file_path):
|
if os.path.exists(file_path):
|
||||||
|
|
Loading…
Reference in New Issue