1#!/usr/local/bin/perl 2# 3# LightSquid Project (c) 2004-2005 Sergey Erokhin aka ESL 4# 5# This program is free software; you can redistribute it and/or 6# modify it under the terms of the GNU General Public License 7# as published by the Free Software Foundation; either version 2 8# of the License, or (at your option) any later version. 9# 10# detail see in gnugpl.txt 11 12use File::Basename; 13push( @INC, ( fileparse($0) )[1] ); 14 15use CGI; 16require "/usr/local/etc/lightsquid/lightsquid.cfg"; 17require "common.pl"; 18 19$co = new CGI; 20 21$year = $co->param('year'); 22$month = $co->param('month'); 23$user = $co->param('user'); 24$mode = $co->param('mode'); 25 26print "Content-Type: text/html\n\n"; 27 28InitTPL("user_month",$co->param('tpl')); 29 30$workperiod = "$MonthName[$month] $year"; 31ReplaceTPL( WORKPERIOD, $workperiod ); 32 33$week_id=0; 34$week_date=$date; 35 36$average = 0; 37$days = 0; 38$filter = "$year$month"; 39@daylist = sort glob("$reportpath/$filter*"); 40@daylist = reverse @daylist; 41foreach $daypath (@daylist ) { 42 open FF, "<$daypath/.total"; 43 $tmp = <FF>; $size = <FF>; 44# $daypath =~ m/(\d\d\d\d)(\d\d)(\d\d)/; 45 46 $daypath =~ m#$reportpath/(.*)#; 47 $date=$1; 48 $date =~ m/^(\d\d\d\d)(\d\d)(\d\d)/; 49 $urldate="year=$1&month=$2&day=$3"; 50 51 $printdate= GetTxtDate($date); 52 53 $weekday = GetWeekDayDate($date); 54 55 $weeksumtpl=""; 56 if ($weekday == 0) { 57 $week_id++; 58 $weeksumtpl="##WEEKSUM$week_id##"; 59 $weeksum[$week_id]=0; 60 } 61 62 $size="?"; 63 64 while (<FF>) { 65 ( $user_, $size_, $hit ) = split; 66 next if ( $user_ ne $user ); 67 $cumulative += $size_; 68 $size = $size_; 69 } 70 71 $weeksum[$week_id]+=$size if ($size ne "?"); 72 73 $printsize =($size eq "?")?"?":FineDec($size); 74 $printcumulative =FineDec($cumulative); 75 76 $daydate_L =URLEncode("user_detail.cgi?$urldate&user=$user"); $daydate_B ="$printdate"; 77 78 $dayattr = ($weekday & 1 )?$hTPLVARIABLE{oddattr}:$hTPLVARIABLE{evenattr}; 79 $dayattr = $hTPLVARIABLE{sundayattr} if ($weekday == 0); 80 $dayattr = $hTPLVARIABLE{saturdayattr} if (($weekday == 6) && ($weekendmode eq "both")); 81 82 83 $oversizeattr=(($perusertrafficlimit>0) && ($size > $perusertrafficlimit))?$hTPLVARIABLE{oversizedattr}:$hTPLVARIABLE{nooversizedattr}; 84 85 86 $tmp=$hTPL{day}; 87 $tmp=~s/##DAYDATE_L##/$daydate_L/; 88 $tmp=~s/##DAYDATE_B##/$daydate_B/; 89 $tmp=~s/##DAYBYTES##/$printsize/; 90 $tmp=~s/##DAYCUMULATIVE##/$printcumulative/; 91 $tmp=~s/##WEEKSUM##/$weeksumtpl/; 92 $tmp=~s/##DAYATTR##/$dayattr/; 93 $tmp=~s/##OVERSIZEATTR##/$oversizeattr/; 94 $tpl{day} .= $tmp; 95 96 97 $days++; 98 close FF; 99} 100 101 102 103$graphurl_L=URLEncode("graph.cgi?year=$year&month=$month&mode=user&user=$user"); 104$graphurl_B="##MSG_GRAPH_LINK##"; 105 106ReplaceTPL_URL(GRAPHURL,$graphurl_L,$graphurl_B); 107 108ReplaceTPL(USER,$user); 109ReplaceTPL(WORKPERIOD,$workperiod); 110ReplaceTPL(TOTALBYTES,$printcumulative); 111 112for ($i=0;$i<=$week_id;$i++) { 113 ReplaceTPL("WEEKSUM$i",FineDec($weeksum[$i])); 114} 115 116ApplyTPL(); 117PrintTPL(); 118 119__END__ 1202005-10-06 ADD : Initial release 1212006-06-28 ADD : &tpl= support 1222006-07-01 ADD : RIC, add sunday highlight 123