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