]> git.ipfire.org Git - thirdparty/sarg.git/blobdiff - topuser.c
Be more consistent with the use of the temporary directory (i.e. always use /tmp...
[thirdparty/sarg.git] / topuser.c
index 29364047db5a75c1222cd82cc7bd4bd1cc75f122..444cfc2ac6bdb59c50fa5321057feac1be416477 100644 (file)
--- a/topuser.c
+++ b/topuser.c
@@ -1,10 +1,11 @@
 /*
- * AUTHOR: Pedro Lineu Orso                         pedro.orso@gmail.com
- *                                                            1998, 2008
  * SARG Squid Analysis Report Generator      http://sarg.sourceforge.net
+ *                                                            1998, 2010
  *
  * SARG donations:
  *      please look at http://sarg.sourceforge.net/donations.php
+ * Support:
+ *     http://sourceforge.net/projects/sarg/forums/forum/363374
  * ---------------------------------------------------------------------
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -33,631 +34,363 @@ void topuser(void)
    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;
-   float perc=0.00;
-   float perc2=0.00;
-   float inperc=0.00, ouperc=0.00;
+   long long int nbytes;
+   long long int nacc;
+   long long int elap, incac, oucac;
+   double perc=0.00;
+   double perc2=0.00;
+   double inperc=0.00, ouperc=0.00;
    int posicao=0;
-   char olduser[MAXLEN], csort[MAXLEN], period[MAXLEN], arqper[MAXLEN];
+   char olduser[MAX_USER_LEN], csort[MAXLEN];
    char wger[MAXLEN], top1[MAXLEN], top2[MAXLEN], top3[MAXLEN];
-   char user[MAXLEN], nacc[20], nbytes[20], preg[MAXLEN], tusr[MAXLEN];
-   char ip[MAXLEN], time[30], date[30], elap[30], incac[30], oucac[30];
+   char user[MAX_USER_LEN], tusr[MAXLEN];
    char ipantes[MAXLEN], nameantes[MAXLEN];
-   char sfield[10]="2,2";
-   char order[255]="-r";
-   char wheader[512]="";
+   const char *sfield="-n -k 2,2";
+   const char *order="-r";
+   char title[80];
+   char *warea;
    int  totuser=0;
    int  topcount=0;
-   char *s;
    int cstatus;
-   char warea[1500];
-   char user2[MAXLEN];
-   char name[MAXLEN];
+   struct getwordstruct gwarea;
+   longline line;
+   struct generalitemstruct item;
+   const struct userinfostruct *uinfo;
 
    ipantes[0]='\0';
    nameantes[0]='\0';
 
-   strcpy(wger,dirname);
-   strcpy(top1,dirname);
-   strcpy(top2,dirname);
-   strcpy(top3,dirname);
-   strcpy(tusr,dirname);
-   strcat(wger,"/sarg-general");
-   strcat(top1,"/top");
-   strcat(top2,"/top.tmp");
-   strcat(tusr,"/sarg-users");
-   strcat(top3,"/index.html");
-
    ntopuser = 0;
+   snprintf(wger,sizeof(wger),"%s/sarg-general",outdirname);
    if((fp_in=fopen(wger,"r"))==NULL) {
-    fprintf(stderr, "SARG: (topuser) %s: %s\n",text[45],wger);
-    exit(1);
+      debuga(_("(topuser) Cannot open file %s\n"),wger);
+      exit(EXIT_FAILURE);
    }
 
+   snprintf(top2,sizeof(top2),"%s/top.tmp",outdirname);
    if((fp_top2=fopen(top2,"w"))==NULL) {
-    fprintf(stderr, "SARG: (topuser) %s: %s\n",text[45],top2);
-    exit(1);
+      debuga(_("(topuser) Cannot open file %s\n"),top2);
+      exit(EXIT_FAILURE);
    }
 
-   //fscanf(fp_in,"%s%s%s%s%s%s%s%s%s%s",user,nacc,nbytes,url,ip,time,date,elap,incac,oucac);
-   fgets(warea,sizeof(warea),fp_in);
-   if (getword(user,sizeof(user),warea,' ')<0) {
-      printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wger);
-      exit(1);
-   }
+   olduser[0]='\0';
+   totuser=0;
 
-   strcpy(olduser,user);
-   totuser=1;
+   if ((line=longline_create())==NULL) {
+      debuga(_("Not enough memory to read the file %s\n"),wger);
+      exit(EXIT_FAILURE);
+   }
 
-   while(!feof(fp_in)) {
-      if (getword(nacc,sizeof(nacc),warea,' ')<0) {
-         printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wger);
-         exit(1);
-      }
-      if (getword(nbytes,sizeof(nbytes),warea,' ')<0) {
-         printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wger);
-         exit(1);
-      }
-      if (getword(url,sizeof(url),warea,' ')<0) {
-         printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wger);
-         exit(1);
-      }
-      if (getword(ip,sizeof(ip),warea,' ')<0) {
-         printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wger);
-         exit(1);
-      }
-      if (getword(time,sizeof(time),warea,' ')<0) {
-         printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wger);
-         exit(1);
-      }
-      if (getword(date,sizeof(date),warea,' ')<0) {
-         printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wger);
-         exit(1);
-      }
-      if (getword(elap,sizeof(elap),warea,' ')<0) {
-         printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wger);
-         exit(1);
-      }
-      if (getword(incac,sizeof(incac),warea,' ')<0) {
-         printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wger);
-         exit(1);
-      }
-      if (getword(oucac,sizeof(oucac),warea,' ')<0) {
-         printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wger);
-         exit(1);
-      }
-      if(strcmp(olduser,user) != 0) {
-         if(strcmp(user,"TOTAL") != 0)
-            totuser++;
-
-         my_lltoa(tnbytes,val1,15);
-         my_lltoa(tnacc,val2,15);
-         my_lltoa(tnelap,val3,15);
-         my_lltoa(tnincache,val4,15);
-         my_lltoa(tnoucache,val5,15);
-         fprintf(fp_top2,"%s %s %s %s %s %s\n",olduser,val1,val2,val3,val4,val5);
-
-         strcpy(olduser,user);
-         ttnbytes+=tnbytes;
-         ttnacc+=tnacc;
-         ttnelap+=tnelap;
-         ttnincache+=tnincache;
-         ttnoucache+=tnoucache;
+   while((warea=longline_read(fp_in,line))!=NULL) {
+      ger_read(warea,&item,wger);
+      if(item.total) continue;
+      if(strcmp(olduser,item.user) != 0) {
+         totuser++;
+
+         if (olduser[0] != '\0') {
+            /*
+            This complicated printf is due to Microsoft's inability to comply with any standard. Msvcrt is unable
+            to print a long long int unless it is exactly 64-bits long.
+            */
+            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);
+
+            ttnbytes+=tnbytes;
+            ttnacc+=tnacc;
+            ttnelap+=tnelap;
+            ttnincache+=tnincache;
+            ttnoucache+=tnoucache;
+         }
+         strcpy(olduser,item.user);
          tnbytes=0;
          tnacc=0;
