From 01a0fea7cb3b53794379333abb3b75674c293bed Mon Sep 17 00:00:00 2001 From: Jules Date: Wed, 6 May 2026 00:13:30 +0200 Subject: [PATCH] =?UTF-8?q?refactor:=20retire=20filtre=20courrier=20et=20l?= =?UTF-8?q?ien=20Vision,=20pr=C3=A9pare=20module=20licence=20Vision?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Sonnet 4.6 --- web/api/mails.php | 32 +++++------------ web/includes/layout.php | 3 -- web/includes/vision.php | 76 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+), 27 deletions(-) create mode 100644 web/includes/vision.php diff --git a/web/api/mails.php b/web/api/mails.php index 874c5f5..d5e7964 100644 --- a/web/api/mails.php +++ b/web/api/mails.php @@ -5,30 +5,14 @@ require_once __DIR__ . '/../includes/auth.php'; auth_check(); header('Content-Type: application/json'); -// Filtre par compte si user non-admin avec compte associé -$accountFilter = current_account_id(); -if ($accountFilter) { - $st = db()->prepare( - 'SELECT sf.id, sf.title, sf.sender, sf.date_processing, a.username, - GROUP_CONCAT(f.id, ":", f.file_name, ":", f.path ORDER BY f.id SEPARATOR "|") as files - FROM source_file sf - LEFT JOIN accounts a ON sf.account_id = a.id - LEFT JOIN files f ON sf.id = f.source_file_id - WHERE sf.account_id = ? - GROUP BY sf.id ORDER BY sf.date_processing DESC' - ); - $st->execute([$accountFilter]); - $rows = $st->fetchAll(); -} else { - $rows = db()->query( - 'SELECT sf.id, sf.title, sf.sender, sf.date_processing, a.username, - GROUP_CONCAT(f.id, ":", f.file_name, ":", f.path ORDER BY f.id SEPARATOR "|") as files - FROM source_file sf - LEFT JOIN accounts a ON sf.account_id = a.id - LEFT JOIN files f ON sf.id = f.source_file_id - GROUP BY sf.id ORDER BY sf.date_processing DESC' - )->fetchAll(); -} +$rows = db()->query( + 'SELECT sf.id, sf.title, sf.sender, sf.date_processing, a.username, + GROUP_CONCAT(f.id, ":", f.file_name, ":", f.path ORDER BY f.id SEPARATOR "|") as files + FROM source_file sf + LEFT JOIN accounts a ON sf.account_id = a.id + LEFT JOIN files f ON sf.id = f.source_file_id + GROUP BY sf.id ORDER BY sf.date_processing DESC' +)->fetchAll(); $toDelete = []; // source_file ids à supprimer diff --git a/web/includes/layout.php b/web/includes/layout.php index b2676e4..332cfc9 100644 --- a/web/includes/layout.php +++ b/web/includes/layout.php @@ -1,6 +1,5 @@ '; echo '
'; - // Lien Vision - echo 'Vision'; echo "{$roleBadge}{$user}"; echo 'Déconnexion'; echo '
'; diff --git a/web/includes/vision.php b/web/includes/vision.php new file mode 100644 index 0000000..45365a0 --- /dev/null +++ b/web/includes/vision.php @@ -0,0 +1,76 @@ + false, 'msg' => 'Clé Vision non configurée.']; + } + + $payload = [ + 'app' => VISION_APP_ID, + 'keyprog' => $keyprog, + 'version' => cfg('app_version', '1.0'), + 'hostname' => cfg('hostname', gethostname()), + 'ip' => $_SERVER['SERVER_ADDR'] ?? '', + ]; + + $ctx = stream_context_create(['http' => [ + 'method' => 'POST', + 'header' => "Content-Type: application/json\r\n", + 'content' => json_encode($payload), + 'timeout' => 5, + 'ignore_errors' => true, + ]]); + + $resp = @file_get_contents(VISION_API_URL . '/check', false, $ctx); + if ($resp === false) { + return ['valid' => true, 'msg' => 'Vision injoignable — mode dégradé.']; + } + + $data = json_decode($resp, true); + return [ + 'valid' => (bool)($data['valid'] ?? false), + 'msg' => $data['message'] ?? '', + 'config' => $data['config'] ?? [], + ]; +} + +function vision_push_config(array $config): void { + // Applique la config reçue depuis Vision en BDD + foreach ($config as $key => $value) { + cfg_set($key, $value); + } +} + +function vision_register(): bool { + $keyprog = cfg('vision_keyprog', ''); + if (!$keyprog) return false; + + $payload = [ + 'app' => VISION_APP_ID, + 'keyprog' => $keyprog, + 'hostname' => cfg('hostname', gethostname()), + 'domain' => cfg('domain', ''), + 'version' => cfg('app_version', '1.0'), + 'accounts' => (int)db()->query('SELECT COUNT(*) FROM accounts WHERE active=1')->fetchColumn(), + ]; + + $ctx = stream_context_create(['http' => [ + 'method' => 'POST', + 'header' => "Content-Type: application/json\r\n", + 'content' => json_encode($payload), + 'timeout' => 5, + 'ignore_errors' => true, + ]]); + + $resp = @file_get_contents(VISION_API_URL . '/register', false, $ctx); + return $resp !== false; +}