From 7f22bb06128ae47e51d8a5c81b797a83d9803679 Mon Sep 17 00:00:00 2001 From: Gmer4Lfe Date: Fri, 14 Aug 2026 19:49:48 -0400 Subject: [PATCH] Run the PHP layer on the host's clock, not UTC MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PHP defaults to UTC on Unraid while every bash script stamps local time, and the two write into the same files — conf_changes.log was four hours out from every log you would correlate it against. The parsing half was worse: vv_ai_syslog_ts() reads local-time syslog lines through strtotime() under UTC, landing every event four hours early, and the repair sweep bounds its scan to "since the last pass" — so a fault that had just happened could read as four hours old and fall outside the window. Also fixes date-string comparisons against bandwidth and cleanup dbs, which bash writes with local dates. --- Plugin/unraid/include/config.php | 33 ++++++++++++++++++++++++++++++++ Plugin/unraid/pages/monitor.php | 4 +++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/Plugin/unraid/include/config.php b/Plugin/unraid/include/config.php index 2f5e939..58596bb 100644 --- a/Plugin/unraid/include/config.php +++ b/Plugin/unraid/include/config.php @@ -111,6 +111,39 @@ define('DEPLOY_DIR', SCRIPTS_DIR . '/Deployment'); // // STATE_DIR moved from SCRIPTS_DIR/State_Files to DATA_DIR/state and kept its name, which is why // the 23 call sites in this layer that build on it needed no edits at all. +// ── The clock this layer runs on ────────────────────────────────────────────────────────────── +// PHP on Unraid defaults to UTC while the host runs local time, and the two halves of Varaverk +// write into the same files. Every bash script stamps its log in local time; every PHP writer — +// the conf audit trail, the AI worker, the repair sweep, api/system.php — stamped UTC. On this +// host that is a four-hour disagreement inside conf_changes.log against every log you would +// correlate it with. +// +// The formatting was the visible half. The damaging half was parsing: vv_ai_syslog_ts() reads +// "Aug 14 19:00:01" out of /var/log/syslog, which the system wrote in local time, and handed it +// to strtotime() under UTC — landing every syslog event four hours earlier than it happened. The +// repair sweep bounds its scan to "since the last pass", so a fault that had just occurred could +// read as four hours old and fall outside the window entirely. It would have found nothing and +// said so honestly. +// +// Same correction fixes the date-string comparisons: bandwidth_history.db and arr_cleanup_stats.db +// are written by bash with local dates and compared against date('Y-m-d') here, which near +// midnight was a day out. +// +// Set from the host rather than hardcoded, and only when PHP has not been told otherwise, so an +// operator who deliberately configures a timezone keeps it. +if (!ini_get('date.timezone') || date_default_timezone_get() === 'UTC') { + $_vv_tz = @readlink('/etc/localtime') ?: ''; + $_vv_p = strpos($_vv_tz, 'zoneinfo/'); + if ($_vv_p !== false) { + $_vv_name = substr($_vv_tz, $_vv_p + 9); + // Validated against the real list — a malformed link must not leave the clock undefined. + if ($_vv_name !== '' && in_array($_vv_name, timezone_identifiers_list(), true)) { + date_default_timezone_set($_vv_name); + } + } + unset($_vv_tz, $_vv_p, $_vv_name); +} + define('DATA_DIR', SCRIPTS_DIR . '/data'); define('DB_DIR', DATA_DIR . '/db'); define('STATE_DIR', DATA_DIR . '/state'); diff --git a/Plugin/unraid/pages/monitor.php b/Plugin/unraid/pages/monitor.php index 50699a5..60e6e74 100644 --- a/Plugin/unraid/pages/monitor.php +++ b/Plugin/unraid/pages/monitor.php @@ -743,7 +743,9 @@ function vvTempColor(tempC, transport) { function vvFmt(v) { return v >= 1000 ? (v / 1000).toFixed(1) + ' TB' : v + ' GB'; } function vvFmtRate(mbs) { - if (mbs >= 1000) return (mbs / 1024).toFixed(1) + ' GB/s'; + // 1024 both sides: the source is MiB/s (common.php divides by 1048576), so the threshold has to + // match the divisor or the unit switches early between 1000 and 1024. + if (mbs >= 1024) return (mbs / 1024).toFixed(1) + ' GB/s'; if (mbs >= 100) return Math.round(mbs) + ' MB/s'; return mbs.toFixed(1) + ' MB/s'; }