From dcb54d067b04c0d0d40c3a97836b76ab5579b9ff Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fr=C3=A9d=C3=A9ric=20Marchal?= Date: Thu, 10 Dec 2009 12:29:17 +0000 Subject: [PATCH] Ported r150 from branches/v2_2_6_1 (useragent report statistics) --- ChangeLog | 4 +++- configure | 46 +++++++++++++++++++++++++++++++++++++++++++++- configure.in | 11 ++++++++++- useragent.c | 32 ++++++++++++++++---------------- 4 files changed, 74 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index e3417d6..b3e02fa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -9,8 +9,10 @@ Dec-03-2009 Version 2.2.7 Dec-09-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=xxx flags in gcc. + - Test for the availability of -Werror=implicit-function-declaration and -Werror=format flags in gcc (thanks to Murilo Moreira de Oliveira and pjetko). - Fix sort delimiter when reading useragent log (thanks to Maxim Britov). + - Fix user agent report font size and statistics on user agent. + - Test for the availability of -Werror=format-security in gcc (thanks to Maxim Britov). 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 a24ce98..8659a5d 100755 --- a/configure +++ b/configure @@ -6126,7 +6126,51 @@ echo "using $IMAGEDIR as the directory of the images" if test "${enable_extraprotection+set}" = set; then enableval=$enable_extraprotection; if test "$enableval"; then - CFLAGS="${CFLAGS} -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=2 -Werror -Wextra -Wno-sign-compare -Wno-unused-parameter" + CFLAGS="${CFLAGS} -fstack-protector -D_FORTIFY_SOURCE=2 -Werror" + + { echo "$as_me:$LINENO: checking for format security flag in gcc" >&5 +echo $ECHO_N "checking for format security flag in gcc... $ECHO_C" >&6; } + saved_CFLAGS="${CFLAGS}" + CFLAGS="${CFLAGS} -Werror=format-security" + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + have_format_security="yes" +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + have_format_security="no" +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + { echo "$as_me:$LINENO: result: have_format_security" >&5 +echo "${ECHO_T}have_format_security" >&6; } + if test "$have_format_security" == "no" ; then + CFLAGS="${saved_CFLAGS}" + fi fi fi diff --git a/configure.in b/configure.in index c779b31..06f2ac8 100644 --- a/configure.in +++ b/configure.in @@ -163,7 +163,16 @@ AC_ARG_ENABLE(extraprotection, Enable compile and runtime extra protections ], [ if test "$enableval"; then - CFLAGS="${CFLAGS} -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=2 -Werror -Wextra -Wno-sign-compare -Wno-unused-parameter" + CFLAGS="${CFLAGS} -fstack-protector -D_FORTIFY_SOURCE=2 -Werror" + + AC_MSG_CHECKING([for format security flag in gcc]) + saved_CFLAGS="${CFLAGS}" + CFLAGS="${CFLAGS} -Werror=format-security" + AC_COMPILE_IFELSE([AC_LANG_SOURCE([])],[have_format_security="yes"],[have_format_security="no"]) + AC_MSG_RESULT(have_format_security) + if test "$have_format_security" == "no" ; then + CFLAGS="${saved_CFLAGS}" + fi fi ]) diff --git a/useragent.c b/useragent.c index 4bb6456..c4d1ef8 100644 --- a/useragent.c +++ b/useragent.c @@ -37,7 +37,7 @@ void useragent(void) char agent_old[MAXLEN]="$#%0a3bc6"; char hfile[MAXLEN]; char idate[MAXLEN], fdate[MAXLEN]; - int agentot=0, agentot2=0, agentdif=0, cont=0; + int agentot=0, agentot2=0, agentdif=0, cont=0, nagent; unsigned long totregsl=0; int cstatus; char ftime[128]; @@ -98,7 +98,7 @@ void useragent(void) if(strlen(user) == 0) strcpy(user,ip); - fprintf(fp_ou,"%s\t%s\t%s\t%s\n",ip,data,agent,user); + fprintf(fp_ou,"%s\t%s\t%s\n",ip,agent,user); user[0]='\0'; } @@ -111,15 +111,11 @@ void useragent(void) fclose(fp_in); fclose(fp_ou); - if (fp_ht) { - fclose(fp_ht); - } - if(debug) { debuga("%s: %s",text[54],tmp2); } - sprintf(csort,"sort -n -t \"\t\" -k 4,4 -k 3,3 -k 2,2 -k 1,1 -o \"%s\" \"%s\"",tmp2,tmp3); + sprintf(csort,"sort -n -t \"\t\" -k 3,3 -k 2,2 -k 1,1 -o \"%s\" \"%s\"",tmp2,tmp3); cstatus=system(csort); if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) { fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus)); @@ -184,7 +180,7 @@ void useragent(void) } else strcpy(ip,namebefore); } - if (getword(data,sizeof(data),buf,'\t')<0 || getword(agent,sizeof(agent),buf,'\t')<0 || + if (getword(agent,sizeof(agent),buf,'\t')<0 || getword(user,sizeof(user),buf,'\t')<0) { printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp2); exit(1); @@ -206,7 +202,7 @@ void useragent(void) fclose(fp_in); fclose(fp_ou); - sprintf(csort,"sort -n -t \"\t\" -k 3,3 -o \"%s\" \"%s\"",tmp3,tmp2); + sprintf(csort,"sort -t \"\t\" -k 2,2 -o \"%s\" \"%s\"",tmp3,tmp2); cstatus=system(csort); if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) { fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus)); @@ -227,9 +223,10 @@ void useragent(void) } agent_old[0]='\0'; + cont=0; while(fgets(buf,sizeof(buf),fp_in)!=NULL) { - if (getword(ip,sizeof(ip),buf,'\t')<0 || getword(data,sizeof(data),buf,'\t')<0 || + if (getword(ip,sizeof(ip),buf,'\t')<0 || getword(agent,sizeof(agent),buf,'\t')<0) { printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp); exit(1); @@ -240,15 +237,14 @@ void useragent(void) strcpy(agent_old,agent); } - agentot++; - if(strcmp(agent,agent_old) != 0) { agentdif++; fprintf(fp_ou,"%06d %s\n",agentot,agent_old); strcpy(agent_old,agent); agentot2+=agentot; - agentot=1; + agentot=0; } + agentot++; } agentdif++; fprintf(fp_ou,"%06d %s\n",agentot,agent); @@ -284,16 +280,20 @@ void useragent(void) fputs("
\n",fp_ht); fprintf(fp_ht,"\n",HeaderBgColor,HeaderColor,text[106],HeaderBgColor,HeaderColor,text[107],HeaderBgColor,HeaderColor); + perc=0.; while(fgets(buf,sizeof(buf),fp_in)!=NULL) { fixendofline(buf); if (getword(tagent,sizeof(tagent),buf,' ')<0) { printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp); exit(1); } - perc=atoi(tagent) * 100; - perc=perc / agentot2; + nagent=atoi(tagent); + if(agentot2>0) { + perc=nagent * 100; + perc=perc / agentot2; + } - fprintf(fp_ht,"\n",TxBgColor,buf,TxBgColor,atoi(tagent),TxBgColor,perc); + fprintf(fp_ht,"\n",TxBgColor,buf,TxBgColor,nagent,TxBgColor,perc); } fputs("
%s%s%%
%s%d%3.2f
%s%d%3.2f
\n",fp_ht); -- 2.47.2