Using file "":
checked>
checked>
checked>
checked>
checked>
checked>



=86400) { $d++; $s-=86400; } while ($s>=3600) { $h++; $s-=3600; } while ($s>=60) { $m++; $s-=60; } if ($d) $str.=$d ."d "; if ($h) $str.=$h ."h "; if ($m) $str.=$m ."m "; $str.=$s."s"; return $str; } function calc_size($b) { $g=(int)($b/(1024*1024*1024)); /* GB */ $m=(int)($b/(1024*1024)); /* MB */ $k=(int)($b/1024); /* KB */ if ($g) return sprintf("%.2f GB", $b/(1024*1024*1024)); if ($m) return sprintf("%.2f MB", $b/(1024*1024)); if ($k) return sprintf("%.2f KB", $b/1024); return $b." bytes"; } /* parsing */ for ($line=0,$all_ones=0,$logfile=file($file);isset($logfile[$line]);$line++) { $tmp[0]=$tmp[1]=$tmp[2]=$tmp[3]=0; $tmp=explode("#", $logfile[$line]); /* only if 3 # are here */ if (!$tmp[0] || !$tmp[1] || !$tmp[2] || !$tmp[3]) continue; $entry=1; /* we have digits only ? */ if (strcspn($tmp[0], "1234567890")>0) $entry=0; if (strcspn($tmp[1], "1234567890")>0) $entry=0; if (strcspn($tmp[2], "1234567890")>0) $entry=0; if (strcspn($tmp[3], "1234567890")>0) $entry=0; if ($entry) { /* yes, we have */ $all_ones++; /* add them, to our arrays */ $outTIME[]=$tmp[0]; /* logout @time*/ $coTIME[]=$tmp[1]; /* time, we were connected */ $sBYTES[]=$tmp[2]; /* send bytes */ $rBYTES[]=$tmp[3]; /* recv bytes */ $inTIME[]=$tmp[0]-$tmp[1]; /* when we got in */ } } /* EOF, for each line */ /* now, calc stats: */ $d_all_time=0; $d_all_send=0; $d_all_recv=0; /* daily stats */ $m_all_time=0; $m_all_send=0; $m_all_recv=0; /* monthly stats */ $w_all_time=0; $w_all_send=0; $w_all_recv=0; /* weekly stats */ $y_all_time=0; $y_all_send=0; $y_all_recv=0; /* yearly stats */ $t_all_time=0; $t_all_send=0; $t_all_recv=0; /* total stats */ $l_year=$l_month=$l_week=$l_day=0; /* last ones */ echo ""; for ($no_summary=1,$entry=0;$entry<$all_ones;$entry++) { /* current entry times */ $c_year= date("Y", $inTIME[$entry]); /* year counter */ $c_month = $name_month[date("n", $inTIME[$entry])-1]; /* 0..11 (month) */ $c_week=strftime("%V", $inTIME[$entry]); /* week counter 1..53 */ $c_day = date("j", $inTIME[$entry]) .". (". $name_day[date("w", $inTIME[$entry])] .")"; /* 0-6 */ /* we have to choose between year/month/week/day updates */ if ($c_year!=$l_year) {$year=1;$month=1;$week=1;$day=1;} if ($c_year==$l_year && $c_month!=$l_month) {$month=1;$week=1;$day=1;} if ($c_year==$l_year && $c_month==$l_month && $c_week!=$l_week) {$week=1;$day=1;} if ($c_year==$l_year && $c_month==$l_month && $c_week==$l_week && $c_day!=$l_day) $day=1; if (isset($no_summary)) { $day=$week=$month=$year=0; unset($no_summary); } if ($day) { $day=0; $time=mkit_from_secs($d_all_time); if ($want_bytes) { $in=number_format($d_all_recv, 0, ",","."); $out=number_format($d_all_send, 0, ",","."); $in_out=number_format($d_all_send+$d_all_recv, 0, ",","."); } else { $in=calc_size($d_all_recv); $out=calc_size($d_all_send); $in_out=calc_size($d_all_recv+$d_all_send);; } if ($want_daily) echo ""; $w_all_time+=$d_all_time; /* add them to weekly stats */ $w_all_send+=$d_all_send; $w_all_recv+=$d_all_recv; $d_all_time=$d_all_send=$d_all_recv=0; /* reset daily stats */ } /* calc stats from current login */ $d_all_time+=$coTIME[$entry]; $d_all_send+=$sBYTES[$entry]; $d_all_recv+=$rBYTES[$entry]; if ($week) { $week=0; $time=mkit_from_secs($w_all_time); if ($want_bytes) { $in=number_format($w_all_recv, 0, ",","."); $out=number_format($w_all_send, 0, ",","."); $in_out=number_format($w_all_send+$w_all_recv, 0, ",","."); } else { $in=calc_size($w_all_recv); $out=calc_size($w_all_send); $in_out=calc_size($w_all_recv+$w_all_send);; } if ($want_weekly) echo ""; $m_all_time+=$w_all_time; /* add weekly to monthly stats */ $m_all_send+=$w_all_send; $m_all_recv+=$w_all_recv; $w_all_time=$w_all_send=$w_all_recv=0; /* reset weekly stats */ } /* print monthly stats */ if ($month) { $month=0; $time=mkit_from_secs($m_all_time); if ($want_bytes) { $in=number_format($m_all_recv, 0, ",","."); $out=number_format($m_all_send, 0, ",","."); $in_out=number_format($m_all_send+$m_all_recv, 0, ",","."); } else { $in=calc_size($m_all_recv); $out=calc_size($m_all_send); $in_out=calc_size($m_all_send+$m_all_recv); } if ($want_monthly) echo ""; $y_all_time+=$m_all_time; /* add them to yearly stats */ $y_all_send+=$m_all_send; $y_all_recv+=$m_all_recv; $m_all_time=$m_all_send=$m_all_recv=0; /* reset monthly stats */ } /* print yaerly stats */ if ($year) { $year=0; $time=mkit_from_secs($y_all_time); if ($want_bytes) { $in=number_format($y_all_recv, 0, ",","."); $out=number_format($y_all_send, 0, ",","."); $in_out=number_format($y_all_send+$y_all_recv, 0, ",","."); } else { $in=calc_size($y_all_recv); $out=calc_size($y_all_send); $in_out=calc_size($y_all_send+$y_all_recv); } if ($want_yearly) echo ""; $t_all_time+=$y_all_time; /* add them to total stats */ $t_all_send+=$y_all_send; $t_all_recv+=$y_all_recv; $y_all_time=$y_all_send=$y_all_recv=0; /* reset yearly stats */ } /* print login stats (always) */ $from_to=date("H:i:s", $inTIME[$entry]) . " - " . date("H:i:s", $outTIME[$entry]); $time=mkit_from_secs($coTIME[$entry]); if ($want_bytes) { $in= number_format($rBYTES[$entry],0, ",","."); $out= number_format($sBYTES[$entry],0, ",","."); $in_out= number_format($sBYTES[$entry]+$rBYTES[$entry],0, ",","."); } else { $in=calc_size($rBYTES[$entry]); $out=calc_size($sBYTES[$entry]); $in_out=calc_size($sBYTES[$entry]+$rBYTES[$entry]); } echo ""; /* last one ist now current */ $l_year=$c_year; $l_month=$c_month; $l_week=$c_week; $l_day=$c_day; } /* EOF for(entrys) */ $time=mkit_from_secs($d_all_time); if ($want_bytes) { $in=number_format($d_all_recv, 0, ",","."); $out=number_format($d_all_send, 0, ",","."); $in_out=number_format($d_all_send+$d_all_recv, 0, ",","."); } else { $in=calc_size($d_all_recv); $out=calc_size($d_all_send); $in_out=calc_size($d_all_recv+$d_all_send);; } if ($want_daily) echo ""; $w_all_time+=$d_all_time; /* add them to monthly stats */ $w_all_send+=$d_all_send; $w_all_recv+=$d_all_recv; $time=mkit_from_secs($w_all_time); if ($want_bytes) { $in=number_format($w_all_recv, 0, ",","."); $out=number_format($w_all_send, 0, ",","."); $in_out=number_format($w_all_send+$w_all_recv, 0, ",","."); } else { $in=calc_size($w_all_recv); $out=calc_size($w_all_send); $in_out=calc_size($w_all_recv+$w_all_send);; } if ($want_weekly) echo ""; $m_all_time+=$w_all_time; /* add weekly to monthly stats */ $m_all_send+=$w_all_send; $m_all_recv+=$w_all_recv; $time=mkit_from_secs($m_all_time); if ($want_bytes) { $in=number_format($m_all_recv, 0, ",","."); $out=number_format($m_all_send, 0, ",","."); $in_out=number_format($m_all_send+$m_all_recv, 0, ",","."); } else { $in=calc_size($m_all_recv); $out=calc_size($m_all_send); $in_out=calc_size($m_all_send+$m_all_recv); } if ($want_monthly) echo ""; $y_all_time+=$m_all_time; /* add them to yearly stats */ $y_all_send+=$m_all_send; $y_all_recv+=$m_all_recv; $time=mkit_from_secs($y_all_time); if ($want_bytes) { $in=number_format($y_all_recv, 0, ",","."); $out=number_format($y_all_send, 0, ",","."); $in_out=number_format($y_all_send+$y_all_recv, 0, ",","."); } else { $in=calc_size($y_all_recv); $out=calc_size($y_all_send); $in_out=calc_size($y_all_send+$y_all_recv); } if ($want_yearly) echo ""; $t_all_time+=$y_all_time; /* add them to total stats */ $t_all_send+=$y_all_send; $t_all_recv+=$y_all_recv; $time=mkit_from_secs($t_all_time); if ($want_bytes) { $in=number_format($t_all_recv, 0, ",","."); $out=number_format($t_all_send, 0, ",","."); $in_out=number_format($t_all_send+$t_all_recv, 0, ",","."); } else { $in=calc_size($t_all_recv); $out=calc_size($t_all_send); $in_out=calc_size($t_all_send+$t_all_recv); } if ($want_total) echo ""; echo "
DATE FROM - TO TIME IN OUT ALL
$l_day $time $in $out $in_out
$l_week. $w_name $time $in $out $in_out
$l_month $time $in $out $in_out

 
$y_name $l_year $time $in $out $in_out

 
  $from_to $time $in $out $in_out
$l_day $time $in $out $in_out
$l_week. $w_name $time $in $out $in_out
$l_month $time $in $out $in_out

 
$l_year $time $in $out $in_out

 
all traffic: $time $in $out $in_out
"; ?>