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