0.4.3: derive VNC connect address from the VM's bridge IP
This commit is contained in:
1 parent
3c2ee78944
commit
b9ad09e717
4 files changed
+41
-6
No files matched your search
+38
-3
@@ -830,23 +830,58 @@ function vmm_delete_data_file(string $dir, string $name): array
|
|||||||
* Turn a bhyve VNC bind address ("0.0.0.0:5901") into something a human can
|
* Turn a bhyve VNC bind address ("0.0.0.0:5901") into something a human can
|
||||||
* actually connect to. 0.0.0.0 is a listen address, not a destination.
|
* actually connect to. 0.0.0.0 is a listen address, not a destination.
|
||||||
*/
|
*/
|
||||||
function vmm_vnc_connect(string $bind): string
|
function vmm_vnc_connect(string $bind, string $host = ''): string
|
||||||
{
|
{
|
||||||
$bind = trim($bind);
|
$bind = trim($bind);
|
||||||
if ($bind === '' || $bind === '-') {
|
if ($bind === '' || $bind === '-') {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
[$host, $port] = array_pad(explode(':', $bind, 2), 2, '');
|
[$bindHost, $port] = array_pad(explode(':', $bind, 2), 2, '');
|
||||||
$port = (int)$port;
|
$port = (int)$port;
|
||||||
if ($port <= 0) {
|
if ($port <= 0) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
if ($host === '0.0.0.0' || $host === '' || $host === '*') {
|
if ($bindHost !== '0.0.0.0' && $bindHost !== '' && $bindHost !== '*') {
|
||||||
|
return $bindHost . ':' . $port;
|
||||||
|
}
|
||||||
|
if ($host === '') {
|
||||||
$host = trim((string)@shell_exec('hostname -f 2>/dev/null')) ?: (gethostname() ?: 'localhost');
|
$host = trim((string)@shell_exec('hostname -f 2>/dev/null')) ?: (gethostname() ?: 'localhost');
|
||||||
}
|
}
|
||||||
return $host . ':' . $port;
|
return $host . ':' . $port;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* IP of the bridge that carries this VM's traffic (the address a client on
|
||||||
|
* that network actually reaches). Falls back to the host name.
|
||||||
|
*/
|
||||||
|
function vmm_vnc_host_for_vm(string $name): string
|
||||||
|
{
|
||||||
|
$switchName = '';
|
||||||
|
$info = vmm_info($name);
|
||||||
|
foreach (($info['sections']['network-interface'] ?? []) as $nic) {
|
||||||
|
if (!empty($nic['data']['virtual-switch'])) {
|
||||||
|
$switchName = (string)$nic['data']['virtual-switch'];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$iface = '';
|
||||||
|
foreach (vmm_switches() as $sw) {
|
||||||
|
if ($switchName === '' || (string)($sw['name'] ?? '') === $switchName) {
|
||||||
|
$iface = (string)($sw['iface'] ?? '');
|
||||||
|
if ($iface !== '' && $iface !== 'n/a') {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($iface !== '' && $iface !== 'n/a') {
|
||||||
|
$out = trim((string)@shell_exec('/sbin/ifconfig ' . escapeshellarg($iface) . ' inet 2>/dev/null'));
|
||||||
|
if (preg_match('/inet (\d+\.\d+\.\d+\.\d+)/', $out, $m)) {
|
||||||
|
return $m[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return trim((string)@shell_exec('hostname -f 2>/dev/null')) ?: (gethostname() ?: 'localhost');
|
||||||
|
}
|
||||||
|
|
||||||
function vmm_vm_conf_path(string $name): string
|
function vmm_vm_conf_path(string $name): string
|
||||||
{
|
{
|
||||||
$dir = vmm_data_dir('');
|
$dir = vmm_data_dir('');
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"appname": "VM Manager",
|
"appname": "VM Manager",
|
||||||
"version": "0.4.2",
|
"version": "0.4.3",
|
||||||
"rootfolder": "/mnt/Daten/extensions/vmmngr",
|
"rootfolder": "/mnt/Daten/extensions/vmmngr",
|
||||||
"vm_source": "auto",
|
"vm_source": "auto",
|
||||||
"bridges": ["ix0bridge"],
|
"bridges": ["ix0bridge"],
|
||||||
|
|||||||
+1
-1
@@ -140,7 +140,7 @@ vmm_nav('dashboard');
|
|||||||
$vncBind = (string)$b['data']['vnc'];
|
$vncBind = (string)$b['data']['vnc'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$vncTarget = vmm_vnc_connect($vncBind);
|
$vncTarget = $vncBind !== '' ? vmm_vnc_connect($vncBind, vmm_vnc_host_for_vm($name)) : '';
|
||||||
?>
|
?>
|
||||||
<?php if ($vncTarget !== ''): ?>
|
<?php if ($vncTarget !== ''): ?>
|
||||||
<table class="area_data_settings" style="width:100%;border-collapse:collapse;">
|
<table class="area_data_settings" style="width:100%;border-collapse:collapse;">
|
||||||
|
|||||||
+1
-1
@@ -1 +1 @@
|
|||||||
0.4.2
|
0.4.3
|
||||||
Reference in new issue
Block a user