]> git.ipfire.org Git - thirdparty/sarg.git/blobdiff - topuser.c
Indent the configure script for more readability.
[thirdparty/sarg.git] / topuser.c
index c4ee9568d337368954b28ee36b9f15f060ee507f..42a5f4976cb36ed87fee84f268831967b9cd00d6 100644 (file)
--- a/topuser.c
+++ b/topuser.c
@@ -1,6 +1,6 @@
 /*
  * SARG Squid Analysis Report Generator      http://sarg.sourceforge.net
- *                                                            1998, 2011
+ *                                                            1998, 2015
  *
  * SARG donations:
  *      please look at http://sarg.sourceforge.net/donations.php
 
 #include "include/conf.h"
 #include "include/defs.h"
+#include "include/filelist.h"
 
-#ifdef ENABLE_DOUBLE_CHECK_DATA
 extern struct globalstatstruct globstat;
-#endif
+extern bool smartfilter;
+extern FileListObject UserAgentLog;
+
+/*!
+Save the total number of users. The number is written in sarg-users and set
+in a global variable for further reference.
+
+\param totuser The total number of users.
+*/
+static void set_total_users(int totuser)
+{
+       char tusr[1024];
+       FILE *fp_ou;
+
+       snprintf(tusr,sizeof(tusr),"%s/sarg-users",outdirname);
+       if((fp_ou=fopen(tusr,"w"))==NULL) {
+               debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),tusr,strerror(errno));
+               exit(EXIT_FAILURE);
+       }
+       fprintf(fp_ou,"%d\n",totuser);
+       if (fclose(fp_ou)==EOF) {
+               debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),tusr,strerror(errno));
+               exit(EXIT_FAILURE);
+       }
+       globstat.totuser=totuser;
+}
 
 void topuser(void)
 {
-       FILE *fp_in = NULL, *fp_ou = NULL, *fp_top1 = NULL, *fp_top2 = NULL, *fp_top3 = NULL;
+       FileObject *fp_in = NULL;
+       FileObject *fp_top1 = NULL;
+       FILE *fp_top2 = NULL, *fp_top3 = NULL;
        long long int ttnbytes=0, ttnacc=0, tnacc=0;
        long long int tnbytes=0, ttnelap=0, tnelap=0;
        long long int tnincache=0, tnoucache=0, ttnincache=0, ttnoucache=0;
@@ -46,8 +73,7 @@ void topuser(void)
        int posicao=0;
        char olduser[MAX_USER_LEN], csort[MAXLEN];
        char wger[MAXLEN], top1[MAXLEN], top2[MAXLEN], top3[MAXLEN];
-       char user[MAX_USER_LEN], tusr[MAXLEN];
-       char ipantes[MAXLEN], nameantes[MAXLEN];
+       char user[MAX_USER_LEN];
        const char *sfield="-n -k 2,2";
        const char *order;
        const char *sort_field;
@@ -60,21 +86,20 @@ void topuser(void)
        struct getwordstruct gwarea;
        longline line;
        struct generalitemstruct item;
-       const struct userinfostruct *uinfo;
-
-       ipantes[0]='\0';
-       nameantes[0]='\0';
+       struct userinfostruct *uinfo;
 
+       if (debugz>=LogLevel_Process)
+               debuga(__FILE__,__LINE__,_("Creating top users report...\n"));
        ntopuser = 0;
        snprintf(wger,sizeof(wger),"%s/sarg-general",outdirname);
-       if((fp_in=fopen(wger,"r"))==NULL) {
-               debuga(_("(topuser) Cannot open file %s\n"),wger);
+       if((fp_in=FileObject_Open(wger))==NULL) {
+               debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),wger,FileObject_GetLastOpenError());
                exit(EXIT_FAILURE);
        }
 
        snprintf(top2,sizeof(top2),"%s/top.tmp",outdirname);
        if((fp_top2=fopen(top2,"w"))==NULL) {
-               debuga(_("(topuser) Cannot open file %s\n"),top2);
+               debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),top2,strerror(errno));
                exit(EXIT_FAILURE);
        }
 
