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