Resolve bash variable references in vv_conf_vars()

PHP reads master.conf values like STATE_DIR="${SCRIPTS_DIR}/State_Files"
literally — the ${SCRIPTS_DIR} token is never expanded, so any PHP code
using the returned STATE_DIR value got an invalid path. Two-pass resolution:
SCRIPTS_DIR first (from PHP constant), then remaining ${VAR} tokens using
the now-resolved var set (covers DATA_DIR-based paths like ARR_SYNC_BLOCKLIST).
This commit is contained in:
Gmer4Lfe
2026-06-14 01:46:51 -04:00
parent 181114aed5
commit 420e13a746
+14
View File
@@ -206,6 +206,20 @@ function vv_conf_vars(): array {
$vars[$key] = str_replace('\\$', '$', trim($m[2][$i]));
}
}
// Resolve bash variable references — bash expands ${VAR} at runtime; PHP reads them literally.
// Pass 1: ${SCRIPTS_DIR} from the PHP-computed constant (other vars depend on it).
// Pass 2: ${VAR} using now-resolved values from within the same conf set.
foreach ($vars as $k => &$v) {
if (is_string($v)) $v = str_replace('${SCRIPTS_DIR}', SCRIPTS_DIR, $v);
}
foreach ($vars as $k => &$v) {
if (is_string($v) && str_contains($v, '${')) {
$v = preg_replace_callback('/\$\{([A-Z0-9_]+)\}/', function ($m) use ($vars) {
return $vars[$m[1]] ?? $m[0];
}, $v);
}
}
unset($v);
return $vars;
}