]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Fixed regressions in creation and reading of a sarg parsed log (thanks to Joao Alves)
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Fri, 22 Jan 2010 09:59:25 +0000 (09:59 +0000)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Fri, 22 Jan 2010 09:59:25 +0000 (09:59 +0000)
CMakeLists.txt
ChangeLog
include/conf.h
include/info.h
log.c
sarg.conf

index 01affbf9c792fc0744a0fdbcbc3424ec6cbe54ba..bcd3f7fae2e9e1d112564850ecf3d6beb65d0ea0 100755 (executable)
@@ -3,7 +3,7 @@ PROJECT(sarg C)
 SET(sarg_VERSION 2)
 SET(sarg_REVISION 2)
 SET(sarg_BUILD "7rc1")
-SET(sarg_BUILDDATE "Jan-20-2010")
+SET(sarg_BUILDDATE "Jan-22-2010")
 
 INCLUDE(AddFileDependencies)
 INCLUDE(CheckIncludeFile)
index 74c6acba00aeb7a5476df958de0ea60772e843cf..0136d27f7bdd3957ef7874defc551626d7c87d08 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,6 @@
 SARG ChangeLog
 
-Jan-20-2010 Version 2.2.7
+Jan-22-2010 Version 2.2.7
                - Extra compile and run time protection (FORTIFY_SOURCE) fixed in configure.
                - Use tabulations as columns separator in intermediary files to avoid problems when a field of the log contains a space.
                - Input log file type detection partly rewritten to clearly distinguish which type is processed where.
@@ -21,6 +21,8 @@ Jan-20-2010 Version 2.2.7
                - Replace --enable-htmldir by --enable-sargphp to avoid confusion on the name.
                - Installation of sarg-php can be disabled with --disable-sargphp.
                - Fixed empty entries in squidGuard log when the URL doesn't start with protocol://.
+               - Fixed regressions in creation and reading of a sarg parsed log (thanks to Joao Alves).
+               - Does not report URLs consisting of only a host name ending with .com as a downloaded file.
 
 Jan-06-2010 Version 2.2.6.1
                - Remove unnecessary dependency on off_t.
index efa0caa353640f7cedc274615076fea12f71c3bf..54be925e667b09ee0c4edfb51daef9b266846bce 100755 (executable)
@@ -143,7 +143,6 @@ char urly[MAXLEN];
 char user[MAXLEN];
 char period[MAXLEN];
 char msg[1024];
-char per_hour[128];
 char code[MAXLEN];
 char code2[MAXLEN];
 char tmp[MAXLEN];
@@ -254,7 +253,7 @@ int ShowSargInfo;
 int BytesInSitesUsersReport;
 int ShowSargLogo;
 char ParsedOutputLog[MAXLEN];
-char ParsedOutputLogCompress[255];
+char ParsedOutputLogCompress[512];
 char DisplayedValues[20];
 char HeaderFontSize[5];
 char TitleFontSize[5];
index a9ee4ce8ce2cffcd778a6d8dd1546a42fb0e910b..45a38c8484a93ea622b92e2f9fb7fa4d8a2c12e2 100755 (executable)
@@ -1,3 +1,3 @@
-#define VERSION PACKAGE_VERSION" Jan-20-2010"
+#define VERSION PACKAGE_VERSION" Jan-22-2010"
 #define PGM PACKAGE_NAME
 #define URL "http://sarg.sourceforge.net"
diff --git a/log.c b/log.c
index f45dc1c4071a02355caeb30d37dbe8d1c8c10353..841f3c9fa0c2614f23895158091682b8d31ebf52 100644 (file)
--- a/log.c
+++ b/log.c
@@ -100,6 +100,8 @@ int main(int argc,char *argv[])
    char bufz[MAXLEN];
    char bufy[MAXLEN];
    char tmp2[MAXLEN];
+   char start_hour[128];
+   char end_hour[128];
    enum InputLogFormat ilf;
    int ilf_count[ILF_Last];
    int  ch;
@@ -125,7 +127,7 @@ int main(int argc,char *argv[])
    unsigned long recs1=0UL;
    unsigned long recs2=0UL;
    int OutputNonZero = REPORT_EVERY_X_LINES ;
-   int download_flag;
+   int download_flag=0;
    char download_url[MAXLEN];
    char sz_Last_User[MAXLEN]="";
    struct getwordstruct gwarea;
@@ -200,7 +202,7 @@ int main(int argc,char *argv[])
    ShowSargInfo=1;
    ShowSargLogo=1;
    strcpy(ParsedOutputLog,"no");
-   strcpy(ParsedOutputLogCompress,"/bin/gzip");
+   strcpy(ParsedOutputLogCompress,"/bin/gzip -f");
    strcpy(DisplayedValues,"abbreviation");
    strcpy(HeaderFontSize,"9px");
    strcpy(TitleFontSize,"11px");
@@ -248,6 +250,8 @@ int main(int argc,char *argv[])
    DataFile[0]='\0';
    SquidGuardConf[0]='\0';
    DansGuardianConf[0]='\0';
+   start_hour[0]='\0';
+   end_hour[0]='\0';
 
    denied_count=0;
    download_count=0;
