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