]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Keep the user name intact in the report.
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Mon, 1 Mar 2010 21:01:32 +0000 (21:01 +0000)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Mon, 1 Mar 2010 21:01:32 +0000 (21:01 +0000)
Speed up the processing of the access.log by keeping more temporary files open.
Replace more gettext macros.
Reduce the number of IP addresses resolutions.

28 files changed:
CMakeLists.txt
Makefile.in
authfail.c
dansguardian_report.c
datafile.c
denied.c
documentation/repday.txt [new file with mode: 0644]
documentation/util.txt
download.c
email.c
getconf.c
grepday.c
html.c
include/conf.h
include/defs.h
log.c
po/fr.po
realtime.c
repday.c
report.c
siteuser.c
smartfilter.c
sort.c
squidguard_report.c
topuser.c
totday.c
userinfo.c [new file with mode: 0644]
util.c

index 1f360f365aae3302cffede7b2bc53c3981f7bd88..4b268155262e4025b4b7ead722f069755f3c88fb 100755 (executable)
@@ -53,7 +53,7 @@ SET(SRC util.c log.c report.c topuser.c email.c sort.c html.c
        smartfilter.c denied.c authfail.c language.c charset.c
        squidguard_log.c squidguard_report.c auth.c download.c grepday.c
        dansguardian_log.c dansguardian_report.c realtime.c btree_cache.c
-       usertab.c)
+       usertab.c userinfo.c)
 
 FOREACH(f ${SRC})
    ADD_FILE_DEPENDENCIES(${f} ${CMAKE_BINARY_DIR}/config.h ${CMAKE_SOURCE_DIR}/include/conf.h ${CMAKE_SOURCE_DIR}/include/info.h ${CMAKE_SOURCE_DIR}/include/defs.h)
index 618bd26be2212910a2a98cc26b9c3d231b9052f4..e6d13e854234d17d80233bc770b43a1a6398657e 100644 (file)
@@ -39,14 +39,17 @@ SRCS = util.c log.c report.c topuser.c email.c sort.c html.c \
        indexonly.c splitlog.c lastlog.c topsites.c siteuser.c css.c \
        smartfilter.c denied.cauthfail.c language.c charset.c \
        squidguard_log.c squidguard_report.c auth.c download.c grepday.c \
-       dansguardian_log.c dansguardian_report.c realtime.c btree_cache.c usertab.c
+       dansguardian_log.c dansguardian_report.c realtime.c btree_cache.c \
+       usertab.c userinfo.c
+
 OBJS = util.o log.o report.o topuser.o email.o sort.o html.o \
        totger.o index.o getconf.o usage.o decomp.o ip2name.o \
        useragent.o exclude.o convlog.o totday.o repday.o datafile.o \
        indexonly.o splitlog.o lastlog.o topsites.o siteuser.o css.o \
        smartfilter.o denied.o authfail.o language.o charset.o \
        squidguard_log.o squidguard_report.o auth.o download.o grepday.o \
-       dansguardian_log.o dansguardian_report.o realtime.o btree_cache.o usertab.o
+       dansguardian_log.o dansguardian_report.o realtime.o btree_cache.o \
+       usertab.o userinfo.o
 
 DISTFILES = $(SRCS) ABOUT-NLS
 
@@ -129,3 +132,5 @@ distclean: clean
 realclean: distclean
        rm -f TAGS
 
+update-po:
+       $(MAKE) -C po update-po
index ff828018b5ba21ce0d2555b9a99dfb922787e3de..cdfa854293aa05b430c026e2eaae615c01315c10 100644 (file)
@@ -45,7 +45,6 @@ void authfail_report(void)
    char ouser2[MAXLEN];
    char data[15];
    char hora[15];
-   char *str;
    char tmp4[MAXLEN];
    char csort[MAXLEN];
    int  z=0;
@@ -53,6 +52,7 @@ void authfail_report(void)
    int  cstatus;
    struct getwordstruct gwarea;
    struct longlinestruct line;
+   struct userinfostruct *uinfo;
 
    if(DataFile[0] != '\0') return;
 
@@ -75,7 +75,7 @@ void authfail_report(void)
       exit(1);
    }
    if (!fgets(period,sizeof(period),fp_in)) {
-      fprintf(stderr,"SARG: (authfail) read error in %s\n",per);
+      debuga(_("(authfail) read error in %s"),per);
       exit(1);
    }
    fclose(fp_in);
@@ -83,13 +83,13 @@ void authfail_report(void)
    sprintf(csort,"sort -b -T \"%s\" -k 3,3 -k 5,5 -o \"%s\" \"%s\"", TempDir, authfail_in, tmp4);
    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);
+      debuga(_("sort command return status %d"),WEXITSTATUS(cstatus));
+      debuga(_("sort command: %s"),csort);
       exit(1);
    }
    if((fp_in=MY_FOPEN(authfail_in,"r"))==NULL) {
       fprintf(stderr, "SARG: (authfail) %s: %s\n",text[45],authfail_in);
-      fprintf(stderr, "SARG: sort command: %s\n",csort);
+      debuga(_("sort command: %s"),csort);
       exit(1);
    }
    unlink(tmp4);
@@ -119,22 +119,20 @@ void authfail_report(void)
       getword_start(&gwarea,buf);
       if (getword(data,sizeof(data),&gwarea,'\t')<0 || getword(hora,sizeof(hora),&gwarea,'\t')<0 ||
           getword(user,sizeof(user),&gwarea,'\t')<0 || getword(ip,sizeof(ip),&gwarea,'\t')<0) {
-         debuga(_("Maybe you have a broken record or garbage in your %s file"),authfail_in);
+         debuga(_("There is a broken record or garbage in file %s"),authfail_in);
          exit(1);
       }
       if (getword_ptr(buf,&url,&gwarea,'\t')<0) {
-         debuga(_("Maybe you have a broken url in your %s file"),authfail_in);
+         debuga(_("There is a broken url in file %s"),authfail_in);
          exit(1);
       }
 
