<?php if (!defined('DASHBOARD_ROOT')) { http_response_code(403); exit; } class ShadowDatabase { public static function generateFakeRecords(int $count = 100, string $sessionId = ''): array { $records = []; $firstNames = ['James','Mary','Robert','Patricia','John','Jennifer','Michael','Linda','David','Elizabeth']; $lastNames = ['Smith','Johnson','Williams','Brown','Jones','Garcia','Miller','Davis','Rodriguez','Martinez']; $domains = ['example.com','testmail.org','fakeinbox.net','mailtest.ca']; $watermarkBase = $sessionId ?: bin2hex(random_bytes(4)); for ($i = 0; $i < $count; $i++) { $first = $firstNames[array_rand($firstNames)]; $last = $lastNames[array_rand($lastNames)]; $wm = 'w' . substr($watermarkBase, 0, 4) . str_pad((string)$i, 4, '0', STR_PAD_LEFT); $records[] = [ 'id' => 1000 + $i, 'first_name' => $first, 'last_name' => $last, 'email' => strtolower($first . '.' . $last . '.' . $wm . '@' . $domains[array_rand($domains)]), 'city' => ['Toronto','Vancouver','Montreal','Calgary','Ottawa'][array_rand([0,1,2,3,4])], 'province' => ['ON','BC','QC','AB','ON'][array_rand([0,1,2,3,4])], 'created_at' => date('Y-m-d H:i:s', time() - mt_rand(86400, 31536000)), ]; } return $records; } public static function logAccess(string $query, string $ip): void { try { Events::record(Events::CAT_SECURITY, 'shadow.db_access', 'security', null, [ 'ip' => $ip, 'query' => substr($query, 0, 500), ]); AuditLogger::log('shadow.db_access', 'security', null, [ 'ip' => $ip, 'alert' => 'CRITICAL -- attacker accessed decoy database', ]); } catch (\Throwable $e) {} } public static function checkWatermark(string $email): ?array { if (preg_match('/\.w([a-f0-9]{4})(\d{4})@/', $email, $m)) { return ['is_watermarked' => true, 'session_chunk' => $m[1], 'record_index' => (int)$m[2]]; } return null; } public static function status(): array { $count = 0; try { $count = (int)Database::scalar("SELECT COUNT(*) FROM events WHERE action = 'shadow.db_access'"); } catch (\Throwable $e) {} return ['access_attempts' => $count, 'decoy_active' => file_exists('/var/www/config.php.bak')]; } } 