From: gaby Date: Sun, 19 Apr 2026 21:33:03 +0000 (+0200) Subject: mistral vibe X-Git-Url: https://git.nothing2do.fr/?a=commitdiff_plain;h=0fdbdb5d3499014e18346c1a5141e8c4ef4d447e;p=diary-web.git mistral vibe --- diff --git a/include/Database.php b/include/Database.php index e026072..e63c0e3 100644 --- a/include/Database.php +++ b/include/Database.php @@ -1,35 +1,25 @@ host = 'localhost'; - $this->db_name = 'ton_nom_de_base'; - $this->username = 'ton_utilisateur'; - $this->password = 'ton_mot_de_passe'; + $this->conn = null; } public function connect() { - $this->conn = null; - + // Include configuration + require_once __DIR__ . '/../config/config.php'; + try { - $dsn = "pgsql:host={$this->host};dbname={$this->db_name}"; - $this->conn = new PDO($dsn, $this->username, $this->password); - $this->conn->exec("set names utf8"); - $this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); - } catch(PDOException $exception) { + // Use the global $db connection from config.php + global $db; + return $db; + } catch(Exception $exception) { echo "Erreur de connexion à la base de données : " . $exception->getMessage(); exit; } - - return $this->conn; } } ?> diff --git a/include/WebAuthnManager.php b/include/WebAuthnManager.php index 8c46dce..3db0d5b 100644 --- a/include/WebAuthnManager.php +++ b/include/WebAuthnManager.php @@ -1,5 +1,5 @@ rpName = "Mon Application"; - $this->rpId = parse_url($_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'], PHP_URL_HOST); - $this->origin = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST']; + $this->rpName = WEBAUTHN_RP_NAME; + $this->rpId = WEBAUTHN_RP_ID; + $this->origin = WEBAUTHN_ORIGIN; + } + + public function getRpName() { + return $this->rpName; + } + + public function getRpId() { + return $this->rpId; + } + + public function getOrigin() { + return $this->origin; } public function generateRegistrationOptions($username) { + $rpEntity = new PublicKeyCredentialRpEntity($this->rpName, $this->rpId); $userEntity = new PublicKeyCredentialUserEntity( $username, - random_bytes(16), + $username, $username ); $challenge = random_bytes(32); $_SESSION['challenge'] = base64_encode($challenge); + $_SESSION['username'] = $username; - return PublicKeyCredentialCreationOptions::create( - $this->rpName, + $creationOptions = PublicKeyCredentialCreationOptions::create( + $rpEntity, $userEntity, $challenge, - [new PublicKeyCredentialDescriptor('public-key', AuthenticatorSelectionCriteria::AUTHENTICATOR_ATTACHMENT_NO_PREFERENCE)] + [] + ); + + $creationOptions->authenticatorSelection = new AuthenticatorSelectionCriteria( + AuthenticatorSelectionCriteria::AUTHENTICATOR_ATTACHMENT_NO_PREFERENCE, + false, + AuthenticatorSelectionCriteria::USER_VERIFICATION_REQUIREMENT_PREFERRED ); + + return $creationOptions; } - public function register($attestationResponse, $username) { - if (!isset($_SESSION['challenge'])) { + public function register($attestationResponse) { + if (!isset($_SESSION['challenge']) || !isset($_SESSION['username'])) { return false; } $challenge = base64_decode($_SESSION['challenge']); + $username = $_SESSION['username']; unset($_SESSION['challenge']); - - $publicKeyCredentialSource = PublicKeyCredentialSource::createFromString($attestationResponse); - $publicKeyCredential = $publicKeyCredentialSource->getPublicKeyCredential(); - - if (!$publicKeyCredential->verify($challenge, $this->origin)) { + unset($_SESSION['username']); + + try { + $publicKeyCredentialSource = PublicKeyCredentialSource::createFromString($attestationResponse); + $publicKeyCredential = $publicKeyCredentialSource->getPublicKeyCredential(); + + if (!$publicKeyCredential->verify($challenge, $this->origin)) { + return false; + } + + return [ + 'credentialId' => base64_encode($publicKeyCredentialSource->getPublicKeyCredentialId()), + 'publicKey' => base64_encode($publicKeyCredentialSource->getPublicKey()), + 'counter' => $publicKeyCredentialSource->getCounter() + ]; + } catch (Exception $e) { + error_log("WebAuthn registration error: " . $e->getMessage()); return false; } - - return [ - 'credentialId' => base64_encode($publicKeyCredential->getId()), - 'publicKey' => base64_encode($publicKeyCredential->getPublicKey()) - ]; } public function generateAuthenticationOptions() { @@ -71,7 +102,9 @@ class WebAuthnManager { $_SESSION['challenge'] = base64_encode($challenge); - return PublicKeyCredentialRequestOptions::create($challenge); + $rpEntity = new PublicKeyCredentialRpEntity($this->rpName, $this->rpId); + + return PublicKeyCredentialRequestOptions::create($rpEntity, $challenge); } public function authenticate($assertionResponse, $storedPublicKey) { @@ -82,14 +115,20 @@ class WebAuthnManager { $challenge = base64_decode($_SESSION['challenge']); unset($_SESSION['challenge']); - $publicKeyCredentialSource = PublicKeyCredentialSource::createFromString($assertionResponse); - $publicKeyCredential = $publicKeyCredentialSource->getPublicKeyCredential(); + try { + $publicKeyCredentialSource = PublicKeyCredentialSource::createFromString($assertionResponse); + $publicKeyCredential = $publicKeyCredentialSource->getPublicKeyCredential(); + + $storedPublicKeyDecoded = base64_decode($storedPublicKey); - if (!$publicKeyCredential->verify($challenge, $this->origin, base64_decode($storedPublicKey))) { + if (!$publicKeyCredential->verify($challenge, $this->origin, $storedPublicKeyDecoded)) { + return false; + } + + return true; + } catch (Exception $e) { + error_log("WebAuthn authentication error: " . $e->getMessage()); return false; } - - return true; } -} -?> +} \ No newline at end of file diff --git a/public/index.php b/public/index.php index 9d2297b..1f4686f 100644 --- a/public/index.php +++ b/public/index.php @@ -1,8 +1,8 @@ createTriplet($_SESSION['user_id'], $label, $keyword, $action); + $_SESSION['status'] = "Triplet créé avec succès!"; + } else { + $_SESSION['status'] = "Tous les champs sont requis!"; + } + + header("Location: index.php"); + exit(); +} + +// Gestion de la mise à jour de triplet +if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['update_triplet'])) { + $tripletId = intval($_POST['triplet_id']); + $label = trim($_POST['label']); + $keyword = trim($_POST['keyword']); + $action = trim($_POST['action']); + + if (!empty($label) && !empty($keyword) && !empty($action)) { + $tripletManager->updateTriplet($tripletId, $label, $keyword, $action); + $_SESSION['status'] = "Triplet mis à jour avec succès!"; + } else { + $_SESSION['status'] = "Tous les champs sont requis!"; + } + + header("Location: index.php"); + exit(); +} + +// Gestion de la suppression de triplet +if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['delete_triplet'])) { + $tripletId = intval($_POST['triplet_id']); + $tripletManager->deleteTriplet($tripletId); + $_SESSION['status'] = "Triplet supprimé avec succès!"; + + header("Location: index.php"); + exit(); } // Récupération des triplets de l'utilisateur @@ -99,6 +177,26 @@ if (empty($triplets)) { border-radius: 5px; box-shadow: 0 2px 5px rgba(0,0,0,0.1); } + .triplet-actions { + margin-top: 10px; + padding-top: 10px; + border-top: 1px solid #eee; + } + .triplet-actions button { + padding: 5px 10px; + margin-left: 5px; + } + form div { + margin-bottom: 10px; + } + form label { + display: inline-block; + width: 80px; + } + form input[type="text"] { + padding: 5px; + width: 200px; + } .triplet h3 { margin-top: 0; } @@ -126,23 +224,129 @@ if (empty($triplets)) {
- +
+ + + '; + echo '

