]>
Commit | Line | Data |
---|---|---|
25697a35 | 1 | /* |
94ff9470 | 2 | * SARG Squid Analysis Report Generator http://sarg.sourceforge.net |
110ce984 | 3 | * 1998, 2015 |
25697a35 GS |
4 | * |
5 | * SARG donations: | |
6 | * please look at http://sarg.sourceforge.net/donations.php | |
1164c474 FM |
7 | * Support: |
8 | * http://sourceforge.net/projects/sarg/forums/forum/363374 | |
25697a35 GS |
9 | * --------------------------------------------------------------------- |
10 | * | |
11 | * This program is free software; you can redistribute it and/or modify | |
12 | * it under the terms of the GNU General Public License as published by | |
13 | * the Free Software Foundation; either version 2 of the License, or | |
14 | * (at your option) any later version. | |
15 | * | |
16 | * This program is distributed in the hope that it will be useful, | |
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | * GNU General Public License for more details. | |
20 | * | |
21 | * You should have received a copy of the GNU General Public License | |
22 | * along with this program; if not, write to the Free Software | |
23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. | |
24 | * | |
25 | */ | |
26 | ||
27 | #include "include/conf.h" | |
5f3cfd1d | 28 | #include "include/defs.h" |
25697a35 | 29 | |
9dc20988 | 30 | extern struct globalstatstruct globstat; |
27d1fa35 | 31 | extern bool smartfilter; |
9dc20988 | 32 | |
124ec0b0 FM |
33 | /*! |
34 | Save the total number of users. The number is written in sarg-users and set | |
35 | in a global variable for further reference. | |
36 | ||
37 | \param totuser The total number of users. | |
38 | */ | |
39 | static void set_total_users(int totuser) | |
40 | { | |
41 | char tusr[1024]; | |
42 | FILE *fp_ou; | |
bd43d81f | 43 | |
124ec0b0 FM |
44 | snprintf(tusr,sizeof(tusr),"%s/sarg-users",outdirname); |
45 | if((fp_ou=fopen(tusr,"w"))==NULL) { | |
96dadc9f | 46 | debuga(_("Cannot open file \"%s\": %s\n"),tusr,strerror(errno)); |
124ec0b0 FM |
47 | exit(EXIT_FAILURE); |
48 | } | |
49 | fprintf(fp_ou,"%d\n",totuser); | |
507460ae | 50 | if (fclose(fp_ou)==EOF) { |
96dadc9f | 51 | debuga(_("Write error in \"%s\": %s\n"),tusr,strerror(errno)); |
507460ae FM |
52 | exit(EXIT_FAILURE); |
53 | } | |
124ec0b0 FM |
54 | globstat.totuser=totuser; |
55 | } | |
56 | ||
32e71fa4 | 57 | void topuser(void) |
25697a35 | 58 | { |
124ec0b0 | 59 | FILE *fp_in = NULL, *fp_top1 = NULL, *fp_top2 = NULL, *fp_top3 = NULL; |
9bd92830 FM |
60 | long long int ttnbytes=0, ttnacc=0, tnacc=0; |
61 | long long int tnbytes=0, ttnelap=0, tnelap=0; | |
62 | long long int tnincache=0, tnoucache=0, ttnincache=0, ttnoucache=0; | |
63 | long long int nbytes; | |
64 | long long int nacc; | |
65 | long long int elap, incac, oucac; | |
66 | double perc=0.00; | |
67 | double perc2=0.00; | |
68 | double inperc=0.00, ouperc=0.00; | |
69 | int posicao=0; | |
70 | char olduser[MAX_USER_LEN], csort[MAXLEN]; | |
71 | char wger[MAXLEN], top1[MAXLEN], top2[MAXLEN], top3[MAXLEN]; | |
124ec0b0 | 72 | char user[MAX_USER_LEN]; |
9bd92830 FM |
73 | const char *sfield="-n -k 2,2"; |
74 | const char *order; | |
75 | const char *sort_field; | |
76 | const char *sort_order; | |
77 | char title[80]; | |
78 | char *warea; | |
79 | int totuser=0; | |
80 | int topcount=0; | |
81 | int cstatus; | |
82 | struct getwordstruct gwarea; | |
83 | longline line; | |
84 | struct generalitemstruct item; | |
a58e6d54 | 85 | struct userinfostruct *uinfo; |
9bd92830 | 86 | |
b7413c4c FM |
87 | if (debugz>=LogLevel_Process) |
88 | debuga(_("Creating top users report...\n")); | |
9bd92830 FM |
89 | ntopuser = 0; |
90 | snprintf(wger,sizeof(wger),"%s/sarg-general",outdirname); | |
91 | if((fp_in=fopen(wger,"r"))==NULL) { | |
96dadc9f | 92 | debuga(_("Cannot open file \"%s\": %s\n"),wger,strerror(errno)); |
9bd92830 FM |
93 | exit(EXIT_FAILURE); |
94 | } | |
95 | ||
96 | snprintf(top2,sizeof(top2),"%s/top.tmp",outdirname); | |
97 | if((fp_top2=fopen(top2,"w"))==NULL) { | |
96dadc9f | 98 | debuga(_("Cannot open file \"%s\": %s\n"),top2,strerror(errno)); |
9bd92830 FM |
99 | exit(EXIT_FAILURE); |
100 | } | |
101 | ||
102 | olduser[0]='\0'; | |
103 | totuser=0; | |
104 | ||
105 | if ((line=longline_create())==NULL) { | |
106 | debuga(_("Not enough memory to read the file %s\n"),wger); | |
107 | exit(EXIT_FAILURE); | |
108 | } | |
109 | ||
110 | while((warea=longline_read(fp_in,line))!=NULL) { | |
111 | ger_read(warea,&item,wger); | |
112 | if(item.total) continue; | |
113 | if(strcmp(olduser,item.user) != 0) { | |
114 | totuser++; | |
115 | ||
116 | if (olduser[0] != '\0') { | |
117 | /* | |
118 | This complicated printf is due to Microsoft's inability to comply with any standard. Msvcrt is unable | |
119 | to print a long long int unless it is exactly 64-bits long. | |
120 | */ | |
121 | fprintf(fp_top2,"%s\t%"PRIu64"\t%"PRIu64"\t%"PRIu64"\t%"PRIu64"\t%"PRIu64"\n",olduser,(uint64_t)tnbytes,(uint64_t)tnacc,(uint64_t)tnelap,(uint64_t)tnincache,(uint64_t)tnoucache); | |
122 | ||
123 | ttnbytes+=tnbytes; | |
124 | ttnacc+=tnacc; | |
125 | ttnelap+=tnelap; | |
126 | ttnincache+=tnincache; | |
127 | ttnoucache+=tnoucache; | |
128 | } | |
129 | strcpy(olduser,item.user); | |
130 | tnbytes=0; | |
131 | tnacc=0; | |
132 | tnelap=0; | |
133 | tnincache=0; | |
134 | tnoucache=0; | |
135 | } | |
136 | ||
137 | tnbytes+=item.nbytes; | |
138 | tnacc+=item.nacc; | |
139 | tnelap+=item.nelap; | |
140 | tnincache+=item.incache; | |
141 | tnoucache+=item.oucache; | |
142 | } | |
204781f4 FM |
143 | if (fclose(fp_in)==EOF) { |
144 | debuga(_("Read error in \"%s\": %s\n"),wger,strerror(errno)); | |
145 | exit(EXIT_FAILURE); | |
146 | } | |
9bd92830 FM |
147 | longline_destroy(&line); |
148 | ||
149 | if (olduser[0] != '\0') { | |
150 | /* | |
151 | This complicated printf is due to Microsoft's inability to comply with any standard. Msvcrt is unable | |
152 | to print a long long int unless it is exactly 64-bits long. | |
153 | */ | |
154 | fprintf(fp_top2,"%s\t%"PRIu64"\t%"PRIu64"\t%"PRIu64"\t%"PRIu64"\t%"PRIu64"\n",olduser,(uint64_t)tnbytes,(uint64_t)tnacc,(uint64_t)tnelap,(uint64_t)tnincache,(uint64_t)tnoucache); | |
155 | ||
156 | ttnbytes+=tnbytes; | |
157 | ttnacc+=tnacc; | |
158 | ttnelap+=tnelap; | |
159 | ttnincache+=tnincache; | |
160 | ttnoucache+=tnoucache; | |
161 | } | |
507460ae | 162 | if (fclose(fp_top2)==EOF) { |
96dadc9f | 163 | debuga(_("Write error in \"%s\": %s\n"),top2,strerror(errno)); |
507460ae FM |
164 | exit(EXIT_FAILURE); |
165 | } | |
9bd92830 | 166 | |
9dc20988 FM |
167 | #ifdef ENABLE_DOUBLE_CHECK_DATA |
168 | if (ttnacc!=globstat.nacc || ttnbytes!=globstat.nbytes || ttnelap!=globstat.elap || | |
169 | ttnincache!=globstat.incache || ttnoucache!=globstat.oucache) { | |
170 | debuga(_("Total statistics mismatch when reading %s to produce the top users\n"),wger); | |
171 | exit(EXIT_FAILURE); | |
172 | } | |
173 | #endif | |
174 | ||
124ec0b0 FM |
175 | set_total_users(totuser); |
176 | ||
9bd92830 FM |
177 | if((TopuserSort & TOPUSER_SORT_USER) != 0) { |
178 | sfield="-k 1,1"; | |
179 | sort_field=_("user"); | |
180 | } else if((TopuserSort & TOPUSER_SORT_CONNECT) != 0) { | |
181 | sfield="-n -k 3,3"; | |
182 | sort_field=_("connect"); | |
183 | } else if((TopuserSort & TOPUSER_SORT_TIME) != 0) { | |
184 | sfield="-n -k 4,4"; | |
eb7ab620 | 185 | sort_field=pgettext("duration","time"); |
9bd92830 FM |
186 | } else { |
187 | sort_field=_("bytes"); | |
188 | } | |
189 | ||
190 | if((TopuserSort & TOPUSER_SORT_REVERSE) == 0) { | |
191 | order=""; | |
192 | sort_order=_("normal"); | |
193 | } else { | |
194 | order="-r"; | |
195 | sort_order=_("reverse"); | |
196 | } | |
197 | ||
198 | snprintf(top1,sizeof(top1),"%s/top",outdirname); | |
78eeb33f FM |
199 | if (snprintf(csort,sizeof(csort),"sort -T \"%s\" -t \"\t\" %s %s -o \"%s\" \"%s\"", tmp, order, sfield, top1, top2)>=sizeof(csort)) { |
200 | debuga(_("Sort command too long when sorting file \"%s\" to \"%s\"\n"),top2,top1); | |
201 | exit(EXIT_FAILURE); | |
202 | } | |
9bd92830 FM |
203 | cstatus=system(csort); |
204 | if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) { | |
205 | debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus)); | |
206 | debuga(_("sort command: %s\n"),csort); | |
207 | exit(EXIT_FAILURE); | |
208 | } | |
209 | ||
210 | if((fp_top1=fopen(top1,"r"))==NULL) { | |
96dadc9f | 211 | debuga(_("Cannot open file \"%s\": %s\n"),top1,strerror(errno)); |
9bd92830 FM |
212 | exit(EXIT_FAILURE); |
213 | } | |
214 | ||
11767c6a FM |
215 | if (!KeepTempLog && unlink(top2)) { |
216 | debuga(_("Cannot delete \"%s\": %s\n"),top2,strerror(errno)); | |
08f9b029 FM |
217 | exit(EXIT_FAILURE); |
218 | } | |
9bd92830 | 219 | |
56b97279 | 220 | snprintf(top3,sizeof(top3),"%s/"INDEX_HTML_FILE,outdirname); |
9bd92830 | 221 | if((fp_top3=fopen(top3,"w"))==NULL) { |
96dadc9f | 222 | debuga(_("Cannot open file \"%s\": %s\n"),top3,strerror(errno)); |
9bd92830 FM |
223 | exit(EXIT_FAILURE); |
224 | } | |
225 | ||
226 | snprintf(title,sizeof(title),_("SARG report for %s"),period.text); | |
227 | write_html_header(fp_top3,(IndexTree == INDEX_TREE_DATE) ? 3 : 1,title,HTML_JS_SORTTABLE); | |
228 | fputs("<tr><td class=\"header_c\">",fp_top3); | |
229 | fprintf(fp_top3,_("Period: %s"),period.html); | |
230 | fputs("</td></tr>\n",fp_top3); | |
124ec0b0 FM |
231 | if ((ReportType & REPORT_TYPE_TOPUSERS) != 0) { |
232 | fputs("<tr><td class=\"header_c\">",fp_top3); | |
233 | fprintf(fp_top3,_("Sort: %s, %s"),sort_field,sort_order); | |
234 | fputs("</td></tr>\n",fp_top3); | |
235 | fprintf(fp_top3,"<tr><th class=\"header_c\">%s</th></tr>\n",_("Top users")); | |
236 | } else { | |
237 | /* TRANSLATORS: This is the title of the main report page when no | |
238 | * top users list are requested. | |
239 | */ | |
240 | fprintf(fp_top3,"<tr><th class=\"header_c\">%s</th></tr>\n",_("Table of content")); | |
241 | } | |
9bd92830 FM |
242 | close_html_header(fp_top3); |
243 | ||
1219fb1a FM |
244 | if (!indexonly) { |
245 | fputs("<div class=\"report\"><table cellpadding=\"1\" cellspacing=\"2\">\n",fp_top3); | |
246 | if((ReportType & REPORT_TYPE_TOPSITES) != 0 && !Privacy) fprintf(fp_top3,"<tr><td class=\"link\" colspan=\"0\"><a href=\"topsites.html\">%s</a></td></tr>\n",_("Top sites")); | |
247 | if((ReportType & REPORT_TYPE_SITES_USERS) != 0 && !Privacy) fprintf(fp_top3,"<tr><td class=\"link\" colspan=\"0\"><a href=\"siteuser.html\">%s</a></td></tr>\n",_("Sites & Users")); | |
248 | if(dansguardian_count) fprintf(fp_top3,"<tr><td class=\"link\" colspan=\"0\"><a href=\"dansguardian.html\">%s</a></td></tr>\n",_("DansGuardian")); | |
330b1c52 | 249 | if(redirector_count) fprintf(fp_top3,"<tr><td class=\"link\" colspan=\"0\"><a href=\"redirector.html\">%s</a></td></tr>\n",_("Redirector")); |
11284535 | 250 | if (is_download()) fprintf(fp_top3,"<tr><td class=\"link\" colspan=\"0\"><a href=\"download.html\">%s</a></td></tr>\n",_("Downloads")); |
8e53b2e7 | 251 | if (is_denied()) fprintf(fp_top3,"<tr><td class=\"link\" colspan=\"0\"><a href=\"denied.html\">%s</a></td></tr>\n",_("Denied accesses")); |
16b013cc | 252 | if (is_authfail()) fprintf(fp_top3,"<tr><td class=\"link\" colspan=\"0\"><a href=\"authfail.html\">%s</a></td></tr>\n",_("Authentication Failures")); |
1219fb1a FM |
253 | if(smartfilter) fprintf(fp_top3,"<tr><td class=\"link\" colspan=\"0\"><a href=\"smartfilter.html\">%s</a></td></tr>\n",_("SmartFilter")); |
254 | if(UserAgentLog[0] != '\0' && useragent_count) fprintf(fp_top3,"<tr><td class=\"link\" colspan=\"0\"><a href=\"useragent.html\">%s</a></td></tr>\n",_("Useragent")); | |
255 | fputs("<tr><td></td></tr>\n</table></div>\n",fp_top3); | |
256 | } | |
9bd92830 FM |
257 | |
258 | if ((ReportType & REPORT_TYPE_TOPUSERS) == 0) { | |
259 | fputs("</body>\n</html>\n",fp_top3); | |
507460ae | 260 | if (fclose (fp_top3)==EOF) { |
96dadc9f | 261 | debuga(_("Write error in \"%s\": %s\n"),top3,strerror(errno)); |
507460ae FM |
262 | exit(EXIT_FAILURE); |
263 | } | |
cb59dc47 | 264 | if (debugz>=LogLevel_Process) debugaz(_("No top users report because it is not configured in report_type\n")); |
9bd92830 FM |
265 | return; |
266 | } | |
267 | ||
268 | fputs("<div class=\"report\"><table cellpadding=\"1\" cellspacing=\"2\"",fp_top3); | |
269 | if (SortTableJs[0]) | |
270 | fputs(" class=\"sortable\"",fp_top3); | |
271 | fputs(">\n<thead><tr>",fp_top3); | |
272 | ||
273 | if((TopUserFields & TOPUSERFIELDS_NUM) != 0) | |
274 | fprintf(fp_top3,"<th class=\"header_l\">%s</th>",_("NUM")); | |
1219fb1a | 275 | if((TopUserFields & TOPUSERFIELDS_DATE_TIME) !=0 && (ReportType & REPORT_TYPE_DATE_TIME) != 0 && !indexonly) { |
9bd92830 FM |
276 | fputs("<th class=\"header_l",fp_top3); |
277 | if (SortTableJs[0]) fputs(" sorttable_nosort",fp_top3); | |
278 | fputs("\"></th>",fp_top3); | |
279 | } | |
280 | if((TopUserFields & TOPUSERFIELDS_USERID) != 0) { | |
281 | fputs("<th class=\"header_l",fp_top3); | |
282 | if (SortTableJs[0]) fputs(" sorttable_alpha",fp_top3); | |
283 | fprintf(fp_top3,"\">%s</th>",_("USERID")); | |
284 | } | |
8e134f1a FM |
285 | if((TopUserFields & TOPUSERFIELDS_USERIP) != 0) { |
286 | fputs("<th class=\"header_l",fp_top3); | |
287 | if (SortTableJs[0]) fputs(" sorttable_alpha",fp_top3); | |
288 | fprintf(fp_top3,"\">%s</th>",_("USERIP")); | |
289 | } | |
9bd92830 FM |
290 | if((TopUserFields & TOPUSERFIELDS_CONNECT) != 0) |
291 | fprintf(fp_top3,"<th class=\"header_l\">%s</th>",_("CONNECT")); | |
292 | if((TopUserFields & TOPUSERFIELDS_BYTES) != 0) | |
293 | fprintf(fp_top3,"<th class=\"header_l\">%s</th>",_("BYTES")); | |
294 | if((TopUserFields & TOPUSERFIELDS_SETYB) != 0) | |
295 | fprintf(fp_top3,"<th class=\"header_l\">%%%s</th>",_("BYTES")); | |
296 | if((TopUserFields & TOPUSERFIELDS_IN_CACHE_OUT) != 0) | |
297 | fprintf(fp_top3,"<th class=\"header_c\" colspan=\"2\">%s</th><th style=\"display:none;\"></th>",_("IN-CACHE-OUT")); | |
298 | if((TopUserFields & TOPUSERFIELDS_USED_TIME) != 0) | |
299 | fprintf(fp_top3,"<th class=\"header_l\">%s</th>",_("ELAPSED TIME")); | |
300 | if((TopUserFields & TOPUSERFIELDS_MILISEC) != 0) | |
301 | fprintf(fp_top3,"<th class=\"header_l\">%s</th>",_("MILLISEC")); | |
302 | if((TopUserFields & TOPUSERFIELDS_PTIME) != 0) | |
eb7ab620 | 303 | fprintf(fp_top3,"<th class=\"header_l\">%%%s</th>",pgettext("duration","TIME")); |
9bd92830 FM |
304 | |
305 | fputs("</tr></thead>\n",fp_top3); | |
306 | ||
58c772bb FM |
307 | greport_prepare(); |
308 | ||
9bd92830 FM |
309 | ntopuser = 0; |
310 | ||
311 | if ((line=longline_create())==NULL) { | |
312 | debuga(_("Not enough memory to read the downloaded files\n")); | |
313 | exit(EXIT_FAILURE); | |
314 | } | |
315 | ||
316 | while((warea=longline_read(fp_top1,line))!=NULL) { | |
317 | getword_start(&gwarea,warea); | |
318 | if (getword(user,sizeof(user),&gwarea,'\t')<0) { | |
00d1f9ed | 319 | debuga(_("Invalid user in file \"%s\"\n"),top1); |
9bd92830 FM |
320 | exit(EXIT_FAILURE); |
321 | } | |
322 | if (getword_atoll(&nbytes,&gwarea,'\t')<0) { | |
00d1f9ed | 323 | debuga(_("Invalid number of bytes in file \"%s\"\n"),top1); |
9bd92830 FM |
324 | exit(EXIT_FAILURE); |
325 | } | |
326 | if (getword_atoll(&nacc,&gwarea,'\t')<0) { | |
00d1f9ed | 327 | debuga(_("Invalid number of accesses in file \"%s\"\n"),top1); |
9bd92830 FM |
328 | exit(EXIT_FAILURE); |
329 | } | |
330 | if (getword_atoll(&elap,&gwarea,'\t')<0) { | |
00d1f9ed | 331 | debuga(_("Invalid elapsed time in file \"%s\"\n"),top1); |
9bd92830 FM |
332 | exit(EXIT_FAILURE); |
333 | } | |
334 | if (getword_atoll(&incac,&gwarea,'\t')<0) { | |
00d1f9ed | 335 | debuga(_("Invalid in-cache size in file \"%s\"\n"),top1); |
9bd92830 FM |
336 | exit(EXIT_FAILURE); |
337 | } | |
338 | if (getword_atoll(&oucac,&gwarea,'\n')<0) { | |
00d1f9ed | 339 | debuga(_("Invalid out-of-cache size in file \"%s\"\n"),top1); |
9bd92830 FM |
340 | exit(EXIT_FAILURE); |
341 | } | |
342 | if(nacc < 1) | |
343 | continue; | |
344 | ntopuser = 1; | |
345 | if(TopUsersNum > 0 && topcount >= TopUsersNum) break; | |
346 | tnbytes=nbytes; | |
347 | tnelap=elap; | |
348 | ||
349 | uinfo=userinfo_find_from_id(user); | |
350 | if (!uinfo) { | |
00d1f9ed | 351 | debuga(_("Unknown user ID %s in file \"%s\"\n"),user,top1); |
9bd92830 FM |
352 | exit(EXIT_FAILURE); |
353 | } | |
a58e6d54 | 354 | uinfo->topuser=1; |
9bd92830 FM |
355 | |
356 | fputs("<tr>",fp_top3); | |
357 | ||
358 | posicao++; | |
359 | if((TopUserFields & TOPUSERFIELDS_NUM) != 0) | |
360 | fprintf(fp_top3,"<td class=\"data\">%d</td>",posicao); | |
361 | ||
1219fb1a FM |
362 | if (!indexonly) { |
363 | if((TopUserFields & TOPUSERFIELDS_DATE_TIME) !=0 && (ReportType & REPORT_TYPE_DATE_TIME) != 0) { | |
364 | fputs("<td class=\"data2\">",fp_top3); | |
25697a35 | 365 | #ifdef HAVE_GD |
1219fb1a | 366 | if(Graphs && GraphFont[0]!='\0') { |
e3e6aef4 | 367 | greport_day(uinfo); |
1219fb1a FM |
368 | //fprintf(fp_top3,"<a href=\"%s/graph_day.png\"><img src=\"%s/graph.png\" title=\"%s\" alt=\"G\"></a> ",uinfo->filename,ImageFile,_("Graphic")); |
369 | fprintf(fp_top3,"<a href=\"%s/graph.html\"><img src=\"%s/graph.png\" title=\"%s\" alt=\"G\"></a> ",uinfo->filename,ImageFile,_("Graphic")); | |
370 | } | |
25697a35 | 371 | #endif |
e3e6aef4 | 372 | report_day(uinfo); |
1219fb1a | 373 | fprintf(fp_top3,"<a href=\"%s/d%s.html\"><img src=\"%s/datetime.png\" title=\"%s\" alt=\"T\"></a></td>",uinfo->filename,uinfo->filename,ImageFile,_("date/time report")); |
e3e6aef4 | 374 | day_deletefile(uinfo); |
08f9b029 | 375 | } |
9bd92830 FM |
376 | } |
377 | if((TopUserFields & TOPUSERFIELDS_USERID) != 0) { | |
1219fb1a FM |
378 | if((ReportType & REPORT_TYPE_USERS_SITES) == 0 || indexonly) |
379 | fprintf(fp_top3,"<td class=\"data2\">%s</td>",uinfo->label); | |
9bd92830 FM |
380 | else |
381 | fprintf(fp_top3,"<td class=\"data2\"><a href=\"%s/%s.html\">%s</a></td>",uinfo->filename,uinfo->filename,uinfo->label); | |
382 | } | |
8e134f1a FM |
383 | if((TopUserFields & TOPUSERFIELDS_USERIP) != 0) { |
384 | fprintf(fp_top3,"<td class=\"data2\">%s</td>",uinfo->ip); | |
385 | } | |
9bd92830 FM |
386 | if((TopUserFields & TOPUSERFIELDS_CONNECT) != 0) { |
387 | fputs("<td class=\"data\"",fp_top3); | |
388 | if (SortTableJs[0]) fprintf(fp_top3," sorttable_customkey=\"%"PRId64"\"",(int64_t)nacc); | |
389 | fprintf(fp_top3,">%s</td>",fixnum(nacc,1)); | |
390 | } | |
391 | if((TopUserFields & TOPUSERFIELDS_BYTES) != 0) { | |
392 | fputs("<td class=\"data\"",fp_top3); | |
393 | if (SortTableJs[0]) fprintf(fp_top3," sorttable_customkey=\"%"PRId64"\"",(int64_t)tnbytes); | |
394 | fprintf(fp_top3,">%s</td>",fixnum(tnbytes,1)); | |
395 | } | |
396 | if((TopUserFields & TOPUSERFIELDS_SETYB) != 0) { | |
397 | perc=(ttnbytes) ? tnbytes * 100. / ttnbytes : 0.; | |
398 | fprintf(fp_top3,"<td class=\"data\">%3.2lf%%</td>",perc); | |
399 | } | |
400 | if((TopUserFields & TOPUSERFIELDS_IN_CACHE_OUT) != 0) { | |
401 | inperc=(tnbytes) ? incac * 100. / tnbytes : 0.; | |
402 | ouperc=(tnbytes) ? oucac * 100. / tnbytes : 0.; | |
403 | fprintf(fp_top3,"<td class=\"data\">%3.2lf%%</td><td class=\"data\">%3.2lf%%</td>",inperc,ouperc); | |
04a01ed3 | 404 | #ifdef ENABLE_DOUBLE_CHECK_DATA |
4e59f0a6 | 405 | if ((inperc!=0. || ouperc!=0.) && fabs(inperc+ouperc-100.)>=0.01) { |
9bd92830 FM |
406 | debuga(_("The total of the in-cache and cache-miss is not 100%% at position %d (user %s)\n"),posicao,uinfo->label); |
407 | } | |
04a01ed3 | 408 | #endif |
9bd92830 FM |
409 | } |
410 | if((TopUserFields & TOPUSERFIELDS_USED_TIME) != 0) { | |
411 | fputs("<td class=\"data\"",fp_top3); | |
412 | if (SortTableJs[0]) fprintf(fp_top3," sorttable_customkey=\"%"PRId64"\"",(int64_t)tnelap); | |
413 | fprintf(fp_top3,">%s</td>",buildtime(tnelap)); | |
414 | } | |
415 | if((TopUserFields & TOPUSERFIELDS_MILISEC) != 0) { | |
416 | fputs("<td class=\"data\"",fp_top3); | |
417 | if (SortTableJs[0]) fprintf(fp_top3," sorttable_customkey=\"%"PRId64"\"",(int64_t)tnelap); | |
418 | fprintf(fp_top3,">%s</td>",fixnum2(tnelap,1)); | |
419 | } | |
420 | if((TopUserFields & TOPUSERFIELDS_PTIME) != 0) { | |
421 | perc2=(ttnelap) ? elap * 100. / ttnelap : 0.; | |
422 | fprintf(fp_top3,"<td class=\"data\">%3.2lf%%</td>",perc2); | |
423 | } | |
424 | ||
425 | fputs("</tr>\n",fp_top3); | |
426 | ||
427 | topcount++; | |
428 | } | |
204781f4 FM |
429 | if (fclose(fp_top1)==EOF) { |
430 | debuga(_("Read error in \"%s\": %s\n"),top1,strerror(errno)); | |
431 | exit(EXIT_FAILURE); | |
432 | } | |
11767c6a FM |
433 | if (!KeepTempLog && unlink(top1)) { |
434 | debuga(_("Cannot delete \"%s\": %s\n"),top1,strerror(errno)); | |
08f9b029 FM |
435 | exit(EXIT_FAILURE); |
436 | } | |
9bd92830 FM |
437 | longline_destroy(&line); |
438 | ||
439 | if((TopUserFields & TOPUSERFIELDS_TOTAL) != 0) { | |
440 | fputs("<tfoot><tr>",fp_top3); | |
441 | if((TopUserFields & TOPUSERFIELDS_NUM) != 0) | |
442 | fputs("<td></td>",fp_top3); | |
1219fb1a | 443 | if((TopUserFields & TOPUSERFIELDS_DATE_TIME) !=0 && (ReportType & REPORT_TYPE_DATE_TIME) != 0 && !indexonly) |
9bd92830 | 444 | fputs("<td></td>",fp_top3); |
8e134f1a FM |
445 | if((TopUserFields & TOPUSERFIELDS_USERIP) != 0) |
446 | fprintf(fp_top3,"<th class=\"header_l\" colspan=\"2\">%s</th>",_("TOTAL")); | |
447 | else | |
448 | fprintf(fp_top3,"<th class=\"header_l\">%s</th>",_("TOTAL")); | |
9bd92830 FM |
449 | |
450 | if((TopUserFields & TOPUSERFIELDS_CONNECT) != 0) | |
451 | fprintf(fp_top3,"<th class=\"header_r\">%s</th>",fixnum(ttnacc,1)); | |
452 | if((TopUserFields & TOPUSERFIELDS_BYTES) != 0) | |
453 | fprintf(fp_top3,"<th class=\"header_r\">%15s</th>",fixnum(ttnbytes,1)); | |
454 | if((TopUserFields & TOPUSERFIELDS_SETYB) != 0) | |
455 | fputs("<td></td>",fp_top3); | |
456 | if((TopUserFields & TOPUSERFIELDS_IN_CACHE_OUT) != 0) | |
457 | { | |
458 | inperc=(ttnbytes) ? ttnincache * 100. / ttnbytes : 0.; | |
459 | ouperc=(ttnbytes) ? ttnoucache *100. / ttnbytes : 0.; | |
460 | fprintf(fp_top3,"<th class=\"header_r\">%3.2lf%%</th><th class=\"header_r\">%3.2lf%%</th>",inperc,ouperc); | |
04a01ed3 | 461 | #ifdef ENABLE_DOUBLE_CHECK_DATA |
9bd92830 FM |
462 | if (fabs(inperc+ouperc-100.)>=0.01) { |
463 | debuga(_("The total of the in-cache and cache-miss is not 100%%\n")); | |
464 | } | |
04a01ed3 | 465 | #endif |
9bd92830 FM |
466 | } |
467 | if((TopUserFields & TOPUSERFIELDS_USED_TIME) != 0) | |
468 | fprintf(fp_top3,"<th class=\"header_r\">%s</th>",buildtime(ttnelap)); | |
469 | if((TopUserFields & TOPUSERFIELDS_MILISEC) != 0) | |
470 | fprintf(fp_top3,"<th class=\"header_r\">%s</th>",fixnum2(ttnelap,1)); | |
471 | ||
472 | fputs("</tr>\n",fp_top3); | |
473 | } | |
58c772bb | 474 | greport_cleanup(); |
9bd92830 FM |
475 | |
476 | if(ntopuser && (TopUserFields & TOPUSERFIELDS_AVERAGE) != 0) { | |
477 | fputs("<tr>",fp_top3); | |
478 | if((TopUserFields & TOPUSERFIELDS_NUM) != 0) | |
479 | fputs("<td></td>",fp_top3); | |
1219fb1a | 480 | if((TopUserFields & TOPUSERFIELDS_DATE_TIME) !=0 && (ReportType & REPORT_TYPE_DATE_TIME) != 0 && !indexonly) |
9bd92830 | 481 | fputs("<td></td>",fp_top3); |
8e134f1a FM |
482 | if((TopUserFields & TOPUSERFIELDS_USERIP) != 0) |
483 | fprintf(fp_top3,"<th class=\"header_l\" colspan=\"2\">%s</th>",_("AVERAGE")); | |
484 | else | |
485 | fprintf(fp_top3,"<th class=\"header_l\">%s</th>",_("AVERAGE")); | |
9bd92830 FM |
486 | |
487 | if((TopUserFields & TOPUSERFIELDS_CONNECT) != 0) | |
488 | fprintf(fp_top3,"<th class=\"header_r\">%s</th>",fixnum(ttnacc/totuser,1)); | |
489 | if((TopUserFields & TOPUSERFIELDS_BYTES) != 0) { | |
490 | tnbytes=(totuser) ? ttnbytes / totuser : 0; | |
491 | fprintf(fp_top3,"<th class=\"header_r\">%15s</th>",fixnum(tnbytes,1)); | |
492 | } | |
493 | if((TopUserFields & TOPUSERFIELDS_SETYB) != 0) | |
494 | fputs("<td></td>",fp_top3); | |
495 | if((TopUserFields & TOPUSERFIELDS_IN_CACHE_OUT) != 0) | |
496 | fputs("<td></td><td></td>",fp_top3); | |
497 | if((TopUserFields & TOPUSERFIELDS_USED_TIME) != 0) | |
498 | fprintf(fp_top3,"<th class=\"header_r\">%s</th>",buildtime(ttnelap/totuser)); | |
499 | if((TopUserFields & TOPUSERFIELDS_MILISEC) != 0) | |
500 | fprintf(fp_top3,"<th class=\"header_r\">%s</th>",fixnum2(ttnelap/totuser,1)); | |
501 | fputs("</tr></tfoot>\n",fp_top3); | |
502 | } | |
503 | ||
504 | fputs("</table></div>\n",fp_top3); | |
342bd723 | 505 | write_html_trailer(fp_top3); |
507460ae | 506 | if (fclose(fp_top3)==EOF) { |
96dadc9f | 507 | debuga(_("Write error in \"%s\": %s\n"),top3,strerror(errno)); |
507460ae FM |
508 | exit(EXIT_FAILURE); |
509 | } | |
9bd92830 | 510 | |
9bd92830 | 511 | return; |
25697a35 | 512 | } |