bandwidth.php misses NFS_ETH_MONITOR
-
As we see in what moses posted (https://forums.fogproject.org/topic/6856/replication-has-stopped-after-ugprade) there seams to be an issue with the interface detection in that script. Testing this on my system I find that
NFS_ETH_MONITOR
on line 7 in bandwidth.php cannot have the correct value as this whole PHP script is not called from within the FOG framework but as URL (like an external call) from dashboardpage.class.php (line 91).So the whole line simply defaults to ‘eth0’ in most cases because ‘NFS_ETH_MONITOR’ is not defined and ‘dev’ is not sent as request parameter either:
$dev = trim(($_REQUEST['dev'] ? basename(htmlentities($_REQUEST['dev'],ENT_QUOTES,'utf-8')) : (defined('NFS_ETH_MONITOR') ? NFS_ETH_MONITOR : 'eth0')));
As already suggested to Tom I’d vote for a complete rewrite of this PHP file to get rid of executing external tools as well… Proposal coming soon!
-
<?php function getInterface() { $dev = trim($_REQUEST['dev'] ? basename(htmlentities($_REQUEST['dev'],ENT_QUOTES,'utf-8')) : 'eth0'); $sys_interfaces = array_diff(scandir('/sys/class/net'), array('..', '.')); $interfaces = array(); foreach ($sys_interfaces as $iface) { if (trim(file_get_contents(sprintf('/sys/class/net/%s/operstate', $iface))) === 'up') { array_push($interfaces, $iface); } } $interface = preg_grep("#$dev#",(array)$interfaces); $dev = @array_shift($interface); if (!empty($dev)) { $rx = trim(file_get_contents(sprintf('/sys/class/net/%s/statistics/rx_bytes', $dev))); $tx = trim(file_get_contents(sprintf('/sys/class/net/%s/statistics/tx_bytes', $dev))); return array('dev' => $dev,'rx' => $rx,'tx' => $tx); } else { return array('dev' => 'unknown', 'rx' => '0', 'tx' => '0'); } } header('Content-Type: text/event-stream'); echo json_encode(getInterface()); exit;
-
/sys/class/net
WOW I wish I knew about that directory a long time ago! It appears to be valid for both Ubuntu 15 and Fedora 23 as well! -
@Wayne-Workman said:
It appears to be valid for both Ubuntu 15 and Fedora 23 as well!
Absolutely!! You can find it within FOS as well… All the systems that use the linux kernel really!
-
@Sebastian-Roth Pushed as suggested.