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:
@@ -206,6 +206,20 @@ function vv_conf_vars(): array {
|
|||||||
$vars[$key] = str_replace('\\$', '$', trim($m[2][$i]));
|
$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;
|
return $vars;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user