diff --git a/app/frontend/src/views/report.vue b/app/frontend/src/views/report.vue index ced0259..6b2e45b 100644 --- a/app/frontend/src/views/report.vue +++ b/app/frontend/src/views/report.vue @@ -113,7 +113,11 @@ export default { router.replace({ name: 'save-capture', params: { capture_token: capture_token } }); }, new_capture: function() { - router.push({ name: 'generate-ap' }) + axios.get('/api/misc/delete-captures', { timeout: 30000 }) + .then(response => { + router.push({ name: 'generate-ap' }) + }) + .catch(err => (console.log(err))) }, grep_keyword: function(kw, level){ try { diff --git a/app/frontend/src/views/splash-screen.vue b/app/frontend/src/views/splash-screen.vue index e608850..dc69f71 100644 --- a/app/frontend/src/views/splash-screen.vue +++ b/app/frontend/src/views/splash-screen.vue @@ -39,6 +39,10 @@ }) .catch(err => (console.log(err))) }, + delete_captures: function() { + axios.get('/api/misc/delete-captures', { timeout: 30000 }) + .catch(err => (console.log(err))) + }, goto_home: function() { var list_ssids = this.list_ssids var internet = this.internet @@ -46,6 +50,7 @@ } }, created: function() { + this.delete_captures(); setTimeout(function () { this.internet_check(); }.bind(this), 5000); } } diff --git a/server/frontend/app/blueprints/misc.py b/server/frontend/app/blueprints/misc.py index c9bbeed..cbd72a3 100644 --- a/server/frontend/app/blueprints/misc.py +++ b/server/frontend/app/blueprints/misc.py @@ -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(): """ diff --git a/server/frontend/app/utils.py b/server/frontend/app/utils.py index 8ebf743..cbd54d1 100644 --- a/server/frontend/app/utils.py +++ b/server/frontend/app/utils.py @@ -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