]> git.ipfire.org Git - thirdparty/sarg.git/blob - html.c
Merge commit 'f209e4f043007b3bb6'
[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 const char *sort_field;
59 const char *sort_order;
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,tmp);
70 strcat(tmp2,"/sargtmp.unsort");
71
72 strcpy(tmp3,tmp);
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 greport_prepare();
112
113 sort_labels(&sort_field,&sort_order);
114
115 if ((dirp = opendir(tmp)) == NULL) {
116 debuga(_("Failed to open directory %s - %s\n"),tmp,strerror(errno));
117 exit(EXIT_FAILURE);
118 }
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)
123 continue;
124
125 count=1;
126 if (dlen>0) {
127 if (dlen>=sizeof(user)) continue;
128 strncpy(user,direntp->d_name,dlen);
129 user[dlen]=0;
130 } else {
131 user[0]=0;
132 }
133
134 uinfo=userinfo_find_from_file(user);
135 if (!uinfo) {
136 debuga(_("Unknown user ID %s in directory %s\n"),user,tmp);
137 exit(EXIT_FAILURE);
138 }
139 str=strrchr(user,'.');
140 if (str)
141 strcpy(denied_report,str+1);
142 else
143 strcpy(denied_report,user);
144
145 if (snprintf(warea,sizeof(warea),"%s/%s",outdirname,user)>=sizeof(warea)) {
146 debuga(_("Destination directory too long: %s/%s\n"),outdirname,user);
147 exit(EXIT_FAILURE);
148 }
149 mkdir(warea,0755);
150
151 report_day(uinfo);
152 greport_day(uinfo);
153
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);
156 exit(EXIT_FAILURE);
157 }
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);
160 exit(EXIT_FAILURE);
161 }
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);
164 exit(EXIT_FAILURE);
165 }
166 if(access(duser, R_OK) != 0)
167 denied_report[0]='\0';
168
169 if ((fp_in = fopen(arqin, "r")) == 0){
170 debuga(_("(html3) Cannot open file %s\n"),arqin);
171 exit(EXIT_FAILURE);
172 }
173
174 if ((line=longline_create())==NULL) {
175 debuga(_("Not enough memory to read file %s\n"),arqin);
176 exit(EXIT_FAILURE);
177 }
178
179 tnacc=0;
180 tnbytes=0;
181 tnelap=0;
182 tnincache=0;
183 tnoucache=0;
184 while((buf=longline_read(fp_in,line))!=NULL) {
185 getword_start(&gwarea,buf);
186 if (getword_atoll(&ltemp,&gwarea,'\t')<0) {
187 debuga(_("There is a broken number of access in file %s\n"),arqin);
188 exit(EXIT_FAILURE);
189 }
190 tnacc+=ltemp;
191 if (getword_atoll(&ltemp,&gwarea,'\t')<0) {
192 debuga(_("There is a broken downloaded size in file %s\n"),arqin);
193 exit(EXIT_FAILURE);
194 }
195 tnbytes+=ltemp;
196 if (getword_ptr(NULL,NULL,&gwarea,'\t')<0) {
197 debuga(_("There is a broken url in file %s\n"),arqin);
198 exit(EXIT_FAILURE);
199 }
200 if (getword_skip(MAXLEN,&gwarea,'\t')<0) {
201 debuga(_("There is a broken access code in file %s\n"),arqin);
202 exit(EXIT_FAILURE);
203 }
204 if (getword_atoll(&ltemp,&gwarea,'\t')<0) {
205 debuga(_("There is a broken elapsed time in file %s\n"),arqin);
206 exit(EXIT_FAILURE);
207 }
208 tnelap+=ltemp;
209 if (getword_atoll(&ltemp,&gwarea,'\t')<0) {
210 debuga(_("There is a broken in-cache volume in file %s\n"),arqin);
211 exit(EXIT_FAILURE);
212 }
213 tnincache+=ltemp;
214 if (getword_atoll(&ltemp,&gwarea,'\n')<0) {
215 debuga(_("There is a broken out-cache volume in file %s\n"),arqin);
216 exit(EXIT_FAILURE);
217 }
218 tnoucache+=ltemp;
219 }
220
221 rewind(fp_in);
222
223 if ((fp_ou = fopen(arqou, "w")) == 0){
224 debuga(_("(html5) Cannot open file %s\n"),arqou);
225 exit(EXIT_FAILURE);
226 }
227
228 write_html_header(fp_ou,(IndexTree == INDEX_TREE_DATE) ? 4 : 2,_("User report"));
229 fprintf(fp_ou,"<tr><td class=\"header_c\">%s:&nbsp;%s</td></tr>\n",_("Period"),period.html);
230 fprintf(fp_ou,"<tr><td class=\"header_c\">%s:&nbsp;%s</td></tr>\n",_("User"),uinfo->label);
231 fputs("<tr><td class=\"header_c\">",fp_ou);
232 fprintf(fp_ou,_("Sort:&nbsp;%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);
236
237 fputs("<div class=\"report\"><table cellpadding=\"2\" cellspacing=\"1\">\n",fp_ou);
238
239 if(denied_report[0]!='\0') {
240 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"));
241 }
242
243 fprintf(fp_ou,"<tr><th></th><th class=\"header_l\">%s</th>",_("ACCESSED SITE"));
244
245 if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0)
246 fprintf(fp_ou,"<th class=\"header_l\">%s</th>",_("CONNECT"));
247 if((UserReportFields & USERREPORTFIELDS_BYTES) != 0)
248 fprintf(fp_ou,"<th class=\"header_l\">%s</th>",_("BYTES"));
249 if((UserReportFields & USERREPORTFIELDS_SETYB) != 0)
250 fprintf(fp_ou,"<th class=\"header_l\">%%%s</th>",_("BYTES"));
251 if((UserReportFields & USERREPORTFIELDS_IN_CACHE_OUT) != 0)
252 fprintf(fp_ou,"<th class=\"header_c\" colspan=\"2\">%s</th>",_("IN-CACHE-OUT"));
253 if((UserReportFields & USERREPORTFIELDS_USED_TIME) != 0)
254 fprintf(fp_ou,"<th class=\"header_l\">%s</th>",_("ELAPSED TIME"));
255 if((UserReportFields & USERREPORTFIELDS_MILISEC) != 0)
256 fprintf(fp_ou,"<th class=\"header_l\">%s</th>",_("MILLISEC"));
257 if((UserReportFields & USERREPORTFIELDS_PTIME) != 0)
258 fprintf(fp_ou,"<th class=\"header_l\">%%%s</th>",_("TIME"));
259
260 fputs("</tr>\n",fp_ou);
261
262 if(debug) {
263 debuga(_("Making report: %s\n"),uinfo->id);
264 }
265
266 while((buf=longline_read(fp_in,line))!=NULL) {
267 getword_start(&gwarea,buf);
268 if (getword_atoll(&twork,&gwarea,'\t')<0) {
269 debuga(_("There is a broken number of access in file %s\n"),arqin);
270 exit(EXIT_FAILURE);
271 }
272 if (getword_atoll(&nnbytes,&gwarea,'\t')<0) {
273 debuga(_("There is a broken number of bytes in file %s\n"),arqin);
274 exit(EXIT_FAILURE);
275 }
276 if (getword_ptr(buf,&url,&gwarea,'\t')<0) {
277 debuga(_("There is a broken url in file %s\n"),arqin);
278 exit(EXIT_FAILURE);
279 }
280 if (getword(tmsg,sizeof(tmsg),&gwarea,'\t')<0) {
281 debuga(_("There is a broken access code in file %s\n"),arqin);
282 exit(EXIT_FAILURE);
283 }
284 if (getword_atoll(&nnelap,&gwarea,'\t')<0) {
285 debuga(_("There is a broken elapsed time in file %s\n"),arqin);
286 exit(EXIT_FAILURE);
287 }
288 if (getword_atoll(&incache,&gwarea,'\t')<0) {
289 debuga(_("There is a broken in cache column in file %s\n"),arqin);
290 exit(EXIT_FAILURE);
291 }
292 if (getword_atoll(&oucache,&gwarea,'\n')<0) {
293 debuga(_("There is a broken out of cache column in file %s (%d)\n"),arqin,__LINE__);
294 exit(EXIT_FAILURE);
295 }
296
297 if(UserReportLimit<=0 || count<=UserReportLimit) {
298 fputs("<tr>",fp_ou);
299
300 if(IndexTree == INDEX_TREE_DATE)
301 sprintf(tmp6,"../%s",ImageFile);
302 else
303 strcpy(tmp6,"../../images");
304
305 if((ReportType & REPORT_TYPE_SITE_USER_TIME_DATE) != 0) {
306 url_to_file(url,siteind,sizeof(siteind));
307 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"));
308 } else {
309 fprintf(fp_ou,"<td class=\"data\"></td>");
310 }
311
312 if(Privacy)
313 fprintf(fp_ou,"<td class=\"data2\"><span style=\"color:%s;\">%s</span></td>",PrivacyStringColor,PrivacyString);
314 else {
315 fputs("<td class=\"data2\">",fp_ou);
316 if(BlockIt[0]!='\0') {
317 fprintf(fp_ou,"<a href=\"%s%s?url=",wwwDocumentRoot,BlockIt);
318 output_html_url(fp_ou,url);
319 fprintf(fp_ou,"\"><img src=\"%s/sarg-squidguard-block.png\"></a>&nbsp;",tmp6);
320 }
321 fputs("<a href=\"http://",fp_ou);
322 output_html_url(fp_ou,url);
323 fputs("\">",fp_ou);
324 output_html_string(fp_ou,url,100);
325 fputs("</a></td>",fp_ou);
326 }
327
328 if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0)
329 fprintf(fp_ou,"<td class=\"data\">%s</td>",fixnum(twork,1));
330 if((UserReportFields & USERREPORTFIELDS_BYTES) != 0)
331 fprintf(fp_ou,"<td class=\"data\">%s</td>",fixnum(nnbytes,1));
332 if((UserReportFields & USERREPORTFIELDS_SETYB) != 0) {
333 perc=(tnbytes) ? nnbytes * 100. / tnbytes : 0.;
334 fprintf(fp_ou,"<td class=\"data\">%3.2lf%%</td>",perc);
335 }
336 if((UserReportFields & USERREPORTFIELDS_IN_CACHE_OUT) != 0) {
337 inperc=(nnbytes) ? incache * 100. / nnbytes : 0.;
338 ouperc=(nnbytes) ? oucache * 100. / nnbytes : 0.;
339 fprintf(fp_ou,"<td class=\"data\">%3.2lf%%</td><td class=\"data\">%3.2lf%%</td>",inperc,ouperc);
340 }
341 if((UserReportFields & USERREPORTFIELDS_USED_TIME) != 0)
342 fprintf(fp_ou,"<td class=\"data\">%s</td>",buildtime(nnelap));
343 if((UserReportFields & USERREPORTFIELDS_MILISEC) != 0)
344 fprintf(fp_ou,"<td class=\"data\">%s</td>",fixnum2(nnelap,1));
345 if((UserReportFields & USERREPORTFIELDS_PTIME) != 0) {
346 perc2=(tnelap) ? nnelap * 100. / tnelap : 0.;
347 fprintf(fp_ou,"<td class=\"data\">%3.2lf%%</td>",perc2);
348 }
349
350 if(strncmp(tmsg,"OK",2) != 0)
351 fprintf(fp_ou,"<td class=\"data\">%s</td>",_("DENIED"));
352
353 fputs("</tr>\n",fp_ou);
354 count++;
355 }
356
357 if(iprel) {
358 if (snprintf(arqip,sizeof(arqip),"%s/%s.ip",tmp,uinfo->filename)>=sizeof(arqip)) {
359 debuga(_("File name too long: %s/%s.ip\n"),tmp,uinfo->filename);
360 exit(EXIT_FAILURE);
361 }
362
363 if ((fp_ip = fopen(arqip, "r")) == 0){
364 debuga(_("(html6) Cannot open file %s\n"),arqip);
365 exit(EXIT_FAILURE);
366 }
367
368 if ((fp_ip2 = MY_FOPEN(tmp2, "a")) == 0){
369 debuga(_("(html7) Cannot open file %s\n"),tmp2);
370 exit(EXIT_FAILURE);
371 }
372
373 if ((line1=longline_create())==NULL) {
374 debuga(_("Not enough memory to read file %s\n"),arqip);
375 exit(EXIT_FAILURE);
376 }
377 while((buf=longline_read(fp_ip,line1))!=NULL) {
378 getword_start(&gwarea,buf);
379 if (getword(user_ip,sizeof(user_ip),&gwarea,'\t')<0) {
380 debuga(_("Maybe you have a broken user IP in your %s file\n"),tmp3);
381 exit(EXIT_FAILURE);
382 }
383 if (getword_ptr(buf,&user_url,&gwarea,'\t')<0) {
384 debuga(_("Maybe you have a broken url in your %s file\n"),tmp3);
385 exit(EXIT_FAILURE);
386 }
387 if (strncmp(user_url,url,strlen(url))!=0) continue;
388 if (getword_skip(15,&gwarea,'\t')<0) {
389 debuga(_("Maybe you have a broken day in your %s file\n"),tmp3);
390 exit(EXIT_FAILURE);
391 }
392 if (getword_skip(15,&gwarea,'\t')<0) {
393 debuga(_("Maybe you have a broken time in your %s file\n"),tmp3);
394 exit(EXIT_FAILURE);
395 }
396 if (getword_atoll(&userbytes,&gwarea,'\t')<0) {
397 debuga(_("Maybe you have a broken size in your %s file\n"),tmp3);
398 exit(EXIT_FAILURE);
399 }
400 if (getword_atoll(&userelap,&gwarea,'\0')<0) {
401 debuga(_("Maybe you have a broken elapsed time in your %s file\n"),tmp3);
402 exit(EXIT_FAILURE);
403 }
404 fprintf(fp_ip2,"%s\t%"PRIu64"\t%"PRIu64"\n",user_ip,(uint64_t)userbytes,(uint64_t)userelap);
405 }
406 longline_destroy(&line1);
407
408 fclose(fp_ip);
409 fclose(fp_ip2);
410
411 sprintf(csort,"sort -n -T \"%s\" -k 1,1 -k 5,5 -o \"%s\" \"%s\"",tmp,tmp3,tmp2);
412 cstatus=system(csort);
413 if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
414 debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus));
415 debuga(_("sort command: %s\n"),csort);
416 exit(EXIT_FAILURE);
417 }
418
419 if ((fp_ip = MY_FOPEN(tmp3, "r")) == 0) {
420 debuga(_("(html8) Cannot open file %s\n"),tmp3);
421 exit(EXIT_FAILURE);
422 }
423
424 olduserip[0]='\0';
425
426 if ((line1=longline_create())==NULL) {
427 debuga(_("Not enough memory to read file %s\n"),arqip);
428 exit(EXIT_FAILURE);
429 }
430 while((buf=longline_read(fp_ip,line1))!=NULL) {
431 getword_start(&gwarea,buf);
432 if (getword(user_ip,sizeof(user_ip),&gwarea,'\t')<0) {
433 debuga(_("Maybe you have a broken user IP in your %s file\n"),tmp3);
434 exit(EXIT_FAILURE);
435 }
436 if (getword_atoll(&userbytes,&gwarea,'\t')<0) {
437 debuga(_("Maybe you have a broken size in your %s file\n"),tmp3);
438 exit(EXIT_FAILURE);
439 }
440 if (getword_atoll(&userelap,&gwarea,'\0')<0) {
441 debuga(_("Maybe you have a broken elapsed time in your %s file\n"),tmp3);
442 exit(EXIT_FAILURE);
443 }
444 if(strcmp(user_ip,olduserip) != 0) {
445 if (olduserip[0]!='\0') {
446 fprintf(fp_ou,"<tr><td></td><td class=\"data\">%s</td>",olduserip);
447 if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0)
448 fputs("<td></td>",fp_ou);
449 if((UserReportFields & USERREPORTFIELDS_BYTES) != 0)
450 fprintf(fp_ou,"<td class=\"data\">%s</td>",fixnum(unbytes,1));
451 if((UserReportFields & USERREPORTFIELDS_SETYB) != 0)
452 fputs("<td></td>",fp_ou);
453 if((UserReportFields & USERREPORTFIELDS_IN_CACHE_OUT) != 0)
454 fputs("</td><td></td><td></td>",fp_ou);
455 if((UserReportFields & USERREPORTFIELDS_USED_TIME) != 0)
456 fprintf(fp_ou,"<td class=\"data\">%s</td>",buildtime(unelap));
457 if((UserReportFields & USERREPORTFIELDS_MILISEC) != 0)
458 fprintf(fp_ou,"<td class=\"data\">%s</td>",fixnum2(unelap,1));
459 fputs("</tr>\n",fp_ou);
460 }
461
462 strcpy(olduserip,user_ip);
463 unacc=0;
464 unbytes=0;
465 unelap=0;
466 }
467
468 unbytes+=userbytes;
469 unelap+=userelap;
470 }
471
472 fclose(fp_ip);
473 longline_destroy(&line1);
474
475 unlink(tmp2);
476 unlink(tmp3);
477
478 if (olduserip[0]!='\0') {
479 fprintf(fp_ou,"<tr><td></td><td class=\"data\">%s</td>",olduserip);
480 if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0)
481 fputs("<td></td>",fp_ou);
482 if((UserReportFields & USERREPORTFIELDS_BYTES) != 0)
483 fprintf(fp_ou,"<td class=\"data\">%s</td>",fixnum(unbytes,1));
484 if((UserReportFields & USERREPORTFIELDS_SETYB) != 0)
485 fputs("<td></td>",fp_ou);
486 if((UserReportFields & USERREPORTFIELDS_IN_CACHE_OUT) != 0)
487 fputs("</td><td></td><td></td>",fp_ou);
488 if((UserReportFields & USERREPORTFIELDS_USED_TIME) != 0)
489 fprintf(fp_ou,"<td class=\"data\">%s</td>",buildtime(unelap));
490 if((UserReportFields & USERREPORTFIELDS_MILISEC) != 0)
491 fprintf(fp_ou,"<td class=\"data\">%s</td>",fixnum2(unelap,1));
492 fputs("</tr>\n",fp_ou);
493 }
494 }
495
496 unacc=0;
497 unbytes=0;
498 unelap=0;
499 }
500
501 fclose(fp_in);
502 longline_destroy(&line);
503
504 if(iprel)
505 unlink(arqip);
506 unlink(arqin);
507
508 if((UserReportFields & USERREPORTFIELDS_TOTAL) != 0) {
509 fprintf(fp_ou,"<tr><th></th><th class=\"header_l\">%s</th>",_("TOTAL"));
510 if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0)
511 fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fixnum(tnacc,1));
512 if((UserReportFields & USERREPORTFIELDS_BYTES) != 0)
513 fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fixnum(tnbytes,1));
514 if((UserReportFields & USERREPORTFIELDS_SETYB) != 0) {
515 perc=(totbytes) ? tnbytes *100. / totbytes :0.;
516 fprintf(fp_ou,"<th class=\"header_r\">%3.2lf%%</th>",perc);
517 }
518 if((UserReportFields & USERREPORTFIELDS_IN_CACHE_OUT) != 0) {
519 inperc=(tnbytes) ? tnincache * 100. / tnbytes : 0.;
520 ouperc=(tnbytes) ? tnoucache * 100. / tnbytes : 0.;
521 fprintf(fp_ou,"<th class=\"header_r\">%3.2lf%%</th><th class=\"header_r\">%3.2lf%%</th>",inperc,ouperc);
522 }
523 if((UserReportFields & USERREPORTFIELDS_USED_TIME) != 0)
524 fprintf(fp_ou,"<th class=\"header_r\">%s</th>",buildtime(tnelap));
525 if((UserReportFields & USERREPORTFIELDS_MILISEC) != 0)
526 fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fixnum2(tnelap,1));
527 if((UserReportFields & USERREPORTFIELDS_PTIME) != 0) {
528 perc2=(totelap) ? tnelap * 100. / totelap : 0.;
529 fprintf(fp_ou,"<th class=\"header_r\">%3.2lf%%</th>",perc2);
530 }
531 fputs("</tr>\n",fp_ou);
532 }
533
534 if(PerUserLimit > 0) {
535 if(tnbytes > (PerUserLimit*1000000)) {
536 limit_flag=0;
537 if(access(PerUserLimitFile, R_OK) == 0) {
538 if((fp_usr = fopen(PerUserLimitFile, "r")) == 0) {
539 debuga(_("(html9) Cannot open file %s\n"),PerUserLimitFile);
540 exit(EXIT_FAILURE);
541 }
542 while(fgets(tmp6,sizeof(tmp6),fp_usr)!=NULL) {
543 fixendofline(tmp6);
544 if(strcmp(tmp6,uinfo->label) == 0) {
545 limit_flag=1;
546 break;
547 }
548 }
549 fclose(fp_usr);
550 }
551
552 if(!limit_flag) {
553 if((fp_usr = fopen(PerUserLimitFile, "a")) == 0) {
554 debuga(_("(html10) Cannot open file %s\n"),PerUserLimitFile);
555 exit(EXIT_FAILURE);
556 }
557 fprintf(fp_usr,"%s\n",uinfo->label);
558 fclose(fp_usr);
559
560 if(debug)
561 debuga(_("User %s limit exceeded (%d MB). Added to file %s\n"),uinfo->label,PerUserLimit,PerUserLimitFile);
562 }
563 }
564 }
565
566 // if(indexonly) {
567 // unlink(arqou);
568 // continue;
569 // }
570
571 if ((ReportType & REPORT_TYPE_TOPUSERS) != 0 && (UserReportFields & USERREPORTFIELDS_AVERAGE) != 0) {
572 totbytes2=totbytes/ntotuser;
573 totelap2=totelap/ntotuser;
574
575 fprintf(fp_ou,"<tr><th></th><th class=\"header_l\">%s</th>",_("AVERAGE"));
576 if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0)
577 fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fixnum(ttnacc/ntotuser,1));
578 if((UserReportFields & USERREPORTFIELDS_BYTES) != 0)
579 fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fixnum(totbytes2,1));
580 fprintf(fp_ou,"<th></th><th></th><th></th>");
581 if((UserReportFields & USERREPORTFIELDS_USED_TIME) != 0)
582 fprintf(fp_ou,"<th class=\"header_r\">%s</th>",buildtime(totelap2));
583 if((UserReportFields & USERREPORTFIELDS_MILISEC) != 0)
584 fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fixnum2(totelap2,1));
585 if((UserReportFields & USERREPORTFIELDS_PTIME) != 0) {
586 perc2 = (totelap) ? totelap2 * 100. / totelap : 0.;
587 fprintf(fp_ou,"<th class=\"header_r\">%3.2lf%%</th>",perc2);
588 }
589 fputs("</tr>\n",fp_ou);
590 }
591
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));
597
598 htaccess(uinfo);
599 }
600
601 (void)closedir(dirp);
602 greport_cleanup();
603
604 return;
605 }