From 41681e0a817aaabf930357543bde94c838d0c40b Mon Sep 17 00:00:00 2001 From: jim-p Date: Wed, 20 Oct 2010 18:37:48 -0400 Subject: Add contributed ifbwstats package from Zorac on the forum. --- config/ifbwstats/ifbwstats_cur.php | 197 +++++++++++++++++++++++++++++++++++++ 1 file changed, 197 insertions(+) create mode 100644 config/ifbwstats/ifbwstats_cur.php (limited to 'config/ifbwstats/ifbwstats_cur.php') diff --git a/config/ifbwstats/ifbwstats_cur.php b/config/ifbwstats/ifbwstats_cur.php new file mode 100644 index 00000000..6cb4870e --- /dev/null +++ b/config/ifbwstats/ifbwstats_cur.php @@ -0,0 +1,197 @@ +'; +include("fbegin.inc"); +echo '

ifBWStats: Daily Statistics For Current Billing Period

'; + +//find all valid data files for active and inactive interfaces +//assume monitoring all interfaces +$datafilestores = array(); +$n=0; + +//if only monitoring one inteface +if ($config['installedpackages']['ifbwstats']['config'][0]['ifmon'] != 'all') +{ + //dont check conf directory, as if only one interface is being monitored, it must be used and therefore in the tmp dir + if (file_exists('/tmp/ifbwstats-'.$config['installedpackages']['ifbwstats']['config'][0]['ifmon'].'.data')) + { + $datafilestores[$n] = '/tmp/ifbwstats-'.$config['installedpackages']['ifbwstats']['config'][0]['ifmon'].'.data'; + cleanup_data_file ($datafilestores[$n], $datafilestores[$n]); + $n++; + } +} +else +{ + if ($handle = opendir('/tmp')) + { + while (false !== ($file = readdir($handle))) + { + if ((preg_match ("/ifbwstats/", $file))&&(preg_match ("/.data/", $file))) + { + $datafilestores[$n] = '/tmp/'.$file; + cleanup_data_file ($datafilestores[$n], $datafilestores[$n]); + $n++; + } + } + } + + if ($handle = opendir('/cf/conf')) + { + while (false !== ($file = readdir($handle))) + { + $filefound = 'no'; + if ((preg_match ("/ifbwstats-/", $file))&&(preg_match ("/.data/", $file))) + { + for ($i = 0; $i < $n; $i++) if (preg_match ("/$file/", $datafilestores[$i])) $filefound = 'yes'; + if ($filefound == 'no') + { + cleanup_data_file ('/cf/conf/'.$file, '/tmp/'.$file); + $datafilestores[$n] = '/tmp/'.$file; + $n++; + } + } + } + } +} + +//display tabs +echo ''; +echo ''; +echo ''; +echo '
'; +$tab_array[0] = array ("Daily", true, "ifbwstats_cur.php"); +$tab_array[1] = array ("Monthly", false, "ifbwstats_disp.php"); +$tab_array[2] = array ("Settings", false, "pkg_edit.php?xml=ifbwstats.xml"); +display_top_tabs($tab_array); +echo '
'; + +//cycle through all valid data files found +foreach ($datafilestores as $wandataallfile) +{ +//----------------------------------------begin file statistics monthly display---------------------------------------- + //read data file + $fp = fopen($wandataallfile,"r") or die("Error Reading File"); + $data = fread($fp, filesize($wandataallfile)); + fclose($fp); + $wandataall = explode("\n", $data); + $n = count($wandataall); + + $monthintotal = 0; + $monthouttotal = 0; + + $interfacename = str_replace('.data', '', $wandataallfile); + $interfacename = str_replace('/tmp/ifbwstats-', '', $interfacename); + $interfacename = str_replace('/cf/conf/ifbwstats-', '', $interfacename); + + echo '
'; + echo ''; + echo ''; + echo '
'.$interfacename.' Statistics Summary
'; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo '
DateDownloadedUploadedTotal Transfered
'; + echo '
'; + echo '
'; + echo ''; + $htmlcode = ''; + for ($i=0 ; $i < $n ; $i++ ) + { + $dataset=explode("|", $wandataall[$i]); + $dateset=explode("-", $dataset[0]); + $monthintotal = $monthintotal + $dataset[1]; + $monthouttotal = $monthouttotal + $dataset[2]; + $total = round((($dataset[1]+$dataset[2])/1024/1024/1024),2); + $dataset[1] = round(($dataset[1]/1024/1024),2); + $dataset[2] = round(($dataset[2]/1024/1024),2); + + //show daily stats + $htmlcode = $htmlcode.''; + + //if there is no more data, show month + if (($n-1) == $i) + { + $total = round((($monthintotal + $monthouttotal)/1024/1024/1024),2); + $monthintotal = round(($monthintotal/1024/1024/1024),2); + $monthouttotal = round(($monthouttotal/1024/1024/1024),2); + + $htmlcode = $htmlcode.''; + echo $htmlcode; + } + //if at the end of the billing cycle, erase month htlmcode as we only want to show the current month + if ($dateset[2] == ($firstday-1)) + { + $htmlcode = ''; + $monthintotal = 0; + $monthouttotal = 0; + } + + //if the billing cycle starts on the first day of the month, figure out the last day of the previous month, and if appropriate erase htmlcode + if ($firstday == '1') + { + //find the last day of the month + $maxday = date("t", strtotime($dateset[0]."-".$dateset[1]."-".$dateset[2])); + if ($dateset[2]==$maxday) + { + $htmlcode = ''; + $monthintotal = 0; + $monthouttotal = 0; + } + } + } + echo '
'.$dataset[0].''.$dataset[1].'MB'.$dataset[2].'MB'.$total.'GB
Current Month Total↓'.$monthintotal.'GB↑'.$monthouttotal.'GB↕'.$total.'GB
'; + echo '
'; + echo '
'; + echo '
'; + unset ($writedata); +//----------------------------------------end file statistics monthly display---------------------------------------- +} +//end foreach loop +echo '
'; + +include("fend.inc"); +echo ''; +echo ''; +?> \ No newline at end of file -- cgit v1.2.3