@@ -82,7 +107,7 @@ void topuser(void)
        totuser=0;
 
        if ((line=longline_create())==NULL) {
-               debuga(_("Not enough memory to read the file %s\n"),wger);
+               debuga(__FILE__,__LINE__,_("Not enough memory to read file \"%s\"\n"),wger);
                exit(EXIT_FAILURE);
        }
 
@@ -119,7 +144,10 @@ void topuser(void)
                tnincache+=item.incache;
                tnoucache+=item.oucache;
        }
-       fclose(fp_in);
+       if (FileObject_Close(fp_in)) {
+               debuga(__FILE__,__LINE__,_("Read error in \"%s\": %s\n"),wger,FileObject_GetLastCloseError());
+               exit(EXIT_FAILURE);
+       }
        longline_destroy(&line);
 
        if (olduser[0] != '\0') {
@@ -135,16 +163,21 @@ void topuser(void)
                ttnincache+=tnincache;
                ttnoucache+=tnoucache;
        }
-       fclose(fp_top2);
+       if (fclose(fp_top2)==EOF) {
+               debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),top2,strerror(errno));
+               exit(EXIT_FAILURE);
+       }
 
 #ifdef ENABLE_DOUBLE_CHECK_DATA
        if (ttnacc!=globstat.nacc || ttnbytes!=globstat.nbytes || ttnelap!=globstat.elap ||
            ttnincache!=globstat.incache || ttnoucache!=globstat.oucache) {
-               debuga(_("Total statistics mismatch when reading %s to produce the top users\n"),wger);
+               debuga(__FILE__,__LINE__,_("Total statistics mismatch when reading \"%s\" to produce the top users\n"),wger);
                exit(EXIT_FAILURE);
        }
 #endif
 
+       set_total_users(totuser);
+
        if((TopuserSort & TOPUSER_SORT_USER) != 0) {
                sfield="-k 1,1";
                sort_field=_("user");
@@ -153,7 +186,7 @@ void topuser(void)
                sort_field=_("connect");
        } else if((TopuserSort & TOPUSER_SORT_TIME) != 0) {
                sfield="-n -k 4,4";
-               sort_field=_("time");
+               sort_field=pgettext("duration","time");
        } else {
                sort_field=_("bytes");
        }
@@ -167,27 +200,30 @@ void topuser(void)
        }
 
        snprintf(top1,sizeof(top1),"%s/top",outdirname);
-       sprintf(csort,"sort -T \"%s\" %s %s -o \"%s\" \"%s\"", tmp, order, sfield, top1, top2);
+       if (snprintf(csort,sizeof(csort),"sort -T \"%s\" -t \"\t\" %s %s -o \"%s\" \"%s\"", tmp, order, sfield, top1, top2)>=sizeof(csort)) {
+               debuga(__FILE__,__LINE__,_("Sort command too long when sorting file \"%s\" to \"%s\"\n"),top2,top1);
+               exit(EXIT_FAILURE);
+       }
        cstatus=system(csort);
        if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
-               debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus));
-               debuga(_("sort command: %s\n"),csort);
+               debuga(__FILE__,__LINE__,_("sort command return status %d\n"),WEXITSTATUS(cstatus));
+               debuga(__FILE__,__LINE__,_("sort command: %s\n"),csort);
                exit(EXIT_FAILURE);
        }
 
-       if((fp_top1=fopen(top1,"r"))==NULL) {
-               debuga(_("(topuser) Cannot open file %s\n"),top1);
+       if((fp_top1=FileObject_Open(top1))==NULL) {
+               debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),top1,FileObject_GetLastOpenError());
                exit(EXIT_FAILURE);
        }
 
