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