Adding unsaved captures deletion
This commit is contained in:
@ -3,7 +3,7 @@
|
||||
|
||||
import subprocess as sp
|
||||
from flask import Blueprint, jsonify
|
||||
from app.utils import read_config
|
||||
from app.utils import read_config, delete_captures
|
||||
import re
|
||||
import sys
|
||||
import os
|
||||
@ -11,6 +11,17 @@ import os
|
||||
misc_bp = Blueprint("misc", __name__)
|
||||
|
||||
|
||||
@misc_bp.route("/delete-captures", methods=["GET"])
|
||||
def api_delete_captures():
|
||||
"""
|
||||
Delete the zombies capture folders (if any)
|
||||
"""
|
||||
if delete_captures():
|
||||
return jsonify({"message": "Captures deleted", "status": True})
|
||||
else:
|
||||
return jsonify({"message": "Issue while removing captures", "status": False})
|
||||
|
||||
|
||||
@misc_bp.route("/reboot", methods=["GET"])
|
||||
def api_reboot():
|
||||
"""
|
||||
|
@ -7,6 +7,8 @@ import yaml
|
||||
import sys
|
||||
import os
|
||||
from functools import reduce
|
||||
import shutil
|
||||
import re
|
||||
|
||||
|
||||
def terminate_process(process):
|
||||
@ -33,3 +35,16 @@ def read_config(path):
|
||||
config = yaml.load(open(os.path.join(dir, "config.yaml"), "r"),
|
||||
Loader=yaml.SafeLoader)
|
||||
return reduce(dict.get, path, config)
|
||||
|
||||
|
||||
def delete_captures():
|
||||
"""
|
||||
Delete potential zombies capture directories
|
||||
"""
|
||||
try:
|
||||
for d in os.listdir("/tmp/"):
|
||||
if re.match("[A-F0-9]{8}", d):
|
||||
shutil.rmtree(os.path.join("/tmp/", d))
|
||||
return True
|
||||
except:
|
||||
return False
|
||||
|
Reference in New Issue
Block a user