$value) { if (is_scalar($value) || $value === null) { $safeDetail[(string)$key] = $value; } } $record = [ 'time' => date('c'), 'event' => $event, 'username' => substr($username, 0, 100), 'success' => $success, 'ip' => admin_client_ip(), 'user_agent' => substr($_SERVER['HTTP_USER_AGENT'] ?? '', 0, 255), 'detail' => $safeDetail, ]; @file_put_contents( $dir . '/admin_audit.log', json_encode($record, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . PHP_EOL, FILE_APPEND | LOCK_EX ); } function admin_audit_log_path(): string { return __DIR__ . '/var/admin_audit.log'; } function admin_mfa_configured(): bool { return defined('ADMIN_TOTP_SECRET') && ADMIN_TOTP_SECRET !== ''; }