-       if (unlink(top2)) {
-               debuga(_("Cannot delete %s - %s\n"),top2,strerror(errno));
+       if (!KeepTempLog && unlink(top2)) {
+               debuga(__FILE__,__LINE__,_("Cannot delete \"%s\": %s\n"),top2,strerror(errno));
                exit(EXIT_FAILURE);
        }
 
-       snprintf(top3,sizeof(top3),"%s/index.html",outdirname);
+       snprintf(top3,sizeof(top3),"%s/"INDEX_HTML_FILE,outdirname);
        if((fp_top3=fopen(top3,"w"))==NULL) {
-               debuga(_("(topuser) Cannot open file %s\n"),top3);
+               debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),top3,strerror(errno));
                exit(EXIT_FAILURE);
        }
 
@@ -196,10 +232,17 @@ void topuser(void)
        fputs("<tr><td class=\"header_c\">",fp_top3);
        fprintf(fp_top3,_("Period: %s"),period.html);
        fputs("</td></tr>\n",fp_top3);
-       fputs("<tr><td class=\"header_c\">",fp_top3);
-       fprintf(fp_top3,_("Sort: %s, %s"),sort_field,sort_order);
-       fputs("</td></tr>\n",fp_top3);
-       fprintf(fp_top3,"<tr><th class=\"header_c\">%s</th></tr>\n",_("Top users"));
+       if ((ReportType & REPORT_TYPE_TOPUSERS) != 0) {
+               fputs("<tr><td class=\"header_c\">",fp_top3);
+               fprintf(fp_top3,_("Sort: %s, %s"),sort_field,sort_order);
+               fputs("</td></tr>\n",fp_top3);
+               fprintf(fp_top3,"<tr><th class=\"header_c\">%s</th></tr>\n",_("Top users"));
+       } else {
+               /* TRANSLATORS: This is the title of the main report page when no
+                * top users list are requested.
+                */
+               fprintf(fp_top3,"<tr><th class=\"header_c\">%s</th></tr>\n",_("Table of content"));
+       }
        close_html_header(fp_top3);
 
        if (!indexonly) {
@@ -207,18 +250,22 @@ void topuser(void)
                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"));
                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"));
                if(dansguardian_count) fprintf(fp_top3,"<tr><td class=\"link\" colspan=\"0\"><a href=\"dansguardian.html\">%s</a></td></tr>\n",_("DansGuardian"));
-               if(squidguard_count) fprintf(fp_top3,"<tr><td class=\"link\" colspan=\"0\"><a href=\"redirector.html\">%s</a></td></tr>\n",_("Redirector"));
-               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"));
-               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"));
-               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"));
+               if(redirector_count) fprintf(fp_top3,"<tr><td class=\"link\" colspan=\"0\"><a href=\"redirector.html\">%s</a></td></tr>\n",_("Redirector"));
+               if (is_download()) fprintf(fp_top3,"<tr><td class=\"link\" colspan=\"0\"><a href=\"download.html\">%s</a></td></tr>\n",_("Downloads"));
+               if (is_denied()) fprintf(fp_top3,"<tr><td class=\"link\" colspan=\"0\"><a href=\"denied.html\">%s</a></td></tr>\n",_("Denied accesses"));
+               if (is_authfail()) fprintf(fp_top3,"<tr><td class=\"link\" colspan=\"0\"><a href=\"authfail.html\">%s</a></td></tr>\n",_("Authentication Failures"));
                if(smartfilter) fprintf(fp_top3,"<tr><td class=\"link\" colspan=\"0\"><a href=\"smartfilter.html\">%s</a></td></tr>\n",_("SmartFilter"));
-               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"));
+               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"));
                fputs("<tr><td></td></tr>\n</table></div>\n",fp_top3);
        }
 
        if ((ReportType & REPORT_TYPE_TOPUSERS) == 0) {
                fputs("</body>\n</html>\n",fp_top3);
-               fclose (fp_top3);
+               if (fclose (fp_top3)==EOF) {
+                       debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),top3,strerror(errno));
+                       exit(EXIT_FAILURE);
+               }
+               if (debugz>=LogLevel_Process) debugaz(__FILE__,__LINE__,_("No top users report because it is not configured in report_type\n"));
                return;
        }
 
