]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
More translations for gettext.
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Wed, 10 Mar 2010 19:48:52 +0000 (19:48 +0000)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Wed, 10 Mar 2010 19:48:52 +0000 (19:48 +0000)
The filtering by week day or hour now works for any input log format and not only for a common squid log file.

documentation/util.txt
include/defs.h
log.c
util.c

index 80e9b1d040a7eb97482012bb5982654f344fb75e..a1774a5b12093c16eaf510618858572d9948a325 100644 (file)
@@ -409,6 +409,20 @@ Format a date to display it in the report.
 
 
 
+/*! \fn time_t computedate(const char *year,const char *month,const char *day);
+Compute a unix timestamp from a date.
+
+\param year The full year with century.
+\param month The name of the month in English as defined by ::mtab1.
+\param day The day of the date.
+
+\return A unix timestamp.
+*/
+
+
+
+
+
 /*! \fn int obtuser(const char *dirname, const char *name)
 Get the number of entries stored in a report data directory. The number is read from
 the <tt>sarg-users</tt> file of the report data's directory.
index fbc9286c133c8bc3f69dd097e8fa6068b778b460..10226e9b4f04e63f1360950e71265358d33fec81 100755 (executable)
@@ -233,6 +233,7 @@ void strip_latin(char *line);
 char *buildtime(long long int elap);
 void obtdate(const char *dirname, const char *name, char *data);
 void formatdate(char *date,int date_size,int year,int month,int day,int hour,int minute,int second,int dst);
+time_t computedate(const char *year,const char *month,const char *day);
 int obtuser(const char *dirname, const char *name);
 void obttotal(const char *dirname, const char *name, char *tbytes, int nuser, char *media);
 void version(void);
diff --git a/log.c b/log.c
index 9961668a19dbb553217c5160811929c371b94f5e..6d30fc5a7427e6900107e23edcf2d7ad545e5f08 100644 (file)
--- a/log.c
+++ b/log.c
@@ -816,18 +816,6 @@ int main(int argc,char *argv[])
          if(strstr(linebuf,"logfile turned over") != 0) continue;
          if(linebuf[0] == ' ') continue;
 
-         // Record only hours usage which is required
-         tt = (time_t) strtoul( linebuf, NULL, 10 );
-         t = localtime( &tt );
-
-         if( bsearch( &( t -> tm_wday ), weekdays.list, weekdays.len,
-                                          sizeof( int ), compar ) == NULL )
-            continue;
-
-         if( bsearch( &( t -> tm_hour ), hours.list, hours.len,
-                                          sizeof( int ), compar ) == NULL )
-            continue;
-
          // exclude_string
          if(ExcludeString[0] != '\0') {
             exstring=0;
@@ -852,7 +840,7 @@ int main(int argc,char *argv[])
          if (ilf==ILF_Squid || ilf==ILF_Common || ilf==ILF_Unknown) {
             getword_start(&gwarea,linebuf);
             if (getword(data,sizeof(data),&gwarea,' ')<0) {
-               printf("SARG: Maybe you have a broken time in your access.log file.\n");
+               debuga(_("Maybe you have a broken time in your access.log file.\n"));
                exit(1);
             }
             if((str=(char *) strchr(data, '.')) != (char *) NULL ) {
@@ -861,18 +849,18 @@ int main(int argc,char *argv[])
                   strcpy(elap,"0");
                   if(squid24) {
                      if (getword(user,sizeof(user),&gwarea,' ')<0 || getword_skip(255,&gwarea,' ')<0) {
-                        printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+                        debuga(_("Maybe you have a broken record or garbage in your %s file.\n"),arq);
                         exit(1);
                      }
                   } else {
                      if (getword_skip(255,&gwarea,' ')<0 || getword(user,sizeof(user),&gwarea,' ')<0) {
-                        printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+                        debuga(_("Maybe you have a broken record or garbage in your %s file.\n"),arq);
                         exit(1);
                      }
                   }
                   if (getword(data,sizeof(data),&gwarea,']')<0 || getword_skip(MAXLEN,&gwarea,'"')<0 ||
                       getword(fun,sizeof(fun),&gwarea,' ')<0) {
-                     printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+                     debuga(_("Maybe you have a broken record or garbage in your %s file.\n"),arq);
                      exit(1);
                   }
                   if (getword_ptr(linebuf,&url,&gwarea,' ')<0) {
@@ -881,17 +869,17 @@ int main(int argc,char *argv[])
                   }
                   if (getword_skip(MAXLEN,&gwarea,' ')<0 || getword(code2,sizeof(code2),&gwarea,' ')<0 ||
                       getword(tam,sizeof(tam),&gwarea,' ')<0) {
-                     printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+                     debuga(_("Maybe you have a broken record or garbage in your %s file.\n"),arq);
                      exit(1);
                   }
                   if((str=(char *) strchr(gwarea.current, ' ')) != (char *) NULL ) {
                      if (getword(code,sizeof(code),&gwarea,' ')<0) {
-                        printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+                        debuga(_("Maybe you have a broken record or garbage in your %s file.\n"),arq);
                         exit(1);
                      }
                   } else {
                      if (getword(code,sizeof(code),&gwarea,'\0')<0) {
-                        printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+                        debuga(_("Maybe you have a broken record or garbage in your %s file.\n"),arq);
                         exit(1);
                      }
                   }
@@ -909,29 +897,29 @@ int main(int argc,char *argv[])
 
             if(ilf==ILF_Unknown || ilf==ILF_Squid) {
                if (getword(elap,sizeof(elap),&gwarea,' ')<0) {
-                  printf("SARG: Maybe you have a broken elapsed time in your %s file.\n",arq);
+                  debuga(_("Maybe you have a broken elapsed time in your %s file.\n"),arq);
                   exit(1);
                }
                while(strcmp(elap,"") == 0 && gwarea.current[0] != '\0')
                   if (getword(elap,sizeof(elap),&gwarea,' ')<0) {
-                     printf("SARG: Maybe you have a broken elapsed time in your %s file.\n",arq);
+                     debuga(_("Maybe you have a broken elapsed time in your %s file.\n"),arq);
                      exit(1);
                   }
                if(strlen(elap) < 1) continue;
                if (getword(ip,sizeof(ip),&gwarea,' ')<0){
-                  printf("SARG: Maybe you have a broken client IP address in your %s file.\n",arq);
+                  debuga(_("Maybe you have a broken client IP address in your %s file.\n"),arq);
                   exit(1);
                }
                if (getword(code,sizeof(code),&gwarea,' ')<0){
-                  printf("SARG: Maybe you have a broken result code in your %s file.\n",arq);
+                  debuga(_("Maybe you have a broken result code in your %s file.\n"),arq);
                   exit(1);
                }
                if (getword(tam,sizeof(tam),&gwarea,' ')<0){
-                  printf("SARG: Maybe you have a broken amount of data in your %s file.\n",arq);
+                  debuga(_("Maybe you have a broken amount of data in your %s file.\n"),arq);
                   exit(1);
                }
                if (getword(fun,sizeof(fun),&gwarea,' ')<0){
-                  printf("SARG: Maybe you have a broken request method in your %s file.\n",arq);
+                  debuga(_("Maybe you have a broken request method in your %s file.\n"),arq);
                   exit(1);
                }
                if (getword_ptr(linebuf,&url,&gwarea,' ')<0){
@@ -939,7 +927,7 @@ int main(int argc,char *argv[])
                   exit(1);
                }
                if (getword(user,sizeof(user),&gwarea,' ')<0){
-                  printf("SARG: Maybe you have a broken user ID in your %s file.\n",arq);
+                  debuga(_("Maybe you have a broken user ID in your %s file.\n"),arq);
                   exit(1);
                }
                ilf=ILF_Squid;
@@ -949,19 +937,19 @@ int main(int argc,char *argv[])
          if (ilf==ILF_Sarg) {
             getword_start(&gwarea,linebuf);
             if (getword(data,sizeof(data),&gwarea,'\t')<0){
-               printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+               debuga(_("Maybe you have a broken record or garbage in your %s file.\n"),arq);
                exit(1);
             }
             if (getword(hora,sizeof(hora),&gwarea,'\t')<0) {
-               printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+               debuga(_("Maybe you have a broken record or garbage in your %s file.\n"),arq);
                exit(1);
             }
             if (getword(user,sizeof(user),&gwarea,'\t')<0) {
-               printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+               debuga(_("Maybe you have a broken record or garbage in your %s file.\n"),arq);
                exit(1);
             }
             if (getword(ip,sizeof(ip),&gwarea,'\t')<0) {
-               printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+               debuga(_("Maybe you have a broken record or garbage in your %s file.\n"),arq);
                exit(1);
             }
             if (getword_ptr(linebuf,&url,&gwarea,'\t')<0){
@@ -969,19 +957,19 @@ int main(int argc,char *argv[])
                exit(1);
             }
             if (getword(tam,sizeof(tam),&gwarea,'\t')<0){
-               printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+               debuga(_("Maybe you have a broken record or garbage in your %s file.\n"),arq);
                exit(1);
             }
             if (getword(code,sizeof(code),&gwarea,'\t')<0){
-               printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+               debuga(_("Maybe you have a broken record or garbage in your %s file.\n"),arq);
                exit(1);
             }
             if (getword(elap,sizeof(elap),&gwarea,'\t')<0){
-               printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+               debuga(_("Maybe you have a broken record or garbage in your %s file.\n"),arq);
                exit(1);
             }
             if (getword(smartfilter,sizeof(smartfilter),&gwarea,'\0')<0){
-               printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+               debuga(_("Maybe you have a broken record or garbage in your %s file.\n"),arq);
                exit(1);
             }
          }
@@ -1000,7 +988,7 @@ int main(int argc,char *argv[])
                ncols=0;
                while(gwarea.current[0] != '\0') {
                   if (getword(val1,sizeof(val1),&gwarea,'\t')<0){
-                     printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+                     debuga(_("Maybe you have a broken record or garbage in your %s file.\n"),arq);
                      exit(1);
                   }
                   if(strcmp(val1,"c-ip") == 0) cols[ISACOL_Ip]=ncols;
@@ -1149,6 +1137,8 @@ int main(int argc,char *argv[])
                snprintf(tbuf,sizeof(tbuf),"%s%s%s",dia,mes,ano);
             builddia(dia,mes,ano,df,wdata);
             idata=atoi(wdata);
+            tt=computedate(ano,mes,dia);
+            t=localtime(&tt);
          } else if (ilf==ILF_Sarg) {
             getword_start(&gwarea,data);
             if(strcmp(df,"u") == 0) {
@@ -1176,6 +1166,8 @@ int main(int argc,char *argv[])
             }
             snprintf(wdata,9,"%s%s%s",ano,mes,dia);
             idata=atoi(wdata);
+            tt=computedate(ano,mes,dia);
+            t=localtime(&tt);
          }
 
          if(debugm)
@@ -1185,6 +1177,16 @@ int main(int argc,char *argv[])
             if(idata < dfrom || idata > duntil) continue;
          }
 
+         // Record only hours usage which is required
+         if( bsearch( &( t -> tm_wday ), weekdays.list, weekdays.len,
+                                          sizeof( int ), compar ) == NULL )
+            continue;
+
+         if( bsearch( &( t -> tm_hour ), hours.list, hours.len,
+                                          sizeof( int ), compar ) == NULL )
+            continue;
+
+
          if(strlen(user) > MAX_USER_LEN) {
             if (debugm) printf(_("User ID too long: %s\n"),user);
             totregsx++;
@@ -1403,7 +1405,7 @@ int main(int argc,char *argv[])
                exit(1);
             }
             if ((ufile->file = MY_FOPEN (tmp3, "a")) == NULL) {
-               fprintf (stderr, "%s: (log) %s: %s - %s\n", argv[0], _("Cannot open temporary file"), tmp3, strerror(errno));
+               debuga(_("(log) Cannot open temporary file: %s - %s\n"), tmp3, strerror(errno));
                exit (1);
             }
          }
@@ -1431,7 +1433,7 @@ int main(int argc,char *argv[])
 
             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], _("Cannot open temporary file"), tmp3, strerror(errno));
+                  debuga(_("(log) Cannot open temporary file: %s - %s\n"),tmp3, strerror(errno));
                   exit (1);
                }
             }
@@ -1477,7 +1479,7 @@ int main(int argc,char *argv[])
       if (!from_stdin) {
          fclose(fp_in);
          if( ShowReadStatistics )
-            printf("SARG: Records in file: %lu, reading: %3.2f%%\n",recs1, (float) 100 );
+            printf(_("SARG: Records in file: %lu, reading: %3.2f%%\n"),recs1, (float) 100 );
       }
    }
 
@@ -1516,9 +1518,9 @@ int main(int argc,char *argv[])
 
       if(totalcount==0) {
          if(!totregsg) {
-            fprintf(stderr, "SARG: %s\n",_("No records found"));
-            fprintf(stderr, "SARG: %s\n",_("End"));
-         } else fprintf(stderr, "SARG: %s\n",_("Log with invalid format"));
+            debuga(_("No records found\n"));
+            debuga(_("End\n"));
+         } else debuga(_("Log with invalid format\n"));
          if(fp_denied)
             fclose(fp_denied);
          if(fp_authfail)
@@ -1535,8 +1537,8 @@ int main(int argc,char *argv[])
    }
 
    if(!totregsg){
-      fprintf(stderr, "SARG: %s\n",_("No records found"));
-      fprintf(stderr, "SARG: %s\n",_("End"));
+      debuga(_("No records found\n"));
+      debuga(_("End\n"));
 //      fclose(fp_ou);
       if(fp_denied)
          fclose(fp_denied);
@@ -1573,16 +1575,16 @@ int main(int argc,char *argv[])
       strcpy(end_hour,tbuf2);
       getword_start(&gwarea,period);
       if (getword(val2,sizeof(val2),&gwarea,'-')<0){
-         printf("SARG: Maybe you have a broken date range definition.\n");
+         debuga(_("Maybe you have a broken date range definition.\n"));
          exit(1);
       }
       if (getword(val1,sizeof(val1),&gwarea,'\0')<0){
-         printf("SARG: Maybe you have a broken date range definition.\n");
+         debuga(_("Maybe you have a broken date range definition.\n"));
          exit(1);
       }
       sprintf(val4,"%s/sarg-%s_%s-%s_%s.log",ParsedOutputLog,val2,start_hour,val1,end_hour);
       if (rename(arq_log,val4)) {
-         fprintf(stderr,"SARG: failed to rename %s to %s - %s\n",arq_log,val4,strerror(errno));
+         debuga(_("failed to rename %s to %s - %s\n"),arq_log,val4,strerror(errno));
       } else {
          strcpy(arq_log,val4);
 
@@ -1594,8 +1596,8 @@ int main(int argc,char *argv[])
             sprintf(val1,"%s \"%s\"",ParsedOutputLogCompress,arq_log);
             cstatus=system(val1);
             if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
-               fprintf(stderr, "SARG: command return status %d\n",WEXITSTATUS(cstatus));
-               fprintf(stderr, "SARG: command: %s\n",val1);
+               debuga(_("command return status %d\n"),WEXITSTATUS(cstatus));
+               debuga(_("command: %s\n"),val1);
                exit(1);
             }
          }
@@ -1608,8 +1610,8 @@ int main(int argc,char *argv[])
       sprintf(csort,"sort -T \"%s\" -k 3,3 -k 5,5 -o \"%s\" \"%s\"",tmp,denied_sort,denied_unsort);
       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\n"),WEXITSTATUS(cstatus));
+         debuga(_("sort command: %s\n"),csort);
          exit(1);
       }
       unlink(denied_unsort);
@@ -1660,21 +1662,21 @@ static void getusers(const char *pwdfile, int debug)
       debuga(_("Loading password file from: %s\n"),pwdfile);
 
    if ((fp_usr = fopen(pwdfile, "r")) == NULL) {
-      fprintf(stderr, "SARG: (getusers) %s: %s - %s\n",_("Cannot open file"),pwdfile,strerror(errno));
+      debuga(_("(getusers) Cannot open file: %s - %s\n"),pwdfile,strerror(errno));
       exit(1);
    }
 
    fseek(fp_usr, 0, SEEK_END);
    nreg = ftell(fp_usr);
    if (nreg<0) {
-      printf("SARG: Cannot get the size of file %s",pwdfile);
+      debuga(_("Cannot get the size of file %s\n"),pwdfile);
       exit(1);
    }
    nreg = nreg+5000;
    fseek(fp_usr, 0, SEEK_SET);
 
    if((userfile=(char *) malloc(nreg))==NULL){
-      fprintf(stderr, "SARG: %s (%ld):\n",_("malloc error"),nreg);
+      debuga(_("malloc error (%ld):\n"),nreg);
       exit(1);
    }
 
@@ -1684,7 +1686,7 @@ static void getusers(const char *pwdfile, int debug)
    while(fgets(buf,sizeof(buf),fp_usr)!=NULL) {
       str=strchr(buf,':');
       if (!str) {
-         printf("SARG: You have an invalid user in your %s file.\n",pwdfile);
+         debuga(_("You have an invalid user in your %s file.\n"),pwdfile);
          exit(1);
       }
       str[1]=0;
diff --git a/util.c b/util.c
index f2fb2fcf0da32a804bd2a4f76e01b280134760b5..c742592486599b8aa60dac4356cd4201b91c0492 100644 (file)
--- a/util.c
+++ b/util.c
@@ -714,6 +714,25 @@ void formatdate(char *date,int date_size,int year,int month,int day,int hour,int
 }
 
 
+time_t computedate(const char *year,const char *month,const char *day)
+{
+   struct tm ltm;
+   int y,m,d;
+
+   y=atoi(year);
+   for(m=0; m<12 && strcmp(mtab1[m],month)!=0; m++);
+   d=atoi(day);
+
+   memset(&ltm,0,sizeof(ltm));
+   ltm.tm_year=y-1900;
+   ltm.tm_mon=m;
+   ltm.tm_mday=d;
+   ltm.tm_hour=12; //be sure to cope with dst
+
+   return(mktime(&ltm));
+}
+
+
 int obtuser(const char *dirname, const char *name)
 {