Créer un nouveau triplet

'; + echo '
'; + echo '
'; + echo '
'; + echo '
'; + echo ''; + echo ''; + echo '
'; + echo ''; + break; + + case 'input': + $helpText = $_SESSION['input_help'] ?? ''; + unset($_SESSION['input_help']); + echo '
'; + echo '

Entrée de texte

'; + if ($helpText) { + echo '

' . htmlspecialchars($helpText) . '

'; + } + echo '
'; + echo '
'; + echo ''; + echo ''; + echo '
'; + echo '
'; + break; + + case 'box': + $boxText = $_SESSION['box_text'] ?? ''; + unset($_SESSION['box_text']); + echo '
'; + echo '

Boîte de dialogue

'; + echo '

' . htmlspecialchars($boxText) . '

'; + echo ''; + echo '
'; + break; + + case 'edit': + $tripletId = $_SESSION['edit_id'] ?? 0; + unset($_SESSION['edit_id']); + $tripletToEdit = null; + foreach ($triplets as $triplet) { + if ($triplet['triplet_id'] == $tripletId) { + $tripletToEdit = $triplet; + break; + } + } + + if ($tripletToEdit): + echo '
'; + echo '

Modifier le triplet

'; + echo '
'; + echo ''; + echo '
'; + echo '
'; + echo '
'; + echo ''; + echo ''; + echo '
'; + echo '
'; + else: + echo '

Triplet non trouvé.

'; + endif; + break; + + case 'configuration': + echo '
'; + echo '

Configuration

'; + echo '

Page de configuration (à implémenter)

'; + echo ''; + echo '
'; + break; + } + ?> + +

Vos Triplets

- -
-

-

Mot-clé :

-

Action :

-
- - - -
-
- + Résultats de recherche pour: ' . htmlspecialchars($_SESSION['search_keyword']) . '

'; + unset($_SESSION['search_keyword']); + endif; + ?> + + +

Aucun triplet trouvé. Créez un nouveau triplet avec l'action "new".

+ + +
+

+

Mot-clé :

+

Action :

+
+
+ + +
+
+ + +
+
+
+ +
@@ -151,8 +355,9 @@ if (empty($triplets)) { -

Exemples d'actions : "new", "input text", "box texte", "set name", "choose keyw", "edit ID", "configuration"

+

Exemples d'actions : "new", "input texte", "box texte", "set name", "choose motcle", "edit ID", "configuration", ou un mot-clé pour rechercher

+