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"
33 FILE *fp_in
, *fp_ou
, *fp_ip
, *fp_ip2
, *fp_usr
;
35 struct dirent
*direntp
;
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
];
45 char user
[MAXLEN
], duser
[MAXLEN
];
46 char user_ip
[MAXLEN
], olduserip
[MAXLEN
], tmp2
[MAXLEN
], tmp3
[MAXLEN
];
47 char denied_report
[255];
53 long long int tnacc
=0, ttnacc
=0, unacc
=0;
54 double perc
=0, perc2
=0, ouperc
=0, inperc
=0;
57 const char txtext
[]=".txt";
58 const char *sort_field
;
59 const char *sort_order
;
61 char siteind
[MAX_TRUNCATED_URL
];
62 struct getwordstruct gwarea
;
64 struct generalitemstruct item
;
65 const struct userinfostruct
*uinfo
;
67 if((ReportType
& REPORT_TYPE_USERS_SITES
) == 0) return;
70 strcat(tmp2
,"/sargtmp.unsort");
73 strcat(tmp3
,"/sargtmp.log");
75 snprintf(arqper
,sizeof(arqper
),"%s/sarg-general",outdirname
);
76 if ((fp_in
= fopen(arqper
, "r")) == 0){
77 debuga(_("(html2) Cannot open file %s\n"),arqper
);
80 if ((line
=longline_create())==NULL
) {
81 debuga(_("Not enough memory to read file %s\n"),arqper
);
87 while((buf
=longline_read(fp_in
,line
))!=NULL
) {
88 ger_read(buf
,&item
,arqper
);
91 totbytes
+=item
.nbytes
;
96 longline_destroy(&line
);
98 snprintf(arqper
,sizeof(arqper
),"%s/sarg-users",outdirname
);
99 if ((fp_in
= fopen(arqper
, "r")) == 0){
100 debuga(_("(html11) Cannot open file %s\n"),arqper
);
103 if (!fgets(totuser
,sizeof(totuser
),fp_in
)) {
104 debuga(_("(html11) read error in %s\n"),arqper
);
108 ntotuser
=my_atoll(totuser
);
109 if (ntotuser
<=0) ntotuser
=1;
113 sort_labels(&sort_field
,&sort_order
);
115 if ((dirp
= opendir(tmp
)) == NULL
) {
116 debuga(_("Failed to open directory %s - %s\n"),tmp
,strerror(errno
));
119 while ( (direntp
= readdir( dirp
)) != NULL
) {
120 dlen
=strlen(direntp
->d_name
)-(sizeof(txtext
)-1);
121 if (dlen
<0) continue;
122 if(strcmp(direntp
->d_name
+dlen
,txtext
) != 0)
127 if (dlen
>=sizeof(user
)) continue;
128 strncpy(user
,direntp
->d_name
,dlen
);
134 uinfo
=userinfo_find_from_file(user
);
136 debuga(_("Unknown user ID %s in directory %s\n"),user
,tmp
);
139 str
=strrchr(user
,'.');
141 strcpy(denied_report
,str
+1);
143 strcpy(denied_report
,user
);
145 if (snprintf(warea
,sizeof(warea
),"%s/%s",outdirname
,user
)>=sizeof(warea
)) {
146 debuga(_("Destination directory too long: %s/%s\n"),outdirname
,user
);
154 if (snprintf(arqin
,sizeof(arqin
),"%s/%s",tmp
,direntp
->d_name
)>=sizeof(arqin
)) {
155 debuga(_("Input file name too long: %s/%s\n"),tmp
,direntp
->d_name
);
158 if (snprintf(arqou
,sizeof(arqou
),"%s/%s/%s.html",outdirname
,uinfo
->filename
,uinfo
->filename
)>=sizeof(arqou
)) {
159 debuga(_("Output file name too long: %s/%s/%s.html\n"),outdirname
,uinfo
->filename
,uinfo
->filename
);
162 if (snprintf(duser
,sizeof(duser
),"%s/%s/denied_%s.html",tmp
,direntp
->d_name
,denied_report
)>=sizeof(duser
)) {
163 debuga(_("File name too long: %s/%s/denied_%s.html\n"),tmp
,direntp
->d_name
,denied_report
);
166 if(access(duser
, R_OK
) != 0)
167 denied_report
[0]='\0';
169 if ((fp_in
= fopen(arqin
, "r")) == 0){
170 debuga(_("(html3) Cannot open file %s\n"),arqin
);
174 if ((line
=longline_create())==NULL
) {
175 debuga(_("Not enough memory to read file %s\n"),arqin
);
184 while((buf
=longline_read(fp_in
,line
))!=NULL
) {
185 getword_start(&gwarea
,buf
);
186 if (getword_atoll(<emp
,&gwarea
,'\t')<0) {
187 debuga(_("There is a broken number of access in file %s\n"),arqin
);
191 if (getword_atoll(<emp
,&gwarea
,'\t')<0) {
192 debuga(_("There is a broken downloaded size in file %s\n"),arqin
);
196 if (getword_ptr(NULL
,NULL
,&gwarea
,'\t')<0) {
197 debuga(_("There is a broken url in file %s\n"),arqin
);
200 if (getword_skip(MAXLEN
,&gwarea
,'\t')<0) {
201 debuga(_("There is a broken access code in file %s\n"),arqin
);
204 if (getword_atoll(<emp
,&gwarea
,'\t')<0) {
205 debuga(_("There is a broken elapsed time in file %s\n"),arqin
);
209 if (getword_atoll(<emp
,&gwarea
,'\t')<0) {
210 debuga(_("There is a broken in-cache volume in file %s\n"),arqin
);
214 if (getword_atoll(<emp
,&gwarea
,'\n')<0) {
215 debuga(_("There is a broken out-cache volume in file %s\n"),arqin
);
223 if ((fp_ou
= fopen(arqou
, "w")) == 0){
224 debuga(_("(html5) Cannot open file %s\n"),arqou
);
228 write_html_header(fp_ou
,(IndexTree
== INDEX_TREE_DATE
) ? 4 : 2,_("User report"),HTML_JS_SORTTABLE
);
229 fprintf(fp_ou
,"<tr><td class=\"header_c\">%s: %s</td></tr>\n",_("Period"),period
.html
);
230 fprintf(fp_ou
,"<tr><td class=\"header_c\">%s: %s</td></tr>\n",_("User"),uinfo
->label
);
231 fputs("<tr><td class=\"header_c\">",fp_ou
);
232 fprintf(fp_ou
,_("Sort: %s, %s"),sort_field
,sort_order
);
233 fputs("</td></tr>\n",fp_ou
);
234 fprintf(fp_ou
,"<tr><th class=\"header_c\">%s</th></tr>\n",_("User report"));
235 close_html_header(fp_ou
);
237 fputs("<div class=\"report\"><table cellpadding=\"2\" cellspacing=\"1\"",fp_ou
);
238 if (SortTableJs
[0]) fputs(" class=\"sortable\"",fp_ou
);
241 /*! \bug This line lays before the header of the table and is therefore invalid
242 HTML. It will also break the sorttable script. Beside, I suspect it serves no purpose.
244 if(denied_report
[0]!='\0') {
245 fprintf(fp_ou
,"<tr><td class=\"header_l\" colspan=\"11\"><a href=\"denied_%s.html\">%s</a> %s</td></tr>\n",denied_report
,_("SmartFilter"),_("Report"));
248 fputs("<thead><tr><th class=\"sorttable_nosort\"></th><th class=\"header_l",fp_ou
);
249 if (SortTableJs
[0]) fputs(" sorttable_alpha",fp_ou
);
250 fprintf(fp_ou
,"\">%s</th>",_("ACCESSED SITE"));
252 if((UserReportFields
& USERREPORTFIELDS_CONNECT
) != 0)
253 fprintf(fp_ou
,"<th class=\"header_l\">%s</th>",_("CONNECT"));
254 if((UserReportFields
& USERREPORTFIELDS_BYTES
) != 0)
255 fprintf(fp_ou
,"<th class=\"header_l\">%s</th>",_("BYTES"));
256 if((UserReportFields
& USERREPORTFIELDS_SETYB
) != 0)
257 fprintf(fp_ou
,"<th class=\"header_l\">%%%s</th>",_("BYTES"));
258 if((UserReportFields
& USERREPORTFIELDS_IN_CACHE_OUT
) != 0)
259 fprintf(fp_ou
,"<th class=\"header_c\" colspan=\"2\">%s</th><th style=\"display:none;\"></th>",_("IN-CACHE-OUT"));
260 if((UserReportFields
& USERREPORTFIELDS_USED_TIME
) != 0)
261 fprintf(fp_ou
,"<th class=\"header_l\">%s</th>",_("ELAPSED TIME"));
262 if((UserReportFields
& USERREPORTFIELDS_MILISEC
) != 0)
263 fprintf(fp_ou
,"<th class=\"header_l\">%s</th>",_("MILLISEC"));
264 if((UserReportFields
& USERREPORTFIELDS_PTIME
) != 0)
265 fprintf(fp_ou
,"<th class=\"header_l\">%%%s</th>",_("TIME"));
267 fputs("</tr></thead>\n",fp_ou
);
270 debuga(_("Making report: %s\n"),uinfo
->id
);
273 while((buf
=longline_read(fp_in
,line
))!=NULL
) {
274 getword_start(&gwarea
,buf
);
275 if (getword_atoll(&twork
,&gwarea
,'\t')<0) {
276 debuga(_("There is a broken number of access in file %s\n"),arqin
);
279 if (getword_atoll(&nnbytes
,&gwarea
,'\t')<0) {
280 debuga(_("There is a broken number of bytes in file %s\n"),arqin
);
283 if (getword_ptr(buf
,&url
,&gwarea
,'\t')<0) {
284 debuga(_("There is a broken url in file %s\n"),arqin
);
287 if (getword(tmsg
,sizeof(tmsg
),&gwarea
,'\t')<0) {
288 debuga(_("There is a broken access code in file %s\n"),arqin
);
291 if (getword_atoll(&nnelap
,&gwarea
,'\t')<0) {
292 debuga(_("There is a broken elapsed time in file %s\n"),arqin
);
295 if (getword_atoll(&incache
,&gwarea
,'\t')<0) {
296 debuga(_("There is a broken in cache column in file %s\n"),arqin
);
299 if (getword_atoll(&oucache
,&gwarea
,'\n')<0) {
300 debuga(_("There is a broken out of cache column in file %s (%d)\n"),arqin
,__LINE__
);
304 if(UserReportLimit
<=0 || count
<=UserReportLimit
) {
307 if(IndexTree
== INDEX_TREE_DATE
)
308 sprintf(tmp6
,"../%s",ImageFile
);
310 strcpy(tmp6
,"../../images");
312 if((ReportType
& REPORT_TYPE_SITE_USER_TIME_DATE
) != 0) {
313 url_to_file(url
,siteind
,sizeof(siteind
));
314 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"));
316 fprintf(fp_ou
,"<td class=\"data\"></td>");
320 fprintf(fp_ou
,"<td class=\"data2\"><span style=\"color:%s;\">%s</span></td>",PrivacyStringColor
,PrivacyString
);
322 fputs("<td class=\"data2\">",fp_ou
);
323 if(BlockIt
[0]!='\0') {
324 fprintf(fp_ou
,"<a href=\"%s%s?url=",wwwDocumentRoot
,BlockIt
);
325 output_html_url(fp_ou
,url
);
326 fprintf(fp_ou
,"\"><img src=\"%s/sarg-squidguard-block.png\"></a> ",tmp6
);
328 fputs("<a href=\"http://",fp_ou
);
329 output_html_url(fp_ou
,url
);
331 output_html_string(fp_ou
,url
,100);
332 fputs("</a></td>",fp_ou
);
335 if((UserReportFields
& USERREPORTFIELDS_CONNECT
) != 0) {
336 fputs("<td class=\"data\"",fp_ou
);
337 if (SortTableJs
[0]) fprintf(fp_ou
," sorttable_customkey=\"%"PRId64
"\"",(int64_t)twork
);
338 fprintf(fp_ou
,">%s</td>",fixnum(twork
,1));
340 if((UserReportFields
& USERREPORTFIELDS_BYTES
) != 0) {
341 fputs("<td class=\"data\"",fp_ou
);
342 if (SortTableJs
[0]) fprintf(fp_ou
," sorttable_customkey=\"%"PRId64
"\"",(int64_t)nnbytes
);
343 fprintf(fp_ou
,">%s</td>",fixnum(nnbytes
,1));
345 if((UserReportFields
& USERREPORTFIELDS_SETYB
) != 0) {
346 perc
=(tnbytes
) ? nnbytes
* 100. / tnbytes
: 0.;
347 fprintf(fp_ou
,"<td class=\"data\">%3.2lf%%</td>",perc
);
349 if((UserReportFields
& USERREPORTFIELDS_IN_CACHE_OUT
) != 0) {
350 inperc
=(nnbytes
) ? incache
* 100. / nnbytes
: 0.;
351 ouperc
=(nnbytes
) ? oucache
* 100. / nnbytes
: 0.;
352 fprintf(fp_ou
,"<td class=\"data\">%3.2lf%%</td><td class=\"data\">%3.2lf%%</td>",inperc
,ouperc
);
354 if((UserReportFields
& USERREPORTFIELDS_USED_TIME
) != 0) {
355 fputs("<td class=\"data\"",fp_ou
);
356 if (SortTableJs
[0]) fprintf(fp_ou
," sorttable_customkey=\"%"PRId64
"\"",(int64_t)nnelap
);
357 fprintf(fp_ou
,">%s</td>",buildtime(nnelap
));
359 if((UserReportFields
& USERREPORTFIELDS_MILISEC
) != 0) {
360 fputs("<td class=\"data\"",fp_ou
);
361 if (SortTableJs
[0]) fprintf(fp_ou
," sorttable_customkey=\"%"PRId64
"\"",(int64_t)nnelap
);
362 fprintf(fp_ou
,">%s</td>",fixnum2(nnelap
,1));
364 if((UserReportFields
& USERREPORTFIELDS_PTIME
) != 0) {
365 perc2
=(tnelap
) ? nnelap
* 100. / tnelap
: 0.;
366 fprintf(fp_ou
,"<td class=\"data\">%3.2lf%%</td>",perc2
);
369 if(strncmp(tmsg
,"OK",2) != 0)
370 fprintf(fp_ou
,"<td class=\"data\">%s</td>",_("DENIED"));
372 fputs("</tr>\n",fp_ou
);
377 if (snprintf(arqip
,sizeof(arqip
),"%s/%s.ip",tmp
,uinfo
->filename
)>=sizeof(arqip
)) {
378 debuga(_("File name too long: %s/%s.ip\n"),tmp
,uinfo
->filename
);
382 if ((fp_ip
= fopen(arqip
, "r")) == 0){
383 debuga(_("(html6) Cannot open file %s\n"),arqip
);
387 if ((fp_ip2
= MY_FOPEN(tmp2
, "a")) == 0){
388 debuga(_("(html7) Cannot open file %s\n"),tmp2
);
392 if ((line1
=longline_create())==NULL
) {
393 debuga(_("Not enough memory to read file %s\n"),arqip
);
396 while((buf
=longline_read(fp_ip
,line1
))!=NULL
) {
397 getword_start(&gwarea
,buf
);
398 if (getword(user_ip
,sizeof(user_ip
),&gwarea
,'\t')<0) {
399 debuga(_("Maybe you have a broken user IP in your %s file\n"),tmp3
);
402 if (getword_ptr(buf
,&user_url
,&gwarea
,'\t')<0) {
403 debuga(_("Maybe you have a broken url in your %s file\n"),tmp3
);
406 if (strncmp(user_url
,url
,strlen(url
))!=0) continue;
407 if (getword_skip(15,&gwarea
,'\t')<0) {
408 debuga(_("Maybe you have a broken day in your %s file\n"),tmp3
);
411 if (getword_skip(15,&gwarea
,'\t')<0) {
412 debuga(_("Maybe you have a broken time in your %s file\n"),tmp3
);
415 if (getword_atoll(&userbytes
,&gwarea
,'\t')<0) {
416 debuga(_("Maybe you have a broken size in your %s file\n"),tmp3
);
419 if (getword_atoll(&userelap
,&gwarea
,'\0')<0) {
420 debuga(_("Maybe you have a broken elapsed time in your %s file\n"),tmp3
);
423 fprintf(fp_ip2
,"%s\t%"PRIu64
"\t%"PRIu64
"\n",user_ip
,(uint64_t)userbytes
,(uint64_t)userelap
);
425 longline_destroy(&line1
);
430 sprintf(csort
,"sort -n -T \"%s\" -k 1,1 -k 2,2 -o \"%s\" \"%s\"",tmp
,tmp3
,tmp2
);
431 cstatus
=system(csort
);
432 if (!WIFEXITED(cstatus
) || WEXITSTATUS(cstatus
)) {
433 debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus
));
434 debuga(_("sort command: %s\n"),csort
);
438 if ((fp_ip
= MY_FOPEN(tmp3
, "r")) == 0) {
439 debuga(_("(html8) Cannot open file %s\n"),tmp3
);
445 if ((line1
=longline_create())==NULL
) {
446 debuga(_("Not enough memory to read file %s\n"),arqip
);
449 while((buf
=longline_read(fp_ip
,line1
))!=NULL
) {
450 getword_start(&gwarea
,buf
);
451 if (getword(user_ip
,sizeof(user_ip
),&gwarea
,'\t')<0) {
452 debuga(_("Maybe you have a broken user IP in your %s file\n"),tmp3
);
455 if (getword_atoll(&userbytes
,&gwarea
,'\t')<0) {
456 debuga(_("Maybe you have a broken size in your %s file\n"),tmp3
);
459 if (getword_atoll(&userelap
,&gwarea
,'\0')<0) {
460 debuga(_("Maybe you have a broken elapsed time in your %s file\n"),tmp3
);
463 if(strcmp(user_ip
,olduserip
) != 0) {
464 if (olduserip
[0]!='\0') {
465 fprintf(fp_ou
,"<tr><td></td><td class=\"data\">%s</td>",olduserip
);
466 if((UserReportFields
& USERREPORTFIELDS_CONNECT
) != 0)
467 fputs("<td></td>",fp_ou
);
468 if((UserReportFields
& USERREPORTFIELDS_BYTES
) != 0)
469 fprintf(fp_ou
,"<td class=\"data\">%s</td>",fixnum(unbytes
,1));
470 if((UserReportFields
& USERREPORTFIELDS_SETYB
) != 0)
471 fputs("<td></td>",fp_ou
);
472 if((UserReportFields
& USERREPORTFIELDS_IN_CACHE_OUT
) != 0)
473 fputs("</td><td></td><td></td>",fp_ou
);
474 if((UserReportFields
& USERREPORTFIELDS_USED_TIME
) != 0)
475 fprintf(fp_ou
,"<td class=\"data\">%s</td>",buildtime(unelap
));
476 if((UserReportFields
& USERREPORTFIELDS_MILISEC
) != 0)
477 fprintf(fp_ou
,"<td class=\"data\">%s</td>",fixnum2(unelap
,1));
478 fputs("</tr>\n",fp_ou
);
481 strcpy(olduserip
,user_ip
);
492 longline_destroy(&line1
);
497 if (olduserip
[0]!='\0') {
498 fprintf(fp_ou
,"<tr><td></td><td class=\"data\">%s</td>",olduserip
);
499 if((UserReportFields
& USERREPORTFIELDS_CONNECT
) != 0)
500 fputs("<td></td>",fp_ou
);
501 if((UserReportFields
& USERREPORTFIELDS_BYTES
) != 0)
502 fprintf(fp_ou
,"<td class=\"data\">%s</td>",fixnum(unbytes
,1));
503 if((UserReportFields
& USERREPORTFIELDS_SETYB
) != 0)
504 fputs("<td></td>",fp_ou
);
505 if((UserReportFields
& USERREPORTFIELDS_IN_CACHE_OUT
) != 0)
506 fputs("</td><td></td><td></td>",fp_ou
);
507 if((UserReportFields
& USERREPORTFIELDS_USED_TIME
) != 0)
508 fprintf(fp_ou
,"<td class=\"data\">%s</td>",buildtime(unelap
));
509 if((UserReportFields
& USERREPORTFIELDS_MILISEC
) != 0)
510 fprintf(fp_ou
,"<td class=\"data\">%s</td>",fixnum2(unelap
,1));
511 fputs("</tr>\n",fp_ou
);
521 longline_destroy(&line
);
527 if ((UserReportFields
& (USERREPORTFIELDS_TOTAL
| USERREPORTFIELDS_AVERAGE
)) != 0)
528 fputs("<tfoot>",fp_ou
);
530 if((UserReportFields
& USERREPORTFIELDS_TOTAL
) != 0) {
531 fprintf(fp_ou
,"<tr><th></th><th class=\"header_l\">%s</th>",_("TOTAL"));
532 if((UserReportFields
& USERREPORTFIELDS_CONNECT
) != 0)
533 fprintf(fp_ou
,"<th class=\"header_r\">%s</th>",fixnum(tnacc
,1));
534 if((UserReportFields
& USERREPORTFIELDS_BYTES
) != 0)
535 fprintf(fp_ou
,"<th class=\"header_r\">%s</th>",fixnum(tnbytes
,1));
536 if((UserReportFields
& USERREPORTFIELDS_SETYB
) != 0) {
537 perc
=(totbytes
) ? tnbytes
*100. / totbytes
:0.;
538 fprintf(fp_ou
,"<th class=\"header_r\">%3.2lf%%</th>",perc
);
540 if((UserReportFields
& USERREPORTFIELDS_IN_CACHE_OUT
) != 0) {
541 inperc
=(tnbytes
) ? tnincache
* 100. / tnbytes
: 0.;
542 ouperc
=(tnbytes
) ? tnoucache
* 100. / tnbytes
: 0.;
543 fprintf(fp_ou
,"<th class=\"header_r\">%3.2lf%%</th><th class=\"header_r\">%3.2lf%%</th>",inperc
,ouperc
);
545 if((UserReportFields
& USERREPORTFIELDS_USED_TIME
) != 0)
546 fprintf(fp_ou
,"<th class=\"header_r\">%s</th>",buildtime(tnelap
));
547 if((UserReportFields
& USERREPORTFIELDS_MILISEC
) != 0)
548 fprintf(fp_ou
,"<th class=\"header_r\">%s</th>",fixnum2(tnelap
,1));
549 if((UserReportFields
& USERREPORTFIELDS_PTIME
) != 0) {
550 perc2
=(totelap
) ? tnelap
* 100. / totelap
: 0.;
551 fprintf(fp_ou
,"<th class=\"header_r\">%3.2lf%%</th>",perc2
);
553 fputs("</tr>\n",fp_ou
);
556 if(PerUserLimit
> 0) {
557 if(tnbytes
> (PerUserLimit
*1000000)) {
559 if(access(PerUserLimitFile
, R_OK
) == 0) {
560 if((fp_usr
= fopen(PerUserLimitFile
, "r")) == 0) {
561 debuga(_("(html9) Cannot open file %s\n"),PerUserLimitFile
);
564 while(fgets(tmp6
,sizeof(tmp6
),fp_usr
)!=NULL
) {
566 if(strcmp(tmp6
,uinfo
->label
) == 0) {
575 if((fp_usr
= fopen(PerUserLimitFile
, "a")) == 0) {
576 debuga(_("(html10) Cannot open file %s\n"),PerUserLimitFile
);
579 fprintf(fp_usr
,"%s\n",uinfo
->label
);
583 debuga(_("User %s limit exceeded (%d MB). Added to file %s\n"),uinfo
->label
,PerUserLimit
,PerUserLimitFile
);
593 if ((ReportType
& REPORT_TYPE_TOPUSERS
) != 0 && (UserReportFields
& USERREPORTFIELDS_AVERAGE
) != 0) {
594 totbytes2
=totbytes
/ntotuser
;
595 totelap2
=totelap
/ntotuser
;
597 fprintf(fp_ou
,"<tr><th></th><th class=\"header_l\">%s</th>",_("AVERAGE"));
598 if((UserReportFields
& USERREPORTFIELDS_CONNECT
) != 0)
599 fprintf(fp_ou
,"<th class=\"header_r\">%s</th>",fixnum(ttnacc
/ntotuser
,1));
600 if((UserReportFields
& USERREPORTFIELDS_BYTES
) != 0)
601 fprintf(fp_ou
,"<th class=\"header_r\">%s</th>",fixnum(totbytes2
,1));
602 fprintf(fp_ou
,"<th></th><th></th><th></th>");
603 if((UserReportFields
& USERREPORTFIELDS_USED_TIME
) != 0)
604 fprintf(fp_ou
,"<th class=\"header_r\">%s</th>",buildtime(totelap2
));
605 if((UserReportFields
& USERREPORTFIELDS_MILISEC
) != 0)
606 fprintf(fp_ou
,"<th class=\"header_r\">%s</th>",fixnum2(totelap2
,1));
607 if((UserReportFields
& USERREPORTFIELDS_PTIME
) != 0) {
608 perc2
= (totelap
) ? totelap2
* 100. / totelap
: 0.;
609 fprintf(fp_ou
,"<th class=\"header_r\">%3.2lf%%</th>",perc2
);
611 fputs("</tr>\n",fp_ou
);
614 if ((UserReportFields
& (USERREPORTFIELDS_TOTAL
| USERREPORTFIELDS_AVERAGE
)) != 0)
615 fputs("</tfoot>",fp_ou
);
617 fputs("</table></div>\n",fp_ou
);
618 if (write_html_trailer(fp_ou
)<0)
619 debuga(_("Write error in file %s\n"),arqou
);
620 if (fclose(fp_ou
)==EOF
)
621 debuga(_("Failed to close file %s - %s\n"),arqou
,strerror(errno
));
626 (void)closedir(dirp
);