]> git.ipfire.org Git - thirdparty/sarg.git/blob - html.c
Update the Russian translation.
[thirdparty/sarg.git] / html.c
1 /*
2 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
3 * 1998, 2013
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 extern struct globalstatstruct globstat;
31
32 void htmlrel(void)
33 {
34 FILE *fp_in, *fp_ou, *fp_ip, *fp_ip2, *fp_usr;
35
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], arqip[MAXLEN];
44 char *url, tmsg[50], csort[MAXLEN];
45 char duser[MAXLEN];
46 char user_ip[MAXLEN], olduserip[MAXLEN], tmp2[MAXLEN], tmp3[MAXLEN];
47 char warea[MAXLEN];
48 char tmp6[MAXLEN];
49 char *user_url;
50 long long int tnacc=0, ttnacc=0;
51 double perc=0, perc2=0, ouperc=0, inperc=0;
52 int count;
53 int cstatus;
54 bool have_denied_report;
55 const char *sort_field;
56 const char *sort_order;
57 char siteind[MAX_TRUNCATED_URL];
58 struct getwordstruct gwarea;
59 longline line,line1;
60 const struct userinfostruct *uinfo;
61 userscan uscan;
62
63 if (snprintf(tmp2,sizeof(tmp2),"%s/sargtmp.int_unsort",tmp)>=sizeof(tmp2)) {
64 debuga(_("Path too long: "));
65 debuga_more("%s/sargtmp.int_unsort\n",tmp);
66 exit(EXIT_FAILURE);
67 }
68
69 if (snprintf(tmp3,sizeof(tmp3),"%s/sargtmp.int_log",tmp)>=sizeof(tmp3)) {
70 debuga(_("Path too long: "));
71 debuga_more("%s/sargtmp.int_log\n",tmp);
72 exit(EXIT_FAILURE);
73 }
74
75 tnacc=globstat.nacc;
76 totbytes=globstat.nbytes;
77 totelap=globstat.elap;
78 ntotuser=globstat.totuser;
79
80 sort_labels(&sort_field,&sort_order);
81
82 uscan=userinfo_startscan();
83 if (uscan == NULL) {
84 debuga(_("Cannot enumerate the user list\n"));
85 exit(EXIT_FAILURE);
86 }
87 while ( (uinfo = userinfo_advancescan(uscan)) != NULL ) {
88 if (snprintf(warea,sizeof(warea),"%s/%s",outdirname,uinfo->filename)>=sizeof(warea)) {
89 debuga(_("Destination directory too long: "));
90 debuga_more("%s/%s\n",outdirname,uinfo->filename);
91 exit(EXIT_FAILURE);
92 }
93 if (!uinfo->topuser) {
94 //! \todo Instead of deleting the supernumerary directories, don't create them in the first place.
95 unlinkdir(warea,0);
96 continue;
97 }
98
99 if (access(warea, R_OK) != 0) {
100 if (mkdir(warea,0755)) {
101 debuga(_("Cannot create directory \"%s\": %s\n"),warea,strerror(errno));
102 exit(EXIT_FAILURE);
103 }
104 }
105 tmpsort(uinfo);
106
107 if (snprintf(arqin,sizeof(arqin),"%s/htmlrel.txt",tmp)>=sizeof(arqin)) {
108 debuga(_("Path too long: "));
109 debuga_more("%s/htmlrel.txt\n",tmp);
110 exit(EXIT_FAILURE);
111 }
112 if ((fp_in = fopen(arqin, "r")) == 0){
113 if (uinfo->no_report) continue;
114 debugapos("html3",_("Cannot open file \"%s\": %s\n"),arqin,strerror(errno));
115 exit(EXIT_FAILURE);
116 }
117
118 if (snprintf(arqou,sizeof(arqou),"%s/%s/%s.html",outdirname,uinfo->filename,uinfo->filename)>=sizeof(arqou)) {
119 debuga(_("Path too long: "));
120 debuga_more("%s/%s/%s.html\n",outdirname,uinfo->filename,uinfo->filename);
121 exit(EXIT_FAILURE);
122 }
123 if (snprintf(duser,sizeof(duser),"%s/denied_%s.html",outdirname,uinfo->filename)>=sizeof(duser)) {
124 debuga(_("Path too long: "));
125 debuga_more("%s/denied_%s.html\n",outdirname,uinfo->filename);
126 exit(EXIT_FAILURE);
127 }
128 if(access(duser, R_OK) != 0)
129 have_denied_report=false;
130 else
131 have_denied_report=true;
132
133 if ((line=longline_create())==NULL) {
134 debuga(_("Not enough memory to read file \"%s\"\n"),arqin);
135 exit(EXIT_FAILURE);
136 }
137
138 tnacc=0;
139 tnbytes=0;
140 tnelap=0;
141 tnincache=0;
142 tnoucache=0;
143 while((buf=longline_read(fp_in,line))!=NULL) {
144 getword_start(&gwarea,buf);
145 if (getword_atoll(&ltemp,&gwarea,'\t')<0) {
146 debuga(_("Invalid number of accesses in file \"%s\"\n"),arqin);
147 exit(EXIT_FAILURE);
148 }
149 tnacc+=ltemp;
150 if (getword_atoll(&ltemp,&gwarea,'\t')<0) {
151 debuga(_("Invalid download size in file \"%s\"\n"),arqin);
152 exit(EXIT_FAILURE);
153 }
154 tnbytes+=ltemp;
155 if (getword_ptr(NULL,NULL,&gwarea,'\t')<0) {
156 debuga(_("Invalid url in file \"%s\"\n"),arqin);
157 exit(EXIT_FAILURE);
158 }
159 if (getword_skip(MAXLEN,&gwarea,'\t')<0) {
160 debuga(_("Invalid access code in file \"%s\"\n"),arqin);
161 exit(EXIT_FAILURE);
162 }
163 if (getword_atoll(&ltemp,&gwarea,'\t')<0) {
164 debuga(_("Invalid elapsed time in file \"%s\"\n"),arqin);
165 exit(EXIT_FAILURE);
166 }
167 tnelap+=ltemp;
168 if (getword_atoll(&ltemp,&gwarea,'\t')<0) {
169 debuga(_("Invalid in-cache volume in file \"%s\"\n"),arqin);
170 exit(EXIT_FAILURE);
171 }
172 tnincache+=ltemp;
173 if (getword_atoll(&ltemp,&gwarea,'\n')<0) {
174 debuga(_("Invalid out-of-cache volume in file \"%s\"\n"),arqin);
175 exit(EXIT_FAILURE);
176 }
177 tnoucache+=ltemp;
178 }
179
180 rewind(fp_in);
181
182 if ((fp_ou = fopen(arqou, "w")) == 0){
183 debugapos("html5",_("Cannot open file \"%s\": %s\n"),arqou,strerror(errno));
184 exit(EXIT_FAILURE);
185 }
186
187 write_html_header(fp_ou,(IndexTree == INDEX_TREE_DATE) ? 4 : 2,_("User report"),HTML_JS_SORTTABLE);
188 fprintf(fp_ou,"<tr><td class=\"header_c\">%s:&nbsp;%s</td></tr>\n",_("Period"),period.html);
189 fprintf(fp_ou,"<tr><td class=\"header_c\">%s:&nbsp;%s</td></tr>\n",_("User"),uinfo->label);
190 fputs("<tr><td class=\"header_c\">",fp_ou);
191 fprintf(fp_ou,_("Sort:&nbsp;%s, %s"),sort_field,sort_order);
192 fputs("</td></tr>\n",fp_ou);
193 fprintf(fp_ou,"<tr><th class=\"header_c\">%s</th></tr>\n",_("User report"));
194 close_html_header(fp_ou);
195
196 if (have_denied_report) {
197 fputs("<div class=\"report\"><table cellpadding=\"1\" cellspacing=\"2\">\n",fp_ou);
198 fprintf(fp_ou,"<tr><td class=\"header_l\" colspan=\"11\"><a href=\"denied_%s.html\">%s</a></td></tr>\n",uinfo->filename,_("SmartFilter report"));
199 fputs("<tr><td></td></tr>\n</table></div>\n",fp_ou);
200 }
201
202 fputs("<div class=\"report\"><table cellpadding=\"2\" cellspacing=\"1\"",fp_ou);
203 if (SortTableJs[0]) fputs(" class=\"sortable\"",fp_ou);
204 fputs(">\n",fp_ou);
205
206 fputs("<thead><tr><th class=\"sorttable_nosort\"></th><th class=\"header_l",fp_ou);
207 if (SortTableJs[0]) fputs(" sorttable_alpha",fp_ou);
208 fprintf(fp_ou,"\">%s</th>",_("ACCESSED SITE"));
209
210 if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0)
211 fprintf(fp_ou,"<th class=\"header_l\">%s</th>",_("CONNECT"));
212 if((UserReportFields & USERREPORTFIELDS_BYTES) != 0)
213 fprintf(fp_ou,"<th class=\"header_l\">%s</th>",_("BYTES"));
214 if((UserReportFields & USERREPORTFIELDS_SETYB) != 0)
215 fprintf(fp_ou,"<th class=\"header_l\">%%%s</th>",_("BYTES"));
216 if((UserReportFields & USERREPORTFIELDS_IN_CACHE_OUT) != 0)
217 fprintf(fp_ou,"<th class=\"header_c\" colspan=\"2\">%s</th><th style=\"display:none;\"></th>",_("IN-CACHE-OUT"));
218 if((UserReportFields & USERREPORTFIELDS_USED_TIME) != 0)
219 fprintf(fp_ou,"<th class=\"header_l\">%s</th>",_("ELAPSED TIME"));
220 if((UserReportFields & USERREPORTFIELDS_MILISEC) != 0)
221 fprintf(fp_ou,"<th class=\"header_l\">%s</th>",_("MILLISEC"));
222 if((UserReportFields & USERREPORTFIELDS_PTIME) != 0)
223 fprintf(fp_ou,"<th class=\"header_l\">%%%s</th>",_("TIME"));
224
225 fputs("</tr></thead>\n",fp_ou);
226
227 if(debug) {
228 debuga(_("Making report %s\n"),uinfo->id);
229 }
230 count=0;
231 arqip[0]='\0';
232
233 while((buf=longline_read(fp_in,line))!=NULL) {
234 getword_start(&gwarea,buf);
235 if (getword_atoll(&twork,&gwarea,'\t')<0) {
236 debuga(_("Invalid number of accesses in file \"%s\"\n"),arqin);
237 exit(EXIT_FAILURE);
238 }
239 if (getword_atoll(&nnbytes,&gwarea,'\t')<0) {
240 debuga(_("Invalid number of bytes in file \"%s\"\n"),arqin);
241 exit(EXIT_FAILURE);
242 }
243 if (getword_ptr(buf,&url,&gwarea,'\t')<0) {
244 debuga(_("Invalid url in file \"%s\"\n"),arqin);
245 exit(EXIT_FAILURE);
246 }
247 if (getword(tmsg,sizeof(tmsg),&gwarea,'\t')<0) {
248 debuga(_("Invalid access code in file \"%s\"\n"),arqin);
249 exit(EXIT_FAILURE);
250 }
251 if (getword_atoll(&nnelap,&gwarea,'\t')<0) {
252 debuga(_("Invalid elapsed time in file \"%s\"\n"),arqin);
253 exit(EXIT_FAILURE);
254 }
255 if (getword_atoll(&incache,&gwarea,'\t')<0) {
256 debuga(_("Invalid in-cache column in file \"%s\"\n"),arqin);
257 exit(EXIT_FAILURE);
258 }
259 if (getword_atoll(&oucache,&gwarea,'\n')<0) {
260 debuga(_("Invalid out-of-cache column in file \"%s\"\n"),arqin);
261 exit(EXIT_FAILURE);
262 }
263
264 if(UserReportLimit<=0 || count<=UserReportLimit) {
265 fputs("<tr>",fp_ou);
266
267 if(IndexTree == INDEX_TREE_DATE)
268 sprintf(tmp6,"../%s",ImageFile);
269 else
270 strcpy(tmp6,"../../images");
271
272 if((ReportType & REPORT_TYPE_SITE_USER_TIME_DATE) != 0) {
273 url_to_file(url,siteind,sizeof(siteind));
274 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"));
275 } else {
276 fprintf(fp_ou,"<td class=\"data\"></td>");
277 }
278
279 if(Privacy)
280 fprintf(fp_ou,"<td class=\"data2\"><span style=\"color:%s;\">%s</span></td>",PrivacyStringColor,PrivacyString);
281 else {
282 fputs("<td class=\"data2\">",fp_ou);
283 if(BlockIt[0]!='\0' && url[0]!=ALIAS_PREFIX) {
284 fprintf(fp_ou,"<a href=\"%s%s?url=",wwwDocumentRoot,BlockIt);
285 output_html_url(fp_ou,url);
286 fprintf(fp_ou,"\"><img src=\"%s/sarg-squidguard-block.png\"></a>&nbsp;",tmp6);
287 }
288 output_html_link(fp_ou,url,100);
289 fputs("</td>",fp_ou);
290 }
291
292 if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0) {
293 fputs("<td class=\"data\"",fp_ou);
294 if (SortTableJs[0]) fprintf(fp_ou," sorttable_customkey=\"%"PRId64"\"",(int64_t)twork);
295 fprintf(fp_ou,">%s</td>",fixnum(twork,1));
296 }
297 if((UserReportFields & USERREPORTFIELDS_BYTES) != 0) {
298 fputs("<td class=\"data\"",fp_ou);
299 if (SortTableJs[0]) fprintf(fp_ou," sorttable_customkey=\"%"PRId64"\"",(int64_t)nnbytes);
300 fprintf(fp_ou,">%s</td>",fixnum(nnbytes,1));
301 }
302 if((UserReportFields & USERREPORTFIELDS_SETYB) != 0) {
303 perc=(tnbytes) ? nnbytes * 100. / tnbytes : 0.;
304 fprintf(fp_ou,"<td class=\"data\">%3.2lf%%</td>",perc);
305 }
306 if((UserReportFields & USERREPORTFIELDS_IN_CACHE_OUT) != 0) {
307 inperc=(nnbytes) ? incache * 100. / nnbytes : 0.;
308 ouperc=(nnbytes) ? oucache * 100. / nnbytes : 0.;
309 fprintf(fp_ou,"<td class=\"data\">%3.2lf%%</td><td class=\"data\">%3.2lf%%</td>",inperc,ouperc);
310 }
311 if((UserReportFields & USERREPORTFIELDS_USED_TIME) != 0) {
312 fputs("<td class=\"data\"",fp_ou);
313 if (SortTableJs[0]) fprintf(fp_ou," sorttable_customkey=\"%"PRId64"\"",(int64_t)nnelap);
314 fprintf(fp_ou,">%s</td>",buildtime(nnelap));
315 }
316 if((UserReportFields & USERREPORTFIELDS_MILISEC) != 0) {
317 fputs("<td class=\"data\"",fp_ou);
318 if (SortTableJs[0]) fprintf(fp_ou," sorttable_customkey=\"%"PRId64"\"",(int64_t)nnelap);
319 fprintf(fp_ou,">%s</td>",fixnum2(nnelap,1));
320 }
321 if((UserReportFields & USERREPORTFIELDS_PTIME) != 0) {
322 perc2=(tnelap) ? nnelap * 100. / tnelap : 0.;
323 fprintf(fp_ou,"<td class=\"data\">%3.2lf%%</td>",perc2);
324 }
325
326 if(strncmp(tmsg,"OK",2) != 0)
327 fprintf(fp_ou,"<td class=\"data\">%s</td>",_("DENIED"));
328
329 fputs("</tr>\n",fp_ou);
330 count++;
331 } else if ((ReportType & REPORT_TYPE_SITE_USER_TIME_DATE) != 0) {
332 url_to_file(url,siteind,sizeof(siteind));
333 snprintf(warea,sizeof(warea),"%s/%s/tt%s-%s.html",outdirname,uinfo->filename,uinfo->filename,siteind);
334 if (unlink(warea)!=0) {
335 debuga(_("Cannot delete \"%s\": %s\n"),warea,strerror(errno));
336 }
337 }
338
339 if(iprel) {
340 if (snprintf(arqip,sizeof(arqip),"%s/%s.ip",tmp,uinfo->filename)>=sizeof(arqip)) {
341 debuga(_("Path too long: "));
342 debuga_more("%s/%s.ip\n",tmp,uinfo->filename);
343 exit(EXIT_FAILURE);
344 }
345
346 if ((fp_ip = fopen(arqip, "r")) == 0){
347 debugapos("html6",_("Cannot open file \"%s\": %s\n"),arqip,strerror(errno));
348 exit(EXIT_FAILURE);
349 }
350
351 if ((fp_ip2 = MY_FOPEN(tmp2, "a")) == 0){
352 debugapos("html7",_("Cannot open file \"%s\": %s\n"),tmp2,strerror(errno));
353 exit(EXIT_FAILURE);
354 }
355
356 if ((line1=longline_create())==NULL) {
357 debuga(_("Not enough memory to read file \"%s\"\n"),arqip);
358 exit(EXIT_FAILURE);
359 }
360 while((buf=longline_read(fp_ip,line1))!=NULL) {
361 getword_start(&gwarea,buf);
362 if (getword(user_ip,sizeof(user_ip),&gwarea,'\t')<0) {
363 debuga(_("Invalid user IP in file \"%s\"\n"),tmp3);
364 exit(EXIT_FAILURE);
365 }
366 if (getword_ptr(buf,&user_url,&gwarea,'\t')<0) {
367 debuga(_("Invalid url in file \"%s\"\n"),tmp3);
368 exit(EXIT_FAILURE);
369 }
370 if (strncmp(user_url,url,strlen(url))!=0) continue;
371 if (getword_skip(15,&gwarea,'\t')<0) {
372 debuga(_("Invalid day in file \"%s\"\n"),tmp3);
373 exit(EXIT_FAILURE);
374 }
375 if (getword_skip(15,&gwarea,'\t')<0) {
376 debuga(_("Invalid time in file \"%s\"\n"),tmp3);
377 exit(EXIT_FAILURE);
378 }
379 if (getword_atoll(&userbytes,&gwarea,'\t')<0) {
380 debuga(_("Invalid size in file \"%s\"\n"),tmp3);
381 exit(EXIT_FAILURE);
382 }
383 if (getword_atoll(&userelap,&gwarea,'\0')<0) {
384 debuga(_("Invalid elapsed time in file \"%s\"\n"),tmp3);
385 exit(EXIT_FAILURE);
386 }
387 fprintf(fp_ip2,"%s\t%"PRIu64"\t%"PRIu64"\n",user_ip,(uint64_t)userbytes,(uint64_t)userelap);
388 }
389 longline_destroy(&line1);
390
391 fclose(fp_ip);
392 fclose(fp_ip2);
393
394 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)) {
395 debuga(_("Command too long: "));
396 debuga_more("sort -n -t \"\t\" -T \"%s\" -k 1,1 -k 2,2 -o \"%s\" \"%s\"",tmp,tmp3,tmp2);
397 exit(EXIT_FAILURE);
398 }
399 cstatus=system(csort);
400 if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
401 debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus));
402 debuga(_("sort command: %s\n"),csort);
403 exit(EXIT_FAILURE);
404 }
405
406 if ((fp_ip = MY_FOPEN(tmp3, "r")) == 0) {
407 debugapos("html8",_("Cannot open file \"%s\": %s\n"),tmp3,strerror(errno));
408 exit(EXIT_FAILURE);
409 }
410
411 if (unlink(tmp2)) {
412 debuga(_("Cannot delete \"%s\": %s\n"),tmp2,strerror(errno));
413 exit(EXIT_FAILURE);
414 }
415
416 olduserip[0]='\0';
417
418 if ((line1=longline_create())==NULL) {
419 debuga(_("Not enough memory to read file \"%s\"\n"),arqip);
420 exit(EXIT_FAILURE);
421 }
422 while((buf=longline_read(fp_ip,line1))!=NULL) {
423 getword_start(&gwarea,buf);
424 if (getword(user_ip,sizeof(user_ip),&gwarea,'\t')<0) {
425 debuga(_("Invalid user IP in file \"%s\"\n"),tmp3);
426 exit(EXIT_FAILURE);
427 }
428 if (getword_atoll(&userbytes,&gwarea,'\t')<0) {
429 debuga(_("Invalid size in file \"%s\"\n"),tmp3);
430 exit(EXIT_FAILURE);
431 }
432 if (getword_atoll(&userelap,&gwarea,'\0')<0) {
433 debuga(_("Invalid elapsed time in file \"%s\"\n"),tmp3);
434 exit(EXIT_FAILURE);
435 }
436 if(strcmp(user_ip,olduserip) != 0) {
437 if (olduserip[0]!='\0') {
438 fprintf(fp_ou,"<tr><td></td><td class=\"data\">%s</td>",olduserip);
439 if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0)
440 fputs("<td></td>",fp_ou);
441 if((UserReportFields & USERREPORTFIELDS_BYTES) != 0)
442 fprintf(fp_ou,"<td class=\"data\">%s</td>",fixnum(unbytes,1));
443 if((UserReportFields & USERREPORTFIELDS_SETYB) != 0)
444 fputs("<td></td>",fp_ou);
445 if((UserReportFields & USERREPORTFIELDS_IN_CACHE_OUT) != 0)
446 fputs("</td><td></td><td></td>",fp_ou);
447 if((UserReportFields & USERREPORTFIELDS_USED_TIME) != 0)
448 fprintf(fp_ou,"<td class=\"data\">%s</td>",buildtime(unelap));
449 if((UserReportFields & USERREPORTFIELDS_MILISEC) != 0)
450 fprintf(fp_ou,"<td class=\"data\">%s</td>",fixnum2(unelap,1));
451 fputs("</tr>\n",fp_ou);
452 }
453
454 strcpy(olduserip,user_ip);
455 unbytes=0;
456 unelap=0;
457 }
458
459 unbytes+=userbytes;
460 unelap+=userelap;
461 }
462
463 fclose(fp_ip);
464 longline_destroy(&line1);
465
466 if (unlink(tmp3)) {
467 debuga(_("Cannot delete \"%s\": %s\n"),tmp3,strerror(errno));
468 exit(EXIT_FAILURE);
469 }
470
471 if (olduserip[0]!='\0') {
472 fprintf(fp_ou,"<tr><td></td><td class=\"data\">%s</td>",olduserip);
473 if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0)
474 fputs("<td></td>",fp_ou);
475 if((UserReportFields & USERREPORTFIELDS_BYTES) != 0)
476 fprintf(fp_ou,"<td class=\"data\">%s</td>",fixnum(unbytes,1));
477 if((UserReportFields & USERREPORTFIELDS_SETYB) != 0)
478 fputs("<td></td>",fp_ou);
479 if((UserReportFields & USERREPORTFIELDS_IN_CACHE_OUT) != 0)
480 fputs("</td><td></td><td></td>",fp_ou);
481 if((UserReportFields & USERREPORTFIELDS_USED_TIME) != 0)
482 fprintf(fp_ou,"<td class=\"data\">%s</td>",buildtime(unelap));
483 if((UserReportFields & USERREPORTFIELDS_MILISEC) != 0)
484 fprintf(fp_ou,"<td class=\"data\">%s</td>",fixnum2(unelap,1));
485 fputs("</tr>\n",fp_ou);
486 }
487 }
488
489 unbytes=0;
490 unelap=0;
491 }
492
493 fclose(fp_in);
494 longline_destroy(&line);
495
496 if (iprel && arqip[0]) {
497 if (!KeepTempLog && unlink(arqip)) {
498 debuga(_("Cannot delete \"%s\": %s\n"),arqip,strerror(errno));
499 exit(EXIT_FAILURE);
500 }
501 }
502 if (!KeepTempLog && unlink(arqin)) {
503 debuga(_("Cannot delete \"%s\": %s\n"),arqin,strerror(errno));
504 exit(EXIT_FAILURE);
505 }
506
507 if ((UserReportFields & (USERREPORTFIELDS_TOTAL | USERREPORTFIELDS_AVERAGE)) != 0)
508 fputs("<tfoot>",fp_ou);
509
510 if((UserReportFields & USERREPORTFIELDS_TOTAL) != 0) {
511 fprintf(fp_ou,"<tr><th></th><th class=\"header_l\">%s</th>",_("TOTAL"));
512 if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0)
513 fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fixnum(tnacc,1));
514 if((UserReportFields & USERREPORTFIELDS_BYTES) != 0)
515 fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fixnum(tnbytes,1));
516 if((UserReportFields & USERREPORTFIELDS_SETYB) != 0) {
517 perc=(totbytes) ? tnbytes *100. / totbytes :0.;
518 fprintf(fp_ou,"<th class=\"header_r\">%3.2lf%%</th>",perc);
519 }
520 if((UserReportFields & USERREPORTFIELDS_IN_CACHE_OUT) != 0) {
521 inperc=(tnbytes) ? tnincache * 100. / tnbytes : 0.;
522 ouperc=(tnbytes) ? tnoucache * 100. / tnbytes : 0.;
523 fprintf(fp_ou,"<th class=\"header_r\">%3.2lf%%</th><th class=\"header_r\">%3.2lf%%</th>",inperc,ouperc);
524 }
525 if((UserReportFields & USERREPORTFIELDS_USED_TIME) != 0)
526 fprintf(fp_ou,"<th class=\"header_r\">%s</th>",buildtime(tnelap));
527 if((UserReportFields & USERREPORTFIELDS_MILISEC) != 0)
528 fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fixnum2(tnelap,1));
529 if((UserReportFields & USERREPORTFIELDS_PTIME) != 0) {
530 perc2=(totelap) ? tnelap * 100. / totelap : 0.;
531 fprintf(fp_ou,"<th class=\"header_r\">%3.2lf%%</th>",perc2);
532 }
533 fputs("</tr>\n",fp_ou);
534 }
535
536 if(PerUserLimit > 0) {
537 if ((int)(tnbytes/1000000LLU) > PerUserLimit) {
538 limit_flag=0;
539 if(access(PerUserLimitFile, R_OK) == 0) {
540 if((fp_usr = fopen(PerUserLimitFile, "r")) == 0) {
541 debugapos("html9",_("Cannot open file \"%s\": %s\n"),PerUserLimitFile,strerror(errno));
542 exit(EXIT_FAILURE);
543 }
544 while(fgets(tmp6,sizeof(tmp6),fp_usr)!=NULL) {
545 fixendofline(tmp6);
546 if(strcmp(tmp6,uinfo->ip) == 0) {
547 limit_flag=1;
548 break;
549 }
550 }
551 fclose(fp_usr);
552 }
553
554 if(!limit_flag) {
555 if((fp_usr = fopen(PerUserLimitFile, "a")) == 0) {
556 debugapos("html10",_("Cannot open file \"%s\": %s\n"),PerUserLimitFile,strerror(errno));
557 exit(EXIT_FAILURE);
558 }
559 fprintf(fp_usr,"%s\n",uinfo->ip);
560 fclose(fp_usr);
561
562 if(debug)
563 debuga(_("User %s limit exceeded (%d MB). Added to file \"%s\"\n"),uinfo->label,PerUserLimit,PerUserLimitFile);
564 }
565 }
566 }
567
568 if ((ReportType & REPORT_TYPE_TOPUSERS) != 0 && (UserReportFields & USERREPORTFIELDS_AVERAGE) != 0) {
569 totbytes2=totbytes/ntotuser;
570 totelap2=totelap/ntotuser;
571
572 fprintf(fp_ou,"<tr><th></th><th class=\"header_l\">%s</th>",_("AVERAGE"));
573 if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0)
574 fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fixnum(ttnacc/ntotuser,1));
575 if((UserReportFields & USERREPORTFIELDS_BYTES) != 0)
576 fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fixnum(totbytes2,1));
577 fprintf(fp_ou,"<th></th><th></th><th></th>");
578 if((UserReportFields & USERREPORTFIELDS_USED_TIME) != 0)
579 fprintf(fp_ou,"<th class=\"header_r\">%s</th>",buildtime(totelap2));
580 if((UserReportFields & USERREPORTFIELDS_MILISEC) != 0)
581 fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fixnum2(totelap2,1));
582 if((UserReportFields & USERREPORTFIELDS_PTIME) != 0) {
583 perc2 = (totelap) ? totelap2 * 100. / totelap : 0.;
584 fprintf(fp_ou,"<th class=\"header_r\">%3.2lf%%</th>",perc2);
585 }
586 fputs("</tr>\n",fp_ou);
587 }
588
589 if ((UserReportFields & (USERREPORTFIELDS_TOTAL | USERREPORTFIELDS_AVERAGE)) != 0)
590 fputs("</tfoot>",fp_ou);
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 userinfo_stopscan(uscan);
602
603 return;
604 }