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