Varaverk: rsync flag toggle + stop button

- Rsync/rsync.sh children in Advanced now show as conf_flag type when the
  parent orch controls a *_RSYNC_ENABLED tier flag; toggle writes true/false
  to master.conf instead of comment/uncommenting a SCRIPTS array entry
- Added vv_conf_flag_value() and vv_conf_flag_set() helpers in scheduler.php
- Added api/flag_toggle.php endpoint (validates *_RSYNC_ENABLED pattern)
- Added api/stop.php: kills process group, sweeps stuck locks, updates stat
- vv-flag-badge CSS (amber, monospace) to distinguish from event/script rows
- vvSaveChild() routes conf_flag children to flag_toggle.php unconditionally
- vvApplyOrchState() keeps conf_flag toggle at real flag value; disables when orch off
- vvSaveAll() skips conf_flag children (immediate-save only)
This commit is contained in:
Gmer4Lfe
2026-05-24 22:38:33 -04:00
parent d0d56ed8b9
commit cdd2dfc990
5 changed files with 203 additions and 3 deletions
@@ -324,6 +324,30 @@ function vv_conf_script_map(): array {
return $cache = $map;
}
// Read a boolean flag value (e.g. INTERMEDIATE_RSYNC_ENABLED) from master.conf.
function vv_conf_flag_value(string $name): bool {
$conf = file_get_contents(CONF_DIR . '/master.conf') ?: '';
if (preg_match('/^\s*' . preg_quote($name, '/') . '\s*=\s*(true|false)\s*$/m', $conf, $m)) {
return $m[1] === 'true';
}
return false;
}
// Write a boolean flag value to master.conf.
function vv_conf_flag_set(string $name, bool $value): bool {
$confPath = CONF_DIR . '/master.conf';
$content = file_get_contents($confPath);
if ($content === false) return false;
$val = $value ? 'true' : 'false';
$new = preg_replace(
'/^(\s*' . preg_quote($name, '/') . '\s*=\s*)(true|false)(\s*(?:#.*)?)$/m',
'${1}' . $val . '${3}',
$content, -1, $count
);
if (!$count) return false;
return file_put_contents($confPath, $new) !== false;
}
// Comment or uncomment a script's line in the first master.conf array that contains it.
function vv_conf_toggle_script(string $rel, bool $enable): bool {
$confPath = CONF_DIR . '/master.conf';
@@ -365,6 +389,12 @@ function vv_script_children(string $orchPath, array $schedule): array {
$seen = [];
$confMap = vv_conf_script_map();
// Detect which tier rsync flag this orch controls (e.g. "INTERMEDIATE" → INTERMEDIATE_RSYNC_ENABLED)
$rsyncFlagName = null;
if (preg_match('/check_rsync_enabled\s+"([A-Z]+)"/', $content, $rm)) {
$rsyncFlagName = $rm[1] . '_RSYNC_ENABLED';
}
$addChild = function(string $rel) use ($scriptsDir, $schedule, $confMap, &$children, &$seen) {
if (isset($seen[$rel]) || !file_exists("$scriptsDir/$rel")) return;
$seen[$rel] = true;
@@ -399,5 +429,18 @@ function vv_script_children(string $orchPath, array $schedule): array {
}
}
// Annotate Rsync/rsync.sh as a conf_flag child if this orch controls a rsync tier flag
if ($rsyncFlagName) {
foreach ($children as &$c) {
if ($c['id'] === 'Rsync/rsync.sh') {
$c['type'] = 'conf_flag';
$c['flag_name'] = $rsyncFlagName;
$c['flag_value'] = vv_conf_flag_value($rsyncFlagName);
break;
}
}
unset($c);
}
return $children;
}