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