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