From 9f6e22875c2857efbe4a73600e31c1b30c2dfdc3 Mon Sep 17 00:00:00 2001 From: rain Date: Wed, 24 May 2023 23:04:19 -0500 Subject: [PATCH] Made database queries a thing for filtering. Tweaked gitignore again oof, added a toggle listener for marking hosts on the web page --- .gitignore | 1 + app/static/css/style.css | 3 +++ app/static/js/table.js | 25 +++++++------------------ app/templates/.base.html.swp | Bin 1024 -> 0 bytes app/templates/404.html | 2 +- app/templates/home.html | 16 ++++++++-------- app/views.py | 34 +++++++++++++++++++++++++++++++--- 7 files changed, 51 insertions(+), 30 deletions(-) delete mode 100644 app/templates/.base.html.swp diff --git a/.gitignore b/.gitignore index bc5ae94..62be209 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ app/scanned.db *.xml **/*.pyc +**/*.swp diff --git a/app/static/css/style.css b/app/static/css/style.css index a2019f9..c4cece9 100755 --- a/app/static/css/style.css +++ b/app/static/css/style.css @@ -41,6 +41,9 @@ tbody tr:hover td { cursor: pointer; } +tbody tr.active td { + background-color: #FFEFC6; +} table tr:last-child td:first-child { border-bottom-left-radius: 10px; diff --git a/app/static/js/table.js b/app/static/js/table.js index b327d01..283e159 100644 --- a/app/static/js/table.js +++ b/app/static/js/table.js @@ -1,20 +1,9 @@ -function filter_ports(filter) { - let portCol = document.querySelectorAll("tbody tr td:last-child"); - portCol.forEach((item) => { - if(!new RegExp(filter).test(item.innerText)){ - item.parentNode.style.display = "none"; - } else { - item.parentNode.style.display = "table-row"; - } - }); -} - -document.querySelector("#ports").addEventListener("keyup", (event) => { - if (event.key === "Enter") { - filter_ports(event.srcElement.value); - } -}); - function count_rows() { return document.querySelectorAll('tr:not([style*="display:none"]):not([style*="display: none"])').length; -} \ No newline at end of file +} + +document.querySelectorAll("tbody tr").forEach(function(elem) { + elem.addEventListener("click", function() { + elem.classList.toggle('active'); + }); +}); \ No newline at end of file diff --git a/app/templates/.base.html.swp b/app/templates/.base.html.swp deleted file mode 100644 index e64c7596d0d8dc854e3d8c06834975b79499e1ff..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1024 zcmYc?$V<%2S1{KzVn6{384L_XiJ5sQf;cz@r70;nsW>E&g!T0Ffv6-kw;(66B(+#S cDX}5Q=Ux0N{cUjQ{`u diff --git a/app/templates/404.html b/app/templates/404.html index ec83c23..ca65a3d 100644 --- a/app/templates/404.html +++ b/app/templates/404.html @@ -24,5 +24,5 @@ {% block main %}

404

That page doesn't even exist.

-

Why don't you just go back home?

+

Why don't you just go back home?

{% endblock %} \ No newline at end of file diff --git a/app/templates/home.html b/app/templates/home.html index 28d3709..e5c12c6 100644 --- a/app/templates/home.html +++ b/app/templates/home.html @@ -7,26 +7,26 @@ - + + + + - - {% for target in targets %} - + {% endfor %} -
OS - HOSTNAME - ADDRESS - +
+ +
{{ target.hostname }} {{ target.address }}{{ target.ports }}{{ target.ports[1:-1]|replace('|', ', ') }}
{% endblock %} diff --git a/app/views.py b/app/views.py index e0ad64a..1e58303 100644 --- a/app/views.py +++ b/app/views.py @@ -1,13 +1,41 @@ -from app import app, db from flask import render_template, request, redirect, url_for, flash +from sqlalchemy import select from app.models import target +from sqlalchemy import func +from app import app, db -@app.route('/') -def home(): +@app.route('/', methods=['GET']) +def get_home(): """Render website's home page.""" targets = db.session.query(target).all() return render_template('home.html', targets=targets) +@app.route('/', methods=['POST']) +def post_home(): + """Render website's home page with applied filters.""" + targets = db.session.query(target) + + os = request.form.get("os") + if os: + targets = targets.where(target.os == os) + + hostname = request.form.get("hostname") + if hostname: + targets = targets.where(target.hostname == hostname) + + address = request.form.get("address") + if address: + targets = targets.where(target.address == address) + + ports = request.form.get("ports") + if ports: + for port in ports.replace(' ','').split(','): + targets = targets.filter(target.ports.like('%|'+port+'|%')) + + + return render_template('home.html', targets=targets.all(), os=os,hostname=hostname,address=address,ports=ports) + + @app.after_request def add_header(response): """