@@ -712,6 +716,7 @@ int main(int argc,char *argv[])
          from_stdin=0;
       }
       ilf=ILF_Unknown;
+      download_flag=0;
       // pre-Read the file only if I have to show stats
       if(ShowReadStatistics && !from_stdin) {
          rewind(fp_in);
@@ -738,9 +743,9 @@ int main(int argc,char *argv[])
 
             if(strncmp(bufz,"*** SARG Log ***",16) == 0) {
                getword_start(&gwarea,arqtt);
-               if (getword(val2,sizeof(val2),&gwarea,'-')<0 || getword(val2,sizeof(val2),&gwarea,'_')<0 ||
-                   getword(val3,sizeof(val3),&gwarea,'-')<0 || getword(val3,sizeof(val3),&gwarea,'_')<0) {
-                  printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+               if (getword_skip(2000,&gwarea,'-')<0 || getword(val2,sizeof(val2),&gwarea,'_')<0 ||
+                   getword_skip(10,&gwarea,'-')<0 || getword(val3,sizeof(val3),&gwarea,'_')<0) {
+                  printf("SARG: The name of the file is invalid: %s\n",arq);
                   exit(1);
                }
                sprintf(period,"%s-%s",val2,val3);
@@ -750,10 +755,9 @@ int main(int argc,char *argv[])
             }
          }
 
-         if(strcmp(ParsedOutputLog, "no") != 0 && ilf!=ILF_Sarg) {
+         if(!fp_log && strcmp(ParsedOutputLog, "no") != 0 && ilf!=ILF_Sarg) {
             if(access(ParsedOutputLog,R_OK) != 0) {
-               sprintf(csort,"%s",ParsedOutputLog);
-               my_mkdir(csort);
+               my_mkdir(ParsedOutputLog);
             }
             sprintf(arq_log,"%s/sarg_temp.log",ParsedOutputLog);
             if((fp_log=MY_FOPEN(arq_log,"w"))==NULL) {
@@ -912,39 +916,39 @@ int main(int argc,char *argv[])
          }
          if (ilf==ILF_Sarg) {
             getword_start(&gwarea,bufz);
-            if (getword(data,sizeof(data),&gwarea,' ')<0){
+            if (getword(data,sizeof(data),&gwarea,'\t')<0){
                printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
                exit(1);
             }
-            if (getword(hora,sizeof(hora),&gwarea,' ')<0) {
+            if (getword(hora,sizeof(hora),&gwarea,'\t')<0) {
                printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
                exit(1);
             }
-            if (getword(user,sizeof(user),&gwarea,' ')<0) {
+            if (getword(user,sizeof(user),&gwarea,'\t')<0) {
                printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
                exit(1);
             }
-            if (getword(ip,sizeof(ip),&gwarea,' ')<0) {
+            if (getword(ip,sizeof(ip),&gwarea,'\t')<0) {
                printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
                exit(1);
             }
-            if (getword(url,sizeof(url),&gwarea,' ')<0){
+            if (getword(url,sizeof(url),&gwarea,'\t')<0){
                printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
                exit(1);
             }
-            if (getword(tam,sizeof(tam),&gwarea,' ')<0){
+            if (getword(tam,sizeof(tam),&gwarea,'\t')<0){
                printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
                exit(1);
             }
-            if (getword(code,sizeof(code),&gwarea,' ')<0){
+            if (getword(code,sizeof(code),&gwarea,'\t')<0){
                printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
                exit(1);
             }
-            if (getword(elap,sizeof(elap),&gwarea,' ')<0){
+            if (getword(elap,sizeof(elap),&gwarea,'\t')<0){
                printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
                exit(1);
             }
-            if (getword(smartfilter,sizeof(smartfilter),&gwarea,' ')<0){
+            if (getword(smartfilter,sizeof(smartfilter),&gwarea,'\0')<0){
                printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
                exit(1);
             }
@@ -1132,10 +1136,16 @@ int main(int argc,char *argv[])
          if(strstr(ReportType,"denied") != 0)
             strcpy(urly,url);
 
-         download_flag=is_download_suffix(url);
-         if (download_flag) {
-            strcpy(download_url,url);
-            download_count++;
+         if(ilf!=ILF_Sarg) {
+            /*
+            The full URL is not saved in sarg log. There is no point in testing the URL to detect
+            a downloaded file.
+            */
+            download_flag=is_download_suffix(url);
+            if (download_flag) {
+               strcpy(download_url,url);
+               download_count++;
+            }
          }
 
          // remove any protocol:// at the beginning of the URL
@@ -1192,15 +1202,15 @@ int main(int argc,char *argv[])
                exit(1);
             }
             getword_start(&gwarea,data);
-            if (getword_multisep(dia,sizeof(dia),&gwarea,'/')<0){
+            if (getword(dia,sizeof(dia),&gwarea,'/')<0){
                printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
                exit(1);
             }
-            if (getword_multisep(mes,sizeof(mes),&gwarea,'/')<0){
+            if (getword(mes,sizeof(mes),&gwarea,'/')<0){
                printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
                exit(1);
             }
-            if (getword_multisep(ano,sizeof(ano),&gwarea,'/')<0){
+            if (getword(ano,sizeof(ano),&gwarea,'/')<0){
                printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
                exit(1);
             }
@@ -1213,18 +1223,31 @@ int main(int argc,char *argv[])
             idata=atoi(wdata);
          } else if (ilf==ILF_Sarg) {
             getword_start(&gwarea,data);
-            if (getword_multisep(mes,sizeof(mes),&gwarea,'/')<0){
-               printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
-               exit(1);
-            }
-            if (getword_multisep(dia,sizeof(dia),&gwarea,'/')<0){
-               printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
-               exit(1);
+            if(strcmp(df,"u") == 0) {
+               if (getword(mes,sizeof(mes),&gwarea,'/')<0){
+                  printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
+                  exit(1);
+               }
+               if (getword(dia,sizeof(dia),&gwarea,'/')<0){
+                  printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
+                  exit(1);
+               }
+            } else {
+               if (getword(dia,sizeof(dia),&gwarea,'/')<0){
+                  printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
+                  exit(1);
+               }
+               if (getword(mes,sizeof(mes),&gwarea,'/')<0){
+                  printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
+                  exit(1);
+               }
             }
-            if (getword_multisep(ano,sizeof(ano),&gwarea,0)<0){
+            if (getword(ano,sizeof(ano),&gwarea,0)<0){
                printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
                exit(1);
             }
+            snprintf(wdata,9,"%s%s%s",ano,mes,dia);
+            idata=atoi(wdata);
          }
 
          if(debugm)
@@ -1351,8 +1374,7 @@ int main(int argc,char *argv[])
                }
                fputs (bufz, fp_Write_User);
 
-               if(strcmp(ParsedOutputLog, "no") != 0 && ilf!=ILF_Sarg)
-                  fputs(bufz,fp_log);
+               if(fp_log && ilf!=ILF_Sarg) fputs(bufz,fp_log);
 
                totregsg++;
 
@@ -1384,7 +1406,7 @@ int main(int argc,char *argv[])
                   totper++;
                   mindate=idata;
                   sprintf(period,"%s-",tbuf);
-                  sprintf(per_hour,"%s-",tbuf2);
+                  strcpy(start_hour,tbuf2);
                   if(date[0] != '\0')
                      fixper(tbuf, period, cduntil);
                   if(debugz){
@@ -1477,7 +1499,6 @@ int main(int argc,char *argv[])
 
    if(date[0] == '\0' && ilf_count[ILF_Sarg]==0) {
       strcat(period,tbuf);
-      strcat(per_hour,tbuf2);
    }
 
    if(debugz){
@@ -1497,34 +1518,36 @@ int main(int argc,char *argv[])
 
    if(fp_log != NULL) {
       fclose(fp_log);
+      strcpy(end_hour,tbuf2);
       getword_start(&gwarea,period);
-      if (getword_multisep(val2,sizeof(val2),&gwarea,'-')<0){
+      if (getword(val2,sizeof(val2),&gwarea,'-')<0){
          printf("SARG: Maybe you have a broken date range definition.\n");
          exit(1);
       }
-      if (getword_multisep(val1,sizeof(val1),&gwarea,'\0')<0){
+      if (getword(val1,sizeof(val1),&gwarea,'\0')<0){
          printf("SARG: Maybe you have a broken date range definition.\n");
          exit(1);
       }
-      getword_start(&gwarea,per_hour);
-      if (getword_multisep(val3,sizeof(val3),&gwarea,'-')<0){
-         printf("SARG: Maybe you have a broken date range definition.\n");
-         exit(1);
-      }
-      sprintf(val4,"%s/sarg-%s_%s-%s_%s.log",ParsedOutputLog,val2,val3,val1,gwarea.current);
-      rename(arq_log,val4);
-      strcpy(arq_log,val4);
-
-      if(strcmp(ParsedOutputLogCompress,"nocompress") != 0) {
-         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);
-            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));
+      } else {
+         strcpy(arq_log,val4);
+
+         if(strcmp(ParsedOutputLogCompress,"nocompress") != 0 && ParsedOutputLogCompress[0] != '\0') {
+            /*
+            No double quotes around ParsedOutputLogCompress because it may contain command line options. If double quotes are
+            necessary around the command name, put them in the configuration file.
+            */
+            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);
+               exit(1);
+            }
          }
       }
-
       if(debug)
          debuga("%s %s",text[123],arq_log);
    }
index 7d7d696fdf9095dadf7dcf014b5209c696e759f2..3f16aeca3f9f608d23220e1ac45380d4e1375adc 100644 (file)
--- a/sarg.conf
+++ b/sarg.conf
 #parsed_output_log none
 
 # TAG: parsed_output_log_compress /bin/gzip|/usr/bin/bzip2|nocompress
-#      sarg logs compress util
+#      Command to run to compress sarg parsed output log. It may contain
+#      options (such as -f to overwrite existing target file). The name of
+#      the file to compresse is provided at the end of this
+#      command line. Don't forget to quote things appropriately.
 #
 #parsed_output_log_compress /bin/gzip