Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Stop Scan functionality #104

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions Dashboard/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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='<id>'))


def new_scan():
Expand Down Expand Up @@ -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():
Expand All @@ -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')


Expand All @@ -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/<id>", endpoint="stopscan",
view_func=stopscan, methods=['GET'])
if __name__ == "__main__":
app.run(host="0.0.0.0",debug=True)
8 changes: 8 additions & 0 deletions Dashboard/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ <h6>Number of files: {{ item['files']['total'] }}</h6>
<div class="progress">
<div id={{ item["_id"] }} class="progress-bar" style="width: 0%;"></div>
</div>
<button type="button" name="button" class="btn btn-danger mt-3" onclick="stopscan('{{ item['_id'] }}')">Stop</button>
</div>
</div>
{% endfor %}
Expand Down Expand Up @@ -109,6 +110,13 @@ <h6>Number of files: {{ item['files']['total'] }}</h6>
function openUploader() {
window.location = "{{ newScanUrl }}";
}

async function stopscan(id){
let to_do = confirm("Do you want to stop scan")
if(to_do){
await fetch(`http://localhost:5000/stopscan/${id}`)
}
}
</script>

<script>
Expand Down