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