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