]> git.ipfire.org Git - thirdparty/sarg.git/blame - topuser.c
Fix a redirector issue
[thirdparty/sarg.git] / topuser.c
CommitLineData
25697a35 1/*
94ff9470 2 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
e99bf0c0 3 * 1998, 2013
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 30extern struct globalstatstruct globstat;
9dc20988 31
124ec0b0
FM
32/*!
33Save the total number of users. The number is written in sarg-users and set
34in a global variable for further reference.
35
36\param totuser The total number of users.
37*/
38static void set_total_users(int totuser)
39{
40 char tusr[1024];
41 FILE *fp_ou;
42
43 snprintf(tusr,sizeof(tusr),"%s/sarg-users",outdirname);
44 if((fp_ou=fopen(tusr,"w"))==NULL) {
45 debuga(_("(topuser) Cannot open file %s\n"),tusr);
46 exit(EXIT_FAILURE);
47 }
48 fprintf(fp_ou,"%d\n",totuser);
49 if (fclose(fp_ou)==EOF)
50 debuga(_("Failed to close file %s - %s\n"),tusr,strerror(errno));
51 globstat.totuser=totuser;
52}
53
32e71fa4 54void topuser(void)
25697a35 55{
124ec0b0 56 FILE *fp_in = NULL, *fp_top1 = NULL, *fp_top2 = NULL, *fp_top3 = NULL;
9bd92830
FM
57 long long int ttnbytes=0, ttnacc=0, tnacc=0;
58 long long int tnbytes=0, ttnelap=0, tnelap=0;
59 long long int tnincache=0, tnoucache=0, ttnincache=0, ttnoucache=0;
60 long long int nbytes;
61 long long int nacc;
62 long long int elap, incac, oucac;
63 double perc=0.00;
64 double perc2=0.00;
65 double inperc=0.00, ouperc=0.00;
66 int posicao=0;
67 char olduser[MAX_USER_LEN], csort[MAXLEN];
68 char wger[MAXLEN], top1[MAXLEN], top2[MAXLEN], top3[MAXLEN];
124ec0b0 69 char user[MAX_USER_LEN];
9bd92830
FM
70 const char *sfield="-n -k 2,2";
71 const char *order;
72 const char *sort_field;
73 const char *sort_order;
74 char title[80];
75 char *warea;
76 int totuser=0;
77 int topcount=0;
78 int cstatus;
79 struct getwordstruct gwarea;
80 longline line;
81 struct generalitemstruct item;
a58e6d54 82 struct userinfostruct *uinfo;
9bd92830 83
9bd92830
FM
84 ntopuser = 0;
85 snprintf(wger,sizeof(wger),"%s/sarg-general",outdirname);
86 if((fp_in=fopen(wger,"r"))==NULL) {
87 debuga(_("(topuser) Cannot open file %s\n"),wger);
88 exit(EXIT_FAILURE);
89 }
90
91 snprintf(top2,sizeof(top2),"%s/top.tmp",outdirname);
92 if((fp_top2=fopen(top2,"w"))==NULL) {
93 debuga(_("(topuser) Cannot open file %s\n"),top2);
94 exit(EXIT_FAILURE);
95 }
96
97 olduser[0]='\0';
98 totuser=0;
99
100 if ((line=longline_create())==NULL) {
101 debuga(_("Not enough memory to read the file %s\n"),wger);
102 exit(EXIT_FAILURE);
103 }
104
105 while((warea=longline_read(fp_in,line))!=NULL) {
106 ger_read(warea,&item,wger);
107 if(item.total) continue;
108 if(strcmp(olduser,item.user) != 0) {
109 totuser++;
110
111 if (olduser[0] != '\0') {
112 /*
113 This complicated printf is due to Microsoft's inability to comply with any standard. Msvcrt is unable
114 to print a long long int unless it is exactly 64-bits long.
115 */
116 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);
117
118 ttnbytes+=tnbytes;
119 ttnacc+=tnacc;
120 ttnelap+=tnelap;
121 ttnincache+=tnincache;
122 ttnoucache+=tnoucache;
123 }
124 strcpy(olduser,item.user);
125 tnbytes=0;
126 tnacc=0;
127 tnelap=0;
128 tnincache=0;
129 tnoucache=0;
130 }
131
132 tnbytes+=item.nbytes;
133 tnacc+=item.nacc;
134 tnelap+=item.nelap;
135 tnincache+=item.incache;
136 tnoucache+=item.oucache;
137 }
138 fclose(fp_in);
139 longline_destroy(&line);
140
141 if (olduser[0] != '\0') {
142 /*
143 This complicated printf is due to Microsoft's inability to comply with any standard. Msvcrt is unable
144 to print a long long int unless it is exactly 64-bits long.
145 */
146 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);
147
148 ttnbytes+=tnbytes;
149 ttnacc+=tnacc;
150 ttnelap+=tnelap;
151 ttnincache+=tnincache;
152 ttnoucache+=tnoucache;
153 }
154 fclose(fp_top2);
155
9dc20988
FM
156#ifdef ENABLE_DOUBLE_CHECK_DATA
157 if (ttnacc!=globstat.nacc || ttnbytes!=globstat.nbytes || ttnelap!=globstat.elap ||
158 ttnincache!=globstat.incache || ttnoucache!=globstat.oucache) {
159 debuga(_("Total statistics mismatch when reading %s to produce the top users\n"),wger);
160 exit(EXIT_FAILURE);
161 }
162#endif
163
124ec0b0
FM
164 set_total_users(totuser);
165
9bd92830
FM
166 if((TopuserSort & TOPUSER_SORT_USER) != 0) {
167 sfield="-k 1,1";
168 sort_field=_("user");
169 } else if((TopuserSort & TOPUSER_SORT_CONNECT) != 0) {
170 sfield="-n -k 3,3";
171 sort_field=_("connect");
172 } else if((TopuserSort & TOPUSER_SORT_TIME) != 0) {
173 sfield="-n -k 4,4";
174 sort_field=_("time");
175 } else {
176 sort_field=_("bytes");
177 }
178
179 if((TopuserSort & TOPUSER_SORT_REVERSE) == 0) {
180 order="";
181 sort_order=_("normal");
182 } else {
183 order="-r";
184 sort_order=_("reverse");
185 }
186
187 snprintf(top1,sizeof(top1),"%s/top",outdirname);
78eeb33f
FM
188 if (snprintf(csort,sizeof(csort),"sort -T \"%s\" -t \"\t\" %s %s -o \"%s\" \"%s\"", tmp, order, sfield, top1, top2)>=sizeof(csort)) {
189 debuga(_("Sort command too long when sorting file \"%s\" to \"%s\"\n"),top2,top1);
190 exit(EXIT_FAILURE);
191 }
9bd92830
FM
192 cstatus=system(csort);
193 if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
194 debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus));
195 debuga(_("sort command: %s\n"),csort);
196 exit(EXIT_FAILURE);
197 }
198
199 if((fp_top1=fopen(top1,"r"))==NULL) {
200 debuga(_("(topuser) Cannot open file %s\n"),top1);
201 exit(EXIT_FAILURE);
202 }
203
11767c6a
FM
204 if (!KeepTempLog && unlink(top2)) {
205 debuga(_("Cannot delete \"%s\": %s\n"),top2,strerror(errno));
08f9b029
FM
206 exit(EXIT_FAILURE);
207 }
9bd92830
FM
208
209 snprintf(top3,sizeof(top3),"%s/index.html",outdirname);
210 if((fp_top3=fopen(top3,"w"))==NULL) {
211 debuga(_("(topuser) Cannot open file %s\n"),top3);
212 exit(EXIT_FAILURE);
213 }
214
215 snprintf(title,sizeof(title),_("SARG report for %s"),period.text);
216 write_html_header(fp_top3,(IndexTree == INDEX_TREE_DATE) ? 3 : 1,title,HTML_JS_SORTTABLE);
217 fputs("<tr><td class=\"header_c\">",fp_top3);
218 fprintf(fp_top3,_("Period: %s"),period.html);
219 fputs("</td></tr>\n",fp_top3);
124ec0b0
FM
220 if ((ReportType & REPORT_TYPE_TOPUSERS) != 0) {
221 fputs("<tr><td class=\"header_c\">",fp_top3);
222 fprintf(fp_top3,_("Sort: %s, %s"),sort_field,sort_order);
223 fputs("</td></tr>\n",fp_top3);
224 fprintf(fp_top3,"<tr><th class=\"header_c\">%s</th></tr>\n",_("Top users"));
225 } else {
226 /* TRANSLATORS: This is the title of the main report page when no
227 * top users list are requested.
228 */
229 fprintf(fp_top3,"<tr><th class=\"header_c\">%s</th></tr>\n",_("Table of content"));
230 }
9bd92830
FM
231 close_html_header(fp_top3);
232
1219fb1a
FM
233 if (!indexonly) {
234 fputs("<div class=\"report\"><table cellpadding=\"1\" cellspacing=\"2\">\n",fp_top3);
235 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"));
236 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"));
237 if(dansguardian_count) fprintf(fp_top3,"<tr><td class=\"link\" colspan=\"0\"><a href=\"dansguardian.html\">%s</a></td></tr>\n",_("DansGuardian"));
330b1c52 238 if(redirector_count) fprintf(fp_top3,"<tr><td class=\"link\" colspan=\"0\"><a href=\"redirector.html\">%s</a></td></tr>\n",_("Redirector"));
1219fb1a
FM
239 if ((ReportType & REPORT_TYPE_DOWNLOADS) != 0 && download_count && !Privacy && ndownload) fprintf(fp_top3,"<tr><td class=\"link\" colspan=\"0\"><a href=\"download.html\">%s</a></td></tr>\n",_("Downloads"));
240 if ((ReportType & REPORT_TYPE_DENIED) != 0 && denied_count && !Privacy) fprintf(fp_top3,"<tr><td class=\"link\" colspan=\"0\"><a href=\"denied.html\">%s</a></td></tr>\n",_("Denied accesses"));
241 if ((ReportType & REPORT_TYPE_AUTH_FAILURES) != 0 && authfail_count && !Privacy) fprintf(fp_top3,"<tr><td class=\"link\" colspan=\"0\"><a href=\"authfail.html\">%s</a></td></tr>\n",_("Authentication Failures"));
242 if(smartfilter) fprintf(fp_top3,"<tr><td class=\"link\" colspan=\"0\"><a href=\"smartfilter.html\">%s</a></td></tr>\n",_("SmartFilter"));
243 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"));
244 fputs("<tr><td></td></tr>\n</table></div>\n",fp_top3);
245 }
9bd92830
FM
246
247 if ((ReportType & REPORT_TYPE_TOPUSERS) == 0) {
248 fputs("</body>\n</html>\n",fp_top3);
249 fclose (fp_top3);
9f93fec3 250 if (debugz) debugaz(_("No top users report because it is not configured in report_type\n"));
9bd92830
FM
251 return;
252 }
253
254 fputs("<div class=\"report\"><table cellpadding=\"1\" cellspacing=\"2\"",fp_top3);
255 if (SortTableJs[0])
256 fputs(" class=\"sortable\"",fp_top3);
257 fputs(">\n<thead><tr>",fp_top3);
258
259 if((TopUserFields & TOPUSERFIELDS_NUM) != 0)
260 fprintf(fp_top3,"<th class=\"header_l\">%s</th>",_("NUM"));
1219fb1a 261 if((TopUserFields & TOPUSERFIELDS_DATE_TIME) !=0 && (ReportType & REPORT_TYPE_DATE_TIME) != 0 && !indexonly) {
9bd92830
FM
262 fputs("<th class=\"header_l",fp_top3);
263 if (SortTableJs[0]) fputs(" sorttable_nosort",fp_top3);
264 fputs("\"></th>",fp_top3);
265 }
266 if((TopUserFields & TOPUSERFIELDS_USERID) != 0) {
267 fputs("<th class=\"header_l",fp_top3);
268 if (SortTableJs[0]) fputs(" sorttable_alpha",fp_top3);
269 fprintf(fp_top3,"\">%s</th>",_("USERID"));
270 }
271 if((TopUserFields & TOPUSERFIELDS_CONNECT) != 0)
272 fprintf(fp_top3,"<th class=\"header_l\">%s</th>",_("CONNECT"));
273 if((TopUserFields & TOPUSERFIELDS_BYTES) != 0)
274 fprintf(fp_top3,"<th class=\"header_l\">%s</th>",_("BYTES"));
275 if((TopUserFields & TOPUSERFIELDS_SETYB) != 0)
276 fprintf(fp_top3,"<th class=\"header_l\">%%%s</th>",_("BYTES"));
277 if((TopUserFields & TOPUSERFIELDS_IN_CACHE_OUT) != 0)
278 fprintf(fp_top3,"<th class=\"header_c\" colspan=\"2\">%s</th><th style=\"display:none;\"></th>",_("IN-CACHE-OUT"));
279 if((TopUserFields & TOPUSERFIELDS_USED_TIME) != 0)
280 fprintf(fp_top3,"<th class=\"header_l\">%s</th>",_("ELAPSED TIME"));
281 if((TopUserFields & TOPUSERFIELDS_MILISEC) != 0)
282 fprintf(fp_top3,"<th class=\"header_l\">%s</th>",_("MILLISEC"));
283 if((TopUserFields & TOPUSERFIELDS_PTIME) != 0)
284 fprintf(fp_top3,"<th class=\"header_l\">%%%s</th>",_("TIME"));
285
286 fputs("</tr></thead>\n",fp_top3);
287
58c772bb
FM
288 greport_prepare();
289
9bd92830
FM
290 ntopuser = 0;
291
292 if ((line=longline_create())==NULL) {
293 debuga(_("Not enough memory to read the downloaded files\n"));
294 exit(EXIT_FAILURE);
295 }
296
297 while((warea=longline_read(fp_top1,line))!=NULL) {
298 getword_start(&gwarea,warea);
299 if (getword(user,sizeof(user),&gwarea,'\t')<0) {
300 debuga(_("There is a broken user in file %s\n"),top1);
301 exit(EXIT_FAILURE);
302 }
303 if (getword_atoll(&nbytes,&gwarea,'\t')<0) {
304 debuga(_("There is a broken number of bytes in file %s\n"),top1);
305 exit(EXIT_FAILURE);
306 }
307 if (getword_atoll(&nacc,&gwarea,'\t')<0) {
308 debuga(_("There is a broken number of access in file %s\n"),top1);
309 exit(EXIT_FAILURE);
310 }
311 if (getword_atoll(&elap,&gwarea,'\t')<0) {
312 debuga(_("There is a broken elpased time in file %s\n"),top1);
313 exit(EXIT_FAILURE);
314 }
315 if (getword_atoll(&incac,&gwarea,'\t')<0) {
316 debuga(_("There is a broken in-cache size in file %s\n"),top1);
317 exit(EXIT_FAILURE);
318 }
319 if (getword_atoll(&oucac,&gwarea,'\n')<0) {
320 debuga(_("There is a broken out-of-cache size in file %s\n"),top1);
321 exit(EXIT_FAILURE);
322 }
323 if(nacc < 1)
324 continue;
325 ntopuser = 1;
326 if(TopUsersNum > 0 && topcount >= TopUsersNum) break;
327 tnbytes=nbytes;
328 tnelap=elap;
329
330 uinfo=userinfo_find_from_id(user);
331 if (!uinfo) {
332 debuga(_("Unknown user ID %s in file %s\n"),user,top1);
333 exit(EXIT_FAILURE);
334 }
a58e6d54 335 uinfo->topuser=1;
9bd92830 336
58c772bb
FM
337 report_day(uinfo);
338 greport_day(uinfo);
339
9bd92830
FM
340 fputs("<tr>",fp_top3);
341
342 posicao++;
343 if((TopUserFields & TOPUSERFIELDS_NUM) != 0)
344 fprintf(fp_top3,"<td class=\"data\">%d</td>",posicao);
345
1219fb1a
FM
346 if (!indexonly) {
347 if((TopUserFields & TOPUSERFIELDS_DATE_TIME) !=0 && (ReportType & REPORT_TYPE_DATE_TIME) != 0) {
348 fputs("<td class=\"data2\">",fp_top3);
25697a35 349#ifdef HAVE_GD
1219fb1a
FM
350 if(Graphs && GraphFont[0]!='\0') {
351 //fprintf(fp_top3,"<a href=\"%s/graph_day.png\"><img src=\"%s/graph.png\" title=\"%s\" alt=\"G\"></a>&nbsp;",uinfo->filename,ImageFile,_("Graphic"));
352 fprintf(fp_top3,"<a href=\"%s/graph.html\"><img src=\"%s/graph.png\" title=\"%s\" alt=\"G\"></a>&nbsp;",uinfo->filename,ImageFile,_("Graphic"));
353 }
25697a35 354#endif
1219fb1a
FM
355 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"));
356 } else {
357 sprintf(val1,"%s/d%s.html",outdirname,uinfo->filename);
358 if (unlink(val1)) {
11767c6a 359 debuga(_("Cannot delete \"%s\": %s\n"),val1,strerror(errno));
1219fb1a
FM
360 exit(EXIT_FAILURE);
361 }
08f9b029 362 }
9bd92830
FM
363 }
364 if((TopUserFields & TOPUSERFIELDS_USERID) != 0) {
1219fb1a
FM
365 if((ReportType & REPORT_TYPE_USERS_SITES) == 0 || indexonly)
366 fprintf(fp_top3,"<td class=\"data2\">%s</td>",uinfo->label);
9bd92830
FM
367 else
368 fprintf(fp_top3,"<td class=\"data2\"><a href=\"%s/%s.html\">%s</a></td>",uinfo->filename,uinfo->filename,uinfo->label);
369 }
370 if((TopUserFields & TOPUSERFIELDS_CONNECT) != 0) {
371 fputs("<td class=\"data\"",fp_top3);
372 if (SortTableJs[0]) fprintf(fp_top3," sorttable_customkey=\"%"PRId64"\"",(int64_t)nacc);
373 fprintf(fp_top3,">%s</td>",fixnum(nacc,1));
374 }
375 if((TopUserFields & TOPUSERFIELDS_BYTES) != 0) {
376 fputs("<td class=\"data\"",fp_top3);
377 if (SortTableJs[0]) fprintf(fp_top3," sorttable_customkey=\"%"PRId64"\"",(int64_t)tnbytes);
378 fprintf(fp_top3,">%s</td>",fixnum(tnbytes,1));
379 }
380 if((TopUserFields & TOPUSERFIELDS_SETYB) != 0) {
381 perc=(ttnbytes) ? tnbytes * 100. / ttnbytes : 0.;
382 fprintf(fp_top3,"<td class=\"data\">%3.2lf%%</td>",perc);
383 }
384 if((TopUserFields & TOPUSERFIELDS_IN_CACHE_OUT) != 0) {
385 inperc=(tnbytes) ? incac * 100. / tnbytes : 0.;
386 ouperc=(tnbytes) ? oucac * 100. / tnbytes : 0.;
387 fprintf(fp_top3,"<td class=\"data\">%3.2lf%%</td><td class=\"data\">%3.2lf%%</td>",inperc,ouperc);
04a01ed3 388#ifdef ENABLE_DOUBLE_CHECK_DATA
4e59f0a6 389 if ((inperc!=0. || ouperc!=0.) && fabs(inperc+ouperc-100.)>=0.01) {
9bd92830
FM
390 debuga(_("The total of the in-cache and cache-miss is not 100%% at position %d (user %s)\n"),posicao,uinfo->label);
391 }
04a01ed3 392#endif
9bd92830
FM
393 }
394 if((TopUserFields & TOPUSERFIELDS_USED_TIME) != 0) {
395 fputs("<td class=\"data\"",fp_top3);
396 if (SortTableJs[0]) fprintf(fp_top3," sorttable_customkey=\"%"PRId64"\"",(int64_t)tnelap);
397 fprintf(fp_top3,">%s</td>",buildtime(tnelap));
398 }
399 if((TopUserFields & TOPUSERFIELDS_MILISEC) != 0) {
400 fputs("<td class=\"data\"",fp_top3);
401 if (SortTableJs[0]) fprintf(fp_top3," sorttable_customkey=\"%"PRId64"\"",(int64_t)tnelap);
402 fprintf(fp_top3,">%s</td>",fixnum2(tnelap,1));
403 }
404 if((TopUserFields & TOPUSERFIELDS_PTIME) != 0) {
405 perc2=(ttnelap) ? elap * 100. / ttnelap : 0.;
406 fprintf(fp_top3,"<td class=\"data\">%3.2lf%%</td>",perc2);
407 }
408
409 fputs("</tr>\n",fp_top3);
410
411 topcount++;
412 }
413 fclose(fp_top1);
11767c6a
FM
414 if (!KeepTempLog && unlink(top1)) {
415 debuga(_("Cannot delete \"%s\": %s\n"),top1,strerror(errno));
08f9b029
FM
416 exit(EXIT_FAILURE);
417 }
9bd92830
FM
418 longline_destroy(&line);
419
420 if((TopUserFields & TOPUSERFIELDS_TOTAL) != 0) {
421 fputs("<tfoot><tr>",fp_top3);
422 if((TopUserFields & TOPUSERFIELDS_NUM) != 0)
423 fputs("<td></td>",fp_top3);
1219fb1a 424 if((TopUserFields & TOPUSERFIELDS_DATE_TIME) !=0 && (ReportType & REPORT_TYPE_DATE_TIME) != 0 && !indexonly)
9bd92830
FM
425 fputs("<td></td>",fp_top3);
426 fprintf(fp_top3,"<th class=\"header_l\">%s</th>",_("TOTAL"));
427
428 if((TopUserFields & TOPUSERFIELDS_CONNECT) != 0)
429 fprintf(fp_top3,"<th class=\"header_r\">%s</th>",fixnum(ttnacc,1));
430 if((TopUserFields & TOPUSERFIELDS_BYTES) != 0)
431 fprintf(fp_top3,"<th class=\"header_r\">%15s</th>",fixnum(ttnbytes,1));
432 if((TopUserFields & TOPUSERFIELDS_SETYB) != 0)
433 fputs("<td></td>",fp_top3);
434 if((TopUserFields & TOPUSERFIELDS_IN_CACHE_OUT) != 0)
435 {
436 inperc=(ttnbytes) ? ttnincache * 100. / ttnbytes : 0.;
437 ouperc=(ttnbytes) ? ttnoucache *100. / ttnbytes : 0.;
438 fprintf(fp_top3,"<th class=\"header_r\">%3.2lf%%</th><th class=\"header_r\">%3.2lf%%</th>",inperc,ouperc);
04a01ed3 439#ifdef ENABLE_DOUBLE_CHECK_DATA
9bd92830
FM
440 if (fabs(inperc+ouperc-100.)>=0.01) {
441 debuga(_("The total of the in-cache and cache-miss is not 100%%\n"));
442 }
04a01ed3 443#endif
9bd92830
FM
444 }
445 if((TopUserFields & TOPUSERFIELDS_USED_TIME) != 0)
446 fprintf(fp_top3,"<th class=\"header_r\">%s</th>",buildtime(ttnelap));
447 if((TopUserFields & TOPUSERFIELDS_MILISEC) != 0)
448 fprintf(fp_top3,"<th class=\"header_r\">%s</th>",fixnum2(ttnelap,1));
449
450 fputs("</tr>\n",fp_top3);
451 }
58c772bb 452 greport_cleanup();
9bd92830
FM
453
454 if(ntopuser && (TopUserFields & TOPUSERFIELDS_AVERAGE) != 0) {
455 fputs("<tr>",fp_top3);
456 if((TopUserFields & TOPUSERFIELDS_NUM) != 0)
457 fputs("<td></td>",fp_top3);
1219fb1a 458 if((TopUserFields & TOPUSERFIELDS_DATE_TIME) !=0 && (ReportType & REPORT_TYPE_DATE_TIME) != 0 && !indexonly)
9bd92830
FM
459 fputs("<td></td>",fp_top3);
460 fprintf(fp_top3,"<th class=\"header_l\">%s</th>",_("AVERAGE"));
461
462 if((TopUserFields & TOPUSERFIELDS_CONNECT) != 0)
463 fprintf(fp_top3,"<th class=\"header_r\">%s</th>",fixnum(ttnacc/totuser,1));
464 if((TopUserFields & TOPUSERFIELDS_BYTES) != 0) {
465 tnbytes=(totuser) ? ttnbytes / totuser : 0;
466 fprintf(fp_top3,"<th class=\"header_r\">%15s</th>",fixnum(tnbytes,1));
467 }
468 if((TopUserFields & TOPUSERFIELDS_SETYB) != 0)
469 fputs("<td></td>",fp_top3);
470 if((TopUserFields & TOPUSERFIELDS_IN_CACHE_OUT) != 0)
471 fputs("<td></td><td></td>",fp_top3);
472 if((TopUserFields & TOPUSERFIELDS_USED_TIME) != 0)
473 fprintf(fp_top3,"<th class=\"header_r\">%s</th>",buildtime(ttnelap/totuser));
474 if((TopUserFields & TOPUSERFIELDS_MILISEC) != 0)
475 fprintf(fp_top3,"<th class=\"header_r\">%s</th>",fixnum2(ttnelap/totuser,1));
476 fputs("</tr></tfoot>\n",fp_top3);
477 }
478
479 fputs("</table></div>\n",fp_top3);
480 if (write_html_trailer(fp_top3)<0)
481 debuga(_("Write error in top user list %s\n"),top3);
482 if (fclose(fp_top3)==EOF)
483 debuga(_("Failed to close the top user list %s - %s\n"),top3,strerror(errno));
484
9bd92830 485 return;
25697a35 486}