Commit 7c3dadb0 authored by Ad Schellevis's avatar Ad Schellevis

(interfaces.lib.inc) extend legacy_interface_stats to support "fetch all interfaces"

parent 99aa186e
...@@ -149,9 +149,15 @@ function legacy_vlan_tag($ifs, $member, $tag) ...@@ -149,9 +149,15 @@ function legacy_vlan_tag($ifs, $member, $tag)
} }
} }
function legacy_interface_stats($ifs) function legacy_interface_stats($ifs=null)
{ {
$cmd = '/usr/local/sbin/ifinfo ' . escapeshellarg($ifs); if ($ifs != null) {
// only request data for selected interface
$cmd = '/usr/local/sbin/ifinfo '. escapeshellarg($ifs);
} else {
// all interfaces
$cmd = '/usr/local/sbin/ifinfo';
}
$stats = array(); $stats = array();
exec($cmd . ' 2>&1', $out, $ret); exec($cmd . ' 2>&1', $out, $ret);
...@@ -160,17 +166,21 @@ function legacy_interface_stats($ifs) ...@@ -160,17 +166,21 @@ function legacy_interface_stats($ifs)
return $stats; return $stats;
} }
if (count($out)) { $current_interface = "";
/* first one is header */ foreach ($out as $line) {
array_shift($out); if (strpos($line, 'Interface') === 0) {
$current_interface = explode(')', explode('(', $line)[1])[0];
foreach ($out as $line) { $stats[$current_interface] = array();
} elseif ($current_interface != "") {
$stat = explode(':', $line); $stat = explode(':', $line);
$stats[trim($stat[0])] = trim($stat[1]); $stats[$current_interface][trim($stat[0])] = trim($stat[1]);
} }
} }
if ($ifs != null) {
return $stats; return $stats[$current_interface];
} else {
return $stats;
}
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment