]>
git.ipfire.org Git - thirdparty/sarg.git/blob - repday.c
2 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
6 * please look at http://sarg.sourceforge.net/donations.php
8 * http://sourceforge.net/projects/sarg/forums/forum/363374
9 * ---------------------------------------------------------------------
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
27 #include "include/conf.h"
28 #include "include/defs.h"
32 void report_day(const struct userinfostruct
*uinfo
)
46 int daylist
[MAX_DATETIME_DAYS
];
47 int daysort
[MAX_DATETIME_DAYS
];
53 long long int tbytes
[MAX_DATETIME_DAYS
*24];
54 long long int telap
[MAX_DATETIME_DAYS
*24];
56 long long int tttime
[24];
58 struct getwordstruct gwarea
;
61 snprintf(wdirname
,sizeof(wdirname
),"%s/%s.day",tmp
,uinfo
->filename
);
62 if(access(wdirname
, R_OK
) != 0) return;
64 if (snprintf(arqout
,sizeof(arqout
),"%s/%s/d%s.html",outdirname
,uinfo
->filename
,uinfo
->filename
)>=sizeof(arqout
)) {
65 debuga(_("Output file name too long: %s/%s/d%s.html\n"),outdirname
,uinfo
->filename
,uinfo
->filename
);
69 if((fp_in
=fopen(wdirname
,"r"))==NULL
) {
70 debuga(_("(repday) Cannot open log file %s\n"),wdirname
);
74 memset(tbytes
,0,sizeof(tbytes
));
75 memset(telap
,0,sizeof(telap
));
78 while(fgets(buf
,sizeof(buf
),fp_in
)!=NULL
) {
80 getword_start(&gwarea
,buf
);
81 if (getword(data
,sizeof(data
),&gwarea
,'\t')<0) {
82 debuga(_("Invalid date in file %s\n"),wdirname
);
85 if (sscanf(data
,"%d/%d/%d",&day
,&month
,&year
)!=3) continue;
86 if (day
<1 || day
>31 || month
<1 || month
>12 || year
>9999) continue;
87 daynum
=(year
*10000)+(month
*100)+day
;
88 for (dayidx
=0 ; dayidx
<ndaylist
&& daynum
!=daylist
[dayidx
] ; dayidx
++);
89 if (dayidx
>=ndaylist
) {
90 if (dayidx
>=sizeof(daylist
)/sizeof(*daylist
)) {
91 debuga(_("Too many different dates in %s\n"),wdirname
);
94 daylist
[ndaylist
++]=daynum
;
97 if (getword_atoll(&hour
,&gwarea
,'\t')<0) {
98 debuga(_("Invalid time in file %s\n"),wdirname
);
104 if ((datetimeby
& DATETIME_BYTE
)!=0) {
105 colsep
=((datetimeby
& DATETIME_ELAP
)!=0) ? '\t' : '\0';
106 if (getword_atoll(&bytes
,&gwarea
,colsep
)<0) {
107 debuga(_("Invalid number of bytes in file %s\n"),wdirname
);
112 if ((datetimeby
& DATETIME_ELAP
)!=0) {
113 if (getword_atoll(&elap
,&gwarea
,'\0')<0) {
114 debuga(_("Invalid elapsed time in file %s\n"),wdirname
);
122 if((fp_ou
=fopen(arqout
,"w"))==NULL
) {
123 debuga(_("(repday) Cannot open log file %s\n"),arqout
);
127 write_html_header(fp_ou
,(IndexTree
== INDEX_TREE_DATE
) ? 4 : 2,_("Day report"));
128 fprintf(fp_ou
,"<tr><td class=\"header_c\" colspan=\"2\">%s: %s</td></tr>\n",_("Period"),period
.html
);
129 fprintf(fp_ou
,"<tr><th class=\"header_c\" colspan=\"2\">%s: %s</th></tr>\n",_("User"),uinfo
->label
);
130 close_html_header(fp_ou
);
133 for (i
=0 ; i
<ndaylist
; i
++) {
135 for (j
=dayidx
; j
>0 && daynum
<daylist
[daysort
[j
-1]] ; j
--) daysort
[j
]=daysort
[j
-1];
140 if((datetimeby
& DATETIME_BYTE
)!=0) {
142 fputs("<table class=\"report\" cellpadding=\"0\" cellspacing=\"2\">\n", fp_ou
);
143 fputs("<tr><th class=\"header_c\"></th>",fp_ou
);
144 for( i
= 0; i
< hours
.len
; i
++ )
145 fprintf(fp_ou
, "<td class=\"header_c\">%02d%s<br>%s</td>\n", hours
.list
[ i
], _("H"), label
);
146 fprintf(fp_ou
, "<td class=\"header_c\">%s<br>%s</td></tr>\n", _("TOTAL"), label
);
148 memset(tttime
,0,sizeof(tttime
));
149 for (dayidx
=0 ; dayidx
<ndaylist
; dayidx
++) {
150 daynum
=daysort
[dayidx
];
151 day
=daylist
[daynum
]%100;
152 month
=(daylist
[daynum
]/100)%100;
153 year
=daylist
[daynum
]/10000;
154 computedate(year
,month
,day
,&t
);
155 strftime(data
,sizeof(data
),"%x",&t
);
156 fprintf(fp_ou
, "<tr><td class=\"data\">%s</td>\n", data
);
158 for( i
= 0; i
< hours
.len
; i
++ ) {
160 if (tbytes
[daynum
*24+ihour
]>0) {
161 fprintf(fp_ou
, "<td class=\"data\">%s</td>\n",fixnum(tbytes
[daynum
*24+ihour
],1));
162 tt
+=tbytes
[daynum
*24+ihour
];
163 tttime
[ihour
]+=tbytes
[daynum
*24+ihour
];
165 fputs("<td class=\"data\"></td>\n",fp_ou
);
167 fprintf(fp_ou
, "<td class=\"data\">%s</td></tr>\n",fixnum(tt
,1));
170 fprintf(fp_ou
, "<tr><td class=\"header_l\">%s</td>\n", _("TOTAL") );
172 for( i
= 0; i
< hours
.len
; i
++ ) {
174 fprintf(fp_ou
, "<td class=\"header_r\">%s</td>\n",fixnum(tttime
[i
],1));
177 fputs("<td class=\"header_r\"></td>\n",fp_ou
);
179 fprintf(fp_ou
, "<td class=\"header_r\">%s</td></tr>\n",fixnum(tt
,1));
180 fputs("</table>\n",fp_ou
);
183 if((datetimeby
& DATETIME_ELAP
)!=0) {
185 fputs("<table class=\"report\" cellpadding=\"0\" cellspacing=\"2\">\n", fp_ou
);
186 fputs("<tr><th class=\"header_c\"></th>",fp_ou
);
187 for( i
= 0; i
< hours
.len
; i
++ )
188 fprintf(fp_ou
, "<td class=\"header_c\">%02d%s<br>%s</td>\n", hours
.list
[ i
], _("H"), label
);
189 fprintf(fp_ou
, "<td class=\"header_c\">%s<br>%s</td></tr>\n", _("TOTAL"), label
);
191 memset(tttime
,0,sizeof(tttime
));
192 for (dayidx
=0 ; dayidx
<ndaylist
; dayidx
++) {
193 daynum
=daysort
[dayidx
];
194 day
=daylist
[daynum
]%100;
195 month
=(daylist
[daynum
]/100)%100;
196 year
=daylist
[daynum
]/10000;
197 computedate(year
,month
,day
,&t
);
198 strftime(data
,sizeof(data
),"%x",&t
);
199 fprintf(fp_ou
, "<tr><td class=\"data\">%s</td>\n", data
);
201 for( i
= 0; i
< hours
.len
; i
++ ) {
203 if (telap
[daynum
*24+ihour
]>0) {
204 fprintf(fp_ou
, "<td class=\"data\">%s</td>\n",fixtime(telap
[daynum
*24+ihour
]));
205 tt
+=telap
[daynum
*24+ihour
];
206 tttime
[ihour
]+=telap
[daynum
*24+ihour
];
208 fputs("<td class=\"data\"></td>\n",fp_ou
);
210 fprintf(fp_ou
, "<td class=\"data\">%s</td></tr>\n",fixtime(tt
));
213 fprintf(fp_ou
, "<tr><td class=\"header_l\">%s</td>\n", _("TOTAL") );
215 for( i
= 0; i
< hours
.len
; i
++ ) {
217 fprintf(fp_ou
, "<td class=\"header_r\">%s</td>\n",fixtime(tttime
[i
]));
220 fputs("<td class=\"header_r\"></td>\n",fp_ou
);
222 fprintf(fp_ou
, "<td class=\"header_r\">%s</td></tr>\n",fixtime(tt
));
223 fputs("</table>\n",fp_ou
);
226 if (write_html_trailer(fp_ou
)<0)
227 debuga(_("Write error in file %s\n"),arqout
);
228 if (fclose(fp_ou
)==EOF
)
229 debuga(_("Failed to close file %s - %s\n"),arqout
,strerror(errno
));