From 14b27795d5ae810b6650ef12db572b70019338d1 Mon Sep 17 00:00:00 2001 From: hs05june Date: Tue, 21 Mar 2023 00:34:27 +0530 Subject: [PATCH 1/2] Stop Scan functionality Signed-off-by: hs05june --- Dashboard/app.py | 14 ++++++++++++-- Dashboard/templates/index.html | 8 ++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Dashboard/app.py b/Dashboard/app.py index 3519e97..aad70ab 100644 --- a/Dashboard/app.py +++ b/Dashboard/app.py @@ -31,7 +31,7 @@ def index(): queued = queuedScans.find() running = runningScans.find() completed = completedScans.find() - return render_template('index.html', prequeued=prequeued, queued=queued, running=running, completed=completed, newScanUrl=url_for('newScan')) + return render_template('index.html', prequeued=prequeued, queued=queued, running=running, completed=completed, newScanUrl=url_for('newScan'),stopscan=url_for('stopscan',id='')) def new_scan(): @@ -64,6 +64,15 @@ def upload_files(): return redirect(url_for('dashboard')) +def stopscan(id): + if request.method == 'GET': + print(id) + try: + runningScans.delete_one({'_id':id}) + except: + print("Error") + + return redirect(url_for('dashboard')) def progress(): def generate(): @@ -75,7 +84,6 @@ def generate(): (item["files"]["completed"] / item["files"]["total"]) * 100) yield "data:" + json.dumps(x) + "\n\n" - return Response(generate(), mimetype='text/event-stream') @@ -86,5 +94,7 @@ def generate(): view_func=progress, methods=['GET']) app.add_url_rule("/upload", endpoint="upload", view_func=upload_files, methods=['GET', 'POST']) +app.add_url_rule("/stopscan/", endpoint="stopscan", + view_func=stopscan, methods=['GET']) if __name__ == "__main__": app.run(host="0.0.0.0",debug=True) diff --git a/Dashboard/templates/index.html b/Dashboard/templates/index.html index e53bf03..9418a0e 100644 --- a/Dashboard/templates/index.html +++ b/Dashboard/templates/index.html @@ -78,6 +78,7 @@
Number of files: {{ item['files']['total'] }}
+ {% endfor %} @@ -109,6 +110,13 @@
Number of files: {{ item['files']['total'] }}
function openUploader() { window.location = "{{ newScanUrl }}"; } + // http://localhost:5000/stopscan/4f9b7edf-8998-4028-9418-0fbc5e6ea2a7 + async function stopscan(id){ + let to_do = confirm("Do you want to stop scan") + if(to_do){ + await fetch(`http://localhost:5000/stopscan/${id}`) + } + }