Select Git revision
-
David Beniamine authoredDavid Beniamine authored
index.py 3.61 KiB
#!/usr/bin/python3
# -*- coding: utf-8 -*
# Copyright (C) 2017 Tetras Libre <contact@Tetras-Libre.fr>
# Author: Beniamine, David <David.Beniamine@Tetras-Libre.fr>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import cgi
import re
from test_pass import test_pass
form = cgi.FieldStorage()
print("Content-type: text/html; charset=utf-8\n")
html = """<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<meta name="author" content="David Beniamine">
<link type="text/css" rel="stylesheet" href="css/style.css" />
<title>Testeur de mot de passes</title>
</head>
<body>
<div id="box">
<div id="content">
<div id="logos">
<img style="float:left" src="img/tl.png" alt="Tetras Libre" />
<h1>
Tetras Pass
</h1>
</div>
"""
if form.getvalue("password") is None:
# Password not defined => show the form
passwordPrompt = "Veuillez saisir le mot de passe à tester ci dessous :"
inputsPrompt = "Veuillez saisir une liste de mots ou de dates au format jj/mm/yyyy, un indice par ligne:"
sendPrompt = "Lancer le test"
html += """
<form action="/index.py" method="post" id="mainform">
<div id="form">
<h2> Defenseur.se </h2>
<p> {} </p>
<input type="password" name="password" value="" />
<h2> Attaquant.e </h2>
<p> {} </p>
<textarea name="inputs" form="mainform"></textarea>
<p>
<input type="submit" name="send" value="{}">
</p>
</div>
</form>
""".format(passwordPrompt, inputsPrompt, sendPrompt)
else:
# Split user inputs
field = form.getvalue("inputs")
if field is not None:
inputs = field.split('\n')
else:
inputs = None
# Retrieve results
lines = test_pass(form.getvalue("password"), inputs)
# Process results for the web
html += "<h2> {} </h2>".format(lines.pop(0))
inlist = False
for line in lines:
line = re.sub('\*\*(.*)\*\*', '<em>\g<1></em>', line)
if line[0] == "\t":
if inlist:
html += "<li>{}</li>".format(line)
else:
inlist = True
html += "<ul><li>{}</li>".format(line)
elif line[0] != "\n":
if inlist:
html += "</ul>"
inlist = False
html += "<h3>{}</h3>".format(line)
html += """
</div>
</div>
</body>
<foot>
<p>
<a href="https://gitlab.tetras-libre.fr/tetras-libre/tetras-pass">Tetra Pass</a> est Logiciel développé par
<a href="http://tetras-libre.fr">Tetras Libre</a>,
distribué sous Licence <a href="https://www.gnu.org/licenses/agpl.html">AGPL</a> V3.0.
</p>
<p>
Le testeur de mot de passe est basé sur la bibliothèque
<a href="https://github.com/dwolfhub/zxcvbn-python">zxcvbn-python</a> distribué sous licence
<a href="https://mit-license.org/">MIT</a>.
</p>
<p>
Les listes de mots et noms français proviennent de <a href="http://www.lexique.org/">lexique.org</a>
et sont distribués sous licence <a href="https://www.gnu.org/licenses/gpl-3.0.txt">GPL</a>.
</p>
</foot>
</html>
"""
print(html)