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