-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroutes.py
More file actions
56 lines (37 loc) · 1.79 KB
/
routes.py
File metadata and controls
56 lines (37 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from . import app
import sqlite3
from flask import request
class InterceptRequestMiddleware:
def __init__(self, wsgi_app):
self.wsgi_app = wsgi_app
def __call__(self, environ, start_response):
environ['Access-Control-Allow-Origin'] = '*'
return self.wsgi_app(environ, start_response)
@app.route("/test", methods=["GET"])
def start():
return "hello"
@app.route("/api/network", methods=["GET"])
def getNetworkTraffic():
connection = sqlite3.connect("Simple-Network-Visualiser/analysis.db")
cursor = connection.cursor()
cursor.execute("SELECT * FROM data;")
return cursor.fetchall()
@app.route("/api/nodes", methods=["GET"])
def getNodes():
minTime = request.args.get("minTime")
maxTime = request.args.get("maxTime")
query = "SELECT DISTINCT d.source, d.destination, dns.common_name FROM data d LEFT JOIN dns_records dns ON d.destination = dns.ip_address;"
if request.args.get("minTime") != None and request.args.get("maxTime") != None:
maxTime = round(float(maxTime) * 1000000)
minTime = round(float(minTime) * 1000000)
query = "SELECT DISTINCT d.source, d.destination, dns.common_name FROM data d LEFT JOIN dns_records dns ON d.destination = dns.ip_address WHERE time >=" + str(minTime) +" AND time <= " + str(maxTime) +" ;"
connection = sqlite3.connect("Simple-Network-Visualiser/analysis.db")
cursor = connection.cursor()
cursor.execute(query)
return cursor.fetchall()
@app.route("/api/time", methods=["GET"])
def get_time_range():
connection = sqlite3.connect("Simple-Network-Visualiser/analysis.db")
cursor = connection.cursor()
cursor.execute("SELECT MIN(time) as smallest, MAX(time) as largest FROM data;")
return cursor.fetchall()