From a1de61fe891cb31174ea715c823f4f6fefd4b031 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fr=C3=A9d=C3=A9ric=20Marchal?= Date: Fri, 18 Dec 2009 13:45:28 +0000 Subject: [PATCH] Ported r167 from branches/v2_2_6_1 (several changes). Use LC_TIME to format the dates and times according to the selected locale. --- CMakeLists.txt | 15 +++++---- ChangeLog | 6 ++-- configure | 5 +-- configure.in | 4 +-- documentation/util.txt | 3 +- getconf.c | 2 +- grepday.c | 10 +++--- include/conf.h | 3 ++ include/config.h.in | 1 + include/defs.h | 2 +- include/info.h | 2 +- index.c | 5 +-- language.c | 3 +- log.c | 4 +++ report.c | 2 +- useragent.c | 2 +- util.c | 76 +++++++++++++++++++++--------------------- 17 files changed, 80 insertions(+), 65 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e2291d0..cce2a98 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ PROJECT(sarg C) SET(sarg_VERSION 2) SET(sarg_REVISION 2) SET(sarg_BUILD "7rc1") -SET(sarg_BUILDDATE "Dec-10-2009") +SET(sarg_BUILDDATE "Dec-18-2009") INCLUDE(AddFileDependencies) INCLUDE(CheckIncludeFile) @@ -97,6 +97,7 @@ CHECK_INCLUDE_FILE(sys/wait.h HAVE_SYS_WAIT_H) CHECK_INCLUDE_FILE(stdarg.h HAVE_STDARG_H) CHECK_INCLUDE_FILE(inttypes.h HAVE_INTTYPES_H) CHECK_INCLUDE_FILE(limits.h HAVE_LIMITS_H) +CHECK_INCLUDE_FILE(locale.h HAVE_LOCALE_H) CHECK_FUNCTION_EXISTS(bzero HAVE_BZERO) @@ -108,10 +109,10 @@ IF(HAVE_GD_H) CHECK_INCLUDE_FILE(gdfonts.h HAVE_GDFONTS_H) CHECK_INCLUDE_FILE(gdfontmb.h HAVE_GDFONTMB_H) CHECK_INCLUDE_FILE(gdfontg.h HAVE_GDFONTG_H) - FIND_LIBRARY(GD_LIBRARY NAMES gd DOC "The GD library") + FIND_LIBRARY(GD_LIBRARY NAMES gd bgd DOC "The GD library") IF(GD_LIBRARY) #CHECK_LIBRARY_EXISTS(gd gdImagePng "." HAVE_GD) - TARGET_LINK_LIBRARIES(sarg gd) + TARGET_LINK_LIBRARIES(sarg ${GD_LIBRARY}) SET(HAVE_GD GD_LIBRARY CACHE PATH DOC "True IF GD was found") SET(HAVE_GD CACHE BOOL DOC "True IF must use GD") ENDIF(GD_LIBRARY) @@ -265,9 +266,9 @@ INSTALL(TARGETS sarg DESTINATION "${BINDIR}") INSTALL(FILES sarg.conf DESTINATION "${SYSCONFDIR}" RENAME sarg.conf.exemple) INSTALL(FILES exclude_codes user_limit_block css.tpl DESTINATION "${SYSCONFDIR}") INSTALL(FILES sarg.1 DESTINATION "${MANDIR}") -INSTALL(DIRECTORY languages/ DESTINATION "${LANGDIR}" PATTERN "CVS" EXCLUDE) -INSTALL(DIRECTORY images/ DESTINATION "${IMAGEDIR}" PATTERN "CVS" EXCLUDE) -INSTALL(DIRECTORY fonts/ DESTINATION "${FONTDIR}" FILES_MATCHING PATTERN "*.ttf" PATTERN "CVS" EXCLUDE) +INSTALL(DIRECTORY languages/ DESTINATION "${LANGDIR}" PATTERN ".svn" EXCLUDE) +INSTALL(DIRECTORY images/ DESTINATION "${IMAGEDIR}" PATTERN ".svn" EXCLUDE) +INSTALL(DIRECTORY fonts/ DESTINATION "${FONTDIR}" FILES_MATCHING PATTERN "*.ttf" PATTERN ".svn" EXCLUDE) # Package creation SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Squid Analysis Report Generator") @@ -276,5 +277,5 @@ SET(CPACK_PACKAGE_VERSION_MINOR "${sarg_REVISION}") SET(CPACK_PACKAGE_VERSION_PATCH "${sarg_BUILD}") SET(CPACK_GENERATOR TGZ) SET(CPACK_SOURCE_GENERATOR TGZ) -SET(CPACK_SOURCE_IGNORE_FILES "/CVS/" "/debian/" "/html/" "Makefile$" "config\\\\.log$" "config\\\\.status$" ".*~$" "\\\\.o$") +SET(CPACK_SOURCE_IGNORE_FILES "/.svn/" "/debian/" "/html/" "Makefile$" "config\\\\.log$" "config\\\\.status$" ".*~$" "\\\\.o$") INCLUDE(CPack) diff --git a/ChangeLog b/ChangeLog index 4c6bdc1..b16d334 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,13 +1,14 @@ SARG ChangeLog -Dec-15-2009 Version 2.2.7 +Dec-18-2009 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. - Read the input log file from standard input if log file name is -. - Use string pointers in getword instead of copying the strings over and over. + - Use LC_TIME to format some dates and times in the report according to the selected locale. -Dec-14-2009 Version 2.2.6.1 +Dec-17-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). @@ -18,6 +19,7 @@ Dec-14-2009 Version 2.2.6.1 - 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). + - my_mkdir changed to avoid the use of getword, be simpler and, maybe, work reliably on windows. 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/configure b/configure index 9441291..8170751 100755 --- a/configure +++ b/configure @@ -4769,12 +4769,13 @@ done + for ac_header in stdio.h stdlib.h string.h strings.h sys/time.h time.h unistd.h sys/dirent.h \ dirent.h sys/socket.h netdb.h arpa/inet.h sys/types.h netinet/in.h sys/stat.h \ ctype.h gd.h gdfontl.h gdfontt.h gdfonts.h gdfontmb.h gdfontg.h iconv.h \ - errno.h sys/resource.h sys/wait.h stdarg.h inttypes.h limits.h + errno.h sys/resource.h sys/wait.h stdarg.h inttypes.h limits.h locale.h do as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh` if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then @@ -5518,7 +5519,7 @@ cat >>conftest.$ac_ext <<_ACEOF int main () { -FILE *f = fopen64 ("/tmp/foo","r"); +FILE *f = fopen64 ("/tmp/foo","r");fclose(f); ; return 0; } diff --git a/configure.in b/configure.in index 7176328..118ec8f 100644 --- a/configure.in +++ b/configure.in @@ -65,7 +65,7 @@ fi AC_CHECK_HEADERS(stdio.h stdlib.h string.h strings.h sys/time.h time.h unistd.h sys/dirent.h \ dirent.h sys/socket.h netdb.h arpa/inet.h sys/types.h netinet/in.h sys/stat.h \ ctype.h gd.h gdfontl.h gdfontt.h gdfonts.h gdfontmb.h gdfontg.h iconv.h \ - errno.h sys/resource.h sys/wait.h stdarg.h inttypes.h limits.h) + errno.h sys/resource.h sys/wait.h stdarg.h inttypes.h limits.h locale.h) AC_CHECK_LIB(gd, gdImagePng,LIBS="-lgd ${LIBS}"; HAVE_GD="yes", HAVE_GD="") @@ -79,7 +79,7 @@ AC_SYS_LARGEFILE # needs to be defined for it AC_MSG_CHECKING([for fopen64]) AC_CACHE_VAL(bu_cv_have_fopen64, -[AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include ]], [[FILE *f = fopen64 ("/tmp/foo","r");]])],[bu_cv_have_fopen64=yes],[saved_CFLAGS=$CFLAGS +[AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include ]], [[FILE *f = fopen64 ("/tmp/foo","r");fclose(f);]])],[bu_cv_have_fopen64=yes],[saved_CFLAGS=$CFLAGS CFLAGS="$CFLAGS -D_LARGEFILE64_SOURCE" AC_TRY_LINK([#include ], [FILE *f = fopen64 ("/tmp/foo","r");], bu_cv_have_fopen64="need -D_LARGEFILE64_SOURCE", diff --git a/documentation/util.txt b/documentation/util.txt index 9de854b..b52ee5d 100644 --- a/documentation/util.txt +++ b/documentation/util.txt @@ -349,7 +349,7 @@ bytes long. -/*! \fn void formatdate(char *date,int date_size,int year,int month,int day,int hour,int minute,int second) +/*! \fn void formatdate(char *date,int date_size,int year,int month,int day,int hour,int minute,int second,int dst) Format a date to display it in the report. \param date The buffer to write the formatted date into. @@ -360,6 +360,7 @@ Format a date to display it in the report. \param hour The hour to format. \param minute The minute to format. \param second The second to format. +\param dst A positive number if the daylight saving is active, zero if it is not active and a negative number if it is unknown. */ diff --git a/getconf.c b/getconf.c index 361e4e8..63ae654 100644 --- a/getconf.c +++ b/getconf.c @@ -1,6 +1,6 @@ /* * AUTHOR: Pedro Lineu Orso pedro.orso@gmail.com - * 1998, 2008 + * 1998, 2009 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net * * SARG donations: diff --git a/grepday.c b/grepday.c index e200278..9cd87de 100644 --- a/grepday.c +++ b/grepday.c @@ -1,6 +1,6 @@ /* * AUTHOR: Pedro Lineu Orso pedro.orso@gmail.com - * 1998, 2008 + * 1998, 2009 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net * * SARG donations: @@ -26,7 +26,7 @@ #include "include/conf.h" #include "include/defs.h" -#if defined(HAVE_GD) && defined(HAVE_ICONV_H) && defined(gdFTEX_Unicode) +#if defined(HAVE_GD) static int blue; static int white; @@ -41,6 +41,7 @@ static int black; //static char *font1 = FONTDIR"/FreeSans.ttf"; static char *font1 = FONTDIR"/DejaVuSans.ttf"; +#if defined(HAVE_ICONV_H) && defined(gdFTEX_Unicode) #include #define SARGgdImageStringFT I18NgdImageStringFT @@ -75,7 +76,6 @@ static char * I18NgdImageStringFT (gdImage * im, int *brect, int fg, char *fontl #define SARGgdImageStringFT gdImageStringFT #endif -#ifdef HAVE_GD static void bar(int x1,long long int n) { gdPoint points[4]; @@ -229,7 +229,7 @@ static void bar(int x1,long long int n) return; } -#endif +#endif //HAVE_GD void greport_day(const char *user) { @@ -482,7 +482,7 @@ void greport_day(const char *user) unlink(wdirname); unlink(tmp5); -#endif +#endif //HAVE_GD return; } diff --git a/include/conf.h b/include/conf.h index 3f98b67..32fddc3 100755 --- a/include/conf.h +++ b/include/conf.h @@ -94,6 +94,9 @@ gdPoint points[4]; #ifdef HAVE_WINSOCK_H #include #endif +#ifdef HAVE_LOCALE_H +#include +#endif #if defined(HAVE_FOPEN64) #define _FILE_OFFSET_BITS 64 diff --git a/include/config.h.in b/include/config.h.in index bc502ed..b86399c 100644 --- a/include/config.h.in +++ b/include/config.h.in @@ -40,6 +40,7 @@ #cmakedefine HAVE_LIMITS_H #cmakedefine HAVE_WINDOWS_H #cmakedefine HAVE_WINSOCK_H +#cmakedefine HAVE_LOCALE_H #cmakedefine IBERTY_LIB diff --git a/include/defs.h b/include/defs.h index c9d5498..96afc89 100755 --- a/include/defs.h +++ b/include/defs.h @@ -153,7 +153,7 @@ void url_module(const char *url, char *w2); 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); +void formatdate(char *date,int date_size,int year,int month,int day,int hour,int minute,int second,int dst); void obtuser(const char *dirname, const char *name, char *tuser); void obttotal(const char *dirname, const char *name, char *tbytes, char *tuser, char *media); void version(void); diff --git a/include/info.h b/include/info.h index 1667894..c26ef74 100755 --- a/include/info.h +++ b/include/info.h @@ -1,3 +1,3 @@ -#define VERSION PACKAGE_VERSION" Dec-10-2009" +#define VERSION PACKAGE_VERSION" Dec-18-2009" #define PGM PACKAGE_NAME #define URL "http://sarg.sourceforge.net" diff --git a/index.c b/index.c index d8f9939..8e0277a 100644 --- a/index.c +++ b/index.c @@ -55,6 +55,7 @@ void make_index(void) char d1[3], d2[3]; char m1[4], m2[4]; struct getwordstruct gwarea; + int iyear, imonth, iday, ihour, iminute, isecond, idst; if(LastLog[0] != '\0') mklastlog(outdir); @@ -203,8 +204,8 @@ void make_index(void) obtdate(outdir,direntp->d_name,data); obtuser(outdir,direntp->d_name,tuser); obttotal(outdir,direntp->d_name,tbytes,tuser,media); - if (sscanf(data,"%d-%d-%d %d:%d:%d",&iyear,&imonth,&iday,&ihour,&iminute,&isecond)==6) { - formatdate(data,sizeof(data),iyear,imonth,iday,ihour,iminute,isecond); + if (sscanf(data,"%d-%d-%d %d:%d:%d %d",&iyear,&imonth,&iday,&ihour,&iminute,&isecond,&idst)==7) { + formatdate(data,sizeof(data),iyear,imonth,iday,ihour,iminute,isecond,idst); 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 { /* diff --git a/language.c b/language.c index e01ceac..0fee78a 100644 --- a/language.c +++ b/language.c @@ -1,6 +1,6 @@ /* * AUTHOR: Pedro Lineu Orso pedro.orso@gmail.com - * 1998, 2008 + * 1998, 2009 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net * * SARG donations: @@ -48,6 +48,7 @@ void language_load(const char *language) while(record=sizeof(w0)) { + fprintf(stderr,"SARG: directory name too long %s\n",name); exit(1); } - strcat(w2,w1); - if(access(w2, R_OK) != 0) { - if(mkdir(w2,0755)) { - fprintf(stderr,"SARG: mkdir %s %s\n",w2,strerror(errno)); - fprintf(stderr,"SARG: process aborted.\n"); - exit(1); + if (chars>0 && name[i] == '/') { + w0[i] = '\0'; + if(access(w0, R_OK) != 0) { + if(mkdir(w0,0755)) { + fprintf(stderr,"SARG: mkdir %s %s\n",w0,strerror(errno)); + fprintf(stderr,"SARG: process aborted.\n"); + exit(1); + } } } - strcat(w2,"/"); + if (name[i] != '/') chars++; + w0[i] = name[i]; } - strcat(w2,gwarea.current); - if(access(w2, R_OK) != 0) { - if(mkdir(w2,0755)) { - fprintf(stderr,"SARG: mkdir %s %s\n",w2,strerror(errno)); + + if(access(name, R_OK) != 0) { + if(mkdir(name,0755)) { + fprintf(stderr,"SARG: mkdir %s %s\n",name,strerror(errno)); fprintf(stderr,"SARG: process aborted.\n"); exit(1); } @@ -646,20 +642,20 @@ 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) +void formatdate(char *date,int date_size,int year,int month,int day,int hour,int minute,int second,int dst) { struct tm ltm; - time_t curtime; memset(<m,0,sizeof(ltm)); - ltm.tm_year=year-1900; - ltm.tm_mon=month-1; - ltm.tm_mday=day; - ltm.tm_hour=hour; - ltm.tm_min=minute; - ltm.tm_sec=second; - curtime=mktime(<m); //tm cannot be used directly because we need the date normalization made by mktime. - strftime(date,date_size,"%a %b %d %H:%M:%S %Z %Y",localtime(&curtime)); + if (year>=1900) ltm.tm_year=year-1900; + if (month>=1 && month<=12) ltm.tm_mon=month-1; + if (day>=1 && day<=31) ltm.tm_mday=day; + if (hour>=0 && hour<24) ltm.tm_hour=hour; + if (minute>=0 && minute<60) ltm.tm_min=minute; + if (second>=0 && second<60) ltm.tm_sec=second; + ltm.tm_isdst=dst; + //strftime(date,date_size,"%a %b %d %H:%M:%S %Z %Y",<m); + strftime(date,date_size,"%c",<m); } @@ -786,6 +782,7 @@ void vrfydir(const char *dir, const char *per1, const char *addr, const char *si char d1[3], d2[3]; char m1[4], m2[4]; time_t curtime; + struct tm *loctm; int cstatus; if(strcmp(IndexTree,"date") == 0) { @@ -932,8 +929,9 @@ void vrfydir(const char *dir, const char *per1, const char *addr, const char *si } time(&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); + loctm=localtime(&curtime); + strftime(wdir,sizeof(wdir),"%Y-%m-%d %H:%M:%S",loctm); + fprintf(fp_ou,"%s %d\n",wdir,loctm->tm_isdst); fclose(fp_ou); strcpy(per2,IMAGEDIR); @@ -1001,13 +999,15 @@ void zdate(char *ftime,int ftimesize, const char *DateFormat) t = time(NULL); local = localtime(&t); + /* if(strcmp(DateFormat,"u") == 0) strftime(ftime, ftimesize, "%b/%d/%Y %H:%M", local); if(strcmp(DateFormat,"e") == 0) strftime(ftime, ftimesize, "%d/%b/%Y-%H:%M", local); if(strcmp(DateFormat,"w") == 0) strftime(ftime, ftimesize, "%V-%H-%M", local); - + */ + strftime(ftime, ftimesize, "%x %X", local); return; } -- 2.47.2