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