-      if((str=(char *) strstr(user, "_")) != (char *) NULL ) {
-         if((str=(char *) strstr(str+1, "_")) != (char *) NULL )
-            fixip(user);
+      uinfo=userinfo_find_from_id(user);
+      if (!uinfo) {
+         debuga(_("Unknown user ID %s in file %s"),user,authfail_in);
+         exit(1);
       }
 
-      if(Ip2Name)
-         ip2name(ip,sizeof(ip));
-
       if(!z) {
          strcpy(ouser,user);
          strcpy(oip,ip);
@@ -150,24 +148,18 @@ void authfail_report(void)
             strcpy(oip,ip);
       }
 
-      user_find(name,sizeof(name), user);
-
-      if(dotinuser && strchr(name,'_')) {
-         subs(name,sizeof(name),"_",".");
-      }
-
      if(AuthfailReportLimit) {
-        if(strcmp(ouser2,name) == 0) {
+        if(strcmp(ouser2,uinfo->label) == 0) {
             count++;
          } else {
             count=1;
-            strcpy(ouser2,name);
+            strcpy(ouser2,uinfo->label);
          }
          if(count >= AuthfailReportLimit)
             continue;
       }
 
-      fprintf(fp_ou,"<tr><td class=\"data2\">%s</td><td class=\"data2\">%s</td><td class=\"data2\">%s-%s</td><td class=\"data2\">",name,ip,data,hora);
+      fprintf(fp_ou,"<tr><td class=\"data2\">%s</td><td class=\"data2\">%s</td><td class=\"data2\">%s-%s</td><td class=\"data2\">",uinfo->label,ip,data,hora);
       if(BlockIt[0]!='\0') {
          fprintf(fp_ou,"<a href=\"%s%s?url=",wwwDocumentRoot,BlockIt);
          output_html_url(fp_ou,url);
index a9f53ead4dbac5a76f939bf8e6e6df478f172717..ea060f6826ef21151fe02d7efbe8d9755ad6b09a 100644 (file)
@@ -45,7 +45,6 @@ void dansguardian_report(void)
    char date[15];
    char date2[15];
    char hour[15];
-   char *str;
    int  z=0;
    int  count=0;
    struct getwordstruct gwarea;
@@ -67,7 +66,7 @@ void dansguardian_report(void)
    }
 
    if (!fgets(period,sizeof(period),fp_in)) {
-      fprintf(stderr,"SARG: (dansguardian_report) read error in %s\n",per);
+      debuga(_("(dansguardian_report) read error in %s"),per);
       exit(1);
    }
    fclose(fp_in);
@@ -125,11 +124,6 @@ void dansguardian_report(void)
          strncat(date,date2,4);
       }
 
-      if((str=(char *) strstr(user, "_")) != (char *) NULL ) {
-         if((str=(char *) strstr(str+1, "_")) != (char *) NULL )
-            fixip(user);
-      }
-
       if(Ip2Name)
          ip2name(ip,sizeof(ip));
 
@@ -150,10 +144,6 @@ void dansguardian_report(void)
 
       user_find(name, sizeof(name), user);
 
-      if(dotinuser && strchr(name,'_')) {
-         subs(name,sizeof(name),"_",".");
-      }
-
      if(DansGuardianReportLimit) {
          if(strcmp(ouser2,name) == 0) {
             count++;
index 8c7ace191660a666d8ac5e5518ccd8c0b2dfaf91..968f6b4eb1159e09e2f4f0cd6127a9725750e5b1 100644 (file)
 #include "include/conf.h"
 #include "include/defs.h"
 
-void saverecs(char *dirname, char *user, long long int nacc, char *url, long long int nbytes, char *ip, char *hora, char *dia, long long int nelap, long long int incache, long long int oucache);
+void saverecs(char *dirname, const struct userinfostruct *uinfo, long long int nacc, char *url, long long int nbytes, char *ip, char *hora, char *dia, long long int nelap, long long int incache, long long int oucache);
 
 void data_file(char *tmp)
 {
 
    FILE *fp_in;
 
-   char accdia[11], acchora[9], accuser[MAXLEN], accip[MAXLEN], accurl[MAXLEN];
+   char accdia[11], acchora[9], accip[MAXLEN], accurl[MAXLEN];
    char oldaccdia[11], oldacchora[9], oldaccip[MAXLEN];
-   char dirname[MAXLEN], wdirname[MAXLEN], oldurl[MAXLEN], oldaccuser[MAXLEN];
+   char dirname[MAXLEN], wdirname[MAXLEN], oldurl[MAXLEN];
    char olduser[MAXLEN], oldmsg[50], acccode[50], oldacccode[50];
    char ipantes[MAXLEN], nameantes[MAXLEN];
    char accsmart[MAXLEN];
    char crc2[50];
    char *str;
    char tmp3[MAXLEN];
+   char user[MAX_USER_LEN];
+   char u2[MAX_USER_LEN];
    DIR *dirp;
    struct dirent *direntp;
    long long int nbytes=0;
@@ -54,7 +56,9 @@ void data_file(char *tmp)
    long long int accbytes;
    long long int accelap;
    int dlen;
+   int new_user;
    struct getwordstruct gwarea;
+   struct userinfostruct *uinfo;
    const char logext[]=".log";
 
    ipantes[0]='\0';
@@ -70,8 +74,25 @@ void data_file(char *tmp)
       if(strcmp(direntp->d_name+dlen,logext) != 0)
          continue;
 
+      if (dlen>0) {
+         if (dlen>=sizeof(user)) continue;
+         strncpy(user,direntp->d_name,dlen);
+         user[dlen]=0;
+      } else {
+         user[0]='\0';
+      }
+
+      uinfo=userinfo_find_from_file(user);
+      if (!uinfo) {
+         debuga(_("Ignoring unknown user file %s"),user);
+         continue;
+      }
+      strcpy(u2,uinfo->id);
+      if(Ip2Name && uinfo->id_is_ip) ip2name(u2,sizeof(u2));
+      user_find(uinfo->label,MAX_USER_LEN, u2);
+
       if (snprintf(tmp3,sizeof(tmp3),"%s/%s",tmp,direntp->d_name)>=sizeof(tmp3)) {
-         fprintf(stderr,"SARG: (datafile) directory path too long: %s/%s\n",tmp,direntp->d_name);
+         debuga(_("(datafile) directory path too long: %s/%s"),tmp,direntp->d_name);
          exit(1);
       }
 
@@ -81,14 +102,15 @@ void data_file(char *tmp)
       }
 
       ttopen=0;
+      new_user=1;
       while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
          getword_start(&gwarea,buf);
          if (getword(accdia,sizeof(accdia),&gwarea,' ')<0 || getword(acchora,sizeof(acchora),&gwarea,' ')<0 ||
-             getword(accuser,sizeof(accuser),&gwarea,' ')<0 || getword(accip,sizeof(accip),&gwarea,' ')<0 ||
+             getword(accip,sizeof(accip),&gwarea,' ')<0 ||
              getword(accurl,sizeof(accurl),&gwarea,' ')<0 || getword_atoll(&accbytes,&gwarea,' ')<0 ||
              getword(acccode,sizeof(acccode),&gwarea,' ')<0 || getword_atoll(&accelap,&gwarea,' ')<0 ||
              getword_skip(20000,&gwarea,' ')<0 || getword(accsmart,sizeof(accsmart),&gwarea,'"')<0) {
-            printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp3);
+            debuga(_("There is a broken record or garbage in file %s"),tmp3);
             exit(1);
          }
 
@@ -104,25 +126,23 @@ void data_file(char *tmp)
          if(!rtotal){
             strcpy(oldurl,accurl);
             strcpy(oldacccode,acccode);
-            strcpy(oldaccuser,accuser);
             strcpy(oldaccip,accip);
             strcpy(oldaccdia,accdia);
             strcpy(oldacchora,acchora);
             rtotal++;
          }
 
-         if(strcmp(oldurl,accurl) != 0 || strcmp(oldaccuser,accuser) != 0){
+         if(strcmp(oldurl,accurl) != 0 || new_user){
             strcpy(oldmsg,"OK");
             if(strstr(oldacccode,"DENIED") != 0) strcpy(oldmsg,text[46]);
-            gravatmp(oldaccuser,oldurl,nacc,nbytes,oldmsg,nelap,indexonly,incache,oucache);
+            gravatmp(uinfo,oldurl,nacc,nbytes,oldmsg,nelap,indexonly,incache,oucache);
             strcpy(wdirname,dirname);
-            saverecs(wdirname,oldaccuser,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache);
+            saverecs(wdirname,uinfo,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache);
             nacc=0;
             nbytes=0;
             nelap=0;
             incache=0;
             oucache=0;
-            if(strcmp(oldaccuser,accuser) != 0) ind2=0;
          }
 
          nacc++;
@@ -137,7 +157,7 @@ void data_file(char *tmp)
          else incache+=accbytes;
 
          strcpy(oldurl,accurl);
-         strcpy(oldaccuser,accuser);
+         new_user=0;
          strcpy(oldacccode,acccode);
          strcpy(oldaccip,accip);
          strcpy(oldaccdia,accdia);
@@ -152,10 +172,9 @@ void data_file(char *tmp)
       debuga("Datafile %s successfully",DataFile);
 }
 
-void saverecs(char *dirname, char *user, long long int nacc, char *url, long long int nbytes, char *ip, char *hora, char *dia, long long int nelap, long long int incache, long long int oucache)
+void saverecs(char *dirname, const struct userinfostruct *uinfo, long long int nacc, char *url, long long int nbytes, char *ip, char *hora, char *dia, long long int nelap, long long int incache, long long int oucache)
 {
    FILE *fp_ou;
-   char reg[MAXLEN];
    char val[20];
 
    if((fp_ou=MY_FOPEN(DataFile,"a"))==NULL){
@@ -164,51 +183,50 @@ void saverecs(char *dirname, char *user, long long int nacc, char *url, long lon
    }
 
    if((DataFileFields & DATA_FIELD_USER) != 0) {
-      strcpy(reg,user);
-      strncat(reg,DataFileDelimiter,1);
+      fputs(uinfo->label,fp_ou);
+      fputc(DataFileDelimiter[0],fp_ou);
    }
    if((DataFileFields & DATA_FIELD_DATE) != 0) {
-      strncat(reg,dia,strlen(dia));
-      strncat(reg,DataFileDelimiter,1);
+      fputs(dia,fp_ou);
+      fputc(DataFileDelimiter[0],fp_ou);
    }
    if((DataFileFields & DATA_FIELD_TIME) != 0) {
-      strncat(reg,hora,strlen(hora));
-      strncat(reg,DataFileDelimiter,1);
+      fputs(hora,fp_ou);
+      fputc(DataFileDelimiter[0],fp_ou);
    }
    if((DataFileFields & DATA_FIELD_URL) != 0) {
       strcpy(name,url);
       if (strcmp(DataFileUrl,"ip") == 0) name2ip(name);
-      strncat(reg,name,strlen(name));
-      strncat(reg,DataFileDelimiter,1);
+      fputs(name,fp_ou);
+      fputc(DataFileDelimiter[0],fp_ou);
    }
    if((DataFileFields & DATA_FIELD_CONNECT) != 0) {
       my_lltoa(nacc,val,sizeof(val),0);
-      strcat(reg,val);
-      strncat(reg,DataFileDelimiter,1);
+      fputs(val,fp_ou);
+      fputc(DataFileDelimiter[0],fp_ou);
    }
    if((DataFileFields & DATA_FIELD_BYTES) != 0) {
       my_lltoa(nbytes,val,sizeof(val),0);
-      strcat(reg,val);
-      strncat(reg,DataFileDelimiter,1);
+      fputs(val,fp_ou);
+      fputc(DataFileDelimiter[0],fp_ou);
    }
    if((DataFileFields & DATA_FIELD_IN_CACHE) != 0) {
       my_lltoa(incache,val,sizeof(val),0);
-      strcat(reg,val);
-      strncat(reg,DataFileDelimiter,1);
+      fputs(val,fp_ou);
+      fputc(DataFileDelimiter[0],fp_ou);
    }
    if((DataFileFields & DATA_FIELD_OUT_CACHE) != 0) {
       my_lltoa(oucache,val,sizeof(val),0);
-      strcat(reg,val);
-      strncat(reg,DataFileDelimiter,1);
+      fputs(val,fp_ou);
+      fputc(DataFileDelimiter[0],fp_ou);
    }
    if((DataFileFields & DATA_FIELD_ELAPSED) != 0) {
       my_lltoa(nelap,val,sizeof(val),0);
-      strcat(reg,val);
-      strncat(reg,DataFileDelimiter,1);
+      fputs(val,fp_ou);
+      fputc(DataFileDelimiter[0],fp_ou);
    }
 
-   reg[strlen(reg)-1]='\n';
-   fputs(reg,fp_ou);
+   fputc('\n',fp_ou);
 
    fclose(fp_ou);
 }
index 5239001abc9b47d3458b84053f765d479de4af7e..3bdda559cc76523dea70d878d663aa866faf36c4 100644 (file)
--- a/denied.c
+++ b/denied.c
@@ -45,11 +45,12 @@ void gen_denied_report(void)
    char ouser2[MAXLEN];
    char data[15];
    char hora[15];
-   char *str;
    int  z=0;
    int  count=0;
+   int new_user;
    struct getwordstruct gwarea;
    struct longlinestruct line;
+   struct userinfostruct *uinfo;
 
    ouser[0]='\0';
    ouser2[0]='\0';
@@ -69,7 +70,7 @@ void gen_denied_report(void)
    }
 
    if (!fgets(period,sizeof(period),fp_in)) {
-      fprintf(stderr,"SARG: (denied) read error in %s\n",per);
+      debuga(_("(denied) read error in %s"),per);
       exit(1);
    }
    fclose(fp_in);
@@ -102,55 +103,54 @@ void gen_denied_report(void)
       getword_start(&gwarea,buf);
       if (getword(data,sizeof(data),&gwarea,'\t')<0 || getword(hora,sizeof(hora),&gwarea,'\t')<0 ||
           getword(user,sizeof(user),&gwarea,'\t')<0 || getword(ip,sizeof(ip),&gwarea,'\t')<0) {
-         printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",denied_in);
+         debuga(_("There is a broken record or garbage in file %s"),denied_in);
          exit(1);
       }
       if (getword_ptr(buf,&url,&gwarea,'\t')<0) {
-         debuga(_("Maybe you have a broken url in your %s file"),denied_in);
+         debuga(_("There is a broken url in file %s"),denied_in);
          exit(1);
       }
 
-      if((str=(char *) strstr(user, "_")) != (char *) NULL ) {
-         if((str=(char *) strstr(str+1, "_")) != (char *) NULL )
-            fixip(user);
+      uinfo=userinfo_find_from_id(user);
+      if (!uinfo) {
+         debuga(_("Unknown user ID %s in file %s"),user,denied_in);
+         exit(1);
       }
 
-      if(Ip2Name)
-         ip2name(ip,sizeof(ip));
-
+      new_user=0;
       if(!z) {
          strcpy(ouser,user);
          strcpy(oip,ip);
          z++;
+         new_user=1;
       } else {
-         if(strcmp(ouser,user) == 0)
-            user[0]='\0';
-         if(user[0] != '\0')
+         if(strcmp(ouser,user) != 0) {
             strcpy(ouser,user);
-         if(strcmp(oip,ip) == 0)
-            ip[0]='\0';
-         if(ip[0] != '\0')
+            new_user=1;
+         }
+         if(strcmp(oip,ip) != 0) {
             strcpy(oip,ip);
-      }
-
-      user_find(name, sizeof(name), user);
-
-      if(dotinuser && strchr(name,'_')) {
-         subs(name,sizeof(name),"_",".");
+            new_user=1;
+         }
       }
 
       if(DeniedReportLimit) {
-         if(strcmp(ouser2,name) == 0) {
+         if(strcmp(ouser2,uinfo->label) == 0) {
             count++;
          } else {
             count=1;
-            strcpy(ouser2,name);
+            strcpy(ouser2,uinfo->label);
          }
          if(count >= DeniedReportLimit)
             continue;
       }
 
-      fprintf(fp_ou,"<tr><td class=\"data\">%s</td><td class=\"data\">%s</td><td class=\"data\">%s-%s</td><td class=\"data2\">",name,ip,data,hora);
+      fputs("<tr>",fp_ou);
+      if (new_user)
+         fprintf(fp_ou,"<td class=\"data\">%s</td><td class=\"data\">%s</td>",uinfo->label,ip);
+      else
+         fputs("<td class=\"data\"></td><td class=\"data\"></td>",fp_ou);
+      fprintf(fp_ou,"<td class=\"data\">%s-%s</td><td class=\"data2\">",data,hora);
       if(BlockIt[0] != '\0') {
          fprintf(fp_ou,"<a href=\"%s%s?url=",wwwDocumentRoot,BlockIt);
          output_html_url(fp_ou,url);
diff --git a/documentation/repday.txt b/documentation/repday.txt
new file mode 100644 (file)
index 0000000..ae89eea
--- /dev/null
@@ -0,0 +1,12 @@
+/*!\file repday.c
+\brief Daily text report.
+*/
+
+
+
+/*! \fn void report_day(const struct userinfostruct *uinfo)
+Create the text report with the daily internet usage made by the user.
+
+\param uinfo The data about the user whose report must be created.
+
+*/
index b5b9656d91fd302b48eb3d0a93e89d6fb9a2bb59..123052fb43113bdababccd9b1fcc14737ee8759e 100644 (file)
@@ -311,19 +311,6 @@ Write a debug message to stderr with the value of a parameter. The message is pr
 
 
 
-/*! \fn void fixip(char *ip)
-Toggle the IP address format from nnn.nnn.nnn.nnn to nnn_nnn_nnn_nnn. Only the first three
-occurences of the . or _ are replaced. That limitation is imposed by a will to mimic as close
-as possible the previous code based on strings copying.
-
-\param ip The IP address to change. It is replaced in place.
-
-*/
-
-
-
-
-
 /*! \fn char *fixnum(long long int value, int n)
 Rewrite a number to make it more readable. The number may be written
 with the suffix K, M, G or T depending on its magnitude or the digits
index 5ba22c46af128ced9d4df0577648141c710152f0..fc22cf83c1d2703ab6461b0f5b2055e858498157 100644 (file)
@@ -49,12 +49,13 @@ void download_report(void)
    char ouser2[MAXLEN];
    char data[15];
    char hora[15];
-   char *str;
    int  z=0;
    int  count=0;
    int i;
+   int new_user;
    struct getwordstruct gwarea;
    struct longlinestruct line;
+   struct userinfostruct *uinfo;
 
    ouser[0]='\0';
    ouser2[0]='\0';
@@ -74,7 +75,7 @@ void download_report(void)
    }
 
    if (!fgets(period,sizeof(period),fp_in)) {
-      fprintf(stderr,"SARG: (download) read error in %s\n",wdirname);
+      debuga(_("(download) read error in %s"),wdirname);
       exit(1);
    }
    fclose(fp_in);
@@ -107,49 +108,42 @@ void download_report(void)
       getword_start(&gwarea,buf);
       if (getword(data,sizeof(data),&gwarea,'\t')<0 || getword(hora,sizeof(hora),&gwarea,'\t')<0 ||
           getword(user,sizeof(user),&gwarea,'\t')<0 || getword(ip,sizeof(ip),&gwarea,'\t')<0) {
-         debuga(_("Maybe you have a broken record or garbage in your %s file"),report_in);
+         debuga(_("There is a broken record or garbage in file %s"),report_in);
          exit(1);
       }
       if (getword_ptr(buf,&url,&gwarea,'\t')<0) {
-         debuga(_("Maybe you have a broken url in your %s file"),report_in);
+         debuga(_("There is a broken url in file %s"),report_in);
          exit(1);
       }
 
-      if((str=(char *) strstr(user, "_")) != (char *) NULL ) {
-         if((str=(char *) strstr(str+1, "_")) != (char *) NULL )
-            fixip(user);
+      uinfo=userinfo_find_from_id(user);
+      if (!uinfo) {
+         debuga(_("Unknown user ID %s in file %s"),user,report_in);
+         exit(1);
       }
-
-      if(Ip2Name)
-         ip2name(ip,sizeof(ip));
-
+      new_user=0;
       if(!z) {
          strcpy(ouser,user);
          strcpy(oip,ip);
          z++;
+         new_user=1;
       } else {
-         if(strcmp(ouser,user) == 0)
-            user[0]='\0';
-         if(user[0] != '\0')
+         if(strcmp(ouser,user) != 0) {
             strcpy(ouser,user);
-         if(strcmp(oip,ip) == 0)
-            ip[0]='\0';
-         if(ip[0] != '\0')
+            new_user=1;
+         }
+         if(strcmp(oip,ip) != 0) {
             strcpy(oip,ip);
-      }
-
-      user_find(name, sizeof(name), user);
-
-      if(dotinuser && strchr(name,'_')) {
-         subs(name,sizeof(name),"_",".");
+            new_user=1;
+         }
       }
 
       if(DownloadReportLimit) {
-         if(strcmp(ouser2,name) == 0) {
+         if(strcmp(ouser2,uinfo->label) == 0) {
             count++;
          } else {
             count=1;
-            strcpy(ouser2,name);
+            strcpy(ouser2,uinfo->label);
          }
          if(count >= DownloadReportLimit)
             continue;
@@ -157,15 +151,20 @@ void download_report(void)
 
       for (i=strlen(url)-1 ; i>=0 && (unsigned char)url[i]<' ' ; i--) url[i]=0;
 
-      fprintf(fp_ou,"<tr><td class=\"data\">%s</td><td class=\"data\">%s</td><td class=\"data\">%s-%s</td><td class=\"data2\">",name,ip,data,hora);
+      fputs("<tr>",fp_ou);
+      if (new_user)
+         fprintf(fp_ou,"<td class=\"data\">%s</td><td class=\"data\">%s</td>",uinfo->label,ip);
+      else
+         fputs("<td class=\"data\"></td><td class=\"data\"></td>",fp_ou);
+      fprintf(fp_ou,"<td class=\"data\">%s-%s</td><td class=\"data2\">",data,hora);
       if(BlockIt[0]!='\0') {
          fprintf(fp_ou,"<a href=\"%s%s?url=\"",wwwDocumentRoot,BlockIt);
          output_html_url(fp_ou,url);
          fprintf(fp_ou,"\"><img src=\"%s/sarg-squidguard-block.png\"></a>&nbsp;",ImageFile);
       }
-      fputs("<a href=\"html://",fp_ou);
+      fputs("<a href=\"http://",fp_ou);
       output_html_url(fp_ou,url);
-      fputs("\">",fp_ou);
+      fputs("\">http://",fp_ou);
       output_html_string(fp_ou,url,100);
       fputs("</a></td></tr>\n",fp_ou);
    }
diff --git a/email.c b/email.c
index 63c7b8c5ea9d0b1a1b28266e222ff7571eb65f20..7ec36a9e6cdb84b769857feb6813cf54e887ac88 100644 (file)
--- a/email.c
+++ b/email.c
@@ -39,7 +39,6 @@ int geramail(const char *dirname, int debug, const char *outdir, int userip, con
    int posicao=0;
    char olduser[MAX_USER_LEN], csort[MAXLEN], period[MAXLEN], arqper[MAXLEN];
    char wger[MAXLEN], top1[MAXLEN], top2[MAXLEN], top3[MAXLEN], user[MAX_USER_LEN], tusr[MAXLEN];
-   char user2[MAX_USER_LEN];
    char strip1[MAXLEN], strip2[MAXLEN], strip3[MAXLEN], strip4[MAXLEN], strip5[MAXLEN], strip6[MAXLEN], strip7[MAXLEN];
    int totuser=0;
    time_t t;
@@ -208,27 +207,22 @@ int geramail(const char *dirname, int debug, const char *outdir, int userip, con
    {
       getword_start(&gwarea,warea);
       if (getword(user,sizeof(user),&gwarea,'\t')<0) {
-         printf("SARG: Maybe you have a broken user in your %s file.\n",top1);
+         debuga(_("There may be a broken user in file %s"),top1);
          exit(1);
       }
       if (getword_atoll(&nbytes,&gwarea,'\t')<0) {
-         printf("SARG: Maybe you have a broken number of bytes in your %s file.\n",top1);
+         debuga(_("There may be a broken number of bytes in file %s"),top1);
          exit(1);
       }
       if (getword_atoll(&nacc,&gwarea,'\t')<0) {
-         printf("SARG: Maybe you have a broken number of access in your %s file.\n",top1);
+         debuga(_("There is a broken number of access in file %s"),top1);
          exit(1);
       }
       if (getword_atoll(&elap,&gwarea,'\t')<0) {
-         printf("SARG: Maybe you have a broken elapsed time in your %s file.\n",top1);
+         debuga(_("There is a broken elapsed time in file %s"),top1);
          exit(1);
       }
 
-      if(strchr(user,'_') != NULL)
-         fixip(user);
-
-      strcpy(user2,user);
-
       perc=(ttnbytes) ? nbytes * 100. / ttnbytes : 0;
       perc2=(ttnelap) ? elap * 100. / ttnelap : 0;
 
@@ -245,11 +239,11 @@ int geramail(const char *dirname, int debug, const char *outdir, int userip, con
 #endif
       } else {
 #if defined(__FreeBSD__)
-         fprintf(fp_top3,"%7d %20s %8lld %15s %3.2lf%% %10s %10qu %3.2lf%%\n",posicao,user2,nacc,fixnum(nbytes,1),perc,buildtime(elap),elap,perc2);
+         fprintf(fp_top3,"%7d %20s %8lld %15s %3.2lf%% %10s %10qu %3.2lf%%\n",posicao,user,nacc,fixnum(nbytes,1),perc,buildtime(elap),elap,perc2);
 #elif defined(__alpha) || __ALPHA
-         fprintf(fp_top3,"%7d %20s %8lld %15s %3.2lf%% %10s %10ld %3.2lf%%\n",posicao,user2,nacc,fixnum(nbytes,1),perc,buildtime(elap),elap,perc2);
+         fprintf(fp_top3,"%7d %20s %8lld %15s %3.2lf%% %10s %10ld %3.2lf%%\n",posicao,user,nacc,fixnum(nbytes,1),perc,buildtime(elap),elap,perc2);
 #else
-         fprintf(fp_top3,"%7d %20s %8lld %15s %3.2lf%% %10s %10lld %3.2lf%%\n",posicao,user2,nacc,fixnum(nbytes,1),perc,buildtime(elap),elap,perc2);
+         fprintf(fp_top3,"%7d %20s %8lld %15s %3.2lf%% %10s %10lld %3.2lf%%\n",posicao,user,nacc,fixnum(nbytes,1),perc,buildtime(elap),elap,perc2);
 #endif
       }
    }
@@ -282,7 +276,7 @@ int geramail(const char *dirname, int debug, const char *outdir, int userip, con
       }
 
       while(fgets(buf,sizeof(buf),fp_top3)!=NULL)
-         printf("%s",buf);
+         fputs(buf,stdout);
     } else {
       sprintf(buf,"\"%s\" -s \"SARG %s, %s\" \"%s\" <\"%s\"",MailUtility,text[55],asctime(local),email,top3);
       cstatus=system(buf);
index fe65246671db28cfe92943093c0af212e9a84171..2a41a351c551b2f6f4d617e4763f646d25cdfd04 100644 (file)
--- a/getconf.c
+++ b/getconf.c
@@ -111,6 +111,19 @@ struct param_list index_tree_values[]=
    {"file",INDEX_TREE_FILE,~INDEX_TREE_FILE},
 };
 
+struct param_list ntml_userformat_values[]=
+{
+   {"user",NTLMUSERFORMAT_USER,~NTLMUSERFORMAT_USER},
+   {"domainname+username",NTLMUSERFORMAT_DOMAINUSER,~NTLMUSERFORMAT_DOMAINUSER},
+};
+
+struct param_list recnouser_values[]=
+{
+   {"ip",RECORDWITHOUTUSER_IP,~RECORDWITHOUTUSER_IP},
+   {"ignore",RECORDWITHOUTUSER_IGNORE,~RECORDWITHOUTUSER_IGNORE},
+   {"everybody",RECORDWITHOUTUSER_EVERYBODY,~RECORDWITHOUTUSER_EVERYBODY},
+};
+
 static int is_param(const char *param,const char *buf)
 {
    int plen;
@@ -419,7 +432,7 @@ static void parmtest(char *buf)
 
    if (getparam_bool("overwrite_report",buf,&OverwriteReport)>0) return;
 
-   if (getparam_string("records_without_userid",buf,RecordsWithoutUser,sizeof(RecordsWithoutUser))>0) return;
+   if (getparam_list("records_without_userid",SET_LIST(recnouser_values),buf,&RecordsWithoutUser)>0) return;
 
    if (getparam_bool("use_comma",buf,&UseComma)>0) return;
 
@@ -540,7 +553,7 @@ static void parmtest(char *buf)
 
    if (getparam_string("ulimit",buf,Ulimit,sizeof(Ulimit))>0) return;
 
-   if (getparam_string("ntlm_user_format",buf,NtlmUserFormat,sizeof(NtlmUserFormat))>0) return;
+   if (getparam_list("ntlm_user_format",SET_LIST(ntml_userformat_values),buf,&NtlmUserFormat)>0) return;
 
    if (getparam_string("realtime_types",buf,RealtimeTypes,sizeof(RealtimeTypes))>0) return;
 
index c70a790e962685ab32c688ba3f6ed981cd63892c..bdb0623b094fe3949dc112f2aeb3bce99b4c23e6 100644 (file)
--- a/grepday.c
+++ b/grepday.c
@@ -234,7 +234,7 @@ static void bar(int x1,long long int n)
 }
 #endif //HAVE_GD
 
-void greport_day(const char *user)
+void greport_day(const struct userinfostruct *uinfo)
 {
 #ifdef HAVE_GD
    FILE *fp_in, *pngout;
@@ -244,7 +244,6 @@ void greport_day(const char *user)
    char wdirname[MAXLEN];
    char graph[MAXLEN];
    char buf[MAXLEN];
-   char wuser[255];
    char csort[255];
    char data[20];
    char s[15];
@@ -267,7 +266,7 @@ void greport_day(const char *user)
       return;
    }
    if(access(GraphFont, R_OK) != 0) {
-      fprintf(stderr, "SARG: (grepday) Fontname: %s not found.\n",GraphFont);
+      debuga(_("(grepday) Fontname: %s not found"),GraphFont);
       exit(1);
    }
 
@@ -339,16 +338,12 @@ void greport_day(const char *user)
    if(strcmp(DateFormat,"e") == 0)
       strftime(ftime, sizeof(ftime), "%d/%b/%Y-%H:%M", local);
 
-   if(dotinuser && strchr(name,'_')) {
-      subs(name,sizeof(name),"_",".");
-   }
-
    SARGgdImageStringFT(im,&brect[0],darkblue,GraphFont,7,0.0,620,470,ftime);
    if(ShowSargInfo) SARGgdImageStringFT(im,&brect[0],darkblue,GraphFont,10,0.0,257,15,"SARG, ");
    SARGgdImageStringFT(im,&brect[0],darkblue,GraphFont,10,0.0,300,15,Title);
    sprintf(warea,"%s: %s",text[89],period);
    SARGgdImageStringFT(im,&brect[0],darkblue,GraphFont,9,0.0,300,27,warea);
-   sprintf(warea,"%s: %s",text[90],name);
+   sprintf(warea,"%s: %s",text[90],uinfo->label);
    SARGgdImageStringFT(im,&brect[0],darkblue,GraphFont,9,0.0,300,38,warea);
    SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,418,"  50K");
    SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,408,"250K");
@@ -392,16 +387,16 @@ void greport_day(const char *user)
       SARGgdImageStringFT(im,&brect[0],black,GraphFont,10,3.14/2,20,248,text[94]);
    SARGgdImageStringFT(im,&brect[0],black,GraphFont,10,0.0,330,460,text[127]);
 
-   if (snprintf(graph,sizeof(graph),"%s/%s/graph_day.png",dirname,user)>=sizeof(graph)) {
-      fprintf(stderr, "SARG: user name too long for: %s/%s/graph_day.png\n",dirname,user);
+   if (snprintf(graph,sizeof(graph),"%s/%s/graph_day.png",dirname,uinfo->filename)>=sizeof(graph)) {
+      debuga(_("user name too long for: %s/%s/graph_day.png"),dirname,uinfo->filename);
       exit(1);
    }
-   if (snprintf(wdirname,sizeof(wdirname),"%s/%s.day",tmp,user)>=sizeof(wdirname)) {
-      fprintf(stderr, "SARG: user name too long for: %s/%s.day\n",tmp,user);
+   if (snprintf(wdirname,sizeof(wdirname),"%s/%s.day",tmp,uinfo->filename)>=sizeof(wdirname)) {
+      debuga(_("user name too long for: %s/%s.day"),tmp,uinfo->filename);
       exit(1);
    }
-   if (snprintf(tmp5,sizeof(tmp5),"%s/%s.graph",tmp,user)>=sizeof(tmp5)) {
-      fprintf(stderr, "SARG: user name too long for: %s/%s.graph\n",tmp,user);
+   if (snprintf(tmp5,sizeof(tmp5),"%s/%s.graph",tmp,uinfo->filename)>=sizeof(tmp5)) {
+      debuga(_("user name too long for: %s/%s.graph"),tmp,uinfo->filename);
       exit(1);
    }
 
@@ -417,8 +412,8 @@ void greport_day(const char *user)
 
    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);
+      debuga(_("sort command return status %d"),WEXITSTATUS(cstatus));
+      debuga(_("sort command: %s"),csort);
       exit(1);
    }
 
@@ -432,18 +427,6 @@ void greport_day(const char *user)
      exit(1);
    }
 
-   strcpy(wuser,user);
-   if(strstr(wuser,"_") != 0)
-      fixip(wuser);
-
-   if(Ip2Name)
-      if((str=(char *) strstr(name, ".")) != (char *) NULL) {
-         if((str=(char *) strstr(str+1, ".")) != (char *) NULL)
-            ip2name(wuser,sizeof(wuser));
-   }
-
-   user_find(name, sizeof(name), wuser);
-
    while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
       fixendofline(buf);
       getword_start(&gwarea,buf);
diff --git a/html.c b/html.c
index 82a393bcd64eba5d1bfbc32340c96208ef94d677..ca965e2795c49020fafe1804360d3bf782466409 100644 (file)
--- a/html.c
+++ b/html.c
@@ -42,10 +42,10 @@ void htmlrel(void)
    char *buf;
    char arqin[MAXLEN], arqou[MAXLEN], arqper[MAXLEN], arqip[MAXLEN];
    char *url, tmsg[50], csort[MAXLEN];
-   char period[MAXLEN], usuario[MAXLEN], wusuario[MAXLEN], u2[MAXLEN], duser[MAXLEN];
+   char period[MAXLEN], usuario[MAXLEN], wusuario[MAXLEN], duser[MAXLEN];
    char userhora[9], userdia[9];
    char user_ip[MAXLEN], olduserip[MAXLEN], tmp2[MAXLEN], tmp3[MAXLEN];
-   char denied_report[255], name2[MAXLEN];
+   char denied_report[255];
    char *str;
    char warea[MAXLEN];
    char totuser[8];
@@ -62,6 +62,7 @@ void htmlrel(void)
    struct getwordstruct gwarea;
    struct longlinestruct line,line1;
    struct generalitemstruct item;
+   const struct userinfostruct *uinfo;
 
    if((ReportType & REPORT_TYPE_USERS_SITES) == 0) return;
 
@@ -136,6 +137,12 @@ void htmlrel(void)
       } else {
          wusuario[0]=0;
       }
+
+      uinfo=userinfo_find_from_file(wusuario);
+      if (!uinfo) {
+         debuga(_("Unknown user ID %s in directory %s"),wusuario,tmp);
+         exit(1);
+      }
       str=strrchr(wusuario,'.');
       if (str)
          strcpy(denied_report,str+1);
@@ -143,48 +150,30 @@ void htmlrel(void)
          strcpy(denied_report,wusuario);
 
       if (snprintf(warea,sizeof(warea),"%s/%s",dirname,wusuario)>=sizeof(warea)) {
-         fprintf(stderr,"SARG: destination directory too long: %s/%s\n",dirname,wusuario);
+         debuga(_("Destination directory too long: %s/%s"),dirname,wusuario);
          exit(1);
       }
       mkdir(warea,0755);
 
-      report_day(wusuario);
-      greport_day(wusuario);
+      report_day(uinfo);
+      greport_day(uinfo);
 
       strcpy(usuario,wusuario);
-      strcpy(arqin,tmp);
-      strcat(arqin,"/");
-      strcpy(arqou,dirname);
-      strcat(arqou,"/");
-      strcat(arqou,usuario);
-      strcat(arqou,"/");
-      strcat(arqou,usuario);
-      strcat(arqou,".html");
-      strcpy(duser,arqin);
-      strcat(duser,"denied_");
-      strcat(arqin,direntp->d_name);
-
-      if((str=(char *) strstr(denied_report, "_")) != (char *) NULL ) {
-         if((str=(char *) strstr(str+1, "_")) != (char *) NULL )
-            fixip(denied_report);
+      if (snprintf(arqin,sizeof(arqin),"%s/%s",tmp,direntp->d_name)>=sizeof(arqin)) {
+         debuga(_("Input file name too long: %s/%s"),tmp,direntp->d_name);
+         exit(1);
+      }
+      if (snprintf(arqou,sizeof(arqou),"%s/%s/%s.html",dirname,uinfo->filename,uinfo->filename)>=sizeof(arqou)) {
+         debuga(_("Output file name too long: %s/%s/%s.html"),dirname,uinfo->filename,uinfo->filename);
+         exit(1);
+      }
+      if (snprintf(duser,sizeof(duser),"%s/%s/denied_%s.html",tmp,direntp->d_name,denied_report)>=sizeof(duser)) {
+         debuga(_("File name too long: %s/%s/denied_%s.html"),tmp,direntp->d_name,denied_report);
+         exit(1);
       }
-      strcat(duser,denied_report);
-      strcat(duser,".html");
       if(access(duser, R_OK) != 0)
          denied_report[0]='\0';
 
-      strcpy(u2,usuario);
-      if(userip)
-         fixip(u2);
-      if(Ip2Name)
-         ip2name(u2,sizeof(u2));
-
-      user_find(name2, sizeof(name2), u2);
-
-      if(dotinuser && strchr(name2,'_')) {
-         subs(name2,sizeof(name2),"_",".");
-      }
-
       if ((fp_in = fopen(arqin, "r")) == 0){
          fprintf(stderr, "SARG: (html3) %s: %s\n",text[45],arqin);
          exit(1);
@@ -203,35 +192,35 @@ void htmlrel(void)
       while((buf=longline_read(fp_in,&line))!=NULL) {
          getword_start(&gwarea,buf);
          if (getword_atoll(&ltemp,&gwarea,'\t')<0) {
-            printf("SARG: Maybe you have a broken number of access in your %s file.\n",arqin);
+            debuga(_("There is a broken number of access in file %s"),arqin);
             exit(1);
          }
          tnacc+=ltemp;
          if (getword_atoll(&ltemp,&gwarea,'\t')<0) {
-            printf("SARG: Maybe you have a broken downloaded size in your %s file.\n",arqin);
+            debuga(_("There is a broken downloaded size in file %s"),arqin);
             exit(1);
          }
          tnbytes+=ltemp;
          if (getword_ptr(NULL,NULL,&gwarea,'\t')<0) {
-            debuga(_("Maybe you have a broken url in your %s file"),arqin);
+            debuga(_("There is a broken url in file %s"),arqin);
             exit(1);
          }
          if (getword_skip(MAXLEN,&gwarea,'\t')<0) {
-            printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqin);
+            debuga(_("There is a broken access code in file %s"),arqin);
             exit(1);
          }
          if (getword_atoll(&ltemp,&gwarea,'\t')<0) {
-            printf("SARG: Maybe you have a broken elapsed time in your %s file.\n",arqin);
+            debuga(_("There is a broken elapsed time in file %s"),arqin);
             exit(1);
          }
          tnelap+=ltemp;
          if (getword_atoll(&ltemp,&gwarea,'\t')<0) {
-            printf("SARG: Maybe you have a broken in-cache volume in your %s file.\n",arqin);
+            debuga(_("There is a broken in-cache volume in file %s"),arqin);
             exit(1);
          }
          tnincache+=ltemp;
          if (getword_atoll(&ltemp,&gwarea,'\n')<0) {
-            printf("SARG: Maybe you have a broken out-cache volume in your %s file (%d).\n",arqin,__LINE__);
+            debuga(_("There is a broken out-cache volume in file %s"),arqin);
             exit(1);
          }
          tnoucache+=ltemp;
@@ -246,7 +235,7 @@ void htmlrel(void)
 
       write_html_header(fp_ou,(IndexTree == INDEX_TREE_DATE) ? 4 : 2,_("User report"));
       fprintf(fp_ou,"<tr><td class=\"header_l\">%s:&nbsp;%s</td></tr>\n",text[89],period);
-      fprintf(fp_ou,"<tr><td class=\"header_l\">%s:&nbsp;%s</td></tr>\n",text[90],name2);
+      fprintf(fp_ou,"<tr><td class=\"header_l\">%s:&nbsp;%s</td></tr>\n",text[90],uinfo->label);
       fprintf(fp_ou,"<tr><td class=\"header_l\">%s:&nbsp;%s, %s</td></tr>\n",text[104],UserSortField,UserSortOrder);
       fprintf(fp_ou,"<tr><td class=\"header_c\">%s %s</td></tr>\n",text[32],text[55]);
       //fputs("<tr><td></td></tr>\n",fp_ou);
@@ -278,12 +267,7 @@ void htmlrel(void)
       fputs("</tr>\n",fp_ou);
 
       if(debug) {
-         if(userip) {
-            strcpy(u2,usuario);
-            fixip(u2);
-            debuga("%s: %s",text[61],u2);
-         } else
-            debuga("%s: %s",text[61],usuario);
+         debuga("%s: %s",text[61],usuario);
       }
 
       while((buf=longline_read(fp_in,&line))!=NULL) {
@@ -527,7 +511,7 @@ void htmlrel(void)
                }
                while(fgets(tmp6,sizeof(tmp6),fp_usr)!=NULL) {
                   fixendofline(tmp6);
-                  if(strcmp(tmp6,u2) == 0) {
+                  if(strcmp(tmp6,uinfo->label) == 0) {
                      limit_flag=1;
                      break;
                   }
@@ -540,11 +524,11 @@ void htmlrel(void)
                   fprintf(stderr, "SARG: (html10) %s: %s\n",text[45],PerUserLimitFile);
                   exit(1);
                }
-               fprintf(fp_usr,"%s\n",u2);
+               fprintf(fp_usr,"%s\n",uinfo->label);
                fclose(fp_usr);
 
                if(debug)
-                  debuga("%s %s %s (%d MB). %s %s",text[32],u2,text[74],PerUserLimit,text[75],PerUserLimitFile);
+                  debuga("%s %s %s (%d MB). %s %s",text[32],uinfo->label,text[74],PerUserLimit,text[75],PerUserLimitFile);
             }
          }
       }
index 623e7e4d48e840a95c12d14b5648c80cbc593c2b..8cdd5a455a9efa9200cec17d5d4977501f36f74f 100755 (executable)
@@ -152,7 +152,8 @@ int mkstemps(char *template, int suffixlen);
 #define MAXLEN 20000
 #define MAX_URL_LEN 40000
 #define MAX_TRUNCATED_URL 512
-#define MAX_USER_LEN 512
+#define MAX_USER_LEN 256
+#define MAX_USER_FNAME_LEN 128
 #define MAX_IP_LEN 64
 #define MAX_DATETIME_LEN 32
 #define MAXLOGS 255
@@ -207,6 +208,13 @@ int mkstemps(char *template, int suffixlen);
 #define INDEX_TREE_DATE 0x0001UL
 #define INDEX_TREE_FILE 0x0002UL
 
+#define NTLMUSERFORMAT_USER       0x0001UL
+#define NTLMUSERFORMAT_DOMAINUSER 0x0002UL
+
+#define RECORDWITHOUTUSER_IP        0x0001UL
+#define RECORDWITHOUTUSER_IGNORE    0x0002UL
+#define RECORDWITHOUTUSER_EVERYBODY 0x0004UL
+
 char outdir[MAXLEN];
 char dirname[MAXLEN];
 char buf[MAXLEN];
@@ -226,7 +234,7 @@ int RemoveTempFiles;
 char ReplaceIndex[256];
 unsigned long int Index;
 int OverwriteReport;
-char RecordsWithoutUser[20];
+unsigned long int RecordsWithoutUser;
 int UseComma;
 char MailUtility[PATH_MAX];
 int TopSitesNum;
@@ -313,7 +321,7 @@ char TitleFontSize[5];
 char wwwDocumentRoot[MAXLEN];
 char ExternalCSSFile[MAXLEN];
 char BlockIt[255];
-char NtlmUserFormat[30];
+unsigned long int NtlmUserFormat;
 unsigned long int IndexTree;
 int UserAuthentication;
 char AuthUserFile[255];
@@ -377,7 +385,6 @@ int  color2;
 int  color3;
 int  z1, z2, z3;
 int  ttopen;
-int  ind2;
 int  sarglog;
 int  isalog;
 int  dfrom;
@@ -397,7 +404,6 @@ int  SiteUsersReportLimit;
 int  DansGuardianReportLimit;
 int  SquidGuardReportLimit;
 int  UserReportLimit;
-int  dotinuser;
 int  realtime_refresh;
 int  realtime_access_log_lines;
 int  realt;
index f4c8a7c5ae8541be6d95358cd166eb6a1ffb02c7..addee806ff1ab7ed95a6b7407e6a173cc68d9a51 100755 (executable)
@@ -1,3 +1,6 @@
+/*!\file
+\brief Declaration of the structures and functions.
+*/
 
 struct getwordstruct
 {
@@ -46,6 +49,18 @@ struct generalitemstruct
    long long oucache;
 };
 
+struct userinfostruct
+{
+   //! The ID of the user as found in the input file.
+   char id[MAX_USER_LEN];
+   //! \c True if the ID is in fact the IP address from which the user connected.
+   int id_is_ip;
+   //! The name of the user to display in the report.
+   char label[MAX_USER_LEN];
+   //! The mangled name to use in file names of that user.
+   char filename[MAX_USER_FNAME_LEN];
+};
+
 // auth.c
 void htaccess(const char *name);
 
@@ -98,7 +113,7 @@ void free_exclude(void);
 void getconf(void);
 
 // grepday.c
-void greport_day(const char *user);
+void greport_day(const struct userinfostruct *user);
 void greport_cleanup(void);
 
 // html.c
@@ -124,10 +139,10 @@ void make_index(void);
 void realtime(void);
 
 // repday.c
-void report_day(const char *user);
+void report_day(const struct userinfostruct *user);
 
 // report.c
-void gravatmp(const char *oldaccuser, const char *oldurl, long long int nacc, long long int nbytes, const char *oldmsg, long long int nelap, int indexonly, long long int incache, long long int oucache);
+void gravatmp(const struct userinfostruct *uinfo, const char *oldurl, long long int nacc, long long int nbytes, const char *oldmsg, long long int nelap, int indexonly, long long int incache, long long int oucache);
 void gerarel(void);
 int ger_read(char *buffer,struct generalitemstruct *item,const char *filename);
 
@@ -157,7 +172,7 @@ void topsites(void);
 void topuser(void);
 
 // totday.c
-void day_totalize(const char *tmp, const char *user, int indexonly);
+void day_totalize(const char *tmp, const struct userinfostruct *uinfo, int indexonly);
 
 // totger.c
 int totalger(const char *dirname, int debug, const char *outdir);
@@ -168,6 +183,12 @@ void usage(const char *prog);
 // useragent.c
 void useragent(void);
 
+// userinfo.c
+struct userinfostruct *userinfo_create(const char *userid);
+void userinfo_free(void);
+struct userinfostruct *userinfo_find_from_file(const char *filename);
+struct userinfostruct *userinfo_find_from_id(const char *id);
+
 // usertab.c
 void init_usertab(const char *UserTabFile);
 void user_find(char *mappedname, int namelen, const char *userlogin);
@@ -189,7 +210,6 @@ void name_month(char *month,int month_len);
 void conv_month_name(char *month);
 void buildymd(const char *dia, const char *mes, const char *ano, char *wdata);
 void date_from(char *date, char *dfrom, char *duntil);
-void fixip(char *ip);
 char *fixnum(long long int value, int n);
 char *fixnum2(long long int value, int n);
 void fixnone(char *str);
diff --git a/log.c b/log.c
index 4ca2b7e0daf5da5de18d467e4e5063ede45bb74d..80fb0a2ddf0ffac76e046e91ade844dd4d4b3ae7 100644 (file)
--- a/log.c
+++ b/log.c
 #include "include/defs.h"
 
 #define REPORT_EVERY_X_LINES 5000
+#define MAX_OPEN_USER_FILES 10
+
+struct userfilestruct
+{
+   struct userfilestruct *next;
+   struct userinfostruct *user;
+   FILE *file;
+};
 
 static char *userfile=NULL;
 
@@ -63,7 +71,6 @@ int main(int argc,char *argv[])
 
    char sz_Download_Unsort[ 20000 ] ;
    FILE * fp_Download_Unsort = NULL ;
-   FILE * fp_Write_User = NULL ;
 
    extern int optind;
    extern int optopt;
@@ -111,7 +118,7 @@ int main(int argc,char *argv[])
    enum InputLogFormat ilf;
    int ilf_count[ILF_Last];
    int  ch;
-   int  x, l;
+   int  x;
    int  errflg=0;
    int  puser=0;
    int  fhost=0;
@@ -124,6 +131,9 @@ int main(int argc,char *argv[])
    int isa_ncols=0,isa_cols[ISACOL_Last];
    int from_stdin;
    int blen;
+   int maxopenfiles;
+   int nopen;
+   int id_is_ip;
    long totregsl=0;
    long totregsg=0;
    long totregsx=0;
@@ -136,9 +146,10 @@ int main(int argc,char *argv[])
    int OutputNonZero = REPORT_EVERY_X_LINES ;
    int download_flag=0;
    char *download_url;
-   char sz_Last_User[MAXLEN]="";
    struct getwordstruct gwarea;
    struct longlinestruct line;
+   struct userinfostruct *uinfo;
+   struct userfilestruct *first_user_file, *ufile, *ufile1, *prev_ufile;
 
    BgImage[0]='\0';
    LogoImage[0]='\0';
@@ -180,7 +191,7 @@ int main(int argc,char *argv[])
    RemoveTempFiles=1;
    strcpy(ReplaceIndex,"index.html");
    Index=INDEX_YES;
-   strcpy(RecordsWithoutUser,"ip");
+   RecordsWithoutUser=RECORDWITHOUTUSER_IP;
    UseComma=0;
    strcpy(MailUtility,"mailx");
    TopSitesNum=100;
@@ -232,7 +243,7 @@ int main(int argc,char *argv[])
    GraphFont[0]='\0';
 #endif
    strcpy(Ulimit,"20000");
-   strcpy(NtlmUserFormat,"domainname+username");
+   NtlmUserFormat=NTLMUSERFORMAT_DOMAINUSER;
    IndexTree=INDEX_TREE_FILE;
    strcpy(RealtimeTypes,"GET,PUT,CONNECT");
    strcpy(RealtimeUnauthRec,"show");
@@ -300,7 +311,6 @@ int main(int argc,char *argv[])
    color1=0;
    color2=0;
    color3=0;
-   dotinuser=0;
    realt=0;
    realtime_refresh=3;
    realtime_access_log_lines=1000;
@@ -309,8 +319,9 @@ int main(int argc,char *argv[])
    ndownload=0;
    squid24=0;
 
-   bzero(IncludeUsers, MAXLEN);
-   bzero(ExcludeString, MAXLEN);
+   bzero(IncludeUsers, sizeof(IncludeUsers));
+   bzero(ExcludeString, sizeof(ExcludeString));
+   first_user_file=NULL;
 
 #ifdef HAVE_LOCALE_H
    setlocale(LC_TIME,"");
@@ -674,6 +685,7 @@ int main(int argc,char *argv[])
    if(debug)
       debuga("sarg %s: %s",text[73],VERSION);
 
+   maxopenfiles=MAX_OPEN_USER_FILES;
 #ifdef HAVE_RLIM_T
    if (Ulimit[0] != '\0') {
       struct rlimit rl;
@@ -700,7 +712,7 @@ int main(int argc,char *argv[])
 #warning "No rlimit resource for the number of open files"
 #endif
       if(rc == -1) {
-            debuga("setrlimit error - %s\n",strerror(errno));
+            debuga(_("setrlimit error - %s\n"),strerror(errno));
       }
 
       if(debug)
@@ -1119,7 +1131,7 @@ int main(int argc,char *argv[])
             sprintf(data," %s/%s/%s:%s",dia,mes,ano,hora);
          }
 
-         if(strlen(user) > 150) {
+         if(strlen(user) > MAX_USER_LEN) {
             if (debugm) printf("User too long: %s\n",user);
             totregsx++;
             continue;
@@ -1167,25 +1179,6 @@ int main(int argc,char *argv[])
          }
 #endif
 
-         for(str=user; *str; str++) {
-            if(*str=='.') dotinuser++;
-            if(*str=='?' || *str=='.' || *str==':' || *str=='/' || *str=='\\' || *str=='\'' || *str=='$' || *str=='@' ||
-               *str=='\"' || *str=='*')
-               *str='_';
-         }
-
-         strlow(user);
-         if(strncmp(NtlmUserFormat,"user",4) == 0) {
-            if((str = strchr(user,'_')) != 0) {
-               strcpy(warea,str+1);
-               strcpy(user,warea);
-            }
-            if((str = strchr(user,'+')) != 0) {
-               strcpy(warea,str+1);
-               strcpy(user,warea);
-            }
-         }
-
          urly=url;
 
          if(ilf!=ILF_Sarg) {
@@ -1305,75 +1298,74 @@ int main(int argc,char *argv[])
          if(debugm)
             printf("DATE=%s IDATA=%d DFROM=%d DUNTIL=%d\n",date,idata,dfrom,duntil);
 
-         l=1;
-         if(l){
-            if(addr[0] != '\0'){
-               if(strcmp(addr,ip)==0)
-                  l=1;else l=0;
-            }
-            if(fhost) {
-//              l=vhexclude(ip);
-               l=vhexclude(url);
-               if(!l) {
-                  if (debugm) printf("Excluded site: %s\n",url);
-                  totregsx++;
-               }
+         if(addr[0] != '\0'){
+            if(strcmp(addr,ip)!=0) continue;
+         }
+         if(fhost) {
+            if(!vhexclude(url)) {
+               if (debugm) printf(_("Excluded site: %s\n"),url);
+               totregsx++;
+               continue;
             }
          }
+         if(url[0] == '\0') continue;
 
-         if(l){
-            if(date[0] != '\0'){
-               if(idata >= dfrom && idata <= duntil)
-                  l=1;else l=0;
-            }
+         if(date[0] != '\0'){
+            if(idata < dfrom || idata > duntil) continue;
          }
-         if(l){
-            if(hm[0] != '\0') {
-               bzero(hmr,sizeof(hmr));
-               chm++;
-               getword_start(&gwarea,hora);
-               while(chm) {
-                  if (getword_multisep(warea,sizeof(warea),&gwarea,':')<0){
-                     printf("SARG: Maybe you have a broken time in your %s file.\n",arq);
-                     exit(1);
-                  }
-                  strncat(hmr,warea,2);
-                  chm--;
-               }
-               strncat(hmr,gwarea.current,2);
 
-               if(atoi(hmr) >= atoi(hm) && atoi(hmr) <= atoi(hmf))
-                  l=1;else l=0;
+         if(hm[0] != '\0') {
+            bzero(hmr,sizeof(hmr));
+            chm++;
+            getword_start(&gwarea,hora);
+            while(chm) {
+               if (getword_multisep(warea,sizeof(warea),&gwarea,':')<0){
+                  printf("SARG: Maybe you have a broken time in your %s file.\n",arq);
+                  exit(1);
+               }
+               strncat(hmr,warea,2);
+               chm--;
             }
+            strncat(hmr,gwarea.current,2);
+
+            if(atoi(hmr) < atoi(hm) || atoi(hmr) > atoi(hmf)) continue;
          }
-         if(l){
-            if(site[0] != '\0'){
-               if(strstr(url,site)!=0)
-                  l=1;else l=0;
-            }
+
+         if(site[0] != '\0'){
+            if(strstr(url,site)==0) continue;
          }
 
-         if(userip)
+         if(userip) {
             strcpy(user,ip);
-
-         if(strcmp(user,"-") == 0 || strcmp(user," ") == 0 || strcmp(user,"") == 0) {
-            if(strcmp(RecordsWithoutUser,"ip") == 0)
-               strcpy(user,ip);
-            if(strcmp(RecordsWithoutUser,"ignore") == 0)
-               continue;
-            if(strcmp(RecordsWithoutUser,"everybody") == 0)
-               strcpy(user,"everybody");
-         }
-         if(us[0] != '\0'){
-            if(strcmp(user,us)==0)
-               l=1;
-            else
-               l=0;
+            id_is_ip=1;
+         } else {
+            id_is_ip=0;
+            if(strcmp(user,"-") == 0 || strcmp(user," ") == 0 || strcmp(user,"") == 0) {
+               if(RecordsWithoutUser == RECORDWITHOUTUSER_IP) {
+                  strcpy(user,ip);
+                  id_is_ip=1;
+               }
+               if(RecordsWithoutUser == RECORDWITHOUTUSER_IGNORE)
+                  continue;
+               if(RecordsWithoutUser == RECORDWITHOUTUSER_EVERYBODY)
+                  strcpy(user,"everybody");
+            } else {
+               strlow(user);
+               if(NtlmUserFormat == NTLMUSERFORMAT_USER) {
+                  if((str = strchr(user,'_')) != 0) {
+                     strcpy(warea,str+1);
+                     strcpy(user,warea);
+                  }
+                  if((str = strchr(user,'+')) != 0) {
+                     strcpy(warea,str+1);
+                     strcpy(user,warea);
+                  }
+               }
+            }
          }
 
-         if(dotinuser) {
-            subs(user,sizeof(user),"_",".");
-            dotinuser=0;
+         if(us[0] != '\0'){
+            if(strcmp(user,us)!=0) continue;
          }
 
          if(puser) {
@@ -1382,103 +1374,141 @@ int main(int argc,char *argv[])
                continue;
          }
 
-         if(l) {
-            if(fuser) {
-               l=vuexclude(user);
-               if(!l) {
-                  if (debugm) printf("Excluded user: %s\n",user);
-                  totregsx++;
-               }
+         if(fuser) {
+            if(!vuexclude(user)) {
+               if (debugm) printf(_("Excluded user: %s\n"),user);
+               totregsx++;
+               continue;
             }
          }
 
-         if(l) {
-            if(userip)
-               fixip(user);
-         }
+         if(strcmp(user,"-") ==0 || strcmp(user," ") ==0 || strcmp(user,"") ==0 || strcmp(user,":") ==0)
+            continue;
 
-         if(l && max_elapsed) {
+         if(max_elapsed) {
             if(atol(elap)>max_elapsed) {
                elap[0]='0';
                elap[1]='\0';
             }
          }
 
-         if(l) {
-            if(strcmp(user,"-") !=0 && url[0] != '\0' && strcmp(user," ") !=0 && strcmp(user,"") !=0 && strcmp(user,":") !=0){
-               if((str=(char *) strstr(linebuf, "[SmartFilter:")) != (char *) NULL ) {
-                  fixendofline(str);
-                  sprintf(smartfilter,"\"%s\"",str+1);
-               } else sprintf(smartfilter,"\"\"");
-
-               if ( strcmp ( user , sz_Last_User ) != 0 ) {
-                  if ( fp_Write_User )
-                     fclose( fp_Write_User ) ;
-                  sprintf (tmp3, "%s/sarg/%s.unsort", tmp, user);
-
-                  if ((fp_Write_User = MY_FOPEN (tmp3, "a")) == NULL) {
-                     fprintf (stderr, "%s: (log) %s: %s - %s\n", argv[0], text[9], tmp3, strerror(errno));
-                     exit (1);
+         if((str=(char *) strstr(linebuf, "[SmartFilter:")) != (char *) NULL ) {
+            fixendofline(str);
+            sprintf(smartfilter,"\"%s\"",str+1);
+         } else sprintf(smartfilter,"\"\"");
+
+         nopen=0;
+         prev_ufile=NULL;
+         for (ufile=first_user_file ; ufile && strcmp(user,ufile->user->id)!=0 ; ufile=ufile->next) {
+            prev_ufile=ufile;
+            if (ufile->file) nopen++;
+         }
+         if (!ufile) {
+            ufile=malloc(sizeof(*ufile));
+            if (!ufile) {
+               debuga(_("Not enough memory to store the user %s"),user);
+               exit(1);
+            }
+            memset(ufile,0,sizeof(*ufile));
+            ufile->next=first_user_file;
+            first_user_file=ufile;
+            uinfo=userinfo_create(user);
+            ufile->user=uinfo;
+            uinfo->id_is_ip=id_is_ip;
+         } else {
+            if (prev_ufile) {
+               prev_ufile->next=ufile->next;
+               ufile->next=first_user_file;
+               first_user_file=ufile;
+            }
+         }
+
+         if (ufile->file==NULL) {
+            if (nopen>=maxopenfiles) {
+               x=0;
+               for (ufile1=first_user_file ; ufile1 ; ufile1=ufile1->next) {
+                  if (ufile1->file!=NULL) {
+                     if (x>=maxopenfiles) {
+                        fclose(ufile1->file);
+                        ufile1->file=NULL;
+                     }
+                     x++;
                   }
-                  strcpy( sz_Last_User , user ) ;
                }
-               fprintf(fp_Write_User, "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",dia,hora,user,ip,url,tam,code,elap,smartfilter);
+            }
+            sprintf (tmp3, "%s/sarg/%s.unsort", tmp, ufile->user->filename);
+            if ((ufile->file = MY_FOPEN (tmp3, "a")) == NULL) {
+               fprintf (stderr, "%s: (log) %s: %s - %s\n", argv[0], text[9], tmp3, strerror(errno));
+               exit (1);
+            }
+         }
 
-               if(fp_log && ilf!=ILF_Sarg)
-                  fprintf(fp_log, "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",dia,hora,user,ip,url,tam,code,elap,smartfilter);
+         /*if ( strcmp ( user , sz_Last_User ) != 0 ) {
+            if ( fp_Write_User )
+               fclose( fp_Write_User ) ;
+            sprintf (tmp3, "%s/sarg/%s.unsort", tmp, user);
 
-               totregsg++;
+            if ((fp_Write_User = MY_FOPEN (tmp3, "a")) == NULL) {
+               fprintf (stderr, "%s: (log) %s: %s - %s\n", argv[0], text[9], tmp3, strerror(errno));
+               exit (1);
+            }
+            strcpy( sz_Last_User , user ) ;
+         }*/
+         fprintf(ufile->file, "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",dia,hora,ip,url,tam,code,elap,smartfilter);
 
-               if(download_flag && strstr(code,"DENIED") == 0) {
-                  ndownload = 1;
+         if(fp_log && ilf!=ILF_Sarg)
+            fprintf(fp_log, "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",dia,hora,user,ip,url,tam,code,elap,smartfilter);
 
-                  if ( ! fp_Download_Unsort ) {
-                     if ((fp_Download_Unsort = MY_FOPEN ( sz_Download_Unsort, "a")) == NULL) {
-                        fprintf (stderr, "%s: (log) %s: %s - %s\n", argv[0], text[9], tmp3, strerror(errno));
-                        exit (1);
-                     }
-                  }
-                  fprintf(fp_Download_Unsort,"%s\t%s\t%s\t%s\t%s\n",dia,hora,user,ip,download_url);
-               }
+         totregsg++;
 
-               if((ReportType & REPORT_TYPE_DENIED) != 0 || (ReportType & REPORT_TYPE_AUTH_FAILURES) != 0) {
-                  if(strstr(code,"DENIED/403") != 0) {
-                     fprintf(fp_denied, "%s\t%s\t%s\t%s\t%s\n",dia,hora,user,ip,urly);
-                     denied_count++;
-                  }
-                  if(strstr(code,"DENIED/401") != 0 || strstr(code,"DENIED/407") != 0) {
-                     if(fp_authfail)
-                        fprintf(fp_authfail, "%s\t%s\t%s\t%s\t%s\n",dia,hora,user,ip,urly);
-                     authfail_count++;
-                  }
-               }
+         if(download_flag && strstr(code,"DENIED") == 0) {
+            ndownload = 1;
 
-               if((!totper || idata<mindate) && ilf!=ILF_Sarg){
-                  totper++;
-                  mindate=idata;
-                  sprintf(period,"%s-",tbuf);
-                  strcpy(start_hour,tbuf2);
-                  if(date[0] != '\0')
-                     fixper(tbuf, period, cduntil);
-                  if(debugz){
-                     debugaz("tbuf",tbuf);
-                     debugaz("period",period);
-                  }
+            if ( ! fp_Download_Unsort ) {
+               if ((fp_Download_Unsort = MY_FOPEN ( sz_Download_Unsort, "a")) == NULL) {
+                  fprintf (stderr, "%s: (log) %s: %s - %s\n", argv[0], text[9], tmp3, strerror(errno));
+                  exit (1);
                }
             }
+            fprintf(fp_Download_Unsort,"%s\t%s\t%s\t%s\t%s\n",dia,hora,user,ip,download_url);
+         }
+
+         if((ReportType & REPORT_TYPE_DENIED) != 0 || (ReportType & REPORT_TYPE_AUTH_FAILURES) != 0) {
+            if(strstr(code,"DENIED/403") != 0) {
+               fprintf(fp_denied, "%s\t%s\t%s\t%s\t%s\n",dia,hora,user,ip,urly);
+               denied_count++;
+            }
+            if(strstr(code,"DENIED/401") != 0 || strstr(code,"DENIED/407") != 0) {
+               if(fp_authfail)
+                  fprintf(fp_authfail, "%s\t%s\t%s\t%s\t%s\n",dia,hora,user,ip,urly);
+               authfail_count++;
+            }
+         }
 
-            if(debugm){
-               printf("IP=\t%s\n",ip);
-               printf("USER=\t%s\n",user);
-               printf("ELAP=\t%s\n",elap);
-               printf("DATE=\t%s\n",dia);
-               printf("TIME=\t%s\n",hora);
-               printf("FUNC=\t%s\n",fun);
-               printf("URL=\t%s\n",url);
-               printf("CODE=\t%s\n",code);
-               printf("LEN=\t%s\n",tam);
+         if((!totper || idata<mindate) && ilf!=ILF_Sarg){
+            totper++;
+            mindate=idata;
+            sprintf(period,"%s-",tbuf);
+            strcpy(start_hour,tbuf2);
+            if(date[0] != '\0')
+               fixper(tbuf, period, cduntil);
+            if(debugz){
+               debugaz("tbuf",tbuf);
+               debugaz("period",period);
             }
          }
+
+         if(debugm){
+            printf("IP=\t%s\n",ip);
+            printf("USER=\t%s\n",user);
+            printf("ELAP=\t%s\n",elap);
+            printf("DATE=\t%s\n",dia);
+            printf("TIME=\t%s\n",hora);
+            printf("FUNC=\t%s\n",fun);
+            printf("URL=\t%s\n",url);
+            printf("CODE=\t%s\n",code);
+            printf("LEN=\t%s\n",tam);
+         }
       }
       if (!from_stdin) {
          fclose(fp_in);
@@ -1491,8 +1521,11 @@ int main(int argc,char *argv[])
    if ( fp_Download_Unsort )
      fclose (fp_Download_Unsort);
 
-   if (fp_Write_User)
-     fclose (fp_Write_User);
+   for (ufile=first_user_file ; ufile ; ufile=ufile1) {
+      ufile1=ufile->next;
+      if (ufile->file!=NULL) fclose(ufile->file);
+      free(ufile);
+   }
 
    free_download();
    free_excludecodes();
@@ -1526,6 +1559,7 @@ int main(int argc,char *argv[])
             fclose(fp_denied);
          if(fp_authfail)
             fclose(fp_authfail);
+         userinfo_free();
          if(userfile)
             free(userfile);
          close_usertab();
@@ -1544,6 +1578,7 @@ int main(int argc,char *argv[])
          fclose(fp_denied);
       if(fp_authfail)
          fclose(fp_authfail);
+      userinfo_free();
       if(userfile)
          free(userfile);
       close_usertab();
@@ -1636,6 +1671,7 @@ int main(int argc,char *argv[])
       unlinkdir(tmp,0);
    }
 
+   userinfo_free();
    if(userfile)
       free(userfile);
    close_usertab();
index b2d8e3ab2fb5a1b4e768fe88951fd4113fbf512e..b5e38a44bb3f839fd39c1c4bbf8c901b58a2573f 100644 (file)
--- a/po/fr.po
+++ b/po/fr.po
@@ -7,7 +7,7 @@ msgid ""
 msgstr ""
 "Project-Id-Version: @PACKAGE@ @VERSION@\n"
 "Report-Msgid-Bugs-To: fmarchal@users.sourceforge.net\n"
-"POT-Creation-Date: 2010-02-09 14:07+0100\n"
+"POT-Creation-Date: 2010-02-28 15:56+0100\n"
 "PO-Revision-Date: 2010-02-09 14:23+0100\n"
 "Last-Translator: Frederic Marchal <fmarchal@users.sourceforge.net>\n"
 "Language-Team: French\n"
@@ -16,65 +16,641 @@ msgstr ""
 "Content-Transfer-Encoding: 8bit\n"
 "Plural-Forms: nplurals=2; plural=(n > 1);\n"
 
-#: authfail.c:97
+#: authfail.c:78
+#, c-format
+msgid "(authfail) read error in %s"
+msgstr ""
+
+#: authfail.c:86 grepday.c:415 realtime.c:82 siteuser.c:80 smartfilter.c:85
+#: topuser.c:172
+#, c-format
+msgid "sort command return status %d"
+msgstr ""
+
+#: authfail.c:87 authfail.c:92 grepday.c:416 realtime.c:83 siteuser.c:81
+#: siteuser.c:87 smartfilter.c:86 smartfilter.c:91 topuser.c:173
+#, c-format
+msgid "sort command: %s"
+msgstr ""
+
+#: authfail.c:102
 msgid "Authentication Failures"
 msgstr "Erreur d'authentification"
 
-#: dansguardian_report.c:85
+#: authfail.c:114 html.c:94 html.c:183 html.c:385 html.c:413 siteuser.c:119
+#: topsites.c:108 topsites.c:215
+#, c-format
+msgid "Not enough memory to read file %s"
+msgstr ""
+
+#: authfail.c:122 denied.c:105 download.c:110 squidguard_report.c:97
+#, c-format
+msgid "There is a broken record or garbage in file %s"
+msgstr ""
+
+#: authfail.c:126 denied.c:109 download.c:114 html.c:205
+#: squidguard_report.c:101
+#, c-format
+msgid "There is a broken url in file %s"
+msgstr ""
+
+#: authfail.c:132 denied.c:115 download.c:120 siteuser.c:128 smartfilter.c:130
+#: topuser.c:284
+#, c-format
+msgid "Unknown user ID %s in file %s"
+msgstr ""
+
+#: dansguardian_log.c:135 dansguardian_log.c:144 dansguardian_report.c:97
+#: log.c:1004 log.c:1063 realtime.c:210 realtime.c:214 realtime.c:218
+#: realtime.c:222 util.c:790 util.c:794
+#, c-format
+msgid "Maybe you have a broken record or garbage in your %s file"
+msgstr ""
+
+#: dansguardian_log.c:139 dansguardian_report.c:101 html.c:284 log.c:915
+#: log.c:974 realtime.c:227 topsites.c:231
+#, c-format
+msgid "Maybe you have a broken url in your %s file"
+msgstr ""
+
+#: dansguardian_report.c:69
+#, c-format
+msgid "(dansguardian_report) read error in %s"
+msgstr ""
+
+#: dansguardian_report.c:84
 msgid "DansGuardian"
 msgstr "DansGuardian"
 
-#: denied.c:85
+#: dansguardian_report.c:105
+#, c-format
+msgid "Maybe you have a broken rule in your %s file"
+msgstr ""
+
+#: denied.c:72
+#, c-format
+msgid "(denied) read error in %s"
+msgstr ""
+
+#: denied.c:87
 msgid "DENIED"
 msgstr "DENIED"
 
-#: download.c:90
+#: denied.c:97
+#, c-format
+msgid "Not enough memory to read the denied accesses"
+msgstr ""
+
+#: download.c:77
+#, c-format
+msgid "(download) read error in %s"
+msgstr ""
+
+#: download.c:92
 msgid "Downloads"
 msgstr "Téléchargements"
 
-#: html.c:238
+#: download.c:102 topuser.c:245
+#, c-format
+msgid "Not enough memory to read the downloaded files"
+msgstr ""
+
+#: email.c:210
+#, c-format
+msgid "There may be a broken user in file %s"
+msgstr ""
+
+#: email.c:214
+#, c-format
+msgid "There may be a broken number of bytes in file %s"
+msgstr ""
+
+#: email.c:218 html.c:195
+#, c-format
+msgid "There is a broken number of access in file %s"
+msgstr ""
+
+#: email.c:222 html.c:213
+#, c-format
+msgid "There is a broken elapsed time in file %s"
+msgstr ""
+
+#: grepday.c:391
+#, c-format
+msgid "user name too long for: %s/%s/graph_day.png"
+msgstr ""
+
+#: grepday.c:395
+#, c-format
+msgid "user name too long for: %s/%s.day"
+msgstr ""
+
+#: grepday.c:399
+#, c-format
+msgid "user name too long for: %s/%s.graph"
+msgstr ""
+
+#: html.c:143
+#, c-format
+msgid "Unknown user ID %s in directory %s"
+msgstr ""
+
+#: html.c:153
+#, c-format
+msgid "Destination directory too long: %s/%s"
+msgstr ""
+
+#: html.c:163
+#, c-format
+msgid "Input file name too long: %s/%s"
+msgstr ""
+
+#: html.c:167
+#, c-format
+msgid "Output file name too long: %s/%s/%s.html"
+msgstr ""
+
+#: html.c:171
+#, c-format
+msgid "File name too long: %s/%s/denied_%s.html"
+msgstr ""
+
+#: html.c:200
+#, c-format
+msgid "There is a broken downloaded size in file %s"
+msgstr ""
+
+#: html.c:209
+#, c-format
+msgid "There is a broken access code in file %s"
+msgstr ""
+
+#: html.c:218
+#, c-format
+msgid "There is a broken in-cache volume in file %s"
+msgstr ""
+
+#: html.c:223
+#, c-format
+msgid "There is a broken out-cache volume in file %s"
+msgstr ""
+
+#: html.c:236
 msgid "User report"
 msgstr "Rapport par utilisateur"
 
-#: repday.c:72
+#: html.c:423
+#, c-format
+msgid "Maybe you have a broken user url in your %s file"
+msgstr ""
+
+#: index.c:339
+#, c-format
+msgid "Maybe you have a broken week day in your %s%s/sarg-date file"
+msgstr ""
+
+#: index.c:343
+#, c-format
+msgid "Maybe you have a broken month in your %s%s/sarg-date file"
+msgstr ""
+
+#: index.c:347
+#, c-format
+msgid "Maybe you have a broken day in your %s%s/sarg-date file"
+msgstr ""
+
+#: index.c:351 index.c:361
+#, c-format
+msgid "Maybe you have a broken time in your %s%s/sarg-date file"
+msgstr ""
+
+#: index.c:356
+#, c-format
+msgid "Maybe you have a broken year in your %s%s/sarg-date file"
+msgstr ""
+
+#: log.c:715
+#, c-format
+msgid "setrlimit error - %s\n"
+msgstr ""
+
+#: log.c:726
+#, c-format
+msgid "Not enough memory to read a log file"
+msgstr ""
+
+#: log.c:1306
+#, c-format
+msgid "Excluded site: %s\n"
+msgstr ""
+
+#: log.c:1379
+#, c-format
+msgid "Excluded user: %s\n"
+msgstr ""
+
+#: log.c:1409
+#, c-format
+msgid "SARG: Not enough memory to store the user %s\n"
+msgstr ""
+
+#: realtime.c:59
+#, c-format
+msgid "(realtime) mkstemp error - %s"
+msgstr ""
+
+#: realtime.c:64 realtime.c:202
+#, c-format
+msgid "Not enough memory to read the log file"
+msgstr ""
+
+#: realtime.c:72
+#, c-format
+msgid "Maybe a broken record or garbage was returned by %s"
+msgstr ""
+
+#: realtime.c:104
+#, c-format
+msgid "The time stamp at column 1 is too long."
+msgstr ""
+
+#: realtime.c:108
+#, c-format
+msgid "The connection duration at column 2 is too long."
+msgstr ""
+
+#: realtime.c:116
+#, c-format
+msgid "The IP address at column 3 is too long."
+msgstr ""
+
+#: realtime.c:120
+#, c-format
+msgid "The status at column 4 is too long."
+msgstr ""
+
+#: realtime.c:124
+#, c-format
+msgid "The size at column 5 is too long."
+msgstr ""
+
+#: realtime.c:128
+#, c-format
+msgid "The action at column 6 is too long."
+msgstr ""
+
+#: realtime.c:133 realtime.c:142 realtime.c:146
+#, c-format
+msgid "The URL at column 7 is too long."
+msgstr ""
+
+#: realtime.c:137
+#, c-format
+msgid "The user ID at column 8 is too long."
+msgstr ""
+
+#: realtime.c:150
+#, c-format
+msgid "The URL at column 7 is too long"
+msgstr ""
+
+#: realtime.c:154
+#, c-format
+msgid "The data at column 8 is too long"
+msgstr ""
+
+#: realtime.c:158
+#, c-format
+msgid "The user at column 9 is too long"
+msgstr ""
+
+#: realtime.c:195
+#, c-format
+msgid "(realtime) open error %s - %s"
+msgstr ""
+
+#: realtime.c:255 report.c:203 report.c:298 report.c:328 siteuser.c:139
+#: siteuser.c:190 topsites.c:122 topsites.c:137
+#, c-format
+msgid "Not enough memory to store the url"
+msgstr ""
+
+#: repday.c:56
+#, c-format
+msgid "Output file name too long: %s/%s/d%s.html"
+msgstr ""
+
+#: repday.c:74
 msgid "Day report"
 msgstr "Rapport journalier"
 
-#: report.c:250
+#: repday.c:103
+#, c-format
+msgid "There is a broken date in file %s"
+msgstr ""
+
+#: repday.c:112
+#, c-format
+msgid "There is a broken time in file %s"
+msgstr ""
+
+#: repday.c:116
+#, c-format
+msgid "There is a broken quantity in file %s"
+msgstr ""
+
+#: report.c:134
+#, c-format
+msgid "Ignoring unknown user file %s"
+msgstr ""
+
+#: report.c:152
+#, c-format
+msgid "Not enough memory to read the downloaded files."
+msgstr ""
+
+#: report.c:162
+#, c-format
+msgid "Maybe you have a broken record or garbage in your %s file (%d)."
+msgstr ""
+
+#: report.c:167
+#, c-format
+msgid "Maybe you have a broken elapsed time in your %s file (%d)."
+msgstr ""
+
+#: report.c:171
+#, c-format
+msgid "Maybe you have a broken smart info in your %s file (%d)."
+msgstr ""
+
+#: report.c:275
 msgid "Site access report"
 msgstr "Rapport des sites visités"
 
-#: siteuser.c:95
+#: report.c:433 report.c:482
+#, c-format
+msgid "Temporary file name too long: %s/%s.utmp"
+msgstr ""
+
+#: report.c:458
+#, c-format
+msgid "Temporary file name too long: %s/%s.htmp"
+msgstr ""
+
+#: report.c:625
+#, c-format
+msgid "Invalid total number of accesses in %s"
+msgstr ""
+
+#: report.c:642
+#, c-format
+msgid "Invalid total size in %s"
+msgstr ""
+
+#: report.c:659
+#, c-format
+msgid "Invalid total elapsed time in %s"
+msgstr ""
+
+#: report.c:676
+#, c-format
+msgid "Invalid total cache hit in %s"
+msgstr ""
+
+#: report.c:693
+#, c-format
+msgid "Invalid total cache miss in %s"
+msgstr ""
+
+#: report.c:703
+#, c-format
+msgid "User name too long or invalid in %s"
+msgstr ""
+
+#: report.c:719
+#, c-format
+msgid "Invalid number of accesses in %s"
+msgstr ""
+
+#: report.c:736
+#, c-format
+msgid "Invalid number of bytes in %s"
+msgstr ""
+
+#: report.c:745
+#, c-format
+msgid "URL too long or invalid in %s"
+msgstr ""
+
+#: report.c:753
+#, c-format
+msgid "IP address too long or invalid in %s"
+msgstr ""
+
+#: report.c:761
+#, c-format
+msgid "Time too long or invalid in %s"
+msgstr ""
+
+#: report.c:769
+#, c-format
+msgid "Date too long or invalid in %s"
+msgstr ""
+
+#: report.c:785
+#, c-format
+msgid "Invalid elapsed time in %s"
+msgstr ""
+
+#: report.c:802
+#, c-format
+msgid "Invalid cache hit size in %s"
+msgstr ""
+
+#: report.c:819
+#, c-format
+msgid "Invalid cache miss size in %s"
+msgstr ""
+
+#: siteuser.c:72
+#, c-format
+msgid "(siteuser) read error in %s"
+msgstr ""
+
+#: siteuser.c:96
 msgid "Sites & Users"
 msgstr "Sites & Utilisateurs"
 
-#: squidguard_report.c:85
+#: smartfilter.c:74
+#, c-format
+msgid "(smartfilter) read error in %s"
+msgstr ""
+
+#: smartfilter.c:80
+#, c-format
+msgid "cannot build the sort command to sort file %s"
+msgstr ""
+
+#: smartfilter.c:124
+#, c-format
+msgid "There is e a broken record or garbage in file %s"
+msgstr ""
+
+#: squidguard_log.c:102 squidguard_log.c:107 squidguard_log.c:112
+#: squidguard_log.c:173
+#, c-format
+msgid "Maybe you have a broken record or garbage in your %s file."
+msgstr ""
+
+#: squidguard_log.c:117
+#, c-format
+msgid "Year string too long in squidGuard log file %s"
+msgstr ""
+
+#: squidguard_log.c:123
+#, c-format
+msgid "Month string too long in squidGuard log file %s"
+msgstr ""
+
+#: squidguard_log.c:129
+#, c-format
+msgid "Day string too long in squidGuard log file %s"
+msgstr ""
+
+#: squidguard_log.c:135
+#, c-format
+msgid "Hour string too long in squidGuard log file %s"
+msgstr ""
+
+#: squidguard_log.c:141
+#, c-format
+msgid "Banning list name too long in squidGuard log file %s"
+msgstr ""
+
+#: squidguard_log.c:147
+#, c-format
+msgid "IP address too long in squidGuard log file %s"
+msgstr ""
+
+#: squidguard_log.c:153
+#, c-format
+msgid "User ID too long in squidGuard log file %s"
+msgstr ""
+
+#: squidguard_log.c:159
+#, c-format
+msgid "URL too long in squidGuard log file %s"
+msgstr ""
+
+#: squidguard_report.c:69
+#, c-format
+msgid "(squidguard) read error in %s"
+msgstr ""
+
+#: squidguard_report.c:84
 msgid "SQUIDGUARD"
 msgstr "SQUIDGUARD"
 
-#: topsites.c:219
+#: squidguard_report.c:105
+#, c-format
+msgid "There is a broken rule in file %s"
+msgstr ""
+
+#: topsites.c:199
 msgid "Top sites"
 msgstr "Sites les plus visités"
 
-#: topuser.c:233
+#: topuser.c:107 util.c:771
+#, c-format
+msgid "Not enough memory to read the file %s"
+msgstr ""
+
+#: topuser.c:189
 #, c-format
 msgid "SARG report for %s"
 msgstr "Rapport pour %s"
 
-#: topuser.c:251
+#: topuser.c:207
 msgid "Useragent"
 msgstr "Useragent"
 
-#: useragent.c:158
+#: topuser.c:252
+#, c-format
+msgid "There may be a broken user in file %s."
+msgstr ""
+
+#: topuser.c:256
+#, c-format
+msgid "There may be a broken number of bytes in file %s."
+msgstr ""
+
+#: topuser.c:260
+#, c-format
+msgid "There may be a broken number of access in file %s."
+msgstr ""
+
+#: topuser.c:264
+#, c-format
+msgid "There may be a broken elpased time in file %s."
+msgstr ""
+
+#: topuser.c:268
+#, c-format
+msgid "There may be a broken in-cache size in file %s."
+msgstr ""
+
+#: topuser.c:272
+#, c-format
+msgid "There may be a broken out-of-cache size in file %s."
+msgstr ""
+
+#: totger.c:51
+#, c-format
+msgid "Not enough memory to read the temporary file %s"
+msgstr ""
+
+#: useragent.c:160
 msgid "Squid Useragent's Report"
 msgstr "Rapport des useragents de Squid"
 
-#: util.c:77
+#: util.c:79
 #, c-format
 msgid "getword backtrace:"
 msgstr "getword backtrace"
 
-#: util.c:1584
+#: util.c:98
+#, c-format
+msgid "Cannot parse again the line as it was modified"
+msgstr ""
+
+#: util.c:242
+#, c-format
+msgid "Invalid buffer passed to getword_ptr"
+msgstr ""
+
+#: util.c:340
+#, c-format
+msgid ""
+"The requested number length passed to my_lltoa (%d) is bigger than the "
+"output buffer size (%d)"
+msgstr ""
+
+#: util.c:478
+msgid "SARG: "
+msgstr ""
+
+#: util.c:784
+#, c-format
+msgid "Maybe you have a invalid user in your %s file"
+msgstr ""
+
+#: util.c:1651
 #, c-format
 msgid "cannot stat %s"
 msgstr "Impossible d'obtenir les stat de %s"
+
+#: util.c:1710 util.c:1723
+#, c-format
+msgid "Not enough memory to read one more line from the input log file"
+msgstr ""
index 43127b81f2a1d016d5db2c73de8f1d74bc296b34..f3d0a5b0082975f7c4662daaad647ad03e1c8c09 100755 (executable)
@@ -56,7 +56,7 @@ static void getlog(void)
    fd2 = mkstemp(template2);
 
    if((fd1 == -1 ) || ((tmp = fdopen (fd1, "w+" )) == NULL)  ) {    /* failure, bail out */
-       fprintf(stderr, "SARG: (realtime) mkstemp error - %s\n",strerror(errno));
+       debuga(_("(realtime) mkstemp error - %s"),strerror(errno));
        exit(1);
    }
 
@@ -69,7 +69,7 @@ static void getlog(void)
    fp = popen(cmd, "r");
    while((buf=longline_read(fp,&line)) != NULL )
       if (getdata(buf,tmp)<0) {
-         fprintf(stderr,"SARG: Maybe a broken record or garbage was returned by %s.\n",cmd);
+         debuga(_("Maybe a broken record or garbage was returned by %s"),cmd);
          exit(1);
       }
    pclose(fp);
@@ -79,8 +79,8 @@ static void getlog(void)
    sprintf(cmd,"sort -r -k 1,1 -k 2,2 -o \"%s\" \"%s\"",template2,template1);
    cstatus=system(cmd);
    if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
-      fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus));
-      fprintf(stderr, "SARG: sort command: %s\n",cmd);
+      debuga(_("sort command return status %d"),WEXITSTATUS(cstatus));
+      debuga(_("sort command: %s"),cmd);
       exit(1);
    }
    unlink(template1);
@@ -101,11 +101,11 @@ static int getdata(char *rec, FILE *ftmp)
 
    getword_start(&gwarea,rec);
    if (getword(dat,sizeof(dat),&gwarea,' ')<0) {
-      fprintf(stderr,"SARG: The time stamp at column 1 is too long.\n");
+      debuga(_("The time stamp at column 1 is too long."));
       return(-1);
    }
    if (getword(warea,sizeof(warea),&gwarea,' ')<0) {
-      fprintf(stderr,"SARG: The connection duration at column 2 is too long.\n");
+      debuga(_("The connection duration at column 2 is too long."));
       return(-1);
    }
    while(strcmp(warea,"") == 0 && gwarea.current[0] != '\0')
@@ -113,19 +113,19 @@ static int getdata(char *rec, FILE *ftmp)
          return(-1);
       }
    if (getword(ip,sizeof(ip),&gwarea,' ')<0) {
-      fprintf(stderr,"SARG: The IP address at column 3 is too long.\n");
+      debuga(_("The IP address at column 3 is too long."));
       return(-1);
    }
    if (getword_skip(MAXLEN,&gwarea,' ')<0) {
-      fprintf(stderr,"SARG: The status at column 4 is too long.\n");
+      debuga(_("The status at column 4 is too long."));
       return(-1);
    }
    if (getword_skip(MAXLEN,&gwarea,' ')<0) {
-      fprintf(stderr,"SARG: The size at column 5 is too long.\n");
+      debuga(_("The size at column 5 is too long."));
       return(-1);
    }
    if (getword(typ,sizeof(typ),&gwarea,' ')<0) {
-      fprintf(stderr,"SARG: The action at column 6 is too long.\n");
+      debuga(_("The action at column 6 is too long."));
       return(-1);
    }
    if(strncmp(typ,"CONNECT",7) == 0) {
@@ -139,11 +139,11 @@ static int getdata(char *rec, FILE *ftmp)
       }
    }else {
       if (getword_skip(MAXLEN,&gwarea,'/')<0) {
-         fprintf(stderr,"SARG: The URL at column 7 is too long.\n");
+         debuga(_("The URL at column 7 is too long."));
          return(-1);
       }
       if (getword_skip(MAXLEN,&gwarea,'/')<0) {
-         fprintf(stderr,"SARG: The URL at column 7 is too long.\n");
+         debuga(_("The URL at column 7 is too long."));
          return(-1);
       }
       if (getword_ptr(rec,&url,&gwarea,'/')<0) {
@@ -192,7 +192,7 @@ static void datashow(const char *tmp)
    struct longlinestruct line;
 
    if((fin=fopen(tmp,"r"))==NULL) {
-      fprintf(stderr, "SARG: (realtime) open error %s - %s\n",tmp,strerror(errno));
+      debuga(_("(realtime) open error %s - %s"),tmp,strerror(errno));
       exit(1);
    }
 
@@ -244,10 +244,6 @@ static void datashow(const char *tmp)
          ip2name(u2,sizeof(u2));
       user_find(name, sizeof(name), u2);
 
-      if(dotinuser && strchr(name,'_')) {
-         subs(name,sizeof(name),"_",".");
-      }
-
       printf("<tr><td class=\"data\">%s %s</td><td class=\"data3\">%s</td><td class=\"data3\">%s</td><td class=\"data3\">%s</td><td class=\"data2\"><a href=\"http://%s\">%s</td></tr>\n",dat,tim,ip,name,typ,url,url);
       strcpy(ouser,user);
 
index 218ad01510e4f3fff531b88d05ea5216ac86c1e6..606978ba5ccbea478a07b11cc13bcc9aa0f1686b 100644 (file)
--- a/repday.c
+++ b/repday.c
@@ -29,7 +29,7 @@
 
 extern numlist hours;
 
-void report_day(const char *user)
+void report_day(const struct userinfostruct *uinfo)
 {
 
    FILE *fp_in, *fp_ou;
@@ -40,7 +40,6 @@ void report_day(const char *user)
    char html[8000];
    char arqout[MAXLEN];
    char wdirname[MAXLEN];
-   char wuser[255];
    char c[ 24 ][20];
    int  count=0;
    int  ihour=0;
@@ -53,8 +52,11 @@ void report_day(const char *user)
    int i;
    struct getwordstruct gwarea;
 
-   sprintf(arqout,"%s/%s/d%s.html",dirname,user,user);
-   sprintf(wdirname,"%s/%s.day",tmp,user);
+   if (snprintf(arqout,sizeof(arqout),"%s/%s/d%s.html",dirname,uinfo->filename,uinfo->filename)>=sizeof(arqout)) {
+      debuga(_("Output file name too long: %s/%s/d%s.html"),dirname,uinfo->filename,uinfo->filename);
+      exit(1);
+   }
+   snprintf(wdirname,sizeof(wdirname),"%s/%s.day",tmp,uinfo->filename);
 
    if(access(wdirname, R_OK) != 0)
       return;
@@ -75,23 +77,7 @@ void report_day(const char *user)
 
    fprintf(fp_ou,"<tr><td class=\"header_c\" colspan=\"2\">%s:&nbsp;%s</td></tr>\n",text[89],period);
 
-   strcpy(wuser,user);
-   if(strstr(wuser,"_") != 0)
-      fixip(wuser);
-
-   if(Ip2Name)
-      if((str=(char *) strstr(name, ".")) != (char *) NULL) {
-         if((str=(char *) strstr(str+1, ".")) != (char *) NULL)
-            ip2name(wuser,sizeof(wuser));
-   }
-
-   user_find(name, sizeof(name), wuser);
-
-   if(dotinuser && strchr(name,'_')) {
-      subs(name,sizeof(name),"_",".");
-   }
-
-   fprintf(fp_ou,"<tr><th class=\"header_c\" colspan=\"2\">%s:&nbsp;%s</th></tr>\n",text[90],name);
+   fprintf(fp_ou,"<tr><th class=\"header_c\" colspan=\"2\">%s:&nbsp;%s</th></tr>\n",text[90],uinfo->label);
 
    fputs("<tr><td></td></tr><tr><td></td></tr>\n",fp_ou);
    fputs("<tr><td></td></tr><tr><td></td></tr></table>\n",fp_ou);
@@ -114,7 +100,7 @@ void report_day(const char *user)
       fixendofline(buf);
       getword_start(&gwarea,buf);
       if (getword(data,sizeof(data),&gwarea,'\t')<0) {
-         printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdirname);
+         debuga(_("There is a broken date in file %s"),wdirname);
          exit(1);
       }
       if(!count) {
@@ -122,8 +108,12 @@ void report_day(const char *user)
          count++;
       }
 
-      if (getword(hour,sizeof(hour),&gwarea,'\t')<0 || getword_atoll(&elap,&gwarea,'\t')<0) {
-         printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdirname);
+      if (getword(hour,sizeof(hour),&gwarea,'\t')<0) {
+         debuga(_("There is a broken time in file %s"),wdirname);
+         exit(1);
+      }
+      if (getword_atoll(&elap,&gwarea,'\t')<0) {
+         debuga(_("There is a broken quantity in file %s"),wdirname);
          exit(1);
       }
 
index 5730be20d1b99428083765a1824bb75a29a34fe0..f05ae736fc1a68129a5150ab16d450c62c7df1f2 100644 (file)
--- a/report.c
+++ b/report.c
@@ -31,10 +31,10 @@ static FILE *fp_tt=NULL;
 
 static void maketmp(const char *user, const char *dirname, int debug, int indexonly);
 static void maketmp_hour(const char *user, const char *dirname, int indexonly);
-static void gravatmp_hora(const char *dirname, const char *user, const char *data, const char *hora, long long int elap, long long int accbytes, int indexonly);
-static void gravatmpf(const char *oldaccuser, const char *dirname, const char *oldurl, long long int nacc, long long int nbytes, const char *oldmsg, long long int nelap, int indexonly, long long int incache, long long int oucache);
-static void gravaporuser(const char *user, const char *dirname, const char *url, const char *ip, const char *data, const char *hora, long long int tam, long long int elap, int indexonly);
-static void gravager(FILE *fp_gen, const char *user, long long int nacc, const char *url, long long int nbytes, const char *ip, const char *hora, const char *dia, long long int nelap, long long int incache, long long int oucache);
+static void gravatmp_hora(const char *dirname, const struct userinfostruct *uinfo, const char *data, const char *hora, long long int elap, long long int accbytes, int indexonly);
+static void gravatmpf(const struct userinfostruct *uinfo, const char *oldurl, long long int nacc, long long int nbytes, const char *oldmsg, long long int nelap, int indexonly, long long int incache, long long int oucache);
+static void gravaporuser(const struct userinfostruct *uinfo, const char *dirname, const char *url, const char *ip, const char *data, const char *hora, long long int tam, long long int elap, int indexonly);
+static void gravager(FILE *fp_gen, const struct userinfostruct *uinfo, long long int nacc, const char *url, long long int nbytes, const char *ip, const char *hora, const char *dia, long long int nelap, long long int incache, long long int oucache);
 static void grava_SmartFilter(const char *dirname, const char *user, const char *ip, const char *data, const char *hora, const char *url, const char *smart);
 
 void gerarel(void)
@@ -44,11 +44,11 @@ void gerarel(void)
    FILE *fp_gen;
 
    char *buf;
-   char accdia[11], acchora[9], accuser[MAX_USER_LEN], accip[MAXLEN], *accurl;
+   char accdia[11], acchora[9], accip[MAXLEN], *accurl;
    char oldaccdia[11], oldacchora[9], oldaccip[MAXLEN];
-   char wdirname[MAXLEN], oldaccuser[MAX_USER_LEN];
+   char wdirname[MAXLEN];
    char *oldurl=NULL;
-   char olduser[MAX_USER_LEN], oldmsg[50], acccode[MAXLEN/2 - 1], oldacccode[MAXLEN/2 - 1], user[MAX_USER_LEN];
+   char oldmsg[50], acccode[MAXLEN/2 - 1], oldacccode[MAXLEN/2 - 1], user[MAX_USER_LEN];
    char ipantes[MAXLEN], nameantes[MAXLEN];
    char accsmart[MAXLEN];
    char crc2[MAXLEN/2 -1];
@@ -56,9 +56,9 @@ void gerarel(void)
    char arqtt[256];
    char *oldurltt=NULL;
    char oldaccdiatt[11],oldacchoratt[9];
-   char u2[MAX_USER_LEN];
    char tmp3[MAXLEN];
    char tmp4[5];
+   char u2[MAX_USER_LEN];
    long long int nbytes=0;
    long long int nelap=0;
    long long int nacc=0;
@@ -75,11 +75,12 @@ void gerarel(void)
    int ourl_size=0;
    int ourltt_size=0;
    int same_url;
+   int new_user;
    struct getwordstruct gwarea;
    struct longlinestruct line;
+   struct userinfostruct *uinfo,*puinfo;
 
    ipantes[0]='\0';
-   nameantes[0]='\0';
    smartfilter=0;
 
    sprintf(dirname, "%s%s", outdir, period);
@@ -99,7 +100,7 @@ void gerarel(void)
       exit(1);
    }
 
-   olduser[0]='\0';
+   puinfo=NULL;
    strncat(tmp,"/sarg",5);
    fp_tt=NULL;
 
@@ -129,53 +130,54 @@ void gerarel(void)
          user[0]='\0';
       }
 
+      uinfo=userinfo_find_from_file(user);
+      if (!uinfo) {
+         debuga(_("Ignoring unknown user file %s"),user);
+         continue;
+      }
+      strcpy(u2,uinfo->id);
+      if(Ip2Name && uinfo->id_is_ip) ip2name(u2,sizeof(u2));
+      user_find(uinfo->label,MAX_USER_LEN, u2);
+
       strcpy(wdirname,dirname);
       maketmp(user,tmp,debug,indexonly);
       maketmp_hour(user,tmp,indexonly);
 
-      strcpy(u2,user);
-      if(Ip2Name)
-         ip2name(u2,sizeof(u2));
-      user_find(name,sizeof(name), u2);
-
-      if(dotinuser && strchr(name,'_')) {
-         subs(name,sizeof(name),"_",".");
-      }
-
       ttopen=0;
       oldurltt=NULL;
       ourltt_size=0;
       memset(oldaccdiatt,0,sizeof(oldaccdiatt));
       memset(oldacchoratt,0,sizeof(oldacchoratt));
+      new_user=1;
 
       if (longline_prepare(&line)<0) {
-         debuga(_("Not enough memory to read the downloaded files"));
+         debuga(_("Not enough memory to read the downloaded files."));
          exit(1);
       }
 
       while((buf=longline_read(fp_in,&line))!=NULL) {
          getword_start(&gwarea,buf);
          if (getword(accdia,sizeof(accdia),&gwarea,'\t')<0 || getword(acchora,sizeof(acchora),&gwarea,'\t')<0 ||
-             getword(accuser,sizeof(accuser),&gwarea,'\t')<0 || getword(accip,sizeof(accip),&gwarea,'\t')<0 ||
+             getword(accip,sizeof(accip),&gwarea,'\t')<0 ||
              getword_ptr(buf,&accurl,&gwarea,'\t')<0 || getword_atoll(&accbytes,&gwarea,'\t')<0 ||
              getword(acccode,sizeof(acccode),&gwarea,'\t')<0) {
-            debuga(_("Maybe you have a broken record or garbage in your %s file (%d)"),tmp3,__LINE__);
+            debuga(_("There is a broken record or garbage in file %s"),tmp3);
             exit(1);
          }
          if(strncmp(acccode,"TCP_DENIED/407",14) == 0) continue;
          if (getword_atoll(&accelap,&gwarea,'\t')<0) {
-            debuga(_("Maybe you have a broken elapsed time in your %s file (%d)"),tmp3,__LINE__);
+            debuga(_("There is a broken elapsed time in file %s"),tmp3);
             exit(1);
          }
          if (getword_skip(20000,&gwarea,'"')<0 || getword(accsmart,sizeof(accsmart),&gwarea,'"')<0) {
-            debuga(_("Maybe you have a broken smart info in your %s file (%d)"),tmp3,__LINE__);
+            debuga(_("There is a broken smart info in file %s"),tmp3);
             exit(1);
          }
 
          if(accsmart[0] != '\0') {
             smartfilter++;
             strcpy(wdirname,dirname);
-            grava_SmartFilter(wdirname,accuser,accip,accdia,acchora,accurl,accsmart);
+            grava_SmartFilter(wdirname,uinfo->id,accip,accdia,acchora,accurl,accsmart);
          }
 
          if(Ip2Name) {
@@ -187,11 +189,11 @@ void gerarel(void)
          }
 
          strcpy(wdirname,dirname);
-         gravatmp_hora(wdirname,accuser,accdia,acchora,accelap,accbytes,indexonly);
+         gravatmp_hora(wdirname,uinfo,accdia,acchora,accelap,accbytes,indexonly);
 
          if(iprel){
             strcpy(wdirname,dirname);
-            gravaporuser(accuser,wdirname,accurl,accip,accdia,acchora,accbytes,accelap,indexonly);
+            gravaporuser(uinfo,wdirname,accurl,accip,accdia,acchora,accbytes,accelap,indexonly);
          }
 
          if(!rtotal){
@@ -206,21 +208,22 @@ void gerarel(void)
             }
             strcpy(oldurl,accurl);
             strcpy(oldacccode,acccode);
-            strcpy(oldaccuser,accuser);
+            puinfo=uinfo;
             strcpy(oldaccip,accip);
             strcpy(oldaccdia,accdia);
             strcpy(oldacchora,acchora);
+            new_user=0;
             rtotal++;
          }
          same_url=(strcmp(oldurl,accurl) == 0);
 
          if(site[0] != '\0') {
-            if(strcmp(oldaccuser,accuser) != 0){
+            if(new_user){
                strcpy(oldmsg,"OK");
                if(strstr(oldacccode,"DENIED") != 0)
                   sprintf(oldmsg,"%s",text[46]);
-               gravatmp(oldaccuser,oldurl,nacc,nbytes,oldmsg,nelap,indexonly,incache,oucache);
-               gravager(fp_gen,oldaccuser,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache);
+               gravatmp(puinfo,oldurl,nacc,nbytes,oldmsg,nelap,indexonly,incache,oucache);
+               gravager(fp_gen,puinfo,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache);
                nacc=0;
                nbytes=0;
                nelap=0;
@@ -228,20 +231,18 @@ void gerarel(void)
                oucache=0;
             }
          } else {
-            if(!same_url || strcmp(oldaccuser,accuser) != 0){
+            if(!same_url || new_user){
                if(strstr(oldacccode,"DENIED") != 0)
                   strcpy(oldmsg,text[46]);
                else
                   strcpy(oldmsg,"OK");
-               gravatmp(oldaccuser,oldurl,nacc,nbytes,oldmsg,nelap,indexonly,incache,oucache);
-               gravager(fp_gen,oldaccuser,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache);
+               gravatmp(puinfo,oldurl,nacc,nbytes,oldmsg,nelap,indexonly,incache,oucache);
+               gravager(fp_gen,puinfo,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache);
                nacc=0;
                nbytes=0;
                nelap=0;
                incache=0;
                oucache=0;
-               if(strcmp(oldaccuser,accuser) != 0)
-                  ind2=0;
             }
          }
          nacc++;
@@ -252,12 +253,11 @@ void gerarel(void)
              (!oldurltt || strcmp(oldurltt,accurl) || strcmp(oldaccdiatt,accdia) || strcmp(oldacchoratt,acchora))) {
 
             if(!ttopen) {
-               ind2++;
                url_to_file(accurl,siteind,sizeof(siteind));
-               snprintf(arqtt,sizeof(arqtt),"%s/%s",dirname,accuser);
+               snprintf(arqtt,sizeof(arqtt),"%s/%s",dirname,uinfo->filename);
                if(access(arqtt, R_OK) != 0)
                   my_mkdir(arqtt);
-               snprintf(arqtt,sizeof(arqtt),"%s/%s/tt%s-%s.html",dirname,accuser,accuser,siteind);
+               snprintf(arqtt,sizeof(arqtt),"%s/%s/tt%s-%s.html",dirname,uinfo->filename,uinfo->filename,siteind);
                if ((fp_tt = fopen(arqtt, "w")) == 0) {
                   fprintf(stderr, "SARG: (report) %s: %s\n",text[45],arqtt);
                   exit(1);
@@ -274,7 +274,7 @@ void gerarel(void)
 
                write_html_header(fp_tt,(IndexTree == INDEX_TREE_DATE) ? 4 : 2,_("Site access report"));
                fprintf(fp_tt,"<tr><td class=\"header_l\">%s:&nbsp;%s</td></tr>\n",text[89],period);
-               fprintf(fp_tt,"<tr><td class=\"header_l\">%s:&nbsp;%s</td></tr>\n",text[90],name);
+               fprintf(fp_tt,"<tr><td class=\"header_l\">%s:&nbsp;%s</td></tr>\n",text[90],uinfo->label);
                fprintf(fp_tt,"<tr><td class=\"header_l\">%s:&nbsp;%s, %s</td></tr>\n",text[104],UserSortField,UserSortOrder);
                fprintf(fp_tt,"<tr><th class=\"header_c\">%s</th></tr>\n",text[32]);
                close_html_header(fp_tt);
@@ -311,12 +311,13 @@ void gerarel(void)
             oucache+=accbytes;
          else incache+=accbytes;
 
-         if(strcmp(accuser,oldaccuser) != 0) {
+         if(new_user) {
+            new_user=0;
             strcpy(wdirname,dirname);
-            day_totalize(tmp,oldaccuser,indexonly);
-            strcpy(oldaccuser,accuser);
+            day_totalize(tmp,puinfo,indexonly);
          }
 
+         puinfo=uinfo;
          strcpy(oldacccode,acccode);
          strcpy(oldaccip,accip);
          if (!same_url) {
@@ -339,7 +340,6 @@ void gerarel(void)
       longline_free(&line);
       if (oldurltt) free(oldurltt);
       unlink(tmp3);
-      bzero(user,sizeof(user));
    }
    closedir(dirp);
 
@@ -349,15 +349,13 @@ void gerarel(void)
       else
          strcpy(oldmsg,"OK");
       strcpy(wdirname,dirname);
-      if(oldaccuser[0] == '\0')
-         strcpy(oldaccuser,accuser);
-      gravatmpf(oldaccuser,wdirname,oldurl,nacc,nbytes,oldmsg,nelap,indexonly,incache,oucache);
+      gravatmpf(puinfo,oldurl,nacc,nbytes,oldmsg,nelap,indexonly,incache,oucache);
       strcpy(wdirname,dirname);
-      gravager(fp_gen,oldaccuser,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache);
+      gravager(fp_gen,puinfo,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache);
       free(oldurl);
    }
    fclose(fp_gen);
-   day_totalize(tmp,oldaccuser,indexonly);
+   if (puinfo) day_totalize(tmp,puinfo,indexonly);
 
    tmpsort();
 
@@ -470,17 +468,16 @@ static void maketmp_hour(const char *user, const char *dirname, int indexonly)
 }
 
 
-void gravatmp(const char *oldaccuser, const char *oldurl, long long int nacc, long long int nbytes, const char *oldmsg, long long int nelap, int indexonly, long long int incache, long long int oucache)
+void gravatmp(const struct userinfostruct *uinfo, const char *oldurl, long long int nacc, long long int nbytes, const char *oldmsg, long long int nelap, int indexonly, long long int incache, long long int oucache)
 {
-
    FILE *fp_ou;
    char wdirname[MAXLEN];
 
    if(indexonly) return;
    if((ReportType & REPORT_TYPE_USERS_SITES) == 0) return;
 
-   if (snprintf(wdirname,sizeof(wdirname),"%s/%s.utmp",tmp,oldaccuser)>=sizeof(wdirname)) {
-      debuga(_("Temporary file name too long: %s/%s.utmp"),tmp,oldaccuser);
+   if (snprintf(wdirname,sizeof(wdirname),"%s/%s.utmp",tmp,uinfo->filename)>=sizeof(wdirname)) {
+      debuga(_("Temporary file name too long: %s/%s.utmp"),tmp,uinfo->filename);
       exit(1);
    }
 
@@ -502,38 +499,42 @@ void gravatmp(const char *oldaccuser, const char *oldurl, long long int nacc, lo
    }
 
    return;
-
 }
 
-
-static void gravatmp_hora(const char *dirname, const char *user, const char *data, const char *hora, long long int elap, long long int bytes, int indexonly)
+static void gravatmpf(const struct userinfostruct *uinfo,const char *oldurl, long long int nacc, long long int nbytes, const char *oldmsg, long long int nelap, int indexonly, long long int incache, long long int oucache)
 {
-
    FILE *fp_ou;
    char wdirname[MAXLEN];
 
-   if(indexonly || ((ReportType & REPORT_TYPE_USERS_SITES) == 0)) return;
+   if(indexonly || (ReportType & REPORT_TYPE_USERS_SITES) == 0) return;
 
-   if (snprintf(wdirname,sizeof(wdirname),"%s/%s.htmp",tmp,user)>=sizeof(wdirname)) {
-      fprintf(stderr,"SARG: Path too long %s/%s.htmp\n",tmp,user);
+   if (snprintf(wdirname,sizeof(wdirname),"%s/%s.utmp",tmp,uinfo->filename)>=sizeof(wdirname)) {
+      debuga(_("Path too long %s/%s.utmp"),tmp,uinfo->filename);
       exit(1);
    }
 
    if((fp_ou=MY_FOPEN(wdirname,"a"))==NULL){
-      fprintf(stderr, "SARG: (report-2) %s: %s - %s\n",text[45],wdirname,strerror(errno));
+      fprintf(stderr, "SARG: (report) %s: %s\n",text[45],wdirname);
       exit(1);
    }
 
-   if(strcmp(datetimeby,"bytes") == 0) fprintf(fp_ou,"%s\t%s\t%lld\n",data,hora,bytes);
-   else fprintf(fp_ou,"%s\t%s\t%lld\n",data,hora,elap);
+   fprintf(fp_ou,"%lld\t%lld\t%s\t%s\t%lld\t%lld\t%lld\n",nacc,nbytes,oldurl,oldmsg,nelap,incache,oucache);
 
    fclose(fp_ou);
+   ttopen=0;
+
+   if(fp_tt) {
+      fputs("</table>\n",fp_tt);
+      fputs("</body>\n</html>\n",fp_tt);
+      fclose(fp_tt);
+      fp_tt=NULL;
+   }
 
    return;
 }
 
 
-static void gravaporuser(const char *user, const char *dirname, const char *url, const char *ip, const char *data, const char *hora, long long int tam, long long int elap, int indexonly)
+static void gravatmp_hora(const char *dirname, const struct userinfostruct *uinfo, const char *data, const char *hora, long long int elap, long long int bytes, int indexonly)
 {
 
    FILE *fp_ou;
@@ -541,26 +542,26 @@ static void gravaporuser(const char *user, const char *dirname, const char *url,
 
    if(indexonly || ((ReportType & REPORT_TYPE_USERS_SITES) == 0)) return;
 
-   if (snprintf(wdirname,sizeof(wdirname),"%s/%s.ip",tmp,user)>=sizeof(wdirname)) {
-      fprintf(stderr,"SARG: Path too long %s/%s.ip\n",tmp,user);
+   if (snprintf(wdirname,sizeof(wdirname),"%s/%s.htmp",tmp,uinfo->filename)>=sizeof(wdirname)) {
+      debuga(_("Path too long %s/%s.htmp"),tmp,uinfo->filename);
       exit(1);
    }
 
    if((fp_ou=MY_FOPEN(wdirname,"a"))==NULL){
-      fprintf(stderr, "SARG: (report) %s: %s\n",text[45],wdirname);
+      fprintf(stderr, "SARG: (report-2) %s: %s - %s\n",text[45],wdirname,strerror(errno));
       exit(1);
    }
 
-   fprintf(fp_ou,"%s\t%s\t%s\t%s\t%lld\t%lld\n",ip,url,data,hora,tam,elap);
+   if(strcmp(datetimeby,"bytes") == 0) fprintf(fp_ou,"%s\t%s\t%lld\n",data,hora,bytes);
+   else fprintf(fp_ou,"%s\t%s\t%lld\n",data,hora,elap);
 
    fclose(fp_ou);
 
    return;
-
 }
 
 
-static void gravatmpf(const char *oldaccuser, const char *dirname, const char *oldurl, long long int nacc, long long int nbytes, const char *oldmsg, long long int nelap, int indexonly, long long int incache, long long int oucache)
+static void gravaporuser(const struct userinfostruct *uinfo, const char *dirname, const char *url, const char *ip, const char *data, const char *hora, long long int tam, long long int elap, int indexonly)
 {
 
    FILE *fp_ou;
@@ -568,8 +569,8 @@ static void gravatmpf(const char *oldaccuser, const char *dirname, const char *o
 
    if(indexonly || ((ReportType & REPORT_TYPE_USERS_SITES) == 0)) return;
 
-   if (snprintf(wdirname,sizeof(wdirname),"%s/%s.utmp",tmp,oldaccuser)>=sizeof(wdirname)) {
-      fprintf(stderr,"SARG: Path too long %s/%s.utmp\n",tmp,oldaccuser);
+   if (snprintf(wdirname,sizeof(wdirname),"%s/%s.ip",tmp,uinfo->filename)>=sizeof(wdirname)) {
+      fprintf(stderr,"SARG: Path too long %s/%s.ip\n",tmp,uinfo->filename);
       exit(1);
    }
 
@@ -578,27 +579,18 @@ static void gravatmpf(const char *oldaccuser, const char *dirname, const char *o
       exit(1);
    }
 
-   fprintf(fp_ou,"%lld\t%lld\t%s\t%s\t%lld\t%lld\t%lld\n",nacc,nbytes,oldurl,oldmsg,nelap,incache,oucache);
+   fprintf(fp_ou,"%s\t%s\t%s\t%s\t%lld\t%lld\n",ip,url,data,hora,tam,elap);
 
    fclose(fp_ou);
-   ttopen=0;
-   ind2=0;
-
-   if(fp_tt) {
-      fputs("</table>\n",fp_tt);
-      fputs("</body>\n</html>\n",fp_tt);
-      fclose(fp_tt);
-      fp_tt=NULL;
-   }
 
    return;
 
 }
 
 
-static void gravager(FILE *fp_gen, const char *user, long long int nacc, const char *url, long long int nbytes, const char *ip, const char *hora, const char *dia, long long int nelap, long long int incache, long long int oucache)
+static void gravager(FILE *fp_gen, const struct userinfostruct *uinfo, long long int nacc, const char *url, long long int nbytes, const char *ip, const char *hora, const char *dia, long long int nelap, long long int incache, long long int oucache)
 {
-   fprintf(fp_gen,"%s\t%lld\t%lld\t%s\t%s\t%s\t%s\t%lld\t%lld\t%lld\n",user,nacc,nbytes,url,ip,hora,dia,nelap,incache,oucache);
+   fprintf(fp_gen,"%s\t%lld\t%lld\t%s\t%s\t%s\t%s\t%lld\t%lld\t%lld\n",uinfo->id,nacc,nbytes,url,ip,hora,dia,nelap,incache,oucache);
    return;
 }
 
index 19597734d4869e16758154e7ff1be338ffbe5e05..a8915c6df4027cdd68fe053555056d6ef8d10759 100644 (file)
@@ -51,6 +51,7 @@ void siteuser(void)
    int cstatus;
    struct longlinestruct line;
    struct generalitemstruct item;
+   const struct userinfostruct *uinfo;
 
    if(Privacy)
       return;
@@ -68,7 +69,7 @@ void siteuser(void)
    }
 
    if (!fgets(period,sizeof(period),fp_in)) {
-      fprintf(stderr,"SARG: (siteuser) read error in %s\n",per);
+      debuga(_("(siteuser) read error in %s"),per);
       exit(1);
    }
    fclose(fp_in);
@@ -76,14 +77,14 @@ void siteuser(void)
    sprintf(csort,"sort -k 4,4 -k 1,1 -o \"%s\" \"%s\"",general2,general);
    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);
+      debuga(_("sort command return status %d"),WEXITSTATUS(cstatus));
+      debuga(_("sort command: %s"),csort);
       exit(1);
    }
 
    if((fp_in=fopen(general2,"r"))==NULL) {
      fprintf(stderr, "SARG: (topsite) %s: %s\n",text[8],general2);
-     fprintf(stderr, "SARG: sort command: %s\n",csort);
+     debuga(_("sort command: %s"),csort);
      exit(1);
    }
 
@@ -122,13 +123,10 @@ void siteuser(void)
    while((buf=longline_read(fp_in,&line))!=NULL) {
       ger_read(buf,&item,general2);
       if(item.total) continue;
-      if(userip)
-         fixip(item.user);
-
-      user_find(name, sizeof(name), item.user);
-
-      if(dotinuser && strchr(name,'_')) {
-         subs(name,sizeof(name),"_",".");
+      uinfo=userinfo_find_from_id(item.user);
+      if (!uinfo) {
+         debuga(_("Unknown user ID %s in file %s"),item.user,general2);
+         exit(1);
       }
 
       if (item.nacc > 0) nsitesusers = 1;
@@ -147,9 +145,9 @@ void siteuser(void)
          regs++;
       }
 
-      sprintf(wuser," %s ",name);
+      sprintf(wuser," %s ",uinfo->label);
       if(strstr(users,wuser) == 0 && strcmp(item.url,ourl) == 0) {
-         strcat(users,name);
+         strcat(users,uinfo->label);
          strcat(users," ");
          ucount++;
          if(ucount>4) {
@@ -182,7 +180,7 @@ void siteuser(void)
 
          regs++;
          ucount=0;
-         strcpy(users,name);
+         strcpy(users,uinfo->label);
          strcat(users," ");
          url_len=strlen(item.url);
          if (url_len>=ourl_size) {
index 9a60be5edf489bc2882063ef9288ce8b29986951..bc1f2590e9e8f494a88bf112acd455604db57353 100644 (file)
@@ -49,10 +49,10 @@ void smartfilter_report(void)
    char smartheader[15];
    char ftime[128];
    char smartuser[MAXLEN];
-   char *str;
    int  fuser=0;
    int cstatus;
    struct getwordstruct gwarea;
+   const struct userinfostruct *uinfo;
 
    ouser[0]='\0';
 
@@ -71,24 +71,24 @@ void smartfilter_report(void)
    }
 
    if (!fgets(period,sizeof(period),fp_in)) {
-      fprintf(stderr,"SARG: (smartfilter) read error in %s\n",per);
+      debuga(_("(smartfilter) read error in %s"),per);
       exit(1);
    }
    fclose(fp_in);
 
    if (snprintf(csort,sizeof(csort),"sort -n -k 1,1 -k 2,2 -k 3,3 -o \"%s\" \"%s\"",smart_ou,smart_in)>=sizeof(csort)) {
-      fprintf(stderr,"SARG: cannot sort file %s\n",smart_in);
+      debuga(_("cannot build the sort command to sort file %s"),smart_in);
       exit(1);
    }
    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);
+      debuga(_("sort command return status %d"),WEXITSTATUS(cstatus));
+      debuga(_("sort command: %s"),csort);
       exit(1);
    }
    if((fp_in=fopen(smart_ou,"r"))==NULL) {
       fprintf(stderr, "SARG: (smartfilter) %s: %s\n",text[8],smart_ou);
-      fprintf(stderr, "SARG: sort command: %s\n",csort);
+      debuga(_("sort command: %s"),csort);
       exit(1);
    }
    unlink(smart_in);
@@ -121,18 +121,18 @@ void smartfilter_report(void)
       if (getword(user,sizeof(user),&gwarea,'\t')<0 || getword(data,sizeof(data),&gwarea,'\t')<0 ||
           getword(hora,sizeof(hora),&gwarea,'\t')<0 || getword(ip,sizeof(ip),&gwarea,'\t')<0 ||
           getword(url,sizeof(url),&gwarea,'\t')<0 || getword(smartcat,sizeof(smartcat),&gwarea,'\n')<0) {
-         printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",smart_ou);
+         debuga(_("There is e a broken record or garbage in file %s"),smart_ou);
          exit(1);
       }
 
-      if((str=(char *) strstr(user, "_")) != (char *) NULL ) {
-         if((str=(char *) strstr(str+1, "_")) != (char *) NULL )
-            fixip(user);
+      uinfo=userinfo_find_from_id(user);
+      if (!uinfo) {
+         debuga(_("Unknown user ID %s in file %s"),user,smart_ou);
+         exit(1);
       }
-
       if(strcmp(ouser,user) != 0) {
          strcpy(ouser,user);
-         sprintf(smartuser,"%s/denied_%s.html",dirname,user);
+         sprintf(smartuser,"%s/denied_%s.html",dirname,uinfo->filename);
          if(fuser) {
             fuser=0;
             fputs("</table>\n",fp_user);
@@ -173,7 +173,7 @@ void smartfilter_report(void)
          if(LogoImage[0]!='\0') fprintf(fp_user,"<tr><th align=left><img src=\"%s\" border=\"0\" align=\"absmiddle\" width=\"%s\" height=\"%s\"><font color=\"%s\">%s</font>\n",LogoImage,Width,Height,LogoTextColor,LogoText);
          fprintf(fp_user,"<tr><th align=\"center\"><b><font color=\"%s\" size=\"+1\">%s</font></b></th></tr>\n",TiColor,Title);
          fprintf(fp_user,"<tr><td align=center bgcolor=%s><font size=%s>%s: %s</font></td></tr>\n",HeaderBgColor,FontSize,text[89],period);
-         fprintf(fp_user,"<tr><td align=center bgcolor=%s><font size=%s>%s:</font><font size=%s> %s</font></td></tr>\n",HeaderBgColor,FontSize,text[90],FontSize,user);
+         fprintf(fp_user,"<tr><td align=\"center\" bgcolor=\"%s\"><font size=\"%s\">%s:</font><font size=\"%s\"> %s</font></td></tr>\n",HeaderBgColor,FontSize,text[90],FontSize,uinfo->label);
          fputs("</table></div>\n",fp_user);
          fputs("<div align=\"center\"><table cellpadding=0 cellspacing=2>\n",fp_user);
          fputs("<tr><td></td></tr>\n",fp_user);
@@ -181,9 +181,9 @@ void smartfilter_report(void)
          fputs("<tr><td></td></tr>\n",fp_user);
          fprintf(fp_user,"<tr><th bgcolor=%s><font size=%s>%s</font></th><th bgcolor=%s><font size=%s>%s</font></th><th bgcolor=%s><font size=%s>%s</font></th><th bgcolor=%s><font size=%s>%s</font></th><th bgcolor=%s><font size=%s>%s</font></th></tr>\n",HeaderBgColor,FontSize,text[98],HeaderBgColor,FontSize,text[111],HeaderBgColor,FontSize,text[110],HeaderBgColor,FontSize,text[91],HeaderBgColor,FontSize,smartheader);
       }
-      fprintf(fp_user,"<tr><td bgcolor=%s align=center><font size=%s>%s</font></td><td bgcolor=%s align=center><font size=%s>%s</font></td><td bgcolor=%s align=center><font size=%s>%s-%s</font></td><td bgcolor=%s><font size=%s>%s</font></td><td bgcolor=%s><font size=%s>%s</font></td></th>\n",TxBgColor,FontSize,user,TxBgColor,FontSize,ip,TxBgColor,FontSize,data,hora,TxBgColor,FontSize,url,TxBgColor,FontSize,smartcat);
+      fprintf(fp_user,"<tr><td bgcolor=%s align=center><font size=%s>%s</font></td><td bgcolor=%s align=center><font size=%s>%s</font></td><td bgcolor=%s align=center><font size=%s>%s-%s</font></td><td bgcolor=%s><font size=%s>%s</font></td><td bgcolor=%s><font size=%s>%s</font></td></th>\n",TxBgColor,FontSize,uinfo->label,TxBgColor,FontSize,ip,TxBgColor,FontSize,data,hora,TxBgColor,FontSize,url,TxBgColor,FontSize,smartcat);
 
-      fprintf(fp_ou,"<tr><td bgcolor=%s align=center><font size=%s>%s</font></td><td bgcolor=%s align=center><font size=%s>%s</font></td><td bgcolor=%s align=center><font size=%s>%s-%s</font></td><td bgcolor=%s><font size=%s>%s</font></td><td bgcolor=%s><font size=%s>%s</font></td></th>\n",TxBgColor,FontSize,user,TxBgColor,FontSize,ip,TxBgColor,FontSize,data,hora,TxBgColor,FontSize,url,TxBgColor,FontSize,smartcat);
+      fprintf(fp_ou,"<tr><td bgcolor=%s align=center><font size=%s>%s</font></td><td bgcolor=%s align=center><font size=%s>%s</font></td><td bgcolor=%s align=center><font size=%s>%s-%s</font></td><td bgcolor=%s><font size=%s>%s</font></td><td bgcolor=%s><font size=%s>%s</font></td></th>\n",TxBgColor,FontSize,uinfo->label,TxBgColor,FontSize,ip,TxBgColor,FontSize,data,hora,TxBgColor,FontSize,url,TxBgColor,FontSize,smartcat);
    }
 
    fputs("</table>\n",fp_ou);
diff --git a/sort.c b/sort.c
index e03cf0935d34a8bb8b8fd362d63737612beca6ad..f664349de4cefb9cd476290537609d8d2f299c5d 100644 (file)
--- a/sort.c
+++ b/sort.c
@@ -146,7 +146,7 @@ void sort_users_log(const char *tmp, int debug)
          clen=snprintf(csort,sizeof(csort),"sort -T \"%s\" -k 3,3 -k 1,1 -k 2,2 -k 5,5 -o \"%s/%s.log\" \"%s/%s.unsort\"",
               tmp, wtmp, user, wtmp, user);
       else
-         clen=snprintf(csort,sizeof(csort),"sort -T \"%s\" -k 5,5 -k 1,1 -k 2,2 -o \"%s/%s.log\" \"%s/%s.unsort\"",
+         clen=snprintf(csort,sizeof(csort),"sort -T \"%s\" -k 4,4 -k 1,1 -k 2,2 -o \"%s/%s.log\" \"%s/%s.unsort\"",
               tmp, wtmp, user, wtmp, user);
       if (clen>=sizeof(csort)) {
          fprintf(stderr, "SARG: user name too long to sort %s\n",csort);
index 49aca08e78ef4f27c8c11d274a3fb8729eadda1a..b63a4899b2e13ae85babcccaa2309d8f3c7a3052 100644 (file)
@@ -45,7 +45,6 @@ void squidguard_report(void)
    char data[15];
    char data2[15];
    char hora[15];
-   char *str;
    int  z=0;
    int  count=0;
    struct getwordstruct gwarea;
@@ -67,7 +66,7 @@ void squidguard_report(void)
    }
 
    if (!fgets(period,sizeof(period),fp_in)) {
-      fprintf(stderr,"SARG: (squidguard) read error in %s\n",per);
+      debuga(_("(squidguard) read error in %s"),per);
       exit(1);
    }
    fclose(fp_in);
@@ -95,15 +94,15 @@ void squidguard_report(void)
       getword_start(&gwarea,buf);
       if (getword(user,sizeof(user),&gwarea,'\t')<0 || getword(data2,sizeof(data2),&gwarea,'\t')<0 ||
           getword(hora,sizeof(hora),&gwarea,'\t')<0 || getword(ip,sizeof(ip),&gwarea,'\t')<0) {
-         debuga(_("Maybe you have a broken record or garbage in your %s file"),squidguard_in);
+         debuga(_("There is a broken record or garbage in file %s"),squidguard_in);
          exit(1);
       }
       if (getword_ptr(buf,&url,&gwarea,'\t')<0) {
-         debuga(_("Maybe you have a broken url in your %s file"),squidguard_in);
+         debuga(_("There is a broken url in file %s"),squidguard_in);
          exit(1);
       }
       if (getword(rule,sizeof(rule),&gwarea,'\n')<0) {
-         debuga(_("Maybe you have a broken rule in your %s file"),squidguard_in);
+         debuga(_("There is a broken rule in file %s"),squidguard_in);
          exit(1);
       }
 
@@ -125,11 +124,6 @@ void squidguard_report(void)
          strncat(data,data2,4);
       }
 
-      if((str=(char *) strstr(user, "_")) != (char *) NULL ) {
-         if((str=(char *) strstr(str+1, "_")) != (char *) NULL )
-            fixip(user);
-      }
-
       if(Ip2Name)
          ip2name(ip,sizeof(ip));
 
@@ -150,10 +144,6 @@ void squidguard_report(void)
 
       user_find(name, sizeof(name), user);
 
-      if(dotinuser && strchr(name,'_')) {
-         subs(name,sizeof(name),"_",".");
-      }
-
      if(SquidGuardReportLimit) {
          if(strcmp(ouser2,name) == 0) {
             count++;
index 52c08cc27b71e2677cc00b665e9b5a5cbdc29fc2..f3d9648724a650c3980d792de2a1b6168eee8f86 100644 (file)
--- a/topuser.c
+++ b/topuser.c
@@ -45,12 +45,10 @@ void topuser(void)
    char wger[MAXLEN], top1[MAXLEN], top2[MAXLEN], top3[MAXLEN];
    char user[MAX_USER_LEN], tusr[MAXLEN];
    char ipantes[MAXLEN], nameantes[MAXLEN];
-   char sfield[10]="2,2";
-   char order[255]="-r";
+   const char *sfield="-n -k 2,2";
+   const char *order="-r";
    char title[80];
    char *warea;
-   char user2[MAXLEN];
-   char name[MAXLEN];
    char ltext110[100];
    int  totuser=0;
    int  topcount=0;
@@ -60,6 +58,7 @@ void topuser(void)
    struct getwordstruct gwarea;
    struct longlinestruct line;
    struct generalitemstruct item;
+   const struct userinfostruct *uinfo;
 
    ipantes[0]='\0';
    nameantes[0]='\0';
@@ -116,7 +115,7 @@ void topuser(void)
          totuser++;
 
          if (olduser[0] != '\0') {
-            fprintf(fp_top2,"%s\t%015lld\t%015lld\t%015lld\t%015lld\t%015lld\n",olduser,tnbytes,tnacc,tnelap,tnincache,tnoucache);
+            fprintf(fp_top2,"%s\t%lld\t%lld\t%lld\t%lld\t%lld\n",olduser,tnbytes,tnacc,tnelap,tnincache,tnoucache);
 
             ttnbytes+=tnbytes;
             ttnacc+=tnacc;
@@ -142,7 +141,7 @@ void topuser(void)
    longline_free(&line);
 
    if (olduser[0] != '\0') {
-      fprintf(fp_top2,"%s\t%015lld\t%015lld\t%015lld\t%015lld\t%015lld\n",olduser,tnbytes,tnacc,tnelap,tnincache,tnoucache);
+      fprintf(fp_top2,"%s\t%lld\t%lld\t%lld\t%lld\t%lld\n",olduser,tnbytes,tnacc,tnelap,tnincache,tnoucache);
 
       ttnbytes+=tnbytes;
       ttnacc+=tnacc;
@@ -156,27 +155,27 @@ void topuser(void)
    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);
+   sprintf(csort,"sort -T \"%s\" %s %s -o \"%s\" \"%s\"", TempDir, 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);
+      debuga(_("sort command return status %d"),WEXITSTATUS(cstatus));
+      debuga(_("sort command: %s"),csort);
       exit(1);
    }
 
    if((fp_top1=fopen(top1,"r"))==NULL) {
-      fprintf(stderr, "SARG: (topuser) %s: %s\n",text[45],top1);
+      debuga("SARG: (topuser) %s: %s\n",text[45],top1);
       exit(1);
    }
 
@@ -250,27 +249,27 @@ void topuser(void)
    while((warea=longline_read(fp_top1,&line))!=NULL) {
       getword_start(&gwarea,warea);
       if (getword(user,sizeof(user),&gwarea,'\t')<0) {
-         printf("SARG: Maybe you have a broken user in your %s file.\n",top1);
+         debuga(_("There may be a broken user in file %s."),top1);
          exit(1);
       }
       if (getword_atoll(&nbytes,&gwarea,'\t')<0) {
-         printf("SARG: Maybe you have a broken number of bytes in your %s file.\n",top1);
+         debuga(_("There may be a broken number of bytes in file %s."),top1);
          exit(1);
       }
       if (getword_atoll(&nacc,&gwarea,'\t')<0) {
-         printf("SARG: Maybe you have a broken number of access in your %s file.\n",top1);
+         debuga(_("There may be a broken number of access in file %s."),top1);
          exit(1);
       }
       if (getword_atoll(&elap,&gwarea,'\t')<0) {
-         printf("SARG: Maybe you have a broken elpased time in your %s file.\n",top1);
+         debuga(_("There may be a broken elpased time in file %s."),top1);
          exit(1);
       }
       if (getword_atoll(&incac,&gwarea,'\t')<0) {
-         printf("SARG: Maybe you have a broken in-cache size in your %s file.\n",top1);
+         debuga(_("There may be a broken in-cache size in file %s."),top1);
          exit(1);
       }
       if (getword_atoll(&oucac,&gwarea,'\n')<0) {
-         printf("SARG: Maybe you have a broken out-of-cache size in your %s file.\n",top1);
+         debuga(_("There may be a broken out-of-cache size in file %s."),top1);
          exit(1);
       }
       if(nacc < 1)
@@ -280,16 +279,10 @@ void topuser(void)
       tnbytes=nbytes;
       tnelap=elap;
 
-      strcpy(user2,user);
-      if(userip) {
-         fixip(user2);
-         if(Ip2Name) {
-            if(strcmp(user2,ipantes) != 0) {
-               strcpy(ipantes,user2);
-               ip2name(user2,sizeof(user2));
-               strcpy(nameantes,user2);
-            } else strcpy(user2,nameantes);
-         }
+      uinfo=userinfo_find_from_id(user);
+      if (!uinfo) {
+         debuga(_("Unknown user ID %s in file %s"),user,top1);
+         exit(1);
       }
 
       fputs("<tr>",fp_top3);
@@ -298,15 +291,6 @@ void topuser(void)
       if((TopUserFields & TOPUSERFIELDS_NUM) != 0)
          fprintf(fp_top3,"<td class=\"data\">%d</td>",posicao);
 
-      user_find(name, sizeof(name), user2);
-      if(Ip2Name &&
-         ((str=(char *) strstr(name, ".")) != (char *) NULL) &&
-         ((str=(char *) strstr(str+1, ".")) != (char *) NULL))
-         ip2name(name,sizeof(name));
-      if(dotinuser && strchr(name,'_')) {
-         subs(name,sizeof(name),"_",".");
-      }
-
       if((TopUserFields & TOPUSERFIELDS_DATE_TIME) !=0 && (ReportType & REPORT_TYPE_DATE_TIME) != 0) {
          s=text[110];
          for(i=0 ; i<sizeof(ltext110)-1 && s[i] ; i++)
@@ -315,23 +299,23 @@ void topuser(void)
          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;",user,ImageFile,text[126]);
+            fprintf(fp_top3,"<a href=\"%s/graph_day.png\"><img src=\"%s/graph.png\" title=\"%s\" alt=\"G\"></a>&nbsp;",uinfo->filename,ImageFile,text[126]);
          }
 #endif
-         fprintf(fp_top3,"<a href=\"%s/d%s.html\"><img src=\"%s/datetime.png\" title=\"%s",user,user,ImageFile,ltext110);
+         fprintf(fp_top3,"<a href=\"%s/d%s.html\"><img src=\"%s/datetime.png\" title=\"%s",uinfo->filename,uinfo->filename,ImageFile,ltext110);
 #ifdef HAVE_GD
          fprintf(fp_top3," %s",text[55]);
 #endif
          fputs("\" alt=\"T\"></a></td>",fp_top3);
       } else {
-         sprintf(val1,"%s/d%s.html",dirname,user);
+         sprintf(val1,"%s/d%s.html",dirname,uinfo->filename);
          unlink(val1);
       }
       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>",user,user,name);
+            fprintf(fp_top3,"<td class=\"data2\"><a href=\"%s/%s.html\">%s</a></td>",uinfo->filename,uinfo->filename,uinfo->label);
       }
       if((TopUserFields & TOPUSERFIELDS_CONNECT) != 0)
          fprintf(fp_top3,"<td class=\"data\">%s</td>",fixnum(nacc,1));
index d24cec484b80d5e2782f5eb2b6b75830336f36bf..b00aa4cc1641e918db1396112a19d168c9945ee4 100644 (file)
--- a/totday.c
+++ b/totday.c
@@ -27,7 +27,7 @@
 #include "include/conf.h"
 #include "include/defs.h"
 
-void day_totalize(const char *tmp, const char *user, int indexonly)
+void day_totalize(const char *tmp, const struct userinfostruct *uinfo, int indexonly)
 {
 
    FILE *fp_in, *fp_ou;
@@ -51,20 +51,20 @@ void day_totalize(const char *tmp, const char *user, int indexonly)
    if(indexonly) return;
    if((ReportType & REPORT_TYPE_USERS_SITES) == 0) return;
 
-   sprintf(wdirname,"%s/%s.htmp",tmp,user);
-   sprintf(arqout,"%s/%s.day",tmp,user);
-   sprintf(sortout,"%s/%s.sort",tmp,user);
+   sprintf(wdirname,"%s/%s.htmp",tmp,uinfo->filename);
+   sprintf(arqout,"%s/%s.day",tmp,uinfo->filename);
+   sprintf(sortout,"%s/%s.sort",tmp,uinfo->filename);
 
    sprintf(csort,"sort -k 1,1 -k 2,2 -o \"%s\" \"%s\"",sortout,wdirname);
    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);
+      debuga(_("sort command return status %d"),WEXITSTATUS(cstatus));
+      debuga(_("sort command: %s"),csort);
       exit(1);
    }
    if((fp_in=fopen(sortout,"r"))==NULL) {
       fprintf(stderr, "SARG: (totday) %s: %s\n",text[8],sortout);
-      fprintf(stderr, "SARG: sort command: %s\n",csort);
+      debuga(_("sort command: %s"),csort);
       exit(1);
    }
 
@@ -81,7 +81,7 @@ void day_totalize(const char *tmp, const char *user, int indexonly)
       if (getword(data,sizeof(data),&gwarea,'\t')<0 || getword(hora,sizeof(hora),&gwarea,':')<0 ||
           getword(min,sizeof(min),&gwarea,':')<0 || getword_skip(20,&gwarea,'\t')<0 ||
           getword(elap,sizeof(elap),&gwarea,0)<0) {
-         printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",sortout);
+         debuga(_("There is a broken record or garbage in file %s"),sortout);
          exit(1);
       }
 
diff --git a/userinfo.c b/userinfo.c
new file mode 100644 (file)
index 0000000..8caa5ee
--- /dev/null
@@ -0,0 +1,151 @@
+/*
+ * 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
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
+ *
+ */
+
+#include "include/conf.h"
+#include "include/defs.h"
+
+//! The number of users to group in one unit.
+#define USERS_PER_GROUP 50
+
+/*! \brief Group the users in one allocation unit.
+Structure to store a group of users and reduce the number of memory
+allocations.
+*/
+struct usergroupstruct
+{
+   //! The next group of users.
+   struct usergroupstruct *next;
+   //! A group of users.
+   struct userinfostruct list[USERS_PER_GROUP];
+   //! The number of users stored in the list.
+   int nusers;
+};
+
+//! The first group of users.
+static struct usergroupstruct *first_user_group=NULL;
+
+struct userinfostruct *userinfo_create(const char *userid)
+{
+   struct usergroupstruct *group, *last;
+   struct userinfostruct *user;
+   int i, lastuser;
+   int skip;
+   int flen;
+   int count, clen;
+   char cstr[9];
+
+   last=NULL;
+   for (group=first_user_group ; group ; group=group->next) {
+      if (group->nusers<USERS_PER_GROUP) break;
+      last=group;
+   }
+
+   if (!group) {
+      group=malloc(sizeof(*group));
+      if (!group) {
+         debuga(_("Not enough memory to store the user"));
+         exit(1);
+      }
+      memset(group,0,sizeof(*group));
+      if (last)
+         last->next=group;
+      else
+         first_user_group=group;
+   }
+   user=group->list+group->nusers++;
+
+   strncpy(user->id,userid,MAX_USER_LEN-1);
+   user->id[MAX_USER_LEN-1]='\0';
+
+   skip=0;
+   for(i=0 ; userid[i] && i<MAX_USER_FNAME_LEN-1 ; i++) {
+      if(userid[i]=='?' || userid[i]=='.' || userid[i]==':' || userid[i]=='/' || userid[i]=='\\' || userid[i]=='\'' ||
+         userid[i]=='$' || userid[i]=='@' || userid[i]=='\"' || userid[i]=='*') {
+         if (!skip) {
+            user->filename[i]='_';
+            skip=1;
+         }
+      } else {
+         user->filename[i]=userid[i];
+         skip=0;
+      }
+   }
+   user->filename[i]='\0';
+   flen=i;
+
+   count=0;
+   for (group=first_user_group ; group ; group=group->next) {
+      lastuser=(group->next) ? group->nusers : group->nusers-1;
+      for (i=0 ; i<lastuser ; i++) {
+         if (strcasecmp(user->filename,group->list[i].filename)==0) {
+            clen=sprintf(cstr,"-%04X",count++);
+            if (flen+clen<MAX_USER_FNAME_LEN)
+               strcpy(user->filename+flen,cstr);
+            else
+               strcpy(user->filename+MAX_USER_FNAME_LEN-clen,cstr);
+         }
+      }
+   }
+
+   return(user);
+}
+
+void userinfo_free(void)
+{
+   struct usergroupstruct *group, *next;
+
+   for (group=first_user_group ; group ; group=next) {
+      next=group->next;
+      free(group);
+   }
+   first_user_group=NULL;
+}
+
+struct userinfostruct *userinfo_find_from_file(const char *filename)
+{
+   struct usergroupstruct *group;
+   int i;
+
+   for (group=first_user_group ; group ; group=group->next) {
+      for (i=0 ; i<group->nusers ; i++)
+         if (strcmp(filename,group->list[i].filename)==0)
+            return(group->list+i);
+   }
+   return(NULL);
+}
+
+struct userinfostruct *userinfo_find_from_id(const char *id)
+{
+   struct usergroupstruct *group;
+   int i;
+
+   for (group=first_user_group ; group ; group=group->next) {
+      for (i=0 ; i<group->nusers ; i++)
+         if (strcmp(id,group->list[i].id)==0)
+            return(group->list+i);
+   }
+   return(NULL);
+}
diff --git a/util.c b/util.c
index 7e963f30d1cff667a0cb326932fb6912f3d68b58..a185741fec533d2fd08e1eb96b038226fb70f855 100644 (file)
--- a/util.c
+++ b/util.c
@@ -475,7 +475,7 @@ void debuga(const char *msg,...)
 {
    va_list ap;
 
-   fputs("SARG: ",stderr);
+   fputs(_("SARG: "),stderr);
    va_start(ap,msg);
    vfprintf(stderr,msg,ap);
    va_end(ap);
@@ -490,35 +490,6 @@ void debugaz(const char *head, const char *msg)
 }
 
 
-void fixip(char *ip)
-{
-   int i;
-   char sep='_';
-   char search=0;
-   int nrepl=0;
-
-   for (i=0; ip[i]; i++) {
-      if (ip[i]=='.') {
-         search='.';
-         sep='_';
-         break;
-      }
-      if (ip[i]=='_') {
-         search='_';
-         sep='.';
-         break;
-      }
-   }
-   for (; ip[i]; i++) {
-      if (ip[i]==search) {
-         ip[i]=sep;
-         nrepl++;
-         if (nrepl>=3) break;
-      }
-   }
-}
-
-
 char *fixnum(long long int value, int n)
 {
 #define MAXLEN_FIXNUM 1024