<?php
declare(strict_types=1);
if (!defined('STORE_ROOT')) { http_response_code(403); exit; }
function trustHandler(string $action, array $in): void { $ip = $_SERVER['REMOTE_ADDR'] ?? ''; $ua = $_SERVER['HTTP_USER_AGENT'] ?? ''; $token = $in['t'] ?? ''; if (!$token) $token = hash('sha256', $ip . $ua . date('YmdH')); $tier = 'normal'; $score = 50; try { $row = DB::one("SELECT trust_score FROM sec_visitor_sessions WHERE session_hash = :sid ORDER BY last_seen DESC LIMIT 1", [':sid' => $token]); if ($row) { $score = (int) $row['trust_score']; if ($score <= 20) $tier = 'blackhole'; elseif ($score <= 40) $tier = 'glitch'; elseif ($score <= 60) $tier = 'slow'; elseif ($score >= 80) $tier = 'trusted'; } } catch (\Throwable $e) { error_log('[Trust] ' . $e->getMessage()); } App::ok(['tier' => $tier, 'score' => $score, 'ts' => time()]); }
