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