]>
Commit | Line | Data |
---|---|---|
25697a35 | 1 | /* |
94ff9470 | 2 | * SARG Squid Analysis Report Generator http://sarg.sourceforge.net |
fbd133bb | 3 | * 1998, 2011 |
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 | |
9dc20988 FM |
30 | extern struct globalstatstruct globstat; |
31 | ||
32e71fa4 | 32 | void htmlrel(void) |
25697a35 | 33 | { |
9bd92830 FM |
34 | FILE *fp_in, *fp_ou, *fp_ip, *fp_ip2, *fp_usr; |
35 | ||
9bd92830 FM |
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; | |
e5b3a129 | 40 | long long int ntotuser; |
9bd92830 FM |
41 | long long int userbytes, userelap; |
42 | char *buf; | |
e5b3a129 | 43 | char arqin[MAXLEN], arqou[MAXLEN], arqip[MAXLEN]; |
9bd92830 | 44 | char *url, tmsg[50], csort[MAXLEN]; |
93551487 | 45 | char duser[MAXLEN]; |
9bd92830 | 46 | char user_ip[MAXLEN], olduserip[MAXLEN], tmp2[MAXLEN], tmp3[MAXLEN]; |
9bd92830 | 47 | char warea[MAXLEN]; |
9bd92830 FM |
48 | char tmp6[MAXLEN]; |
49 | char *user_url; | |
50 | long long int tnacc=0, ttnacc=0, unacc=0; | |
51 | double perc=0, perc2=0, ouperc=0, inperc=0; | |
52 | int count; | |
53 | int cstatus; | |
93551487 | 54 | int have_denied_report; |
9bd92830 FM |
55 | const char *sort_field; |
56 | const char *sort_order; | |
9bd92830 FM |
57 | char siteind[MAX_TRUNCATED_URL]; |
58 | struct getwordstruct gwarea; | |
59 | longline line,line1; | |
9bd92830 | 60 | const struct userinfostruct *uinfo; |
93551487 | 61 | userscan uscan; |
9bd92830 | 62 | |
8d811f76 FM |
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 | } | |
9bd92830 | 67 | |
8d811f76 FM |
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 | } | |
9bd92830 | 72 | |
9dc20988 FM |
73 | tnacc=globstat.nacc; |
74 | totbytes=globstat.nbytes; | |
75 | totelap=globstat.elap; | |
e5b3a129 | 76 | ntotuser=globstat.totuser; |
9bd92830 FM |
77 | |
78 | greport_prepare(); | |
79 | ||
80 | sort_labels(&sort_field,&sort_order); | |
81 | ||
93551487 FM |
82 | uscan=userinfo_startscan(); |
83 | if (uscan == NULL) { | |
84 | debuga(_("Cannot enumerate the user list\n")); | |
9bd92830 FM |
85 | exit(EXIT_FAILURE); |
86 | } | |
93551487 | 87 | while ( (uinfo = userinfo_advancescan(uscan)) != NULL ) { |
e5b3a129 FM |
88 | if (!uinfo->topuser) { |
89 | continue; | |
90 | } | |
91 | tmpsort(uinfo); | |
9bd92830 | 92 | |
e5b3a129 FM |
93 | if (snprintf(warea,sizeof(warea),"%s/%s",outdirname,uinfo->filename)>=sizeof(warea)) { |
94 | debuga(_("Destination directory too long: %s/%s\n"),outdirname,uinfo->filename); | |
9bd92830 FM |
95 | exit(EXIT_FAILURE); |
96 | } | |
affa72c5 FM |
97 | if (access(warea, R_OK) != 0) { |
98 | if (mkdir(warea,0755)) { | |
99 | debuga(_("Cannot create directory %s - %s\n"),warea,strerror(errno)); | |
100 | exit(EXIT_FAILURE); | |
101 | } | |
102 | } | |
9bd92830 FM |
103 | |
104 | report_day(uinfo); | |
105 | greport_day(uinfo); | |
106 | ||
e5b3a129 FM |
107 | if (snprintf(arqin,sizeof(arqin),"%s/htmlrel.txt",tmp)>=sizeof(arqin)) { |
108 | debuga(_("Input file name too long: %s/htmlrel.txt\n"),tmp); | |
93551487 FM |
109 | exit(EXIT_FAILURE); |
110 | } | |
111 | if ((fp_in = fopen(arqin, "r")) == 0){ | |
112 | if (uinfo->no_report) continue; | |
113 | debuga(_("(html3) Cannot open file %s\n"),arqin); | |
9bd92830 FM |
114 | exit(EXIT_FAILURE); |
115 | } | |
93551487 | 116 | |
9bd92830 FM |
117 | if (snprintf(arqou,sizeof(arqou),"%s/%s/%s.html",outdirname,uinfo->filename,uinfo->filename)>=sizeof(arqou)) { |
118 | debuga(_("Output file name too long: %s/%s/%s.html\n"),outdirname,uinfo->filename,uinfo->filename); | |
119 | exit(EXIT_FAILURE); | |
120 | } | |
93551487 FM |
121 | if (snprintf(duser,sizeof(duser),"%s/%s/denied_%s.html",tmp,uinfo->filename,uinfo->filename)>=sizeof(duser)) { |
122 | debuga(_("File name too long: %s/%s/denied_%s.html\n"),tmp,uinfo->filename,uinfo->filename); | |
9bd92830 FM |
123 | exit(EXIT_FAILURE); |
124 | } | |
125 | if(access(duser, R_OK) != 0) | |
93551487 FM |
126 | have_denied_report=0; |
127 | else | |
128 | have_denied_report=1; | |
9bd92830 FM |
129 | |
130 | if ((line=longline_create())==NULL) { | |
131 | debuga(_("Not enough memory to read file %s\n"),arqin); | |
132 | exit(EXIT_FAILURE); | |
133 | } | |
134 | ||
135 | tnacc=0; | |
136 | tnbytes=0; | |
137 | tnelap=0; | |
138 | tnincache=0; | |
139 | tnoucache=0; | |
140 | while((buf=longline_read(fp_in,line))!=NULL) { | |
141 | getword_start(&gwarea,buf); | |
142 | if (getword_atoll(<emp,&gwarea,'\t')<0) { | |
143 | debuga(_("There is a broken number of access in file %s\n"),arqin); | |
144 | exit(EXIT_FAILURE); | |
145 | } | |
146 | tnacc+=ltemp; | |
147 | if (getword_atoll(<emp,&gwarea,'\t')<0) { | |
148 | debuga(_("There is a broken downloaded size in file %s\n"),arqin); | |
149 | exit(EXIT_FAILURE); | |
150 | } | |
151 | tnbytes+=ltemp; | |
152 | if (getword_ptr(NULL,NULL,&gwarea,'\t')<0) { | |
153 | debuga(_("There is a broken url in file %s\n"),arqin); | |
154 | exit(EXIT_FAILURE); | |
155 | } | |
156 | if (getword_skip(MAXLEN,&gwarea,'\t')<0) { | |
157 | debuga(_("There is a broken access code in file %s\n"),arqin); | |
158 | exit(EXIT_FAILURE); | |
159 | } | |
160 | if (getword_atoll(<emp,&gwarea,'\t')<0) { | |
161 | debuga(_("There is a broken elapsed time in file %s\n"),arqin); | |
162 | exit(EXIT_FAILURE); | |
163 | } | |
164 | tnelap+=ltemp; | |
165 | if (getword_atoll(<emp,&gwarea,'\t')<0) { | |
166 | debuga(_("There is a broken in-cache volume in file %s\n"),arqin); | |
167 | exit(EXIT_FAILURE); | |
168 | } | |
169 | tnincache+=ltemp; | |
170 | if (getword_atoll(<emp,&gwarea,'\n')<0) { | |
171 | debuga(_("There is a broken out-cache volume in file %s\n"),arqin); | |
172 | exit(EXIT_FAILURE); | |
173 | } | |
174 | tnoucache+=ltemp; | |
175 | } | |
176 | ||
177 | rewind(fp_in); | |
178 | ||
179 | if ((fp_ou = fopen(arqou, "w")) == 0){ | |
180 | debuga(_("(html5) Cannot open file %s\n"),arqou); | |
181 | exit(EXIT_FAILURE); | |
182 | } | |
183 | ||
184 | write_html_header(fp_ou,(IndexTree == INDEX_TREE_DATE) ? 4 : 2,_("User report"),HTML_JS_SORTTABLE); | |
185 | fprintf(fp_ou,"<tr><td class=\"header_c\">%s: %s</td></tr>\n",_("Period"),period.html); | |
186 | fprintf(fp_ou,"<tr><td class=\"header_c\">%s: %s</td></tr>\n",_("User"),uinfo->label); | |
187 | fputs("<tr><td class=\"header_c\">",fp_ou); | |
188 | fprintf(fp_ou,_("Sort: %s, %s"),sort_field,sort_order); | |
189 | fputs("</td></tr>\n",fp_ou); | |
190 | fprintf(fp_ou,"<tr><th class=\"header_c\">%s</th></tr>\n",_("User report")); | |
191 | close_html_header(fp_ou); | |
192 | ||
193 | fputs("<div class=\"report\"><table cellpadding=\"2\" cellspacing=\"1\"",fp_ou); | |
194 | if (SortTableJs[0]) fputs(" class=\"sortable\"",fp_ou); | |
195 | fputs(">\n",fp_ou); | |
196 | ||
197 | /*! \bug This line lays before the header of the table and is therefore invalid | |
198 | HTML. It will also break the sorttable script. Beside, I suspect it serves no purpose. | |
199 | */ | |
93551487 FM |
200 | if(have_denied_report) { |
201 | 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 |
202 | } |
203 | ||
204 | fputs("<thead><tr><th class=\"sorttable_nosort\"></th><th class=\"header_l",fp_ou); | |
205 | if (SortTableJs[0]) fputs(" sorttable_alpha",fp_ou); | |
206 | fprintf(fp_ou,"\">%s</th>",_("ACCESSED SITE")); | |
207 | ||
208 | if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0) | |
209 | fprintf(fp_ou,"<th class=\"header_l\">%s</th>",_("CONNECT")); | |
210 | if((UserReportFields & USERREPORTFIELDS_BYTES) != 0) | |
211 | fprintf(fp_ou,"<th class=\"header_l\">%s</th>",_("BYTES")); | |
212 | if((UserReportFields & USERREPORTFIELDS_SETYB) != 0) | |
213 | fprintf(fp_ou,"<th class=\"header_l\">%%%s</th>",_("BYTES")); | |
214 | if((UserReportFields & USERREPORTFIELDS_IN_CACHE_OUT) != 0) | |
215 | fprintf(fp_ou,"<th class=\"header_c\" colspan=\"2\">%s</th><th style=\"display:none;\"></th>",_("IN-CACHE-OUT")); | |
216 | if((UserReportFields & USERREPORTFIELDS_USED_TIME) != 0) | |
217 | fprintf(fp_ou,"<th class=\"header_l\">%s</th>",_("ELAPSED TIME")); | |
218 | if((UserReportFields & USERREPORTFIELDS_MILISEC) != 0) | |
219 | fprintf(fp_ou,"<th class=\"header_l\">%s</th>",_("MILLISEC")); | |
220 | if((UserReportFields & USERREPORTFIELDS_PTIME) != 0) | |
221 | fprintf(fp_ou,"<th class=\"header_l\">%%%s</th>",_("TIME")); | |
222 | ||
223 | fputs("</tr></thead>\n",fp_ou); | |
224 | ||
225 | if(debug) { | |
226 | debuga(_("Making report: %s\n"),uinfo->id); | |
227 | } | |
ddcf5214 | 228 | count=0; |
a5267dd6 | 229 | arqip[0]='\0'; |
9bd92830 FM |
230 | |
231 | while((buf=longline_read(fp_in,line))!=NULL) { | |
232 | getword_start(&gwarea,buf); | |
233 | if (getword_atoll(&twork,&gwarea,'\t')<0) { | |
234 | debuga(_("There is a broken number of access in file %s\n"),arqin); | |
235 | exit(EXIT_FAILURE); | |
236 | } | |
237 | if (getword_atoll(&nnbytes,&gwarea,'\t')<0) { | |
238 | debuga(_("There is a broken number of bytes in file %s\n"),arqin); | |
239 | exit(EXIT_FAILURE); | |
240 | } | |
241 | if (getword_ptr(buf,&url,&gwarea,'\t')<0) { | |
242 | debuga(_("There is a broken url in file %s\n"),arqin); | |
243 | exit(EXIT_FAILURE); | |
244 | } | |
245 | if (getword(tmsg,sizeof(tmsg),&gwarea,'\t')<0) { | |
246 | debuga(_("There is a broken access code in file %s\n"),arqin); | |
247 | exit(EXIT_FAILURE); | |
248 | } | |
249 | if (getword_atoll(&nnelap,&gwarea,'\t')<0) { | |
250 | debuga(_("There is a broken elapsed time in file %s\n"),arqin); | |
251 | exit(EXIT_FAILURE); | |
252 | } | |
253 | if (getword_atoll(&incache,&gwarea,'\t')<0) { | |
254 | debuga(_("There is a broken in cache column in file %s\n"),arqin); | |
255 | exit(EXIT_FAILURE); | |
256 | } | |
257 | if (getword_atoll(&oucache,&gwarea,'\n')<0) { | |
258 | debuga(_("There is a broken out of cache column in file %s (%d)\n"),arqin,__LINE__); | |
259 | exit(EXIT_FAILURE); | |
260 | } | |
261 | ||
262 | if(UserReportLimit<=0 || count<=UserReportLimit) { | |
263 | fputs("<tr>",fp_ou); | |
264 | ||
265 | if(IndexTree == INDEX_TREE_DATE) | |
266 | sprintf(tmp6,"../%s",ImageFile); | |
267 | else | |
268 | strcpy(tmp6,"../../images"); | |
269 | ||
270 | if((ReportType & REPORT_TYPE_SITE_USER_TIME_DATE) != 0) { | |
271 | url_to_file(url,siteind,sizeof(siteind)); | |
272 | 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")); | |
273 | } else { | |
274 | fprintf(fp_ou,"<td class=\"data\"></td>"); | |
275 | } | |
276 | ||
277 | if(Privacy) | |
278 | fprintf(fp_ou,"<td class=\"data2\"><span style=\"color:%s;\">%s</span></td>",PrivacyStringColor,PrivacyString); | |
279 | else { | |
280 | fputs("<td class=\"data2\">",fp_ou); | |
67a93701 | 281 | if(BlockIt[0]!='\0' && url[0]!=ALIAS_PREFIX) { |
9bd92830 FM |
282 | fprintf(fp_ou,"<a href=\"%s%s?url=",wwwDocumentRoot,BlockIt); |
283 | output_html_url(fp_ou,url); | |
284 | fprintf(fp_ou,"\"><img src=\"%s/sarg-squidguard-block.png\"></a> ",tmp6); | |
285 | } | |
67a93701 FM |
286 | output_html_link(fp_ou,url,100); |
287 | fputs("</td>",fp_ou); | |
9bd92830 FM |
288 | } |
289 | ||
290 | if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0) { | |
291 | fputs("<td class=\"data\"",fp_ou); | |
292 | if (SortTableJs[0]) fprintf(fp_ou," sorttable_customkey=\"%"PRId64"\"",(int64_t)twork); | |
293 | fprintf(fp_ou,">%s</td>",fixnum(twork,1)); | |
294 | } | |
295 | if((UserReportFields & USERREPORTFIELDS_BYTES) != 0) { | |
296 | fputs("<td class=\"data\"",fp_ou); | |
297 | if (SortTableJs[0]) fprintf(fp_ou," sorttable_customkey=\"%"PRId64"\"",(int64_t)nnbytes); | |
298 | fprintf(fp_ou,">%s</td>",fixnum(nnbytes,1)); | |
299 | } | |
300 | if((UserReportFields & USERREPORTFIELDS_SETYB) != 0) { | |
301 | perc=(tnbytes) ? nnbytes * 100. / tnbytes : 0.; | |
302 | fprintf(fp_ou,"<td class=\"data\">%3.2lf%%</td>",perc); | |
303 | } | |
304 | if((UserReportFields & USERREPORTFIELDS_IN_CACHE_OUT) != 0) { | |
305 | inperc=(nnbytes) ? incache * 100. / nnbytes : 0.; | |
306 | ouperc=(nnbytes) ? oucache * 100. / nnbytes : 0.; | |
307 | fprintf(fp_ou,"<td class=\"data\">%3.2lf%%</td><td class=\"data\">%3.2lf%%</td>",inperc,ouperc); | |
308 | } | |
309 | if((UserReportFields & USERREPORTFIELDS_USED_TIME) != 0) { | |
310 | fputs("<td class=\"data\"",fp_ou); | |
311 | if (SortTableJs[0]) fprintf(fp_ou," sorttable_customkey=\"%"PRId64"\"",(int64_t)nnelap); | |
312 | fprintf(fp_ou,">%s</td>",buildtime(nnelap)); | |
313 | } | |
314 | if((UserReportFields & USERREPORTFIELDS_MILISEC) != 0) { | |
315 | fputs("<td class=\"data\"",fp_ou); | |
316 | if (SortTableJs[0]) fprintf(fp_ou," sorttable_customkey=\"%"PRId64"\"",(int64_t)nnelap); | |
317 | fprintf(fp_ou,">%s</td>",fixnum2(nnelap,1)); | |
318 | } | |
319 | if((UserReportFields & USERREPORTFIELDS_PTIME) != 0) { | |
320 | perc2=(tnelap) ? nnelap * 100. / tnelap : 0.; | |
321 | fprintf(fp_ou,"<td class=\"data\">%3.2lf%%</td>",perc2); | |
322 | } | |
323 | ||
324 | if(strncmp(tmsg,"OK",2) != 0) | |
325 | fprintf(fp_ou,"<td class=\"data\">%s</td>",_("DENIED")); | |
326 | ||
327 | fputs("</tr>\n",fp_ou); | |
328 | count++; | |
329 | } else if ((ReportType & REPORT_TYPE_SITE_USER_TIME_DATE) != 0) { | |
330 | url_to_file(url,siteind,sizeof(siteind)); | |
331 | snprintf(tmp2,sizeof(tmp2),"%s/%s/tt%s-%s.html",outdirname,uinfo->filename,uinfo->filename,siteind); | |
332 | if (unlink(tmp2)!=0) { | |
333 | debuga(_("Cannot delete unused file \"%s\" - %s\n"),tmp2,strerror(errno)); | |
334 | } | |
335 | } | |
336 | ||
337 | if(iprel) { | |
338 | if (snprintf(arqip,sizeof(arqip),"%s/%s.ip",tmp,uinfo->filename)>=sizeof(arqip)) { | |
339 | debuga(_("File name too long: %s/%s.ip\n"),tmp,uinfo->filename); | |
340 | exit(EXIT_FAILURE); | |
341 | } | |
342 | ||
343 | if ((fp_ip = fopen(arqip, "r")) == 0){ | |
344 | debuga(_("(html6) Cannot open file %s\n"),arqip); | |
345 | exit(EXIT_FAILURE); | |
346 | } | |
347 | ||
348 | if ((fp_ip2 = MY_FOPEN(tmp2, "a")) == 0){ | |
349 | debuga(_("(html7) Cannot open file %s\n"),tmp2); | |
350 | exit(EXIT_FAILURE); | |
351 | } | |
352 | ||
353 | if ((line1=longline_create())==NULL) { | |
354 | debuga(_("Not enough memory to read file %s\n"),arqip); | |
355 | exit(EXIT_FAILURE); | |
356 | } | |
357 | while((buf=longline_read(fp_ip,line1))!=NULL) { | |
358 | getword_start(&gwarea,buf); | |
359 | if (getword(user_ip,sizeof(user_ip),&gwarea,'\t')<0) { | |
360 | debuga(_("Maybe you have a broken user IP in your %s file\n"),tmp3); | |
361 | exit(EXIT_FAILURE); | |
362 | } | |
363 | if (getword_ptr(buf,&user_url,&gwarea,'\t')<0) { | |
364 | debuga(_("Maybe you have a broken url in your %s file\n"),tmp3); | |
365 | exit(EXIT_FAILURE); | |
366 | } | |
367 | if (strncmp(user_url,url,strlen(url))!=0) continue; | |
368 | if (getword_skip(15,&gwarea,'\t')<0) { | |
369 | debuga(_("Maybe you have a broken day in your %s file\n"),tmp3); | |
370 | exit(EXIT_FAILURE); | |
371 | } | |
372 | if (getword_skip(15,&gwarea,'\t')<0) { | |
373 | debuga(_("Maybe you have a broken time in your %s file\n"),tmp3); | |
374 | exit(EXIT_FAILURE); | |
375 | } | |
376 | if (getword_atoll(&userbytes,&gwarea,'\t')<0) { | |
377 | debuga(_("Maybe you have a broken size in your %s file\n"),tmp3); | |
378 | exit(EXIT_FAILURE); | |
379 | } | |
380 | if (getword_atoll(&userelap,&gwarea,'\0')<0) { | |
381 | debuga(_("Maybe you have a broken elapsed time in your %s file\n"),tmp3); | |
382 | exit(EXIT_FAILURE); | |
383 | } | |
384 | fprintf(fp_ip2,"%s\t%"PRIu64"\t%"PRIu64"\n",user_ip,(uint64_t)userbytes,(uint64_t)userelap); | |
385 | } | |
386 | longline_destroy(&line1); | |
387 | ||
388 | fclose(fp_ip); | |
389 | fclose(fp_ip2); | |
390 | ||
78eeb33f FM |
391 | 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)) { |
392 | debuga(_("Sort command too long when sorting file \"%s\" to \"%s\"\n"),tmp2,tmp3); | |
393 | exit(EXIT_FAILURE); | |
394 | } | |
9bd92830 FM |
395 | cstatus=system(csort); |
396 | if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) { | |
397 | debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus)); | |
398 | debuga(_("sort command: %s\n"),csort); | |
399 | exit(EXIT_FAILURE); | |
400 | } | |
401 | ||
402 | if ((fp_ip = MY_FOPEN(tmp3, "r")) == 0) { | |
403 | debuga(_("(html8) Cannot open file %s\n"),tmp3); | |
404 | exit(EXIT_FAILURE); | |
405 | } | |
406 | ||
407 | olduserip[0]='\0'; | |
408 | ||
409 | if ((line1=longline_create())==NULL) { | |
410 | debuga(_("Not enough memory to read file %s\n"),arqip); | |
411 | exit(EXIT_FAILURE); | |
412 | } | |
413 | while((buf=longline_read(fp_ip,line1))!=NULL) { | |
414 | getword_start(&gwarea,buf); | |
415 | if (getword(user_ip,sizeof(user_ip),&gwarea,'\t')<0) { | |
416 | debuga(_("Maybe you have a broken user IP in your %s file\n"),tmp3); | |
417 | exit(EXIT_FAILURE); | |
418 | } | |
419 | if (getword_atoll(&userbytes,&gwarea,'\t')<0) { | |
420 | debuga(_("Maybe you have a broken size in your %s file\n"),tmp3); | |
421 | exit(EXIT_FAILURE); | |
422 | } | |
423 | if (getword_atoll(&userelap,&gwarea,'\0')<0) { | |
424 | debuga(_("Maybe you have a broken elapsed time in your %s file\n"),tmp3); | |
425 | exit(EXIT_FAILURE); | |
426 | } | |
427 | if(strcmp(user_ip,olduserip) != 0) { | |
428 | if (olduserip[0]!='\0') { | |
429 | fprintf(fp_ou,"<tr><td></td><td class=\"data\">%s</td>",olduserip); | |
430 | if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0) | |
431 | fputs("<td></td>",fp_ou); | |
432 | if((UserReportFields & USERREPORTFIELDS_BYTES) != 0) | |
433 | fprintf(fp_ou,"<td class=\"data\">%s</td>",fixnum(unbytes,1)); | |
434 | if((UserReportFields & USERREPORTFIELDS_SETYB) != 0) | |
435 | fputs("<td></td>",fp_ou); | |
436 | if((UserReportFields & USERREPORTFIELDS_IN_CACHE_OUT) != 0) | |
437 | fputs("</td><td></td><td></td>",fp_ou); | |
438 | if((UserReportFields & USERREPORTFIELDS_USED_TIME) != 0) | |
439 | fprintf(fp_ou,"<td class=\"data\">%s</td>",buildtime(unelap)); | |
440 | if((UserReportFields & USERREPORTFIELDS_MILISEC) != 0) | |
441 | fprintf(fp_ou,"<td class=\"data\">%s</td>",fixnum2(unelap,1)); | |
442 | fputs("</tr>\n",fp_ou); | |
443 | } | |
444 | ||
445 | strcpy(olduserip,user_ip); | |
446 | unacc=0; | |
447 | unbytes=0; | |
448 | unelap=0; | |
449 | } | |
450 | ||
451 | unbytes+=userbytes; | |
452 | unelap+=userelap; | |
453 | } | |
454 | ||
455 | fclose(fp_ip); | |
456 | longline_destroy(&line1); | |
457 | ||
08f9b029 FM |
458 | if (unlink(tmp2)) { |
459 | debuga(_("Cannot delete %s - %s\n"),tmp2,strerror(errno)); | |
460 | exit(EXIT_FAILURE); | |
461 | } | |
462 | if (unlink(tmp3)) { | |
463 | debuga(_("Cannot delete %s - %s\n"),tmp3,strerror(errno)); | |
464 | exit(EXIT_FAILURE); | |
465 | } | |
9bd92830 FM |
466 | |
467 | if (olduserip[0]!='\0') { | |
468 | fprintf(fp_ou,"<tr><td></td><td class=\"data\">%s</td>",olduserip); | |
469 | if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0) | |
470 | fputs("<td></td>",fp_ou); | |
471 | if((UserReportFields & USERREPORTFIELDS_BYTES) != 0) | |
472 | fprintf(fp_ou,"<td class=\"data\">%s</td>",fixnum(unbytes,1)); | |
473 | if((UserReportFields & USERREPORTFIELDS_SETYB) != 0) | |
474 | fputs("<td></td>",fp_ou); | |
475 | if((UserReportFields & USERREPORTFIELDS_IN_CACHE_OUT) != 0) | |
476 | fputs("</td><td></td><td></td>",fp_ou); | |
477 | if((UserReportFields & USERREPORTFIELDS_USED_TIME) != 0) | |
478 | fprintf(fp_ou,"<td class=\"data\">%s</td>",buildtime(unelap)); | |
479 | if((UserReportFields & USERREPORTFIELDS_MILISEC) != 0) | |
480 | fprintf(fp_ou,"<td class=\"data\">%s</td>",fixnum2(unelap,1)); | |
481 | fputs("</tr>\n",fp_ou); | |
482 | } | |
483 | } | |
484 | ||
485 | unacc=0; | |
486 | unbytes=0; | |
487 | unelap=0; | |
488 | } | |
489 | ||
490 | fclose(fp_in); | |
491 | longline_destroy(&line); | |
492 | ||
a5267dd6 | 493 | if (iprel && arqip[0]) { |
08f9b029 FM |
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 | } | |
9bd92830 FM |
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 | } | |
25697a35 | 564 | |
9bd92830 FM |
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 | ||
93551487 | 598 | userinfo_stopscan(uscan); |
9bd92830 FM |
599 | greport_cleanup(); |
600 | ||
601 | return; | |
25697a35 | 602 | } |