Patch de toutes les failles de la première issue, close #1
Signed-off-by: Rick <rick@gnous.eu>
This commit is contained in:
parent
b5d6fed34a
commit
b7f9dfdbe6
1 changed files with 22 additions and 21 deletions
43
app.py
43
app.py
|
@ -1,10 +1,21 @@
|
||||||
from flask import Flask, render_template, request, redirect, url_for, make_response
|
from flask import Flask, render_template, request, redirect, url_for, make_response, Markup
|
||||||
from os import path
|
from enum import Enum
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
app = Flask('ui', static_url_path="/static")
|
app = Flask('ui', static_url_path="/static")
|
||||||
app.config['TEMPLATES_AUTO_RELOAD'] = True
|
app.config['TEMPLATES_AUTO_RELOAD'] = True
|
||||||
|
|
||||||
|
class Status(Enum):
|
||||||
|
ERREUR_LIEN = "Le lien doit être en http ou https !",
|
||||||
|
BON = "Lien ajouté !"
|
||||||
|
|
||||||
|
def ecritureFichierHtml(nouvLien, cheminFichier):
|
||||||
|
with open(cheminFichier, 'r') as file:
|
||||||
|
soup = BeautifulSoup(file, 'html.parser')
|
||||||
|
soup.find("hr").insert_after("", nouvLien)
|
||||||
|
with open(cheminFichier, 'w') as file:
|
||||||
|
file.write(soup.prettify())
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def slash():
|
def slash():
|
||||||
response = make_response(render_template("index.html"))
|
response = make_response(render_template("index.html"))
|
||||||
|
@ -22,32 +33,22 @@ def apropos():
|
||||||
@app.route("/bizutage", methods=["POST"])
|
@app.route("/bizutage", methods=["POST"])
|
||||||
def bizutage():
|
def bizutage():
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
titre = request.values['titre']
|
|
||||||
lien = request.values['lien']
|
lien = request.values['lien']
|
||||||
desc = request.values['desc']
|
if not (lien.startswith("http") or lien.startswith("https")):
|
||||||
|
return render_template("ajout.html", erreur=Status.ERREUR_LIEN.value)
|
||||||
|
|
||||||
|
titre = Markup.escape(request.values['titre'])
|
||||||
|
desc = Markup.escape(request.values['desc'])
|
||||||
nouvLien = "<div class=\"elem\"><h2>{}</h2><p><a href=\"{}\">Lien</a></p><hr><p>{}</p>".format(titre, lien, desc)
|
nouvLien = "<div class=\"elem\"><h2>{}</h2><p><a href=\"{}\">Lien</a></p><hr><p>{}</p>".format(titre, lien, desc)
|
||||||
nouvLienHtml = BeautifulSoup(nouvLien, "html.parser")
|
nouvLienHtml = BeautifulSoup(nouvLien, "html.parser")
|
||||||
|
nouvLienHtmlJinja = BeautifulSoup("{% raw %}" + nouvLien + "{% endraw %}", "html.parser")
|
||||||
|
|
||||||
if nouvLienHtml.find("script") != None:
|
ecritureFichierHtml(nouvLienHtmlJinja, "templates/index.html")
|
||||||
erreur = "Vous ne pouvez pas charger de balises script !"
|
ecritureFichierHtml(nouvLienHtml, "lite/index.html")
|
||||||
return render_template("ajout.html", erreur=erreur)
|
|
||||||
|
|
||||||
with open("templates/index.html", 'r') as file:
|
|
||||||
soup = BeautifulSoup(file, 'html.parser')
|
|
||||||
soup.find("hr").insert_after("", nouvLienHtml)
|
|
||||||
with open("templates/index.html", 'w') as file:
|
|
||||||
file.write(soup.prettify())
|
|
||||||
|
|
||||||
with open("lite/index.html", 'r') as file:
|
|
||||||
soup = BeautifulSoup(file, 'html.parser')
|
|
||||||
soup.find("hr").insert_after("", nouvLienHtml)
|
|
||||||
with open("lite/index.html", 'w') as file:
|
|
||||||
file.write(soup.prettify())
|
|
||||||
|
|
||||||
reussite = "Lien ajouté !"
|
|
||||||
else:
|
else:
|
||||||
print("error")
|
print("error")
|
||||||
return render_template("ajout.html", reussi=reussite)
|
return render_template("ajout.html", reussi=Status.BON.value)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app.run()
|
app.run()
|
||||||
|
|
Loading…
Reference in a new issue