#!/usr/bin/env php */ require_once __DIR__ . '/../lib/CryptoService.php'; require_once __DIR__ . '/../lib/DatabaseConnection.php'; require_once __DIR__ . '/../lib/helpers.php'; // Vérifier les arguments if ($argc < 3) { error("Usage: " . basename($argv[0]) . " "); error("Exemple: " . basename($argv[0]) . " dva 5"); exit(1); } $environment = strtoupper($argv[1]); $entiteId = (int)$argv[2]; try { // Ouvrir le tunnel SSH si nécessaire $tunnelScript = __DIR__ . '/_ssh-tunnel.sh'; exec("$tunnelScript open $environment 2>&1", $output, $exitCode); if ($exitCode !== 0) { error("Impossible d'ouvrir le tunnel SSH"); exit(1); } // Connexion à la base de données $db = new DatabaseConnection($environment); $pdo = $db->connect(); info("Environnement: $environment"); info("Recherche de l'entité #$entiteId...\n"); // Requête pour récupérer l'entité $stmt = $pdo->prepare(" SELECT e.*, COUNT(DISTINCT u.id) as nb_users, COUNT(DISTINCT o.id) as nb_operations FROM entites e LEFT JOIN users u ON u.fk_entite = e.id LEFT JOIN operations o ON o.fk_entite = e.id WHERE e.id = :entite_id GROUP BY e.id "); $stmt->execute(['entite_id' => $entiteId]); $entite = $stmt->fetch(); if (!$entite) { error("Entité #$entiteId introuvable"); exit(1); } // Déchiffrer les données $config = DatabaseConfig::getInstance(); $crypto = new CryptoService($config->getEncryptionKey()); $entite['name'] = $crypto->decryptWithIV($entite['encrypted_name']); $entite['email'] = $crypto->decryptSearchable($entite['encrypted_email']); $entite['phone'] = $crypto->decryptWithIV($entite['encrypted_phone']); $entite['mobile'] = $crypto->decryptWithIV($entite['encrypted_mobile']); $entite['iban'] = $crypto->decryptWithIV($entite['encrypted_iban']); $entite['bic'] = $crypto->decryptWithIV($entite['encrypted_bic']); // Affichage title("ENTITÉ (AMICALE) #" . $entite['id']); echo color("Identité\n", 'bold'); display("Nom", $entite['name']); display("Email", $entite['email']); display("Téléphone", $entite['phone']); display("Mobile", $entite['mobile']); echo "\n" . color("Adresse\n", 'bold'); display("Adresse 1", $entite['adresse1'] ?: '-'); display("Adresse 2", $entite['adresse2'] ?: '-'); display("Code postal", $entite['code_postal'] ?: '-'); display("Ville", $entite['ville'] ?: '-'); echo "\n" . color("Coordonnées bancaires\n", 'bold'); display("IBAN", $entite['iban'] ?: '-'); display("BIC", $entite['bic'] ?: '-'); echo "\n" . color("Configuration\n", 'bold'); display("Stripe activé", $entite['chk_stripe'] ? 'Oui' : 'Non'); display("Gestion MDP manuelle", $entite['chk_mdp_manuel'] ? 'Oui' : 'Non'); display("Gestion username manuelle", $entite['chk_username_manuel'] ? 'Oui' : 'Non'); display("Copie mail reçu", $entite['chk_copie_mail_recu'] ? 'Oui' : 'Non'); display("Accepte SMS", $entite['chk_accept_sms'] ? 'Oui' : 'Non'); echo "\n" . color("Statistiques\n", 'bold'); display("Nombre d'utilisateurs", (string)$entite['nb_users']); display("Nombre d'opérations", (string)$entite['nb_operations']); echo "\n" . color("Dates\n", 'bold'); display("Date création", formatDate($entite['created_at'])); display("Dernière modif", formatDate($entite['updated_at'])); echo "\n"; success("Entité déchiffrée avec succès"); } catch (Exception $e) { error("Erreur: " . $e->getMessage()); exit(1); }