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