]> git.ipfire.org Git - thirdparty/sarg.git/blob - html.c
Strengthen the making of the report file name to drastically limit the characters...
[thirdparty/sarg.git] / html.c
1 /*
2 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
3 * 1998, 2010
4 *
5 * SARG donations:
6 * please look at http://sarg.sourceforge.net/donations.php
7 * Support:
8 * http://sourceforge.net/projects/sarg/forums/forum/363374
9 * ---------------------------------------------------------------------
10 *
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.
15 *
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.
20 *
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.
24 *
25 */
26
27 #include "include/conf.h"
28 #include "include/defs.h"
29
30 void htmlrel(void)
31 {
32 DIR *dirp;
33 FILE *fp_in, *fp_ou, *fp_ip, *fp_ip2, *fp_usr;
34
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;
39 long long int ltemp;
40 long long int ntotuser;
41 long long int userbytes, userelap;
42 char *buf;
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 userhora[9], userdia[9];
47 char user_ip[MAXLEN], olduserip[MAXLEN], tmp2[MAXLEN], tmp3[MAXLEN];
48 char denied_report[255];
49 char *str;
50 char warea[MAXLEN];
51 char totuser[8];
52 char ltext110[100];
53 char tmp6[MAXLEN];
54 long long int tnacc=0, ttnacc=0, unacc=0;
55 double perc=0, perc2=0, ouperc=0, inperc=0;
56 char *s;
57 int count;
58 int cstatus;
59 const char txtext[]=".txt";
60 int dlen;
61 char siteind[MAX_TRUNCATED_URL];
62 struct getwordstruct gwarea;
63 longline line,line1;
64 struct generalitemstruct item;
65 const struct userinfostruct *uinfo;
66
67 if((ReportType & REPORT_TYPE_USERS_SITES) == 0) return;
68
69 strcpy(tmp2,TempDir);
70 strcat(tmp2,"/sargtmp.unsort");
71
72 strcpy(tmp3,TempDir);
73 strcat(tmp3,"/sargtmp.log");
74
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);
78 exit(EXIT_FAILURE);
79 }
80 if ((line=longline_create())==NULL) {
81 debuga(_("Not enough memory to read file %s\n"),arqper);
82 exit(EXIT_FAILURE);
83 }
84 ttnacc=0;
85 totbytes=0;
86 totelap=0;
87 while((buf=longline_read(fp_in,line))!=NULL) {
88 ger_read(buf,&item,arqper);
89 if(item.total) {
90 ttnacc+=item.nacc;
91 totbytes+=item.nbytes;
92 totelap+=item.nelap;
93 }
94 }
95 fclose(fp_in);
96 longline_destroy(&line);
97
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);
101 exit(EXIT_FAILURE);
102 }
103 if (!fgets(totuser,sizeof(totuser),fp_in)) {
104 debuga(_("(html11) read error in %s\n"),arqper);
105 exit(EXIT_FAILURE);
106 }
107 fclose(fp_in);
108 ntotuser=my_atoll(totuser);
109 if (ntotuser<=0) ntotuser=1;
110
111 if ((dirp = opendir(tmp)) == NULL) {
112 debuga(_("Failed to open directory %s - %s\n"),tmp,strerror(errno));
113 exit(EXIT_FAILURE);
114 }
115 while ( (direntp = readdir( dirp )) != NULL ) {
116 dlen=strlen(direntp->d_name)-(sizeof(txtext)-1);
117 if (dlen<0) continue;
118 if(strcmp(direntp->d_name+dlen,txtext) != 0)
119 continue;
120
121 count=1;
122 if (dlen>0) {
123 if (dlen>=sizeof(user)) continue;
124 strncpy(user,direntp->d_name,dlen);
125 user[dlen]=0;
126 } else {
127 user[0]=0;
128 }
129
130 uinfo=userinfo_find_from_file(user);
131 if (!uinfo) {
132 debuga(_("Unknown user ID %s in directory %s\n"),user,tmp);
133 exit(EXIT_FAILURE);
134 }
135 str=strrchr(user,'.');
136 if (str)
137 strcpy(denied_report,str+1);
138 else
139 strcpy(denied_report,user);
140
141 if (snprintf(warea,sizeof(warea),"%s/%s",outdirname,user)>=sizeof(warea)) {
142 debuga(_("Destination directory too long: %s/%s\n"),outdirname,user);
143 exit(EXIT_FAILURE);
144 }
145 mkdir(warea,0755);
146
147 report_day(uinfo);
148 greport_day(uinfo);
149
150 if (snprintf(arqin,sizeof(arqin),"%s/%s",tmp,direntp->d_name)>=sizeof(arqin)) {
151 debuga(_("Input file name too long: %s/%s\n"),tmp,direntp->d_name);
152 exit(EXIT_FAILURE);
153 }
154 if (snprintf(arqou,sizeof(arqou),"%s/%s/%s.html",outdirname,uinfo->filename,uinfo->filename)>=sizeof(arqou)) {
155 debuga(_("Output file name too long: %s/%s/%s.html\n"),outdirname,uinfo->filename,uinfo->filename);
156 exit(EXIT_FAILURE);
157 }
158 if (snprintf(duser,sizeof(duser),"%s/%s/denied_%s.html",tmp,direntp->d_name,denied_report)>=sizeof(duser)) {
159 debuga(_("File name too long: %s/%s/denied_%s.html\n"),tmp,direntp->d_name,denied_report);
160 exit(EXIT_FAILURE);
161 }
162 if(access(duser, R_OK) != 0)
163 denied_report[0]='\0';
164
165 if ((fp_in = fopen(arqin, "r")) == 0){
166 debuga(_("(html3) Cannot open file %s\n"),arqin);
167 exit(EXIT_FAILURE);
168 }
169
170 if ((line=longline_create())==NULL) {
171 debuga(_("Not enough memory to read file %s\n"),arqin);
172 exit(EXIT_FAILURE);
173 }
174
175 tnacc=0;
176 tnbytes=0;
177 tnelap=0;
178 tnincache=0;
179 tnoucache=0;
180 while((buf=longline_read(fp_in,line))!=NULL) {
181 getword_start(&gwarea,buf);
182 if (getword_atoll(&ltemp,&gwarea,'\t')<0) {
183 debuga(_("There is a broken number of access in file %s\n"),arqin);
184 exit(EXIT_FAILURE);
185 }
186 tnacc+=ltemp;
187 if (getword_atoll(&ltemp,&gwarea,'\t')<0) {
188 debuga(_("There is a broken downloaded size in file %s\n"),arqin);
189 exit(EXIT_FAILURE);
190 }
191 tnbytes+=ltemp;
192 if (getword_ptr(NULL,NULL,&gwarea,'\t')<0) {
193 debuga(_("There is a broken url in file %s\n"),arqin);
194 exit(EXIT_FAILURE);
195 }
196 if (getword_skip(MAXLEN,&gwarea,'\t')<0) {
197 debuga(_("There is a broken access code in file %s\n"),arqin);
198 exit(EXIT_FAILURE);
199 }
200 if (getword_atoll(&ltemp,&gwarea,'\t')<0) {
201 debuga(_("There is a broken elapsed time in file %s\n"),arqin);
202 exit(EXIT_FAILURE);
203 }
204 tnelap+=ltemp;
205 if (getword_atoll(&ltemp,&gwarea,'\t')<0) {
206 debuga(_("There is a broken in-cache volume in file %s\n"),arqin);
207 exit(EXIT_FAILURE);
208 }
209 tnincache+=ltemp;
210 if (getword_atoll(&ltemp,&gwarea,'\n')<0) {
211 debuga(_("There is a broken out-cache volume in file %s\n"),arqin);
212 exit(EXIT_FAILURE);
213 }
214 tnoucache+=ltemp;
215 }
216
217 rewind(fp_in);
218
219 if ((fp_ou = fopen(arqou, "w")) == 0){
220 debuga(_("(html5) Cannot open file %s\n"),arqou);
221 exit(EXIT_FAILURE);
222 }
223
224 write_html_header(fp_ou,(IndexTree == INDEX_TREE_DATE) ? 4 : 2,_("User report"));
225 fprintf(fp_ou,"<tr><td class=\"header_c\">%s:&nbsp;%s</td></tr>\n",_("Period"),period.html);
226 fprintf(fp_ou,"<tr><td class=\"header_c\">%s:&nbsp;%s</td></tr>\n",_("User"),uinfo->label);
227 fprintf(fp_ou,"<tr><td class=\"header_c\">%s:&nbsp;%s, %s</td></tr>\n",_("Sort"),UserSortField,UserSortOrder);
228 fprintf(fp_ou,"<tr><th class=\"header_c\">%s</th></tr>\n",_("User report"));
229 close_html_header(fp_ou);
230
231 fputs("<div class=\"report\"><table cellpadding=\"2\" cellspacing=\"1\">\n",fp_ou);
232
233 if(denied_report[0]!='\0') {
234 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"));
235 }
236
237 fprintf(fp_ou,"<tr><th></th><th class=\"header_l\">%s</th>",_("ACCESSED SITE"));
238
239 if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0)
240 fprintf(fp_ou,"<th class=\"header_l\">%s</th>",_("CONNECT"));
241 if((UserReportFields & USERREPORTFIELDS_BYTES) != 0)
242 fprintf(fp_ou,"<th class=\"header_l\">%s</th>",_("BYTES"));
243 if((UserReportFields & USERREPORTFIELDS_SETYB) != 0)
244 fprintf(fp_ou,"<th class=\"header_l\">%%%s</th>",_("BYTES"));
245 if((UserReportFields & USERREPORTFIELDS_IN_CACHE_OUT) != 0)
246 fprintf(fp_ou,"<th class=\"header_c\" colspan=\"2\">%s</th>",_("IN-CACHE-OUT"));
247 if((UserReportFields & USERREPORTFIELDS_USED_TIME) != 0)
248 fprintf(fp_ou,"<th class=\"header_l\">%s</th>",_("ELAPSED TIME"));
249 if((UserReportFields & USERREPORTFIELDS_MILISEC) != 0)
250 fprintf(fp_ou,"<th class=\"header_l\">%s</th>",_("MILLISEC"));
251 if((UserReportFields & USERREPORTFIELDS_PTIME) != 0)
252 fprintf(fp_ou,"<th class=\"header_l\">%%%s</th>",_("TIME"));
253
254 fputs("</tr>\n",fp_ou);
255
256 if(debug) {
257 debuga(_("Making report: %s\n"),uinfo->id);
258 }
259
260 while((buf=longline_read(fp_in,line))!=NULL) {
261 getword_start(&gwarea,buf);
262 if (getword_atoll(&twork,&gwarea,'\t')<0) {
263 debuga(_("There is a broken number of access in file %s\n"),arqin);
264 exit(EXIT_FAILURE);
265 }
266 if (getword_atoll(&nnbytes,&gwarea,'\t')<0) {
267 debuga(_("There is a broken number of bytes in file %s\n"),arqin);
268 exit(EXIT_FAILURE);
269 }
270 if (getword_ptr(buf,&url,&gwarea,'\t')<0) {
271 debuga(_("There is a broken url in file %s\n"),arqin);
272 exit(EXIT_FAILURE);
273 }
274 if (getword(tmsg,sizeof(tmsg),&gwarea,'\t')<0) {
275 debuga(_("There is a broken access code in file %s\n"),arqin);
276 exit(EXIT_FAILURE);
277 }
278 if (getword_atoll(&nnelap,&gwarea,'\t')<0) {
279 debuga(_("There is a broken elapsed time in file %s\n"),arqin);
280 exit(EXIT_FAILURE);
281 }
282 if (getword_atoll(&incache,&gwarea,'\t')<0) {
283 debuga(_("There is a broken in cache column in file %s\n"),arqin);
284 exit(EXIT_FAILURE);
285 }
286 if (getword_atoll(&oucache,&gwarea,'\n')<0) {
287 debuga(_("There is a broken out of cache column in file %s (%d)\n"),arqin,__LINE__);
288 exit(EXIT_FAILURE);
289 }
290
291 if(UserReportLimit<=0 || count<=UserReportLimit) {
292 fputs("<tr>",fp_ou);
293
294 if(IndexTree == INDEX_TREE_DATE)
295 sprintf(tmp6,"../%s",ImageFile);
296 else
297 strcpy(tmp6,"../../images");
298
299 if((ReportType & REPORT_TYPE_SITE_USER_TIME_DATE) != 0) {
300 s=_("DATE/TIME");
301 for(z1=0 ; z1<sizeof(ltext110)-1 && s[z1] ; z1++)
302 ltext110[z1]=tolower(s[z1]);
303 ltext110[z1]='\0';
304 url_to_file(url,siteind,sizeof(siteind));
305 fprintf(fp_ou,"<td class=\"data\"><a href=\"tt%s-%s.html\"><img src=\"%s/datetime.png\" title=\"%s %s\" alt=\"T\"></a></td>",uinfo->filename,siteind,tmp6,ltext110,_("Report"));
306 } else {
307 fprintf(fp_ou,"<td class=\"data\"></td>");
308 }
309
310 if(Privacy)
311 fprintf(fp_ou,"<td class=\"data2\"><span style=\"color:%s;\">%s</span></td>",PrivacyStringColor,PrivacyString);
312 else {
313 fputs("<td class=\"data2\">",fp_ou);
314 if(BlockIt[0]!='\0') {
315 fprintf(fp_ou,"<a href=\"%s%s?url=",wwwDocumentRoot,BlockIt);
316 output_html_url(fp_ou,url);
317 fprintf(fp_ou,"\"><img src=\"%s/sarg-squidguard-block.png\"></a>&nbsp;",tmp6);
318 }
319 fputs("<a href=\"http://",fp_ou);
320 output_html_url(fp_ou,url);
321 fputs("\">",fp_ou);
322 output_html_string(fp_ou,url,100);
323 fputs("</a></td>",fp_ou);
324 }
325
326 if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0)
327 fprintf(fp_ou,"<td class=\"data\">%s</td>",fixnum(twork,1));
328 if((UserReportFields & USERREPORTFIELDS_BYTES) != 0)
329 fprintf(fp_ou,"<td class=\"data\">%s</td>",fixnum(nnbytes,1));
330 if((UserReportFields & USERREPORTFIELDS_SETYB) != 0) {
331 perc=(tnbytes) ? nnbytes * 100. / tnbytes : 0.;
332 fprintf(fp_ou,"<td class=\"data\">%3.2lf%%</td>",perc);
333 }
334 if((UserReportFields & USERREPORTFIELDS_IN_CACHE_OUT) != 0) {
335 inperc=(nnbytes) ? incache * 100. / nnbytes : 0.;
336 ouperc=(nnbytes) ? oucache * 100. / nnbytes : 0.;
337 fprintf(fp_ou,"<td class=\"data\">%3.2lf%%</td><td class=\"data\">%3.2lf%%</td>",inperc,ouperc);
338 }
339 if((UserReportFields & USERREPORTFIELDS_USED_TIME) != 0)
340 fprintf(fp_ou,"<td class=\"data\">%s</td>",buildtime(nnelap));
341 if((UserReportFields & USERREPORTFIELDS_MILISEC) != 0)
342 fprintf(fp_ou,"<td class=\"data\">%s</td>",fixnum2(nnelap,1));
343 if((UserReportFields & USERREPORTFIELDS_PTIME) != 0) {
344 perc2=(tnelap) ? nnelap * 100. / tnelap : 0.;
345 fprintf(fp_ou,"<td class=\"data\">%3.2lf%%</td>",perc2);
346 }
347
348 if(strncmp(tmsg,"OK",2) != 0)
349 fprintf(fp_ou,"<td class=\"data\">%s</td>",_("DENIED"));
350
351 fputs("</tr>\n",fp_ou);
352 count++;
353 }
354
355 if(iprel) {
356 if (snprintf(arqip,sizeof(arqip),"%s/%s.ip",tmp,uinfo->filename)>=sizeof(arqip)) {
357 debuga(_("File name too long: %s/%s.ip\n"),tmp,uinfo->filename);
358 exit(EXIT_FAILURE);
359 }
360
361 if ((fp_ip = fopen(arqip, "r")) == 0){
362 debuga(_("(html6) Cannot open file %s\n"),arqip);
363 exit(EXIT_FAILURE);
364 }
365
366 if ((fp_ip2 = MY_FOPEN(tmp2, "a")) == 0){
367 debuga(_("(html7) Cannot open file %s\n"),tmp2);
368 exit(EXIT_FAILURE);
369 }
370
371 if ((line1=longline_create())==NULL) {
372 debuga(_("Not enough memory to read file %s\n"),arqip);
373 exit(EXIT_FAILURE);
374 }
375 while((buf=longline_read(fp_ip,line1))!=NULL) {
376 if(strstr(buf,url) != 0)
377 fputs(buf,fp_ip2);
378 }
379 longline_destroy(&line1);
380
381 fclose(fp_ip);
382 fclose(fp_ip2);
383
384 sprintf(csort,"sort -n -T \"%s\" -k 1,1 -k 5,5 -o \"%s\" \"%s\"",TempDir,tmp3,tmp2);
385 cstatus=system(csort);
386 if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
387 debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus));
388 debuga(_("sort command: %s\n"),csort);
389 exit(EXIT_FAILURE);
390 }
391
392 if ((fp_ip = MY_FOPEN(tmp3, "r")) == 0) {
393 debuga(_("(html8) Cannot open file %s\n"),tmp3);
394 exit(EXIT_FAILURE);
395 }
396
397 olduserip[0]='\0';
398
399 if ((line1=longline_create())==NULL) {
400 debuga(_("Not enough memory to read file %s\n"),arqip);
401 exit(EXIT_FAILURE);
402 }
403 while((buf=longline_read(fp_ip,line1))!=NULL) {
404 getword_start(&gwarea,buf);
405 if (getword(user_ip,sizeof(user_ip),&gwarea,'\t')<0) {
406 debuga(_("Maybe you have a broken user IP in your %s file\n"),tmp3);
407 exit(EXIT_FAILURE);
408 }
409 if (getword_ptr(NULL,NULL,&gwarea,'\t')<0) {
410 debuga(_("Maybe you have a broken url in your %s file\n"),tmp3);
411 exit(EXIT_FAILURE);
412 }
413 if (getword(userdia,sizeof(userdia),&gwarea,'\t')<0) {
414 debuga(_("Maybe you have a broken day in your %s file\n"),tmp3);
415 exit(EXIT_FAILURE);
416 }
417 if (getword(userhora,sizeof(userhora),&gwarea,'\t')<0) {
418 debuga(_("Maybe you have a broken time in your %s file\n"),tmp3);
419 exit(EXIT_FAILURE);
420 }
421 if (getword_atoll(&userbytes,&gwarea,'\t')<0) {
422 debuga(_("Maybe you have a broken size in your %s file\n"),tmp3);
423 exit(EXIT_FAILURE);
424 }
425 if (getword_atoll(&userelap,&gwarea,'\t')<0) {
426 debuga(_("Maybe you have a broken elapsed time in your %s file\n"),tmp3);
427 exit(EXIT_FAILURE);
428 }
429 if(strcmp(user_ip,olduserip) != 0) {
430 sprintf(wwork1,"%s",fixnum(unbytes,1));
431 fprintf(fp_ou,"<tr><td></td><td class=\"data\">%s</td><td></td><td class=\"data\">%s</td><td></td><td></td><td></td><td class=\"data\">%s</td><td class=\"data\">%lld</td></tr>\n",olduserip,wwork1,buildtime(unelap),unelap);
432
433 strcpy(olduserip,user_ip);
434 unacc=0;
435 unbytes=0;
436 unelap=0;
437 }
438
439 unbytes=unbytes+userbytes;
440 unelap=unelap+userelap;
441 }
442
443 fclose(fp_ip);
444 longline_destroy(&line1);
445
446 unlink(tmp2);
447 unlink(tmp3);
448
449 sprintf(wwork1,"%s",fixnum(unbytes,1));
450 fprintf(fp_ou,"<tr><td></td><td class=\"data\">%s</td><td></td><td class=\"data\">%s</td><td></td><td></td><td></td><td class=\"data\">%s</td><td class=\"data\">%lld</td></tr>\n",olduserip,wwork1,buildtime(unelap),unelap);
451 }
452
453 unacc=0;
454 unbytes=0;
455 unelap=0;
456 }
457
458 fclose(fp_in);
459 longline_destroy(&line);
460
461 if(iprel)
462 unlink(arqip);
463 unlink(arqin);
464
465 if((UserReportFields & USERREPORTFIELDS_TOTAL) != 0) {
466 fprintf(fp_ou,"<tr><th></th><th class=\"header_l\">%s</th>",_("TOTAL"));
467 if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0)
468 fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fixnum(tnacc,1));
469 if((UserReportFields & USERREPORTFIELDS_BYTES) != 0)
470 fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fixnum(tnbytes,1));
471 if((UserReportFields & USERREPORTFIELDS_SETYB) != 0) {
472 perc=(totbytes) ? tnbytes *100. / totbytes :0.;
473 fprintf(fp_ou,"<th class=\"header_r\">%3.2lf%%</th>",perc);
474 }
475 if((UserReportFields & USERREPORTFIELDS_IN_CACHE_OUT) != 0) {
476 inperc=(tnbytes) ? tnincache * 100. / tnbytes : 0.;
477 ouperc=(tnbytes) ? tnoucache * 100. / tnbytes : 0.;
478 fprintf(fp_ou,"<th class=\"header_r\">%3.2lf%%</th><th class=\"header_r\">%3.2lf%%</th>",inperc,ouperc);
479 }
480 if((UserReportFields & USERREPORTFIELDS_USED_TIME) != 0)
481 fprintf(fp_ou,"<th class=\"header_r\">%s</th>",buildtime(tnelap));
482 if((UserReportFields & USERREPORTFIELDS_MILISEC) != 0)
483 fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fixnum2(tnelap,1));
484 if((UserReportFields & USERREPORTFIELDS_PTIME) != 0) {
485 perc2=(totelap) ? tnelap * 100. / totelap : 0.;
486 fprintf(fp_ou,"<th class=\"header_r\">%3.2lf%%</th>",perc2);
487 }
488 fputs("</tr>\n",fp_ou);
489 }
490
491 if(PerUserLimit > 0) {
492 if(tnbytes > (PerUserLimit*1000000)) {
493 limit_flag=0;
494 if(access(PerUserLimitFile, R_OK) == 0) {
495 if((fp_usr = fopen(PerUserLimitFile, "r")) == 0) {
496 debuga(_("(html9) Cannot open file %s\n"),PerUserLimitFile);
497 exit(EXIT_FAILURE);
498 }
499 while(fgets(tmp6,sizeof(tmp6),fp_usr)!=NULL) {
500 fixendofline(tmp6);
501 if(strcmp(tmp6,uinfo->label) == 0) {
502 limit_flag=1;
503 break;
504 }
505 }
506 fclose(fp_usr);
507 }
508
509 if(!limit_flag) {
510 if((fp_usr = fopen(PerUserLimitFile, "a")) == 0) {
511 debuga(_("(html10) Cannot open file %s\n"),PerUserLimitFile);
512 exit(EXIT_FAILURE);
513 }
514 fprintf(fp_usr,"%s\n",uinfo->label);
515 fclose(fp_usr);
516
517 if(debug)
518 debuga(_("User %s limit exceeded (%d MB). Added to file %s\n"),uinfo->label,PerUserLimit,PerUserLimitFile);
519 }
520 }
521 }
522
523 // if(indexonly) {
524 // unlink(arqou);
525 // continue;
526 // }
527
528 if ((ReportType & REPORT_TYPE_TOPUSERS) != 0 && (UserReportFields & USERREPORTFIELDS_AVERAGE) != 0) {
529 totbytes2=totbytes/ntotuser;
530 totelap2=totelap/ntotuser;
531
532 fprintf(fp_ou,"<tr><th></th><th class=\"header_l\">%s</th>",_("AVERAGE"));
533 if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0)
534 fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fixnum(ttnacc/ntotuser,1));
535 if((UserReportFields & USERREPORTFIELDS_BYTES) != 0)
536 fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fixnum(totbytes2,1));
537 fprintf(fp_ou,"<th></th><th></th><th></th>");
538 if((UserReportFields & USERREPORTFIELDS_USED_TIME) != 0)
539 fprintf(fp_ou,"<th class=\"header_r\">%s</th>",buildtime(totelap2));
540 if((UserReportFields & USERREPORTFIELDS_MILISEC) != 0)
541 fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fixnum2(totelap2,1));
542 if((UserReportFields & USERREPORTFIELDS_PTIME) != 0) {
543 perc2 = (totelap) ? totelap2 * 100. / totelap : 0.;
544 fprintf(fp_ou,"<th class=\"header_r\">%3.2lf%%</th>",perc2);
545 }
546 fputs("</tr>\n",fp_ou);
547 }
548
549 fputs("</table></div>\n",fp_ou);
550 if (write_html_trailer(fp_ou)<0)
551 debuga(_("Write error in file %s\n"),arqou);
552 if (fclose(fp_ou)==EOF)
553 debuga(_("Failed to close file %s - %s\n"),arqou,strerror(errno));
554
555 htaccess(uinfo);
556 }
557
558 (void)closedir(dirp);
559 greport_cleanup();
560
561 return;
562 }