'; include("fbegin.inc"); echo '

ifBWStats: Monthly Statistics

'; //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", false, "ifbwstats_cur.php"); $tab_array[1] = array ("Monthly", true, "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; $monthdaystart = 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 '
Month EndingDownloadedUploadedTotal Transfered
'; echo '
'; echo '
'; //echo '
'; echo ''; 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 /*echo ''; echo ''; echo ''; echo ''; echo ''; echo '';*/ //as data file saved by day, determin if a monthy total is required to be shown based on setting 'first day of billing period' $showmonth = '0'; //if at the end of the billing cycle show month totals, 1 to indicate that a full billing period has passed and to show a 'month end' total if ($dateset[2] == ($firstday-1)) $showmonth = '1'; //if there is no more data, show month totals, 2 to show 'current month' if (($n-1) == $i) $showmonth = '2'; //if the billing cycle starts on the first day of the month, figure out the last day of the previous month, and if appropriate show month totals if ($firstday == '1') { //find the last day of the month $maxday = date("t", strtotime($dateset[0]."-".$dateset[1]."-".$dateset[2])); if ($dateset[2]==$maxday) $showmonth = '1'; } if (($showmonth == '1')||($showmonth == '2')) { $total = round((($monthintotal + $monthouttotal)/1024/1024/1024),2); $monthintotal = round(($monthintotal/1024/1024/1024),2); $monthouttotal = round(($monthouttotal/1024/1024/1024),2); if ($showmonth == '2') $dataset[0]='Current%20Month'; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; $monthdaystart = $i + 1; $monthintotal = 0; $monthouttotal = 0; } } echo '
'.$dataset[0].''.$dataset[1].'MB'.$dataset[2].'MB'.$total.'GB
'.str_replace('%20', ' ', $dataset[0]).'↓'.$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 ''; ?>