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