2603.18 - frequenet added since parameter
This commit is contained in:
@@ -203,19 +203,32 @@ function set_setting(string $key, string $value): void {
|
||||
/**
|
||||
* Return all IPs with a total connection count >= $min_connections, sorted
|
||||
* highest-count first. Includes first and last seen timestamps.
|
||||
*
|
||||
* @param int $min_connections Minimum number of connections to include.
|
||||
* @param string|null $since Optional ISO datetime; only IPs whose
|
||||
* most-recent connection is >= this value
|
||||
* are returned.
|
||||
*/
|
||||
function frequent_ips(int $min_connections): array {
|
||||
function frequent_ips(int $min_connections, ?string $since = null): array {
|
||||
$having = 'total_connections >= ?';
|
||||
$params = [$min_connections];
|
||||
|
||||
if ($since !== null) {
|
||||
$having .= ' AND last_seen >= ?';
|
||||
$params[] = $since;
|
||||
}
|
||||
|
||||
$s = db()->prepare(
|
||||
'SELECT src_ip,
|
||||
COUNT(*) AS total_connections,
|
||||
COUNT(*) AS total_connections,
|
||||
MIN(occurred_at) AS first_seen,
|
||||
MAX(occurred_at) AS last_seen
|
||||
FROM connections
|
||||
GROUP BY src_ip
|
||||
HAVING total_connections >= ?
|
||||
HAVING ' . $having . '
|
||||
ORDER BY total_connections DESC'
|
||||
);
|
||||
$s->execute([$min_connections]);
|
||||
$s->execute($params);
|
||||
return $s->fetchAll();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user