@@ -239,6 +286,11 @@ void topuser(void)
                if (SortTableJs[0]) fputs(" sorttable_alpha",fp_top3);
                fprintf(fp_top3,"\">%s</th>",_("USERID"));
        }
+       if((TopUserFields & TOPUSERFIELDS_USERIP) != 0) {
+               fputs("<th class=\"header_l",fp_top3);
+               if (SortTableJs[0]) fputs(" sorttable_alpha",fp_top3);
+               fprintf(fp_top3,"\">%s</th>",_("USERIP"));
+       }
        if((TopUserFields & TOPUSERFIELDS_CONNECT) != 0)
                fprintf(fp_top3,"<th class=\"header_l\">%s</th>",_("CONNECT"));
        if((TopUserFields & TOPUSERFIELDS_BYTES) != 0)
@@ -252,41 +304,43 @@ void topuser(void)
        if((TopUserFields & TOPUSERFIELDS_MILISEC) != 0)
                fprintf(fp_top3,"<th class=\"header_l\">%s</th>",_("MILLISEC"));
        if((TopUserFields & TOPUSERFIELDS_PTIME) != 0)
-               fprintf(fp_top3,"<th class=\"header_l\">%%%s</th>",_("TIME"));
+               fprintf(fp_top3,"<th class=\"header_l\">%%%s</th>",pgettext("duration","TIME"));
 
        fputs("</tr></thead>\n",fp_top3);
 
+       greport_prepare();
+
        ntopuser = 0;
 
        if ((line=longline_create())==NULL) {
-               debuga(_("Not enough memory to read the downloaded files\n"));
+               debuga(__FILE__,__LINE__,_("Not enough memory to read file \"%s\"\n"),top1);
                exit(EXIT_FAILURE);
        }
 
        while((warea=longline_read(fp_top1,line))!=NULL) {
                getword_start(&gwarea,warea);
                if (getword(user,sizeof(user),&gwarea,'\t')<0) {
-                       debuga(_("There is a broken user in file %s\n"),top1);
+                       debuga(__FILE__,__LINE__,_("Invalid user in file \"%s\"\n"),top1);
                        exit(EXIT_FAILURE);
                }
                if (getword_atoll(&nbytes,&gwarea,'\t')<0) {
-                       debuga(_("There is a broken number of bytes in file %s\n"),top1);
+                       debuga(__FILE__,__LINE__,_("Invalid number of bytes in file \"%s\"\n"),top1);
                        exit(EXIT_FAILURE);
                }
                if (getword_atoll(&nacc,&gwarea,'\t')<0) {
-                       debuga(_("There is a broken number of access in file %s\n"),top1);
+                       debuga(__FILE__,__LINE__,_("Invalid number of accesses in file \"%s\"\n"),top1);
                        exit(EXIT_FAILURE);
                }
                if (getword_atoll(&elap,&gwarea,'\t')<0) {
-                       debuga(_("There is a broken elpased time in file %s\n"),top1);
+                       debuga(__FILE__,__LINE__,_("Invalid elapsed time in file \"%s\"\n"),top1);
                        exit(EXIT_FAILURE);
                }
                if (getword_atoll(&incac,&gwarea,'\t')<0) {
-                       debuga(_("There is a broken in-cache size in file %s\n"),top1);
+                       debuga(__FILE__,__LINE__,_("Invalid in-cache size in file \"%s\"\n"),top1);
                        exit(EXIT_FAILURE);
                }
                if (getword_atoll(&oucac,&gwarea,'\n')<0) {
-                       debuga(_("There is a broken out-of-cache size in file %s\n"),top1);
+                       debuga(__FILE__,__LINE__,_("Invalid out-of-cache size in file \"%s\"\n"),top1);
                        exit(EXIT_FAILURE);
                }
                if(nacc < 1)
@@ -298,9 +352,10 @@ void topuser(void)
 
                uinfo=userinfo_find_from_id(user);
                if (!uinfo) {
-                       debuga(_("Unknown user ID %s in file %s\n"),user,top1);
+                       debuga(__FILE__,__LINE__,_("Unknown user ID %s in file \"%s\"\n"),user,top1);
                        exit(EXIT_FAILURE);
                }
+               uinfo->topuser=1;
 
                fputs("<tr>",fp_top3);
 
@@ -313,17 +368,14 @@ void topuser(void)
                                fputs("<td class=\"data2\">",fp_top3);
 #ifdef HAVE_GD
                                if(Graphs && GraphFont[0]!='\0') {
+                                       greport_day(uinfo);
                                        //fprintf(fp_top3,"<a href=\"%s/graph_day.png\"><img src=\"%s/graph.png\" title=\"%s\" alt=\"G\"></a>&nbsp;",uinfo->filename,ImageFile,_("Graphic"));
                                        fprintf(fp_top3,"<a href=\"%s/graph.html\"><img src=\"%s/graph.png\" title=\"%s\" alt=\"G\"></a>&nbsp;",uinfo->filename,ImageFile,_("Graphic"));
                                }
 #endif
+                               report_day(uinfo);
                                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"));
-                       } else {
-                               sprintf(val1,"%s/d%s.html",outdirname,uinfo->filename);
-                               if (unlink(val1)) {
-                                       debuga(_("Cannot delete %s - %s\n"),val1,strerror(errno));
-                                       exit(EXIT_FAILURE);
-                               }
+                               day_deletefile(uinfo);
                        }
                }
                if((TopUserFields & TOPUSERFIELDS_USERID) != 0) {
@@ -332,6 +384,9 @@ void topuser(void)
                        else
                                fprintf(fp_top3,"<td class=\"data2\"><a href=\"%s/%s.html\">%s</a></td>",uinfo->filename,uinfo->filename,uinfo->label);
                }
