diff --git a/plugins/dynamix.vm.manager/VMMachines.page b/plugins/dynamix.vm.manager/VMMachines.page index 5a5f2e3d5..6c757ec89 100644 --- a/plugins/dynamix.vm.manager/VMMachines.page +++ b/plugins/dynamix.vm.manager/VMMachines.page @@ -175,7 +175,7 @@ if ($action) { $vnc = ''; if ($vncport > 0) { $wsport = $lv->domain_get_ws_port($res); - $vnc = '/plugins/dynamix.vm.manager/vnc.html?autoconnect=true&host=' . $var['IPADDR'] . '&port=' . $wsport; + $vnc = '/plugins/dynamix.vm.manager/vnc.html?autoconnect=true&host=' . $eth0['IPADDR:0'] . '&port=' . $wsport; } else { $vncport = ($vncport < 0) ? "auto" : ""; } diff --git a/plugins/dynamix/Eth0.page b/plugins/dynamix/Eth0.page new file mode 100644 index 000000000..1172b0914 --- /dev/null +++ b/plugins/dynamix/Eth0.page @@ -0,0 +1,398 @@ +Menu="NetworkSettings" +Title="Interface eth0" +Png="ethernet.png" +--- + + +$build = false; +$template = '/usr/local/emhttp/webGui/EthX.page'; +$ini = '/var/local/emhttp/network.ini'; +$validIP = '(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])'; + +function normalize($name) { + return ucfirst(trim($name)); +} + +// get available ethernet ports (excluding eth0) +exec("ip -br addr|grep -Po '^eth[1-9]+\s'",$ports); +$ports = array_map('normalize', $ports); + +// remove non-existing ethernet ports +foreach (glob('/usr/local/emhttp/webGui/Eth[1-9]*.page',GLOB_NOSORT) as $port) { + if (!in_array(basename($port,'.page'), $ports)) { + @unlink($port); + $build = true; + } +} +// add new ethernet ports +foreach ($ports as $port) { + $file = "/usr/local/emhttp/webGui/$port.page"; + if (!file_exists($file)) { + copy($template, $file); + $eth = strtolower($port); + exec("sed -i 's/x-settings/NetworkSettings/;s/ethX/$eth/g' $file"); + $build = true; + } +} +// enable when array is stopped +$disabled = exec("virsh list|grep -om1 running") ? 'disabled' : ''; + +// get VLAN interfaces +$vlan_eth0 = [0]; +if (isset($eth0)) foreach ($eth0 as $key => $val) if (substr($key,0,6)=='VLANID') $vlan_eth0[] = substr($key,7); +?> + + +
diff --git a/plugins/dynamix/EthX.page b/plugins/dynamix/EthX.page new file mode 100644 index 000000000..f8b61c5d9 --- /dev/null +++ b/plugins/dynamix/EthX.page @@ -0,0 +1,165 @@ +Menu="x-settings" +Title="Interface ethX" +Png="ethernet.png" +--- + + +// get interface configuration state +$down = strlen(exec("ip link show ethX|grep -om1 ',UP[,>]'"))==0; + +// get VLAN interfaces +$vlan_ethX = [0]; +if (isset($ethX)) foreach ($ethX as $key => $val) if (substr($key,0,6)=='VLANID') $vlan_ethX[] = substr($key,7); + +// get bond membership +$bond_ethX = isset($eth0['BONDNICS']) ? in_array('ethX',explode(',',$eth0['BONDNICS'])) : false; +?> + + diff --git a/plugins/dynamix/NetworkSettings.page b/plugins/dynamix/NetworkSettings.page index be6616932..4e6b18aa0 100644 --- a/plugins/dynamix/NetworkSettings.page +++ b/plugins/dynamix/NetworkSettings.page @@ -1,179 +1,4 @@ Menu="OtherSettings" +Type="xmenu" Title="Network Settings" Icon="network-settings.png" ---- - - $disabled = $var['fsState']!='Stopped' ? 'disabled' : ''; ?> - - diff --git a/plugins/dynamix/icons/ethernet.png b/plugins/dynamix/icons/ethernet.png new file mode 100644 index 000000000..e9984870a Binary files /dev/null and b/plugins/dynamix/icons/ethernet.png differ diff --git a/plugins/dynamix/include/update.ethernet.php b/plugins/dynamix/include/update.ethernet.php new file mode 100644 index 000000000..0c2439b07 --- /dev/null +++ b/plugins/dynamix/include/update.ethernet.php @@ -0,0 +1,15 @@ + + +if ($_POST['#arg'][1] != 'none') unset($keys[$_POST['#section']]); // do nothing when only description has changed +?> \ No newline at end of file diff --git a/plugins/dynamix/scripts/netconfig b/plugins/dynamix/scripts/netconfig new file mode 100644 index 000000000..303fc7655 --- /dev/null +++ b/plugins/dynamix/scripts/netconfig @@ -0,0 +1,74 @@ +#!/usr/bin/php -q + + +$set = $ifname = $argv[1]; +$run = $set != 'none'; +$ini = parse_ini_file('/var/local/emhttp/network.ini',true); ksort($ini,SORT_NATURAL); +$cfg = '/boot/config/network.cfg'; + +if ($run && file_exists($cfg)) { + $old = parse_ini_file($cfg); + $i = preg_replace('/[^\d]/','',$set); + if (isset($old['SYSNICS'])) { + // new syntax + $ifname = isset($old['IFNAME'][$i]) ? $old['IFNAME'][$i] : $set; + } else { + // legacy syntax + if ($i==0) $ifname = $old['BRIDGING']=='yes' ? $old['BRNAME'] : ($old['BONDING']=='yes' ? $old['BONDNAME'] : $set); + } +} + +// stop interface with existing (old) configuration +// don't execute when only interface description has changed +if ($run) exec("/etc/rc.d/rc.inet1 {$ifname}_stop >/dev/null"); + +if ($bonding = isset($ini['eth0']) && $ini['eth0']['BONDING']=='yes') { + $ini['eth0']['BONDNICS'] = str_replace(',',' ',$ini['eth0']['BONDNICS']); + $members = explode(' ',trim(str_replace('eth0','',$ini['eth0']['BONDNICS']))); +} + +// create configuration file for all available interfaces +$index = 0; +$new = []; $new[] = "# Generated settings:"; +foreach ($ini as $name => $port) { + if ($bonding && in_array($name,$members)) continue; + $bridging = $port['BRIDGING']=='yes'; + $trunk = $port['TYPE']=='trunk'; + $i = 0; $id0 = 0; + $iface = $bridging ? $port['BRNAME'] : ($bonding && $name=='eth0' ? $port['BONDNAME'] : $name); + $new[] = "IFNAME[$index]=\"$iface\""; + if ($set==$name) $ifname = $iface; + foreach ($port as $key => $val) { + if (preg_match('/^(TYPE|BONDING$|BRIDGING)/',$key)) continue; + if (!$bonding && preg_match('/^(BONDING_MODE|BONDING_MIIMON|BONDNICS|BONDNAME)/',$key)) continue; + if (!$bridging && preg_match('/^(BRSTP|BRFD|BRNICS|BRNAME)/',$key)) continue; + list($item,$id) = explode(':',$key,2); + if ($trunk && $id>0 && preg_match('/^(VLANID|USE_DHCP|IPADDR|NETMASK|DESCRIPTION)/',$key)) { + if ($id0 != $id) {$id0 = $id; $i++;} + $vlan = ",$i]"; + } else $vlan = ''; + if (!$vlan && preg_match('/^VLANID/',$key)) continue; + $new[] = $item.(preg_match('/^(GATEWAY|DNS_SERVER|DHCP_KEEPRESOLV)/',$key)?'':'['.$index.($vlan?'':']')).$vlan."=\"$val\""; + } + if ($trunk) $new[] = "VLANS[$index]=\"".($i+1)."\""; + $index++; +} +$new[] = "SYSNICS=\"$index\""; + +file_put_contents($cfg,implode("\r\n",$new)."\r\n"); +// start interface with updated (new) configuration +// don't execute when only interface description has changed +if ($run) exec("/etc/rc.d/rc.inet1 {$ifname}_start >/dev/null &"); +exit(0); +?> diff --git a/plugins/dynamix/template.php b/plugins/dynamix/template.php index 2d2fc78a3..68f8d2cec 100644 --- a/plugins/dynamix/template.php +++ b/plugins/dynamix/template.php @@ -39,6 +39,9 @@ $shares = parse_ini_file('state/shares.ini',true); $sec_nfs = parse_ini_file('state/sec_nfs.ini',true); $sec_afp = parse_ini_file('state/sec_afp.ini',true); +// Read network settings +extract(parse_ini_file('state/network.ini',true)); + // Merge SMART settings require_once 'include/CustomMerge.php';