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:
@@ -1,6 +1,5 @@
|
||||
<?php
|
||||
|
||||
define('VISION_URL', 'http://192.168.111.212');
|
||||
|
||||
function html_head(string $title): void {
|
||||
$domain = cfg('domain', 'copymail');
|
||||
@@ -48,8 +47,6 @@ function html_navbar(string $active = ''): void {
|
||||
}
|
||||
echo '</ul>';
|
||||
echo '<div class="d-flex align-items-center gap-2">';
|
||||
// Lien Vision
|
||||
echo '<a class="btn btn-outline-light btn-sm" href="' . VISION_URL . '" target="_blank" title="Ouvrir Vision"><i class="bi bi-grid-fill me-1"></i>Vision</a>';
|
||||
echo "{$roleBadge}<span class=\"navbar-text me-2\"><i class=\"bi bi-person-circle me-1\"></i>{$user}</span>";
|
||||
echo '<a class="btn btn-outline-light btn-sm" href="/logout.php"><i class="bi bi-box-arrow-right me-1"></i>Déconnexion</a>';
|
||||
echo '</div></div></div></nav>';
|
||||
|
||||
76
web/includes/vision.php
Normal file
76
web/includes/vision.php
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user