Adding unsaved captures deletion

This commit is contained in:
Félix Aime 2021-06-03 14:08:34 +02:00
parent e04ef547c2
commit 2968d6fcb6
4 changed files with 37 additions and 2 deletions

View File

@ -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 {

View File

@ -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);
}
}

View File

@ -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():
"""

View File

@ -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