Fixed eth0 port status detection and port up/down execution

This commit is contained in:
bergware
2016-06-11 08:38:29 +02:00
parent e00a1ab317
commit ffbeb594a0
3 changed files with 15 additions and 5 deletions

View File

@@ -44,6 +44,9 @@ foreach ($ports as $port) {
$service = exec("pgrep libvirt") ? 'VMs' : '';
$service .= exec("pgrep docker") ? ($service ? ' and ' : '').'Docker' : '';
// eth0 port status
$no_eth0 = exec("ip link show eth0|grep -Pom1 '(NO-CARRIER|state DOWN)'");
// 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);

View File

@@ -28,7 +28,7 @@ $vlan_ethX = [0];
if (!$locked && isset($ethX)) foreach ($ethX as $key => $val) if (substr($key,0,6)=='VLANID') $vlan_ethX[] = substr($key,7);
$cmd = 'Down';
if (strlen(exec("ip link show ethX|grep -om1 ',UP[,>]'"))==0) {
if (!exec("ip link show ethX|grep -om1 'UP>'")) {
$more = true;
$reason = "Interface is shutdown (inactive)";
$class = 'blue';
@@ -74,8 +74,8 @@ $(function() {
<?if ($locked || $service):?>
disableForm(form,true);
<?endif;?>
<?if (strlen(exec("ip link show eth0|grep -om1 ',UP[,>]'"))==0):?>
$('input[name="#shut"]').prop('disabled',true);
<?if ($no_eth0):?>
$('input[name="#shut_ethX"]').prop('disabled',true);
<?endif;?>
setTimeout(portcheck_ethX,Number('ethX'.substr(3))*1000);
});
@@ -263,5 +263,5 @@ Network mask:
</script>
&nbsp;
: <input type="submit" value="Apply" onclick="$(waitid).show()"><input type="button" value="Done" onclick="done()"><input type="button" name="#shut" value="Port <?=$cmd?>" onclick="portToggle('ethX','<?=$cmd?>')"><?if ($service) echo "$service must be <b>STOPPED</b> to change"?>
: <input type="submit" value="Apply" onclick="$(waitid).show()"><input type="button" value="Done" onclick="done()"><input type="button" name="#shut_ethX" value="Port <?=$cmd?>" onclick="portToggle('ethX','<?=$cmd?>')"><?if ($service) echo "$service must be <b>STOPPED</b> to change"?>
</form>

View File

@@ -13,5 +13,12 @@
<?
$port = $_POST['port'];
$cmd = strtolower($_POST['cmd']);
if ($port) exec("ip link set $port $cmd");
exec("ip link set $port $cmd");
$pass = $cmd=='up' ? 'UP>' : '';
$wait = 5;
while ($wait > 0) {
if (exec("ip link show $port|grep -om1 'UP>'")==$pass) break;
sleep(1);
$wait--;
}
?>