]> git.ipfire.org Git - thirdparty/sarg.git/blobdiff - log.c
The date range passed as argument is not restricted to the actual range covered by...
[thirdparty/sarg.git] / log.c
diff --git a/log.c b/log.c
index fc62647637500fc2d70469f4214fdd7c2a071b2d..34a7a8e8839477366e13f30524a3589647fde69c 100644 (file)
--- a/log.c
+++ b/log.c
@@ -335,6 +335,8 @@ int main(int argc,char *argv[])
    nocost=50000000;
    ndownload=0;
    squid24=false;
+   dfrom=0;
+   duntil=0;
 
    bzero(IncludeUsers, sizeof(IncludeUsers));
    bzero(ExcludeString, sizeof(ExcludeString));
@@ -363,14 +365,7 @@ int main(int argc,char *argv[])
          case 'd':
             strncpy(date,optarg,sizeof(date)-1);
             date[sizeof(date)-1]='\0';
-            getword_start(&gwarea,optarg);
-            if (getword(cdfrom,sizeof(cdfrom),&gwarea,'-')<0 || getword(cduntil,sizeof(cduntil),&gwarea,'\0')<0) {
-               printf(_("SARG: The date range requested on the command line by option -d is invalid.\n"));
-               exit(EXIT_FAILURE);
-            }
-            date_from(date, cdfrom, cduntil);
-            dfrom=atoi(cdfrom);
-            duntil=atoi(cduntil);
+            date_from(date, &dfrom, &duntil);
             break;
          case 'e':
             strcpy(email,optarg);
@@ -1490,6 +1485,9 @@ int main(int argc,char *argv[])
       }
    }
 
+   if (debug)
+      debuga(_("   Records read: %ld, written: %ld, excluded: %ld\n"),totregsl,totregsg,totregsx);
+
    longline_destroy(&line);
    if ( fp_Download_Unsort )
      fclose (fp_Download_Unsort);
@@ -1500,11 +1498,6 @@ int main(int argc,char *argv[])
       free(ufile);
    }
 
-   if (getperiod_buildtext(&period)<0) {
-      debuga(_("Failed to build the string representation of the date range\n"));
-      exit(EXIT_FAILURE);
-   }
-
    free_download();
    free_excludecodes();
    free_exclude();
@@ -1514,8 +1507,6 @@ int main(int argc,char *argv[])
 
       for (ilf=0 ; ilf<ILF_Last ; ilf++) totalcount+=ilf_count[ilf];
 
-      debuga(_("   Records read: %ld, written: %ld, excluded: %ld\n"),totregsl,totregsg,totregsx);
-
       if(ilf_count[ILF_Common]>0 && ilf_count[ILF_Squid]>0)
          debuga(_("Log with mixed records format (squid and common log)\n"));
 
@@ -1528,41 +1519,34 @@ int main(int argc,char *argv[])
       if(ilf_count[ILF_Sarg]>0)
          debuga(_("Sarg log format\n"));
 
-      if(totalcount==0) {
-         if(!totregsg) {
-            debuga(_("No records found\n"));
-            debuga(_("End\n"));
-         } else debuga(_("Log with invalid format\n"));
-         if(fp_denied)
-            fclose(fp_denied);
-         if(fp_authfail)
-            fclose(fp_authfail);
-         userinfo_free();
-         if(userfile)
-            free(userfile);
-         close_usertab();
-         unlink(denied_unsort);
-         unlink(authfail_unsort);
-         unlink(tmp3);
-         exit(EXIT_SUCCESS);
-      }
+      if(totalcount==0 && totregsg)
+         debuga(_("Log with invalid format\n"));
    }
 
    if(!totregsg){
       debuga(_("No records found\n"));
       debuga(_("End\n"));
-//      fclose(fp_ou);
-      if(fp_denied)
-         fclose(fp_denied);
-      if(fp_authfail)
-         fclose(fp_authfail);
+      if(fp_denied) fclose(fp_denied);
+      if(fp_authfail) fclose(fp_authfail);
       userinfo_free();
-      if(userfile)
-         free(userfile);
+      if(userfile) free(userfile);
       close_usertab();
       exit(EXIT_SUCCESS);
    }
 
+   if (date[0]!='\0') {
+      char date0[30], date1[30];
+
+      strftime(date0,sizeof(date0),"%d/%m/%Y",&period.start);
+      strftime(date1,sizeof(date1),"%d/%m/%Y",&period.end);
+      debuga(_("Period covered by log files: %s-%s\n"),date0,date1);
+      getperiod_fromrange(&period,dfrom,duntil);
+   }
+   if (getperiod_buildtext(&period)<0) {
+      debuga(_("Failed to build the string representation of the date range\n"));
+      exit(EXIT_FAILURE);
+   }
+
    if(debugz){
       debugaz("data",dia);
       debugaz("period",period.text);