add new featurs like realtime 2026-5-10-19

This commit is contained in:
Hamza-Ayed
2026-05-10 02:10:17 +03:00
parent c1a97a368f
commit b17787c636

View File

@@ -1,15 +1,18 @@
<?php <?php
// Admin/v2/security/audit_logs.php // Admin/v2/security/audit_logs.php
// ── سجل تتبع فورييكتب قبل أي شيء آخر ──────────────── // ── سجل تتبع — نكتب في مجلد logs لأن مجلد security ممنوع الكتابة فيه
$debugFile = __DIR__ . '/fetch_debug.txt'; $debugFile = __DIR__ . '/../../../logs/audit_debug.txt';
file_put_contents($debugFile, "[" . date('Y-m-d H:i:s') . "] === REQUEST START ===\n", FILE_APPEND); $logDir = dirname($debugFile);
if (!is_dir($logDir)) @mkdir($logDir, 0777, true);
@file_put_contents($debugFile, "[" . date('Y-m-d H:i:s') . "] === REQUEST START ===\n", FILE_APPEND);
try { try {
require_once __DIR__ . '/../../../connect.php'; require_once __DIR__ . '/../../../connect.php';
file_put_contents($debugFile, " → connect.php loaded. user_id=$user_id | role=$role\n", FILE_APPEND); @file_put_contents($debugFile, " → connect.php OK. user_id=$user_id | role=$role\n", FILE_APPEND);
} catch (Exception $e) { } catch (Exception $e) {
file_put_contents($debugFile, " → connect.php FAILED: " . $e->getMessage() . "\n", FILE_APPEND); @file_put_contents($debugFile, " → connect.php FAILED: " . $e->getMessage() . "\n", FILE_APPEND);
http_response_code(500); http_response_code(500);
echo json_encode(['status' => 'failure', 'message' => 'connect failed: ' . $e->getMessage()]); echo json_encode(['status' => 'failure', 'message' => 'connect failed: ' . $e->getMessage()]);
exit; exit;
@@ -17,7 +20,7 @@ try {
// ── فحص الصلاحيات ──────────────────────────────────────── // ── فحص الصلاحيات ────────────────────────────────────────
if ($role !== 'super_admin' && $role !== 'admin') { if ($role !== 'super_admin' && $role !== 'admin') {
file_put_contents($debugFile, " → BLOCKED: role=$role\n", FILE_APPEND); @file_put_contents($debugFile, " → BLOCKED: role=$role\n", FILE_APPEND);
jsonError("Unauthorized. role=$role", 403); jsonError("Unauthorized. role=$role", 403);
} }
@@ -25,7 +28,7 @@ try {
$tableExists = $con->query("SHOW TABLES LIKE 'admin_audit_log'")->rowCount() > 0; $tableExists = $con->query("SHOW TABLES LIKE 'admin_audit_log'")->rowCount() > 0;
if (!$tableExists) { if (!$tableExists) {
file_put_contents($debugFile, " → Table NOT FOUND\n", FILE_APPEND); @file_put_contents($debugFile, " → Table NOT FOUND\n", FILE_APPEND);
jsonSuccess([], 'Audit log table not found'); jsonSuccess([], 'Audit log table not found');
} }
@@ -41,12 +44,12 @@ try {
$logs = $stmt->fetchAll(PDO::FETCH_ASSOC); $logs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$count = count($logs); $count = count($logs);
file_put_contents($debugFile, " → SUCCESS: fetched $count logs\n", FILE_APPEND); @file_put_contents($debugFile, " → SUCCESS: fetched $count logs\n", FILE_APPEND);
jsonSuccess($logs); jsonSuccess($logs);
} catch (Exception $e) { } catch (Exception $e) {
file_put_contents($debugFile, " → QUERY ERROR: " . $e->getMessage() . "\n", FILE_APPEND); @file_put_contents($debugFile, " → QUERY ERROR: " . $e->getMessage() . "\n", FILE_APPEND);
jsonError('Query failed: ' . $e->getMessage(), 500); jsonError('Query failed: ' . $e->getMessage(), 500);
} }
?> ?>