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