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
], 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;
68 strcat(tmp2
,"/sargtmp.unsort");
71 strcat(tmp3
,"/sargtmp.log");
74 totbytes
=globstat
.nbytes
;
75 totelap
=globstat
.elap
;
77 snprintf(arqper
,sizeof(arqper
),"%s/sarg-users",outdirname
);
78 if ((fp_in
= fopen(arqper
, "r")) == 0){
79 debuga(_("(html11) Cannot open file %s\n"),arqper
);
82 if (!fgets(totuser
,sizeof(totuser
),fp_in
)) {
83 debuga(_("(html11) read error in %s\n"),arqper
);
87 ntotuser
=my_atoll(totuser
);
88 if (ntotuser
<=0) ntotuser
=1;
92 sort_labels(&sort_field
,&sort_order
);
94 uscan
=userinfo_startscan();
96 debuga(_("Cannot enumerate the user list\n"));
99 while ( (uinfo
= userinfo_advancescan(uscan
)) != NULL
) {
100 user
=uinfo
->filename
;
102 if (snprintf(warea
,sizeof(warea
),"%s/%s",outdirname
,user
)>=sizeof(warea
)) {
103 debuga(_("Destination directory too long: %s/%s\n"),outdirname
,user
);
106 if (access(warea
, R_OK
) != 0) {
107 if (mkdir(warea
,0755)) {
108 debuga(_("Cannot create directory %s - %s\n"),warea
,strerror(errno
));
116 if (snprintf(arqin
,sizeof(arqin
),"%s/%s.txt",tmp
,uinfo
->filename
)>=sizeof(arqin
)) {
117 debuga(_("Input file name too long: %s/%s.txt\n"),tmp
,uinfo
->filename
);
120 if ((fp_in
= fopen(arqin
, "r")) == 0){
121 if (uinfo
->no_report
) continue;
122 debuga(_("(html3) Cannot open file %s\n"),arqin
);
126 if (snprintf(arqou
,sizeof(arqou
),"%s/%s/%s.html",outdirname
,uinfo
->filename
,uinfo
->filename
)>=sizeof(arqou
)) {
127 debuga(_("Output file name too long: %s/%s/%s.html\n"),outdirname
,uinfo
->filename
,uinfo
->filename
);
130 if (snprintf(duser
,sizeof(duser
),"%s/%s/denied_%s.html",tmp
,uinfo
->filename
,uinfo
->filename
)>=sizeof(duser
)) {
131 debuga(_("File name too long: %s/%s/denied_%s.html\n"),tmp
,uinfo
->filename
,uinfo
->filename
);
134 if(access(duser
, R_OK
) != 0)
135 have_denied_report
=0;
137 have_denied_report
=1;
139 if ((line
=longline_create())==NULL
) {
140 debuga(_("Not enough memory to read file %s\n"),arqin
);
149 while((buf
=longline_read(fp_in
,line
))!=NULL
) {
150 getword_start(&gwarea
,buf
);
151 if (getword_atoll(<emp
,&gwarea
,'\t')<0) {
152 debuga(_("There is a broken number of access in file %s\n"),arqin
);
156 if (getword_atoll(<emp
,&gwarea
,'\t')<0) {
157 debuga(_("There is a broken downloaded size in file %s\n"),arqin
);
161 if (getword_ptr(NULL
,NULL
,&gwarea
,'\t')<0) {
162 debuga(_("There is a broken url in file %s\n"),arqin
);
165 if (getword_skip(MAXLEN
,&gwarea
,'\t')<0) {
166 debuga(_("There is a broken access code in file %s\n"),arqin
);
169 if (getword_atoll(<emp
,&gwarea
,'\t')<0) {
170 debuga(_("There is a broken elapsed time in file %s\n"),arqin
);
174 if (getword_atoll(<emp
,&gwarea
,'\t')<0) {
175 debuga(_("There is a broken in-cache volume in file %s\n"),arqin
);
179 if (getword_atoll(<emp
,&gwarea
,'\n')<0) {
180 debuga(_("There is a broken out-cache volume in file %s\n"),arqin
);
188 if ((fp_ou
= fopen(arqou
, "w")) == 0){
189 debuga(_("(html5) Cannot open file %s\n"),arqou
);
193 write_html_header(fp_ou
,(IndexTree
== INDEX_TREE_DATE
) ? 4 : 2,_("User report"),HTML_JS_SORTTABLE
);
194 fprintf(fp_ou
,"<tr><td class=\"header_c\">%s: %s</td></tr>\n",_("Period"),period
.html
);
195 fprintf(fp_ou
,"<tr><td class=\"header_c\">%s: %s</td></tr>\n",_("User"),uinfo
->label
);
196 fputs("<tr><td class=\"header_c\">",fp_ou
);
197 fprintf(fp_ou
,_("Sort: %s, %s"),sort_field
,sort_order
);
198 fputs("</td></tr>\n",fp_ou
);
199 fprintf(fp_ou
,"<tr><th class=\"header_c\">%s</th></tr>\n",_("User report"));
200 close_html_header(fp_ou
);
202 fputs("<div class=\"report\"><table cellpadding=\"2\" cellspacing=\"1\"",fp_ou
);
203 if (SortTableJs
[0]) fputs(" class=\"sortable\"",fp_ou
);
206 /*! \bug This line lays before the header of the table and is therefore invalid
207 HTML. It will also break the sorttable script. Beside, I suspect it serves no purpose.
209 if(have_denied_report
) {
210 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"));
213 fputs("<thead><tr><th class=\"sorttable_nosort\"></th><th class=\"header_l",fp_ou
);
214 if (SortTableJs
[0]) fputs(" sorttable_alpha",fp_ou
);
215 fprintf(fp_ou
,"\">%s</th>",_("ACCESSED SITE"));
217 if((UserReportFields
& USERREPORTFIELDS_CONNECT
) != 0)
218 fprintf(fp_ou
,"<th class=\"header_l\">%s</th>",_("CONNECT"));
219 if((UserReportFields
& USERREPORTFIELDS_BYTES
) != 0)
220 fprintf(fp_ou
,"<th class=\"header_l\">%s</th>",_("BYTES"));
221 if((UserReportFields
& USERREPORTFIELDS_SETYB
) != 0)
222 fprintf(fp_ou
,"<th class=\"header_l\">%%%s</th>",_("BYTES"));
223 if((UserReportFields
& USERREPORTFIELDS_IN_CACHE_OUT
) != 0)
224 fprintf(fp_ou
,"<th class=\"header_c\" colspan=\"2\">%s</th><th style=\"display:none;\"></th>",_("IN-CACHE-OUT"));
225 if((UserReportFields
& USERREPORTFIELDS_USED_TIME
) != 0)
226 fprintf(fp_ou
,"<th class=\"header_l\">%s</th>",_("ELAPSED TIME"));
227 if((UserReportFields
& USERREPORTFIELDS_MILISEC
) != 0)
228 fprintf(fp_ou
,"<th class=\"header_l\">%s</th>",_("MILLISEC"));
229 if((UserReportFields
& USERREPORTFIELDS_PTIME
) != 0)
230 fprintf(fp_ou
,"<th class=\"header_l\">%%%s</th>",_("TIME"));
232 fputs("</tr></thead>\n",fp_ou
);
235 debuga(_("Making report: %s\n"),uinfo
->id
);
240 while((buf
=longline_read(fp_in
,line
))!=NULL
) {
241 getword_start(&gwarea
,buf
);
242 if (getword_atoll(&twork
,&gwarea
,'\t')<0) {
243 debuga(_("There is a broken number of access in file %s\n"),arqin
);
246 if (getword_atoll(&nnbytes
,&gwarea
,'\t')<0) {
247 debuga(_("There is a broken number of bytes in file %s\n"),arqin
);
250 if (getword_ptr(buf
,&url
,&gwarea
,'\t')<0) {
251 debuga(_("There is a broken url in file %s\n"),arqin
);
254 if (getword(tmsg
,sizeof(tmsg
),&gwarea
,'\t')<0) {
255 debuga(_("There is a broken access code in file %s\n"),arqin
);
258 if (getword_atoll(&nnelap
,&gwarea
,'\t')<0) {
259 debuga(_("There is a broken elapsed time in file %s\n"),arqin
);
262 if (getword_atoll(&incache
,&gwarea
,'\t')<0) {
263 debuga(_("There is a broken in cache column in file %s\n"),arqin
);
266 if (getword_atoll(&oucache
,&gwarea
,'\n')<0) {
267 debuga(_("There is a broken out of cache column in file %s (%d)\n"),arqin
,__LINE__
);
271 if(UserReportLimit
<=0 || count
<=UserReportLimit
) {
274 if(IndexTree
== INDEX_TREE_DATE
)
275 sprintf(tmp6
,"../%s",ImageFile
);
277 strcpy(tmp6
,"../../images");
279 if((ReportType
& REPORT_TYPE_SITE_USER_TIME_DATE
) != 0) {
280 url_to_file(url
,siteind
,sizeof(siteind
));
281 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"));
283 fprintf(fp_ou
,"<td class=\"data\"></td>");
287 fprintf(fp_ou
,"<td class=\"data2\"><span style=\"color:%s;\">%s</span></td>",PrivacyStringColor
,PrivacyString
);
289 fputs("<td class=\"data2\">",fp_ou
);
290 if(BlockIt
[0]!='\0') {
291 fprintf(fp_ou
,"<a href=\"%s%s?url=",wwwDocumentRoot
,BlockIt
);
292 output_html_url(fp_ou
,url
);
293 fprintf(fp_ou
,"\"><img src=\"%s/sarg-squidguard-block.png\"></a> ",tmp6
);
295 fputs("<a href=\"http://",fp_ou
);
296 output_html_url(fp_ou
,url
);
298 output_html_string(fp_ou
,url
,100);
299 fputs("</a></td>",fp_ou
);
302 if((UserReportFields
& USERREPORTFIELDS_CONNECT
) != 0) {
303 fputs("<td class=\"data\"",fp_ou
);
304 if (SortTableJs
[0]) fprintf(fp_ou
," sorttable_customkey=\"%"PRId64
"\"",(int64_t)twork
);
305 fprintf(fp_ou
,">%s</td>",fixnum(twork
,1));
307 if((UserReportFields
& USERREPORTFIELDS_BYTES
) != 0) {
308 fputs("<td class=\"data\"",fp_ou
);
309 if (SortTableJs
[0]) fprintf(fp_ou
," sorttable_customkey=\"%"PRId64
"\"",(int64_t)nnbytes
);
310 fprintf(fp_ou
,">%s</td>",fixnum(nnbytes
,1));
312 if((UserReportFields
& USERREPORTFIELDS_SETYB
) != 0) {
313 perc
=(tnbytes
) ? nnbytes
* 100. / tnbytes
: 0.;
314 fprintf(fp_ou
,"<td class=\"data\">%3.2lf%%</td>",perc
);
316 if((UserReportFields
& USERREPORTFIELDS_IN_CACHE_OUT
) != 0) {
317 inperc
=(nnbytes
) ? incache
* 100. / nnbytes
: 0.;
318 ouperc
=(nnbytes
) ? oucache
* 100. / nnbytes
: 0.;
319 fprintf(fp_ou
,"<td class=\"data\">%3.2lf%%</td><td class=\"data\">%3.2lf%%</td>",inperc
,ouperc
);
321 if((UserReportFields
& USERREPORTFIELDS_USED_TIME
) != 0) {
322 fputs("<td class=\"data\"",fp_ou
);
323 if (SortTableJs
[0]) fprintf(fp_ou
," sorttable_customkey=\"%"PRId64
"\"",(int64_t)nnelap
);
324 fprintf(fp_ou
,">%s</td>",buildtime(nnelap
));
326 if((UserReportFields
& USERREPORTFIELDS_MILISEC
) != 0) {
327 fputs("<td class=\"data\"",fp_ou
);
328 if (SortTableJs
[0]) fprintf(fp_ou
," sorttable_customkey=\"%"PRId64
"\"",(int64_t)nnelap
);
329 fprintf(fp_ou
,">%s</td>",fixnum2(nnelap
,1));
331 if((UserReportFields
& USERREPORTFIELDS_PTIME
) != 0) {
332 perc2
=(tnelap
) ? nnelap
* 100. / tnelap
: 0.;
333 fprintf(fp_ou
,"<td class=\"data\">%3.2lf%%</td>",perc2
);
336 if(strncmp(tmsg
,"OK",2) != 0)
337 fprintf(fp_ou
,"<td class=\"data\">%s</td>",_("DENIED"));
339 fputs("</tr>\n",fp_ou
);
341 } else if ((ReportType
& REPORT_TYPE_SITE_USER_TIME_DATE
) != 0) {
342 url_to_file(url
,siteind
,sizeof(siteind
));
343 snprintf(tmp2
,sizeof(tmp2
),"%s/%s/tt%s-%s.html",outdirname
,uinfo
->filename
,uinfo
->filename
,siteind
);
344 if (unlink(tmp2
)!=0) {
345 debuga(_("Cannot delete unused file \"%s\" - %s\n"),tmp2
,strerror(errno
));
350 if (snprintf(arqip
,sizeof(arqip
),"%s/%s.ip",tmp
,uinfo
->filename
)>=sizeof(arqip
)) {
351 debuga(_("File name too long: %s/%s.ip\n"),tmp
,uinfo
->filename
);
355 if ((fp_ip
= fopen(arqip
, "r")) == 0){
356 debuga(_("(html6) Cannot open file %s\n"),arqip
);
360 if ((fp_ip2
= MY_FOPEN(tmp2
, "a")) == 0){
361 debuga(_("(html7) Cannot open file %s\n"),tmp2
);
365 if ((line1
=longline_create())==NULL
) {
366 debuga(_("Not enough memory to read file %s\n"),arqip
);
369 while((buf
=longline_read(fp_ip
,line1
))!=NULL
) {
370 getword_start(&gwarea
,buf
);
371 if (getword(user_ip
,sizeof(user_ip
),&gwarea
,'\t')<0) {
372 debuga(_("Maybe you have a broken user IP in your %s file\n"),tmp3
);
375 if (getword_ptr(buf
,&user_url
,&gwarea
,'\t')<0) {
376 debuga(_("Maybe you have a broken url in your %s file\n"),tmp3
);
379 if (strncmp(user_url
,url
,strlen(url
))!=0) continue;
380 if (getword_skip(15,&gwarea
,'\t')<0) {
381 debuga(_("Maybe you have a broken day in your %s file\n"),tmp3
);
384 if (getword_skip(15,&gwarea
,'\t')<0) {
385 debuga(_("Maybe you have a broken time in your %s file\n"),tmp3
);
388 if (getword_atoll(&userbytes
,&gwarea
,'\t')<0) {
389 debuga(_("Maybe you have a broken size in your %s file\n"),tmp3
);
392 if (getword_atoll(&userelap
,&gwarea
,'\0')<0) {
393 debuga(_("Maybe you have a broken elapsed time in your %s file\n"),tmp3
);
396 fprintf(fp_ip2
,"%s\t%"PRIu64
"\t%"PRIu64
"\n",user_ip
,(uint64_t)userbytes
,(uint64_t)userelap
);
398 longline_destroy(&line1
);
403 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
)) {
404 debuga(_("Sort command too long when sorting file \"%s\" to \"%s\"\n"),tmp2
,tmp3
);
407 cstatus
=system(csort
);
408 if (!WIFEXITED(cstatus
) || WEXITSTATUS(cstatus
)) {
409 debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus
));
410 debuga(_("sort command: %s\n"),csort
);
414 if ((fp_ip
= MY_FOPEN(tmp3
, "r")) == 0) {
415 debuga(_("(html8) Cannot open file %s\n"),tmp3
);
421 if ((line1
=longline_create())==NULL
) {
422 debuga(_("Not enough memory to read file %s\n"),arqip
);
425 while((buf
=longline_read(fp_ip
,line1
))!=NULL
) {
426 getword_start(&gwarea
,buf
);
427 if (getword(user_ip
,sizeof(user_ip
),&gwarea
,'\t')<0) {
428 debuga(_("Maybe you have a broken user IP in your %s file\n"),tmp3
);
431 if (getword_atoll(&userbytes
,&gwarea
,'\t')<0) {
432 debuga(_("Maybe you have a broken size in your %s file\n"),tmp3
);
435 if (getword_atoll(&userelap
,&gwarea
,'\0')<0) {
436 debuga(_("Maybe you have a broken elapsed time in your %s file\n"),tmp3
);
439 if(strcmp(user_ip
,olduserip
) != 0) {
440 if (olduserip
[0]!='\0') {
441 fprintf(fp_ou
,"<tr><td></td><td class=\"data\">%s</td>",olduserip
);
442 if((UserReportFields
& USERREPORTFIELDS_CONNECT
) != 0)
443 fputs("<td></td>",fp_ou
);
444 if((UserReportFields
& USERREPORTFIELDS_BYTES
) != 0)
445 fprintf(fp_ou
,"<td class=\"data\">%s</td>",fixnum(unbytes
,1));
446 if((UserReportFields
& USERREPORTFIELDS_SETYB
) != 0)
447 fputs("<td></td>",fp_ou
);
448 if((UserReportFields
& USERREPORTFIELDS_IN_CACHE_OUT
) != 0)
449 fputs("</td><td></td><td></td>",fp_ou
);
450 if((UserReportFields
& USERREPORTFIELDS_USED_TIME
) != 0)
451 fprintf(fp_ou
,"<td class=\"data\">%s</td>",buildtime(unelap
));
452 if((UserReportFields
& USERREPORTFIELDS_MILISEC
) != 0)
453 fprintf(fp_ou
,"<td class=\"data\">%s</td>",fixnum2(unelap
,1));
454 fputs("</tr>\n",fp_ou
);
457 strcpy(olduserip
,user_ip
);
468 longline_destroy(&line1
);
471 debuga(_("Cannot delete %s - %s\n"),tmp2
,strerror(errno
));
475 debuga(_("Cannot delete %s - %s\n"),tmp3
,strerror(errno
));
479 if (olduserip
[0]!='\0') {
480 fprintf(fp_ou
,"<tr><td></td><td class=\"data\">%s</td>",olduserip
);
481 if((UserReportFields
& USERREPORTFIELDS_CONNECT
) != 0)
482 fputs("<td></td>",fp_ou
);
483 if((UserReportFields
& USERREPORTFIELDS_BYTES
) != 0)
484 fprintf(fp_ou
,"<td class=\"data\">%s</td>",fixnum(unbytes
,1));
485 if((UserReportFields
& USERREPORTFIELDS_SETYB
) != 0)
486 fputs("<td></td>",fp_ou
);
487 if((UserReportFields
& USERREPORTFIELDS_IN_CACHE_OUT
) != 0)
488 fputs("</td><td></td><td></td>",fp_ou
);
489 if((UserReportFields
& USERREPORTFIELDS_USED_TIME
) != 0)
490 fprintf(fp_ou
,"<td class=\"data\">%s</td>",buildtime(unelap
));
491 if((UserReportFields
& USERREPORTFIELDS_MILISEC
) != 0)
492 fprintf(fp_ou
,"<td class=\"data\">%s</td>",fixnum2(unelap
,1));
493 fputs("</tr>\n",fp_ou
);
503 longline_destroy(&line
);
505 if (iprel
&& arqip
[0]) {
507 debuga(_("Cannot delete %s - %s\n"),arqip
,strerror(errno
));
512 debuga(_("Cannot delete %s - %s\n"),arqin
,strerror(errno
));
516 if ((UserReportFields
& (USERREPORTFIELDS_TOTAL
| USERREPORTFIELDS_AVERAGE
)) != 0)
517 fputs("<tfoot>",fp_ou
);
519 if((UserReportFields
& USERREPORTFIELDS_TOTAL
) != 0) {
520 fprintf(fp_ou
,"<tr><th></th><th class=\"header_l\">%s</th>",_("TOTAL"));
521 if((UserReportFields
& USERREPORTFIELDS_CONNECT
) != 0)
522 fprintf(fp_ou
,"<th class=\"header_r\">%s</th>",fixnum(tnacc
,1));
523 if((UserReportFields
& USERREPORTFIELDS_BYTES
) != 0)
524 fprintf(fp_ou
,"<th class=\"header_r\">%s</th>",fixnum(tnbytes
,1));
525 if((UserReportFields
& USERREPORTFIELDS_SETYB
) != 0) {
526 perc
=(totbytes
) ? tnbytes
*100. / totbytes
:0.;
527 fprintf(fp_ou
,"<th class=\"header_r\">%3.2lf%%</th>",perc
);
529 if((UserReportFields
& USERREPORTFIELDS_IN_CACHE_OUT
) != 0) {
530 inperc
=(tnbytes
) ? tnincache
* 100. / tnbytes
: 0.;
531 ouperc
=(tnbytes
) ? tnoucache
* 100. / tnbytes
: 0.;
532 fprintf(fp_ou
,"<th class=\"header_r\">%3.2lf%%</th><th class=\"header_r\">%3.2lf%%</th>",inperc
,ouperc
);
534 if((UserReportFields
& USERREPORTFIELDS_USED_TIME
) != 0)
535 fprintf(fp_ou
,"<th class=\"header_r\">%s</th>",buildtime(tnelap
));
536 if((UserReportFields
& USERREPORTFIELDS_MILISEC
) != 0)
537 fprintf(fp_ou
,"<th class=\"header_r\">%s</th>",fixnum2(tnelap
,1));
538 if((UserReportFields
& USERREPORTFIELDS_PTIME
) != 0) {
539 perc2
=(totelap
) ? tnelap
* 100. / totelap
: 0.;
540 fprintf(fp_ou
,"<th class=\"header_r\">%3.2lf%%</th>",perc2
);
542 fputs("</tr>\n",fp_ou
);
545 if(PerUserLimit
> 0) {
546 if(tnbytes
> (PerUserLimit
*1000000)) {
548 if(access(PerUserLimitFile
, R_OK
) == 0) {
549 if((fp_usr
= fopen(PerUserLimitFile
, "r")) == 0) {
550 debuga(_("(html9) Cannot open file %s\n"),PerUserLimitFile
);
553 while(fgets(tmp6
,sizeof(tmp6
),fp_usr
)!=NULL
) {
555 if(strcmp(tmp6
,uinfo
->label
) == 0) {
564 if((fp_usr
= fopen(PerUserLimitFile
, "a")) == 0) {
565 debuga(_("(html10) Cannot open file %s\n"),PerUserLimitFile
);
568 fprintf(fp_usr
,"%s\n",uinfo
->label
);
572 debuga(_("User %s limit exceeded (%d MB). Added to file %s\n"),uinfo
->label
,PerUserLimit
,PerUserLimitFile
);
577 if ((ReportType
& REPORT_TYPE_TOPUSERS
) != 0 && (UserReportFields
& USERREPORTFIELDS_AVERAGE
) != 0) {
578 totbytes2
=totbytes
/ntotuser
;
579 totelap2
=totelap
/ntotuser
;
581 fprintf(fp_ou
,"<tr><th></th><th class=\"header_l\">%s</th>",_("AVERAGE"));
582 if((UserReportFields
& USERREPORTFIELDS_CONNECT
) != 0)
583 fprintf(fp_ou
,"<th class=\"header_r\">%s</th>",fixnum(ttnacc
/ntotuser
,1));
584 if((UserReportFields
& USERREPORTFIELDS_BYTES
) != 0)
585 fprintf(fp_ou
,"<th class=\"header_r\">%s</th>",fixnum(totbytes2
,1));
586 fprintf(fp_ou
,"<th></th><th></th><th></th>");
587 if((UserReportFields
& USERREPORTFIELDS_USED_TIME
) != 0)
588 fprintf(fp_ou
,"<th class=\"header_r\">%s</th>",buildtime(totelap2
));
589 if((UserReportFields
& USERREPORTFIELDS_MILISEC
) != 0)
590 fprintf(fp_ou
,"<th class=\"header_r\">%s</th>",fixnum2(totelap2
,1));
591 if((UserReportFields
& USERREPORTFIELDS_PTIME
) != 0) {
592 perc2
= (totelap
) ? totelap2
* 100. / totelap
: 0.;
593 fprintf(fp_ou
,"<th class=\"header_r\">%3.2lf%%</th>",perc2
);
595 fputs("</tr>\n",fp_ou
);
598 if ((UserReportFields
& (USERREPORTFIELDS_TOTAL
| USERREPORTFIELDS_AVERAGE
)) != 0)
599 fputs("</tfoot>",fp_ou
);
601 fputs("</table></div>\n",fp_ou
);
602 if (write_html_trailer(fp_ou
)<0)
603 debuga(_("Write error in file %s\n"),arqou
);
604 if (fclose(fp_ou
)==EOF
)
605 debuga(_("Failed to close file %s - %s\n"),arqou
,strerror(errno
));
610 userinfo_stopscan(uscan
);