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
];
34 //! How to create a per user file.
35 enum PerUserFileCreationEnum PerUserFileCreation
=PUFC_Always
;
37 extern struct globalstatstruct globstat
;
41 FILE *fp_in
, *fp_ou
, *fp_ip
, *fp_ip2
;
43 long long int nnbytes
=0, unbytes
=0, tnbytes
=0, totbytes
=0, totbytes2
=0;
44 long long int totelap
=0, totelap2
=0, nnelap
=0, unelap
=0, tnelap
=0;
45 long long int incache
=0, oucache
=0, tnincache
=0, tnoucache
=0, twork
=0;
47 long long int ntotuser
;
48 long long int userbytes
, userelap
;
50 char arqin
[MAXLEN
], arqou
[MAXLEN
], arqip
[MAXLEN
];
51 char *url
, tmsg
[50], csort
[MAXLEN
];
53 char user_ip
[MAXLEN
], olduserip
[MAXLEN
], tmp2
[MAXLEN
], tmp3
[MAXLEN
];
57 long long int tnacc
=0, ttnacc
=0;
58 double perc
=0, perc2
=0, ouperc
=0, inperc
=0;
62 unsigned int user_limit
[(MAX_USER_LIMITS
+sizeof(unsigned int)-1)/sizeof(unsigned int)];
63 bool have_denied_report
;
64 const char *sort_field
;
65 const char *sort_order
;
66 char siteind
[MAX_TRUNCATED_URL
];
67 struct getwordstruct gwarea
;
69 const struct userinfostruct
*uinfo
;
72 if (snprintf(tmp2
,sizeof(tmp2
),"%s/sargtmp.int_unsort",tmp
)>=sizeof(tmp2
)) {
73 debuga(_("File name too long: %s/sargtmp.int_unsort\n"),tmp
);
77 if (snprintf(tmp3
,sizeof(tmp3
),"%s/sargtmp.int_log",tmp
)>=sizeof(tmp3
)) {
78 debuga(_("File name too long: %s/sargtmp.int_log\n"),tmp
);
83 totbytes
=globstat
.nbytes
;
84 totelap
=globstat
.elap
;
85 ntotuser
=globstat
.totuser
;
87 sort_labels(&sort_field
,&sort_order
);
89 switch (PerUserFileCreation
)
92 for (i
=0 ; i
<PerUserLimitsNumber
; i
++) {
93 FILE *fp_usr
=fopen(PerUserLimits
[i
].File
,"wt");
95 debuga(_("Cannot create empty per_user_limit file \"%s\": %s"),PerUserLimits
[i
].File
,
103 case PUFC_AsRequired
:
104 for (i
=0 ; i
<PerUserLimitsNumber
; i
++) {
105 if (access(PerUserLimits
[i
].File
,R_OK
)==0 && unlink(PerUserLimits
[i
].File
)==-1) {
106 debuga(_("Cannot delete per_user_limit file \"%s\": %s"),PerUserLimits
[i
].File
,
114 uscan
=userinfo_startscan();
116 debuga(_("Cannot enumerate the user list\n"));
119 while ( (uinfo
= userinfo_advancescan(uscan
)) != NULL
) {
120 if (snprintf(warea
,sizeof(warea
),"%s/%s",outdirname
,uinfo
->filename
)>=sizeof(warea
)) {
121 debuga(_("Destination directory too long: %s/%s\n"),outdirname
,uinfo
->filename
);
124 if (!uinfo
->topuser
) {
125 //! \todo Instead of deleting the supernumerary directories, don't create them in the first place.
130 if (access(warea
, R_OK
) != 0) {
131 if (mkdir(warea
,0755)) {
132 debuga(_("Cannot create directory %s - %s\n"),warea
,strerror(errno
));
138 if (snprintf(arqin
,sizeof(arqin
),"%s/htmlrel.txt",tmp
)>=sizeof(arqin
)) {
139 debuga(_("Input file name too long: %s/htmlrel.txt\n"),tmp
);
142 if ((fp_in
= fopen(arqin
, "r")) == 0){
143 if (uinfo
->no_report
) continue;
144 debuga(_("(html3) Cannot open file %s: %s\n"),arqin
,strerror(errno
));
148 if (snprintf(arqou
,sizeof(arqou
),"%s/%s/%s.html",outdirname
,uinfo
->filename
,uinfo
->filename
)>=sizeof(arqou
)) {
149 debuga(_("Output file name too long: %s/%s/%s.html\n"),outdirname
,uinfo
->filename
,uinfo
->filename
);
152 if (snprintf(duser
,sizeof(duser
),"%s/denied_%s.html",outdirname
,uinfo
->filename
)>=sizeof(duser
)) {
153 debuga(_("File name too long: %s/denied_%s.html\n"),outdirname
,uinfo
->filename
);
156 if(access(duser
, R_OK
) != 0)
157 have_denied_report
=false;
159 have_denied_report
=true;
161 if ((line
=longline_create())==NULL
) {
162 debuga(_("Not enough memory to read file %s\n"),arqin
);
166 for (i
=0 ; i
<sizeof(user_limit
)/sizeof(user_limit
[0]) ; i
++)
174 while((buf
=longline_read(fp_in
,line
))!=NULL
) {
175 getword_start(&gwarea
,buf
);
176 if (getword_atoll(<emp
,&gwarea
,'\t')<0) {
177 debuga(_("There is a broken number of access in file %s\n"),arqin
);
181 if (getword_atoll(<emp
,&gwarea
,'\t')<0) {
182 debuga(_("There is a broken downloaded size in file %s\n"),arqin
);
186 if (getword_ptr(NULL
,NULL
,&gwarea
,'\t')<0) {
187 debuga(_("There is a broken url in file %s\n"),arqin
);
190 if (getword_skip(MAXLEN
,&gwarea
,'\t')<0) {
191 debuga(_("There is a broken access code in file %s\n"),arqin
);
194 if (getword_atoll(<emp
,&gwarea
,'\t')<0) {
195 debuga(_("There is a broken elapsed time in file %s\n"),arqin
);
199 if (getword_atoll(<emp
,&gwarea
,'\t')<0) {
200 debuga(_("There is a broken in-cache volume in file %s\n"),arqin
);
204 if (getword_atoll(<emp
,&gwarea
,'\n')<0) {
205 debuga(_("There is a broken out-cache volume in file %s\n"),arqin
);
213 if ((fp_ou
= fopen(arqou
, "w")) == 0){
214 debuga(_("(html5) Cannot open file %s: %s\n"),arqou
,strerror(errno
));
218 write_html_header(fp_ou
,(IndexTree
== INDEX_TREE_DATE
) ? 4 : 2,_("User report"),HTML_JS_SORTTABLE
);
219 fprintf(fp_ou
,"<tr><td class=\"header_c\">%s: %s</td></tr>\n",_("Period"),period
.html
);
220 fprintf(fp_ou
,"<tr><td class=\"header_c\">%s: %s</td></tr>\n",_("User"),uinfo
->label
);
221 fputs("<tr><td class=\"header_c\">",fp_ou
);
222 fprintf(fp_ou
,_("Sort: %s, %s"),sort_field
,sort_order
);
223 fputs("</td></tr>\n",fp_ou
);
224 fprintf(fp_ou
,"<tr><th class=\"header_c\">%s</th></tr>\n",_("User report"));
225 close_html_header(fp_ou
);
227 if (have_denied_report
) {
228 fputs("<div class=\"report\"><table cellpadding=\"1\" cellspacing=\"2\">\n",fp_ou
);
229 fprintf(fp_ou
,"<tr><td class=\"header_l\" colspan=\"11\"><a href=\"denied_%s.html\">%s</a></td></tr>\n",uinfo
->filename
,_("SmartFilter report"));
230 fputs("<tr><td></td></tr>\n</table></div>\n",fp_ou
);
233 fputs("<div class=\"report\"><table cellpadding=\"2\" cellspacing=\"1\"",fp_ou
);
234 if (SortTableJs
[0]) fputs(" class=\"sortable\"",fp_ou
);
237 fputs("<thead><tr><th class=\"sorttable_nosort\"></th><th class=\"header_l",fp_ou
);
238 if (SortTableJs
[0]) fputs(" sorttable_alpha",fp_ou
);
239 fprintf(fp_ou
,"\">%s</th>",_("ACCESSED SITE"));
241 if((UserReportFields
& USERREPORTFIELDS_CONNECT
) != 0)
242 fprintf(fp_ou
,"<th class=\"header_l\">%s</th>",_("CONNECT"));
243 if((UserReportFields
& USERREPORTFIELDS_BYTES
) != 0)
244 fprintf(fp_ou
,"<th class=\"header_l\">%s</th>",_("BYTES"));
245 if((UserReportFields
& USERREPORTFIELDS_SETYB
) != 0)
246 fprintf(fp_ou
,"<th class=\"header_l\">%s</th>",_("%BYTES"));
247 if((UserReportFields
& USERREPORTFIELDS_IN_CACHE_OUT
) != 0)
248 fprintf(fp_ou
,"<th class=\"header_c\" colspan=\"2\">%s</th><th style=\"display:none;\"></th>",_("IN-CACHE-OUT"));
249 if((UserReportFields
& USERREPORTFIELDS_USED_TIME
) != 0)
250 fprintf(fp_ou
,"<th class=\"header_l\">%s</th>",_("ELAPSED TIME"));
251 if((UserReportFields
& USERREPORTFIELDS_MILISEC
) != 0)
252 fprintf(fp_ou
,"<th class=\"header_l\">%s</th>",_("MILLISEC"));
253 if((UserReportFields
& USERREPORTFIELDS_PTIME
) != 0)
254 fprintf(fp_ou
,"<th class=\"header_l\">%s</th>",pgettext("duration","%TIME"));
256 fputs("</tr></thead>\n",fp_ou
);
259 debuga(_("Making report: %s\n"),uinfo
->id
);
264 while((buf
=longline_read(fp_in
,line
))!=NULL
) {
265 getword_start(&gwarea
,buf
);
266 if (getword_atoll(&twork
,&gwarea
,'\t')<0) {
267 debuga(_("There is a broken number of access in file %s\n"),arqin
);
270 if (getword_atoll(&nnbytes
,&gwarea
,'\t')<0) {
271 debuga(_("There is a broken number of bytes in file %s\n"),arqin
);
274 if (getword_ptr(buf
,&url
,&gwarea
,'\t')<0) {
275 debuga(_("There is a broken url in file %s\n"),arqin
);
278 if (getword(tmsg
,sizeof(tmsg
),&gwarea
,'\t')<0) {
279 debuga(_("There is a broken access code in file %s\n"),arqin
);
282 if (getword_atoll(&nnelap
,&gwarea
,'\t')<0) {
283 debuga(_("There is a broken elapsed time in file %s\n"),arqin
);
286 if (getword_atoll(&incache
,&gwarea
,'\t')<0) {
287 debuga(_("There is a broken in cache column in file %s\n"),arqin
);
290 if (getword_atoll(&oucache
,&gwarea
,'\n')<0) {
291 debuga(_("There is a broken out of cache column in file %s (%d)\n"),arqin
,__LINE__
);
295 if(UserReportLimit
<=0 || count
<=UserReportLimit
) {
298 if(IndexTree
== INDEX_TREE_DATE
)
299 sprintf(tmp6
,"../%s",ImageFile
);
301 strcpy(tmp6
,"../../images");
303 if((ReportType
& REPORT_TYPE_SITE_USER_TIME_DATE
) != 0) {
304 url_to_anchor(url
,siteind
,sizeof(siteind
));
305 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"));
307 fprintf(fp_ou
,"<td class=\"data\"></td>");
311 fprintf(fp_ou
,"<td class=\"data2\"><span style=\"color:%s;\">%s</span></td>",PrivacyStringColor
,PrivacyString
);
313 fputs("<td class=\"data2\">",fp_ou
);
314 if(BlockIt
[0]!='\0' && url
[0]!=ALIAS_PREFIX
) {
315 fprintf(fp_ou
,"<a href=\"%s%s?url=",wwwDocumentRoot
,BlockIt
);
316 output_html_url(fp_ou
,url
);
317 fprintf(fp_ou
,"\"><img src=\"%s/sarg-squidguard-block.png\"></a> ",tmp6
);
319 output_html_link(fp_ou
,url
,100);
320 fputs("</td>",fp_ou
);
323 if((UserReportFields
& USERREPORTFIELDS_CONNECT
) != 0) {
324 fputs("<td class=\"data\"",fp_ou
);
325 if (SortTableJs
[0]) fprintf(fp_ou
," sorttable_customkey=\"%"PRId64
"\"",(int64_t)twork
);
326 fprintf(fp_ou
,">%s</td>",fixnum(twork
,1));
328 if((UserReportFields
& USERREPORTFIELDS_BYTES
) != 0) {
329 fputs("<td class=\"data\"",fp_ou
);
330 if (SortTableJs
[0]) fprintf(fp_ou
," sorttable_customkey=\"%"PRId64
"\"",(int64_t)nnbytes
);
331 fprintf(fp_ou
,">%s</td>",fixnum(nnbytes
,1));
333 if((UserReportFields
& USERREPORTFIELDS_SETYB
) != 0) {
334 perc
=(tnbytes
) ? nnbytes
* 100. / tnbytes
: 0.;
335 fprintf(fp_ou
,"<td class=\"data\">%3.2lf%%</td>",perc
);
337 if((UserReportFields
& USERREPORTFIELDS_IN_CACHE_OUT
) != 0) {
338 inperc
=(nnbytes
) ? incache
* 100. / nnbytes
: 0.;
339 ouperc
=(nnbytes
) ? oucache
* 100. / nnbytes
: 0.;
340 fprintf(fp_ou
,"<td class=\"data\">%3.2lf%%</td><td class=\"data\">%3.2lf%%</td>",inperc
,ouperc
);
342 if((UserReportFields
& USERREPORTFIELDS_USED_TIME
) != 0) {
343 fputs("<td class=\"data\"",fp_ou
);
344 if (SortTableJs
[0]) fprintf(fp_ou
," sorttable_customkey=\"%"PRId64
"\"",(int64_t)nnelap
);
345 fprintf(fp_ou
,">%s</td>",buildtime(nnelap
));
347 if((UserReportFields
& USERREPORTFIELDS_MILISEC
) != 0) {
348 fputs("<td class=\"data\"",fp_ou
);
349 if (SortTableJs
[0]) fprintf(fp_ou
," sorttable_customkey=\"%"PRId64
"\"",(int64_t)nnelap
);
350 fprintf(fp_ou
,">%s</td>",fixnum2(nnelap
,1));
352 if((UserReportFields
& USERREPORTFIELDS_PTIME
) != 0) {
353 perc2
=(tnelap
) ? nnelap
* 100. / tnelap
: 0.;
354 fprintf(fp_ou
,"<td class=\"data\">%3.2lf%%</td>",perc2
);
357 if(strncmp(tmsg
,"OK",2) != 0)
358 fprintf(fp_ou
,"<td class=\"data\">%s</td>",_("DENIED"));
360 fputs("</tr>\n",fp_ou
);
362 } else if ((ReportType
& REPORT_TYPE_SITE_USER_TIME_DATE
) != 0) {
363 snprintf(warea
,sizeof(warea
),"%s/%s/tt.html",outdirname
,uinfo
->filename
);
364 if (unlink(warea
)!=0) {
365 debuga(_("Cannot delete \"%s\": %s\n"),warea
,strerror(errno
));
370 if (snprintf(arqip
,sizeof(arqip
),"%s/%s.ip",tmp
,uinfo
->filename
)>=sizeof(arqip
)) {
371 debuga(_("File name too long: %s/%s.ip\n"),tmp
,uinfo
->filename
);
375 if ((fp_ip
= fopen(arqip
, "r")) == 0){
376 debuga(_("(html6) Cannot open file %s: %s\n"),arqip
,strerror(errno
));
380 if ((fp_ip2
= MY_FOPEN(tmp2
, "a")) == 0){
381 debuga(_("(html7) Cannot open file %s: %s\n"),tmp2
,strerror(errno
));
385 if ((line1
=longline_create())==NULL
) {
386 debuga(_("Not enough memory to read file %s\n"),arqip
);
389 while((buf
=longline_read(fp_ip
,line1
))!=NULL
) {
390 getword_start(&gwarea
,buf
);
391 if (getword(user_ip
,sizeof(user_ip
),&gwarea
,'\t')<0) {
392 debuga(_("Maybe you have a broken user IP in your %s file\n"),tmp3
);
395 if (getword_ptr(buf
,&user_url
,&gwarea
,'\t')<0) {
396 debuga(_("Maybe you have a broken url in your %s file\n"),tmp3
);
399 if (strncmp(user_url
,url
,strlen(url
))!=0) continue;
400 if (getword_skip(15,&gwarea
,'\t')<0) {
401 debuga(_("Maybe you have a broken day in your %s file\n"),tmp3
);
404 if (getword_skip(15,&gwarea
,'\t')<0) {
405 debuga(_("Maybe you have a broken time in your %s file\n"),tmp3
);
408 if (getword_atoll(&userbytes
,&gwarea
,'\t')<0) {
409 debuga(_("Maybe you have a broken size in your %s file\n"),tmp3
);
412 if (getword_atoll(&userelap
,&gwarea
,'\0')<0) {
413 debuga(_("Maybe you have a broken elapsed time in your %s file\n"),tmp3
);
416 fprintf(fp_ip2
,"%s\t%"PRIu64
"\t%"PRIu64
"\n",user_ip
,(uint64_t)userbytes
,(uint64_t)userelap
);
418 longline_destroy(&line1
);
421 if (fclose(fp_ip2
)==EOF
) {
422 debuga(_("Write error in %s: %s\n"),tmp2
,strerror(errno
));
426 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
)) {
427 debuga(_("Sort command too long when sorting file \"%s\" to \"%s\"\n"),tmp2
,tmp3
);
430 cstatus
=system(csort
);
431 if (!WIFEXITED(cstatus
) || WEXITSTATUS(cstatus
)) {
432 debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus
));
433 debuga(_("sort command: %s\n"),csort
);
437 if ((fp_ip
= MY_FOPEN(tmp3
, "r")) == 0) {
438 debuga(_("(html8) Cannot open file %s: %s\n"),tmp3
,strerror(errno
));
443 debuga(_("Cannot delete \"%s\": %s\n"),tmp2
,strerror(errno
));
449 if ((line1
=longline_create())==NULL
) {
450 debuga(_("Not enough memory to read file %s\n"),arqip
);
453 while((buf
=longline_read(fp_ip
,line1
))!=NULL
) {
454 getword_start(&gwarea
,buf
);
455 if (getword(user_ip
,sizeof(user_ip
),&gwarea
,'\t')<0) {
456 debuga(_("Maybe you have a broken user IP in your %s file\n"),tmp3
);
459 if (getword_atoll(&userbytes
,&gwarea
,'\t')<0) {
460 debuga(_("Maybe you have a broken size in your %s file\n"),tmp3
);
463 if (getword_atoll(&userelap
,&gwarea
,'\0')<0) {
464 debuga(_("Maybe you have a broken elapsed time in your %s file\n"),tmp3
);
467 if(strcmp(user_ip
,olduserip
) != 0) {
468 if (olduserip
[0]!='\0') {
469 fprintf(fp_ou
,"<tr><td></td><td class=\"data\">%s</td>",olduserip
);
470 if((UserReportFields
& USERREPORTFIELDS_CONNECT
) != 0)
471 fputs("<td></td>",fp_ou
);
472 if((UserReportFields
& USERREPORTFIELDS_BYTES
) != 0)
473 fprintf(fp_ou
,"<td class=\"data\">%s</td>",fixnum(unbytes
,1));
474 if((UserReportFields
& USERREPORTFIELDS_SETYB
) != 0)
475 fputs("<td></td>",fp_ou
);
476 if((UserReportFields
& USERREPORTFIELDS_IN_CACHE_OUT
) != 0)
477 fputs("</td><td></td><td></td>",fp_ou
);
478 if((UserReportFields
& USERREPORTFIELDS_USED_TIME
) != 0)
479 fprintf(fp_ou
,"<td class=\"data\">%s</td>",buildtime(unelap
));
480 if((UserReportFields
& USERREPORTFIELDS_MILISEC
) != 0)
481 fprintf(fp_ou
,"<td class=\"data\">%s</td>",fixnum2(unelap
,1));
482 fputs("</tr>\n",fp_ou
);
485 strcpy(olduserip
,user_ip
);
495 longline_destroy(&line1
);
498 debuga(_("Cannot delete \"%s\": %s\n"),tmp3
,strerror(errno
));
502 if (olduserip
[0]!='\0') {
503 fprintf(fp_ou
,"<tr><td></td><td class=\"data\">%s</td>",olduserip
);
504 if((UserReportFields
& USERREPORTFIELDS_CONNECT
) != 0)
505 fputs("<td></td>",fp_ou
);
506 if((UserReportFields
& USERREPORTFIELDS_BYTES
) != 0)
507 fprintf(fp_ou
,"<td class=\"data\">%s</td>",fixnum(unbytes
,1));
508 if((UserReportFields
& USERREPORTFIELDS_SETYB
) != 0)
509 fputs("<td></td>",fp_ou
);
510 if((UserReportFields
& USERREPORTFIELDS_IN_CACHE_OUT
) != 0)
511 fputs("</td><td></td><td></td>",fp_ou
);
512 if((UserReportFields
& USERREPORTFIELDS_USED_TIME
) != 0)
513 fprintf(fp_ou
,"<td class=\"data\">%s</td>",buildtime(unelap
));
514 if((UserReportFields
& USERREPORTFIELDS_MILISEC
) != 0)
515 fprintf(fp_ou
,"<td class=\"data\">%s</td>",fixnum2(unelap
,1));
516 fputs("</tr>\n",fp_ou
);
525 longline_destroy(&line
);
527 if (iprel
&& arqip
[0]) {
528 if (!KeepTempLog
&& unlink(arqip
)) {
529 debuga(_("Cannot delete \"%s\": %s\n"),arqip
,strerror(errno
));
533 if (!KeepTempLog
&& unlink(arqin
)) {
534 debuga(_("Cannot delete \"%s\": %s\n"),arqin
,strerror(errno
));
538 if ((UserReportFields
& (USERREPORTFIELDS_TOTAL
| USERREPORTFIELDS_AVERAGE
)) != 0)
539 fputs("<tfoot>",fp_ou
);
541 if((UserReportFields
& USERREPORTFIELDS_TOTAL
) != 0) {
542 fprintf(fp_ou
,"<tr><th></th><th class=\"header_l\">%s</th>",_("TOTAL"));
543 if((UserReportFields
& USERREPORTFIELDS_CONNECT
) != 0)
544 fprintf(fp_ou
,"<th class=\"header_r\">%s</th>",fixnum(tnacc
,1));
545 if((UserReportFields
& USERREPORTFIELDS_BYTES
) != 0)
546 fprintf(fp_ou
,"<th class=\"header_r\">%s</th>",fixnum(tnbytes
,1));
547 if((UserReportFields
& USERREPORTFIELDS_SETYB
) != 0) {
548 perc
=(totbytes
) ? tnbytes
*100. / totbytes
:0.;
549 fprintf(fp_ou
,"<th class=\"header_r\">%3.2lf%%</th>",perc
);
551 if((UserReportFields
& USERREPORTFIELDS_IN_CACHE_OUT
) != 0) {
552 inperc
=(tnbytes
) ? tnincache
* 100. / tnbytes
: 0.;
553 ouperc
=(tnbytes
) ? tnoucache
* 100. / tnbytes
: 0.;
554 fprintf(fp_ou
,"<th class=\"header_r\">%3.2lf%%</th><th class=\"header_r\">%3.2lf%%</th>",inperc
,ouperc
);
556 if((UserReportFields
& USERREPORTFIELDS_USED_TIME
) != 0)
557 fprintf(fp_ou
,"<th class=\"header_r\">%s</th>",buildtime(tnelap
));
558 if((UserReportFields
& USERREPORTFIELDS_MILISEC
) != 0)
559 fprintf(fp_ou
,"<th class=\"header_r\">%s</th>",fixnum2(tnelap
,1));
560 if((UserReportFields
& USERREPORTFIELDS_PTIME
) != 0) {
561 perc2
=(totelap
) ? tnelap
* 100. / totelap
: 0.;
562 fprintf(fp_ou
,"<th class=\"header_r\">%3.2lf%%</th>",perc2
);
564 fputs("</tr>\n",fp_ou
);
567 if (PerUserLimitsNumber
>0) {
568 int limit
=(int)(tnbytes
/1000000LLU);
571 for (i
=0 ; i
<PerUserLimitsNumber
; i
++) {
572 maskid
=i
/sizeof(unsigned int);
573 mask
=0x1U
<< (i
% sizeof(unsigned int));
574 if (limit
>PerUserLimits
[i
].Limit
&& (user_limit
[maskid
] & mask
)==0) {
577 if((fp_usr
= fopen(PerUserLimits
[i
].File
, "at")) == 0) {
578 debuga(_("(html10) Cannot open per user limit file %s: %s\n"),PerUserLimits
[i
].File
,strerror(errno
));
581 if (PerUserLimits
[i
].UserId
)
582 fprintf(fp_usr
,"%s\n",uinfo
->label
);
584 fprintf(fp_usr
,"%s\n",uinfo
->ip
);
585 if (fclose(fp_usr
)==EOF
) {
586 debuga(_("Write error in per user limit file %s: %s\n"),PerUserLimits
[i
].File
,strerror(errno
));
589 user_limit
[maskid
]|=mask
;
592 debuga(_("User %s limit exceeded (%d MB). Added to file %s\n"),uinfo
->label
,
593 PerUserLimits
[i
].Limit
,PerUserLimits
[i
].File
);
598 if ((ReportType
& REPORT_TYPE_TOPUSERS
) != 0 && (UserReportFields
& USERREPORTFIELDS_AVERAGE
) != 0) {
599 totbytes2
=totbytes
/ntotuser
;
600 totelap2
=totelap
/ntotuser
;
602 fprintf(fp_ou
,"<tr><th></th><th class=\"header_l\">%s</th>",_("AVERAGE"));
603 if((UserReportFields
& USERREPORTFIELDS_CONNECT
) != 0)
604 fprintf(fp_ou
,"<th class=\"header_r\">%s</th>",fixnum(ttnacc
/ntotuser
,1));
605 if((UserReportFields
& USERREPORTFIELDS_BYTES
) != 0)
606 fprintf(fp_ou
,"<th class=\"header_r\">%s</th>",fixnum(totbytes2
,1));
607 fprintf(fp_ou
,"<th></th><th></th><th></th>");
608 if((UserReportFields
& USERREPORTFIELDS_USED_TIME
) != 0)
609 fprintf(fp_ou
,"<th class=\"header_r\">%s</th>",buildtime(totelap2
));
610 if((UserReportFields
& USERREPORTFIELDS_MILISEC
) != 0)
611 fprintf(fp_ou
,"<th class=\"header_r\">%s</th>",fixnum2(totelap2
,1));
612 if((UserReportFields
& USERREPORTFIELDS_PTIME
) != 0) {
613 perc2
= (totelap
) ? totelap2
* 100. / totelap
: 0.;
614 fprintf(fp_ou
,"<th class=\"header_r\">%3.2lf%%</th>",perc2
);
616 fputs("</tr>\n",fp_ou
);
619 if ((UserReportFields
& (USERREPORTFIELDS_TOTAL
| USERREPORTFIELDS_AVERAGE
)) != 0)
620 fputs("</tfoot>",fp_ou
);
622 fputs("</table></div>\n",fp_ou
);
623 if (write_html_trailer(fp_ou
)<0)
624 debuga(_("Write error in file %s\n"),arqou
);
625 if (fclose(fp_ou
)==EOF
) {
626 debuga(_("Write error in %s: %s\n"),arqou
,strerror(errno
));
633 userinfo_stopscan(uscan
);