def index(req): req.content_type="text/html" content=str() condition=req.form["condition"] conn=connexionBD() cur=conn.cursor() sql="select * from paquet where {} ORDER BY heure DESC;".format(condition) cur.execute(sql) conn.commit() data=cur.fetchall() conn.close() for i in data : content+=("""<tr>""" + """<td>""" + str(i[1]) + """</td>""" + """<td>""" + str(i[2]) + """</td>""" + """<td>""" + lien('ip_source.py?ip=' + str(i[3]), str(i[3])) + """</td>""" + """<td>""" + lien('ip_destination.py?ip=' + str(i[4]), str(i[4])) + """</td>""" + """<td>""" + lien('port_source.py?port=' + str(i[5]), str(i[5])) + """</td>""" + """<td>""" + lien('port_destination.py?port=' + str(i[6]), str(i[6])) + """</td>""" + """</tr>""") req.write(""" <table class="data_tab"> <tr><th>Heure</th><th>Protocole</th><th>IP Source</th><th>IP Destination</th><th>Port Source</th><th>Port Destination</th></tr> """ + content + """ </table>""")
def index(req): req.content_type = "text/html" sess = Session.Session(req) login = req.form['login'] password = req.form['password'] conn = fonctions.connexionBD() cur = conn.cursor() sql = "select * from util where login=%s and mdp =%s;" cur.execute(sql, ( login, password, )) data = cur.fetchall() if not data: sess.delete() req.write( fonctions.codeHTML( "Erreur !", """<h3>Identifiants invalides</h3>""" + fonctions.lien( 'form-connexion.py', "Retour à la page de connexion"))) else: id_util = data[0] sess["login"] = login sess["id_util"] = id_util[0] sess.save() req.write( fonctions.codeHTML( "Connexion", """<h3>Identifiants valides</h3>""" + fonctions.lien('menu.py', "Menu du site")))
def index(req): req.content_type = "text/html" content = str() #sql part conn = connexionBD() cur = conn.cursor() sql = "SELECT * FROM paquet ORDER BY heure DESC LIMIT 20;" sql_count = "SELECT COUNT(*) FROM paquet;" cur.execute(sql) conn.commit() data = cur.fetchall() cur.execute(sql_count) conn.commit() count = cur.fetchone() count = str(count[0]) conn.close() #sql part #takes every lines from the select for i in data: content += ("""<tr>""" + """<td>""" + str(i[1]) + """</td>""" + """<td>""" + str(i[2]) + """</td>""" + """<td>""" + lien('ip_source.py?ip=' + str(i[3]), str(i[3])) + """</td>""" + """<td>""" + lien('ip_destination.py?ip=' + str(i[4]), str(i[4])) + """</td>""" + """<td>""" + lien('port_source.py?port=' + str(i[5]), str(i[5])) + """</td>""" + """<td>""" + lien('port_destination.py?port=' + str(i[6]), str(i[6])) + """</td>""" + """</tr>""") #write the html page req.write( baseHTML( "ATS - Accueil", """ <h1>ATS</h1> <div id="tip" style="display:block;"> Afin de voir le reverse DNS d'une adresse IP, cliquez sur cette dernière dans le tableau <button id="ok" onclick="toggle_div(this,'tip');">OK</button></div> <p>Nombre total de paquets : <b>""" + count + """</b></p> <em>Pour afficher toute la table, cliquez</em> <button id="afficheTas" onclick="affiche_tas()">ICI</button><br/> <div id="tab"> <table class="data_tab"> <tr><th>Heure</th><th>Protocole</th><th>IP Source</th><th>IP Destination</th><th>Port Source</th><th>Port Destination</th></tr> """ + content + """ </table> </div> <script src="tip.js"></script> <script src="tas.js"></script> """))
def index(req): req.content_type = "text/html" sess = Session.Session(req) #recup session redirectionSiNonConnecte(req, sess) #redirige si la session est nouvelle id_util = sess["id_util"] #recup l'id_util #start sql check que l'util est root conn = connexionBD() cur = conn.cursor() sql = "select login from util where util.id_util={} and util.login='******';".format( id_util, 'root') cur.execute(sql) conn.commit() data = cur.fetchall() if not data: req.write( codeHTML( "Erreur !", """ <h3><g>Seul l'utilisateur root a le droit d'ajouter un utilisateur.</g></h3> """ + lien('menu.py', "Retour au menu"))) #end sql check util root else: req.write( codeHTML( "Ajout d'un utilisateur", """ <p><b>Ajout d'un utilisateur</b></p> <form method="POST" action="ajout-util.py" onsubmit="return isItGood()"> <table> <tr> <td>Login</td> <td><input type="text" name="login" id="login" onkeyup="alreadyUsed()"/></td> <td></td> </tr> <tr> <td>Mot de passe</td> <td><input type="password" name="motdepasse" id="motdepasse"/></td> <td></td> </tr> <tr> <td>Confirmation du mot de passe</td> <td><input type="password" name="conf" id="conf"/></td> <td></td> </tr> </table> <div id="used"></div> </form> """ + lien("menu.py", "Retour au menu principal") + """ <script src="form-ajout-util.js"></script> """))
def index(req): req.content_type = "text/html" sess = Session.Session(req) fonctions.redirectionSiNonConnecte(req, sess) req.write( fonctions.codeHTML( "Liste des contacts", """<b> Liste des contacts </b> <br/> Rechercher un nom : <input type="text" onkeyup="chargementContacts(this.value)"/> <div id="liste"></div>""" + fonctions.lien("menu.py", "Retour au menu")) + """ <script> function chargementContacts(value) { if(value == null){ value = ""; } var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { document.getElementById("liste").innerHTML = this.responseText; } }; xhttp.open("GET", "affiche-liste.py?nom=" + value, true); xhttp.send(); } chargementContacts(); </script>""")
def index(req): req.content_type = "text/html" sess = Session.Session(req) #recup session redirectionSiNonConnecte(req, sess) #redirige si la session est nouvelle id_util = sess["id_util"] #recup l'id_util login = req.form['login'] mdp = req.form['motdepasse'] conn = connexionBD() cur = conn.cursor() sql = "insert into util (login,mdp) values (%s,%s);" cur.execute(sql, ( login, mdp, )) conn.commit() conn.close() req.write( codeHTML( "", """ <p><b>Nouvel utilisateur</b></p> <p>""" + login + """ a bien été ajouté</p> """ + lien('menu.py', "Retour au menu principal")))
def index(req): req.content_type = "text/javascript" sess = Session.Session(req) fonctions.redirectionSiNonConnecte(req, sess) try: req.form["nom"] except KeyError: req.form["nom"] = "" _db = fonctions.connexionBD() _cursor = _db.cursor() _cursor.execute("SELECT * FROM CONTACT WHERE id_util = %s AND nom LIKE %s", (sess['id_util'], "%%" + req.form["nom"] + "%%")) _rows = _cursor.fetchall() req.write("layerGroup.clearLayers();") bounds = "" for row in _rows: if row[5] != 0 and row[6] != 0: req.write("\nvar m = L.marker ({lat: " + str(row[5]) + " , lon: " + str(row[6]) + "});") req.write("\nm.addTo(layerGroup); \nm.bindPopup('" + fonctions.lien("fiche.py?id_contact=" + str(row[0]), row[1]) + "');") bounds += "[" + str(row[5]) + ", " + str(row[6]) + "], " if bounds != "": req.write("\nmap.fitBounds([" + bounds + "]);") _db.close()
def index(req): req.content_type="text/html" sess = Session.Session(req) fonctions.redirectionSiNonConnecte(req,sess) req.write(fonctions.codeHTML("Ajout d'un contact",""" <p><b>Ajout d'un contact</b></p> <form method="POST" action="ajout.py" onsubmit="return isItGood()"> <table> <tr> <td>Nom</td> <td><input type="text" name="nom" id="nom"/></td> <td></td> </tr> <tr> <td>Adresse</td> <td><input type="text" name="adresse"/></td> <td></td> </tr> <tr> <td>Email</td> <td><input type="text" name="email" id="email"/></td> <td></td> </tr> <tr> <td>Téléphone</td> <td><input type="text" name="telephone" id="telephone"/></td> <td><input type="submit" value="Valider" id="submit"></td> </tr> </table> </form> """ + fonctions.lien("menu.py","Retour au menu principal") + """ <script src="form-ajout.js"></script> """))
def index(req): req.content_type = "text/html" sess = Session.Session(req) redirectionSiNonConnecte(req, sess) id_util = sess["id_util"] id_contact = req.form["id_contact"] conn = connexionBD() cur = conn.cursor() sql = "select * from contact where id_contact={} and id_util={};".format( id_contact, id_util) cur.execute(sql) conn.commit() data = cur.fetchall() if not data: req.write( codeHTML( "Erreur !", """ <p>Ce contact ne vous appartient pas.</p> """ + lien('menu.py', "Retour au menu"))) conn.close() else: sql = "delete from contact where id_contact={};".format(id_contact) cur.execute(sql) conn.commit() conn.close() util.redirect(req, "liste.py")
def index(req): req.content_type = "text/html" sess = Session.Session(req) fonctions.redirectionSiNonConnecte(req, sess) if sess['id_util'] == 1: create_util = "<li>" + fonctions.lien('form-ajout-util.py', 'Ajout d\'un utilisateur') + "</li>" else: create_util = "" req.write(fonctions.codeHTML("Menu principal","""<b> Menu principal </b> <br/> Vous êtes connecté en tant que <b> """ + sess['login'] + """. </b><ul> <li>"""+fonctions.lien('form-ajout.py', 'Ajout d\'un contact')+"""</li> <li>"""+fonctions.lien('liste.py', 'Liste de contacts')+"""</li> <li>"""+fonctions.lien('localisation.py', 'Carte des contacts')+"""</li> """ + create_util + """ <li>"""+fonctions.lien('deconnexion.py', 'Déconnexion')+"""</li> </ul> """))
def index(req): req.content_type = "text/html" _cursor.execute("SELECT mdp, id_util FROM UTIL WHERE login = %s", (req.form['login'], )) query = _cursor.fetchone() if (query == None or req.form["password"] != query[0]): req.write( fonctions.codeHTML( "Erreur", "Login ou mot de passe incorrects. " + fonctions.lien("form-connexion.py", "Connexion"))) else: sess = Session.Session(req) sess["id_util"] = query[1] sess["login"] = req.form['login'] sess.save() req.write( fonctions.codeHTML( "Connexion réussie", fonctions.lien("menu.py", "Connexion réussie, allez au menu")))
def index(req): req.content_type = "text/html" sess = Session.Session(req) fonctions.redirectionSiNonConnecte(req, sess) _db = fonctions.connexionBD() _cursor = _db.cursor() _cursor.execute("SELECT * FROM CONTACT WHERE id_util = %s AND id_contact = %s", (sess['id_util'], req.form["id_contact"],)) user = _cursor.fetchone() if user is None: req.write(fonctions.codeHTML("Erreur utilisateur", "Utilisateur introuvable. <br/> " + fonctions.lien('menu.py','Retour au menu principal'))) else: table_contents = "<tr> <td>Nom</td> <td>" + user[1] + "</td></tr>" if user[2]: table_contents += "<tr> <td>Email</td> <td>" + fonctions.lien("mailto:" + user[2], user[2]) + "</td></tr>" if user[3]: table_contents += "<tr> <td>Téléphone</td> <td>" + user[3] + "</td></tr>" if user[4]: table_contents += "<tr> <td>Adresse</td> <td>" + user[4] + "</td></tr>" if user[5] != 0 and user[6] != 0: map_contents = """ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.5.1/leaflet.css" /> <div id="carte" style="width: 600px; height: 400px;"> </div> <script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.5.1/leaflet.js"></script> <script> var map = L.map("carte"); map.setView({lat: """ + str(user[5]) + """, lon: """ + str(user[6]) + """}, 10); url = 'http://{s}.tile.osm.org/{z}/{x}/{y}.png'; var layer = L.tileLayer(url); layer.addTo(map); var m = L.marker ({lat: """ + str(user[5]) + """ , lon: """ + str(user[6]) + """}); m.addTo(map); </script>""" else: map_contents = "<p>Adresse du contact introuvable</p>" req.write(fonctions.codeHTML("Fiche d'un contact","""<b> Fiche d'un contact </b> <br/> <table>""" + table_contents + """</table>""" + map_contents + fonctions.lien("suppression.py?id_contact=" + str(user[0]) ,"Supprimer l'utilisateur") + "<br/>" + fonctions.lien("menu.py","Retour au menu principal"))) _db.close()
def index(req): req.content_type = "text/html" sess = Session.Session(req) redirectionSiNonConnecte(req, sess) req.write( codeHTML( "Menu principal", """ <p><b>Menu principal</b><br/> Vous êtes connecté en tant que <b>""" + sess["login"] + """</b> </p> <ul> <li>""" + lien("form-ajout.py", "Ajout d'un contact") + """</li> <li>""" + lien("liste.py", "Liste des contacts") + """</li> <li>""" + lien("localisation.py", "Localisation des contacts") + """</li> <li>""" + lien("form-ajout-util.py", "Ajout d'un utilisateur") + """</li> <li>""" + lien("deconnexion.py", "Déconnexion") + """</li> </ul> """))
def index(req): req.content_type="text/html" sess = Session.Session(req) #recup session redirectionSiNonConnecte(req,sess) #redirige si la session est nouvelle id_util=sess["id_util"] #recup l'id_util #sqlstart conn = connexionBD() cur = conn.cursor() sql = "select * from contact where id_util={} and latitude is not null and longitude is not null;".format(id_util) #ajout des deux (lon et lat) pour être sur si jamais il y a un bug avec un seul des deux renseigné cur.execute(sql) conn.commit() data = cur.fetchall() conn.close() #sqlend #mapstart maps=""" <link rel="stylesheet" href="leaflet.css"/> <script src="leaflet.js"></script> <div id="carte" style="width: 600px; height: 400px"></div> <script> var map = L.map("carte"); map.setView({lat: 0 , lon: 0}, 1); url="https://{s}.tile.openstreetmap.org" + "/{z}/{x}/{y}.png"; var layer = L.tileLayer(url); layer.addTo(map); """#initialise tous ce qui ne changera pas #debut prise donné par contact for i in range(len(data)): lat=str(data[i][5]) lon=str(data[i][6]) id_contact=str(data[i][0]) nom=str(data[i][1]) maps+=""" var m = L.marker({lat: """ + lat + """, lon: """ + lon + """}); m.addTo(map); m.bindPopup('<a href="fiche.py?id_contact=""" + id_contact + """">""" + nom + """</a>'); """ #fin prise donné par contact maps+="</script>" #mapsend req.write(codeHTML("Localisation",""" <p><b>Localisation des contacts</b></p> <br/> """ + maps + lien("menu.py","Retour au menu")))
def index(req): req.content_type = "text/html" sess = Session.Session(req) redirectionSiNonConnecte(req, sess) req.write( codeHTML( "Liste des contacts", """ <p><b>Liste des contacts</b></p> <b>Rechercher un nom :</b> <input type="text" id="nom" onkeyup="cherche()"/><br/> <div id="liste"></div> """ + lien("menu.py", "Retour au menu") + """ <script src="liste.js"></script> """))
def index(req): req.content_type = "text/html" sess=Session.Session(req) fonctions.redirectionSiNonConnecte(req, sess) _db=fonctions.connexionBD() _cursor=_db.cursor() _cursor.execute("INSERT INTO UTIL (login, mdp) VALUES (%s , %s)", (req.form['login'], req.form['password'],)) _db.commit() req.write(fonctions.codeHTML("Menu principal",""" <b> Nouvel utilisateur </b> <br/> <p>""" + req.form['login'] + """ a bien été ajouté à la base de données. </p> """ + fonctions.lien('menu.py','Retour au menu principal'))) _db.close()
def index(req): req.content_type="text/html" content=str() #write the html page req.write(baseHTML("ATS - Syntaxe",""" <h1>Syntaxe</h1> <p>La """+lien('syntaxe.py','syntaxe')+""" pour utiliser les filtres disponibles sur la page """+lien('filtrage.py','filtrage')+""" est la suivante :</p> <p><colonne>='<valeur>'</p><br/> <table> <tr><th>colonne</th><th>valeur</th><th>exemple</th></tr> <tr><td>heure</td><td>hh:mm:ss</td><td>heure='10:41:30'</td></tr> <tr><td>protocole</td><td>texte</td><td>protocole='TCP'</td></tr> <tr><td>ip_source</td><td>W.X.Y.Z</td><td>ip_source='10.0.2.15'</td></tr> <tr><td>ip_destination</td><td>W.X.Y.Z</td><td>ip_destination='1.1.1.1'</td></tr> <tr><td>port_source</td><td>X</td><td>port_source='35042'</td></tr> <tr><td>port_destination</td><td>X</td><td>port_destination='80'</td></tr> </table> """))
def index(req): req.content_type = "text/html" sess = Session.Session(req) fonctions.redirectionSiNonConnecte(req, sess) nom = req.form['nom'] adresse = req.form['adresse'] email = req.form['email'] telephone = req.form['telephone'] id_util = sess["id_util"] conn = fonctions.connexionBD() cur = conn.cursor() #debut geocodage # geo=geocodage.geocodageIUTV(adresse) #decommentez pour utilisation IUT geo = geocodage.geocodage(adresse) #decommentez pour utilisation home if not geo: lat = None lon = None else: lat = geo[0] lon = geo[1] #fin geocodage sql = "insert into contact (nom,email,tel,adresse,latitude,longitude,id_util) values (%s,%s,%s,%s,%s,%s,%s);" cur.execute(sql, ( nom, email, telephone, adresse, lat, lon, id_util, )) conn.commit() conn.close() req.write( fonctions.codeHTML( "Nouveau contact", """ <p><b>Nouveau contact</b></p> <p>""" + nom + """ a bien été ajouté à vos contacts</p> """ + fonctions.lien('menu.py', "Retour au menu principal")))
def index(req): req.content_type = "text/html" sess = Session.Session(req) fonctions.redirectionSiNonConnecte(req, sess) _db = fonctions.connexionBD() _cursor = _db.cursor() _cursor.execute( "DELETE FROM CONTACT WHERE id_util = %s AND id_contact = %s", ( sess['id_util'], req.form["id_contact"], )) if _cursor.rowcount == 0: req.write( fonctions.codeHTML( "Erreur utilisateur", "Utilisateur introuvable. <br/> " + fonctions.lien('menu.py', 'Retour au menu principal'))) else: _db.commit() util.redirect(req, 'liste.py') _db.close()
def index(req): req.content_type = "text/html" sess = Session.Session(req) fonctions.redirectionSiNonConnecte(req, sess) try: req.form["nom"] except KeyError: req.form["nom"] = "" _db = fonctions.connexionBD() _cursor = _db.cursor() _cursor.execute("SELECT * FROM CONTACT WHERE id_util = %s AND nom LIKE %s", (sess['id_util'], "%%" + req.form["nom"] + "%%",)) _rows = _cursor.fetchall() req.write("<ul>") for row in _rows: req.write("<li>" + fonctions.lien("fiche.py?id_contact=" + str(row[0]), row[1]) + "</li>") req.write("</ul>") _db.close()
def index(req): req.content_type = "text/html" sess = Session.Session(req) redirectionSiNonConnecte(req, sess) id_util = sess["id_util"] nom = req.form["nom"] conn = connexionBD() cur = conn.cursor() sql = "select id_contact, nom from contact where id_util={} and nom like '%{}%';".format( id_util, nom) cur.execute(sql) conn.commit() data = cur.fetchall() conn.close() for i in data: req.write("""<ul><li>""" + lien('fiche.py?id_contact=' + str(i[0]), str(i[1])) + """</li></ul>""")
def index(req): req.content_type = "text/html" sess=Session.Session(req) fonctions.redirectionSiNonConnecte(req, sess) _db=fonctions.connexionBD() _cursor=_db.cursor() geocode = geocodage.geocodage(req.form['address']) if geocode != None: lat = geocode[0] lon = geocode[1] else: lat = 0 lon = 0 _cursor.execute("INSERT INTO CONTACT (id_util, nom, email, tel, adresse, latitude, longitude) VALUES (%s , %s, %s, %s, %s, %s, %s)", (sess['id_util'],req.form['nom'], req.form['email'], req.form['telephone'], req.form['address'], lat, lon)) _db.commit() req.write(fonctions.codeHTML("Menu principal",""" <b> Nouveau contact </b> <br/> <p>""" + req.form['nom'] + """ a bien été ajouté à vos contacts. </p> """ + fonctions.lien('menu.py','Retour au menu principal'))) _db.close()
def index(req): req.content_type = "text/html" sess = Session.Session(req) fonctions.redirectionSiNonConnecte(req, sess) req.write( fonctions.codeHTML( "Ajout d'un contact", """<b>Ajout d'un contact</b> <br/> <form action="ajout.py" method="post" name="form" onsubmit="return validate()"> <table> <tr> <th></th> <th></th> <th></th> </tr> <tr> <td> <label for="nom">Nom</label> </td> <td> <input type="text" id="nom" name="nom" /> </td> <td></td> </tr> <tr> <td> <label for="address">Adresse</label> </td> <td> <input type="address" id="address" name="address" /> </td> <td> </td> </tr> <tr> <td> <label for="email">Mail</label> </td> <td> <input type="email" id="email" name="email" /> </td> <td> </td> </tr> <tr> <td> <label for="telephone">Téléphone</label> </td> <td> <input type="telephone" id="telephone" name="telephone" /> </td> <td> <input type="submit" value="Valider" /> </td> </tr> </table> </form> <script> function validate(){ var nom = document.forms["form"]["nom"].value; if (nom == "") { alert("Le nom ne doit pas être vide !"); return false; } var email = document.forms["form"]["email"].value; if(email.indexOf("@") == "-1"){ alert("L'email doit contenir un @ !"); return false; } else { var pos = email.indexOf("@") } if(email.indexOf(".", pos) == "-1"){ alert("L'email doit contenir un . !"); return false; } var address = document.forms["form"]["address"].value; if (address == "") { alert("L'adresse ne doit pas être vide !"); return false; } var telephone = document.forms["form"]["telephone"].value; if(! /^\d+$/.test(telephone)){ alert("Le numéro de téléphone doit être composé de chiffres"); return false; } if(telephone.length != 10){ alert("Le numéro de téléphone doit être une suite de 10 chiffres"); return false; } } </script> """ + fonctions.lien('menu.py', 'Retour au menu principal')))
def index(req): req.content_type="text/html" #partie socket #check si ip est bien la try: ip=req.form["ip"] except KeyError: mod_python.util.redirect(req, "index.py") #check si ip a le bon format try: socket.inet_aton(ip) except socket.error: mod_python.util.redirect(req, "index.py") content=str() #reverse dns try: rdns=socket.gethostbyaddr(ip)[0] except socket.herror: rdns="<em>Non connu</em>" #partie socket #sql part conn=connexionBD() cur=conn.cursor() sql="SELECT * FROM paquet WHERE ip_source=%s ORDER BY heure DESC" sql_count="SELECT COUNT(*) FROM paquet WHERE ip_source=%s" cur.execute(sql, (ip, )) conn.commit() data=cur.fetchall() cur.execute(sql_count, (ip, )) conn.commit() count=cur.fetchone() conn.close() #sql part #takes every lines from the select for i in data : content+=("""<tr>""" + """<td>""" + str(i[1]) + """</td>""" + """<td>""" + str(i[2]) + """</td>""" + """<td>""" + lien('ip_source.py?ip=' + str(i[3]), str(i[3])) + """</td>""" + """<td>""" + lien('ip_destination.py?ip=' + str(i[4]), str(i[4])) + """</td>""" + """<td>""" + lien('port_source.py?port=' + str(i[5]), str(i[5])) + """</td>""" + """<td>""" + lien('port_destination.py?port=' + str(i[6]), str(i[6])) + """</td>""" + """</tr>""") #write the html page req.write(baseHTML("ATS - " + ip,""" <h1>IP source : """ + ip + """</h1> <p>Nombre de paquets venant de """+ ip + """ : <b>"""+ str(count[0])+ """</b></p> <p>Reverse DNS : <b>"""+rdns+"""</b><p> <div id="tab"> <table class="data_tab"> <tr><th>Heure</th><th>Protocole</th><th>IP Source</th><th>IP Destination</th><th>Port Source</th><th>Port Destination</th></tr> """ + content + """ </table> </div> """))
def index(req): req.content_type = "text/html" sess = Session.Session(req) #recup session redirectionSiNonConnecte(req, sess) #redirige si la session est nouvelle id_util = sess["id_util"] #recup l'id_util id_contact = req.form["id_contact"] #recup l'id_contact #debut sql conn = connexionBD() cur = conn.cursor() sql = "select * from contact where id_contact={} and id_util={};".format( id_contact, id_util) cur.execute(sql) conn.commit() data = cur.fetchall() conn.close() #fin sql if not data: req.write( codeHTML( "Erreur !", """ <p>Ce contact ne vous appartient pas.</p> """ + lien('menu.py', "Retour au menu"))) #si le resultat de la req sql est vide #alors le contact n'appartient pas à l'utilisateur connecté else: #début prise info dans les var data = data[0] nom = str(data[1]) email = str(data[2]) tel = str(data[3]) addr = str(data[4]) lat = str(data[5]) lon = str(data[6]) #fin prise infos content = "" #ou tout le surplus va être ajouté (en plus du nom) if email != "": content += """ <tr> <td>Email</td> <td>""" + lien("mailto:" + email, email) + """</td> </tr> """ #check si l'email est donné if tel != "": content += """ <tr> <td>Telephone</td> <td>""" + tel + """</td> </tr> """ #check si le num est donné if addr != "": content += """ <tr> <td>Adresse</td> <td>""" + addr + """</td> </tr> """ #check si l'addresse est donné #debut affiche map if addr == "": #si pas d'adresse maps = "<b>Adresse non précisé</b>" elif lat == "None" and lon == "None": #si le geocodage ne renvoit rien maps = "<b>Emplacement indisponible</b>" else: #créé la map avec lat et lon de geocodage maps = """ <link rel="stylesheet" href="leaflet.css"/> <script src="leaflet.js"></script> <div id="carte" style="width: 600px; height: 400px"></div> <script> var map = L.map("carte"); map.setView({lat: """ + lat + """, lon: """ + lon + """}, 10); url="https://{s}.tile.openstreetmap.org" + "/{z}/{x}/{y}.png"; var layer = L.tileLayer(url); layer.addTo(map); var m = L.marker({lat: """ + lat + """, lon: """ + lon + """}); m.addTo(map); </script> """ #fin affichage maps #la suite écrit la page avec les différentes variables données req.write( codeHTML( "Fiche d'un contact", """ <b>Fiche d'un contact</b><br/> <table> <tr> <td>Nom</td> <td>""" + nom + """</td> </tr> """ + content + """ </table> """ + maps + """ <br/> """ + lien("supression.py?id_contact=" + id_contact, "Supression du contact") + """ <br/> """ + lien("menu.py", "Retour au menu")))
def index(req): req.content_type = "text/html" sess = Session.Session(req) fonctions.redirectionSiNonConnecte(req, sess) fonctions.redirectionSiNonRoot(req, sess) req.write( fonctions.codeHTML( "Ajout d'un utilisateur", """<b>Ajout d'un utilisateur</b> <br/> <form action="ajout-util.py" method="post" name="form" onsubmit="return validate()"> <table> <tr> <th></th> <th></th> <th></th> </tr> <tr> <td> <label for="login">Login</label> </td> <td> <input type="text" id="login" name="login" onblur="checkLogin(this.value)"/> </td> <td></td> </tr> <tr> <td> <label for="password">Mot de passe</label> </td> <td> <input type="password" id="password" name="password" /> </td> <td> </td> </tr> <tr> <td> <label for="password-again">Confirmation du mot de passe</label> </td> <td> <input type="password" id="password-again" name="password-again" /> </td> <td> <input type="submit" value="Valider" /> </td> </tr> </table> </form> <script> function validate(){ var login = document.forms["form"]["login"].value; if (login == "") { alert("Le login ne doit pas être vide !"); return false; } var password = document.forms["form"]["password"].value; if (password.length < 8) { alert("Le mot de passe doit faire plus de 8 caractères"); return false; } var password_again = document.forms["form"]["password-again"].value; if (password != password_again) { alert("Les mots de passe ne correspondent pas"); return false; } var login = document.forms["form"]["login"]; if(login.getAttribute("available") == "no"){ alert("Nom d'utilisateur déjà existant"); return false; } } function checkLogin(login){ var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { response = JSON.parse(this.responseText); if(response.taken){ document.forms["form"]["login"].setAttribute("available", "no"); } else { document.forms["form"]["login"].setAttribute("available", "yes"); } } }; xhttp.open("GET", "verif-util.py?login="******""" + fonctions.lien('menu.py', 'Retour au menu principal')))
def index(req): req.content_type = "text/html" ipdst = str() portdst = str() ipsrc = str() portsrc = str() #sql part conn = connexionBD() cur = conn.cursor() ### 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 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 j in champs: for k in suff: nom = "each_" + j + "_" + k for i in globals()[nom]: if j == "ip" and k == "dst": globals()[j + k] += ("""<tr> <td>""" + lien('ip_destination.py?ip=' + str(i[0]), str(i[0])) + """</td> <td>""" + str(i[1]) + """</td> </tr>""") elif j == "port" and k == "dst": globals()[j + k] += ("""<tr> <td>""" + lien('port_destination.py?port=' + str(i[0]), str(i[0])) + """</td> <td>""" + str(i[1]) + """</td> </tr>""") elif j == "ip" and k == "src": globals()[j + k] += ("""<tr> <td>""" + lien('ip_source.py?ip=' + str(i[0]), str(i[0])) + """</td> <td>""" + str(i[1]) + """</td> </tr>""") else: globals()[j + k] += ("""<tr> <td>""" + lien('port_source.py?port=' + str(i[0]), str(i[0])) + """</td> <td>""" + str(i[1]) + """</td> </tr>""") #write the html page req.write( baseHTML( "ATS - Bilan", """ <h1>Bilan</h1> <div id="tip" style="display:block;"> Afin de voir le reverse DNS d'une adresse IP, cliquez sur cette dernière dans le tableau <button id="ok" onclick="toggle_div(this,'tip');">OK</button></div> <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> <div id="bilan_tab"> <table class="inlineTable"> <tr><th>IP destination</th><th>Récurrence</th></tr> """ + str(ipdst) + """ </table> <table class="inlineTable"> <tr><th>Port destination</th><th>Récurrence</th></tr> """ + str(portdst) + """ </table> <table class="inlineTable"> <tr><th>IP source</th><th>Récurrence</th></tr> """ + str(ipsrc) + """ </table> <table class="inlineTable"> <tr><th>Port source</th><th>Récurrence</th></tr> """ + str(portsrc) + """ </table> </div> <script src="tip.js"></script> """))
def index(req): req.content_type = "text/html" #check si ip est bien la try: port = req.form["port"] except KeyError: mod_python.util.redirect(req, "index.py") #check si port a le bon format try: float(port) except ValueError: mod_python.util.redirect(req, "index.py") content = str() #sql part conn = connexionBD() cur = conn.cursor() sql = "SELECT * FROM paquet WHERE port_destination=%s ORDER BY heure DESC" sql_count = "SELECT COUNT(*) FROM paquet WHERE port_destination=%s" cur.execute(sql, (port, )) conn.commit() data = cur.fetchall() cur.execute(sql_count, (port, )) conn.commit() count = cur.fetchone() conn.close() #sql part #takes every lines from the select for i in data: content += ("""<tr>""" + """<td>""" + str(i[1]) + """</td>""" + """<td>""" + str(i[2]) + """</td>""" + """<td>""" + lien('ip_source.py?ip=' + str(i[3]), str(i[3])) + """</td>""" + """<td>""" + lien('ip_destination.py?ip=' + str(i[4]), str(i[4])) + """</td>""" + """<td>""" + lien('port_source.py?port=' + str(i[5]), str(i[5])) + """</td>""" + """<td>""" + lien('port_destination.py?port=' + str(i[6]), str(i[6])) + """</td>""" + """</tr>""") #write the html page req.write( baseHTML( "ATS - " + port, """ <h1>Port destination : """ + port + """</h1> <div id="tip" style="display:block;"> Afin de voir le reverse DNS d'une adresse IP, cliquez sur cette dernière dans le tableau <button id="ok" onclick="toggle_div(this,'tip');">OK</button></div> <p>Nombre de paquets en destination de """ + port + """ : <b>""" + str(count[0]) + """</b></p> <div id="tab"> <table class="data_tab"> <tr><th>Heure</th><th>Protocole</th><th>IP Source</th><th>IP Destination</th><th>Port Source</th><th>Port Destination</th></tr> """ + content + """ </table> </div> <script src="tip.js"></script> """))