bandwidth.php (fogproject-1.5.5) | : | bandwidth.php (fogproject-1.5.6) | ||
---|---|---|---|---|
skipping to change at line 44 | skipping to change at line 44 | |||
* | * | |||
* @throws Exception | * @throws Exception | |||
* @return int | * @return int | |||
*/ | */ | |||
$getBytes = function ($dev) { | $getBytes = function ($dev) { | |||
if (!is_string($dev)) { | if (!is_string($dev)) { | |||
throw new Exception(_('Device must be a string')); | throw new Exception(_('Device must be a string')); | |||
} | } | |||
$txpath = "/sys/class/net/$dev/statistics/tx_bytes"; | $txpath = "/sys/class/net/$dev/statistics/tx_bytes"; | |||
$rxpath = "/sys/class/net/$dev/statistics/rx_bytes"; | $rxpath = "/sys/class/net/$dev/statistics/rx_bytes"; | |||
$tx = file_get_contents($txpath); | $tx = trim(file_get_contents($txpath)); | |||
$rx = file_get_contents($rxpath); | $rx = trim(file_get_contents($rxpath)); | |||
return [$rx,$tx]; | return [$rx,$tx]; | |||
}; | }; | |||
// Make sure a device is set | // Make sure a device is set | |||
$dev = filter_input(INPUT_GET, 'dev'); | $dev = filter_input(INPUT_GET, 'dev'); | |||
if (!$dev) { | if (!$dev) { | |||
$dev = 'eth0'; | $dev = 'eth0'; | |||
} | } | |||
// Only use the last bit in case somebody is doing stuff bad | // Only use the last bit in case somebody is doing stuff bad | |||
$dev = trim(basename($dev)); | $dev = trim(basename($dev)); | |||
// Directory to check for interfaces and get all system interfaces | // Directory to check for interfaces and get all system interfaces | |||
skipping to change at line 91 | skipping to change at line 91 | |||
if (count($interface) < 1) { | if (count($interface) < 1) { | |||
include '../commons/base.inc.php'; | include '../commons/base.inc.php'; | |||
session_write_close(); | session_write_close(); | |||
ignore_user_abort(true); | ignore_user_abort(true); | |||
set_time_limit(0); | set_time_limit(0); | |||
// Find our server address | // Find our server address | |||
$srvAddr = $_SERVER['SERVER_ADDR']; | $srvAddr = $_SERVER['SERVER_ADDR']; | |||
// If accessed by hostname resolve to ip | // If accessed by hostname resolve to ip | |||
$resName = FOGCore::resolveHostname($srvAddr); | $resName = FOGCore::resolveHostname($srvAddr); | |||
// Use the resolved name to find our interface | // Use the resolved name to find our interface | |||
$dev = FOGCore::getMasterInterface($resname); | $dev = FOGCore::getMasterInterface($resName); | |||
} | } | |||
// Trim the device | // Trim the device | |||
$dev = trim($dev); | $dev = trim($dev); | |||
// If the device is not set or found return Unknown | // If the device is not set or found return Unknown | |||
if (!$dev) { | if (!$dev) { | |||
$ret = [ | $ret = [ | |||
'dev' => 'Unknown', | 'dev' => 'Unknown', | |||
'rx' => 0, | 'rx' => 0, | |||
'tx' => 0, | 'tx' => 0, | |||
]; | ]; | |||
End of changes. 2 change blocks. | ||||
3 lines changed or deleted | 3 lines changed or added |