]> git.ipfire.org Git - thirdparty/sarg.git/blame - html.c
Don't generate the date/time report page if it isn't used
[thirdparty/sarg.git] / html.c
CommitLineData
25697a35 1/*
94ff9470 2 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
67302a9e 3 * 1998, 2013
25697a35
GS
4 *
5 * SARG donations:
6 * please look at http://sarg.sourceforge.net/donations.php
1164c474
FM
7 * Support:
8 * http://sourceforge.net/projects/sarg/forums/forum/363374
25697a35
GS
9 * ---------------------------------------------------------------------
10 *
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.
15 *
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.
20 *
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.
24 *
25 */
26
27#include "include/conf.h"
5f3cfd1d 28#include "include/defs.h"
25697a35 29
9dc20988
FM
30extern struct globalstatstruct globstat;
31
32e71fa4 32void htmlrel(void)
25697a35 33{
aa6ac9f2 34 FILE *fp_in, *fp_ou, *fp_ip, *fp_ip2;
9bd92830 35
9bd92830
FM
36 long long int nnbytes=0, unbytes=0, tnbytes=0, totbytes=0, totbytes2=0;
37 long long int totelap=0, totelap2=0, nnelap=0, unelap=0, tnelap=0;
38 long long int incache=0, oucache=0, tnincache=0, tnoucache=0, twork=0;
39 long long int ltemp;
e5b3a129 40 long long int ntotuser;
9bd92830
FM
41 long long int userbytes, userelap;
42 char *buf;
e5b3a129 43 char arqin[MAXLEN], arqou[MAXLEN], arqip[MAXLEN];
9bd92830 44 char *url, tmsg[50], csort[MAXLEN];
93551487 45 char duser[MAXLEN];
9bd92830 46 char user_ip[MAXLEN], olduserip[MAXLEN], tmp2[MAXLEN], tmp3[MAXLEN];
9bd92830 47 char warea[MAXLEN];
9bd92830
FM
48 char tmp6[MAXLEN];
49 char *user_url;
5025f299 50 long long int tnacc=0, ttnacc=0;
9bd92830
FM
51 double perc=0, perc2=0, ouperc=0, inperc=0;
52 int count;
53 int cstatus;
f6bcfe7d 54 bool have_denied_report;
9bd92830
FM
55 const char *sort_field;
56 const char *sort_order;
9bd92830
FM
57 char siteind[MAX_TRUNCATED_URL];
58 struct getwordstruct gwarea;
59 longline line,line1;
aa6ac9f2 60 struct userinfostruct *uinfo;
93551487 61 userscan uscan;
9bd92830 62
c98d6a0f
FM
63 if (snprintf(tmp2,sizeof(tmp2),"%s/sargtmp.int_unsort",tmp)>=sizeof(tmp2)) {
64 debuga(_("File name too long: %s/sargtmp.int_unsort\n"),tmp);
8d811f76
FM
65 exit(EXIT_FAILURE);
66 }
9bd92830 67
c98d6a0f
FM
68 if (snprintf(tmp3,sizeof(tmp3),"%s/sargtmp.int_log",tmp)>=sizeof(tmp3)) {
69 debuga(_("File name too long: %s/sargtmp.int_log\n"),tmp);
8d811f76
FM
70 exit(EXIT_FAILURE);
71 }
9bd92830 72
9dc20988
FM
73 tnacc=globstat.nacc;
74 totbytes=globstat.nbytes;
75 totelap=globstat.elap;
e5b3a129 76 ntotuser=globstat.totuser;
9bd92830 77
9bd92830
FM
78 sort_labels(&sort_field,&sort_order);
79
93551487
FM
80 uscan=userinfo_startscan();
81 if (uscan == NULL) {
82 debuga(_("Cannot enumerate the user list\n"));
9bd92830
FM
83 exit(EXIT_FAILURE);
84 }
93551487 85 while ( (uinfo = userinfo_advancescan(uscan)) != NULL ) {
e5b3a129
FM
86 if (snprintf(warea,sizeof(warea),"%s/%s",outdirname,uinfo->filename)>=sizeof(warea)) {
87 debuga(_("Destination directory too long: %s/%s\n"),outdirname,uinfo->filename);
9bd92830
FM
88 exit(EXIT_FAILURE);
89 }
c649f9b7
FM
90 if (!uinfo->topuser) {
91 //! \todo Instead of deleting the supernumerary directories, don't create them in the first place.
92 unlinkdir(warea,0);
93 continue;
94 }
95
affa72c5
FM
96 if (access(warea, R_OK) != 0) {
97 if (mkdir(warea,0755)) {
98 debuga(_("Cannot create directory %s - %s\n"),warea,strerror(errno));
99 exit(EXIT_FAILURE);
100 }
101 }
c649f9b7 102 tmpsort(uinfo);
9bd92830 103
e5b3a129
FM
104 if (snprintf(arqin,sizeof(arqin),"%s/htmlrel.txt",tmp)>=sizeof(arqin)) {
105 debuga(_("Input file name too long: %s/htmlrel.txt\n"),tmp);
93551487
FM
106 exit(EXIT_FAILURE);
107 }
108 if ((fp_in = fopen(arqin, "r")) == 0){
109 if (uinfo->no_report) continue;
d6f0349d 110 debuga(_("(html3) Cannot open file %s: %s\n"),arqin,strerror(errno));
9bd92830
FM
111 exit(EXIT_FAILURE);
112 }
93551487 113
9bd92830
FM
114 if (snprintf(arqou,sizeof(arqou),"%s/%s/%s.html",outdirname,uinfo->filename,uinfo->filename)>=sizeof(arqou)) {
115 debuga(_("Output file name too long: %s/%s/%s.html\n"),outdirname,uinfo->filename,uinfo->filename);
116 exit(EXIT_FAILURE);
117 }
f6bcfe7d
FM
118 if (snprintf(duser,sizeof(duser),"%s/denied_%s.html",outdirname,uinfo->filename)>=sizeof(duser)) {
119 debuga(_("File name too long: %s/denied_%s.html\n"),outdirname,uinfo->filename);
9bd92830
FM
120 exit(EXIT_FAILURE);
121 }
122 if(access(duser, R_OK) != 0)
f6bcfe7d 123 have_denied_report=false;
93551487 124 else
f6bcfe7d 125 have_denied_report=true;
9bd92830
FM
126
127 if ((line=longline_create())==NULL) {
128 debuga(_("Not enough memory to read file %s\n"),arqin);
129 exit(EXIT_FAILURE);
130 }
131
132 tnacc=0;
133 tnbytes=0;
134 tnelap=0;
135 tnincache=0;
136 tnoucache=0;
137 while((buf=longline_read(fp_in,line))!=NULL) {
138 getword_start(&gwarea,buf);
139 if (getword_atoll(&ltemp,&gwarea,'\t')<0) {
140 debuga(_("There is a broken number of access in file %s\n"),arqin);
141 exit(EXIT_FAILURE);
142 }
143 tnacc+=ltemp;
144 if (getword_atoll(&ltemp,&gwarea,'\t')<0) {
145 debuga(_("There is a broken downloaded size in file %s\n"),arqin);
146 exit(EXIT_FAILURE);
147 }
148 tnbytes+=ltemp;
149 if (getword_ptr(NULL,NULL,&gwarea,'\t')<0) {
150 debuga(_("There is a broken url in file %s\n"),arqin);
151 exit(EXIT_FAILURE);
152 }
153 if (getword_skip(MAXLEN,&gwarea,'\t')<0) {
154 debuga(_("There is a broken access code in file %s\n"),arqin);
155 exit(EXIT_FAILURE);
156 }
157 if (getword_atoll(&ltemp,&gwarea,'\t')<0) {
158 debuga(_("There is a broken elapsed time in file %s\n"),arqin);
159 exit(EXIT_FAILURE);
160 }
161 tnelap+=ltemp;
162 if (getword_atoll(&ltemp,&gwarea,'\t')<0) {
163 debuga(_("There is a broken in-cache volume in file %s\n"),arqin);
164 exit(EXIT_FAILURE);
165 }
166 tnincache+=ltemp;
167 if (getword_atoll(&ltemp,&gwarea,'\n')<0) {
168 debuga(_("There is a broken out-cache volume in file %s\n"),arqin);
169 exit(EXIT_FAILURE);
170 }
171 tnoucache+=ltemp;
172 }
173
174 rewind(fp_in);
175
176 if ((fp_ou = fopen(arqou, "w")) == 0){
d6f0349d 177 debuga(_("(html5) Cannot open file %s: %s\n"),arqou,strerror(errno));
9bd92830
FM
178 exit(EXIT_FAILURE);
179 }
180
181 write_html_header(fp_ou,(IndexTree == INDEX_TREE_DATE) ? 4 : 2,_("User report"),HTML_JS_SORTTABLE);
182 fprintf(fp_ou,"<tr><td class=\"header_c\">%s:&nbsp;%s</td></tr>\n",_("Period"),period.html);
183 fprintf(fp_ou,"<tr><td class=\"header_c\">%s:&nbsp;%s</td></tr>\n",_("User"),uinfo->label);
184 fputs("<tr><td class=\"header_c\">",fp_ou);
185 fprintf(fp_ou,_("Sort:&nbsp;%s, %s"),sort_field,sort_order);
186 fputs("</td></tr>\n",fp_ou);
187 fprintf(fp_ou,"<tr><th class=\"header_c\">%s</th></tr>\n",_("User report"));
188 close_html_header(fp_ou);
189
f6bcfe7d
FM
190 if (have_denied_report) {
191 fputs("<div class=\"report\"><table cellpadding=\"1\" cellspacing=\"2\">\n",fp_ou);
192 fprintf(fp_ou,"<tr><td class=\"header_l\" colspan=\"11\"><a href=\"denied_%s.html\">%s</a></td></tr>\n",uinfo->filename,_("SmartFilter report"));
193 fputs("<tr><td></td></tr>\n</table></div>\n",fp_ou);
194 }
195
9bd92830
FM
196 fputs("<div class=\"report\"><table cellpadding=\"2\" cellspacing=\"1\"",fp_ou);
197 if (SortTableJs[0]) fputs(" class=\"sortable\"",fp_ou);
198 fputs(">\n",fp_ou);
199
9bd92830
FM
200 fputs("<thead><tr><th class=\"sorttable_nosort\"></th><th class=\"header_l",fp_ou);
201 if (SortTableJs[0]) fputs(" sorttable_alpha",fp_ou);
202 fprintf(fp_ou,"\">%s</th>",_("ACCESSED SITE"));
203
204 if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0)
205 fprintf(fp_ou,"<th class=\"header_l\">%s</th>",_("CONNECT"));
206 if((UserReportFields & USERREPORTFIELDS_BYTES) != 0)
207 fprintf(fp_ou,"<th class=\"header_l\">%s</th>",_("BYTES"));
208 if((UserReportFields & USERREPORTFIELDS_SETYB) != 0)
eb7ab620 209 fprintf(fp_ou,"<th class=\"header_l\">%s</th>",_("%BYTES"));
9bd92830
FM
210 if((UserReportFields & USERREPORTFIELDS_IN_CACHE_OUT) != 0)
211 fprintf(fp_ou,"<th class=\"header_c\" colspan=\"2\">%s</th><th style=\"display:none;\"></th>",_("IN-CACHE-OUT"));
212 if((UserReportFields & USERREPORTFIELDS_USED_TIME) != 0)
213 fprintf(fp_ou,"<th class=\"header_l\">%s</th>",_("ELAPSED TIME"));
214 if((UserReportFields & USERREPORTFIELDS_MILISEC) != 0)
215 fprintf(fp_ou,"<th class=\"header_l\">%s</th>",_("MILLISEC"));
216 if((UserReportFields & USERREPORTFIELDS_PTIME) != 0)
eb7ab620 217 fprintf(fp_ou,"<th class=\"header_l\">%s</th>",pgettext("duration","%TIME"));
9bd92830
FM
218
219 fputs("</tr></thead>\n",fp_ou);
220
221 if(debug) {
222 debuga(_("Making report: %s\n"),uinfo->id);
223 }
ddcf5214 224 count=0;
a5267dd6 225 arqip[0]='\0';
9bd92830
FM
226
227 while((buf=longline_read(fp_in,line))!=NULL) {
228 getword_start(&gwarea,buf);
229 if (getword_atoll(&twork,&gwarea,'\t')<0) {
230 debuga(_("There is a broken number of access in file %s\n"),arqin);
231 exit(EXIT_FAILURE);
232 }
233 if (getword_atoll(&nnbytes,&gwarea,'\t')<0) {
234 debuga(_("There is a broken number of bytes in file %s\n"),arqin);
235 exit(EXIT_FAILURE);
236 }
237 if (getword_ptr(buf,&url,&gwarea,'\t')<0) {
238 debuga(_("There is a broken url in file %s\n"),arqin);
239 exit(EXIT_FAILURE);
240 }
241 if (getword(tmsg,sizeof(tmsg),&gwarea,'\t')<0) {
242 debuga(_("There is a broken access code in file %s\n"),arqin);
243 exit(EXIT_FAILURE);
244 }
245 if (getword_atoll(&nnelap,&gwarea,'\t')<0) {
246 debuga(_("There is a broken elapsed time in file %s\n"),arqin);
247 exit(EXIT_FAILURE);
248 }
249 if (getword_atoll(&incache,&gwarea,'\t')<0) {
250 debuga(_("There is a broken in cache column in file %s\n"),arqin);
251 exit(EXIT_FAILURE);
252 }
253 if (getword_atoll(&oucache,&gwarea,'\n')<0) {
254 debuga(_("There is a broken out of cache column in file %s (%d)\n"),arqin,__LINE__);
255 exit(EXIT_FAILURE);
256 }
257
258 if(UserReportLimit<=0 || count<=UserReportLimit) {
259 fputs("<tr>",fp_ou);
260
261 if(IndexTree == INDEX_TREE_DATE)
262 sprintf(tmp6,"../%s",ImageFile);
263 else
264 strcpy(tmp6,"../../images");
265
266 if((ReportType & REPORT_TYPE_SITE_USER_TIME_DATE) != 0) {
f72b484a
FM
267 url_to_anchor(url,siteind,sizeof(siteind));
268 fprintf(fp_ou,"<td class=\"data\"><a href=\"tt.html#%s\"><img src=\"%s/datetime.png\" title=\"%s\" alt=\"T\"></a></td>",siteind,tmp6,_("date/time report"));
9bd92830
FM
269 } else {
270 fprintf(fp_ou,"<td class=\"data\"></td>");
271 }
272
273 if(Privacy)
274 fprintf(fp_ou,"<td class=\"data2\"><span style=\"color:%s;\">%s</span></td>",PrivacyStringColor,PrivacyString);
275 else {
276 fputs("<td class=\"data2\">",fp_ou);
67a93701 277 if(BlockIt[0]!='\0' && url[0]!=ALIAS_PREFIX) {
9bd92830
FM
278 fprintf(fp_ou,"<a href=\"%s%s?url=",wwwDocumentRoot,BlockIt);
279 output_html_url(fp_ou,url);
280 fprintf(fp_ou,"\"><img src=\"%s/sarg-squidguard-block.png\"></a>&nbsp;",tmp6);
281 }
6fa33a32 282 output_html_link(fp_ou,url,100);
67a93701 283 fputs("</td>",fp_ou);
9bd92830
FM
284 }
285
286 if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0) {
287 fputs("<td class=\"data\"",fp_ou);
288 if (SortTableJs[0]) fprintf(fp_ou," sorttable_customkey=\"%"PRId64"\"",(int64_t)twork);
289 fprintf(fp_ou,">%s</td>",fixnum(twork,1));
290 }
291 if((UserReportFields & USERREPORTFIELDS_BYTES) != 0) {
292 fputs("<td class=\"data\"",fp_ou);
293 if (SortTableJs[0]) fprintf(fp_ou," sorttable_customkey=\"%"PRId64"\"",(int64_t)nnbytes);
294 fprintf(fp_ou,">%s</td>",fixnum(nnbytes,1));
295 }
296 if((UserReportFields & USERREPORTFIELDS_SETYB) != 0) {
297 perc=(tnbytes) ? nnbytes * 100. / tnbytes : 0.;
298 fprintf(fp_ou,"<td class=\"data\">%3.2lf%%</td>",perc);
299 }
300 if((UserReportFields & USERREPORTFIELDS_IN_CACHE_OUT) != 0) {
301 inperc=(nnbytes) ? incache * 100. / nnbytes : 0.;
302 ouperc=(nnbytes) ? oucache * 100. / nnbytes : 0.;
303 fprintf(fp_ou,"<td class=\"data\">%3.2lf%%</td><td class=\"data\">%3.2lf%%</td>",inperc,ouperc);
304 }
305 if((UserReportFields & USERREPORTFIELDS_USED_TIME) != 0) {
306 fputs("<td class=\"data\"",fp_ou);
307 if (SortTableJs[0]) fprintf(fp_ou," sorttable_customkey=\"%"PRId64"\"",(int64_t)nnelap);
308 fprintf(fp_ou,">%s</td>",buildtime(nnelap));
309 }
310 if((UserReportFields & USERREPORTFIELDS_MILISEC) != 0) {
311 fputs("<td class=\"data\"",fp_ou);
312 if (SortTableJs[0]) fprintf(fp_ou," sorttable_customkey=\"%"PRId64"\"",(int64_t)nnelap);
313 fprintf(fp_ou,">%s</td>",fixnum2(nnelap,1));
314 }
315 if((UserReportFields & USERREPORTFIELDS_PTIME) != 0) {
316 perc2=(tnelap) ? nnelap * 100. / tnelap : 0.;
317 fprintf(fp_ou,"<td class=\"data\">%3.2lf%%</td>",perc2);
318 }
319
320 if(strncmp(tmsg,"OK",2) != 0)
321 fprintf(fp_ou,"<td class=\"data\">%s</td>",_("DENIED"));
322
323 fputs("</tr>\n",fp_ou);
324 count++;
325 } else if ((ReportType & REPORT_TYPE_SITE_USER_TIME_DATE) != 0) {
f72b484a 326 snprintf(warea,sizeof(warea),"%s/%s/tt.html",outdirname,uinfo->filename);
4e4d5fba
FM
327 if (unlink(warea)!=0) {
328 debuga(_("Cannot delete \"%s\": %s\n"),warea,strerror(errno));
9bd92830
FM
329 }
330 }
331
332 if(iprel) {
333 if (snprintf(arqip,sizeof(arqip),"%s/%s.ip",tmp,uinfo->filename)>=sizeof(arqip)) {
334 debuga(_("File name too long: %s/%s.ip\n"),tmp,uinfo->filename);
335 exit(EXIT_FAILURE);
336 }
337
338 if ((fp_ip = fopen(arqip, "r")) == 0){
d6f0349d 339 debuga(_("(html6) Cannot open file %s: %s\n"),arqip,strerror(errno));
9bd92830
FM
340 exit(EXIT_FAILURE);
341 }
342
343 if ((fp_ip2 = MY_FOPEN(tmp2, "a")) == 0){
d6f0349d 344 debuga(_("(html7) Cannot open file %s: %s\n"),tmp2,strerror(errno));
9bd92830
FM
345 exit(EXIT_FAILURE);
346 }
347
348 if ((line1=longline_create())==NULL) {
349 debuga(_("Not enough memory to read file %s\n"),arqip);
350 exit(EXIT_FAILURE);
351 }
352 while((buf=longline_read(fp_ip,line1))!=NULL) {
353 getword_start(&gwarea,buf);
354 if (getword(user_ip,sizeof(user_ip),&gwarea,'\t')<0) {
355 debuga(_("Maybe you have a broken user IP in your %s file\n"),tmp3);
356 exit(EXIT_FAILURE);
357 }
358 if (getword_ptr(buf,&user_url,&gwarea,'\t')<0) {
359 debuga(_("Maybe you have a broken url in your %s file\n"),tmp3);
360 exit(EXIT_FAILURE);
361 }
362 if (strncmp(user_url,url,strlen(url))!=0) continue;
363 if (getword_skip(15,&gwarea,'\t')<0) {
364 debuga(_("Maybe you have a broken day in your %s file\n"),tmp3);
365 exit(EXIT_FAILURE);
366 }
367 if (getword_skip(15,&gwarea,'\t')<0) {
368 debuga(_("Maybe you have a broken time in your %s file\n"),tmp3);
369 exit(EXIT_FAILURE);
370 }
371 if (getword_atoll(&userbytes,&gwarea,'\t')<0) {
372 debuga(_("Maybe you have a broken size in your %s file\n"),tmp3);
373 exit(EXIT_FAILURE);
374 }
375 if (getword_atoll(&userelap,&gwarea,'\0')<0) {
376 debuga(_("Maybe you have a broken elapsed time in your %s file\n"),tmp3);
377 exit(EXIT_FAILURE);
378 }
379 fprintf(fp_ip2,"%s\t%"PRIu64"\t%"PRIu64"\n",user_ip,(uint64_t)userbytes,(uint64_t)userelap);
380 }
381 longline_destroy(&line1);
382
383 fclose(fp_ip);
507460ae
FM
384 if (fclose(fp_ip2)==EOF) {
385 debuga(_("Write error in %s: %s\n"),tmp2,strerror(errno));
386 exit(EXIT_FAILURE);
387 }
9bd92830 388
78eeb33f
FM
389 if (snprintf(csort,sizeof(csort),"sort -n -t \"\t\" -T \"%s\" -k 1,1 -k 2,2 -o \"%s\" \"%s\"",tmp,tmp3,tmp2)>=sizeof(csort)) {
390 debuga(_("Sort command too long when sorting file \"%s\" to \"%s\"\n"),tmp2,tmp3);
391 exit(EXIT_FAILURE);
392 }
9bd92830
FM
393 cstatus=system(csort);
394 if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
395 debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus));
396 debuga(_("sort command: %s\n"),csort);
397 exit(EXIT_FAILURE);
398 }
399
400 if ((fp_ip = MY_FOPEN(tmp3, "r")) == 0) {
d6f0349d 401 debuga(_("(html8) Cannot open file %s: %s\n"),tmp3,strerror(errno));
9bd92830
FM
402 exit(EXIT_FAILURE);
403 }
404
4e4d5fba
FM
405 if (unlink(tmp2)) {
406 debuga(_("Cannot delete \"%s\": %s\n"),tmp2,strerror(errno));
407 exit(EXIT_FAILURE);
408 }
409
9bd92830
FM
410 olduserip[0]='\0';
411
412 if ((line1=longline_create())==NULL) {
413 debuga(_("Not enough memory to read file %s\n"),arqip);
414 exit(EXIT_FAILURE);
415 }
416 while((buf=longline_read(fp_ip,line1))!=NULL) {
417 getword_start(&gwarea,buf);
418 if (getword(user_ip,sizeof(user_ip),&gwarea,'\t')<0) {
419 debuga(_("Maybe you have a broken user IP in your %s file\n"),tmp3);
420 exit(EXIT_FAILURE);
421 }
422 if (getword_atoll(&userbytes,&gwarea,'\t')<0) {
423 debuga(_("Maybe you have a broken size in your %s file\n"),tmp3);
424 exit(EXIT_FAILURE);
425 }
426 if (getword_atoll(&userelap,&gwarea,'\0')<0) {
427 debuga(_("Maybe you have a broken elapsed time in your %s file\n"),tmp3);
428 exit(EXIT_FAILURE);
429 }
430 if(strcmp(user_ip,olduserip) != 0) {
431 if (olduserip[0]!='\0') {
432 fprintf(fp_ou,"<tr><td></td><td class=\"data\">%s</td>",olduserip);
433 if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0)
434 fputs("<td></td>",fp_ou);
435 if((UserReportFields & USERREPORTFIELDS_BYTES) != 0)
436 fprintf(fp_ou,"<td class=\"data\">%s</td>",fixnum(unbytes,1));
437 if((UserReportFields & USERREPORTFIELDS_SETYB) != 0)
438 fputs("<td></td>",fp_ou);
439 if((UserReportFields & USERREPORTFIELDS_IN_CACHE_OUT) != 0)
440 fputs("</td><td></td><td></td>",fp_ou);
441 if((UserReportFields & USERREPORTFIELDS_USED_TIME) != 0)
442 fprintf(fp_ou,"<td class=\"data\">%s</td>",buildtime(unelap));
443 if((UserReportFields & USERREPORTFIELDS_MILISEC) != 0)
444 fprintf(fp_ou,"<td class=\"data\">%s</td>",fixnum2(unelap,1));
445 fputs("</tr>\n",fp_ou);
446 }
447
448 strcpy(olduserip,user_ip);
9bd92830
FM
449 unbytes=0;
450 unelap=0;
451 }
452
453 unbytes+=userbytes;
454 unelap+=userelap;
455 }
456
457 fclose(fp_ip);
458 longline_destroy(&line1);
459
08f9b029 460 if (unlink(tmp3)) {
4e4d5fba 461 debuga(_("Cannot delete \"%s\": %s\n"),tmp3,strerror(errno));
08f9b029
FM
462 exit(EXIT_FAILURE);
463 }
9bd92830
FM
464
465 if (olduserip[0]!='\0') {
466 fprintf(fp_ou,"<tr><td></td><td class=\"data\">%s</td>",olduserip);
467 if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0)
468 fputs("<td></td>",fp_ou);
469 if((UserReportFields & USERREPORTFIELDS_BYTES) != 0)
470 fprintf(fp_ou,"<td class=\"data\">%s</td>",fixnum(unbytes,1));
471 if((UserReportFields & USERREPORTFIELDS_SETYB) != 0)
472 fputs("<td></td>",fp_ou);
473 if((UserReportFields & USERREPORTFIELDS_IN_CACHE_OUT) != 0)
474 fputs("</td><td></td><td></td>",fp_ou);
475 if((UserReportFields & USERREPORTFIELDS_USED_TIME) != 0)
476 fprintf(fp_ou,"<td class=\"data\">%s</td>",buildtime(unelap));
477 if((UserReportFields & USERREPORTFIELDS_MILISEC) != 0)
478 fprintf(fp_ou,"<td class=\"data\">%s</td>",fixnum2(unelap,1));
479 fputs("</tr>\n",fp_ou);
480 }
481 }
482
9bd92830
FM
483 unbytes=0;
484 unelap=0;
485 }
486
487 fclose(fp_in);
488 longline_destroy(&line);
489
a5267dd6 490 if (iprel && arqip[0]) {
11767c6a
FM
491 if (!KeepTempLog && unlink(arqip)) {
492 debuga(_("Cannot delete \"%s\": %s\n"),arqip,strerror(errno));
08f9b029
FM
493 exit(EXIT_FAILURE);
494 }
495 }
11767c6a
FM
496 if (!KeepTempLog && unlink(arqin)) {
497 debuga(_("Cannot delete \"%s\": %s\n"),arqin,strerror(errno));
08f9b029
FM
498 exit(EXIT_FAILURE);
499 }
9bd92830
FM
500
501 if ((UserReportFields & (USERREPORTFIELDS_TOTAL | USERREPORTFIELDS_AVERAGE)) != 0)
502 fputs("<tfoot>",fp_ou);
503
504 if((UserReportFields & USERREPORTFIELDS_TOTAL) != 0) {
505 fprintf(fp_ou,"<tr><th></th><th class=\"header_l\">%s</th>",_("TOTAL"));
506 if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0)
507 fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fixnum(tnacc,1));
508 if((UserReportFields & USERREPORTFIELDS_BYTES) != 0)
509 fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fixnum(tnbytes,1));
510 if((UserReportFields & USERREPORTFIELDS_SETYB) != 0) {
511 perc=(totbytes) ? tnbytes *100. / totbytes :0.;
512 fprintf(fp_ou,"<th class=\"header_r\">%3.2lf%%</th>",perc);
513 }
514 if((UserReportFields & USERREPORTFIELDS_IN_CACHE_OUT) != 0) {
515 inperc=(tnbytes) ? tnincache * 100. / tnbytes : 0.;
516 ouperc=(tnbytes) ? tnoucache * 100. / tnbytes : 0.;
517 fprintf(fp_ou,"<th class=\"header_r\">%3.2lf%%</th><th class=\"header_r\">%3.2lf%%</th>",inperc,ouperc);
518 }
519 if((UserReportFields & USERREPORTFIELDS_USED_TIME) != 0)
520 fprintf(fp_ou,"<th class=\"header_r\">%s</th>",buildtime(tnelap));
521 if((UserReportFields & USERREPORTFIELDS_MILISEC) != 0)
522 fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fixnum2(tnelap,1));
523 if((UserReportFields & USERREPORTFIELDS_PTIME) != 0) {
524 perc2=(totelap) ? tnelap * 100. / totelap : 0.;
525 fprintf(fp_ou,"<th class=\"header_r\">%3.2lf%%</th>",perc2);
526 }
527 fputs("</tr>\n",fp_ou);
528 }
529
aa6ac9f2
FM
530 if (PerUserLimit > 0 && (int)(tnbytes/1000000LLU) > PerUserLimit && !uinfo->user_limit) {
531 FILE *fp_usr;
9bd92830 532
aa6ac9f2
FM
533 if((fp_usr = fopen(PerUserLimitFile, "a")) == 0) {
534 debuga(_("(html10) Cannot open file %s: %s\n"),PerUserLimitFile,strerror(errno));
535 exit(EXIT_FAILURE);
9bd92830 536 }
aa6ac9f2
FM
537 fprintf(fp_usr,"%s\n",uinfo->ip);
538 if (fclose(fp_usr)==EOF) {
539 debuga(_("Write error in %s: %s\n"),PerUserLimitFile,strerror(errno));
540 exit(EXIT_FAILURE);
541 }
542 uinfo->user_limit=1;
543
544 if(debug)
545 debuga(_("User %s limit exceeded (%d MB). Added to file %s\n"),uinfo->label,PerUserLimit,PerUserLimitFile);
9bd92830 546 }
25697a35 547
9bd92830
FM
548 if ((ReportType & REPORT_TYPE_TOPUSERS) != 0 && (UserReportFields & USERREPORTFIELDS_AVERAGE) != 0) {
549 totbytes2=totbytes/ntotuser;
550 totelap2=totelap/ntotuser;
551
552 fprintf(fp_ou,"<tr><th></th><th class=\"header_l\">%s</th>",_("AVERAGE"));
553 if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0)
554 fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fixnum(ttnacc/ntotuser,1));
555 if((UserReportFields & USERREPORTFIELDS_BYTES) != 0)
556 fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fixnum(totbytes2,1));
557 fprintf(fp_ou,"<th></th><th></th><th></th>");
558 if((UserReportFields & USERREPORTFIELDS_USED_TIME) != 0)
559 fprintf(fp_ou,"<th class=\"header_r\">%s</th>",buildtime(totelap2));
560 if((UserReportFields & USERREPORTFIELDS_MILISEC) != 0)
561 fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fixnum2(totelap2,1));
562 if((UserReportFields & USERREPORTFIELDS_PTIME) != 0) {
563 perc2 = (totelap) ? totelap2 * 100. / totelap : 0.;
564 fprintf(fp_ou,"<th class=\"header_r\">%3.2lf%%</th>",perc2);
565 }
566 fputs("</tr>\n",fp_ou);
567 }
568
569 if ((UserReportFields & (USERREPORTFIELDS_TOTAL | USERREPORTFIELDS_AVERAGE)) != 0)
570 fputs("</tfoot>",fp_ou);
571
572 fputs("</table></div>\n",fp_ou);
573 if (write_html_trailer(fp_ou)<0)
574 debuga(_("Write error in file %s\n"),arqou);
507460ae
FM
575 if (fclose(fp_ou)==EOF) {
576 debuga(_("Write error in %s: %s\n"),arqou,strerror(errno));
577 exit(EXIT_FAILURE);
578 }
9bd92830
FM
579
580 htaccess(uinfo);
581 }
582
93551487 583 userinfo_stopscan(uscan);
9bd92830
FM
584
585 return;
25697a35 586}