77 lines
2.4 KiB
PHP
77 lines
2.4 KiB
PHP
<?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;
|
|
}
|