refactor: retire filtre courrier et lien Vision, prépare module licence Vision

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Jules
2026-05-06 00:13:30 +02:00
parent 3f73421fd3
commit 01a0fea7cb
3 changed files with 84 additions and 27 deletions

76
web/includes/vision.php Normal file
View File

@@ -0,0 +1,76 @@
<?php
/**
* vision.php — Intégration Vision (licence + config)
* CopyMail s'enregistre auprès de Vision et vérifie sa licence.
* À compléter avec l'endpoint et le format exact de l'API Vision.
*/
define('VISION_API_URL', 'https://vision.copydev.fr/api');
define('VISION_APP_ID', 'copymail');
function vision_check(): array {
$keyprog = cfg('vision_keyprog', '');
if (!$keyprog) {
return ['valid' => 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;
}