aboutsummaryrefslogtreecommitdiff
path: root/www/html/bilan.py
diff options
context:
space:
mode:
Diffstat (limited to 'www/html/bilan.py')
-rwxr-xr-xwww/html/bilan.py82
1 files changed, 41 insertions, 41 deletions
diff --git a/www/html/bilan.py b/www/html/bilan.py
index 29d42b0..a85fe98 100755
--- a/www/html/bilan.py
+++ b/www/html/bilan.py
@@ -8,59 +8,51 @@ def index(req):
req.content_type="text/html"
ipdst=str()
portdst=str()
+ ipsrc=str()
+ portsrc=str()
#sql part
conn=connexionBD()
cur=conn.cursor()
###
- cur.execute("SELECT COUNT(*) FROM paquet")
- conn.commit()
- total=str(cur.fetchone()[0])
-#
- cur.execute("SELECT COUNT(DISTINCT ip_source) FROM paquet")
- conn.commit()
- total_ip_src=str(cur.fetchone()[0])
-#
- cur.execute("SELECT COUNT(DISTINCT ip_destination) FROM paquet")
- conn.commit()
- total_ip_dst=str(cur.fetchone()[0])
-#
- cur.execute("SELECT COUNT(DISTINCT port_source) FROM paquet")
- conn.commit()
- total_port_src=str(cur.fetchone()[0])
-#
- cur.execute("SELECT COUNT(DISTINCT port_destination) FROM paquet")
- conn.commit()
- total_port_dst=str(cur.fetchone()[0])
-#
- cur.execute("SELECT COUNT(*) FROM paquet WHERE (heure>=( SELECT LOCALTIME - interval '1 hour' ) AND heure<= (SELECT LOCALTIME));")
- conn.commit()
- total_uneheure=str(cur.fetchone()[0])
-#
- cur.execute("SELECT ip_destination, COUNT(ip_destination) FROM paquet GROUP BY ip_destination DESC")
- conn.commit()
- each_ip_dest=cur.fetchall()
-#
- cur.execute("SELECT port_destination, COUNT(port_destination) FROM paquet GROUP BY port_destination")
- conn.commit()
- each_port_dest=cur.fetchall()
+ sql=["SELECT COUNT(*) FROM paquet","SELECT COUNT(DISTINCT ip_source) FROM paquet","SELECT COUNT(DISTINCT ip_destination) FROM paquet","SELECT COUNT(DISTINCT port_source) FROM paquet","SELECT COUNT(DISTINCT port_destination) FROM paquet","SELECT COUNT(*) FROM paquet WHERE (heure>=( SELECT LOCALTIME - interval '1 hour' ) AND heure<= (SELECT LOCALTIME));"]
+ var=["total","total_ip_src","total_ip_dst","total_port_src","total_port_dst","total_uneheure"]
+ for x,y in zip(sql,var):
+ cur.execute(x)
+ conn.commit()
+ globals()[y]=str(cur.fetchone()[0])
+#
+ sql=["SELECT ip_destination, COUNT(ip_destination) FROM paquet GROUP BY ip_destination ORDER BY count DESC","SELECT port_destination, COUNT(port_destination) FROM paquet GROUP BY port_destination ORDER BY count DESC","SELECT ip_source, COUNT(ip_source) FROM paquet GROUP BY ip_source ORDER BY count DESC","SELECT port_source, COUNT(port_source) FROM paquet GROUP BY port_source ORDER BY count DESC"]
+ var=["each_ip_dst","each_port_dst","each_ip_src","each_port_src"]
+ for x,y in zip(sql,var):
+ cur.execute(x)
+ conn.commit()
+ globals()[y]=cur.fetchall()
###
conn.close()
+
#sql part
-#loops
- for i in each_ip_dest :
- ipdst+=("""<tr>
-<td>""" + str(i[0]) + """</td>
-<td>""" + str(i[1]) + """</td>
- </tr>""")
+ champs=["ip","port"]
+ suff=["dst","src"]
+ global each_ip_dst
+ global each_ip_src
+ global each_port_dst
+ global each_port_src
+ global ipdst
+ global ipsrc
+ global portdst
+ global portsrc
- for i in each_port_dest :
- portdst+=("""<tr>
+ for j in champs:
+ for k in suff:
+ nom="each_"+j+"_"+k
+ for i in globals()[nom]:
+ globals()[j+k]+=("""<tr>
<td>""" + str(i[0]) + """</td>
<td>""" + str(i[1]) + """</td>
- </tr>""")
-#loops
+ </tr>""")
+
#write the html page
@@ -83,6 +75,14 @@ def index(req):
<tr><th>Port destination</th><th>Reccurrence</th></tr>
"""+str(portdst)+"""
</table>
+<table class="inlineTable">
+<tr><th>IP source</th><th>Reccurrence</th></tr>
+"""+str(ipsrc)+"""
+</table>
+<table class="inlineTable">
+<tr><th>Port source</th><th>Reccurrence</th></tr>
+"""+str(portsrc)+"""
+</table>
<canvas id="protocole" width="20vh" height="40vw"></canvas>
<script src="/Chart.js"></script>
<script src="/pie.js"></script>