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"
32 FILE *fp_in
, *fp_ou
, *fp_ip
, *fp_ip2
, *fp_usr
;
34 long long int nnbytes
=0, unbytes
=0, tnbytes
=0, totbytes
=0, totbytes2
=0;
35 long long int totelap
=0, totelap2
=0, nnelap
=0, unelap
=0, tnelap
=0;
36 long long int incache
=0, oucache
=0, tnincache
=0, tnoucache
=0, twork
=0;
38 long long int ntotuser
;
39 long long int userbytes
, userelap
;
41 char arqin
[MAXLEN
], arqou
[MAXLEN
], arqper
[MAXLEN
], arqip
[MAXLEN
];
42 char *url
, tmsg
[50], csort
[MAXLEN
];
44 char user_ip
[MAXLEN
], olduserip
[MAXLEN
], tmp2
[MAXLEN
], tmp3
[MAXLEN
];
49 long long int tnacc
=0, ttnacc
=0, unacc
=0;
50 double perc
=0, perc2
=0, ouperc
=0, inperc
=0;
53 int have_denied_report
;
54 const char *sort_field
;
55 const char *sort_order
;
57 char siteind
[MAX_TRUNCATED_URL
];
58 struct getwordstruct gwarea
;
60 struct generalitemstruct item
;
61 const struct userinfostruct
*uinfo
;
64 if((ReportType
& REPORT_TYPE_USERS_SITES
) == 0) return;
67 strcat(tmp2
,"/sargtmp.unsort");
70 strcat(tmp3
,"/sargtmp.log");
72 snprintf(arqper
,sizeof(arqper
),"%s/sarg-general",outdirname
);
73 if ((fp_in
= fopen(arqper
, "r")) == 0){
74 debuga(_("(html2) Cannot open file %s\n"),arqper
);
77 if ((line
=longline_create())==NULL
) {
78 debuga(_("Not enough memory to read file %s\n"),arqper
);
84 while((buf
=longline_read(fp_in
,line
))!=NULL
) {
85 ger_read(buf
,&item
,arqper
);
88 totbytes
+=item
.nbytes
;
93 longline_destroy(&line
);
95 snprintf(arqper
,sizeof(arqper
),"%s/sarg-users",outdirname
);
96 if ((fp_in
= fopen(arqper
, "r")) == 0){
97 debuga(_("(html11) Cannot open file %s\n"),arqper
);
100 if (!fgets(totuser
,sizeof(totuser
),fp_in
)) {
101 debuga(_("(html11) read error in %s\n"),arqper
);
105 ntotuser
=my_atoll(totuser
);
106 if (ntotuser
<=0) ntotuser
=1;
110 sort_labels(&sort_field
,&sort_order
);
112 uscan
=userinfo_startscan();
114 debuga(_("Cannot enumerate the user list\n"));
117 while ( (uinfo
= userinfo_advancescan(uscan
)) != NULL
) {
118 user
=uinfo
->filename
;
120 if (snprintf(warea
,sizeof(warea
),"%s/%s",outdirname
,user
)>=sizeof(warea
)) {
121 debuga(_("Destination directory too long: %s/%s\n"),outdirname
,user
);
124 if (access(warea
, R_OK
) != 0) {
125 if (mkdir(warea
,0755)) {
126 debuga(_("Cannot create directory %s - %s\n"),warea
,strerror(errno
));
134 if (snprintf(arqin
,sizeof(arqin
),"%s/%s.txt",tmp
,uinfo
->filename
)>=sizeof(arqin
)) {
135 debuga(_("Input file name too long: %s/%s.txt\n"),tmp
,uinfo
->filename
);
138 if ((fp_in
= fopen(arqin
, "r")) == 0){
139 if (uinfo
->no_report
) continue;
140 debuga(_("(html3) Cannot open file %s\n"),arqin
);
144 if (snprintf(arqou
,sizeof(arqou
),"%s/%s/%s.html",outdirname
,uinfo
->filename
,uinfo
->filename
)>=sizeof(arqou
)) {
145 debuga(_("Output file name too long: %s/%s/%s.html\n"),outdirname
,uinfo
->filename
,uinfo
->filename
);
148 if (snprintf(duser
,sizeof(duser
),"%s/%s/denied_%s.html",tmp
,uinfo
->filename
,uinfo
->filename
)>=sizeof(duser
)) {
149 debuga(_("File name too long: %s/%s/denied_%s.html\n"),tmp
,uinfo
->filename
,uinfo
->filename
);
152 if(access(duser
, R_OK
) != 0)
153 have_denied_report
=0;
155 have_denied_report
=1;
157 if ((line
=longline_create())==NULL
) {
158 debuga(_("Not enough memory to read file %s\n"),arqin
);
167 while((buf
=longline_read(fp_in
,line
))!=NULL
) {
168 getword_start(&gwarea
,buf
);
169 if (getword_atoll(<emp
,&gwarea
,'\t')<0) {
170 debuga(_("There is a broken number of access in file %s\n"),arqin
);
174 if (getword_atoll(<emp
,&gwarea
,'\t')<0) {
175 debuga(_("There is a broken downloaded size in file %s\n"),arqin
);
179 if (getword_ptr(NULL
,NULL
,&gwarea
,'\t')<0) {
180 debuga(_("There is a broken url in file %s\n"),arqin
);
183 if (getword_skip(MAXLEN
,&gwarea
,'\t')<0) {
184 debuga(_("There is a broken access code in file %s\n"),arqin
);
187 if (getword_atoll(<emp
,&gwarea
,'\t')<0) {
188 debuga(_("There is a broken elapsed time in file %s\n"),arqin
);
192 if (getword_atoll(<emp
,&gwarea
,'\t')<0) {
193 debuga(_("There is a broken in-cache volume in file %s\n"),arqin
);
197 if (getword_atoll(<emp
,&gwarea
,'\n')<0) {
198 debuga(_("There is a broken out-cache volume in file %s\n"),arqin
);
206 if ((fp_ou
= fopen(arqou
, "w")) == 0){
207 debuga(_("(html5) Cannot open file %s\n"),arqou
);
211 write_html_header(fp_ou
,(IndexTree
== INDEX_TREE_DATE
) ? 4 : 2,_("User report"),HTML_JS_SORTTABLE
);
212 fprintf(fp_ou
,"<tr><td class=\"header_c\">%s: %s</td></tr>\n",_("Period"),period
.html
);
213 fprintf(fp_ou
,"<tr><td class=\"header_c\">%s: %s</td></tr>\n",_("User"),uinfo
->label
);
214 fputs("<tr><td class=\"header_c\">",fp_ou
);
215 fprintf(fp_ou
,_("Sort: %s, %s"),sort_field
,sort_order
);
216 fputs("</td></tr>\n",fp_ou
);
217 fprintf(fp_ou
,"<tr><th class=\"header_c\">%s</th></tr>\n",_("User report"));
218 close_html_header(fp_ou
);
220 fputs("<div class=\"report\"><table cellpadding=\"2\" cellspacing=\"1\"",fp_ou
);
221 if (SortTableJs
[0]) fputs(" class=\"sortable\"",fp_ou
);
224 /*! \bug This line lays before the header of the table and is therefore invalid
225 HTML. It will also break the sorttable script. Beside, I suspect it serves no purpose.
227 if(have_denied_report
) {
228 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"));
231 fputs("<thead><tr><th class=\"sorttable_nosort\"></th><th class=\"header_l",fp_ou
);
232 if (SortTableJs
[0]) fputs(" sorttable_alpha",fp_ou
);
233 fprintf(fp_ou
,"\">%s</th>",_("ACCESSED SITE"));
235 if((UserReportFields
& USERREPORTFIELDS_CONNECT
) != 0)
236 fprintf(fp_ou
,"<th class=\"header_l\">%s</th>",_("CONNECT"));
237 if((UserReportFields
& USERREPORTFIELDS_BYTES
) != 0)
238 fprintf(fp_ou
,"<th class=\"header_l\">%s</th>",_("BYTES"));
239 if((UserReportFields
& USERREPORTFIELDS_SETYB
) != 0)
240 fprintf(fp_ou
,"<th class=\"header_l\">%%%s</th>",_("BYTES"));
241 if((UserReportFields
& USERREPORTFIELDS_IN_CACHE_OUT
) != 0)
242 fprintf(fp_ou
,"<th class=\"header_c\" colspan=\"2\">%s</th><th style=\"display:none;\"></th>",_("IN-CACHE-OUT"));
243 if((UserReportFields
& USERREPORTFIELDS_USED_TIME
) != 0)
244 fprintf(fp_ou
,"<th class=\"header_l\">%s</th>",_("ELAPSED TIME"));
245 if((UserReportFields
& USERREPORTFIELDS_MILISEC
) != 0)
246 fprintf(fp_ou
,"<th class=\"header_l\">%s</th>",_("MILLISEC"));
247 if((UserReportFields
& USERREPORTFIELDS_PTIME
) != 0)
248 fprintf(fp_ou
,"<th class=\"header_l\">%%%s</th>",_("TIME"));
250 fputs("</tr></thead>\n",fp_ou
);
253 debuga(_("Making report: %s\n"),uinfo
->id
);
257 while((buf
=longline_read(fp_in
,line
))!=NULL
) {
258 getword_start(&gwarea
,buf
);
259 if (getword_atoll(&twork
,&gwarea
,'\t')<0) {
260 debuga(_("There is a broken number of access in file %s\n"),arqin
);
263 if (getword_atoll(&nnbytes
,&gwarea
,'\t')<0) {
264 debuga(_("There is a broken number of bytes in file %s\n"),arqin
);
267 if (getword_ptr(buf
,&url
,&gwarea
,'\t')<0) {
268 debuga(_("There is a broken url in file %s\n"),arqin
);
271 if (getword(tmsg
,sizeof(tmsg
),&gwarea
,'\t')<0) {
272 debuga(_("There is a broken access code in file %s\n"),arqin
);
275 if (getword_atoll(&nnelap
,&gwarea
,'\t')<0) {
276 debuga(_("There is a broken elapsed time in file %s\n"),arqin
);
279 if (getword_atoll(&incache
,&gwarea
,'\t')<0) {
280 debuga(_("There is a broken in cache column in file %s\n"),arqin
);
283 if (getword_atoll(&oucache
,&gwarea
,'\n')<0) {
284 debuga(_("There is a broken out of cache column in file %s (%d)\n"),arqin
,__LINE__
);
288 if(UserReportLimit
<=0 || count
<=UserReportLimit
) {
291 if(IndexTree
== INDEX_TREE_DATE
)
292 sprintf(tmp6
,"../%s",ImageFile
);
294 strcpy(tmp6
,"../../images");
296 if((ReportType
& REPORT_TYPE_SITE_USER_TIME_DATE
) != 0) {
297 url_to_file(url
,siteind
,sizeof(siteind
));
298 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"));
300 fprintf(fp_ou
,"<td class=\"data\"></td>");
304 fprintf(fp_ou
,"<td class=\"data2\"><span style=\"color:%s;\">%s</span></td>",PrivacyStringColor
,PrivacyString
);
306 fputs("<td class=\"data2\">",fp_ou
);
307 if(BlockIt
[0]!='\0') {
308 fprintf(fp_ou
,"<a href=\"%s%s?url=",wwwDocumentRoot
,BlockIt
);
309 output_html_url(fp_ou
,url
);
310 fprintf(fp_ou
,"\"><img src=\"%s/sarg-squidguard-block.png\"></a> ",tmp6
);
312 fputs("<a href=\"http://",fp_ou
);
313 output_html_url(fp_ou
,url
);
315 output_html_string(fp_ou
,url
,100);
316 fputs("</a></td>",fp_ou
);
319 if((UserReportFields
& USERREPORTFIELDS_CONNECT
) != 0) {
320 fputs("<td class=\"data\"",fp_ou
);
321 if (SortTableJs
[0]) fprintf(fp_ou
," sorttable_customkey=\"%"PRId64
"\"",(int64_t)twork
);
322 fprintf(fp_ou
,">%s</td>",fixnum(twork
,1));
324 if((UserReportFields
& USERREPORTFIELDS_BYTES
) != 0) {
325 fputs("<td class=\"data\"",fp_ou
);
326 if (SortTableJs
[0]) fprintf(fp_ou
," sorttable_customkey=\"%"PRId64
"\"",(int64_t)nnbytes
);
327 fprintf(fp_ou
,">%s</td>",fixnum(nnbytes
,1));
329 if((UserReportFields
& USERREPORTFIELDS_SETYB
) != 0) {
330 perc
=(tnbytes
) ? nnbytes
* 100. / tnbytes
: 0.;
331 fprintf(fp_ou
,"<td class=\"data\">%3.2lf%%</td>",perc
);
333 if((UserReportFields
& USERREPORTFIELDS_IN_CACHE_OUT
) != 0) {
334 inperc
=(nnbytes
) ? incache
* 100. / nnbytes
: 0.;
335 ouperc
=(nnbytes
) ? oucache
* 100. / nnbytes
: 0.;
336 fprintf(fp_ou
,"<td class=\"data\">%3.2lf%%</td><td class=\"data\">%3.2lf%%</td>",inperc
,ouperc
);
338 if((UserReportFields
& USERREPORTFIELDS_USED_TIME
) != 0) {
339 fputs("<td class=\"data\"",fp_ou
);
340 if (SortTableJs
[0]) fprintf(fp_ou
," sorttable_customkey=\"%"PRId64
"\"",(int64_t)nnelap
);
341 fprintf(fp_ou
,">%s</td>",buildtime(nnelap
));
343 if((UserReportFields
& USERREPORTFIELDS_MILISEC
) != 0) {
344 fputs("<td class=\"data\"",fp_ou
);
345 if (SortTableJs
[0]) fprintf(fp_ou
," sorttable_customkey=\"%"PRId64
"\"",(int64_t)nnelap
);
346 fprintf(fp_ou
,">%s</td>",fixnum2(nnelap
,1));
348 if((UserReportFields
& USERREPORTFIELDS_PTIME
) != 0) {
349 perc2
=(tnelap
) ? nnelap
* 100. / tnelap
: 0.;
350 fprintf(fp_ou
,"<td class=\"data\">%3.2lf%%</td>",perc2
);
353 if(strncmp(tmsg
,"OK",2) != 0)
354 fprintf(fp_ou
,"<td class=\"data\">%s</td>",_("DENIED"));
356 fputs("</tr>\n",fp_ou
);
358 } else if ((ReportType
& REPORT_TYPE_SITE_USER_TIME_DATE
) != 0) {
359 url_to_file(url
,siteind
,sizeof(siteind
));
360 snprintf(tmp2
,sizeof(tmp2
),"%s/%s/tt%s-%s.html",outdirname
,uinfo
->filename
,uinfo
->filename
,siteind
);
361 if (unlink(tmp2
)!=0) {
362 debuga(_("Cannot delete unused file \"%s\" - %s\n"),tmp2
,strerror(errno
));
367 if (snprintf(arqip
,sizeof(arqip
),"%s/%s.ip",tmp
,uinfo
->filename
)>=sizeof(arqip
)) {
368 debuga(_("File name too long: %s/%s.ip\n"),tmp
,uinfo
->filename
);
372 if ((fp_ip
= fopen(arqip
, "r")) == 0){
373 debuga(_("(html6) Cannot open file %s\n"),arqip
);
377 if ((fp_ip2
= MY_FOPEN(tmp2
, "a")) == 0){
378 debuga(_("(html7) Cannot open file %s\n"),tmp2
);
382 if ((line1
=longline_create())==NULL
) {
383 debuga(_("Not enough memory to read file %s\n"),arqip
);
386 while((buf
=longline_read(fp_ip
,line1
))!=NULL
) {
387 getword_start(&gwarea
,buf
);
388 if (getword(user_ip
,sizeof(user_ip
),&gwarea
,'\t')<0) {
389 debuga(_("Maybe you have a broken user IP in your %s file\n"),tmp3
);
392 if (getword_ptr(buf
,&user_url
,&gwarea
,'\t')<0) {
393 debuga(_("Maybe you have a broken url in your %s file\n"),tmp3
);
396 if (strncmp(user_url
,url
,strlen(url
))!=0) continue;
397 if (getword_skip(15,&gwarea
,'\t')<0) {
398 debuga(_("Maybe you have a broken day in your %s file\n"),tmp3
);
401 if (getword_skip(15,&gwarea
,'\t')<0) {
402 debuga(_("Maybe you have a broken time in your %s file\n"),tmp3
);
405 if (getword_atoll(&userbytes
,&gwarea
,'\t')<0) {
406 debuga(_("Maybe you have a broken size in your %s file\n"),tmp3
);
409 if (getword_atoll(&userelap
,&gwarea
,'\0')<0) {
410 debuga(_("Maybe you have a broken elapsed time in your %s file\n"),tmp3
);
413 fprintf(fp_ip2
,"%s\t%"PRIu64
"\t%"PRIu64
"\n",user_ip
,(uint64_t)userbytes
,(uint64_t)userelap
);
415 longline_destroy(&line1
);
420 sprintf(csort
,"sort -n -T \"%s\" -k 1,1 -k 2,2 -o \"%s\" \"%s\"",tmp
,tmp3
,tmp2
);
421 cstatus
=system(csort
);
422 if (!WIFEXITED(cstatus
) || WEXITSTATUS(cstatus
)) {
423 debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus
));
424 debuga(_("sort command: %s\n"),csort
);
428 if ((fp_ip
= MY_FOPEN(tmp3
, "r")) == 0) {
429 debuga(_("(html8) Cannot open file %s\n"),tmp3
);
435 if ((line1
=longline_create())==NULL
) {
436 debuga(_("Not enough memory to read file %s\n"),arqip
);
439 while((buf
=longline_read(fp_ip
,line1
))!=NULL
) {
440 getword_start(&gwarea
,buf
);
441 if (getword(user_ip
,sizeof(user_ip
),&gwarea
,'\t')<0) {
442 debuga(_("Maybe you have a broken user IP in your %s file\n"),tmp3
);
445 if (getword_atoll(&userbytes
,&gwarea
,'\t')<0) {
446 debuga(_("Maybe you have a broken size in your %s file\n"),tmp3
);
449 if (getword_atoll(&userelap
,&gwarea
,'\0')<0) {
450 debuga(_("Maybe you have a broken elapsed time in your %s file\n"),tmp3
);
453 if(strcmp(user_ip
,olduserip
) != 0) {
454 if (olduserip
[0]!='\0') {
455 fprintf(fp_ou
,"<tr><td></td><td class=\"data\">%s</td>",olduserip
);
456 if((UserReportFields
& USERREPORTFIELDS_CONNECT
) != 0)
457 fputs("<td></td>",fp_ou
);
458 if((UserReportFields
& USERREPORTFIELDS_BYTES
) != 0)
459 fprintf(fp_ou
,"<td class=\"data\">%s</td>",fixnum(unbytes
,1));
460 if((UserReportFields
& USERREPORTFIELDS_SETYB
) != 0)
461 fputs("<td></td>",fp_ou
);
462 if((UserReportFields
& USERREPORTFIELDS_IN_CACHE_OUT
) != 0)
463 fputs("</td><td></td><td></td>",fp_ou
);
464 if((UserReportFields
& USERREPORTFIELDS_USED_TIME
) != 0)
465 fprintf(fp_ou
,"<td class=\"data\">%s</td>",buildtime(unelap
));
466 if((UserReportFields
& USERREPORTFIELDS_MILISEC
) != 0)
467 fprintf(fp_ou
,"<td class=\"data\">%s</td>",fixnum2(unelap
,1));
468 fputs("</tr>\n",fp_ou
);
471 strcpy(olduserip
,user_ip
);
482 longline_destroy(&line1
);
485 debuga(_("Cannot delete %s - %s\n"),tmp2
,strerror(errno
));
489 debuga(_("Cannot delete %s - %s\n"),tmp3
,strerror(errno
));
493 if (olduserip
[0]!='\0') {
494 fprintf(fp_ou
,"<tr><td></td><td class=\"data\">%s</td>",olduserip
);
495 if((UserReportFields
& USERREPORTFIELDS_CONNECT
) != 0)
496 fputs("<td></td>",fp_ou
);
497 if((UserReportFields
& USERREPORTFIELDS_BYTES
) != 0)
498 fprintf(fp_ou
,"<td class=\"data\">%s</td>",fixnum(unbytes
,1));
499 if((UserReportFields
& USERREPORTFIELDS_SETYB
) != 0)
500 fputs("<td></td>",fp_ou
);
501 if((UserReportFields
& USERREPORTFIELDS_IN_CACHE_OUT
) != 0)
502 fputs("</td><td></td><td></td>",fp_ou
);
503 if((UserReportFields
& USERREPORTFIELDS_USED_TIME
) != 0)
504 fprintf(fp_ou
,"<td class=\"data\">%s</td>",buildtime(unelap
));
505 if((UserReportFields
& USERREPORTFIELDS_MILISEC
) != 0)
506 fprintf(fp_ou
,"<td class=\"data\">%s</td>",fixnum2(unelap
,1));
507 fputs("</tr>\n",fp_ou
);
517 longline_destroy(&line
);
521 debuga(_("Cannot delete %s - %s\n"),arqip
,strerror(errno
));
526 debuga(_("Cannot delete %s - %s\n"),arqin
,strerror(errno
));
530 if ((UserReportFields
& (USERREPORTFIELDS_TOTAL
| USERREPORTFIELDS_AVERAGE
)) != 0)
531 fputs("<tfoot>",fp_ou
);
533 if((UserReportFields
& USERREPORTFIELDS_TOTAL
) != 0) {
534 fprintf(fp_ou
,"<tr><th></th><th class=\"header_l\">%s</th>",_("TOTAL"));
535 if((UserReportFields
& USERREPORTFIELDS_CONNECT
) != 0)
536 fprintf(fp_ou
,"<th class=\"header_r\">%s</th>",fixnum(tnacc
,1));
537 if((UserReportFields
& USERREPORTFIELDS_BYTES
) != 0)
538 fprintf(fp_ou
,"<th class=\"header_r\">%s</th>",fixnum(tnbytes
,1));
539 if((UserReportFields
& USERREPORTFIELDS_SETYB
) != 0) {
540 perc
=(totbytes
) ? tnbytes
*100. / totbytes
:0.;
541 fprintf(fp_ou
,"<th class=\"header_r\">%3.2lf%%</th>",perc
);
543 if((UserReportFields
& USERREPORTFIELDS_IN_CACHE_OUT
) != 0) {
544 inperc
=(tnbytes
) ? tnincache
* 100. / tnbytes
: 0.;
545 ouperc
=(tnbytes
) ? tnoucache
* 100. / tnbytes
: 0.;
546 fprintf(fp_ou
,"<th class=\"header_r\">%3.2lf%%</th><th class=\"header_r\">%3.2lf%%</th>",inperc
,ouperc
);
548 if((UserReportFields
& USERREPORTFIELDS_USED_TIME
) != 0)
549 fprintf(fp_ou
,"<th class=\"header_r\">%s</th>",buildtime(tnelap
));
550 if((UserReportFields
& USERREPORTFIELDS_MILISEC
) != 0)
551 fprintf(fp_ou
,"<th class=\"header_r\">%s</th>",fixnum2(tnelap
,1));
552 if((UserReportFields
& USERREPORTFIELDS_PTIME
) != 0) {
553 perc2
=(totelap
) ? tnelap
* 100. / totelap
: 0.;
554 fprintf(fp_ou
,"<th class=\"header_r\">%3.2lf%%</th>",perc2
);
556 fputs("</tr>\n",fp_ou
);
559 if(PerUserLimit
> 0) {
560 if(tnbytes
> (PerUserLimit
*1000000)) {
562 if(access(PerUserLimitFile
, R_OK
) == 0) {
563 if((fp_usr
= fopen(PerUserLimitFile
, "r")) == 0) {
564 debuga(_("(html9) Cannot open file %s\n"),PerUserLimitFile
);
567 while(fgets(tmp6
,sizeof(tmp6
),fp_usr
)!=NULL
) {
569 if(strcmp(tmp6
,uinfo
->label
) == 0) {
578 if((fp_usr
= fopen(PerUserLimitFile
, "a")) == 0) {
579 debuga(_("(html10) Cannot open file %s\n"),PerUserLimitFile
);
582 fprintf(fp_usr
,"%s\n",uinfo
->label
);
586 debuga(_("User %s limit exceeded (%d MB). Added to file %s\n"),uinfo
->label
,PerUserLimit
,PerUserLimitFile
);
591 if ((ReportType
& REPORT_TYPE_TOPUSERS
) != 0 && (UserReportFields
& USERREPORTFIELDS_AVERAGE
) != 0) {
592 totbytes2
=totbytes
/ntotuser
;
593 totelap2
=totelap
/ntotuser
;
595 fprintf(fp_ou
,"<tr><th></th><th class=\"header_l\">%s</th>",_("AVERAGE"));
596 if((UserReportFields
& USERREPORTFIELDS_CONNECT
) != 0)
597 fprintf(fp_ou
,"<th class=\"header_r\">%s</th>",fixnum(ttnacc
/ntotuser
,1));
598 if((UserReportFields
& USERREPORTFIELDS_BYTES
) != 0)
599 fprintf(fp_ou
,"<th class=\"header_r\">%s</th>",fixnum(totbytes2
,1));
600 fprintf(fp_ou
,"<th></th><th></th><th></th>");
601 if((UserReportFields
& USERREPORTFIELDS_USED_TIME
) != 0)
602 fprintf(fp_ou
,"<th class=\"header_r\">%s</th>",buildtime(totelap2
));
603 if((UserReportFields
& USERREPORTFIELDS_MILISEC
) != 0)
604 fprintf(fp_ou
,"<th class=\"header_r\">%s</th>",fixnum2(totelap2
,1));
605 if((UserReportFields
& USERREPORTFIELDS_PTIME
) != 0) {
606 perc2
= (totelap
) ? totelap2
* 100. / totelap
: 0.;
607 fprintf(fp_ou
,"<th class=\"header_r\">%3.2lf%%</th>",perc2
);
609 fputs("</tr>\n",fp_ou
);
612 if ((UserReportFields
& (USERREPORTFIELDS_TOTAL
| USERREPORTFIELDS_AVERAGE
)) != 0)
613 fputs("</tfoot>",fp_ou
);
615 fputs("</table></div>\n",fp_ou
);
616 if (write_html_trailer(fp_ou
)<0)
617 debuga(_("Write error in file %s\n"),arqou
);
618 if (fclose(fp_ou
)==EOF
)
619 debuga(_("Failed to close file %s - %s\n"),arqou
,strerror(errno
));
624 userinfo_stopscan(uscan
);