"; print "".WEB_auth_unknown.""; require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.simple.php"); exit; } // === 2. Преобразуем IP в BIGINT (беззнаковый) === $ip_long = sprintf('%u', ip2long($auth_ip)); // === 3. Находим авторизацию и пользователя за один JOIN === $sql = " SELECT ul.id AS user_id, ul.login, ul.description, ul.enabled AS user_enabled, ul.blocked AS user_blocked, ul.month_quota, ul.day_quota, ul.filter_group_id, ul.queue_id, ua.id AS auth_id, ua.ip_int, ua.enabled AS auth_enabled, ua.blocked AS auth_blocked, ua.month_quota AS auth_month_quota, ua.day_quota AS auth_day_quota FROM user_auth ua JOIN user_list ul ON ua.user_id = ul.id WHERE ua.ip_int = ? AND ua.deleted = 0 AND ul.deleted = 0 "; $record = get_record_sql($db_link, $sql, [$ip_long]); if (!$record) { print "
"; print "".WEB_cell_ip . " " . htmlspecialchars($auth_ip, ENT_QUOTES) . "  - " . WEB_unknown . "!"; require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.simple.php"); exit; } // === 4. Подготавливаем данные === $auth_id = $record['auth_id']; $user_id = $record['user_id']; $KB = get_const('KB') ? 1024 : 1000; // Квоты пользователя $user_month_quota = ($record['month_quota'] ?? 0) * $KB * $KB; $user_day_quota = ($record['day_quota'] ?? 0) * $KB * $KB; // Квоты IP (auth) $auth_month_quota = ($record['auth_month_quota'] ?? $record['month_quota'] ?? 0) * $KB * $KB; $auth_day_quota = ($record['auth_day_quota'] ?? $record['day_quota'] ?? 0) * $KB * $KB; // === 5. Вычисляем временные границы === $now = new DateTime(); $date1 = $now->format('Y-m-d 00:00:00'); $date2 = $now->format('Y-m-d 23:59:59'); $date1m = $now->format('Y-m-01 00:00:00'); $date2m = (clone $now)->modify('last day of this month')->format('Y-m-d 23:59:59'); // === 6. Получаем трафик за день и месяц === $day_traffic = get_record_sql($db_link, " SELECT SUM(CASE WHEN ua.id = ? THEN us.byte_in ELSE 0 END) AS auth_in, SUM(CASE WHEN ua.id = ? THEN us.byte_out ELSE 0 END) AS auth_out, SUM(us.byte_in) AS user_in, SUM(us.byte_out) AS user_out FROM user_stats us JOIN user_auth ua ON us.auth_id = ua.id WHERE us.ts >= ? AND us.ts < ? AND ua.user_id = ? AND ua.deleted = 0 ", [$auth_id, $auth_id, $date1, $date2, $user_id]); $month_traffic = get_record_sql($db_link, " SELECT SUM(CASE WHEN ua.id = ? THEN us.byte_in ELSE 0 END) AS auth_in, SUM(CASE WHEN ua.id = ? THEN us.byte_out ELSE 0 END) AS auth_out, SUM(us.byte_in) AS user_in, SUM(us.byte_out) AS user_out FROM user_stats us JOIN user_auth ua ON us.auth_id = ua.id WHERE us.ts >= ? AND us.ts < ? AND ua.user_id = ? AND ua.deleted = 0 ", [$auth_id, $auth_id, $date1m, $date2m, $user_id]); $day_auth_sum_in = $day_traffic['auth_in'] ?? 0; $day_auth_sum_out = $day_traffic['auth_out'] ?? 0; $day_user_sum_in = $day_traffic['user_in'] ?? 0; $day_user_sum_out = $day_traffic['user_out'] ?? 0; $month_auth_sum_in = $month_traffic['auth_in'] ?? 0; $month_auth_sum_out = $month_traffic['auth_out'] ?? 0; $month_user_sum_in = $month_traffic['user_in'] ?? 0; $month_user_sum_out = $month_traffic['user_out'] ?? 0; ?>
' . WEB_msg_disabled . ' '; } if ($record['user_blocked']) { echo '' . WEB_msg_traffic_blocked . ''; } } ?>
' . WEB_msg_disabled . ' '; } elseif (!$record['auth_enabled']) { echo '' . WEB_msg_disabled . ' '; } if ($record['auth_blocked']) { echo '' . WEB_msg_traffic_blocked . ''; } } ?>