diff --git a/gui/ext/vmmngr/vmmngr.conf b/gui/ext/vmmngr/vmmngr.conf index 7b2e6c3..4e5011b 100644 --- a/gui/ext/vmmngr/vmmngr.conf +++ b/gui/ext/vmmngr/vmmngr.conf @@ -1,6 +1,6 @@ { "appname": "VM Manager", - "version": "0.8.1", + "version": "0.9.0", "rootfolder": "/mnt/Daten/extensions/vmmngr", "vm_source": "auto", "bridges": ["ix0bridge"], diff --git a/gui/vmmngr-boot.inc b/gui/vmmngr-boot.inc index 78d7dd5..35a97d0 100644 --- a/gui/vmmngr-boot.inc +++ b/gui/vmmngr-boot.inc @@ -56,6 +56,7 @@ if (!function_exists('vmm_nav')) { 'images' => ['vmmngr_images.php', gettext('Images')], 'templates' => ['vmmngr_templates.php', gettext('Templates')], 'datastores' => ['vmmngr_datastores.php', gettext('Datastores')], + 'switches' => ['vmmngr_switches.php', gettext('Switches')], 'jobs' => ['vmmngr_jobs.php', gettext('Jobs')], 'config' => ['vmmngr_config.php', gettext('Configuration')], ]; diff --git a/gui/vmmngr_switches.php b/gui/vmmngr_switches.php new file mode 100644 index 0000000..a02b518 --- /dev/null +++ b/gui/vmmngr_switches.php @@ -0,0 +1,164 @@ +/dev/null')))); + if (!preg_match('/^[A-Za-z0-9][A-Za-z0-9_-]{0,31}$/', $swName)) { + $_SESSION['vmmngr_error'] = gettext('Invalid switch name.'); + } elseif (!in_array($bridge, $hostBridges, true)) { + $_SESSION['vmmngr_error'] = gettext('Choose an existing host bridge - the addon does not create bridges.'); + } else { + $res = vmm_run(['switch', 'create', '-t', 'manual', '-b', $bridge, $swName], 30); + $_SESSION['vmmngr_error'] = $res['rc'] === 0 + ? sprintf(gettext('Switch %s created on %s.'), $swName, $bridge) + : trim($res['stderr'] ?: $res['stdout'] ?: 'unknown error'); + } + header('Location: vmmngr_switches.php'); + exit; +} + +if ($post && str_starts_with($act, 'destroy:')) { + $swName = substr($act, 8); + if (($_POST['confirm'] ?? '') !== $swName) { + $_SESSION['vmmngr_error'] = gettext('Confirmation mismatch - switch kept.'); + } else { + $res = vmm_run(['switch', 'destroy', $swName], 30); + $_SESSION['vmmngr_error'] = $res['rc'] === 0 + ? sprintf(gettext('Switch %s removed.'), $swName) + : trim($res['stderr'] ?: $res['stdout'] ?: 'unknown error'); + } + header('Location: vmmngr_switches.php'); + exit; +} + +$switches = vmm_switches(); +$vms = vmm_list(); +$bySwitch = []; +foreach ($vms as $v) { + $info = vmm_info((string)$v['name']); + foreach (($info['sections']['network-interface'] ?? []) as $nic) { + $sw = (string)($nic['data']['virtual-switch'] ?? ''); + if ($sw !== '') { + $bySwitch[$sw][] = (string)$v['name']; + } + } +} +$hostBridges = array_values(array_filter(array_map('trim', explode("\n", trim((string)@shell_exec('/sbin/ifconfig -g bridge 2>/dev/null')))))); + +$pgtitle = [gettext('Extensions'), gettext('VM Manager'), gettext('Switches')]; +include 'fbegin.inc'; +vmm_css(); +vmm_nav('switches'); +?> + + +
+ diff --git a/version.txt b/version.txt index 6f4eebd..ac39a10 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -0.8.1 +0.9.0