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