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