]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Ported r159 from branches/v2_2_6_1 (sarg-date format change)
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Mon, 14 Dec 2009 09:19:18 +0000 (09:19 +0000)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Mon, 14 Dec 2009 09:19:18 +0000 (09:19 +0000)
ChangeLog
index.c
util.c

index b4bcb722bb7bf6fff6cfb3b9c1ccf8d8d0e69faf..4d1842ed407d2fbeecca501bcd35c58234c318a3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -6,7 +6,7 @@ Dec-03-2009 Version 2.2.7
                - Input log file type detection partly rewritten to clearly distinguish which type is processed where.
                - Read the input log file from standard input if log file name is -.
 
-Dec-09-2009 Version 2.2.6.1
+Dec-14-2009 Version 2.2.6.1
                - Remove unecessary dependency on off_t.
                - Configuration doesn't fail if rlim_t is not available.
                - Test for the availability of -Werror=implicit-function-declaration and -Werror=format flags in gcc (thanks to Murilo Moreira de Oliveira and pjetko).
@@ -15,6 +15,8 @@ Dec-09-2009 Version 2.2.6.1
                - Test for the availability of -Werror=format-security in gcc (thanks to Maxim Britov).
                - Test the existence of bzero with autoconf and don't redefine it (tkanks to Maxim Britov).
                - Remove warnings if libgd is not available.
+               - The date stored in sarg-date is now stored in a more machine readable form (thanks to rcastanheira for pointing this out).
+               - The date read from sarg-date was not properly parsed and would produce a wrongly sorted index accross a year change (thanks to rcastanheira for pointing this out).
 
 Oct-14-2009 Version 2.2.6
                - Protection against buffer overflows in getword and friends and report the origin of the error instead of always blaming access.log.
diff --git a/index.c b/index.c
index f42409314c9e359031d74842da9bad72f4114f77..3e756d21f1f23155eb16278515d8f5935dbdb532 100644 (file)
--- a/index.c
+++ b/index.c
@@ -47,12 +47,13 @@ void make_index(void)
    char tbytes[20];
    char media[20];
    char ftime[128];
-   char day[16], mon[16], year[6], hour[10];
+   char day[16], mon[16], year[40], hour[10];
    char h[3], m[3], s[3];
    int cstatus;
    char y1[5], y2[5];
    char d1[3], d2[3];
    char m1[4], m2[4];
+   int iyear, imonth, iday, ihour, iminute, isecond;
 
    if(LastLog[0] != '\0') mklastlog(outdir);
 
@@ -205,42 +206,51 @@ void make_index(void)
          obtdate(outdir,direntp->d_name,data);
          obtuser(outdir,direntp->d_name,tuser);
          obttotal(outdir,direntp->d_name,tbytes,tuser,media);
