filemtime($b) <=> filemtime($a)); $lastLog = $lastLogs[0]; $profile = preg_replace('/^rsync_(.+)\.last\.log$/', '$1', basename($lastLog)); $lines = file($lastLog, FILE_IGNORE_NEW_LINES) ?: []; } } // Strip ANSI escape codes, keep last 200 lines $lines = array_map(fn($l) => preg_replace('/\x1b\[[0-9;]*[mGKHF]/', '', $l), $lines); $lines = array_slice($lines, -200); echo json_encode(['ok' => true, 'live' => $live, 'profile' => $profile, 'elapsed' => $elapsed, 'lines' => array_values($lines)]); exit; } $base = vv_rsync_status(); $vars = vv_conf_vars(); $base['windows']['fallback'] = ($vars['FALLBACK_RSYNC_ENABLED'] ?? 'true') !== 'false'; $base['windows']['monthly'] = ($vars['MONTHLY_RSYNC_ENABLED'] ?? 'true') !== 'false'; // Bandwidth history — last 30 days $bwLog = DATA_DIR . '/bandwidth_history.db'; $warnGb = (float)($vars['BANDWIDTH_WARN_GB'] ?? 50); $cutoff = date('Y-m-d', strtotime('-30 days')); $history = []; if (file_exists($bwLog)) { foreach (file($bwLog, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) ?: [] as $line) { $p = explode('|', $line); if (count($p) < 5) continue; if ($p[0] < $cutoff) continue; $history[] = [ 'date' => $p[0], 'time' => $p[1], 'profile' => $p[2], 'duration' => (int)$p[3], 'status' => trim($p[4]), 'bytes' => isset($p[5]) ? (int)$p[5] : 0, ]; } } // Per-window orch arrays (scripts + sync shares) $masterRaw = vv_read_conf_raw('master.conf'); $myId = strtoupper(vv_detect_host()); $hostRaw = vv_read_conf_raw(vv_detect_host() . '.conf'); $winArrayDefs = [ 'critical' => ['CRITICAL_MAINTENANCE_SCRIPTS', "{$myId}_CRITICAL_SYNC_SHARES"], 'intermediate' => ['INTERMEDIATE_MAINTENANCE_SCRIPTS', "{$myId}_INTERMEDIATE_SYNC_SHARES"], 'daily' => ['DAILY_MAINTENANCE_SCRIPTS', "{$myId}_DAILY_SYNC_SHARES"], 'weekly' => ['WEEKLY_MAINTENANCE_SCRIPTS', "{$myId}_WEEKLY_SYNC_SHARES"], // monthly_maintenance.sh has no rsync section (ZFS scrub/SMART tests only) — no shares var exists. 'monthly' => ['MONTHLY_MAINTENANCE_SCRIPTS', null], 'fallback' => [null, null], ]; $winArrays = []; foreach ($winArrayDefs as $win => [$sv, $shv]) { $winArrays[$win] = [ 'scripts' => $sv ? vv_parse_bash_array($masterRaw, $sv) : [], 'shares' => $shv ? vv_parse_bash_array($hostRaw, $shv) : [], ]; } echo json_encode([ 'enabled' => $base['enabled'], 'windows' => $base['windows'], 'active' => $base['active'], 'last_sync' => $base['last_sync'], 'bw_history' => $history, 'bw_warn_gb' => $warnGb, 'win_arrays' => $winArrays, 'settings' => [ 'bw_limit' => (int)($vars['BW_LIMIT'] ?? 0), 'retry_count' => (int)($vars['RETRY_COUNT'] ?? 3), 'sleep' => (int)($vars['SLEEP'] ?? 300), 'bw_warn_gb' => (float)($vars['BANDWIDTH_WARN_GB'] ?? 50), ], 'ts' => time(), ]);