-         tnelap=0; 
+         tnelap=0;
          tnincache=0;
          tnoucache=0;
       }
 
-      tnbytes+=my_atoll(nbytes);
-      tnacc+=my_atoll(nacc);
-      tnelap+=my_atoll(elap);
-      tnincache+=my_atoll(incac);
-      tnoucache+=my_atoll(oucac);
-
-      //fscanf(fp_in,"%s%s%s%s%s%s%s%s%s%s",user,nacc,nbytes,url,ip,time,date,elap,incac,oucac);
-      fgets(warea,sizeof(warea),fp_in);
-      if (getword(user,sizeof(user),warea,' ')<0) {
-         printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wger);
-         exit(1);
-      }
-
-      if(strcmp(user,"TOTAL") == 0)
-         continue;
+      tnbytes+=item.nbytes;
+      tnacc+=item.nacc;
+      tnelap+=item.nelap;
+      tnincache+=item.incache;
+      tnoucache+=item.oucache;
    }
-
-   my_lltoa(tnbytes,val1,15);
-   my_lltoa(tnacc,val2,15);
-   my_lltoa(tnelap,val3,15);
-   my_lltoa(tnincache,val4,15);
-   my_lltoa(tnoucache,val5,15);
-   fprintf(fp_top2,"%s %s %s %s %s %s\n",olduser,val1,val2,val3,val4,val5);
-
-   ttnbytes+=tnbytes;
-   ttnacc+=tnacc;
-   ttnelap+=tnelap;
-   ttnincache+=tnincache;
-   ttnoucache+=tnoucache;
-
-   my_lltoa(ttnbytes,val1,15);
-   my_lltoa(ttnacc,val2,15);
-   my_lltoa(ttnelap,val3,15);
-   my_lltoa(ttnincache,val4,15);
-   my_lltoa(ttnoucache,val5,15);
-   if (fp_in) fclose(fp_in);
-   if (fp_top2) fclose(fp_top2);
+   fclose(fp_in);
+   longline_destroy(&line);
+
+   if (olduser[0] != '\0') {
+      /*
+      This complicated printf is due to Microsoft's inability to comply with any standard. Msvcrt is unable
+      to print a long long int unless it is exactly 64-bits long.
+      */
+      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);
+
+      ttnbytes+=tnbytes;
+      ttnacc+=tnacc;
+      ttnelap+=tnelap;
+      ttnincache+=tnincache;
+      ttnoucache+=tnoucache;
+   }
+   fclose(fp_top2);
 
    strup(TopuserSortField);
    strlow(TopuserSortOrder);
 
    if(strcmp(TopuserSortField,"USER") == 0)
-      strcpy(sfield,"1,1");
+      sfield="-k 1,1";
 
    if(strcmp(TopuserSortField,"CONNECT") == 0)
-      strcpy(sfield,"3,3");
+      sfield="-n -k 3,3";
 
    if(strcmp(TopuserSortField,"TIME") == 0)
-      strcpy(sfield,"4,4");
+      sfield="-n -k 4,4";
 
    if(strcmp(TopuserSortOrder,"normal") == 0)
-      order[0]='\0';
+      order="";
 
-   sprintf(csort,"sort -n -T %s %s -k %s -o '%s' '%s'", TempDir, order, sfield, top1, top2);
+   snprintf(top1,sizeof(top1),"%s/top",outdirname);
+   sprintf(csort,"sort -T \"%s\" %s %s -o \"%s\" \"%s\"", tmp, order, sfield, top1, top2);
    cstatus=system(csort);
    if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
-      fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus));
-      fprintf(stderr, "SARG: sort command: %s\n",csort);
-      exit(1);
-   }
-   if((fp_top1=fopen(top1,"a"))==NULL) {
-      fprintf(stderr, "SARG: (topuser) %s: %s\n",text[45],top1);
-      fprintf(stderr, "SARG: sort command: %s\n",csort);
-      exit(1);
+      debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus));
+      debuga(_("sort command: %s\n"),csort);
+      exit(EXIT_FAILURE);
    }
 