-         strcpy(html,data);
-         if (getword_multisep(mon,sizeof(mon),html,' ')<0) {
-            printf("SARG: Maybe you have a broken week day in your %s%s/sarg-date file.\n",outdir,direntp->d_name);
-            exit(1);
-         }
-         if (getword_multisep(mon,sizeof(mon),html,' ')<0) {
-            printf("SARG: Maybe you have a broken month in your %s%s/sarg-date file.\n",outdir,direntp->d_name);
-            exit(1);
-         }
-         if (getword_multisep(day,sizeof(day),html,' ')<0) {
-            printf("SARG: Maybe you have a broken day in your %s%s/sarg-date file.\n",outdir,direntp->d_name);
-            exit(1);
-         }
-         if (getword_multisep(hour,sizeof(hour),html,' ')<0) {
-            printf("SARG: Maybe you have a broken time in your %s%s/sarg-date file.\n",outdir,direntp->d_name);
-            exit(1);
-         }
-         if (getword_multisep(year,sizeof(year),html,' ')<0) {
-            printf("SARG: Maybe you have a broken year in your %s%s/sarg-date file.\n",outdir,direntp->d_name);
-            exit(1);
-         }
-         strcpy(html,hour);
-         if (getword_multisep(h,sizeof(h),html,':')<0) {
-            printf("SARG: Maybe you have a broken hour in your %s%s/sarg-date file.\n",outdir,direntp->d_name);
-            exit(1);
-         }
-         if (getword_multisep(m,sizeof(m),html,':')<0) {
-            printf("SARG: Maybe you have a broken minute in your %s%s/sarg-date file.\n",outdir,direntp->d_name);
-            exit(1);
-         }
-         if (getword_multisep(s,sizeof(s),html,0)<0) {
-            printf("SARG: Maybe you have a broken second in your %s%s/sarg-date file.\n",outdir,direntp->d_name);
-            exit(1);
+         if (sscanf(data,"%d-%d-%d %d:%d:%d",&iyear,&imonth,&iday,&ihour,&iminute,&isecond)==6) {
+            fprintf(fp_tmp,"%04d%02d%02d%02d%02d%02d;%s;%s;%s;%s;%s;%s\n",iyear,imonth,iday,ihour,iminute,isecond, direntp->d_name, data, tuser, tbytes, media,newname);
+         } else {
+            /*
+            Old code to parse a date stored by sarg before 2.2.6.1 in the sarg-date file of each report directory.
+            */
+            strcpy(html,data);
+            if (getword_multisep(mon,sizeof(mon),html,' ')<0) {
+               printf("SARG: Maybe you have a broken week day in your %s%s/sarg-date file.\n",outdir,direntp->d_name);
+               exit(1);
+            }
+            if (getword_multisep(mon,sizeof(mon),html,' ')<0) {
+               printf("SARG: Maybe you have a broken month in your %s%s/sarg-date file.\n",outdir,direntp->d_name);
+               exit(1);
+            }
+            if (getword_multisep(day,sizeof(day),html,' ')<0) {
+               printf("SARG: Maybe you have a broken day in your %s%s/sarg-date file.\n",outdir,direntp->d_name);
+               exit(1);
+            }
+            if (getword_multisep(hour,sizeof(hour),html,' ')<0) {
+               printf("SARG: Maybe you have a broken time in your %s%s/sarg-date file.\n",outdir,direntp->d_name);
+               exit(1);
+            }
+            do {
+               if (getword_multisep(year,sizeof(year),html,' ')<0) {
+                  printf("SARG: Maybe you have a broken year in your %s%s/sarg-date file.\n",outdir,direntp->d_name);
+                  exit(1);
+               }
+            } while (year[0] && !isdigit(year[0])); //skip time zone information with spaces until the year is found
+            strcpy(html,hour);
+            if (getword_multisep(h,sizeof(h),html,':')<0) {
+               printf("SARG: Maybe you have a broken hour in your %s%s/sarg-date file.\n",outdir,direntp->d_name);
+               exit(1);
+            }
+            if (getword_multisep(m,sizeof(m),html,':')<0) {
+               printf("SARG: Maybe you have a broken minute in your %s%s/sarg-date file.\n",outdir,direntp->d_name);
+               exit(1);
+            }
+            if (getword_multisep(s,sizeof(s),html,0)<0) {
+               printf("SARG: Maybe you have a broken second in your %s%s/sarg-date file.\n",outdir,direntp->d_name);
+               exit(1);
+            }
+            buildymd(day,mon,year,ftime);
+            fprintf(fp_tmp,"%s%s%s%s;%s;%s;%s;%s;%s;%s\n",ftime, h, m, s, direntp->d_name, data, tuser, tbytes, media,newname);
          }
-         buildymd(day,mon,year,ftime);
-         fprintf(fp_tmp,"%s%s%s%s;%s;%s;%s;%s;%s;%s\n",ftime, h, m, s, direntp->d_name, data, tuser, tbytes, media,newname);
          continue;
       }
    }
diff --git a/util.c b/util.c
index 88ed598df4c6e2e43e9dc50efe9c6a8256c0b1c6..5e1d1a2fa83a9e73386f8f61cb2ba50d75c2c2ad 100644 (file)
--- a/util.c
+++ b/util.c
@@ -905,7 +905,8 @@ void vrfydir(const char *dir, const char *per1, const char *addr, const char *si
       exit(1);
    }
    time(&curtime);
-   strftime(wdir,sizeof(wdir),"%a %b %d %H:%M:%S %Z %Y",localtime(&curtime));
+   //strftime(wdir,sizeof(wdir),"%a %b %d %H:%M:%S %Z %Y",localtime(&curtime));
+   strftime(wdir,sizeof(wdir),"%Y-%m-%d %H:%M:%S",localtime(&curtime));
    fprintf(fp_ou,"%s\n",wdir);
    fclose(fp_ou);