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"
31 int PerUserLimitsNumber
=0;
32 //! Log user's who downloaded more than the limit.
33 struct PerUserLimitStruct PerUserLimits
[MAX_USER_LIMITS
];
35 extern struct globalstatstruct globstat
;
39 FILE *fp_in
, *fp_ou
, *fp_ip
, *fp_ip2
;
41 long long int nnbytes
=0, unbytes
=0, tnbytes
=0, totbytes
=0, totbytes2
=0;
42 long long int totelap
=0, totelap2
=0, nnelap
=0, unelap
=0, tnelap
=0;
43 long long int incache
=0, oucache
=0, tnincache
=0, tnoucache
=0, twork
=0;
45 long long int ntotuser
;
46 long long int userbytes
, userelap
;
48 char arqin
[MAXLEN
], arqou
[MAXLEN
], arqip
[MAXLEN
];
49 char *url
, tmsg
[50], csort
[MAXLEN
];
51 char user_ip
[MAXLEN
], olduserip
[MAXLEN
], tmp2
[MAXLEN
], tmp3
[MAXLEN
];
55 long long int tnacc
=0, ttnacc
=0;
56 double perc
=0, perc2
=0, ouperc
=0, inperc
=0;
60 unsigned int user_limit
[(MAX_USER_LIMITS
+sizeof(unsigned int)-1)/sizeof(unsigned int)];
61 bool have_denied_report
;
62 const char *sort_field
;
63 const char *sort_order
;
64 char siteind
[MAX_TRUNCATED_URL
];
65 struct getwordstruct gwarea
;
67 const struct userinfostruct
*uinfo
;
70 if (snprintf(tmp2
,sizeof(tmp2
),"%s/sargtmp.int_unsort",tmp
)>=sizeof(tmp2
)) {
71 debuga(_("File name too long: %s/sargtmp.int_unsort\n"),tmp
);
75 if (snprintf(tmp3
,sizeof(tmp3
),"%s/sargtmp.int_log",tmp
)>=sizeof(tmp3
)) {
76 debuga(_("File name too long: %s/sargtmp.int_log\n"),tmp
);
81 totbytes
=globstat
.nbytes
;
82 totelap
=globstat
.elap
;
83 ntotuser
=globstat
.totuser
;
85 sort_labels(&sort_field
,&sort_order
);
87 for (i
=0 ; i
<PerUserLimitsNumber
; i
++) {
88 if (access(PerUserLimits
[i
].File
,R_OK
)==0 && unlink(PerUserLimits
[i
].File
)==-1) {
89 debuga(_("Cannot delete per_user_limit file \"%s\": %s"),PerUserLimits
[i
].File
,
95 uscan
=userinfo_startscan();
97 debuga(_("Cannot enumerate the user list\n"));
100 while ( (uinfo
= userinfo_advancescan(uscan
)) != NULL
) {
101 if (snprintf(warea
,sizeof(warea
),"%s/%s",outdirname
,uinfo
->filename
)>=sizeof(warea
)) {
102 debuga(_("Destination directory too long: %s/%s\n"),outdirname
,uinfo
->filename
);
105 if (!uinfo
->topuser
) {
106 //! \todo Instead of deleting the supernumerary directories, don't create them in the first place.
111 if (access(warea
, R_OK
) != 0) {
112 if (mkdir(warea
,0755)) {
113 debuga(_("Cannot create directory %s - %s\n"),warea
,strerror(errno
));
119 if (snprintf(arqin
,sizeof(arqin
),"%s/htmlrel.txt",tmp
)>=sizeof(arqin
)) {
120 debuga(_("Input file name too long: %s/htmlrel.txt\n"),tmp
);
123 if ((fp_in
= fopen(arqin
, "r")) == 0){
124 if (uinfo
->no_report
) continue;
125 debuga(_("(html3) Cannot open file %s: %s\n"),arqin
,strerror(errno
));
129 if (snprintf(arqou
,sizeof(arqou
),"%s/%s/%s.html",outdirname
,uinfo
->filename
,uinfo
->filename
)>=sizeof(arqou
)) {
130 debuga(_("Output file name too long: %s/%s/%s.html\n"),outdirname
,uinfo
->filename
,uinfo
->filename
);
133 if (snprintf(duser
,sizeof(duser
),"%s/denied_%s.html",outdirname
,uinfo
->filename
)>=sizeof(duser
)) {
134 debuga(_("File name too long: %s/denied_%s.html\n"),outdirname
,uinfo
->filename
);
137 if(access(duser
, R_OK
) != 0)
138 have_denied_report
=false;
140 have_denied_report
=true;
142 if ((line
=longline_create())==NULL
) {
143 debuga(_("Not enough memory to read file %s\n"),arqin
);
147 for (i
=0 ; i
<sizeof(user_limit
)/sizeof(user_limit
[0]) ; i
++)
155 while((buf
=longline_read(fp_in
,line
))!=NULL
) {
156 getword_start(&gwarea
,buf
);
157 if (getword_atoll(<emp
,&gwarea
,'\t')<0) {
158 debuga(_("There is a broken number of access in file %s\n"),arqin
);
162 if (getword_atoll(<emp
,&gwarea
,'\t')<0) {
163 debuga(_("There is a broken downloaded size in file %s\n"),arqin
);
167 if (getword_ptr(NULL
,NULL
,&gwarea
,'\t')<0) {
168 debuga(_("There is a broken url in file %s\n"),arqin
);
171 if (getword_skip(MAXLEN
,&gwarea
,'\t')<0) {
172 debuga(_("There is a broken access code in file %s\n"),arqin
);
175 if (getword_atoll(<emp
,&gwarea
,'\t')<0) {
176 debuga(_("There is a broken elapsed time in file %s\n"),arqin
);
180 if (getword_atoll(<emp
,&gwarea
,'\t')<0) {
181 debuga(_("There is a broken in-cache volume in file %s\n"),arqin
);
185 if (getword_atoll(<emp
,&gwarea
,'\n')<0) {
186 debuga(_("There is a broken out-cache volume in file %s\n"),arqin
);
194 if ((fp_ou
= fopen(arqou
, "w")) == 0){
195 debuga(_("(html5) Cannot open file %s: %s\n"),arqou
,strerror(errno
));
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: %s</td></tr>\n",_("Period"),period
.html
);
201 fprintf(fp_ou
,"<tr><td class=\"header_c\">%s: %s</td></tr>\n",_("User"),uinfo
->label
);
202 fputs("<tr><td class=\"header_c\">",fp_ou
);
203 fprintf(fp_ou
,_("Sort: %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
);
208 if (have_denied_report
) {
209 fputs("<div class=\"report\"><table cellpadding=\"1\" cellspacing=\"2\">\n",fp_ou
);
210 fprintf(fp_ou
,"<tr><td class=\"header_l\" colspan=\"11\"><a href=\"denied_%s.html\">%s</a></td></tr>\n",uinfo
->filename
,_("SmartFilter report"));
211 fputs("<tr><td></td></tr>\n</table></div>\n",fp_ou
);
214 fputs("<div class=\"report\"><table cellpadding=\"2\" cellspacing=\"1\"",fp_ou
);
215 if (SortTableJs
[0]) fputs(" class=\"sortable\"",fp_ou
);
218 fputs("<thead><tr><th class=\"sorttable_nosort\"></th><th class=\"header_l",fp_ou
);
219 if (SortTableJs
[0]) fputs(" sorttable_alpha",fp_ou
);
220 fprintf(fp_ou
,"\">%s</th>",_("ACCESSED SITE"));
222 if((UserReportFields
& USERREPORTFIELDS_CONNECT
) != 0)
223 fprintf(fp_ou
,"<th class=\"header_l\">%s</th>",_("CONNECT"));
224 if((UserReportFields
& USERREPORTFIELDS_BYTES
) != 0)
225 fprintf(fp_ou
,"<th class=\"header_l\">%s</th>",_("BYTES"));
226 if((UserReportFields
& USERREPORTFIELDS_SETYB
) != 0)
227 fprintf(fp_ou
,"<th class=\"header_l\">%s</th>",_("%BYTES"));
228 if((UserReportFields
& USERREPORTFIELDS_IN_CACHE_OUT
) != 0)
229 fprintf(fp_ou
,"<th class=\"header_c\" colspan=\"2\">%s</th><th style=\"display:none;\"></th>",_("IN-CACHE-OUT"));
230 if((UserReportFields
& USERREPORTFIELDS_USED_TIME
) != 0)
231 fprintf(fp_ou
,"<th class=\"header_l\">%s</th>",_("ELAPSED TIME"));
232 if((UserReportFields
& USERREPORTFIELDS_MILISEC
) != 0)
233 fprintf(fp_ou
,"<th class=\"header_l\">%s</th>",_("MILLISEC"));
234 if((UserReportFields
& USERREPORTFIELDS_PTIME
) != 0)
235 fprintf(fp_ou
,"<th class=\"header_l\">%s</th>",pgettext("duration","%TIME"));
237 fputs("</tr></thead>\n",fp_ou
);
240 debuga(_("Making report: %s\n"),uinfo
->id
);
245 while((buf
=longline_read(fp_in
,line
))!=NULL
) {
246 getword_start(&gwarea
,buf
);
247 if (getword_atoll(&twork
,&gwarea
,'\t')<0) {
248 debuga(_("There is a broken number of access in file %s\n"),arqin
);
251 if (getword_atoll(&nnbytes
,&gwarea
,'\t')<0) {
252 debuga(_("There is a broken number of bytes in file %s\n"),arqin
);
255 if (getword_ptr(buf
,&url
,&gwarea
,'\t')<0) {
256 debuga(_("There is a broken url in file %s\n"),arqin
);
259 if (getword(tmsg
,sizeof(tmsg
),&gwarea
,'\t')<0) {
260 debuga(_("There is a broken access code in file %s\n"),arqin
);
263 if (getword_atoll(&nnelap
,&gwarea
,'\t')<0) {
264 debuga(_("There is a broken elapsed time in file %s\n"),arqin
);
267 if (getword_atoll(&incache
,&gwarea
,'\t')<0) {
268 debuga(_("There is a broken in cache column in file %s\n"),arqin
);
271 if (getword_atoll(&oucache
,&gwarea
,'\n')<0) {
272 debuga(_("There is a broken out of cache column in file %s (%d)\n"),arqin
,__LINE__
);
276 if(UserReportLimit
<=0 || count
<=UserReportLimit
) {
279 if(IndexTree
== INDEX_TREE_DATE
)
280 sprintf(tmp6
,"../%s",ImageFile
);
282 strcpy(tmp6
,"../../images");
284 if((ReportType
& REPORT_TYPE_SITE_USER_TIME_DATE
) != 0) {
285 url_to_anchor(url
,siteind
,sizeof(siteind
));
286 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"));
288 fprintf(fp_ou
,"<td class=\"data\"></td>");
292 fprintf(fp_ou
,"<td class=\"data2\"><span style=\"color:%s;\">%s</span></td>",PrivacyStringColor
,PrivacyString
);
294 fputs("<td class=\"data2\">",fp_ou
);
295 if(BlockIt
[0]!='\0' && url
[0]!=ALIAS_PREFIX
) {
296 fprintf(fp_ou
,"<a href=\"%s%s?url=",wwwDocumentRoot
,BlockIt
);
297 output_html_url(fp_ou
,url
);
298 fprintf(fp_ou
,"\"><img src=\"%s/sarg-squidguard-block.png\"></a> ",tmp6
);
300 output_html_link(fp_ou
,url
,100);
301 fputs("</td>",fp_ou
);
304 if((UserReportFields
& USERREPORTFIELDS_CONNECT
) != 0) {
305 fputs("<td class=\"data\"",fp_ou
);
306 if (SortTableJs
[0]) fprintf(fp_ou
," sorttable_customkey=\"%"PRId64
"\"",(int64_t)twork
);
307 fprintf(fp_ou
,">%s</td>",fixnum(twork
,1));
309 if((UserReportFields
& USERREPORTFIELDS_BYTES
) != 0) {
310 fputs("<td class=\"data\"",fp_ou
);
311 if (SortTableJs
[0]) fprintf(fp_ou
," sorttable_customkey=\"%"PRId64
"\"",(int64_t)nnbytes
);
312 fprintf(fp_ou
,">%s</td>",fixnum(nnbytes
,1));
314 if((UserReportFields
& USERREPORTFIELDS_SETYB
) != 0) {
315 perc
=(tnbytes
) ? nnbytes
* 100. / tnbytes
: 0.;
316 fprintf(fp_ou
,"<td class=\"data\">%3.2lf%%</td>",perc
);
318 if((UserReportFields
& USERREPORTFIELDS_IN_CACHE_OUT
) != 0) {
319 inperc
=(nnbytes
) ? incache
* 100. / nnbytes
: 0.;
320 ouperc
=(nnbytes
) ? oucache
* 100. / nnbytes
: 0.;
321 fprintf(fp_ou
,"<td class=\"data\">%3.2lf%%</td><td class=\"data\">%3.2lf%%</td>",inperc
,ouperc
);
323 if((UserReportFields
& USERREPORTFIELDS_USED_TIME
) != 0) {
324 fputs("<td class=\"data\"",fp_ou
);
325 if (SortTableJs
[0]) fprintf(fp_ou
," sorttable_customkey=\"%"PRId64
"\"",(int64_t)nnelap
);
326 fprintf(fp_ou
,">%s</td>",buildtime(nnelap
));
328 if((UserReportFields
& USERREPORTFIELDS_MILISEC
) != 0) {
329 fputs("<td class=\"data\"",fp_ou
);
330 if (SortTableJs
[0]) fprintf(fp_ou
," sorttable_customkey=\"%"PRId64
"\"",(int64_t)nnelap
);
331 fprintf(fp_ou
,">%s</td>",fixnum2(nnelap
,1));
333 if((UserReportFields
& USERREPORTFIELDS_PTIME
) != 0) {
334 perc2
=(tnelap
) ? nnelap
* 100. / tnelap
: 0.;
335 fprintf(fp_ou
,"<td class=\"data\">%3.2lf%%</td>",perc2
);
338 if(strncmp(tmsg
,"OK",2) != 0)
339 fprintf(fp_ou
,"<td class=\"data\">%s</td>",_("DENIED"));
341 fputs("</tr>\n",fp_ou
);
343 } else if ((ReportType
& REPORT_TYPE_SITE_USER_TIME_DATE
) != 0) {
344 snprintf(warea
,sizeof(warea
),"%s/%s/tt.html",outdirname
,uinfo
->filename
);
345 if (unlink(warea
)!=0) {
346 debuga(_("Cannot delete \"%s\": %s\n"),warea
,strerror(errno
));
351 if (snprintf(arqip
,sizeof(arqip
),"%s/%s.ip",tmp
,uinfo
->filename
)>=sizeof(arqip
)) {
352 debuga(_("File name too long: %s/%s.ip\n"),tmp
,uinfo
->filename
);
356 if ((fp_ip
= fopen(arqip
, "r")) == 0){
357 debuga(_("(html6) Cannot open file %s: %s\n"),arqip
,strerror(errno
));
361 if ((fp_ip2
= MY_FOPEN(tmp2
, "a")) == 0){
362 debuga(_("(html7) Cannot open file %s: %s\n"),tmp2
,strerror(errno
));
366 if ((line1
=longline_create())==NULL
) {
367 debuga(_("Not enough memory to read file %s\n"),arqip
);
370 while((buf
=longline_read(fp_ip
,line1
))!=NULL
) {
371 getword_start(&gwarea
,buf
);
372 if (getword(user_ip
,sizeof(user_ip
),&gwarea
,'\t')<0) {
373 debuga(_("Maybe you have a broken user IP in your %s file\n"),tmp3
);
376 if (getword_ptr(buf
,&user_url
,&gwarea
,'\t')<0) {
377 debuga(_("Maybe you have a broken url in your %s file\n"),tmp3
);
380 if (strncmp(user_url
,url
,strlen(url
))!=0) continue;
381 if (getword_skip(15,&gwarea
,'\t')<0) {
382 debuga(_("Maybe you have a broken day in your %s file\n"),tmp3
);
385 if (getword_skip(15,&gwarea
,'\t')<0) {
386 debuga(_("Maybe you have a broken time in your %s file\n"),tmp3
);
389 if (getword_atoll(&userbytes
,&gwarea
,'\t')<0) {
390 debuga(_("Maybe you have a broken size in your %s file\n"),tmp3
);
393 if (getword_atoll(&userelap
,&gwarea
,'\0')<0) {
394 debuga(_("Maybe you have a broken elapsed time in your %s file\n"),tmp3
);
397 fprintf(fp_ip2
,"%s\t%"PRIu64
"\t%"PRIu64
"\n",user_ip
,(uint64_t)userbytes
,(uint64_t)userelap
);
399 longline_destroy(&line1
);
402 if (fclose(fp_ip2
)==EOF
) {
403 debuga(_("Write error in %s: %s\n"),tmp2
,strerror(errno
));
407 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
)) {
408 debuga(_("Sort command too long when sorting file \"%s\" to \"%s\"\n"),tmp2
,tmp3
);
411 cstatus
=system(csort
);
412 if (!WIFEXITED(cstatus
) || WEXITSTATUS(cstatus
)) {
413 debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus
));
414 debuga(_("sort command: %s\n"),csort
);
418 if ((fp_ip
= MY_FOPEN(tmp3
, "r")) == 0) {
419 debuga(_("(html8) Cannot open file %s: %s\n"),tmp3
,strerror(errno
));
424 debuga(_("Cannot delete \"%s\": %s\n"),tmp2
,strerror(errno
));
430 if ((line1
=longline_create())==NULL
) {
431 debuga(_("Not enough memory to read file %s\n"),arqip
);
434 while((buf
=longline_read(fp_ip
,line1
))!=NULL
) {
435 getword_start(&gwarea
,buf
);
436 if (getword(user_ip
,sizeof(user_ip
),&gwarea
,'\t')<0) {
437 debuga(_("Maybe you have a broken user IP in your %s file\n"),tmp3
);
440 if (getword_atoll(&userbytes
,&gwarea
,'\t')<0) {
441 debuga(_("Maybe you have a broken size in your %s file\n"),tmp3
);
444 if (getword_atoll(&userelap
,&gwarea
,'\0')<0) {
445 debuga(_("Maybe you have a broken elapsed time in your %s file\n"),tmp3
);
448 if(strcmp(user_ip
,olduserip
) != 0) {
449 if (olduserip
[0]!='\0') {
450 fprintf(fp_ou
,"<tr><td></td><td class=\"data\">%s</td>",olduserip
);
451 if((UserReportFields
& USERREPORTFIELDS_CONNECT
) != 0)
452 fputs("<td></td>",fp_ou
);
453 if((UserReportFields
& USERREPORTFIELDS_BYTES
) != 0)
454 fprintf(fp_ou
,"<td class=\"data\">%s</td>",fixnum(unbytes
,1));
455 if((UserReportFields
& USERREPORTFIELDS_SETYB
) != 0)
456 fputs("<td></td>",fp_ou
);
457 if((UserReportFields
& USERREPORTFIELDS_IN_CACHE_OUT
) != 0)
458 fputs("</td><td></td><td></td>",fp_ou
);
459 if((UserReportFields
& USERREPORTFIELDS_USED_TIME
) != 0)
460 fprintf(fp_ou
,"<td class=\"data\">%s</td>",buildtime(unelap
));
461 if((UserReportFields
& USERREPORTFIELDS_MILISEC
) != 0)
462 fprintf(fp_ou
,"<td class=\"data\">%s</td>",fixnum2(unelap
,1));
463 fputs("</tr>\n",fp_ou
);
466 strcpy(olduserip
,user_ip
);
476 longline_destroy(&line1
);
479 debuga(_("Cannot delete \"%s\": %s\n"),tmp3
,strerror(errno
));
483 if (olduserip
[0]!='\0') {
484 fprintf(fp_ou
,"<tr><td></td><td class=\"data\">%s</td>",olduserip
);
485 if((UserReportFields
& USERREPORTFIELDS_CONNECT
) != 0)
486 fputs("<td></td>",fp_ou
);
487 if((UserReportFields
& USERREPORTFIELDS_BYTES
) != 0)
488 fprintf(fp_ou
,"<td class=\"data\">%s</td>",fixnum(unbytes
,1));
489 if((UserReportFields
& USERREPORTFIELDS_SETYB
) != 0)
490 fputs("<td></td>",fp_ou
);
491 if((UserReportFields
& USERREPORTFIELDS_IN_CACHE_OUT
) != 0)
492 fputs("</td><td></td><td></td>",fp_ou
);
493 if((UserReportFields
& USERREPORTFIELDS_USED_TIME
) != 0)
494 fprintf(fp_ou
,"<td class=\"data\">%s</td>",buildtime(unelap
));
495 if((UserReportFields
& USERREPORTFIELDS_MILISEC
) != 0)
496 fprintf(fp_ou
,"<td class=\"data\">%s</td>",fixnum2(unelap
,1));
497 fputs("</tr>\n",fp_ou
);
506 longline_destroy(&line
);
508 if (iprel
&& arqip
[0]) {
509 if (!KeepTempLog
&& unlink(arqip
)) {
510 debuga(_("Cannot delete \"%s\": %s\n"),arqip
,strerror(errno
));
514 if (!KeepTempLog
&& unlink(arqin
)) {
515 debuga(_("Cannot delete \"%s\": %s\n"),arqin
,strerror(errno
));
519 if ((UserReportFields
& (USERREPORTFIELDS_TOTAL
| USERREPORTFIELDS_AVERAGE
)) != 0)
520 fputs("<tfoot>",fp_ou
);
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
);
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
);
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
);
545 fputs("</tr>\n",fp_ou
);
548 if (PerUserLimitsNumber
>0) {
549 int limit
=(int)(tnbytes
/1000000LLU);
552 for (i
=0 ; i
<PerUserLimitsNumber
; i
++) {
553 maskid
=i
/sizeof(unsigned int);
554 mask
=0x1U
<< (i
% sizeof(unsigned int));
555 if (limit
>PerUserLimits
[i
].Limit
&& (user_limit
[maskid
] & mask
)==0) {
558 if((fp_usr
= fopen(PerUserLimits
[i
].File
, "a")) == 0) {
559 debuga(_("(html10) Cannot open per user limit file %s: %s\n"),PerUserLimits
[i
].File
,strerror(errno
));
562 if (PerUserLimits
[i
].UserId
)
563 fprintf(fp_usr
,"%s\n",uinfo
->label
);
565 fprintf(fp_usr
,"%s\n",uinfo
->ip
);
566 if (fclose(fp_usr
)==EOF
) {
567 debuga(_("Write error in per user limit file %s: %s\n"),PerUserLimits
[i
].File
,strerror(errno
));
570 user_limit
[maskid
]|=mask
;
573 debuga(_("User %s limit exceeded (%d MB). Added to file %s\n"),uinfo
->label
,
574 PerUserLimits
[i
].Limit
,PerUserLimits
[i
].File
);
579 if ((ReportType
& REPORT_TYPE_TOPUSERS
) != 0 && (UserReportFields
& USERREPORTFIELDS_AVERAGE
) != 0) {
580 totbytes2
=totbytes
/ntotuser
;
581 totelap2
=totelap
/ntotuser
;
583 fprintf(fp_ou
,"<tr><th></th><th class=\"header_l\">%s</th>",_("AVERAGE"));
584 if((UserReportFields
& USERREPORTFIELDS_CONNECT
) != 0)
585 fprintf(fp_ou
,"<th class=\"header_r\">%s</th>",fixnum(ttnacc
/ntotuser
,1));
586 if((UserReportFields
& USERREPORTFIELDS_BYTES
) != 0)
587 fprintf(fp_ou
,"<th class=\"header_r\">%s</th>",fixnum(totbytes2
,1));
588 fprintf(fp_ou
,"<th></th><th></th><th></th>");
589 if((UserReportFields
& USERREPORTFIELDS_USED_TIME
) != 0)
590 fprintf(fp_ou
,"<th class=\"header_r\">%s</th>",buildtime(totelap2
));
591 if((UserReportFields
& USERREPORTFIELDS_MILISEC
) != 0)
592 fprintf(fp_ou
,"<th class=\"header_r\">%s</th>",fixnum2(totelap2
,1));
593 if((UserReportFields
& USERREPORTFIELDS_PTIME
) != 0) {
594 perc2
= (totelap
) ? totelap2
* 100. / totelap
: 0.;
595 fprintf(fp_ou
,"<th class=\"header_r\">%3.2lf%%</th>",perc2
);
597 fputs("</tr>\n",fp_ou
);
600 if ((UserReportFields
& (USERREPORTFIELDS_TOTAL
| USERREPORTFIELDS_AVERAGE
)) != 0)
601 fputs("</tfoot>",fp_ou
);
603 fputs("</table></div>\n",fp_ou
);
604 if (write_html_trailer(fp_ou
)<0)
605 debuga(_("Write error in file %s\n"),arqou
);
606 if (fclose(fp_ou
)==EOF
) {
607 debuga(_("Write error in %s: %s\n"),arqou
,strerror(errno
));
614 userinfo_stopscan(uscan
);