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(_("Path too long: "));
74 debuga_more("%s/sargtmp.int_unsort\n",tmp
);
78 if (snprintf(tmp3
,sizeof(tmp3
),"%s/sargtmp.int_log",tmp
)>=sizeof(tmp3
)) {
79 debuga(_("Path too long: "));
80 debuga_more("%s/sargtmp.int_log\n",tmp
);
85 totbytes
=globstat
.nbytes
;
86 totelap
=globstat
.elap
;
87 ntotuser
=globstat
.totuser
;
89 sort_labels(&sort_field
,&sort_order
);
91 switch (PerUserFileCreation
)
94 for (i
=0 ; i
<PerUserLimitsNumber
; i
++) {
95 FILE *fp_usr
=fopen(PerUserLimits
[i
].File
,"wt");
97 debuga(_("Cannot create empty per_user_limit file \"%s\": %s\n"),PerUserLimits
[i
].File
,
101 if (fclose(fp_usr
)==EOF
) {
102 debuga(_("Write error in \"%s\": %s\n"),PerUserLimits
[i
].File
,strerror(errno
));
108 case PUFC_AsRequired
:
109 for (i
=0 ; i
<PerUserLimitsNumber
; i
++) {
110 if (access(PerUserLimits
[i
].File
,R_OK
)==0 && unlink(PerUserLimits
[i
].File
)==-1) {
111 debuga(_("Cannot delete \"%s\": %s\n"),PerUserLimits
[i
].File
,
119 uscan
=userinfo_startscan();
121 debuga(_("Cannot enumerate the user list\n"));
124 while ( (uinfo
= userinfo_advancescan(uscan
)) != NULL
) {
125 if (snprintf(warea
,sizeof(warea
),"%s/%s",outdirname
,uinfo
->filename
)>=sizeof(warea
)) {
126 debuga(_("Path too long: "));
127 debuga_more("%s/%s\n",outdirname
,uinfo
->filename
);
130 if (!uinfo
->topuser
) {
131 //! \todo Instead of deleting the supernumerary directories, don't create them in the first place.
136 if (access(warea
, R_OK
) != 0) {
137 if (PortableMkDir(warea
,0755)) {
138 debuga(_("Cannot create directory \"%s\": %s\n"),warea
,strerror(errno
));
144 if (snprintf(arqin
,sizeof(arqin
),"%s/htmlrel.txt",tmp
)>=sizeof(arqin
)) {
145 debuga(_("Input file name too long: %s/htmlrel.txt\n"),tmp
);
148 if ((fp_in
= fopen(arqin
, "r")) == 0){
149 if (uinfo
->no_report
) continue;
150 debuga(_("Cannot open file \"%s\": %s\n"),arqin
,strerror(errno
));
154 if (snprintf(arqou
,sizeof(arqou
),"%s/%s/%s.html",outdirname
,uinfo
->filename
,uinfo
->filename
)>=sizeof(arqou
)) {
155 debuga(_("Path too long: "));
156 debuga_more("%s/%s/%s.html\n",outdirname
,uinfo
->filename
,uinfo
->filename
);
159 if (snprintf(duser
,sizeof(duser
),"%s/denied_%s.html",outdirname
,uinfo
->filename
)>=sizeof(duser
)) {
160 debuga(_("Path too long: "));
161 debuga_more("%s/denied_%s.html\n",outdirname
,uinfo
->filename
);
164 if(access(duser
, R_OK
) != 0)
165 have_denied_report
=false;
167 have_denied_report
=true;
169 if ((line
=longline_create())==NULL
) {
170 debuga(_("Not enough memory to read file \"%s\"\n"),arqin
);
174 for (i
=0 ; i
<sizeof(user_limit
)/sizeof(user_limit
[0]) ; i
++)
182 while((buf
=longline_read(fp_in
,line
))!=NULL
) {
183 getword_start(&gwarea
,buf
);
184 if (getword_atoll(<emp
,&gwarea
,'\t')<0) {
185 debuga(_("Invalid number of accesses in file \"%s\"\n"),arqin
);
189 if (getword_atoll(<emp
,&gwarea
,'\t')<0) {
190 debuga(_("Invalid downloaded size in file \"%s\"\n"),arqin
);
194 if (getword_ptr(NULL
,NULL
,&gwarea
,'\t')<0) {
195 debuga(_("Invalid url in file \"%s\"\n"),arqin
);
198 if (getword_skip(MAXLEN
,&gwarea
,'\t')<0) {
199 debuga(_("Invalid access code in file \"%s\"\n"),arqin
);
202 if (getword_atoll(<emp
,&gwarea
,'\t')<0) {
203 debuga(_("Invalid elapsed time in file \"%s\"\n"),arqin
);
207 if (getword_atoll(<emp
,&gwarea
,'\t')<0) {
208 debuga(_("Invalid in-cache size in file \"%s\"\n"),arqin
);
212 if (getword_atoll(<emp
,&gwarea
,'\n')<0) {
213 debuga(_("Invalid out-of-cache size in file \"%s\"\n"),arqin
);
221 if ((fp_ou
= fopen(arqou
, "w")) == 0){
222 debuga(_("Cannot open file \"%s\": %s\n"),arqou
,strerror(errno
));
226 write_html_header(fp_ou
,(IndexTree
== INDEX_TREE_DATE
) ? 4 : 2,_("User report"),HTML_JS_SORTTABLE
);
227 fprintf(fp_ou
,"<tr><td class=\"header_c\">%s: %s</td></tr>\n",_("Period"),period
.html
);
228 fprintf(fp_ou
,"<tr><td class=\"header_c\">%s: %s</td></tr>\n",_("User"),uinfo
->label
);
229 fputs("<tr><td class=\"header_c\">",fp_ou
);
230 fprintf(fp_ou
,_("Sort: %s, %s"),sort_field
,sort_order
);
231 fputs("</td></tr>\n",fp_ou
);
232 fprintf(fp_ou
,"<tr><th class=\"header_c\">%s</th></tr>\n",_("User report"));
233 close_html_header(fp_ou
);
235 if (have_denied_report
) {
236 fputs("<div class=\"report\"><table cellpadding=\"1\" cellspacing=\"2\">\n",fp_ou
);
237 fprintf(fp_ou
,"<tr><td class=\"header_l\" colspan=\"11\"><a href=\"denied_%s.html\">%s</a></td></tr>\n",uinfo
->filename
,_("SmartFilter report"));
238 fputs("<tr><td></td></tr>\n</table></div>\n",fp_ou
);
241 fputs("<div class=\"report\"><table cellpadding=\"2\" cellspacing=\"1\"",fp_ou
);
242 if (SortTableJs
[0]) fputs(" class=\"sortable\"",fp_ou
);
245 fputs("<thead><tr><th class=\"sorttable_nosort\"></th><th class=\"header_l",fp_ou
);
246 if (SortTableJs
[0]) fputs(" sorttable_alpha",fp_ou
);
247 fprintf(fp_ou
,"\">%s</th>",_("ACCESSED SITE"));
249 if((UserReportFields
& USERREPORTFIELDS_CONNECT
) != 0)
250 fprintf(fp_ou
,"<th class=\"header_l\">%s</th>",_("CONNECT"));
251 if((UserReportFields
& USERREPORTFIELDS_BYTES
) != 0)
252 fprintf(fp_ou
,"<th class=\"header_l\">%s</th>",_("BYTES"));
253 if((UserReportFields
& USERREPORTFIELDS_SETYB
) != 0)
254 fprintf(fp_ou
,"<th class=\"header_l\">%s</th>",_("%BYTES"));
255 if((UserReportFields
& USERREPORTFIELDS_IN_CACHE_OUT
) != 0)
256 fprintf(fp_ou
,"<th class=\"header_c\" colspan=\"2\">%s</th><th style=\"display:none;\"></th>",_("IN-CACHE-OUT"));
257 if((UserReportFields
& USERREPORTFIELDS_USED_TIME
) != 0)
258 fprintf(fp_ou
,"<th class=\"header_l\">%s</th>",_("ELAPSED TIME"));
259 if((UserReportFields
& USERREPORTFIELDS_MILISEC
) != 0)
260 fprintf(fp_ou
,"<th class=\"header_l\">%s</th>",_("MILLISEC"));
261 if((UserReportFields
& USERREPORTFIELDS_PTIME
) != 0)
262 fprintf(fp_ou
,"<th class=\"header_l\">%s</th>",pgettext("duration","%TIME"));
264 fputs("</tr></thead>\n",fp_ou
);
267 debuga(_("Making report %s\n"),uinfo
->id
);
272 while((buf
=longline_read(fp_in
,line
))!=NULL
) {
273 getword_start(&gwarea
,buf
);
274 if (getword_atoll(&twork
,&gwarea
,'\t')<0) {
275 debuga(_("Invalid number of accesses in file \"%s\"\n"),arqin
);
278 if (getword_atoll(&nnbytes
,&gwarea
,'\t')<0) {
279 debuga(_("Invalid number of bytes in file \"%s\"\n"),arqin
);
282 if (getword_ptr(buf
,&url
,&gwarea
,'\t')<0) {
283 debuga(_("Invalid url in file \"%s\"\n"),arqin
);
286 if (getword(tmsg
,sizeof(tmsg
),&gwarea
,'\t')<0) {
287 debuga(_("Invalid access code in file \"%s\"\n"),arqin
);
290 if (getword_atoll(&nnelap
,&gwarea
,'\t')<0) {
291 debuga(_("Invalid elapsed time in file \"%s\"\n"),arqin
);
294 if (getword_atoll(&incache
,&gwarea
,'\t')<0) {
295 debuga(_("Invalid in-cache size in file \"%s\"\n"),arqin
);
298 if (getword_atoll(&oucache
,&gwarea
,'\n')<0) {
299 debuga(_("Invalid out-of-cache size in file \"%s\"\n"),arqin
);
303 if(UserReportLimit
<=0 || count
<=UserReportLimit
) {
306 if(IndexTree
== INDEX_TREE_DATE
)
307 sprintf(tmp6
,"../%s",ImageFile
);
309 strcpy(tmp6
,"../../images");
311 if((ReportType
& REPORT_TYPE_SITE_USER_TIME_DATE
) != 0) {
312 url_to_anchor(url
,siteind
,sizeof(siteind
));
313 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"));
315 fprintf(fp_ou
,"<td class=\"data\"></td>");
319 fprintf(fp_ou
,"<td class=\"data2\"><span style=\"color:%s;\">%s</span></td>",PrivacyStringColor
,PrivacyString
);
321 fputs("<td class=\"data2\">",fp_ou
);
322 if(BlockIt
[0]!='\0' && url
[0]!=ALIAS_PREFIX
) {
323 fprintf(fp_ou
,"<a href=\"%s%s?url=",wwwDocumentRoot
,BlockIt
);
324 output_html_url(fp_ou
,url
);
325 fprintf(fp_ou
,"\"><img src=\"%s/sarg-squidguard-block.png\"></a> ",tmp6
);
327 output_html_link(fp_ou
,url
,100);
328 fputs("</td>",fp_ou
);
331 if((UserReportFields
& USERREPORTFIELDS_CONNECT
) != 0) {
332 fputs("<td class=\"data\"",fp_ou
);
333 if (SortTableJs
[0]) fprintf(fp_ou
," sorttable_customkey=\"%"PRId64
"\"",(int64_t)twork
);
334 fprintf(fp_ou
,">%s</td>",fixnum(twork
,1));
336 if((UserReportFields
& USERREPORTFIELDS_BYTES
) != 0) {
337 fputs("<td class=\"data\"",fp_ou
);
338 if (SortTableJs
[0]) fprintf(fp_ou
," sorttable_customkey=\"%"PRId64
"\"",(int64_t)nnbytes
);
339 fprintf(fp_ou
,">%s</td>",fixnum(nnbytes
,1));
341 if((UserReportFields
& USERREPORTFIELDS_SETYB
) != 0) {
342 perc
=(tnbytes
) ? nnbytes
* 100. / tnbytes
: 0.;
343 fprintf(fp_ou
,"<td class=\"data\">%3.2lf%%</td>",perc
);
345 if((UserReportFields
& USERREPORTFIELDS_IN_CACHE_OUT
) != 0) {
346 inperc
=(nnbytes
) ? incache
* 100. / nnbytes
: 0.;
347 ouperc
=(nnbytes
) ? oucache
* 100. / nnbytes
: 0.;
348 fprintf(fp_ou
,"<td class=\"data\">%3.2lf%%</td><td class=\"data\">%3.2lf%%</td>",inperc
,ouperc
);
350 if((UserReportFields
& USERREPORTFIELDS_USED_TIME
) != 0) {
351 fputs("<td class=\"data\"",fp_ou
);
352 if (SortTableJs
[0]) fprintf(fp_ou
," sorttable_customkey=\"%"PRId64
"\"",(int64_t)nnelap
);
353 fprintf(fp_ou
,">%s</td>",buildtime(nnelap
));
355 if((UserReportFields
& USERREPORTFIELDS_MILISEC
) != 0) {
356 fputs("<td class=\"data\"",fp_ou
);
357 if (SortTableJs
[0]) fprintf(fp_ou
," sorttable_customkey=\"%"PRId64
"\"",(int64_t)nnelap
);
358 fprintf(fp_ou
,">%s</td>",fixnum2(nnelap
,1));
360 if((UserReportFields
& USERREPORTFIELDS_PTIME
) != 0) {
361 perc2
=(tnelap
) ? nnelap
* 100. / tnelap
: 0.;
362 fprintf(fp_ou
,"<td class=\"data\">%3.2lf%%</td>",perc2
);
365 if(strncmp(tmsg
,"OK",2) != 0)
366 fprintf(fp_ou
,"<td class=\"data\">%s</td>",_("DENIED"));
368 fputs("</tr>\n",fp_ou
);
370 } else if ((ReportType
& REPORT_TYPE_SITE_USER_TIME_DATE
) != 0) {
371 snprintf(warea
,sizeof(warea
),"%s/%s/tt.html",outdirname
,uinfo
->filename
);
372 if (unlink(warea
)!=0) {
373 debuga(_("Cannot delete \"%s\": %s\n"),warea
,strerror(errno
));
378 if (snprintf(arqip
,sizeof(arqip
),"%s/%s.ip",tmp
,uinfo
->filename
)>=sizeof(arqip
)) {
379 debuga(_("Path too long: "));
380 debuga_more("%s/%s.ip\n",tmp
,uinfo
->filename
);
384 if ((fp_ip
= fopen(arqip
, "r")) == 0){
385 debuga(_("Cannot open file \"%s\": %s\n"),arqip
,strerror(errno
));
389 if ((fp_ip2
= MY_FOPEN(tmp2
, "a")) == 0){
390 debuga(_("Cannot open file \"%s\": %s\n"),tmp2
,strerror(errno
));
394 if ((line1
=longline_create())==NULL
) {
395 debuga(_("Not enough memory to read file \"%s\"\n"),arqip
);
398 while((buf
=longline_read(fp_ip
,line1
))!=NULL
) {
399 getword_start(&gwarea
,buf
);
400 if (getword(user_ip
,sizeof(user_ip
),&gwarea
,'\t')<0) {
401 debuga(_("Invalid user IP in file \"%s\"\n"),tmp3
);
404 if (getword_ptr(buf
,&user_url
,&gwarea
,'\t')<0) {
405 debuga(_("Invalid url in file \"%s\"\n"),tmp3
);
408 if (strncmp(user_url
,url
,strlen(url
))!=0) continue;
409 if (getword_skip(15,&gwarea
,'\t')<0) {
410 debuga(_("Invalid day in file \"%s\"\n"),tmp3
);
413 if (getword_skip(15,&gwarea
,'\t')<0) {
414 debuga(_("Invalid time in file \"%s\"\n"),tmp3
);
417 if (getword_atoll(&userbytes
,&gwarea
,'\t')<0) {
418 debuga(_("Invalid size in file \"%s\"\n"),tmp3
);
421 if (getword_atoll(&userelap
,&gwarea
,'\0')<0) {
422 debuga(_("Invalid elapsed time in file \"%s\"\n"),tmp3
);
425 fprintf(fp_ip2
,"%s\t%"PRIu64
"\t%"PRIu64
"\n",user_ip
,(uint64_t)userbytes
,(uint64_t)userelap
);
427 longline_destroy(&line1
);
429 if (fclose(fp_ip2
)==EOF
) {
430 debuga(_("Write error in \"%s\": %s\n"),tmp2
,strerror(errno
));
433 if (fclose(fp_ip
)==EOF
) {
434 debuga(_("Read error in \"%s\": %s\n"),arqip
,strerror(errno
));
438 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
)) {
439 debuga(_("Sort command too long when sorting file \"%s\" to \"%s\"\n"),tmp2
,tmp3
);
442 cstatus
=system(csort
);
443 if (!WIFEXITED(cstatus
) || WEXITSTATUS(cstatus
)) {
444 debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus
));
445 debuga(_("sort command: %s\n"),csort
);
449 if ((fp_ip
= MY_FOPEN(tmp3
, "r")) == 0) {
450 debuga(_("Cannot open file \"%s\": %s\n"),tmp3
,strerror(errno
));
455 debuga(_("Cannot delete \"%s\": %s\n"),tmp2
,strerror(errno
));
461 if ((line1
=longline_create())==NULL
) {
462 debuga(_("Not enough memory to read file \"%s\"\n"),arqip
);
465 while((buf
=longline_read(fp_ip
,line1
))!=NULL
) {
466 getword_start(&gwarea
,buf
);
467 if (getword(user_ip
,sizeof(user_ip
),&gwarea
,'\t')<0) {
468 debuga(_("Invalid user IP in file \"%s\"\n"),tmp3
);
471 if (getword_atoll(&userbytes
,&gwarea
,'\t')<0) {
472 debuga(_("Invalid size in file \"%s\"\n"),tmp3
);
475 if (getword_atoll(&userelap
,&gwarea
,'\0')<0) {
476 debuga(_("Invalid elapsed time in file \"%s\"\n"),tmp3
);
479 if(strcmp(user_ip
,olduserip
) != 0) {
480 if (olduserip
[0]!='\0') {
481 fprintf(fp_ou
,"<tr><td></td><td class=\"data\">%s</td>",olduserip
);
482 if((UserReportFields
& USERREPORTFIELDS_CONNECT
) != 0)
483 fputs("<td></td>",fp_ou
);
484 if((UserReportFields
& USERREPORTFIELDS_BYTES
) != 0)
485 fprintf(fp_ou
,"<td class=\"data\">%s</td>",fixnum(unbytes
,1));
486 if((UserReportFields
& USERREPORTFIELDS_SETYB
) != 0)
487 fputs("<td></td>",fp_ou
);
488 if((UserReportFields
& USERREPORTFIELDS_IN_CACHE_OUT
) != 0)
489 fputs("</td><td></td><td></td>",fp_ou
);
490 if((UserReportFields
& USERREPORTFIELDS_USED_TIME
) != 0)
491 fprintf(fp_ou
,"<td class=\"data\">%s</td>",buildtime(unelap
));
492 if((UserReportFields
& USERREPORTFIELDS_MILISEC
) != 0)
493 fprintf(fp_ou
,"<td class=\"data\">%s</td>",fixnum2(unelap
,1));
494 fputs("</tr>\n",fp_ou
);
497 strcpy(olduserip
,user_ip
);
506 if (fclose(fp_ip
)==EOF
) {
507 debuga(_("Read error in \"%s\": %s\n"),tmp3
,strerror(errno
));
510 longline_destroy(&line1
);
513 debuga(_("Cannot delete \"%s\": %s\n"),tmp3
,strerror(errno
));
517 if (olduserip
[0]!='\0') {
518 fprintf(fp_ou
,"<tr><td></td><td class=\"data\">%s</td>",olduserip
);
519 if((UserReportFields
& USERREPORTFIELDS_CONNECT
) != 0)
520 fputs("<td></td>",fp_ou
);
521 if((UserReportFields
& USERREPORTFIELDS_BYTES
) != 0)
522 fprintf(fp_ou
,"<td class=\"data\">%s</td>",fixnum(unbytes
,1));
523 if((UserReportFields
& USERREPORTFIELDS_SETYB
) != 0)
524 fputs("<td></td>",fp_ou
);
525 if((UserReportFields
& USERREPORTFIELDS_IN_CACHE_OUT
) != 0)
526 fputs("</td><td></td><td></td>",fp_ou
);
527 if((UserReportFields
& USERREPORTFIELDS_USED_TIME
) != 0)
528 fprintf(fp_ou
,"<td class=\"data\">%s</td>",buildtime(unelap
));
529 if((UserReportFields
& USERREPORTFIELDS_MILISEC
) != 0)
530 fprintf(fp_ou
,"<td class=\"data\">%s</td>",fixnum2(unelap
,1));
531 fputs("</tr>\n",fp_ou
);
539 if (fclose(fp_in
)==EOF
) {
540 debuga(_("Read error in \"%s\": %s\n"),arqin
,strerror(errno
));
543 longline_destroy(&line
);
545 if (iprel
&& arqip
[0]) {
546 if (!KeepTempLog
&& unlink(arqip
)) {
547 debuga(_("Cannot delete \"%s\": %s\n"),arqip
,strerror(errno
));
551 if (!KeepTempLog
&& unlink(arqin
)) {
552 debuga(_("Cannot delete \"%s\": %s\n"),arqin
,strerror(errno
));
556 if ((UserReportFields
& (USERREPORTFIELDS_TOTAL
| USERREPORTFIELDS_AVERAGE
)) != 0)
557 fputs("<tfoot>",fp_ou
);
559 if((UserReportFields
& USERREPORTFIELDS_TOTAL
) != 0) {
560 fprintf(fp_ou
,"<tr><th></th><th class=\"header_l\">%s</th>",_("TOTAL"));
561 if((UserReportFields
& USERREPORTFIELDS_CONNECT
) != 0)
562 fprintf(fp_ou
,"<th class=\"header_r\">%s</th>",fixnum(tnacc
,1));
563 if((UserReportFields
& USERREPORTFIELDS_BYTES
) != 0)
564 fprintf(fp_ou
,"<th class=\"header_r\">%s</th>",fixnum(tnbytes
,1));
565 if((UserReportFields
& USERREPORTFIELDS_SETYB
) != 0) {
566 perc
=(totbytes
) ? tnbytes
*100. / totbytes
:0.;
567 fprintf(fp_ou
,"<th class=\"header_r\">%3.2lf%%</th>",perc
);
569 if((UserReportFields
& USERREPORTFIELDS_IN_CACHE_OUT
) != 0) {
570 inperc
=(tnbytes
) ? tnincache
* 100. / tnbytes
: 0.;
571 ouperc
=(tnbytes
) ? tnoucache
* 100. / tnbytes
: 0.;
572 fprintf(fp_ou
,"<th class=\"header_r\">%3.2lf%%</th><th class=\"header_r\">%3.2lf%%</th>",inperc
,ouperc
);
574 if((UserReportFields
& USERREPORTFIELDS_USED_TIME
) != 0)
575 fprintf(fp_ou
,"<th class=\"header_r\">%s</th>",buildtime(tnelap
));
576 if((UserReportFields
& USERREPORTFIELDS_MILISEC
) != 0)
577 fprintf(fp_ou
,"<th class=\"header_r\">%s</th>",fixnum2(tnelap
,1));
578 if((UserReportFields
& USERREPORTFIELDS_PTIME
) != 0) {
579 perc2
=(totelap
) ? tnelap
* 100. / totelap
: 0.;
580 fprintf(fp_ou
,"<th class=\"header_r\">%3.2lf%%</th>",perc2
);
582 fputs("</tr>\n",fp_ou
);
585 if (PerUserLimitsNumber
>0) {
586 int limit
=(int)(tnbytes
/1000000LLU);
589 for (i
=0 ; i
<PerUserLimitsNumber
; i
++) {
590 maskid
=i
/sizeof(unsigned int);
591 mask
=0x1U
<< (i
% sizeof(unsigned int));
592 if (limit
>PerUserLimits
[i
].Limit
&& (user_limit
[maskid
] & mask
)==0) {
595 if((fp_usr
= fopen(PerUserLimits
[i
].File
, "at")) == 0) {
596 debuga(_("Cannot open file \"%s\": %s\n"),PerUserLimits
[i
].File
,strerror(errno
));
599 switch (PerUserLimits
[i
].Output
)
602 fprintf(fp_usr
,"%s\n",uinfo
->label
);
605 fprintf(fp_usr
,"%s\n",uinfo
->ip
);
608 if (fclose(fp_usr
)==EOF
) {
609 debuga(_("Write error in \"%s\": %s\n"),PerUserLimits
[i
].File
,strerror(errno
));
612 user_limit
[maskid
]|=mask
;
615 debuga(_("Limit exceeded for user %s (%d MB). Added to file \"%s\"\n"),uinfo
->label
,
616 PerUserLimits
[i
].Limit
,PerUserLimits
[i
].File
);
621 if ((ReportType
& REPORT_TYPE_TOPUSERS
) != 0 && (UserReportFields
& USERREPORTFIELDS_AVERAGE
) != 0) {
622 totbytes2
=totbytes
/ntotuser
;
623 totelap2
=totelap
/ntotuser
;
625 fprintf(fp_ou
,"<tr><th></th><th class=\"header_l\">%s</th>",_("AVERAGE"));
626 if((UserReportFields
& USERREPORTFIELDS_CONNECT
) != 0)
627 fprintf(fp_ou
,"<th class=\"header_r\">%s</th>",fixnum(ttnacc
/ntotuser
,1));
628 if((UserReportFields
& USERREPORTFIELDS_BYTES
) != 0)
629 fprintf(fp_ou
,"<th class=\"header_r\">%s</th>",fixnum(totbytes2
,1));
630 fprintf(fp_ou
,"<th></th><th></th><th></th>");
631 if((UserReportFields
& USERREPORTFIELDS_USED_TIME
) != 0)
632 fprintf(fp_ou
,"<th class=\"header_r\">%s</th>",buildtime(totelap2
));
633 if((UserReportFields
& USERREPORTFIELDS_MILISEC
) != 0)
634 fprintf(fp_ou
,"<th class=\"header_r\">%s</th>",fixnum2(totelap2
,1));
635 if((UserReportFields
& USERREPORTFIELDS_PTIME
) != 0) {
636 perc2
= (totelap
) ? totelap2
* 100. / totelap
: 0.;
637 fprintf(fp_ou
,"<th class=\"header_r\">%3.2lf%%</th>",perc2
);
639 fputs("</tr>\n",fp_ou
);
642 if ((UserReportFields
& (USERREPORTFIELDS_TOTAL
| USERREPORTFIELDS_AVERAGE
)) != 0)
643 fputs("</tfoot>",fp_ou
);
645 fputs("</table></div>\n",fp_ou
);
646 write_html_trailer(fp_ou
);
647 if (fclose(fp_ou
)==EOF
) {
648 debuga(_("Write error in \"%s\": %s\n"),arqou
,strerror(errno
));
655 userinfo_stopscan(uscan
);