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
;
41 long long int userbytes
, userelap
;
43 char arqin
[MAXLEN
], arqou
[MAXLEN
], arqip
[MAXLEN
];
44 char *url
, tmsg
[50], csort
[MAXLEN
];
46 char user_ip
[MAXLEN
], olduserip
[MAXLEN
], tmp2
[MAXLEN
], tmp3
[MAXLEN
];
50 long long int tnacc
=0, ttnacc
=0;
51 double perc
=0, perc2
=0, ouperc
=0, inperc
=0;
54 bool have_denied_report
;
55 const char *sort_field
;
56 const char *sort_order
;
57 char siteind
[MAX_TRUNCATED_URL
];
58 struct getwordstruct gwarea
;
60 const struct userinfostruct
*uinfo
;
63 if (snprintf(tmp2
,sizeof(tmp2
),"%s/sargtmp.int_unsort",tmp
)>=sizeof(tmp2
)) {
64 debuga(_("Path too long: "));
65 debuga_more("%s/sargtmp.int_unsort\n",tmp
);
69 if (snprintf(tmp3
,sizeof(tmp3
),"%s/sargtmp.int_log",tmp
)>=sizeof(tmp3
)) {
70 debuga(_("Path too long: "));
71 debuga_more("%s/sargtmp.int_log\n",tmp
);
76 totbytes
=globstat
.nbytes
;
77 totelap
=globstat
.elap
;
78 ntotuser
=globstat
.totuser
;
80 sort_labels(&sort_field
,&sort_order
);
82 uscan
=userinfo_startscan();
84 debuga(_("Cannot enumerate the user list\n"));
87 while ( (uinfo
= userinfo_advancescan(uscan
)) != NULL
) {
88 if (snprintf(warea
,sizeof(warea
),"%s/%s",outdirname
,uinfo
->filename
)>=sizeof(warea
)) {
89 debuga(_("Destination directory too long: "));
90 debuga_more("%s/%s\n",outdirname
,uinfo
->filename
);
93 if (!uinfo
->topuser
) {
94 //! \todo Instead of deleting the supernumerary directories, don't create them in the first place.
99 if (access(warea
, R_OK
) != 0) {
100 if (mkdir(warea
,0755)) {
101 debuga(_("Cannot create directory \"%s\": %s\n"),warea
,strerror(errno
));
107 if (snprintf(arqin
,sizeof(arqin
),"%s/htmlrel.txt",tmp
)>=sizeof(arqin
)) {
108 debuga(_("Path too long: "));
109 debuga_more("%s/htmlrel.txt\n",tmp
);
112 if ((fp_in
= fopen(arqin
, "r")) == 0){
113 if (uinfo
->no_report
) continue;
114 debugapos("html3",_("Cannot open file \"%s\": %s\n"),arqin
,strerror(errno
));
118 if (snprintf(arqou
,sizeof(arqou
),"%s/%s/%s.html",outdirname
,uinfo
->filename
,uinfo
->filename
)>=sizeof(arqou
)) {
119 debuga(_("Path too long: "));
120 debuga_more("%s/%s/%s.html\n",outdirname
,uinfo
->filename
,uinfo
->filename
);
123 if (snprintf(duser
,sizeof(duser
),"%s/denied_%s.html",outdirname
,uinfo
->filename
)>=sizeof(duser
)) {
124 debuga(_("Path too long: "));
125 debuga_more("%s/denied_%s.html\n",outdirname
,uinfo
->filename
);
128 if(access(duser
, R_OK
) != 0)
129 have_denied_report
=false;
131 have_denied_report
=true;
133 if ((line
=longline_create())==NULL
) {
134 debuga(_("Not enough memory to read file \"%s\"\n"),arqin
);
143 while((buf
=longline_read(fp_in
,line
))!=NULL
) {
144 getword_start(&gwarea
,buf
);
145 if (getword_atoll(<emp
,&gwarea
,'\t')<0) {
146 debuga(_("Invalid number of accesses in file \"%s\"\n"),arqin
);
150 if (getword_atoll(<emp
,&gwarea
,'\t')<0) {
151 debuga(_("Invalid download size in file \"%s\"\n"),arqin
);
155 if (getword_ptr(NULL
,NULL
,&gwarea
,'\t')<0) {
156 debuga(_("Invalid url in file \"%s\"\n"),arqin
);
159 if (getword_skip(MAXLEN
,&gwarea
,'\t')<0) {
160 debuga(_("Invalid access code in file \"%s\"\n"),arqin
);
163 if (getword_atoll(<emp
,&gwarea
,'\t')<0) {
164 debuga(_("Invalid elapsed time in file \"%s\"\n"),arqin
);
168 if (getword_atoll(<emp
,&gwarea
,'\t')<0) {
169 debuga(_("Invalid in-cache volume in file \"%s\"\n"),arqin
);
173 if (getword_atoll(<emp
,&gwarea
,'\n')<0) {
174 debuga(_("Invalid out-of-cache volume in file \"%s\"\n"),arqin
);
182 if ((fp_ou
= fopen(arqou
, "w")) == 0){
183 debugapos("html5",_("Cannot open file \"%s\": %s\n"),arqou
,strerror(errno
));
187 write_html_header(fp_ou
,(IndexTree
== INDEX_TREE_DATE
) ? 4 : 2,_("User report"),HTML_JS_SORTTABLE
);
188 fprintf(fp_ou
,"<tr><td class=\"header_c\">%s: %s</td></tr>\n",_("Period"),period
.html
);
189 fprintf(fp_ou
,"<tr><td class=\"header_c\">%s: %s</td></tr>\n",_("User"),uinfo
->label
);
190 fputs("<tr><td class=\"header_c\">",fp_ou
);
191 fprintf(fp_ou
,_("Sort: %s, %s"),sort_field
,sort_order
);
192 fputs("</td></tr>\n",fp_ou
);
193 fprintf(fp_ou
,"<tr><th class=\"header_c\">%s</th></tr>\n",_("User report"));
194 close_html_header(fp_ou
);
196 if (have_denied_report
) {
197 fputs("<div class=\"report\"><table cellpadding=\"1\" cellspacing=\"2\">\n",fp_ou
);
198 fprintf(fp_ou
,"<tr><td class=\"header_l\" colspan=\"11\"><a href=\"denied_%s.html\">%s</a></td></tr>\n",uinfo
->filename
,_("SmartFilter report"));
199 fputs("<tr><td></td></tr>\n</table></div>\n",fp_ou
);
202 fputs("<div class=\"report\"><table cellpadding=\"2\" cellspacing=\"1\"",fp_ou
);
203 if (SortTableJs
[0]) fputs(" class=\"sortable\"",fp_ou
);
206 fputs("<thead><tr><th class=\"sorttable_nosort\"></th><th class=\"header_l",fp_ou
);
207 if (SortTableJs
[0]) fputs(" sorttable_alpha",fp_ou
);
208 fprintf(fp_ou
,"\">%s</th>",_("ACCESSED SITE"));
210 if((UserReportFields
& USERREPORTFIELDS_CONNECT
) != 0)
211 fprintf(fp_ou
,"<th class=\"header_l\">%s</th>",_("CONNECT"));
212 if((UserReportFields
& USERREPORTFIELDS_BYTES
) != 0)
213 fprintf(fp_ou
,"<th class=\"header_l\">%s</th>",_("BYTES"));
214 if((UserReportFields
& USERREPORTFIELDS_SETYB
) != 0)
215 fprintf(fp_ou
,"<th class=\"header_l\">%%%s</th>",_("BYTES"));
216 if((UserReportFields
& USERREPORTFIELDS_IN_CACHE_OUT
) != 0)
217 fprintf(fp_ou
,"<th class=\"header_c\" colspan=\"2\">%s</th><th style=\"display:none;\"></th>",_("IN-CACHE-OUT"));
218 if((UserReportFields
& USERREPORTFIELDS_USED_TIME
) != 0)
219 fprintf(fp_ou
,"<th class=\"header_l\">%s</th>",_("ELAPSED TIME"));
220 if((UserReportFields
& USERREPORTFIELDS_MILISEC
) != 0)
221 fprintf(fp_ou
,"<th class=\"header_l\">%s</th>",_("MILLISEC"));
222 if((UserReportFields
& USERREPORTFIELDS_PTIME
) != 0)
223 fprintf(fp_ou
,"<th class=\"header_l\">%%%s</th>",_("TIME"));
225 fputs("</tr></thead>\n",fp_ou
);
228 debuga(_("Making report %s\n"),uinfo
->id
);
233 while((buf
=longline_read(fp_in
,line
))!=NULL
) {
234 getword_start(&gwarea
,buf
);
235 if (getword_atoll(&twork
,&gwarea
,'\t')<0) {
236 debuga(_("Invalid number of accesses in file \"%s\"\n"),arqin
);
239 if (getword_atoll(&nnbytes
,&gwarea
,'\t')<0) {
240 debuga(_("Invalid number of bytes in file \"%s\"\n"),arqin
);
243 if (getword_ptr(buf
,&url
,&gwarea
,'\t')<0) {
244 debuga(_("Invalid url in file \"%s\"\n"),arqin
);
247 if (getword(tmsg
,sizeof(tmsg
),&gwarea
,'\t')<0) {
248 debuga(_("Invalid access code in file \"%s\"\n"),arqin
);
251 if (getword_atoll(&nnelap
,&gwarea
,'\t')<0) {
252 debuga(_("Invalid elapsed time in file \"%s\"\n"),arqin
);
255 if (getword_atoll(&incache
,&gwarea
,'\t')<0) {
256 debuga(_("Invalid in-cache column in file \"%s\"\n"),arqin
);
259 if (getword_atoll(&oucache
,&gwarea
,'\n')<0) {
260 debuga(_("Invalid out-of-cache column in file \"%s\"\n"),arqin
);
264 if(UserReportLimit
<=0 || count
<=UserReportLimit
) {
267 if(IndexTree
== INDEX_TREE_DATE
)
268 sprintf(tmp6
,"../%s",ImageFile
);
270 strcpy(tmp6
,"../../images");
272 if((ReportType
& REPORT_TYPE_SITE_USER_TIME_DATE
) != 0) {
273 url_to_file(url
,siteind
,sizeof(siteind
));
274 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"));
276 fprintf(fp_ou
,"<td class=\"data\"></td>");
280 fprintf(fp_ou
,"<td class=\"data2\"><span style=\"color:%s;\">%s</span></td>",PrivacyStringColor
,PrivacyString
);
282 fputs("<td class=\"data2\">",fp_ou
);
283 if(BlockIt
[0]!='\0' && url
[0]!=ALIAS_PREFIX
) {
284 fprintf(fp_ou
,"<a href=\"%s%s?url=",wwwDocumentRoot
,BlockIt
);
285 output_html_url(fp_ou
,url
);
286 fprintf(fp_ou
,"\"><img src=\"%s/sarg-squidguard-block.png\"></a> ",tmp6
);
288 output_html_link(fp_ou
,url
,100);
289 fputs("</td>",fp_ou
);
292 if((UserReportFields
& USERREPORTFIELDS_CONNECT
) != 0) {
293 fputs("<td class=\"data\"",fp_ou
);
294 if (SortTableJs
[0]) fprintf(fp_ou
," sorttable_customkey=\"%"PRId64
"\"",(int64_t)twork
);
295 fprintf(fp_ou
,">%s</td>",fixnum(twork
,1));
297 if((UserReportFields
& USERREPORTFIELDS_BYTES
) != 0) {
298 fputs("<td class=\"data\"",fp_ou
);
299 if (SortTableJs
[0]) fprintf(fp_ou
," sorttable_customkey=\"%"PRId64
"\"",(int64_t)nnbytes
);
300 fprintf(fp_ou
,">%s</td>",fixnum(nnbytes
,1));
302 if((UserReportFields
& USERREPORTFIELDS_SETYB
) != 0) {
303 perc
=(tnbytes
) ? nnbytes
* 100. / tnbytes
: 0.;
304 fprintf(fp_ou
,"<td class=\"data\">%3.2lf%%</td>",perc
);
306 if((UserReportFields
& USERREPORTFIELDS_IN_CACHE_OUT
) != 0) {
307 inperc
=(nnbytes
) ? incache
* 100. / nnbytes
: 0.;
308 ouperc
=(nnbytes
) ? oucache
* 100. / nnbytes
: 0.;
309 fprintf(fp_ou
,"<td class=\"data\">%3.2lf%%</td><td class=\"data\">%3.2lf%%</td>",inperc
,ouperc
);
311 if((UserReportFields
& USERREPORTFIELDS_USED_TIME
) != 0) {
312 fputs("<td class=\"data\"",fp_ou
);
313 if (SortTableJs
[0]) fprintf(fp_ou
," sorttable_customkey=\"%"PRId64
"\"",(int64_t)nnelap
);
314 fprintf(fp_ou
,">%s</td>",buildtime(nnelap
));
316 if((UserReportFields
& USERREPORTFIELDS_MILISEC
) != 0) {
317 fputs("<td class=\"data\"",fp_ou
);
318 if (SortTableJs
[0]) fprintf(fp_ou
," sorttable_customkey=\"%"PRId64
"\"",(int64_t)nnelap
);
319 fprintf(fp_ou
,">%s</td>",fixnum2(nnelap
,1));
321 if((UserReportFields
& USERREPORTFIELDS_PTIME
) != 0) {
322 perc2
=(tnelap
) ? nnelap
* 100. / tnelap
: 0.;
323 fprintf(fp_ou
,"<td class=\"data\">%3.2lf%%</td>",perc2
);
326 if(strncmp(tmsg
,"OK",2) != 0)
327 fprintf(fp_ou
,"<td class=\"data\">%s</td>",_("DENIED"));
329 fputs("</tr>\n",fp_ou
);
331 } else if ((ReportType
& REPORT_TYPE_SITE_USER_TIME_DATE
) != 0) {
332 url_to_file(url
,siteind
,sizeof(siteind
));
333 snprintf(warea
,sizeof(warea
),"%s/%s/tt%s-%s.html",outdirname
,uinfo
->filename
,uinfo
->filename
,siteind
);
334 if (unlink(warea
)!=0) {
335 debuga(_("Cannot delete \"%s\": %s\n"),warea
,strerror(errno
));
340 if (snprintf(arqip
,sizeof(arqip
),"%s/%s.ip",tmp
,uinfo
->filename
)>=sizeof(arqip
)) {
341 debuga(_("Path too long: "));
342 debuga_more("%s/%s.ip\n",tmp
,uinfo
->filename
);
346 if ((fp_ip
= fopen(arqip
, "r")) == 0){
347 debugapos("html6",_("Cannot open file \"%s\": %s\n"),arqip
,strerror(errno
));
351 if ((fp_ip2
= MY_FOPEN(tmp2
, "a")) == 0){
352 debugapos("html7",_("Cannot open file \"%s\": %s\n"),tmp2
,strerror(errno
));
356 if ((line1
=longline_create())==NULL
) {
357 debuga(_("Not enough memory to read file \"%s\"\n"),arqip
);
360 while((buf
=longline_read(fp_ip
,line1
))!=NULL
) {
361 getword_start(&gwarea
,buf
);
362 if (getword(user_ip
,sizeof(user_ip
),&gwarea
,'\t')<0) {
363 debuga(_("Invalid user IP in file \"%s\"\n"),tmp3
);
366 if (getword_ptr(buf
,&user_url
,&gwarea
,'\t')<0) {
367 debuga(_("Invalid url in file \"%s\"\n"),tmp3
);
370 if (strncmp(user_url
,url
,strlen(url
))!=0) continue;
371 if (getword_skip(15,&gwarea
,'\t')<0) {
372 debuga(_("Invalid day in file \"%s\"\n"),tmp3
);
375 if (getword_skip(15,&gwarea
,'\t')<0) {
376 debuga(_("Invalid time in file \"%s\"\n"),tmp3
);
379 if (getword_atoll(&userbytes
,&gwarea
,'\t')<0) {
380 debuga(_("Invalid size in file \"%s\"\n"),tmp3
);
383 if (getword_atoll(&userelap
,&gwarea
,'\0')<0) {
384 debuga(_("Invalid elapsed time in file \"%s\"\n"),tmp3
);
387 fprintf(fp_ip2
,"%s\t%"PRIu64
"\t%"PRIu64
"\n",user_ip
,(uint64_t)userbytes
,(uint64_t)userelap
);
389 longline_destroy(&line1
);
394 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
)) {
395 debuga(_("Command too long: "));
396 debuga_more("sort -n -t \"\t\" -T \"%s\" -k 1,1 -k 2,2 -o \"%s\" \"%s\"",tmp
,tmp3
,tmp2
);
399 cstatus
=system(csort
);
400 if (!WIFEXITED(cstatus
) || WEXITSTATUS(cstatus
)) {
401 debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus
));
402 debuga(_("sort command: %s\n"),csort
);
406 if ((fp_ip
= MY_FOPEN(tmp3
, "r")) == 0) {
407 debugapos("html8",_("Cannot open file \"%s\": %s\n"),tmp3
,strerror(errno
));
412 debuga(_("Cannot delete \"%s\": %s\n"),tmp2
,strerror(errno
));
418 if ((line1
=longline_create())==NULL
) {
419 debuga(_("Not enough memory to read file \"%s\"\n"),arqip
);
422 while((buf
=longline_read(fp_ip
,line1
))!=NULL
) {
423 getword_start(&gwarea
,buf
);
424 if (getword(user_ip
,sizeof(user_ip
),&gwarea
,'\t')<0) {
425 debuga(_("Invalid user IP in file \"%s\"\n"),tmp3
);
428 if (getword_atoll(&userbytes
,&gwarea
,'\t')<0) {
429 debuga(_("Invalid size in file \"%s\"\n"),tmp3
);
432 if (getword_atoll(&userelap
,&gwarea
,'\0')<0) {
433 debuga(_("Invalid elapsed time in file \"%s\"\n"),tmp3
);
436 if(strcmp(user_ip
,olduserip
) != 0) {
437 if (olduserip
[0]!='\0') {
438 fprintf(fp_ou
,"<tr><td></td><td class=\"data\">%s</td>",olduserip
);
439 if((UserReportFields
& USERREPORTFIELDS_CONNECT
) != 0)
440 fputs("<td></td>",fp_ou
);
441 if((UserReportFields
& USERREPORTFIELDS_BYTES
) != 0)
442 fprintf(fp_ou
,"<td class=\"data\">%s</td>",fixnum(unbytes
,1));
443 if((UserReportFields
& USERREPORTFIELDS_SETYB
) != 0)
444 fputs("<td></td>",fp_ou
);
445 if((UserReportFields
& USERREPORTFIELDS_IN_CACHE_OUT
) != 0)
446 fputs("</td><td></td><td></td>",fp_ou
);
447 if((UserReportFields
& USERREPORTFIELDS_USED_TIME
) != 0)
448 fprintf(fp_ou
,"<td class=\"data\">%s</td>",buildtime(unelap
));
449 if((UserReportFields
& USERREPORTFIELDS_MILISEC
) != 0)
450 fprintf(fp_ou
,"<td class=\"data\">%s</td>",fixnum2(unelap
,1));
451 fputs("</tr>\n",fp_ou
);
454 strcpy(olduserip
,user_ip
);
464 longline_destroy(&line1
);
467 debuga(_("Cannot delete \"%s\": %s\n"),tmp3
,strerror(errno
));
471 if (olduserip
[0]!='\0') {
472 fprintf(fp_ou
,"<tr><td></td><td class=\"data\">%s</td>",olduserip
);
473 if((UserReportFields
& USERREPORTFIELDS_CONNECT
) != 0)
474 fputs("<td></td>",fp_ou
);
475 if((UserReportFields
& USERREPORTFIELDS_BYTES
) != 0)
476 fprintf(fp_ou
,"<td class=\"data\">%s</td>",fixnum(unbytes
,1));
477 if((UserReportFields
& USERREPORTFIELDS_SETYB
) != 0)
478 fputs("<td></td>",fp_ou
);
479 if((UserReportFields
& USERREPORTFIELDS_IN_CACHE_OUT
) != 0)
480 fputs("</td><td></td><td></td>",fp_ou
);
481 if((UserReportFields
& USERREPORTFIELDS_USED_TIME
) != 0)
482 fprintf(fp_ou
,"<td class=\"data\">%s</td>",buildtime(unelap
));
483 if((UserReportFields
& USERREPORTFIELDS_MILISEC
) != 0)
484 fprintf(fp_ou
,"<td class=\"data\">%s</td>",fixnum2(unelap
,1));
485 fputs("</tr>\n",fp_ou
);
494 longline_destroy(&line
);
496 if (iprel
&& arqip
[0]) {
497 if (!KeepTempLog
&& unlink(arqip
)) {
498 debuga(_("Cannot delete \"%s\": %s\n"),arqip
,strerror(errno
));
502 if (!KeepTempLog
&& unlink(arqin
)) {
503 debuga(_("Cannot delete \"%s\": %s\n"),arqin
,strerror(errno
));
507 if ((UserReportFields
& (USERREPORTFIELDS_TOTAL
| USERREPORTFIELDS_AVERAGE
)) != 0)
508 fputs("<tfoot>",fp_ou
);
510 if((UserReportFields
& USERREPORTFIELDS_TOTAL
) != 0) {
511 fprintf(fp_ou
,"<tr><th></th><th class=\"header_l\">%s</th>",_("TOTAL"));
512 if((UserReportFields
& USERREPORTFIELDS_CONNECT
) != 0)
513 fprintf(fp_ou
,"<th class=\"header_r\">%s</th>",fixnum(tnacc
,1));
514 if((UserReportFields
& USERREPORTFIELDS_BYTES
) != 0)
515 fprintf(fp_ou
,"<th class=\"header_r\">%s</th>",fixnum(tnbytes
,1));
516 if((UserReportFields
& USERREPORTFIELDS_SETYB
) != 0) {
517 perc
=(totbytes
) ? tnbytes
*100. / totbytes
:0.;
518 fprintf(fp_ou
,"<th class=\"header_r\">%3.2lf%%</th>",perc
);
520 if((UserReportFields
& USERREPORTFIELDS_IN_CACHE_OUT
) != 0) {
521 inperc
=(tnbytes
) ? tnincache
* 100. / tnbytes
: 0.;
522 ouperc
=(tnbytes
) ? tnoucache
* 100. / tnbytes
: 0.;
523 fprintf(fp_ou
,"<th class=\"header_r\">%3.2lf%%</th><th class=\"header_r\">%3.2lf%%</th>",inperc
,ouperc
);
525 if((UserReportFields
& USERREPORTFIELDS_USED_TIME
) != 0)
526 fprintf(fp_ou
,"<th class=\"header_r\">%s</th>",buildtime(tnelap
));
527 if((UserReportFields
& USERREPORTFIELDS_MILISEC
) != 0)
528 fprintf(fp_ou
,"<th class=\"header_r\">%s</th>",fixnum2(tnelap
,1));
529 if((UserReportFields
& USERREPORTFIELDS_PTIME
) != 0) {
530 perc2
=(totelap
) ? tnelap
* 100. / totelap
: 0.;
531 fprintf(fp_ou
,"<th class=\"header_r\">%3.2lf%%</th>",perc2
);
533 fputs("</tr>\n",fp_ou
);
536 if(PerUserLimit
> 0) {
537 if ((int)(tnbytes
/1000000LLU) > PerUserLimit
) {
539 if(access(PerUserLimitFile
, R_OK
) == 0) {
540 if((fp_usr
= fopen(PerUserLimitFile
, "r")) == 0) {
541 debugapos("html9",_("Cannot open file \"%s\": %s\n"),PerUserLimitFile
,strerror(errno
));
544 while(fgets(tmp6
,sizeof(tmp6
),fp_usr
)!=NULL
) {
546 if(strcmp(tmp6
,uinfo
->ip
) == 0) {
555 if((fp_usr
= fopen(PerUserLimitFile
, "a")) == 0) {
556 debugapos("html10",_("Cannot open file \"%s\": %s\n"),PerUserLimitFile
,strerror(errno
));
559 fprintf(fp_usr
,"%s\n",uinfo
->ip
);
563 debuga(_("User %s limit exceeded (%d MB). Added to file \"%s\"\n"),uinfo
->label
,PerUserLimit
,PerUserLimitFile
);
568 if ((ReportType
& REPORT_TYPE_TOPUSERS
) != 0 && (UserReportFields
& USERREPORTFIELDS_AVERAGE
) != 0) {
569 totbytes2
=totbytes
/ntotuser
;
570 totelap2
=totelap
/ntotuser
;
572 fprintf(fp_ou
,"<tr><th></th><th class=\"header_l\">%s</th>",_("AVERAGE"));
573 if((UserReportFields
& USERREPORTFIELDS_CONNECT
) != 0)
574 fprintf(fp_ou
,"<th class=\"header_r\">%s</th>",fixnum(ttnacc
/ntotuser
,1));
575 if((UserReportFields
& USERREPORTFIELDS_BYTES
) != 0)
576 fprintf(fp_ou
,"<th class=\"header_r\">%s</th>",fixnum(totbytes2
,1));
577 fprintf(fp_ou
,"<th></th><th></th><th></th>");
578 if((UserReportFields
& USERREPORTFIELDS_USED_TIME
) != 0)
579 fprintf(fp_ou
,"<th class=\"header_r\">%s</th>",buildtime(totelap2
));
580 if((UserReportFields
& USERREPORTFIELDS_MILISEC
) != 0)
581 fprintf(fp_ou
,"<th class=\"header_r\">%s</th>",fixnum2(totelap2
,1));
582 if((UserReportFields
& USERREPORTFIELDS_PTIME
) != 0) {
583 perc2
= (totelap
) ? totelap2
* 100. / totelap
: 0.;
584 fprintf(fp_ou
,"<th class=\"header_r\">%3.2lf%%</th>",perc2
);
586 fputs("</tr>\n",fp_ou
);
589 if ((UserReportFields
& (USERREPORTFIELDS_TOTAL
| USERREPORTFIELDS_AVERAGE
)) != 0)
590 fputs("</tfoot>",fp_ou
);
592 fputs("</table></div>\n",fp_ou
);
593 if (write_html_trailer(fp_ou
)<0)
594 debuga(_("Write error in file \"%s\"\n"),arqou
);
595 if (fclose(fp_ou
)==EOF
)
596 debuga(_("Failed to close file \"%s\": %s\n"),arqou
,strerror(errno
));
601 userinfo_stopscan(uscan
);