diff --git a/gui/ext/vmmngr/vmmngr.conf b/gui/ext/vmmngr/vmmngr.conf index 75e7bd8..ff48387 100644 --- a/gui/ext/vmmngr/vmmngr.conf +++ b/gui/ext/vmmngr/vmmngr.conf @@ -1,6 +1,6 @@ { "appname": "VM Manager", - "version": "0.3.1", + "version": "0.3.2", "rootfolder": "/mnt/Daten/extensions/vmmngr", "vm_source": "auto", "bridges": ["ix0bridge"], diff --git a/gui/vmmngr-config-lib.inc b/gui/vmmngr-config-lib.inc new file mode 100644 index 0000000..8d9394d --- /dev/null +++ b/gui/vmmngr-config-lib.inc @@ -0,0 +1,108 @@ + 'YES', 'nmdm_load' => 'YES']; + if (!isset($config['loaderconf']) || !is_array($config['loaderconf'])) { + $config['loaderconf'] = []; + } + if (!isset($config['loaderconf']['param']) || !is_array($config['loaderconf']['param'])) { + $config['loaderconf']['param'] = []; + } + $have = []; + foreach ($config['loaderconf']['param'] as $p) { + if (isset($p['name'])) { + $have[(string)$p['name']] = true; + } + } + foreach ($want as $key => $value) { + if (isset($have[$key])) { + continue; + } + $config['loaderconf']['param'][] = [ + 'uuid' => uuid(), + 'enable' => '', + 'name' => $key, + 'value' => $value, + 'comment' => '', + ]; + $added[] = $key; + } + + // 2) postinit hook: repairs symlinks and loads modules at every boot + $cmd = VMM_ROOT . '/vmm-init -p'; + $found = false; + if (isset($config['rc']['param']) && is_array($config['rc']['param'])) { + foreach ($config['rc']['param'] as $p) { + if (trim((string)($p['value'] ?? '')) === $cmd) { + $found = true; + break; + } + } + } else { + if (!isset($config['rc']) || !is_array($config['rc'])) { + $config['rc'] = []; + } + $config['rc']['param'] = []; + } + if (!$found) { + $config['rc']['param'][] = [ + 'uuid' => uuid(), + 'name' => 'VM Manager Extension', + 'value' => $cmd, + 'comment' => 'Start VM Manager', + 'typeid' => '2', + 'enable' => true, + ]; + $added[] = 'rc postinit'; + } + + if ($added !== []) { + write_config(); + } + return $added; + } + + function vmm_boot_state(): array + { + global $config; + $loader = []; + foreach (($config['loaderconf']['param'] ?? []) as $p) { + if (isset($p['name'])) { + $loader[(string)$p['name']] = (string)($p['value'] ?? ''); + } + } + $rcCmd = VMM_ROOT . '/vmm-init -p'; + $rcOk = false; + foreach (($config['rc']['param'] ?? []) as $p) { + if (trim((string)($p['value'] ?? '')) === $rcCmd) { + $rcOk = true; + break; + } + } + return [ + 'vmm_load' => $loader['vmm_load'] ?? '', + 'nmdm_load' => $loader['nmdm_load'] ?? '', + 'rc_postinit' => $rcOk, + ]; + } +} diff --git a/gui/vmmngr_config.php b/gui/vmmngr_config.php index c853e58..1899e60 100644 --- a/gui/vmmngr_config.php +++ b/gui/vmmngr_config.php @@ -4,6 +4,16 @@ */ require_once 'vmmngr-boot.inc'; +require_once 'vmmngr-config-lib.inc'; + +if (strtoupper((string)($_SERVER['REQUEST_METHOD'] ?? '')) === 'POST' && ($_POST['act'] ?? '') === 'register') { + $added = vmm_register_boot(); + $_SESSION['vmmngr_error'] = $added === [] + ? gettext('Boot integration was already complete - nothing changed.') + : sprintf(gettext('Added to config.xml: %s. Modules take effect at the next boot.'), implode(', ', $added)); + header('Location: vmmngr_config.php'); + exit; +} $pgtitle = [gettext('Extensions'), gettext('VM Manager'), gettext('Configuration')]; $sc = vmm_selfcheck(); @@ -16,6 +26,35 @@ vmm_nav('config'); ?>