maj de 18h38
This commit is contained in:
222
flask/index.html
Normal file
222
flask/index.html
Normal file
@@ -0,0 +1,222 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||
<title>Loustiques Home - Connexion</title>
|
||||
<style>
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: system-ui, sans-serif;
|
||||
background: #1f1f1f;
|
||||
color: #f0f0f0;
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.carte {
|
||||
width: 380px;
|
||||
max-width: 95vw;
|
||||
background: #2a2a2a;
|
||||
border-radius: 8px;
|
||||
padding: 40px 36px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 26px;
|
||||
font-weight: 700;
|
||||
margin-bottom: 8px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.soustitre {
|
||||
font-size: 14px;
|
||||
color: #888;
|
||||
margin-bottom: 36px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.champ {
|
||||
margin-bottom: 18px;
|
||||
}
|
||||
|
||||
label {
|
||||
display: block;
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
margin-bottom: 6px;
|
||||
color: #aaa;
|
||||
}
|
||||
|
||||
input {
|
||||
width: 100%;
|
||||
padding: 11px 14px;
|
||||
font-size: 14px;
|
||||
font-family: inherit;
|
||||
border: 1px solid #3a3a3a;
|
||||
border-radius: 6px;
|
||||
outline: none;
|
||||
transition: border-color 0.15s;
|
||||
color: #f0f0f0;
|
||||
background: #333;
|
||||
}
|
||||
|
||||
input:focus {
|
||||
border-color: #2563eb;
|
||||
}
|
||||
|
||||
input::placeholder {
|
||||
color: #555;
|
||||
}
|
||||
|
||||
button {
|
||||
width: 100%;
|
||||
margin-top: 10px;
|
||||
padding: 12px;
|
||||
background: #2563eb;
|
||||
color: #fff;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
font-family: inherit;
|
||||
cursor: pointer;
|
||||
transition: background 0.15s;
|
||||
}
|
||||
|
||||
button:hover { background: #1d4ed8; }
|
||||
button:active { background: #1e40af; }
|
||||
button:disabled { opacity: 0.4; cursor: not-allowed; }
|
||||
|
||||
.message {
|
||||
margin-top: 14px;
|
||||
font-size: 13px;
|
||||
display: none;
|
||||
}
|
||||
.message.error {
|
||||
display: block;
|
||||
color: #f87171;
|
||||
}
|
||||
.message.success {
|
||||
display: block;
|
||||
color: #4ade80;
|
||||
}
|
||||
|
||||
.footer {
|
||||
margin-top: 28px;
|
||||
font-size: 12px;
|
||||
color: #555;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="carte">
|
||||
<h1>Loustiques Home</h1>
|
||||
<p class="soustitre">Connectez-vous via mot de passe ou avec votre bagde pour accéder à votre espace.</p>
|
||||
|
||||
<div class="champ">
|
||||
<label for="username">Identifiant</label>
|
||||
<input type="text" id="username" placeholder="Nom du loustique" autocomplete="username" />
|
||||
</div>
|
||||
|
||||
<div class="champ">
|
||||
<label for="password">Mot de passe</label>
|
||||
<input type="password" id="password" placeholder="Wola ouais" autocomplete="current-password" />
|
||||
</div>
|
||||
|
||||
<button id="btn" onclick="handleLogin()">Se connecter</button>
|
||||
|
||||
<div class="message" id="msg"></div>
|
||||
|
||||
<p class="footer">Accès réservé aux utilisateurs ajoutés par les loustiques.</p>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// 1. Écoute de la touche Entrée
|
||||
["username", "password"].forEach(id => {
|
||||
document.getElementById(id).addEventListener("keydown", e => {
|
||||
if (e.key === "Enter") handleLogin();
|
||||
});
|
||||
});
|
||||
|
||||
// 2. Fonction de connexion manuelle (Mot de passe)
|
||||
async function handleLogin() {
|
||||
const username = document.getElementById("username").value.trim();
|
||||
const password = document.getElementById("password").value;
|
||||
const btn = document.getElementById("btn");
|
||||
const msg = document.getElementById("msg");
|
||||
|
||||
msg.className = "message";
|
||||
|
||||
if (!username || !password) {
|
||||
msg.className = "message error";
|
||||
msg.textContent = "Veuillez remplir tous les champs.";
|
||||
return;
|
||||
}
|
||||
|
||||
btn.disabled = true;
|
||||
btn.textContent = "Vérification...";
|
||||
|
||||
try {
|
||||
const res = await fetch("/login", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ username, password })
|
||||
});
|
||||
const data = await res.json();
|
||||
|
||||
if (data.success) {
|
||||
msg.className = "message success";
|
||||
msg.textContent = "Connexion réussie !";
|
||||
window.location.href = "/dashboard";
|
||||
} else {
|
||||
msg.className = "message error";
|
||||
msg.textContent = data.message || "Identifiants incorrects.";
|
||||
}
|
||||
} catch {
|
||||
msg.className = "message error";
|
||||
msg.textContent = "Impossible de contacter le serveur.";
|
||||
} finally {
|
||||
btn.disabled = false;
|
||||
btn.textContent = "Se connecter";
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Écoute automatique du badge (RFID) - SORTI DE LA FONCTION !
|
||||
setInterval(async () => {
|
||||
try {
|
||||
// Attention : Vérifie que cette route correspond bien à celle dans main.py
|
||||
// (J'avais mis /check-rfid-login dans mon exemple précédent)
|
||||
const res = await fetch('/check-rfid-login');
|
||||
const data = await res.json();
|
||||
|
||||
if (data.success) {
|
||||
const msg = document.getElementById("msg");
|
||||
const btn = document.getElementById("btn");
|
||||
const inputs = document.querySelectorAll("input");
|
||||
|
||||
btn.disabled = true;
|
||||
inputs.forEach(input => input.disabled = true);
|
||||
|
||||
msg.className = "message success";
|
||||
msg.textContent = "Badge reconnu ! Bienvenue " + data.username + "...";
|
||||
|
||||
setTimeout(() => {
|
||||
window.location.href = "/dashboard";
|
||||
}, 1000);
|
||||
}
|
||||
} catch (e) {
|
||||
// Erreurs ignorées silencieusement
|
||||
}
|
||||
}, 1500);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -10,14 +10,14 @@ import re
|
||||
|
||||
app = Flask(__name__)
|
||||
Talisman(app, force_https=True,
|
||||
content_security_policy=False )
|
||||
content_security_policy=False)
|
||||
current_user = None
|
||||
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
composants = os.path.join(BASE_DIR, "composants", "byPanda")
|
||||
sys.path.insert(0, composants)
|
||||
from alarme import SystemeAlarme
|
||||
from lumiere import SystemeLumieres
|
||||
from lumieres import SystemeLumieres
|
||||
from board1main import *
|
||||
|
||||
@app.route("/")
|
||||
@@ -48,21 +48,45 @@ def call_led():
|
||||
else:
|
||||
SystemeLumieres.eteindreLumieres()
|
||||
return jsonify({"success": True})
|
||||
# Variable temporaire pour stocker le dernier badge scanné
|
||||
dernier_badge_scanne = None
|
||||
|
||||
@app.route("/rfid-scan", methods=["POST"])
|
||||
def rfid_scan():
|
||||
global dernier_badge_scanne
|
||||
data = request.get_json()
|
||||
badge_id = str(data.get("badge_id"))
|
||||
badge_id = data.get("badge_id")
|
||||
|
||||
# On va créer cette fonction dans ton fichier auth.py juste après
|
||||
username = auth.get_user_by_rfid(badge_id)
|
||||
|
||||
if username:
|
||||
|
||||
# Le badge est dans la base de données ! On autorise.
|
||||
dernier_badge_scanne = username
|
||||
return jsonify({"success": True, "username": username})
|
||||
else:
|
||||
# Badge inconnu dans la BDD
|
||||
# Badge inconnu
|
||||
return jsonify({"success": False})
|
||||
|
||||
@app.route("/check-rfid-login", methods=["GET"])
|
||||
def check_rfid_login():
|
||||
global dernier_badge_scanne
|
||||
global current_user
|
||||
|
||||
# Si le Raspberry Pi a signalé un badge validé récemment
|
||||
if dernier_badge_scanne:
|
||||
user = dernier_badge_scanne
|
||||
|
||||
# On valide la connexion côté serveur
|
||||
current_user = user
|
||||
|
||||
# On vide la variable pour ne pas le reconnecter en boucle à l'infini
|
||||
dernier_badge_scanne = None
|
||||
|
||||
return jsonify({"success": True, "username": user})
|
||||
|
||||
return jsonify({"success": False})
|
||||
|
||||
|
||||
|
||||
@app.route("/alarme",methods=["POST"])
|
||||
@@ -107,6 +131,23 @@ def get_users():
|
||||
users = auth.get_users()
|
||||
return jsonify({"success": True, "users": users})
|
||||
|
||||
@app.route("/api/relais-pi2/<action>", methods=["GET"])
|
||||
def relais_pi2(action):
|
||||
"""
|
||||
Flask sert de relais. Le navigateur demande à Flask, et Flask demande au Pi 2.
|
||||
"""
|
||||
try:
|
||||
# L'adresse de ton Pi 2
|
||||
url_pi2 = f"https://pi32.local:8000/{action}"
|
||||
|
||||
# Le Pi 1 fait la requête ! verify=False permet d'ignorer le faux certificat
|
||||
reponse = requests.get(url_pi2, timeout=5, verify=False)
|
||||
|
||||
return jsonify(reponse.json())
|
||||
|
||||
except Exception as e:
|
||||
return jsonify({"success": False, "message": str(e)})
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("[*] Démarrage du lecteur RFID et de l'alarme en arrière-plan...")
|
||||
|
||||
@@ -46,14 +46,14 @@ Vérification des certificats SSL
|
||||
==================================
|
||||
EOF
|
||||
|
||||
bash web_secu/ssl.sh
|
||||
bash ../web_secu/ssl.sh
|
||||
|
||||
cat << 'EOF'
|
||||
=============================
|
||||
Vérification du daemon Avahi
|
||||
============================
|
||||
EOF
|
||||
bash web_secu/avahi.sh
|
||||
bash ../web_secu/avahi.sh
|
||||
|
||||
|
||||
cat << 'EOF'
|
||||
|
||||
@@ -268,14 +268,14 @@
|
||||
<div class="section-title">Actions rapides</div>
|
||||
|
||||
<div class="actions">
|
||||
<button class="action-btn" onclick="callLed()">
|
||||
<span class="a-label">💡 LED</span>
|
||||
<span class="a-sub">Contrôler la LED</span>
|
||||
<button class="action-btn" onclick="call_led_up()">
|
||||
<span class="a-label">💡 UP LED</span>
|
||||
<span class="a-sub">Allumer la LED</span>
|
||||
<span class="a-arrow">›</span>
|
||||
</button>
|
||||
<button class="action-btn" onclick="callAlarm()">
|
||||
<span class="a-label">Alarme</span>
|
||||
<span class="a-sub">Armer l'alarme</span>
|
||||
<span class="a-label">DOWN led</span>
|
||||
<span class="a-sub">Eteindre la led</span>
|
||||
<span class="a-arrow">›</span></button>
|
||||
<button class="action-btn" onclick="callAlarm()">
|
||||
<span class="a-label">Alarme</span>
|
||||
@@ -306,17 +306,7 @@
|
||||
setInterval(updateClock, 1000);
|
||||
|
||||
|
||||
async function callLed() {
|
||||
try {
|
||||
const res = await fetch('/led', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' }
|
||||
});
|
||||
showToast("LED activée !");
|
||||
} catch {
|
||||
showToast("Erreur lors de l'appel LED.");
|
||||
}
|
||||
}
|
||||
|
||||
async function callAlarm() {
|
||||
try {
|
||||
const res = await fetch('/alarme', {
|
||||
@@ -329,7 +319,7 @@
|
||||
}
|
||||
async function call_led_down() {
|
||||
try {
|
||||
const res = await fetch('http://pi32.local/down_led', {
|
||||
const res = await fetch('https://pi32.local:8000down_led', {
|
||||
method: 'GET',
|
||||
headers: { 'Content-Type': 'application/json' }
|
||||
});
|
||||
@@ -340,16 +330,14 @@
|
||||
}
|
||||
async function call_led_up() {
|
||||
try {
|
||||
const res = await fetch('http://pi32.local/up_led', {
|
||||
const res = await fetch('https://pi32.local:8000/up_led', {
|
||||
method: 'GET',
|
||||
headers: { 'Content-Type': 'application/json' }
|
||||
});
|
||||
showToast("led activée !");
|
||||
showToast("LED allumée !");
|
||||
} catch {
|
||||
showToast("Erreur lors de l'appel board1.");
|
||||
showToast("Erreur lors de l'appel Pi 2.");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -192,7 +192,7 @@
|
||||
setInterval(async () => {
|
||||
try {
|
||||
|
||||
const res = await fetch('/check-rfid-login');
|
||||
const res = await fetch('/rfid-scan');
|
||||
const data = await res.json();
|
||||
|
||||
if (data.success) {
|
||||
|
||||
Reference in New Issue
Block a user