]> git.ipfire.org Git - thirdparty/sarg.git/blob - html.c
Don't save the unnecessary columns in the intermediary file that is sorted to produce...
[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 user_ip[MAXLEN], olduserip[MAXLEN], tmp2[MAXLEN], tmp3[MAXLEN];
47 char denied_report[255];
48 char *str;
49 char warea[MAXLEN];
50 char totuser[8];
51 char tmp6[MAXLEN];
52 char *user_url;
53 long long int tnacc=0, ttnacc=0, unacc=0;
54 double perc=0, perc2=0, ouperc=0, inperc=0;
55 int count;
56 int cstatus;
57 const char txtext[]=".txt";
58 int dlen;
59 char siteind[MAX_TRUNCATED_URL];
60 struct getwordstruct gwarea;
61 longline line,line1;
62 struct generalitemstruct item;
63 const struct userinfostruct *uinfo;
64
65 if((ReportType & REPORT_TYPE_USERS_SITES) == 0) return;
66
67 strcpy(tmp2,tmp);
68 strcat(tmp2,"/sargtmp.unsort");
69
70 strcpy(tmp3,tmp);
71 strcat(tmp3,"/sargtmp.log");
72
73 snprintf(arqper,sizeof(arqper),"%s/sarg-general",outdirname);
74 if ((fp_in = fopen(arqper, "r")) == 0){
75 debuga(_("(html2) Cannot open file %s\n"),arqper);
76 exit(EXIT_FAILURE);
77 }
78 if ((line=longline_create())==NULL) {
79 debuga(_("Not enough memory to read file %s\n"),arqper);
80 exit(EXIT_FAILURE);
81 }
82 ttnacc=0;
83 totbytes=0;
84 totelap=0;
85 while((buf=longline_read(fp_in,line))!=NULL) {
86 ger_read(buf,&item,arqper);
87 if(item.total) {
88 ttnacc+=item.nacc;
89 totbytes+=item.nbytes;
90 totelap+=item.nelap;
91 }
92 }
93 fclose(fp_in);
94 longline_destroy(&line);
95
96 snprintf(arqper,sizeof(arqper),"%s/sarg-users",outdirname);
97 if ((fp_in = fopen(arqper, "r")) == 0){
98 debuga(_("(html11) Cannot open file %s\n"),arqper);
99 exit(EXIT_FAILURE);
100 }
101 if (!fgets(totuser,sizeof(totuser),fp_in)) {
102 debuga(_("(html11) read error in %s\n"),arqper);
103 exit(EXIT_FAILURE);
104 }
105 fclose(fp_in);
106 ntotuser=my_atoll(totuser);
107 if (ntotuser<=0) ntotuser=1;
108
109 greport_prepare();
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 url_to_file(url,siteind,sizeof(siteind));
301 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"));
302 } else {
303 fprintf(fp_ou,"<td class=\"data\"></td>");
304 }
305
306 if(Privacy)
307 fprintf(fp_ou,"<td class=\"data2\"><span style=\"color:%s;\">%s</span></td>",PrivacyStringColor,PrivacyString);
308 else {
309 fputs("<td class=\"data2\">",fp_ou);
310 if(BlockIt[0]!='\0') {
311 fprintf(fp_ou,"<a href=\"%s%s?url=",wwwDocumentRoot,BlockIt);
312 output_html_url(fp_ou,url);
313 fprintf(fp_ou,"\"><img src=\"%s/sarg-squidguard-block.png\"></a>&nbsp;",tmp6);
314 }
315 fputs("<a href=\"http://",fp_ou);
316 output_html_url(fp_ou,url);
317 fputs("\">",fp_ou);
318 output_html_string(fp_ou,url,100);
319 fputs("</a></td>",fp_ou);
320 }
321
322 if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0)
323 fprintf(fp_ou,"<td class=\"data\">%s</td>",fixnum(twork,1));
324 if((UserReportFields & USERREPORTFIELDS_BYTES) != 0)
325 fprintf(fp_ou,"<td class=\"data\">%s</td>",fixnum(nnbytes,1));
326 if((UserReportFields & USERREPORTFIELDS_SETYB) != 0) {
327 perc=(tnbytes) ? nnbytes * 100. / tnbytes : 0.;
328 fprintf(fp_ou,"<td class=\"data\">%3.2lf%%</td>",perc);
329 }
330 if((UserReportFields & USERREPORTFIELDS_IN_CACHE_OUT) != 0) {
331 inperc=(nnbytes) ? incache * 100. / nnbytes : 0.;
332 ouperc=(nnbytes) ? oucache * 100. / nnbytes : 0.;
333 fprintf(fp_ou,"<td class=\"data\">%3.2lf%%</td><td class=\"data\">%3.2lf%%</td>",inperc,ouperc);
334 }
335 if((UserReportFields & USERREPORTFIELDS_USED_TIME) != 0)
336 fprintf(fp_ou,"<td class=\"data\">%s</td>",buildtime(nnelap));
337 if((UserReportFields & USERREPORTFIELDS_MILISEC) != 0)
338 fprintf(fp_ou,"<td class=\"data\">%s</td>",fixnum2(nnelap,1));
339 if((UserReportFields & USERREPORTFIELDS_PTIME) != 0) {
340 perc2=(tnelap) ? nnelap * 100. / tnelap : 0.;
341 fprintf(fp_ou,"<td class=\"data\">%3.2lf%%</td>",perc2);
342 }
343
344 if(strncmp(tmsg,"OK",2) != 0)
345 fprintf(fp_ou,"<td class=\"data\">%s</td>",_("DENIED"));
346
347 fputs("</tr>\n",fp_ou);
348 count++;
349 }
350
351 if(iprel) {
352 if (snprintf(arqip,sizeof(arqip),"%s/%s.ip",tmp,uinfo->filename)>=sizeof(arqip)) {
353 debuga(_("File name too long: %s/%s.ip\n"),tmp,uinfo->filename);
354 exit(EXIT_FAILURE);
355 }
356
357 if ((fp_ip = fopen(arqip, "r")) == 0){
358 debuga(_("(html6) Cannot open file %s\n"),arqip);
359 exit(EXIT_FAILURE);
360 }
361
362 if ((fp_ip2 = MY_FOPEN(tmp2, "a")) == 0){
363 debuga(_("(html7) Cannot open file %s\n"),tmp2);
364 exit(EXIT_FAILURE);
365 }
366
367 if ((line1=longline_create())==NULL) {
368 debuga(_("Not enough memory to read file %s\n"),arqip);
369 exit(EXIT_FAILURE);
370 }
371 while((buf=longline_read(fp_ip,line1))!=NULL) {
372 getword_start(&gwarea,buf);
373 if (getword(user_ip,sizeof(user_ip),&gwarea,'\t')<0) {
374 debuga(_("Maybe you have a broken user IP in your %s file\n"),tmp3);
375 exit(EXIT_FAILURE);
376 }
377 if (getword_ptr(buf,&user_url,&gwarea,'\t')<0) {
378 debuga(_("Maybe you have a broken url in your %s file\n"),tmp3);
379 exit(EXIT_FAILURE);
380 }
381 if (strncmp(user_url,url,strlen(url))!=0) continue;
382 if (getword_skip(15,&gwarea,'\t')<0) {
383 debuga(_("Maybe you have a broken day in your %s file\n"),tmp3);
384 exit(EXIT_FAILURE);
385 }
386 if (getword_skip(15,&gwarea,'\t')<0) {
387 debuga(_("Maybe you have a broken time in your %s file\n"),tmp3);
388 exit(EXIT_FAILURE);
389 }
390 if (getword_atoll(&userbytes,&gwarea,'\t')<0) {
391 debuga(_("Maybe you have a broken size in your %s file\n"),tmp3);
392 exit(EXIT_FAILURE);
393 }
394 if (getword_atoll(&userelap,&gwarea,'\0')<0) {
395 debuga(_("Maybe you have a broken elapsed time in your %s file\n"),tmp3);
396 exit(EXIT_FAILURE);
397 }
398 fprintf(fp_ip2,"%s\t%"PRIu64"\t%"PRIu64"\n",user_ip,(uint64_t)userbytes,(uint64_t)userelap);
399 }
400 longline_destroy(&line1);
401
402 fclose(fp_ip);
403 fclose(fp_ip2);
404
405 sprintf(csort,"sort -n -T \"%s\" -k 1,1 -k 2,2 -o \"%s\" \"%s\"",tmp,tmp3,tmp2);
406 cstatus=system(csort);
407 if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
408 debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus));
409 debuga(_("sort command: %s\n"),csort);
410 exit(EXIT_FAILURE);
411 }
412
413 if ((fp_ip = MY_FOPEN(tmp3, "r")) == 0) {
414 debuga(_("(html8) Cannot open file %s\n"),tmp3);
415 exit(EXIT_FAILURE);
416 }
417
418 olduserip[0]='\0';
419
420 if ((line1=longline_create())==NULL) {
421 debuga(_("Not enough memory to read file %s\n"),arqip);
422 exit(EXIT_FAILURE);
423 }
424 while((buf=longline_read(fp_ip,line1))!=NULL) {
425 getword_start(&gwarea,buf);
426 if (getword(user_ip,sizeof(user_ip),&gwarea,'\t')<0) {
427 debuga(_("Maybe you have a broken user IP in your %s file\n"),tmp3);
428 exit(EXIT_FAILURE);
429 }
430 if (getword_atoll(&userbytes,&gwarea,'\t')<0) {
431 debuga(_("Maybe you have a broken size in your %s file\n"),tmp3);
432 exit(EXIT_FAILURE);
433 }
434 if (getword_atoll(&userelap,&gwarea,'\0')<0) {
435 debuga(_("Maybe you have a broken elapsed time in your %s file\n"),tmp3);
436 exit(EXIT_FAILURE);
437 }
438 if(strcmp(user_ip,olduserip) != 0) {
439 if (olduserip[0]!='\0') {
440 fprintf(fp_ou,"<tr><td></td><td class=\"data\">%s</td>",olduserip);
441 if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0)
442 fputs("<td></td>",fp_ou);
443 if((UserReportFields & USERREPORTFIELDS_BYTES) != 0)
444 fprintf(fp_ou,"<td class=\"data\">%s</td>",fixnum(unbytes,1));
445 if((UserReportFields & USERREPORTFIELDS_SETYB) != 0)
446 fputs("<td></td>",fp_ou);
447 if((UserReportFields & USERREPORTFIELDS_IN_CACHE_OUT) != 0)
448 fputs("</td><td></td><td></td>",fp_ou);
449 if((UserReportFields & USERREPORTFIELDS_USED_TIME) != 0)
450 fprintf(fp_ou,"<td class=\"data\">%s</td>",buildtime(unelap));
451 if((UserReportFields & USERREPORTFIELDS_MILISEC) != 0)
452 fprintf(fp_ou,"<td class=\"data\">%s</td>",fixnum2(unelap,1));
453 fputs("</tr>\n",fp_ou);
454 }
455
456 strcpy(olduserip,user_ip);
457 unacc=0;
458 unbytes=0;
459 unelap=0;
460 }
461
462 unbytes+=userbytes;
463 unelap+=userelap;
464 }
465
466 fclose(fp_ip);
467 longline_destroy(&line1);
468
469 unlink(tmp2);
470 unlink(tmp3);
471
472 if (olduserip[0]!='\0') {
473 fprintf(fp_ou,"<tr><td></td><td class=\"data\">%s</td>",olduserip);
474 if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0)
475 fputs("<td></td>",fp_ou);
476 if((UserReportFields & USERREPORTFIELDS_BYTES) != 0)
477 fprintf(fp_ou,"<td class=\"data\">%s</td>",fixnum(unbytes,1));
478 if((UserReportFields & USERREPORTFIELDS_SETYB) != 0)
479 fputs("<td></td>",fp_ou);
480 if((UserReportFields & USERREPORTFIELDS_IN_CACHE_OUT) != 0)
481 fputs("</td><td></td><td></td>",fp_ou);
482 if((UserReportFields & USERREPORTFIELDS_USED_TIME) != 0)
483 fprintf(fp_ou,"<td class=\"data\">%s</td>",buildtime(unelap));
484 if((UserReportFields & USERREPORTFIELDS_MILISEC) != 0)
485 fprintf(fp_ou,"<td class=\"data\">%s</td>",fixnum2(unelap,1));
486 fputs("</tr>\n",fp_ou);
487 }
488 }
489
490 unacc=0;
491 unbytes=0;
492 unelap=0;
493 }
494
495 fclose(fp_in);
496 longline_destroy(&line);
497
498 if(iprel)
499 unlink(arqip);
500 unlink(arqin);
501
502 if((UserReportFields & USERREPORTFIELDS_TOTAL) != 0) {
503 fprintf(fp_ou,"<tr><th></th><th class=\"header_l\">%s</th>",_("TOTAL"));
504 if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0)
505 fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fixnum(tnacc,1));
506 if((UserReportFields & USERREPORTFIELDS_BYTES) != 0)
507 fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fixnum(tnbytes,1));
508 if((UserReportFields & USERREPORTFIELDS_SETYB) != 0) {
509 perc=(totbytes) ? tnbytes *100. / totbytes :0.;
510 fprintf(fp_ou,"<th class=\"header_r\">%3.2lf%%</th>",perc);
511 }
512 if((UserReportFields & USERREPORTFIELDS_IN_CACHE_OUT) != 0) {
513 inperc=(tnbytes) ? tnincache * 100. / tnbytes : 0.;
514 ouperc=(tnbytes) ? tnoucache * 100. / tnbytes : 0.;
515 fprintf(fp_ou,"<th class=\"header_r\">%3.2lf%%</th><th class=\"header_r\">%3.2lf%%</th>",inperc,ouperc);
516 }
517 if((UserReportFields & USERREPORTFIELDS_USED_TIME) != 0)
518 fprintf(fp_ou,"<th class=\"header_r\">%s</th>",buildtime(tnelap));
519 if((UserReportFields & USERREPORTFIELDS_MILISEC) != 0)
520 fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fixnum2(tnelap,1));
521 if((UserReportFields & USERREPORTFIELDS_PTIME) != 0) {
522 perc2=(totelap) ? tnelap * 100. / totelap : 0.;
523 fprintf(fp_ou,"<th class=\"header_r\">%3.2lf%%</th>",perc2);
524 }
525 fputs("</tr>\n",fp_ou);
526 }
527
528 if(PerUserLimit > 0) {
529 if(tnbytes > (PerUserLimit*1000000)) {
530 limit_flag=0;
531 if(access(PerUserLimitFile, R_OK) == 0) {
532 if((fp_usr = fopen(PerUserLimitFile, "r")) == 0) {
533 debuga(_("(html9) Cannot open file %s\n"),PerUserLimitFile);
534 exit(EXIT_FAILURE);
535 }
536 while(fgets(tmp6,sizeof(tmp6),fp_usr)!=NULL) {
537 fixendofline(tmp6);
538 if(strcmp(tmp6,uinfo->label) == 0) {
539 limit_flag=1;
540 break;
541 }
542 }
543 fclose(fp_usr);
544 }
545
546 if(!limit_flag) {
547 if((fp_usr = fopen(PerUserLimitFile, "a")) == 0) {
548 debuga(_("(html10) Cannot open file %s\n"),PerUserLimitFile);
549 exit(EXIT_FAILURE);
550 }
551 fprintf(fp_usr,"%s\n",uinfo->label);
552 fclose(fp_usr);
553
554 if(debug)
555 debuga(_("User %s limit exceeded (%d MB). Added to file %s\n"),uinfo->label,PerUserLimit,PerUserLimitFile);
556 }
557 }
558 }
559
560 // if(indexonly) {
561 // unlink(arqou);
562 // continue;
563 // }
564
565 if ((ReportType & REPORT_TYPE_TOPUSERS) != 0 && (UserReportFields & USERREPORTFIELDS_AVERAGE) != 0) {
566 totbytes2=totbytes/ntotuser;
567 totelap2=totelap/ntotuser;
568
569 fprintf(fp_ou,"<tr><th></th><th class=\"header_l\">%s</th>",_("AVERAGE"));
570 if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0)
571 fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fixnum(ttnacc/ntotuser,1));
572 if((UserReportFields & USERREPORTFIELDS_BYTES) != 0)
573 fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fixnum(totbytes2,1));
574 fprintf(fp_ou,"<th></th><th></th><th></th>");
575 if((UserReportFields & USERREPORTFIELDS_USED_TIME) != 0)
576 fprintf(fp_ou,"<th class=\"header_r\">%s</th>",buildtime(totelap2));
577 if((UserReportFields & USERREPORTFIELDS_MILISEC) != 0)
578 fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fixnum2(totelap2,1));
579 if((UserReportFields & USERREPORTFIELDS_PTIME) != 0) {
580 perc2 = (totelap) ? totelap2 * 100. / totelap : 0.;
581 fprintf(fp_ou,"<th class=\"header_r\">%3.2lf%%</th>",perc2);
582 }
583 fputs("</tr>\n",fp_ou);
584 }
585
586 fputs("</table></div>\n",fp_ou);
587 if (write_html_trailer(fp_ou)<0)
588 debuga(_("Write error in file %s\n"),arqou);
589 if (fclose(fp_ou)==EOF)
590 debuga(_("Failed to close file %s - %s\n"),arqou,strerror(errno));
591
592 htaccess(uinfo);
593 }
594
595 (void)closedir(dirp);
596 greport_cleanup();
597
598 return;
599 }