Files
2026-03-11 10:14:26 -04:00

37 lines
1.1 KiB
PHP
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env php
<?php
/**
* portspoof_concentrator fetch cron
*
* Polls every enabled portspoof_py node's JSON API and ingests new connections.
* Must be run from the command line — exits immediately if called over HTTP.
*
* Recommended crontab entry (every minute):
* * * * * * /usr/bin/php /path/to/portspoof_concentrator/cron/fetch.php >> /var/log/portspoof_concentrator/fetch.log 2>&1
*/
if (PHP_SAPI !== 'cli') {
http_response_code(403);
exit;
}
require_once __DIR__ . '/../includes/functions.php';
$nodes = get_all_nodes();
$enabled = array_filter($nodes, fn($n) => (bool)$n['enabled']);
if (empty($enabled)) {
echo date('[Y-m-d H:i:s]') . " No enabled nodes configured.\n";
exit(0);
}
foreach (run_fetch() as $r) {
$label = sprintf('[%s] node #%d (%s)', date('Y-m-d H:i:s'), $r['node_id'], $r['name']);
if ($r['error']) {
echo "$label ERROR: {$r['error']}\n";
} else {
echo "$label fetched={$r['fetched']} inserted={$r['inserted']}"
. " last_event_at=" . ($r['last_event_at'] ?? 'none') . "\n";
}
}