add new featurs like realtime 2026-5-10-18
This commit is contained in:
@@ -1,26 +1,31 @@
|
|||||||
<?php
|
<?php
|
||||||
// Admin/v2/security/audit_logs.php
|
// Admin/v2/security/audit_logs.php
|
||||||
require_once __DIR__ . '/../../../connect.php';
|
|
||||||
|
|
||||||
// ── سجل تتبع لفحص كل ما يحدث ─────────────────────────
|
// ── سجل تتبع فوري — يكتب قبل أي شيء آخر ────────────────
|
||||||
$debugFile = __DIR__ . '/fetch_debug.txt';
|
$debugFile = __DIR__ . '/fetch_debug.txt';
|
||||||
$debugLog = "[" . date('Y-m-d H:i:s') . "] ";
|
file_put_contents($debugFile, "[" . date('Y-m-d H:i:s') . "] === REQUEST START ===\n", FILE_APPEND);
|
||||||
$debugLog .= "user_id=$user_id | role=$role | method={$_SERVER['REQUEST_METHOD']}";
|
|
||||||
file_put_contents($debugFile, $debugLog . "\n", FILE_APPEND);
|
try {
|
||||||
|
require_once __DIR__ . '/../../../connect.php';
|
||||||
|
file_put_contents($debugFile, " → connect.php loaded. user_id=$user_id | role=$role\n", FILE_APPEND);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
file_put_contents($debugFile, " → connect.php FAILED: " . $e->getMessage() . "\n", FILE_APPEND);
|
||||||
|
http_response_code(500);
|
||||||
|
echo json_encode(['status' => 'failure', 'message' => 'connect failed: ' . $e->getMessage()]);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
// ── فحص الصلاحيات ────────────────────────────────────────
|
// ── فحص الصلاحيات ────────────────────────────────────────
|
||||||
if ($role !== 'super_admin' && $role !== 'admin') {
|
if ($role !== 'super_admin' && $role !== 'admin') {
|
||||||
$msg = "Unauthorized. role=$role, user_id=$user_id";
|
file_put_contents($debugFile, " → BLOCKED: role=$role\n", FILE_APPEND);
|
||||||
file_put_contents($debugFile, " → BLOCKED: $msg\n", FILE_APPEND);
|
jsonError("Unauthorized. role=$role", 403);
|
||||||
jsonError($msg, 403);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
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 admin_audit_log 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,7 +46,7 @@ try {
|
|||||||
jsonSuccess($logs);
|
jsonSuccess($logs);
|
||||||
|
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
file_put_contents($debugFile, " → ERROR: " . $e->getMessage() . "\n", FILE_APPEND);
|
file_put_contents($debugFile, " → QUERY ERROR: " . $e->getMessage() . "\n", FILE_APPEND);
|
||||||
jsonError('Audit log query failed: ' . $e->getMessage(), 500);
|
jsonError('Query failed: ' . $e->getMessage(), 500);
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|||||||
Reference in New Issue
Block a user