From fd4dbc548fe201587cef0537582a7aa0ca268113 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fr=C3=A9d=C3=A9ric=20Marchal?= Date: Mon, 14 Dec 2009 09:19:18 +0000 Subject: [PATCH] Ported r159 from branches/v2_2_6_1 (sarg-date format change) --- ChangeLog | 4 ++- index.c | 82 +++++++++++++++++++++++++++++++------------------------ util.c | 3 +- 3 files changed, 51 insertions(+), 38 deletions(-) diff --git a/ChangeLog b/ChangeLog index b4bcb72..4d1842e 100644 --- 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 f424093..3e756d2 100644 --- 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 88ed598..5e1d1a2 100644 --- 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); -- 2.47.2