= 0) { for ($n=0; $n<$fndentry; $n++) $fpwrite .= $fpdata[$n]."\n"; for ($n=$fndentry+6; $n<$i-1; $n++) $fpwrite .= $fpdata[$n]."\n"; $fpwrite .= $fpdata[$i-1]; $fp = fopen('/etc/rc.shutdown',"w") or die("Error Reading File"); fwrite($fp, $fpwrite); fclose($fp); } //remove reboot entry $fp = fopen('/etc/rc.reboot',"r") or die("Error Reading File"); $data = fread($fp, filesize('/etc/rc.reboot')); fclose($fp); $fpdata = explode("\n", $data); $fpwrite = ''; $i = count($fpdata); $fndentry = -1; //found reboot entry for ($n=0; $n<$i; $n++) if ((strstr($fpdata[$n], '# ifBWStats:'))&&($fndentry < 0)) $fndentry = $n; if ($fndentry >= 0) { for ($n=0; $n<$fndentry; $n++) $fpwrite .= $fpdata[$n]."\n"; for ($n=$fndentry+6; $n<$i-1; $n++) $fpwrite .= $fpdata[$n]."\n"; $fpwrite .= $fpdata[$i-1]; $fp = fopen('/etc/rc.reboot',"w") or die("Error Reading File"); fwrite($fp, $fpwrite); fclose($fp); } //remove halt entry $fp = fopen('/etc/rc.halt',"r") or die("Error Reading File"); $data = fread($fp, filesize('/etc/rc.halt')); fclose($fp); $fpdata = explode("\n", $data); $fpwrite = ''; $i = count($fpdata); $fndentry = -1; //found halt entry for ($n=0; $n<$i; $n++) if ((strstr($fpdata[$n], '# ifBWStats:'))&&($fndentry < 0)) $fndentry = $n; if ($fndentry >= 0) { for ($n=0; $n<$fndentry; $n++) $fpwrite .= $fpdata[$n]."\n"; for ($n=$fndentry+6; $n<$i-1; $n++) $fpwrite .= $fpdata[$n]."\n"; $fpwrite .= $fpdata[$i-1]; $fp = fopen('/etc/rc.halt',"w") or die("Error Reading File"); fwrite($fp, $fpwrite); fclose($fp); } } function cleanup_data_file ($readfile, $writefile) { //----------------------------------------maintain file incase of errors in the file---------------------------------------- $wandataall = array(); $wandataarray = array(); //read data file $fp = fopen($readfile,"r") or die("Error Reading File"); $data = fread($fp, filesize($readfile)); fclose($fp); $wandataall = explode("\n", $data); $n = count($wandataall); //expode data into two dim. array for ($x=0; $x<$n; $x++) { $line = explode('|',$wandataall[$x]); // save it by coulmns otherwise it will saved like rows for ($i=0; $i<=2; $i++) { if ($i==0) $wandataarray[$x][$i] = date("Y-m-d", strtotime($line[$i])); else $wandataarray[$x][$i] = $line[$i]; } } //sort array into chronological order sort ($wandataarray); $m=$n; //check for multiple entries, and if so add them for ($x=0; $x<$n; $x++) { if (($wandataarray[$x][0] == $wandataarray[$x+1][0]) && ($x+1<$m)) { $wandataarray[$x][1] = $wandataarray[$x][1] + $wandataarray[$x+1][1]; $wandataarray[$x][2] = $wandataarray[$x][2] + $wandataarray[$x+1][2]; for ($i = $x+1; $i<$n; $i++) { if (!is_null($wandataarray[$i+1][0])) $wandataarray[$i][0]=$wandataarray[$i+1][0]; if (!is_null($wandataarray[$i+1][1])) $wandataarray[$i][1]=$wandataarray[$i+1][1]; if (!is_null($wandataarray[$i+1][2])) $wandataarray[$i][2]=$wandataarray[$i+1][2]; } $x--; $m--; } } //check for missing entries $nextday=$wandataarray[0][0]; $x=0; while ($x<$m) { //missing entry between days if ($nextday != $wandataarray[$x][0]) { $m++; for ($i=$m; $i>$x; $i--) { $wandataarray[$i][0] = $wandataarray[$i-1][0]; $wandataarray[$i][1] = $wandataarray[$i-1][1]; $wandataarray[$i][2] = $wandataarray[$i-1][2]; $wandataarray[$i][3] = $wandataarray[$i-1][3]; $wandataarray[$i][4] = $wandataarray[$i-1][4]; } //fill in 0 bytes transfered for missing days $wandataarray[$x][0] = $nextday; $wandataarray[$x][1] = 0; $wandataarray[$x][2] = 0; } $x++; //add one day to the date $nextday = date("Y-m-d", strtotime(date("Y-m-d", strtotime($nextday)) . " +1 day")); //echo 'x: '.$x.' m: '.$m.' array date: '.strtotime($wandataarray[$x-1][0]).' current date: '.strtotime(date("Y-m-d")).'
'; //add missing entries at end of file if required if (($x==$m)&&(strtotime($wandataarray[$x-1][0] ) < strtotime(date("Y-m-d")))) { $wandataarray[$x][0] = $nextday; $wandataarray[$x][1] = 0; $wandataarray[$x][2] = 0; $m++; } } //put array data into variable for wirting $writedata = ''; for ($x=0; $x<$m-1; $x++) $writedata .= $wandataarray[$x][0].'|'.$wandataarray[$x][1].'|'.$wandataarray[$x][2]."\n"; $writedata .= $wandataarray[$m-1][0].'|'.$wandataarray[$m-1][1].'|'.$wandataarray[$m-1][2]; //write data file $fp = fopen($writefile,"w") or die("Error Reading File"); fwrite($fp, $writedata); fclose($fp); //----------------------------------------end of file maintaince---------------------------------------- } ?>