bump
This commit is contained in:
36
pull.php
36
pull.php
@@ -4,6 +4,7 @@
|
|||||||
// Each run logs itself in the info table using the current timestamp as list value.
|
// Each run logs itself in the info table using the current timestamp as list value.
|
||||||
// Safe to run repeatedly (e.g. via cron) — uses ON DUPLICATE KEY UPDATE.
|
// Safe to run repeatedly (e.g. via cron) — uses ON DUPLICATE KEY UPDATE.
|
||||||
|
|
||||||
|
set_time_limit(0);
|
||||||
date_default_timezone_set("America/Montreal");
|
date_default_timezone_set("America/Montreal");
|
||||||
include('conn.php');
|
include('conn.php');
|
||||||
include('functions.php');
|
include('functions.php');
|
||||||
@@ -59,14 +60,14 @@ if (!isset($data['ips']) || !is_array($data['ips'])) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------
|
// ------------------------------------------------------------------
|
||||||
// 3. Ingest IPs newer than last_pulled
|
// 3. Ingest IPs newer than last_pulled (single bulk query)
|
||||||
// ------------------------------------------------------------------
|
// ------------------------------------------------------------------
|
||||||
$inserted = 0;
|
$skipped = 0;
|
||||||
$updated = 0;
|
$values = [];
|
||||||
$skipped = 0;
|
$reason_safe = mysqli_real_escape_string($con, $reason);
|
||||||
|
|
||||||
foreach ($data['ips'] as $entry) {
|
foreach ($data['ips'] as $entry) {
|
||||||
$src_ip = $entry['src_ip'];
|
$src_ip = $entry['src_ip'];
|
||||||
$last_seen_str = $entry['last_seen'];
|
$last_seen_str = $entry['last_seen'];
|
||||||
|
|
||||||
// last_seen format: "2026-03-14 10:14:37.000000" — strip microseconds
|
// last_seen format: "2026-03-14 10:14:37.000000" — strip microseconds
|
||||||
@@ -82,21 +83,22 @@ foreach ($data['ips'] as $entry) {
|
|||||||
$src_ip .= '/32';
|
$src_ip .= '/32';
|
||||||
}
|
}
|
||||||
|
|
||||||
$ip_safe = mysqli_real_escape_string($con, $src_ip);
|
$ip_safe = mysqli_real_escape_string($con, $src_ip);
|
||||||
$reason_safe = mysqli_real_escape_string($con, $reason);
|
$values[] = "('" . $ip_safe . "', " . $pull_type . ", " . $now . ", " . $enddate . ", '" . $reason_safe . "')";
|
||||||
|
}
|
||||||
|
|
||||||
$SQL = "INSERT INTO blacklist (ip, type, adddate, enddate, reason)"
|
$processed = 0;
|
||||||
. " VALUES ('" . $ip_safe . "', " . $pull_type . ", " . $now . ", " . $enddate . ", '" . $reason_safe . "')"
|
$chunk_size = 100;
|
||||||
|
|
||||||
|
foreach (array_chunk($values, $chunk_size) as $chunk) {
|
||||||
|
$SQL = "INSERT INTO blacklist (ip, type, adddate, enddate, reason) VALUES "
|
||||||
|
. implode(", ", $chunk)
|
||||||
. " ON DUPLICATE KEY UPDATE enddate=" . $enddate . ", type=" . $pull_type . ", reason='" . $reason_safe . "'";
|
. " ON DUPLICATE KEY UPDATE enddate=" . $enddate . ", type=" . $pull_type . ", reason='" . $reason_safe . "'";
|
||||||
|
|
||||||
if ($con->query($SQL) === TRUE) {
|
if ($con->query($SQL) === TRUE) {
|
||||||
if ($con->affected_rows == 1) {
|
$processed += count($chunk);
|
||||||
$inserted++;
|
|
||||||
} else {
|
|
||||||
$updated++;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
echo "Error on " . $src_ip . ": " . $con->error . "\n";
|
echo "Error: " . $con->error . "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,12 +111,12 @@ $SQL_pull = "INSERT INTO info (list, last) VALUES (" . $info_list . ", " . $now
|
|||||||
$con->query($SQL_pull);
|
$con->query($SQL_pull);
|
||||||
|
|
||||||
// Update blacklist last-modified only when rows were actually written
|
// Update blacklist last-modified only when rows were actually written
|
||||||
if ($inserted > 0 || $updated > 0) {
|
if ($processed > 0) {
|
||||||
$SQL_bl = "UPDATE info SET last=" . $now . " WHERE list=0";
|
$SQL_bl = "UPDATE info SET last=" . $now . " WHERE list=0";
|
||||||
$con->query($SQL_bl);
|
$con->query($SQL_bl);
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "Done. Inserted: " . $inserted . ", Updated: " . $updated . ", Skipped: " . $skipped . "\n";
|
echo "Done. Processed: " . $processed . ", Skipped: " . $skipped . "\n";
|
||||||
|
|
||||||
$con->close();
|
$con->close();
|
||||||
?>
|
?>
|
||||||
|
|||||||
Reference in New Issue
Block a user