예제 #1
0
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()
예제 #2
0
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")))
예제 #4
0
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/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")
예제 #6
0
파일: index.py 프로젝트: clyhtsuriva/ATS
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>
"""))
예제 #7
0
def index(req):
    req.content_type = "application/json"

    _db = fonctions.connexionBD()
    _cursor = _db.cursor()
    _cursor.execute("SELECT * FROM Util WHERE login = %s",
                    (req.form["login"], ))
    if _cursor.fetchone() is not None:
        req.write(json.dumps({"taken": True}))
    else:
        req.write(json.dumps({"taken": False}))
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) #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")))
예제 #10
0
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 longitude, latitude, nom, id_contact FROM CONTACT WHERE id_util = %s",
        (sess['id_util'], ))
    markers = ""
    _db.close()

    req.write(
        fonctions.codeHTML(
            "Localisation", """
<label for="search">Rechercher un contact :</label>
<input type="text" id="search" onkeyup="chargementMarqueurs(this.value)"/>
<br><br>
<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");
url = 'http://{s}.tile.osm.org/{z}/{x}/{y}.png';
var layer = L.tileLayer(url);
var layerGroup = L.layerGroup().addTo(map);
layer.addTo(map);

chargementMarqueurs();

function chargementMarqueurs(filter) {
  if(filter == null){
  	filter = "";
  }
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
     eval(this.responseText);
    }
  };
  xhttp.open("GET", "affiche-markers.py?nom=" + filter, true);
  xhttp.send();
}
</script>
"""))
예제 #11
0
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()
예제 #12
0
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")))
예제 #13
0
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()
예제 #14
0
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()
예제 #15
0
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)
    redirectionSiNonConnecte(req, sess)
    id_util = sess["id_util"]
    nom = req.form["nom"]

    conn = connexionBD()
    cur = conn.cursor()

    sql = "select * from contact where id_util={} and latitude is not null and longitude is not null and nom like '%{}%';".format(
        id_util, nom)
    cur.execute(sql)
    conn.commit()
    data = cur.fetchall()
    conn.close()

    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 = ""

        contact += """
var m = L.marker({lat: """ + lat + """, lon: """ + lon + """});
        m.addTo(map);
        m.bindPopup('<a href="fiche.py?id_contact=""" + id_contact + """">""" + nom + """</a>');
"""

    req.write("""
<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);
""" + contact)
예제 #18
0
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()
예제 #19
0
def index(req):
    req.content_type = "text/html"

    sess = Session.Session(req)
    redirectionSiNonConnecte(req, sess)
    id_util = sess["id_util"]
    login = req.form["login"]
    conn = connexionBD()
    cur = conn.cursor()

    sql = "select login from util where util.login='******';".format(login)
    cur.execute(sql)
    conn.commit()
    data = cur.fetchall()
    conn.close()

    if not data:
        req.write("""<input type="submit" value="Valider" id="submit">""")
    else:
        req.write(
            """<b>Erreur : Ce login est déjà utilisé par un autre utilisateur</b>"""
        )
예제 #20
0
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")))
예제 #21
0
#!/usr/bin/python
# coding: utf-8
# Antonin Guyot

from mod_python import Session
import fonctions

_db = fonctions.connexionBD()
_cursor = _db.cursor()


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")))
예제 #22
0
#!/usr/bin/python

import fonctions

fonctions.connexionBD()

conn = .cursor()
conn.execute("INSERT INTO contact(nom, email, tel, adresse) VALUES(?, ?, ?, ?,)",(nom, email, tel, adresse))
예제 #23
0
파일: bilan.py 프로젝트: clyhtsuriva/ATS
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>
"""))
예제 #24
0
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>
"""))
예제 #25
0
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>
"""))
예제 #26
0
                 caracteristiques = BeautifulSoup(str(c), "lxml").find("div", class_="details-characteristics")
                 details = caracteristiques.find_all("span", class_="qt")
                 
                 tab = []
                 for i in details:
                     tab.append(BeautifulSoup(str(i), "lxml").find("span", class_="qt").getText().upper().strip())
                 
                 if(tab.__contains__('N/A') or (tab[4] != "GASOIL" and tab[4] != "ESSENCE")):
                     tab.clear()
                 else:
                     km = tab[2].split()
                     tab[2] = int(km[0])
                     #---------------------------------------------------------------------------------------------------
                     #       Connexion à la base de données PostgreSQL pour insérer les données
                     #---------------------------------------------------------------------------------------------------
                     connexion = connexionBD()
                     cursor = connexion.cursor()
                     sql = """
                         INSERT INTO voiture_a_vendre_1 (marque, modele, kilometrage, transmission,
                         carburant, annee, prix, localisation, image, lienAnnonce)
                         VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)
                     """
                     cursor.execute(sql,(tab[0],tab[1],tab[2],tab[3],tab[4],anneeVoiture,prix,localisation,image,lienAnnonce))
                     connexion.commit()
                     cursor.close()
                     connexion.close()
             else:
                 break
     except Exception:
         print("Erreur lors de la recherche des informations")
 else: