mirror of
https://github.com/unraid/webgui.git
synced 2026-02-18 06:58:47 -06:00
Networking: fix empty config when updating DNS and docker/vms are running
This commit is contained in:
@@ -48,17 +48,17 @@ function locked($source, $port) {
|
||||
}
|
||||
|
||||
function vlanID($cfg) {
|
||||
return array_filter($cfg,function($key){return strpos($key,'VLANID:')===0;},ARRAY_FILTER_USE_KEY);
|
||||
return array_filter($cfg, function($key){return strpos($key, 'VLANID:')===0;}, ARRAY_FILTER_USE_KEY);
|
||||
}
|
||||
|
||||
function index($key) {
|
||||
return filter_var($key,FILTER_SANITIZE_NUMBER_INT);
|
||||
return filter_var($key, FILTER_SANITIZE_NUMBER_INT);
|
||||
}
|
||||
|
||||
function metric($eth, $prot, $index) {
|
||||
$system = '/sys/class/net';
|
||||
$bridge = str_replace('eth','br',$eth);
|
||||
$bond = str_replace('eth','bond',$eth);
|
||||
$bridge = str_replace('eth','br', $eth);
|
||||
$bond = str_replace('eth','bond', $eth);
|
||||
$port = file_exists("$system/$bridge") ? $bridge : (file_exists("$system/$bond") ? $bond : $eth);
|
||||
$metric = exec("ip -$prot route show default dev $port 2>/dev/null | grep -Pom1 ' metric \K\d+'");
|
||||
if ($metric) return $metric + $index;
|
||||
@@ -67,8 +67,8 @@ function metric($eth, $prot, $index) {
|
||||
}
|
||||
|
||||
// remove non-existing ethernet ports
|
||||
foreach (glob("$docroot/webGui/Eth[1-9]*.page",GLOB_NOSORT) as $port) {
|
||||
if (!in_array(strtolower(basename($port,'.page')), $ports)) {
|
||||
foreach (glob("$docroot/webGui/Eth[1-9]*.page", GLOB_NOSORT) as $port) {
|
||||
if (!in_array(strtolower(basename($port, '.page')), $ports)) {
|
||||
@unlink($port);
|
||||
$build = true;
|
||||
}
|
||||
@@ -78,8 +78,8 @@ foreach (glob("$docroot/webGui/Eth[1-9]*.page",GLOB_NOSORT) as $port) {
|
||||
foreach ($ports as $ethX) {
|
||||
$file = "$docroot/webGui/".ucfirst($ethX).".page";
|
||||
if (!file_exists($file)) {
|
||||
$X = filter_var($ethX,FILTER_SANITIZE_NUMBER_INT);
|
||||
file_put_contents($file,str_replace(['parentname:nnn','tabX','bondX','brX','ethX'],['NetworkSettings:'.($X+100),'tab'.($X+1),'bond'.$X,'br'.$X,$ethX],file_get_contents($template)));
|
||||
$X = filter_var($ethX, FILTER_SANITIZE_NUMBER_INT);
|
||||
file_put_contents($file, str_replace(['parentname:nnn','tabX','bondX','brX','ethX'],['NetworkSettings:'.($X+100),'tab'.($X+1),'bond'.$X,'br'.$X,$ethX], file_get_contents($template)));
|
||||
$build = true;
|
||||
}
|
||||
}
|
||||
@@ -93,7 +93,7 @@ $no_eth0 = exec("ip -br link show eth0 | awk '{print \$2;exit}'")=='DOWN';
|
||||
// get VLAN interfaces
|
||||
$vlan_eth0 = $sort_eth0 = [];
|
||||
if (isset($eth0)) foreach (vlanID($eth0) as $key => $val) {$vlan_eth0[] = index($key); $sort_eth0[] = (int)$val;}
|
||||
array_multisort($sort_eth0,$vlan_eth0);
|
||||
array_multisort($sort_eth0, $vlan_eth0);
|
||||
?>
|
||||
|
||||
<script>
|
||||
@@ -163,12 +163,14 @@ function prepareSettings(form) {
|
||||
if ($(form).find('input[name="#arg[1]"]').val() == 'none') return true;
|
||||
|
||||
var metrics = [], metrics6 = [];
|
||||
$(form).find('input[name^="METRIC:"]').each(function(){if($(this).val()>0) metrics.push($(this).val());});
|
||||
$(form).find('input[name^="METRIC6:"]').each(function(){if($(this).val()>0) metrics6.push($(this).val());});
|
||||
$(form).find('input[name^="METRIC:"]').each(function(){if($(this).val() > 0) metrics.push($(this).val());});
|
||||
$(form).find('input[name^="METRIC6:"]').each(function(){if($(this).val() > 0) metrics6.push($(this).val());});
|
||||
if (metrics.same() || metrics6.same()) {
|
||||
swal({title:'Duplicate metrics',text:'List of default gateways contains duplicate metric values',animation:'none',type:'error',html:true,confirmButtonText:"_(Ok)_"});
|
||||
swal({title:'Duplicate metrics', text:'List of default gateways contains duplicate metric values', animation:'none', type:'error', html:true, confirmButtonText:"_(Ok)_"});
|
||||
return false;
|
||||
}
|
||||
// enable form items for submission
|
||||
$(form).find('input,select').prop('disabled',false);
|
||||
if (form.TYPE.value == 'access') {
|
||||
$(form).find('input[name^="VLANID:"]').prop('disabled',false).val('');
|
||||
$(form).find('input[name^="DESCRIPTION:"]').not('input[name$=":0"]').prop('disabled',false).val('');
|
||||
@@ -195,17 +197,17 @@ function prepareSettings(form) {
|
||||
var protocol = $(this).val() || 'ipv4';
|
||||
var i = $(this).prop('name').split(':')[1];
|
||||
if (protocol == 'ipv6') {
|
||||
$(form).find('input[name="IPADDR:'+i+'"]').prop('disabled',false).val('');
|
||||
$(form).find('select[name="NETMASK:'+i+'"]').prop('disabled',false).val('');
|
||||
$(form).find('input[name="GATEWAY:'+i+'"]').prop('disabled',false).val('');
|
||||
$(form).find('input[name="METRIC:'+i+'"]').prop('disabled',false).val('');
|
||||
$(form).find('input[name="IPADDR:'+i+'"]').val('');
|
||||
$(form).find('select[name="NETMASK:'+i+'"]').val('');
|
||||
$(form).find('input[name="GATEWAY:'+i+'"]').val('');
|
||||
$(form).find('input[name="METRIC:'+i+'"]').val('');
|
||||
}
|
||||
if (protocol == 'ipv4') {
|
||||
$(form).find('input[name="IPADDR6:'+i+'"]').prop('disabled',false).val('');
|
||||
$(form).find('input[name="NETMASK6:'+i+'"]').prop('disabled',false).val('');
|
||||
$(form).find('input[name="GATEWAY6:'+i+'"]').prop('disabled',false).val('');
|
||||
$(form).find('input[name="METRIC6:'+i+'"]').prop('disabled',false).val('');
|
||||
$(form).find('select[name="PRIVACY6:'+i+'"]').prop('disabled',false).val('');
|
||||
$(form).find('input[name="IPADDR6:'+i+'"]').val('');
|
||||
$(form).find('input[name="NETMASK6:'+i+'"]').val('');
|
||||
$(form).find('input[name="GATEWAY6:'+i+'"]').val('');
|
||||
$(form).find('input[name="METRIC6:'+i+'"]').val('');
|
||||
$(form).find('select[name="PRIVACY6:'+i+'"]').val('');
|
||||
}
|
||||
});
|
||||
$(form).find('select[name^="USE_DHCP:"]').each(function() {
|
||||
@@ -214,9 +216,9 @@ function prepareSettings(form) {
|
||||
var metric = $(form).find('input[name="METRIC:'+i+'"]').val();
|
||||
var gw4 = (port == 'eth0') ? true : $(form).find('input[name="USE_GW4:'+i+'"]').prop('checked');
|
||||
if (protocol != 'ipv6' && $(this).val() != 'no') {
|
||||
$(form).find('input[name="IPADDR:'+i+'"]').prop('disabled',false).val('');
|
||||
$(form).find('input[name="GATEWAY:'+i+'"]').prop('disabled',false).val('');
|
||||
$(form).find('input[name="METRIC:'+i+'"]').prop('disabled',false).val(gw4?'':'0');
|
||||
$(form).find('input[name="IPADDR:'+i+'"]').val('');
|
||||
$(form).find('input[name="GATEWAY:'+i+'"]').val('');
|
||||
$(form).find('input[name="METRIC:'+i+'"]').val(gw4?'':'0');
|
||||
}
|
||||
});
|
||||
$(form).find('select[name^="USE_DHCP6:"]').each(function() {
|
||||
@@ -225,11 +227,11 @@ function prepareSettings(form) {
|
||||
var metric = $(form).find('input[name="METRIC6:'+i+'"]').val();
|
||||
var gw6 = (port == 'eth0') ? true : $(form).find('input[name="USE_GW6:'+i+'"]').prop('checked');
|
||||
if (protocol != 'ipv4' && $(this).val() != 'no') {
|
||||
$(form).find('input[name="IPADDR6:'+i+'"]').prop('disabled',false).val('');
|
||||
$(form).find('input[name="GATEWAY6:'+i+'"]').prop('disabled',false).val('');
|
||||
$(form).find('input[name="METRIC6:'+i+'"]').prop('disabled',false).val(gw6?'':'0');
|
||||
$(form).find('input[name="IPADDR6:'+i+'"]').val('');
|
||||
$(form).find('input[name="GATEWAY6:'+i+'"]').val('');
|
||||
$(form).find('input[name="METRIC6:'+i+'"]').val(gw6?'':'0');
|
||||
}
|
||||
if ($(this).val() != 'yes') $(form).find('input[name="PRIVACY6:'+i+'"]').prop('disabled',false).val('');
|
||||
if ($(this).val() != 'yes') $(form).find('input[name="PRIVACY6:'+i+'"]').val('');
|
||||
});
|
||||
if (port == 'eth0') {
|
||||
$(dns).find('select,input').each(function(){
|
||||
|
||||
Reference in New Issue
Block a user