Files
wevads-platform/scripts/console-history.php
2026-02-26 04:53:11 +01:00

112 lines
4.2 KiB
PHP
Executable File

<?php
$logFile = '/opt/wevads/storage/office365/console_history.log';
// API pour ajouter des logs
if($_SERVER['REQUEST_METHOD'] === 'POST') {
header('Content-Type: application/json');
$msg = $_POST['message'] ?? '';
$type = $_POST['type'] ?? 'info';
if($msg) {
$line = date('Y-m-d H:i:s') . " [$type] $msg\n";
file_put_contents($logFile, $line, FILE_APPEND);
echo json_encode(['success' => true]);
}
exit;
}
// API pour récupérer les logs
if(isset($_GET['api'])) {
header('Content-Type: application/json');
$lines = file_exists($logFile) ? file($logFile, FILE_IGNORE_NEW_LINES) : [];
$last = intval($_GET['last'] ?? 100);
echo json_encode(['logs' => array_slice($lines, -$last)]);
exit;
}
// API pour effacer
if(isset($_GET['clear'])) {
file_put_contents($logFile, '');
header('Location: console-history.php');
exit;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Console History</title>
<style>
body { background: #0f172a; color: #e2e8f0; font-family: monospace; margin: 0; padding: 20px; }
h1 { color: #22d3ee; margin-bottom: 20px; }
.toolbar { margin-bottom: 15px; }
.btn { padding: 10px 20px; background: #3b82f6; color: white; border: none; border-radius: 8px; cursor: pointer; margin-right: 10px; }
.btn:hover { background: #2563eb; }
.btn.danger { background: #ef4444; }
#console { background: #1e293b; padding: 20px; border-radius: 12px; height: 70vh; overflow-y: auto; font-size: 13px; line-height: 1.8; }
.info { color: #60a5fa; }
.success { color: #34d399; }
.error { color: #f87171; }
.warning { color: #fbbf24; }
.time { color: #a78bfa; font-weight: bold; }
</style>
</head>
<body>
<h1>📜 Console History</h1>
<div class="toolbar">
<button class="btn" onclick="refresh()">🔄 Refresh</button>
<button class="btn" onclick="toggleAuto()">⏱ Auto-refresh: <span id="autoStatus">OFF</span></button>
<button class="btn danger" onclick="clearLogs()">🗑 Clear</button>
<a href="office-workflow.php" class="btn" style="text-decoration:none;display:inline-block">← Retour Workflow</a>
</div>
<div id="console"></div>
<script>
let autoRefresh = null;
function refresh() {
fetch('?api=1&last=500')
.then(r => r.json())
.then(d => {
let html = '';
d.logs.forEach(line => {
let cls = 'info';
if(line.includes('[success]')) cls = 'success';
else if(line.includes('[error]')) cls = 'error';
else if(line.includes('[warning]')) cls = 'warning';
// Format: date [type] message
let parts = line.match(/^(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}) \[(\w+)\] (.*)$/);
if(parts) {
html += '<div><span class="time">[' + parts[1] + ']</span> <span class="' + cls + '">' + parts[3] + '</span></div>';
} else {
html += '<div class="' + cls + '">' + line + '</div>';
}
});
document.getElementById('console').innerHTML = html || '<div style="color:#64748b">Aucun log</div>';
document.getElementById('console').scrollTop = document.getElementById('console').scrollHeight;
});
}
function toggleAuto() {
if(autoRefresh) {
clearInterval(autoRefresh);
autoRefresh = null;
document.getElementById('autoStatus').textContent = 'OFF';
} else {
autoRefresh = setInterval(refresh, 2000);
document.getElementById('autoStatus').textContent = 'ON';
}
}
function clearLogs() {
if(confirm('Effacer tout l\'historique?')) {
window.location = '?clear=1';
}
}
refresh();
</script>
<?php include("includes/chatbot-widget.php"); ?>
</body>
</html>