%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/local/share/
Upload File :
Create Path :
Current File : //usr/local/share/ethparse.php

<?php
function startsWith($haystack, $needle)
{
    return $needle === "" || strpos($haystack, $needle) === 0;
}

	$iface = $argv[1]." ";
	$lines = file("/tmp/routerifc.txt");
	$has = false;
	ob_start();
	foreach ($lines as $line)
	{
		if(!startsWith($line, " "))
		{
			if(startsWith($line, $iface))
			{
				$has = true;
			}
			else
			{
				$has = false;
			}
		}
		if($has)
		{
			echo $line;
		}
	}
	$txt = ob_get_clean();
	echo $txt;

	$iface = trim($iface);
	$js = file_get_contents("/var/lib/rrd/routerstats.json");
	if(!$js) $js = "{}";
	$s = json_decode($js);
	if(!isset($s->{$iface}))
	{
		$s->{$iface} = new stdClass();
		$s->{$iface}->transmit = 0;
		$s->{$iface}->receive = 0;
		$s->{$iface}->rx = 0;
		$s->{$iface}->tx = 0;
	}
	$date = date("Y-m-d");
	if(!isset($s->{$iface}->{$date}))
	{
		$s->{$iface}->{$date} = new stdClass();
		$s->{$iface}->{$date}->transmit = 0;
		$s->{$iface}->{$date}->receive = 0;
	}
	preg_match_all("/RX bytes:([0-9]+).*?TX bytes:([0-9]+)/si", $txt, $matches);
	$tx = (int)$matches[2][0];
	$rx = (int)$matches[1][0];
	print_r($matches);
	if($s->{$iface}->rx > $rx)
	{
		$rrx = $rx;
	}
	else
	{
		$rrx = $rx - $s->{$iface}->rx;
	}
	if($s->{$iface}->tx > $tx)
	{
		$rtx = $tx;
	}
	else
	{
		$rtx = $tx - $s->{$iface}->tx;
	}
	$s->{$iface}->rx = $rx;
	$s->{$iface}->tx = $tx;
	$s->{$iface}->transmit += $rtx;
	$s->{$iface}->receive += $rrx;
	$s->{$iface}->{$date}->transmit += $rtx;
	$s->{$iface}->{$date}->receive += $rrx;

	$txt = date("Y-m-d H:i:s") . "\t$iface\t$rrx\t$rtx";
	file_put_contents("/var/lib/rrd/routerstats.json", json_encode($s, JSON_PRETTY_PRINT));
	if($rtx || $rrx)
		file_put_contents('/var/lib/rrd/routerstats-5m.txt', $txt.PHP_EOL , FILE_APPEND | LOCK_EX);

?>

Zerion Mini Shell 1.0