+               if((TopUserFields & TOPUSERFIELDS_USERIP) != 0) {
+                       fprintf(fp_top3,"<td class=\"data2\">%s</td>",uinfo->ip);
+               }
                if((TopUserFields & TOPUSERFIELDS_CONNECT) != 0) {
                        fputs("<td class=\"data\"",fp_top3);
                        if (SortTableJs[0]) fprintf(fp_top3," sorttable_customkey=\"%"PRId64"\"",(int64_t)nacc);
@@ -351,8 +406,8 @@ void topuser(void)
                        ouperc=(tnbytes) ? oucac * 100. / tnbytes : 0.;
                        fprintf(fp_top3,"<td class=\"data\">%3.2lf%%</td><td class=\"data\">%3.2lf%%</td>",inperc,ouperc);
 #ifdef ENABLE_DOUBLE_CHECK_DATA
-                       if (fabs(inperc+ouperc-100.)>=0.01) {
-                               debuga(_("The total of the in-cache and cache-miss is not 100%% at position %d (user %s)\n"),posicao,uinfo->label);
+                       if ((inperc!=0. || ouperc!=0.) && fabs(inperc+ouperc-100.)>=0.01) {
+                               debuga(__FILE__,__LINE__,_("The total of the in-cache and cache-miss is not 100%% at position %d (user %s)\n"),posicao,uinfo->label);
                        }
 #endif
                }
@@ -375,9 +430,12 @@ void topuser(void)
 
                topcount++;
        }
