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:
@@ -5,21 +5,6 @@ require_once __DIR__ . '/../includes/auth.php';
|
|||||||
auth_check();
|
auth_check();
|
||||||
header('Content-Type: application/json');
|
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(
|
$rows = db()->query(
|
||||||
'SELECT sf.id, sf.title, sf.sender, sf.date_processing, a.username,
|
'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
|
GROUP_CONCAT(f.id, ":", f.file_name, ":", f.path ORDER BY f.id SEPARATOR "|") as files
|
||||||
@@ -28,7 +13,6 @@ if ($accountFilter) {
|
|||||||
LEFT JOIN files f ON sf.id = f.source_file_id
|
LEFT JOIN files f ON sf.id = f.source_file_id
|
||||||
GROUP BY sf.id ORDER BY sf.date_processing DESC'
|
GROUP BY sf.id ORDER BY sf.date_processing DESC'
|
||||||
)->fetchAll();
|
)->fetchAll();
|
||||||
}
|
|
||||||
|
|
||||||
$toDelete = []; // source_file ids à supprimer
|
$toDelete = []; // source_file ids à supprimer
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
define('VISION_URL', 'http://192.168.111.212');
|
|
||||||
|
|
||||||
function html_head(string $title): void {
|
function html_head(string $title): void {
|
||||||
$domain = cfg('domain', 'copymail');
|
$domain = cfg('domain', 'copymail');
|
||||||
@@ -48,8 +47,6 @@ function html_navbar(string $active = ''): void {
|
|||||||
}
|
}
|
||||||
echo '</ul>';
|
echo '</ul>';
|
||||||
echo '<div class="d-flex align-items-center gap-2">';
|
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 "{$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 '<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>';
|
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