aboutsummaryrefslogtreecommitdiff
path: root/www/html/bilan.py
blob: 376f0c63ba863f3af700ac61aeb98b031c86ea79 (plain)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import mod_python
from fonctions import baseHTML, connexionBD, lien

def index(req):
    req.content_type="text/html"
    content=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")
    conn.commit()
    each_ip_dest=cur.fetchall()
###
    conn.close()
#sql part

#loop
    for i in each_ip_dest :
        content+=("""<tr>
<td>""" + str(i[0]) + """</td>
<td>""" + str(i[1]) + """</td>
                </tr>""")
#loop

#write the html page

    req.write(baseHTML("ATS-Project","""
<h1>Bilan</h1>
<ul>
<li>Nombre total de paquets : <b>"""+total+"""</b></li>
<li>Nombre total de paquets depuis 1h : <b>"""+total_uneheure+"""</b></li>
<li>Nombre total d'adresses IP source differentes : <b>"""+total_ip_src+"""</b></li>
<li>Nombre total d'adresses IP destination differentes : <b>"""+total_ip_dst+"""</b></li>
<li>Nombre total de ports source differents : <b>"""+total_port_src+"""</b></li>
<li>Nombre total de ports destination differents : <b>"""+total_port_dst+"""</b></li>
</ul>
<br/>
<table>
<tr><th>IP destination</th><th>Recurrence</th></tr>
"""+str(content)+"""
</table>
<canvas id="protocole" width="20vh" height="40vw"></canvas>
<script src="/Chart.js"></script>
<script src="/pie.js"></script>
"""
))