From: Frederic Marchal Date: Sun, 1 Nov 2015 16:11:32 +0000 (+0100) Subject: The reported user agent report date was wrong X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ba3b652e915475d4e3ff5b9fdcf884309aac52b1;p=thirdparty%2Fsarg.git The reported user agent report date was wrong At the top of the user agent report, the period covered by the report was wrong when the entries were coming from an extended log or when several useragent.log files were provided with the useragent option in sarg.conf. Thanks to Evgeniy Yakushev for reporting this bug. --- diff --git a/include/defs.h b/include/defs.h index 26a1c4c..17d2ab3 100644 --- a/include/defs.h +++ b/include/defs.h @@ -337,7 +337,7 @@ void usage(const char *prog); // useragent.c FILE *UserAgent_Open(void); -void UserAgent_Write(FILE *fp,const char *Ip,const char *User,const char *Agent); +void UserAgent_Write(FILE *fp,const struct tm *Time,const char *Ip,const char *User,const char *Agent); void UserAgent_Readlog(void); void UserAgent(void); @@ -420,7 +420,7 @@ char *strlow(char *string); char *strup(char *string); int month2num(const char *month); int builddia(int day, int month, int year); -int compare_date(struct tm *date1,struct tm *date2); +int compare_date(const struct tm *date1,const struct tm *date2); bool IsTreeFileDirName(const char *Name); bool IsTreeYearFileName(const char *Name); bool IsTreeMonthFileName(const char *Name); diff --git a/readlog.c b/readlog.c index 3805de0..1b66c49 100644 --- a/readlog.c +++ b/readlog.c @@ -719,7 +719,7 @@ static void ReadOneLogFile(struct ReadLogDataStruct *Filter,const char *arq) { if (!UseragentLog) UseragentLog=UserAgent_Open(); - UserAgent_Write(UseragentLog,log_entry.Ip,log_entry.User,log_entry.UserAgent); + UserAgent_Write(UseragentLog,&log_entry.EntryTime,log_entry.Ip,log_entry.User,log_entry.UserAgent); } if (log_line.current_format!=&ReadSargLog) { diff --git a/useragent.c b/useragent.c index 1193420..c95c2fd 100644 --- a/useragent.c +++ b/useragent.c @@ -71,9 +71,13 @@ FILE *UserAgent_Open(void) * \param User The user name. * \param Agent The user agent string. */ -void UserAgent_Write(FILE *fp,const char *Ip,const char *User,const char *Agent) +void UserAgent_Write(FILE *fp,const struct tm *Time,const char *Ip,const char *User,const char *Agent) { if (fp) { + if (useragent_count==0 || compare_date(&UserAgentStartDate,Time)>0) + memcpy(&UserAgentStartDate,Time,sizeof(UserAgentStartDate)); + if (useragent_count==0 || compare_date(&UserAgentEndDate,Time)<0) + memcpy(&UserAgentEndDate,Time,sizeof(UserAgentEndDate)); fprintf(fp,"%s\t%s\t%s\n",Ip,Agent,User); useragent_count++; } @@ -150,10 +154,6 @@ void UserAgent_Readlog(void) logtime.tm_year=year-1900; logtime.tm_mon=month-1; logtime.tm_mday=day; - if (totregsl==1 || compare_date(&UserAgentStartDate,&logtime)>0) - memcpy(&UserAgentStartDate,&logtime,sizeof(logtime)); - if (compare_date(&UserAgentEndDate,&logtime)<0) - memcpy(&UserAgentEndDate,&logtime,sizeof(logtime)); if (getword_skip(MAXLEN,&gwarea,'"')<0 || getword(agent,sizeof(agent),&gwarea,'"')<0) { debuga(__FILE__,__LINE__,_("Invalid useragent in file \"%s\"\n"),FileName); exit(EXIT_FAILURE); @@ -172,7 +172,7 @@ void UserAgent_Readlog(void) strcpy(user,ip); } - UserAgent_Write(fp_ou,ip,user,agent); + UserAgent_Write(fp_ou,&logtime,ip,user,agent); } if (FileObject_Close(fp_log)==EOF) { diff --git a/util.c b/util.c index 0a48ffe..cdcbf16 100644 --- a/util.c +++ b/util.c @@ -507,7 +507,7 @@ Compare two dates. \retval 0 If date1==date2. \retval 1 if date1>date2. */ -int compare_date(struct tm *date1,struct tm *date2) +int compare_date(const struct tm *date1,const struct tm *date2) { if (date1->tm_yeartm_year) return(-1); if (date1->tm_year>date2->tm_year) return(1);