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"
30 extern struct globalstatstruct globstat
;
34 FILE *fp_in
, *fp_ou
, *fp_ip
, *fp_ip2
, *fp_usr
;
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;
40 long long int ntotuser
=1;
41 long long int userbytes
, userelap
;
43 char arqin
[MAXLEN
], arqou
[MAXLEN
], arqper
[MAXLEN
], arqip
[MAXLEN
];
44 char *url
, tmsg
[50], csort
[MAXLEN
];
46 char user_ip
[MAXLEN
], olduserip
[MAXLEN
], tmp2
[MAXLEN
], tmp3
[MAXLEN
];
51 long long int tnacc
=0, ttnacc
=0, unacc
=0;
52 double perc
=0, perc2
=0, ouperc
=0, inperc
=0;
55 int have_denied_report
;
56 const char *sort_field
;
57 const char *sort_order
;
59 char siteind
[MAX_TRUNCATED_URL
];
60 struct getwordstruct gwarea
;
62 const struct userinfostruct
*uinfo
;
65 if((ReportType
& REPORT_TYPE_USERS_SITES
) == 0) return;
67 if (snprintf(tmp2
,sizeof(tmp2
),"%s/sargtmp.unsort",tmp
)>=sizeof(tmp2
)) {
68 debuga(_("File name too long: %s/sargtmp.unsort\n"),tmp
);
72 if (snprintf(tmp3
,sizeof(tmp3
),"%s/sargtmp.log",tmp
)>=sizeof(tmp3
)) {
73 debuga(_("File name too long: %s/sargtmp.log\n"),tmp
);
78 totbytes
=globstat
.nbytes
;
79 totelap
=globstat
.elap
;
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
));
87 if (!fgets(totuser
,sizeof(totuser
),fp_in
)) {
88 debuga(_("(html11) read error in %s\n"),arqper
);
92 ntotuser
=my_atoll(totuser
);
93 if (ntotuser
<=0) ntotuser
=1;
98 sort_labels(&sort_field
,&sort_order
);
100 uscan
=userinfo_startscan();
102 debuga(_("Cannot enumerate the user list\n"));
105 while ( (uinfo
= userinfo_advancescan(uscan
)) != NULL
) {
106 user
=uinfo
->filename
;
108 if (snprintf(warea
,sizeof(warea
),"%s/%s",outdirname
,user
)>=sizeof(warea
)) {
109 debuga(_("Destination directory too long: %s/%s\n"),outdirname
,user
);
112 if (access(warea
, R_OK
) != 0) {
113 if (mkdir(warea
,0755)) {
114 debuga(_("Cannot create directory %s - %s\n"),warea
,strerror(errno
));
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
);
126 if ((fp_in
= fopen(arqin
, "r")) == 0){
127 if (uinfo
->no_report
) continue;
128 debuga(_("(html3) Cannot open file %s\n"),arqin
);
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
);
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
);
140 if(access(duser
, R_OK
) != 0)
141 have_denied_report
=0;
143 have_denied_report
=1;
145 if ((line
=longline_create())==NULL
) {
146 debuga(_("Not enough memory to read file %s\n"),arqin
);
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\n"),arqou
);
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 fputs("<div class=\"report\"><table cellpadding=\"2\" cellspacing=\"1\"",fp_ou
);
209 if (SortTableJs
[0]) fputs(" class=\"sortable\"",fp_ou
);
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.
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"));
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"));
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"));
238 fputs("</tr></thead>\n",fp_ou
);
241 debuga(_("Making report: %s\n"),uinfo
->id
);
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
);
252 if (getword_atoll(&nnbytes
,&gwarea
,'\t')<0) {
253 debuga(_("There is a broken number of bytes in file %s\n"),arqin
);
256 if (getword_ptr(buf
,&url
,&gwarea
,'\t')<0) {
257 debuga(_("There is a broken url in file %s\n"),arqin
);
260 if (getword(tmsg
,sizeof(tmsg
),&gwarea
,'\t')<0) {
261 debuga(_("There is a broken access code in file %s\n"),arqin
);
264 if (getword_atoll(&nnelap
,&gwarea
,'\t')<0) {
265 debuga(_("There is a broken elapsed time in file %s\n"),arqin
);
268 if (getword_atoll(&incache
,&gwarea
,'\t')<0) {
269 debuga(_("There is a broken in cache column in file %s\n"),arqin
);
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__
);
277 if(UserReportLimit
<=0 || count
<=UserReportLimit
) {
280 if(IndexTree
== INDEX_TREE_DATE
)
281 sprintf(tmp6
,"../%s",ImageFile
);
283 strcpy(tmp6
,"../../images");
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"));
289 fprintf(fp_ou
,"<td class=\"data\"></td>");
293 fprintf(fp_ou
,"<td class=\"data2\"><span style=\"color:%s;\">%s</span></td>",PrivacyStringColor
,PrivacyString
);
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> ",tmp6
);
301 output_html_link(fp_ou
,url
,100);
302 fputs("</td>",fp_ou
);
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));
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));
315 if((UserReportFields
& USERREPORTFIELDS_SETYB
) != 0) {
316 perc
=(tnbytes
) ? nnbytes
* 100. / tnbytes
: 0.;
317 fprintf(fp_ou
,"<td class=\"data\">%3.2lf%%</td>",perc
);
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
);
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
));
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));
334 if((UserReportFields
& USERREPORTFIELDS_PTIME
) != 0) {
335 perc2
=(tnelap
) ? nnelap
* 100. / tnelap
: 0.;
336 fprintf(fp_ou
,"<td class=\"data\">%3.2lf%%</td>",perc2
);
339 if(strncmp(tmsg
,"OK",2) != 0)
340 fprintf(fp_ou
,"<td class=\"data\">%s</td>",_("DENIED"));
342 fputs("</tr>\n",fp_ou
);
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
));
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
);
358 if ((fp_ip
= fopen(arqip
, "r")) == 0){
359 debuga(_("(html6) Cannot open file %s\n"),arqip
);
363 if ((fp_ip2
= MY_FOPEN(tmp2
, "a")) == 0){
364 debuga(_("(html7) Cannot open file %s\n"),tmp2
);
368 if ((line1
=longline_create())==NULL
) {
369 debuga(_("Not enough memory to read file %s\n"),arqip
);
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
);
378 if (getword_ptr(buf
,&user_url
,&gwarea
,'\t')<0) {
379 debuga(_("Maybe you have a broken url in your %s file\n"),tmp3
);
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
);
387 if (getword_skip(15,&gwarea
,'\t')<0) {
388 debuga(_("Maybe you have a broken time in your %s file\n"),tmp3
);
391 if (getword_atoll(&userbytes
,&gwarea
,'\t')<0) {
392 debuga(_("Maybe you have a broken size in your %s file\n"),tmp3
);
395 if (getword_atoll(&userelap
,&gwarea
,'\0')<0) {
396 debuga(_("Maybe you have a broken elapsed time in your %s file\n"),tmp3
);
399 fprintf(fp_ip2
,"%s\t%"PRIu64
"\t%"PRIu64
"\n",user_ip
,(uint64_t)userbytes
,(uint64_t)userelap
);
401 longline_destroy(&line1
);
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
);
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
);
417 if ((fp_ip
= MY_FOPEN(tmp3
, "r")) == 0) {
418 debuga(_("(html8) Cannot open file %s\n"),tmp3
);
424 if ((line1
=longline_create())==NULL
) {
425 debuga(_("Not enough memory to read file %s\n"),arqip
);
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
);
434 if (getword_atoll(&userbytes
,&gwarea
,'\t')<0) {
435 debuga(_("Maybe you have a broken size in your %s file\n"),tmp3
);
438 if (getword_atoll(&userelap
,&gwarea
,'\0')<0) {
439 debuga(_("Maybe you have a broken elapsed time in your %s file\n"),tmp3
);
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
);
460 strcpy(olduserip
,user_ip
);
471 longline_destroy(&line1
);
474 debuga(_("Cannot delete %s - %s\n"),tmp2
,strerror(errno
));
478 debuga(_("Cannot delete %s - %s\n"),tmp3
,strerror(errno
));
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
);
506 longline_destroy(&line
);
508 if (iprel
&& arqip
[0]) {
510 debuga(_("Cannot delete %s - %s\n"),arqip
,strerror(errno
));
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(PerUserLimit
> 0) {
549 if(tnbytes
> (PerUserLimit
*1000000)) {
551 if(access(PerUserLimitFile
, R_OK
) == 0) {
552 if((fp_usr
= fopen(PerUserLimitFile
, "r")) == 0) {
553 debuga(_("(html9) Cannot open file %s\n"),PerUserLimitFile
);
556 while(fgets(tmp6
,sizeof(tmp6
),fp_usr
)!=NULL
) {
558 if(strcmp(tmp6
,uinfo
->label
) == 0) {
567 if((fp_usr
= fopen(PerUserLimitFile
, "a")) == 0) {
568 debuga(_("(html10) Cannot open file %s\n"),PerUserLimitFile
);
571 fprintf(fp_usr
,"%s\n",uinfo
->label
);
575 debuga(_("User %s limit exceeded (%d MB). Added to file %s\n"),uinfo
->label
,PerUserLimit
,PerUserLimitFile
);
580 if ((ReportType
& REPORT_TYPE_TOPUSERS
) != 0 && (UserReportFields
& USERREPORTFIELDS_AVERAGE
) != 0) {
581 totbytes2
=totbytes
/ntotuser
;
582 totelap2
=totelap
/ntotuser
;
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
);
598 fputs("</tr>\n",fp_ou
);
601 if ((UserReportFields
& (USERREPORTFIELDS_TOTAL
| USERREPORTFIELDS_AVERAGE
)) != 0)
602 fputs("</tfoot>",fp_ou
);
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
));
613 userinfo_stopscan(uscan
);