* * * * Comments or corrections: bjorn@swift.st * *********************************************************/ # Define timeframe $intFromDate = mktime(0,0,0,$_GET['fmFromMonth'],$_GET['fmFromDay'],$_GET['fmFromYear']); $intToDate = mktime(0,0,0,$_GET['fmToMonth'],$_GET['fmToDay'],$_GET['fmToYear']); $intTotalSeconds = $intToDate - $intFromDate; # Scale Function function fncScale($intNumber, $strFormat, $intDem, $intReturn){ if ($strFormat == "bytes"){ $arrFormat = array("Bytes","KBytes","MBytes","GBytes","TBytes"); } else { $intNumber = $intNumber * 8; $arrFormat = array("bits","Kbits","Mbits","Gbits","Tbits"); } for ($i = 0; $i < sizeof($arrFormat); $i++){ if (($intNumber / 1024 < 1) | (sizeof($arrFormat) == $i+1)){ if (!$intReturn) return number_format($intNumber,$intDem) ." $arrFormat[$i]"; elseif ($intReturn == 1) return number_format($intNumber,$intDem); elseif ($intReturn == 2) return "$arrFormat[$i]"; break; } else { $intNumber = $intNumber / 1024; } } } # fncGoThroughLog Function - This does all the work... function fncGoThroughLog($fmLogfileReal){ # Create the array and define other expressions i want to use $arrValues = array(); $intOkOver = 0; $intCounter = 0; $intTotalIn = 0; $intTotalOut = 0; # Get the public values global $intFromDate; global $intToDate; global $intTotalSeconds; # Open log file. Make sure that there are no disallowed characters # in $strLogfile. list($strLogname, $strLogfile) = split(";", $fmLogfileReal); if ($strLogfile == eregi_replace("[^a-zA-Z0-9\_\.\-]", "x", $strLogfile)) $fd = fopen("$strLogfile", "r") or die("Can't open log file"); else die("Invalid path to logfile"); # Take the values inside the time frame and load them into the array while (!feof($fd)) { $strLina = fgets($fd, 4096); $arrLina = split(" ", $strLina); if (($arrLina[0] > $intFromDate) & ($arrLina[0] < $intToDate)){ $arrValues[$intCounter] = array($arrLina[0],$arrLina[1],$arrLina[2]); $intCounter ++; $intOkOver = 1; } else if ($intOkOver){ $arrValues[$intCounter] = array($arrLina[0],$arrLina[1],$arrLina[2]); $intCounter ++; $intOkOver = 0; } } fclose ($fd); # Run though the array and start calculating for ($i = sizeof($arrValues)-1; $i >= 0; $i--){ list($intTime, $intIn, $intOut) = $arrValues[$i]; if ($i == sizeof($arrValues)-1){ $intLastTime = $intTime; } else{ $intRange = $intTime - $intLastTime; $intTotalIn += $intRange * $intIn; $intTotalOut += $intRange * $intOut; $intLastTime = $intTime; } } ?>
-   
Bits In
Avg. Bits In
Bits Out
Avg. Bits Out
Bytes In
Bytes Out

?> MRTG Total Traffic Generator <?php echo $strVersion?> Total Traffic
Back

MRTG Total Traffic Generator
by Björn Patrick Swift <bjorn@swift.st>