Arrs: remote host cards via SSH cache, vv_arrs_local_node(), 2h refresh schedule

This commit is contained in:
Gmer4Lfe
2026-06-03 18:16:56 -04:00
parent 6c0164713b
commit 2223cf80f7
4 changed files with 245 additions and 23 deletions
+32
View File
@@ -2,6 +2,38 @@
header('Content-Type: application/json');
require_once dirname(__DIR__) . '/include/config.php';
// ── Manual remote refresh — runs remote_arr_cache_writer for one host ─────────
$_action = trim($_GET['action'] ?? '');
if ($_action === 'refresh_remote') {
$host = strtolower(trim($_GET['host'] ?? ''));
if (!preg_match('/^host\d+$/', $host)) {
echo json_encode(['ok' => false, 'error' => 'Invalid host']); exit;
}
$script = SCRIPTS_DIR . '/Tools/remote_arr_cache_writer.sh';
if (!file_exists($script)) {
echo json_encode(['ok' => false, 'error' => 'remote_arr_cache_writer.sh not found']); exit;
}
set_time_limit(30);
$out = []; $exit = 0;
exec('bash ' . escapeshellarg($script) . ' --host=' . escapeshellarg(strtoupper($host)) . ' 2>&1', $out, $exit);
$cacheFile = VV_CACHE_DIR . '/arrs_remote_' . $host . '.json';
$node = null;
if (file_exists($cacheFile)) {
$node = json_decode(file_get_contents($cacheFile), true) ?: null;
if ($node) {
$node['cached'] = true;
$node['cache_age'] = time() - (int)filemtime($cacheFile);
}
}
// Bust the main arrs cache so next poll gets fresh data
@unlink(VV_CACHE_DIR . '/arrs.json');
echo json_encode(['ok' => $exit === 0, 'node' => $node, 'output' => implode("\n", $out)]);
exit;
}
unset($_action);
// ── Normal data load ──────────────────────────────────────────────────────────
$_vv_cached = vv_cache_read('arrs', 90);
if ($_vv_cached !== null) { echo json_encode($_vv_cached); exit; }
unset($_vv_cached);