-   unlink(top2);
-
-   fprintf(fp_top1,"TOTAL %s %s %s %s %s\n",val1,val2,val3,val4,val5);
-   fclose(fp_top1);
-
    if((fp_top1=fopen(top1,"r"))==NULL) {
-      fprintf(stderr, "SARG: (topuser) %s: %s\n",text[45],top1);
-      exit(1);
+      debuga(_("(topuser) Cannot open file %s\n"),top1);
+      exit(EXIT_FAILURE);
    }
 
-   if((fp_top3=fopen(top3,"w"))==NULL) {
-      fprintf(stderr, "SARG: (topuser) %s: %s\n",text[45],top3);
-      exit(1);
-   }
-
- /*
- * get period
- */
-
-   strcpy(arqper,dirname);
-   strcat(arqper,"/sarg-period");
+   unlink(top2);
 
-   if ((fp_in = fopen(arqper, "r")) == 0) {
-      fprintf(stderr, "SARG: (topuser) %s: %s\n",text[45],arqper);
-      exit(1);
+   snprintf(top3,sizeof(top3),"%s/index.html",outdirname);
+   if((fp_top3=fopen(top3,"w"))==NULL) {
+      debuga(_("(topuser) Cannot open file %s\n"),top3);
+      exit(EXIT_FAILURE);
    }
 
-   fgets(period,sizeof(period),fp_in);
-   fclose(fp_in);
-
-   fprintf(fp_top3, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<html>\n<head>\n  <meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\">\n",CharSet);
-   fputs("</head>\n",fp_top3);
-   css(fp_top3);
-   fprintf(fp_top3,"<body class=\"body\">");
-   if(strlen(LogoImage) > 0) fprintf(fp_top3, "<center><table cellpadding=\"0\" cellspacing=\"0\">\n<tr><th class=\"logo\"><img src='%s' border=0 align=absmiddle width=%s height=%s>&nbsp;%s</th></tr>\n<tr><td height=\"5\"></td></tr>\n</table>\n",LogoImage,Width,Height,LogoText);
-
-   if(strcmp(IndexTree,"date") == 0)
-      show_sarg(fp_top3, "../../..");
-   else
-      show_sarg(fp_top3, "..");
-   fputs("<center><table cellpadding=\"0\" cellspacing=\"0\">\n",fp_top3);
-   fprintf(fp_top3,"<tr><th align=\"center\" class=\"title\">%s</th></tr>\n",Title);
-
-   fprintf(fp_top3,"<tr><td class=\"header3\">%s: %s</td></tr>\n",text[89],period);
-   strcat(wheader,(char *)text[104]);
-   strcat(wheader,": ");
-   strcat(wheader,TopuserSortField);
-   strcat(wheader,", ");
-   strcat(wheader,TopuserSortOrder);
-   fprintf(fp_top3,"<tr><td class=\"header3\">%s</td></tr>\n",wheader);
-   fprintf(fp_top3,"<tr><th class=\"header3\">%s</th></tr>\n",text[137]);
-
-   fputs("</table></center>\n",fp_top3);
-   fputs("<center><table cellpadding=\"1\" cellspacing=\"2\">\n",fp_top3);
-   fputs("<tr><td><br></td><td></td></tr>\n",fp_top3);
-
-   if(strstr(ReportType,"topsites") != 0 && strcmp(Privacy,"yes") != 0) fprintf(fp_top3,"<tr><td class=\"link\" colspan=11><a href=\"topsites.html\"><font class=\"link\">%s</font></a><font class=\"text\"></font></td></tr>\n",text[119]);
-   if(strstr(ReportType,"sites_users") != 0 && strcmp(Privacy,"yes") != 0) fprintf(fp_top3,"<tr><td class=\"link\" colspan=11><a href=\"siteuser.html\"><font class=\"link\">%s</font></a><font class=\"text\"></font></td></tr>\n",text[85]);
-   if(dansguardian_count) fprintf(fp_top3,"<tr><td class=\"link\" colspan=11><a href=\"dansguardian.html\"><font class=\"link\">%s</font></a><font class=\"text\"></font></td></tr>\n",text[128]);
-   if(squidguard_count) fprintf(fp_top3,"<tr><td class=\"link\" colspan=11><a href=\"squidguard.html\"><font class=\"link\">%s</font></a><font class=\"text\"></font></td></tr>\n",text[122]);
-   if (strstr(ReportType,"downloads") != 0 && download_count && strcmp(Privacy,"yes") != 0 && ndownload) fprintf(fp_top3,"<tr><td class=\"link\" colspan=11><a href=\"download.html\"><font class=\"link\">%s</font></a><font class=\"text\"></font></td></tr>\n",text[125]);
-   if (strstr(ReportType,"denied") != 0 && denied_count && strcmp(Privacy,"yes") != 0) fprintf(fp_top3,"<tr><td class=\"link\" colspan=11><a href=\"denied.html\"><font class=\"link\">%s</font></a><font class=\"text\"></font></td></tr>\n",text[118]);
-   if (strstr(ReportType,"auth_failures") != 0 && authfail_count && strcmp(Privacy,"yes") != 0) fprintf(fp_top3,"<tr><td class=\"link\" colspan=11><a href=\"authfail.html\"><font class=\"link\">%s</font></a><font class=\"text\"></font></td></tr>\n",text[117]);
-   if(smartfilter) fprintf(fp_top3,"<tr><td class=\"link\" colspan=11><a href=\"smartfilter.html\"><font class=\"link\">%s</font></a><font class=\"text\"></font></td></tr>\n",text[116]);
-   fputs("<tr><td></td></tr>\n",fp_top3);
-
-   if (strstr(ReportType,"topuser") == 0) {
+   snprintf(title,sizeof(title),_("SARG report for %s"),period.text);
+   write_html_header(fp_top3,(IndexTree == INDEX_TREE_DATE) ? 3 : 1,title);
+   fputs("<tr><td class=\"header_c\">",fp_top3);
+   fprintf(fp_top3,_("Period: %s"),period.html);
+   fputs("</td></tr>\n",fp_top3);
+   fprintf(fp_top3,"<tr><td class=\"header_c\">%s: %s, %s</td></tr>\n",_("Sort"),TopuserSortField,TopuserSortOrder);
+   fprintf(fp_top3,"<tr><th class=\"header_c\">%s</th></tr>\n",_("Top users"));
+   close_html_header(fp_top3);
+
+   fputs("<div class=\"report\"><table cellpadding=\"1\" cellspacing=\"2\">\n",fp_top3);
+
+   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(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"));
+   fputs("<tr><td></td></tr>\n</table></div>\n",fp_top3);
+
+   if ((ReportType & REPORT_TYPE_TOPUSERS) == 0) {
       fputs("</body>\n</html>\n",fp_top3);
-      if (fp_top3) fclose (fp_top3);
+      fclose (fp_top3);
       return;
    }
-   strcpy(val1,text[100]);
-   strcpy(val2,text[98]);
-   strcpy(val3,text[92]);
-   strcpy(val4,text[93]);
-   sprintf(val11,"%%%s",text[93]);
-   sprintf(val5,"%s-%s-%s",text[113],text[114],text[112]);
-   strcpy(val6,text[94]);
-   strcpy(val7,text[95]);
-   sprintf(val8,"%%%s",text[99]);
-   strcpy(val9,"colspan=2");
-   bzero(val10, 255);
-   strcpy(hbc1,"class=\"header\"");
-   strcpy(hbc2,"class=\"header\"");
-   strcpy(hbc3,"class=\"header\"");
-   strcpy(hbc4,"class=\"header\"");
-   strcpy(hbc5,"class=\"header3\"");
-   strcpy(hbc6,"class=\"header\"");
-   strcpy(hbc7,"class=\"header\"");
-   strcpy(hbc8,"class=\"header\"");
-   strcpy(hbc9,"class=\"header\"");
-   strcpy(hbc10,"class=\"header\"");
-
-   if(strstr(TopUserFields,"NUM") == 0) {
-      bzero(val1, 255);
-      bzero(hbc1, 30);
-   }
-   if(strstr(TopUserFields,"USERID") == 0) {
-      bzero(val2, 255);
-      bzero(hbc2, 30);
-   }
-   if(strstr(TopUserFields,"CONNECT") == 0) {
-      bzero(val3, 255);
-      bzero(hbc3, 30);
-   }
-   if(strstr(TopUserFields,"BYTES") == 0) {
-      bzero(val4, 255);
-      bzero(hbc4, 30);
-   }
-   if(strstr(TopUserFields,"SETYB") == 0) {
-      bzero(val11, 255);
-      bzero(hbc9, 30);
-   }
-   if(strstr(TopUserFields,"IN-CACHE-OUT") == 0) {
-      bzero(val5, 255);
-      bzero(hbc5, 30);
-      bzero(val9, 255);
-      strcpy(val10,"<td></td>");
-   }
-   if(strstr(TopUserFields,"USED_TIME") == 0) {
-      bzero(val6, 255);
-      bzero(hbc6, 30);
-   }
-   if(strstr(TopUserFields,"MILISEC") == 0) { 
-      bzero(val7, 255);
-      bzero(hbc7, 30);
-   }
-   if(strstr(TopUserFields,"%TIME") == 0) {
-      bzero(val8, 255);
-      bzero(hbc8, 30);
-   }
 
-   fprintf(fp_top3,"<tr><th %s>%s</th><th %s></th><th %s>%s</th><th %s>%s</th><th %s>%s</th><th %s>%s</th><th %s %s>%s%s</th><th %s>%s</th><th %s>%s</th><th %s>%s</th></tr>\n",hbc1,val1,hbc1,hbc2,val2,hbc3,val3,hbc4,val4,hbc9,val11,hbc5,val9,val5,val10,hbc6,val6,hbc7,val7,hbc8,val8);
+   fputs("<div class=\"report\"><table cellpadding=\"1\" cellspacing=\"2\">\n",fp_top3);
+   fputs("<tr>",fp_top3);
+
+   if((TopUserFields & TOPUSERFIELDS_NUM) != 0)
+      fprintf(fp_top3,"<th class=\"header_l\">%s</th>",_("NUM"));
+   if((TopUserFields & TOPUSERFIELDS_DATE_TIME) !=0 && (ReportType & REPORT_TYPE_DATE_TIME) != 0)
+      fputs("<th class=\"header_l\"></th>",fp_top3);
+   if((TopUserFields & TOPUSERFIELDS_USERID) != 0)
+      fprintf(fp_top3,"<th class=\"header_l\">%s</th>",_("USERID"));
+   if((TopUserFields & TOPUSERFIELDS_CONNECT) != 0)
+      fprintf(fp_top3,"<th class=\"header_l\">%s</th>",_("CONNECT"));
+   if((TopUserFields & TOPUSERFIELDS_BYTES) != 0)
+      fprintf(fp_top3,"<th class=\"header_l\">%s</th>",_("BYTES"));
+   if((TopUserFields & TOPUSERFIELDS_SETYB) != 0)
+      fprintf(fp_top3,"<th class=\"header_l\">%%%s</th>",_("BYTES"));
+   if((TopUserFields & TOPUSERFIELDS_IN_CACHE_OUT) != 0)
+      fprintf(fp_top3,"<th class=\"header_c\" colspan=\"2\">%s</th>",_("IN-CACHE-OUT"));
+   if((TopUserFields & TOPUSERFIELDS_USED_TIME) != 0)
+      fprintf(fp_top3,"<th class=\"header_l\">%s</th>",_("ELAPSED TIME"));
+   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"));
+
+   fputs("</tr>\n",fp_top3);
 
    ntopuser = 0;
 
-   fscanf(fp_top1,"%s%s%s%s%s%s",user,nbytes,nacc,elap,incac,oucac);
-   while(!feof(fp_top1)) {
-      if(atoi(nacc) < 1) {
-         fscanf(fp_top1,"%s%s%s%s%s%s",user,nbytes,nacc,elap,incac,oucac);
-         continue;
-      } else ntopuser = 1;
-      if(atoi(TopUsersNum) > 0 && topcount >= atoi(TopUsersNum)) goto final;
-      strcpy(user2,user);
-      tnbytes=my_atoll(nbytes);
-
-      if(tnbytes) {
-         perc=tnbytes * 100;
-         perc=perc / ttnbytes;
-      } else perc = 0;
-
-      if(atol(elap)) {
-         perc2=atol(elap);
-         perc2=((perc2 * 100) / ttnelap);
-      } else perc2 = 0;
-
-      if(atol(incac)) {
-         inperc=atol(incac);
-         inperc=((inperc * 100) / tnbytes);
-      } else inperc = 0;
-
-      if(atol(oucac)) {
-         ouperc=atol(oucac);
-         ouperc=((ouperc * 100) / tnbytes);
-      } else ouperc = 0;
-
-      strcpy(href," ");
-      strcpy(href2," ");
-      strcpy(href3," ");
-
-      if(strcmp(user,"TOTAL") != 0){
-         sprintf(href,"<a href='%s/",user);
-         sprintf(href2,"<a href='%s/d",user);
-         sprintf(href3,"<a href='%s/graph_day.png'>",user);
-         strcat(href,user);
-         strcat(href2,user);
-         strcat(href,".html'>");
-         strcat(href2,".html'>");
-      }
-
-      if(strcmp(Graphs,"yes") != 0)
-         bzero(href3,MAXLEN);
-
-      posicao++;
-
-      tnelap=my_atoll(elap);
+   if ((line=longline_create())==NULL) {
+      debuga(_("Not enough memory to read the downloaded files\n"));
+      exit(EXIT_FAILURE);
+   }
 
-      if(userip) {
-         fixip(user2);
-         if(strcmp(Ip2Name,"yes") == 0) {
-            if(strcmp(user2,ipantes) != 0) {
-               strcpy(ipantes,user2);
-               ip2name(user2,sizeof(user2));
-               strcpy(nameantes,user2);
-            } else strcpy(user2,nameantes);
-         }
+   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);
+         exit(EXIT_FAILURE);
       }
-    
-      if(strstr(ReportType,"date_time") != 0) {
-         sprintf(ltext110,"%s",text[110]);
-         for(s=ltext110; *s; ++s)
-            *s=tolower(*s);
-      } else {
-         bzero(href2, MAXLEN);
-         bzero(ltext110, 50);
-         sprintf(val1,"%s/d%s.html",dirname,user);
-         unlink(val1);
+      if (getword_atoll(&nbytes,&gwarea,'\t')<0) {
+         debuga(_("There is a broken number of bytes in file %s\n"),top1);
+         exit(EXIT_FAILURE);
       }
-
-//      if(UserTabFile[0] != '\0' && strstr(user2,".") != 0) {
-      if(UserTabFile[0] != '\0' && strcmp(user2,"TOTAL") != 0) {
-         sprintf(warea,":%s:",user2);
-         if((str=(char *) strstr(userfile,warea)) != (char *) NULL ) {
-            z1=0;
-            str2=(char *) strstr(str+1,":");
-            str2++;
-            bzero(name, MAXLEN);
-            while(str2[z1] != ':') {
-               name[z1]=str2[z1];
-               z1++;
-            }
-         } else strcpy(name,user2);
-      } else strcpy(name,user2);
-
-      if((strcmp(Ip2Name,"yes") == 0) && 
-        ((str=(char *) strstr(name, ".")) != (char *) NULL) && 
-        ((str=(char *) strstr(str+1, ".")) != (char *) NULL))
-         ip2name(name,sizeof(name));
-
-      twork=my_atoll(nacc);
-      my_lltoa(twork,nacc,0);
-      sprintf(wwork1,"%s",fixnum(twork,1));
-      sprintf(wwork2,"%s",fixnum(tnbytes,1));
-      sprintf(wwork3,"%s",fixnum2(tnelap,1));
-
-      sprintf(val1,"%d",posicao);
-#ifdef HAVE_GD
-      sprintf(val2,"%s<img src=\"%s/graph.png\" border=\"0\" title=\"%s\"></a>&nbsp;%s<img src=\"%s/datetime.png\" border=\"0\" title=\"%s %s\">\n",href3,ImageFile,text[126],href2,ImageFile,ltext110,text[55]);
-#else
-      sprintf(val2,"%s<img src=\"%s/datetime.png\" border=\"0\" title=\"%s\">\n",href2,ImageFile,ltext110);
-#endif
-
-      sprintf(val3,"%3.2f%%",perc);
-      sprintf(val4,"%3.2f%%",inperc);
-      sprintf(val5,"%3.2f%%",ouperc);
-      sprintf(val6,"%s",buildtime(tnelap));
-      sprintf(val7,"%3.2f%%",perc2);
-
-      strcpy(hbc1,"class=\"data\"");
-      strcpy(hbc2,"class=\"data2\"");
-      strcpy(hbc3,"class=\"data\"");
-      strcpy(hbc4,"class=\"data\"");
-      strcpy(hbc5,"class=\"data\"");
-      strcpy(hbc6,"class=\"data\"");
-      strcpy(hbc7,"class=\"data\"");
-      strcpy(hbc8,"class=\"data\"");
-      strcpy(hbc9,"class=\"data\"");
-      strcpy(hbc10,"class=\"data\"");
-
-      if(strstr(TopUserFields,"NUM") == 0) {
-         bzero(val1, 255);
-         bzero(hbc1, 30);
+      if (getword_atoll(&nacc,&gwarea,'\t')<0) {
+         debuga(_("There is a broken number of access in file %s\n"),top1);
+         exit(EXIT_FAILURE);
       }
-      if(strstr(TopUserFields,"USERID") == 0) {
-         bzero(val2, 255);
-         bzero(hbc2, 30);
+      if (getword_atoll(&elap,&gwarea,'\t')<0) {
+         debuga(_("There is a broken elpased time in file %s\n"),top1);
+         exit(EXIT_FAILURE);
       }
-      if(strstr(TopUserFields,"CONNECT") == 0) {
-         bzero(wwork1, 255);
-         bzero(hbc3, 30);
+      if (getword_atoll(&incac,&gwarea,'\t')<0) {
+         debuga(_("There is a broken in-cache size in file %s\n"),top1);
+         exit(EXIT_FAILURE);
       }
-      if(strstr(TopUserFields,"BYTES") == 0) { 
-         bzero(wwork2, 255);
-         bzero(hbc4, 30);
+      if (getword_atoll(&oucac,&gwarea,'\n')<0) {
+         debuga(_("There is a broken out-of-cache size in file %s\n"),top1);
+         exit(EXIT_FAILURE);
       }
-      if(strstr(TopUserFields,"SETYB") == 0) {
-         bzero(val3, 255);
-         bzero(hbc5, 30);
+      if(nacc < 1)
+         continue;
+      ntopuser = 1;
+      if(TopUsersNum > 0 && topcount >= TopUsersNum) break;
+      tnbytes=nbytes;
+      tnelap=elap;
+
+      uinfo=userinfo_find_from_id(user);
+      if (!uinfo) {
+         debuga(_("Unknown user ID %s in file %s\n"),user,top1);
+         exit(EXIT_FAILURE);
       }
 
-      if(strstr(TopUserFields,"IN-CACHE-OUT") == 0) {
-         bzero(val4, 255);
-         bzero(hbc6, 30);
+      fputs("<tr>",fp_top3);
+
+      posicao++;
+      if((TopUserFields & TOPUSERFIELDS_NUM) != 0)
+         fprintf(fp_top3,"<td class=\"data\">%d</td>",posicao);
+
+      if((TopUserFields & TOPUSERFIELDS_DATE_TIME) !=0 && (ReportType & REPORT_TYPE_DATE_TIME) != 0) {
+         fputs("<td class=\"data2\">",fp_top3);
+#ifdef HAVE_GD
+         if(Graphs && GraphFont[0]!='\0') {
+            //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
+         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);
+         unlink(val1);
       }
-      if(strstr(TopUserFields,"IN-CACHE-OUT") == 0) {
-         bzero(val5, 255);
-         bzero(hbc7, 30);
+      if((TopUserFields & TOPUSERFIELDS_USERID) != 0) {
+         if((ReportType & REPORT_TYPE_USERS_SITES) == 0)
+            fprintf(fp_top3,"<td class=\"data2\">%s</td>",name);
+         else
+            fprintf(fp_top3,"<td class=\"data2\"><a href=\"%s/%s.html\">%s</a></td>",uinfo->filename,uinfo->filename,uinfo->label);
       }
-      if(strstr(TopUserFields,"USED_TIME") == 0) {
-         bzero(val6, 255);
-         bzero(hbc8, 30);
+      if((TopUserFields & TOPUSERFIELDS_CONNECT) != 0)
+         fprintf(fp_top3,"<td class=\"data\">%s</td>",fixnum(nacc,1));
+      if((TopUserFields & TOPUSERFIELDS_BYTES) != 0)
+         fprintf(fp_top3,"<td class=\"data\">%s</td>",fixnum(tnbytes,1));
+      if((TopUserFields & TOPUSERFIELDS_SETYB) != 0) {
+         perc=(ttnbytes) ? tnbytes * 100. / ttnbytes : 0.;
+         fprintf(fp_top3,"<td class=\"data\">%3.2lf%%</td>",perc);
       }
-      if(strstr(TopUserFields,"MILISEC") == 0) {
-         bzero(wwork3, 255);
-         bzero(hbc9, 30);
+      if((TopUserFields & TOPUSERFIELDS_IN_CACHE_OUT) != 0) {
+         inperc=(tnbytes) ? incac * 100. / tnbytes : 0.;
+         ouperc=(tnbytes) ? oucac * 100. / tnbytes : 0.;
+         fprintf(fp_top3,"<td class=\"data\">%3.2lf%%</td><td class=\"data\">%3.2lf%%</td>",inperc,ouperc);
       }
-      if(strstr(TopUserFields,"%TIME") == 0) {
-         bzero(val7, 255);
-         bzero(hbc10, 30);
+      if((TopUserFields & TOPUSERFIELDS_USED_TIME) != 0)
+         fprintf(fp_top3,"<td class=\"data\">%s</td>",buildtime(tnelap));
+      if((TopUserFields & TOPUSERFIELDS_MILISEC) != 0)
+         fprintf(fp_top3,"<td class=\"data\">%s</td>",fixnum2(tnelap,1));
+      if((TopUserFields & TOPUSERFIELDS_PTIME) != 0) {
+         perc2=(ttnelap) ? elap * 100. / ttnelap : 0.;
+         fprintf(fp_top3,"<td class=\"data\">%3.2lf%%</td>",perc2);
       }
 
-      if(strstr(ReportType,"users_sites") == 0)
-         href[0]='\0';
-
-      if(dotinuser && strstr(name,"_")) {
-         str2=(char *)subs(name,"_",".");
-         strcpy(name,str2);
-         free(str2);
-      }
-
-      sprintf(preg,"<tr><td %s>%s</td><td %s>%s</td><td %s>%s%s</td><td %s>%s</td><td %s>%s</td><td %s>%s</td><td %s>%s</td><td %s>%s</td><td %s>%s</td><td %s>%s<td %s>%s</td></tr>\n",hbc1,val1,hbc2,val2,hbc2,href,name,hbc3,wwork1,hbc4,wwork2,hbc5,val3,hbc6,val4,hbc7,val5,hbc8,val6,hbc9,wwork3,hbc10,val7);
-
-      if(strstr(user,"TOTAL") != 0) {
-
-         if(atol(incac)) {
-            inperc=ttnbytes / 100;
-            inperc=atol(incac) / inperc;
-         } else inperc = 0;
-
-         if(atol(oucac)) {
-            ouperc=ttnbytes / 100;
-            ouperc=atol(oucac) / ouperc;
-         } else ouperc = 0;
-
-         sprintf(wwork1,"%s",fixnum(ttnacc,1));
-         sprintf(wwork2,"%s",fixnum(ttnbytes,1));
-         sprintf(wwork3,"%s",fixnum2(ttnelap,1));
-
-         strcpy(hbc1,"class=\"header2\"");
-         strcpy(hbc2,"class=\"header2\"");
-         strcpy(hbc3,"class=\"header2\"");
-         strcpy(hbc4,"class=\"header2\"");
-         strcpy(hbc5,"class=\"header2\"");
-         strcpy(hbc6,"class=\"header2\""); 
-         strcpy(hbc7,"class=\"header2\"");
-         strcpy(hbc8,"class=\"header2\"");
-         strcpy(hbc9,"class=\"header2\"");
-         strcpy(hbc10,"class=\"header\"");
-
-         sprintf(val4,"%3.2f%%",inperc);
-         sprintf(val5,"%3.2f%%",ouperc);
-         sprintf(val6,"%s",buildtime(ttnelap));
-         sprintf(val7,"%3.2f%%",perc2);
-
-         if(strstr(TopUserFields,"CONNECT") == 0) {
-            bzero(wwork1, 255);
-            bzero(hbc1, 30);
-         }
-         if(strstr(TopUserFields,"BYTES") == 0) {
-            bzero(wwork2, 255);
-            bzero(hbc2, 30);
-         }
-         if(strstr(TopUserFields,"IN-CACHE-OUT") == 0) {
-            bzero(val4, 255);
-            bzero(val5, 255);
-            bzero(hbc3, 30);
-            bzero(hbc4, 30);
-         }
-         if(strstr(TopUserFields,"USED_TIME") == 0) {
-            bzero(val6, 255);
-            bzero(hbc5, 30);
-         }
-         if(strstr(TopUserFields,"MILISEC") == 0) {
-            bzero(wwork3, 255);
-            bzero(hbc6, 30);
-         }
-
-         if(strstr(ReportType,"date_time") != 0) {
-           if(strstr(TopUserFields,"TOTAL") != 0)
-               sprintf(preg,"<tr><td></td><td></td><th %s>%s</th><th %s>%s</th><th %s>%15s</th><td></td><th %s>%s</th><th %s>%s</th><th %s>%s</th><th %s>%s</th></tr>\n",hbc10,text[107],hbc1,wwork1,hbc2,wwork2,hbc3,val4,hbc4,val5,hbc5,val6,hbc6,wwork3);
-        } else if(strstr(TopUserFields,"TOTAL") != 0)
-            sprintf(preg,"<tr><td></td><td></td><th %s>%s</th><th %s>%s</th><th %s>%15s</th><td></td><th %s>%s</th><th %s>%s</th><th %s>%s</th><th %s>%s</th></tr>\n",hbc10,text[107],hbc1,wwork1,hbc2,wwork2,hbc3,val4,hbc4,val5,hbc5,val6,hbc6,wwork3);
-      }
-
-      fputs(preg,fp_top3);
+      fputs("</tr>\n",fp_top3);
 
       topcount++;
-
-      fscanf(fp_top1,"%s%s%s%s%s%s",user,nbytes,nacc,elap,incac,oucac);
-   }
-
-   if(ttnbytes) tnbytes=ttnbytes / totuser;
-   else tnbytes=0;
-
-   twork=ttnacc/totuser;
-   twork2=ttnelap/totuser;
-   sprintf(wwork1,"%s",fixnum(twork,1));
-   sprintf(wwork2,"%s",fixnum(tnbytes,1));
-   sprintf(wwork3,"%s",fixnum2(twork2,1));
-
-   if(strstr(TopUserFields,"CONNECT") == 0) {
-      bzero(wwork1, 255);
-      bzero(hbc1, 30);
-   }
-   if(strstr(TopUserFields,"BYTES") == 0) {
-      bzero(wwork2, 255);
-      bzero(hbc2, 30);
-   }
-   if(strstr(TopUserFields,"IN-CACHE-OUT") == 0) {
-      bzero(val4, 255);
-      bzero(val5, 255);
-      bzero(hbc3, 30);
-      bzero(hbc4, 30);
-   }
-   if(strstr(TopUserFields,"USED_TIME") == 0) {
-      bzero(val6, 255);
-      bzero(hbc5, 30);
-   }
-   if(strstr(TopUserFields,"MILISEC") == 0) {
-      bzero(wwork3, 255);
-      bzero(hbc6, 30);
    }
+   fclose(fp_top1);
+   unlink(top1);
+   longline_destroy(&line);
+
+   if((TopUserFields & TOPUSERFIELDS_TOTAL) != 0) {
+      fputs("<tr>",fp_top3);
+      if((TopUserFields & TOPUSERFIELDS_NUM) != 0)
+         fputs("<td></td>",fp_top3);
+      if((TopUserFields & TOPUSERFIELDS_DATE_TIME) !=0 && (ReportType & REPORT_TYPE_DATE_TIME) != 0)
+         fputs("<td></td>",fp_top3);
+      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));
+      if((TopUserFields & TOPUSERFIELDS_BYTES) != 0)
+         fprintf(fp_top3,"<th class=\"header_r\">%15s</th>",fixnum(ttnbytes,1));
+      if((TopUserFields & TOPUSERFIELDS_SETYB) != 0)
+         fputs("<td></td>",fp_top3);
+      if((TopUserFields & TOPUSERFIELDS_IN_CACHE_OUT) != 0)
+      {
+         inperc=(ttnbytes) ? ttnincache * 100. / ttnbytes : 0.;
+         ouperc=(ttnbytes) ? ttnoucache *100. / ttnbytes : 0.;
+         fprintf(fp_top3,"<th class=\"header_r\">%3.2lf%%</th><th class=\"header_r\">%3.2lf%%</th>",inperc,ouperc);
+      }
+      if((TopUserFields & TOPUSERFIELDS_USED_TIME) != 0)
+         fprintf(fp_top3,"<th class=\"header_r\">%s</th>",buildtime(ttnelap));
+      if((TopUserFields & TOPUSERFIELDS_MILISEC) != 0)
+         fprintf(fp_top3,"<th class=\"header_r\">%s</th>",fixnum2(ttnelap,1));
 
-   if(ntopuser) {
-      if((strstr(ReportType,"date_time") != 0 && strstr(TopUserFields,"AVERAGE") != 0)) fprintf(fp_top3,"<tr><td></td><th></th><th %s>%s</th><th %s>%s</th><th %s>%15s</th><td></td><td></td><td></td><th %s>%s</th><th %s>%s</th></tr>\n",hbc10,text[96],hbc1,wwork1,hbc2,wwork2,hbc3,buildtime(ttnelap/totuser),hbc4,wwork3);
-      else if(strstr(TopUserFields,"AVERAGE") != 0) fprintf(fp_top3,"<tr><td></td><th></th><td></td><th %s>%s</th><th %s>%s</th><th %s>%15s</th><td></td><td></td><td></td><th %s>%s</th><th %s>%s</th></tr>\n",hbc10,text[96],hbc1,wwork1,hbc2,wwork2,hbc3,buildtime(ttnelap/totuser),hbc4,wwork3);
+      fputs("</tr>\n",fp_top3);
    }
 
-   if(strlen(UserAgentLog) > 0) {
-      fputs("<tr><td></td></tr>\n",fp_top3);
-      fputs("<tr><td></td></tr>\n",fp_top3);
-      fputs("<td align=\"left\" colspan=8><font size=-1><a href='useragent.html'>Useragent</a> Report</td>\n",fp_top3);
+   if(ntopuser && (TopUserFields & TOPUSERFIELDS_AVERAGE) != 0) {
+      fputs("<tr>",fp_top3);
+      if((TopUserFields & TOPUSERFIELDS_NUM) != 0)
+         fputs("<td></td>",fp_top3);
+      if((TopUserFields & TOPUSERFIELDS_DATE_TIME) !=0 && (ReportType & REPORT_TYPE_DATE_TIME) != 0)
+         fputs("<td></td>",fp_top3);
+      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));
+      if((TopUserFields & TOPUSERFIELDS_BYTES) != 0) {
+         tnbytes=(totuser) ? ttnbytes / totuser : 0;
+         fprintf(fp_top3,"<th class=\"header_r\">%15s</th>",fixnum(tnbytes,1));
+      }
+      if((TopUserFields & TOPUSERFIELDS_SETYB) != 0)
+         fputs("<td></td>",fp_top3);
+      if((TopUserFields & TOPUSERFIELDS_IN_CACHE_OUT) != 0)
+         fputs("<td></td><td></td>",fp_top3);
+      if((TopUserFields & TOPUSERFIELDS_USED_TIME) != 0)
+         fprintf(fp_top3,"<th class=\"header_r\">%s</th>",buildtime(ttnelap/totuser));
+      if((TopUserFields & TOPUSERFIELDS_MILISEC) != 0)
+         fprintf(fp_top3,"<th class=\"header_r\">%s</th>",fixnum2(ttnelap/totuser,1));
+      fputs("</tr>\n",fp_top3);
    }
 
-   fputs("</table></center>",fp_top3);
-
-   show_info(fp_top3);
-
-final:
-   fclose(fp_top1);
-   unlink(top1);
+   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) {
-      fprintf(stderr, "SARG: (topuser) %s: %s\n",text[45],tusr);
-      exit(1);
+      debuga(_("(topuser) Cannot open file %s\n"),tusr);
+      exit(EXIT_FAILURE);
    }
-
    fprintf(fp_ou,"%d\n",totuser);
-
-   fputs("</body>\n</html>\n",fp_top3);
-   fclose(fp_top3);
-   fclose(fp_ou);
+   if (fclose(fp_ou)==EOF)
+      debuga(_("Failed to close file %s - %s\n"),tusr,strerror(errno));
 
    return;
 }