-       fclose(fp_top1);
-       if (unlink(top1)) {
-               debuga(_("Cannot delete %s - %s\n"),top1,strerror(errno));
+       if (FileObject_Close(fp_top1)) {
+               debuga(__FILE__,__LINE__,_("Read error in \"%s\": %s\n"),top1,FileObject_GetLastCloseError());
+               exit(EXIT_FAILURE);
+       }
+       if (!KeepTempLog && unlink(top1)) {
+               debuga(__FILE__,__LINE__,_("Cannot delete \"%s\": %s\n"),top1,strerror(errno));
                exit(EXIT_FAILURE);
        }
        longline_destroy(&line);
@@ -388,7 +446,10 @@ void topuser(void)
                        fputs("<td></td>",fp_top3);
                if((TopUserFields & TOPUSERFIELDS_DATE_TIME) !=0 && (ReportType & REPORT_TYPE_DATE_TIME) != 0 && !indexonly)
                        fputs("<td></td>",fp_top3);
-               fprintf(fp_top3,"<th class=\"header_l\">%s</th>",_("TOTAL"));
+               if((TopUserFields & TOPUSERFIELDS_USERIP) != 0)
+                       fprintf(fp_top3,"<th class=\"header_l\" colspan=\"2\">%s</th>",_("TOTAL"));
+               else
+                       fprintf(fp_top3,"<th class=\"header_l\">%s</th>",_("TOTAL"));
 
                if((TopUserFields & TOPUSERFIELDS_CONNECT) != 0)
                        fprintf(fp_top3,"<th class=\"header_r\">%s</th>",fixnum(ttnacc,1));
@@ -403,7 +464,7 @@ void topuser(void)
                        fprintf(fp_top3,"<th class=\"header_r\">%3.2lf%%</th><th class=\"header_r\">%3.2lf%%</th>",inperc,ouperc);
 #ifdef ENABLE_DOUBLE_CHECK_DATA
                        if (fabs(inperc+ouperc-100.)>=0.01) {
-                               debuga(_("The total of the in-cache and cache-miss is not 100%%\n"));
+                               debuga(__FILE__,__LINE__,_("The total of the in-cache and cache-miss is not 100%%\n"));
                        }
 #endif
                }
@@ -414,6 +475,7 @@ void topuser(void)
 
                fputs("</tr>\n",fp_top3);
        }
+       greport_cleanup();
 
        if(ntopuser && (TopUserFields & TOPUSERFIELDS_AVERAGE) != 0) {
                fputs("<tr>",fp_top3);
@@ -421,7 +483,10 @@ void topuser(void)
                        fputs("<td></td>",fp_top3);
                if((TopUserFields & TOPUSERFIELDS_DATE_TIME) !=0 && (ReportType & REPORT_TYPE_DATE_TIME) != 0 && !indexonly)
                        fputs("<td></td>",fp_top3);
-               fprintf(fp_top3,"<th class=\"header_l\">%s</th>",_("AVERAGE"));
+               if((TopUserFields & TOPUSERFIELDS_USERIP) != 0)
+                       fprintf(fp_top3,"<th class=\"header_l\" colspan=\"2\">%s</th>",_("AVERAGE"));
+               else
+                       fprintf(fp_top3,"<th class=\"header_l\">%s</th>",_("AVERAGE"));
 
                if((TopUserFields & TOPUSERFIELDS_CONNECT) != 0)
                        fprintf(fp_top3,"<th class=\"header_r\">%s</th>",fixnum(ttnacc/totuser,1));
@@ -441,19 +506,11 @@ void topuser(void)
        }
 
        fputs("</table></div>\n",fp_top3);
-       if (write_html_trailer(fp_top3)<0)
-               debuga(_("Write error in top user list %s\n"),top3);
-       if (fclose(fp_top3)==EOF)
-               debuga(_("Failed to close the top user list %s - %s\n"),top3,strerror(errno));
-
-       snprintf(tusr,sizeof(tusr),"%s/sarg-users",outdirname);
-       if((fp_ou=fopen(tusr,"w"))==NULL) {
-               debuga(_("(topuser) Cannot open file %s\n"),tusr);
+       write_html_trailer(fp_top3);
+       if (fclose(fp_top3)==EOF) {
+               debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),top3,strerror(errno));
                exit(EXIT_FAILURE);
        }
-       fprintf(fp_ou,"%d\n",totuser);
-       if (fclose(fp_ou)==EOF)
-               debuga(_("Failed to close file %s - %s\n"),tusr,strerror(errno));
 
        return;
 }