From 3becf85c60d7ddb16c851ac99e60a730cbb83879 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fr=C3=A9d=C3=A9ric=20Marchal?= Date: Wed, 10 Feb 2010 15:45:47 +0000 Subject: [PATCH] Ported r242 to r245 from branches/v2_2_7 (custom graph font + a few bug fixes) --- CMakeLists.txt | 2 +- ChangeLog | 7 +++- Makefile.in | 28 ++++++++----- README | 2 +- configure.in | 18 ++++++--- getconf.c | 2 + grepday.c | 105 ++++++++++++++++++++++++------------------------- include/conf.h | 2 +- include/info.h | 2 +- log.c | 9 ++++- sarg.conf | 11 +++--- topuser.c | 2 +- 12 files changed, 107 insertions(+), 83 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2b7c8fd..518f8ef 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ PROJECT(sarg C) SET(sarg_VERSION 2) SET(sarg_REVISION "3rc1") SET(sarg_BUILD "") -SET(sarg_BUILDDATE "Feb-04-2010") +SET(sarg_BUILDDATE "Feb-10-2010") INCLUDE(AddFileDependencies) INCLUDE(CheckIncludeFile) diff --git a/ChangeLog b/ChangeLog index 4e23dec..37b2c03 100644 --- a/ChangeLog +++ b/ChangeLog @@ -10,7 +10,12 @@ Feb-09-2009 Version 2.3 - Link to external css file instead of including it verbatim in each HTML file (thanks to Maxim Britov). - Enable gettext configuration for autotools. -Feb-04-2010 Version 2.2.7 +Feb-10-2010 Version 2.2.7.1 + - Fixed compilation error reported by some compilers due to an sizeof in a fprintf (thanks to Maxim Britov and Renato Botelho). + - The path to the font used to create the graphs can be set in sarg.conf. + - The installation of our fonts can be disabled with --disable-fontdir. + +Feb-05-2010 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. diff --git a/Makefile.in b/Makefile.in index f13c1ea..618bd26 100644 --- a/Makefile.in +++ b/Makefile.in @@ -48,7 +48,10 @@ OBJS = util.o log.o report.o topuser.o email.o sort.o html.o \ squidguard_log.o squidguard_report.o auth.o download.o grepday.o \ dansguardian_log.o dansguardian_report.o realtime.o btree_cache.o usertab.o -DISTFILES = $(SRCS) +DISTFILES = $(SRCS) ABOUT-NLS + +SUBDIRS = po +.PHONY: install clean uninstall mostlyclean distclean $(SUBDIRS) all: sarg @@ -58,7 +61,10 @@ all: sarg sarg: $(OBJS) $(CC) $(LDFLAGS) $(OBJS) -o $@ $(LIBS) $(LIBCRYPT) -install: all +$(SUBDIRS): + $(MAKE) -C $@ + +install: all po -@if test ! -d $(DESTDIR)$(BINDIR); then \ echo "creating $(DESTDIR)$(BINDIR)"; \ mkdir -p $(DESTDIR)$(BINDIR); \ @@ -75,10 +81,6 @@ install: all echo "Creating $(DESTDIR)$(LANGDIR)"; \ mkdir -p $(DESTDIR)$(LANGDIR); \ fi - -@if test ! -d $(DESTDIR)$(FONTDIR); then \ - echo "Creating $(DESTDIR)$(FONTDIR)"; \ - mkdir -p $(DESTDIR)$(FONTDIR); \ - fi -@if test ! -d $(DESTDIR)$(IMAGEDIR); then \ echo "Creating $(DESTDIR)$(IMAGEDIR)"; \ mkdir -p $(DESTDIR)$(IMAGEDIR); \ @@ -97,20 +99,26 @@ install: all cp ./exclude_codes $(DESTDIR)$(SYSCONFDIR); cp ./user_limit_block $(DESTDIR)$(SYSCONFDIR); cp -r ./images/* $(DESTDIR)$(IMAGEDIR); - cp -r ./fonts/* $(DESTDIR)$(FONTDIR); + -@if test -n "$(FONTDIR)" ; then \ + if test ! -d "$(DESTDIR)$(FONTDIR)" ; then \ + echo "Creating $(DESTDIR)$(FONTDIR)"; \ + mkdir -p "$(DESTDIR)$(FONTDIR)"; \ + fi; \ + cp -r ./fonts/* "$(DESTDIR)$(FONTDIR)"; \ + fi cp -r ./css.tpl $(DESTDIR)$(SYSCONFDIR); -@if test -n "$(SARGPHPDIR)" -a -d "$(DESTDIR)$(SARGPHPDIR)"; then \ - cp -r ./sarg-php $(DESTDIR)$(SARGPHPDIR); \ + cp -r ./sarg-php $(DESTDIR)$(SARGPHPDIR); \ fi -uninstall: +uninstall: po rm -f $(DESTDIR)$(BINDIR)/sarg rm -f $(DESTDIR)$(MANDIR)/sarg.1 TAGS: $(SRCS) etags $(SRCS) -clean: +clean: po rm -f sarg *.o core mostlyclean: clean diff --git a/README b/README index 0f9c448..84918ab 100644 --- a/README +++ b/README @@ -61,7 +61,7 @@ If you use native squid log format, the elapsed time will be in reports (emulate --enable-languagedir - where the translation of sarg are default: /usr/local/share/sarg/languages - --enable-fontdir - where to find the fonts for the reports + --enable-fontdir - where to find the fonts for the reports (--diable-fontdir don't install the fonts) default: /usr/local/share/sarg/fonts --enable-imagedir - where sarg take the images to include in the reports diff --git a/configure.in b/configure.in index c6dac3d..7c5f7f8 100644 --- a/configure.in +++ b/configure.in @@ -139,7 +139,8 @@ AC_ARG_ENABLE(sargphp, fi ],[SARGPHPDIR="/var/www/html"]) if test "$SARGPHPDIR" ; then - echo "using $SARGPHPDIR as the directory to install sarg-php" + tempfullpath=`eval "echo $SARGPHPDIR"` + echo "using $tempfullpath as the directory to install sarg-php" AC_SUBST(SARGPHPDIR) fi @@ -152,7 +153,8 @@ AC_ARG_ENABLE(languagedir, LANGDIR=$enableval fi ],[LANGDIR="${datarootdir}/sarg/languages"]) -echo "using $LANGDIR as the directory of the translations" +tempfullpath=`eval "echo $LANGDIR"` +echo "using $tempfullpath as the directory of the translations" AC_SUBST(LANGDIR) dnl Select fonts dir @@ -160,12 +162,15 @@ AC_ARG_ENABLE(fontdir, [ --enable-fontdir=fontdir Select fontdir as the directory with the fonts to use in the reports ], [ - if test "$enableval"; then + if test "$enableval" -a "x$enableval" != "xno" ; then FONTDIR=$enableval fi ],[FONTDIR="${datarootdir}/sarg/fonts"]) -echo "using $FONTDIR as the directory of the fonts" -AC_SUBST(FONTDIR) +if test "$FONTDIR" ; then + tempfullpath=`eval "echo $FONTDIR"` + echo "using $tempfullpath as the directory of the fonts" + AC_SUBST(FONTDIR) +fi dnl Select images dir AC_ARG_ENABLE(imagedir, @@ -176,7 +181,8 @@ AC_ARG_ENABLE(imagedir, IMAGEDIR=$enableval fi ],[IMAGEDIR="${datarootdir}/sarg/images"]) -echo "using $IMAGEDIR as the directory of the images" +tempfullpath=`eval "echo $IMAGEDIR"` +echo "using $tempfullpath as the directory of the images" AC_SUBST(IMAGEDIR) dnl Enable extra compile and run time protection diff --git a/getconf.c b/getconf.c index 63875a6..fe65246 100644 --- a/getconf.c +++ b/getconf.c @@ -566,6 +566,8 @@ static void parmtest(char *buf) if (getparam_string("LDAPTargetAttr",buf,LDAPTargetAttr,sizeof(LDAPTargetAttr))>0) return; + if (getparam_string("graph_font",buf,GraphFont,sizeof(GraphFont))>0) return; + if(strstr(buf,"squid24") != 0) { squid24++; return; diff --git a/grepday.c b/grepday.c index 522703a..ee3c26f 100644 --- a/grepday.c +++ b/grepday.c @@ -39,8 +39,6 @@ static int goldenrod2; static int gray; static int silver; static int black; -//static char *font1 = FONTDIR"/FreeSans.ttf"; -static char *font1 = FONTDIR"/DejaVuSans.ttf"; #if defined(HAVE_ICONV_H) && defined(gdFTEX_Unicode) #include @@ -156,11 +154,6 @@ static void bar(int x1,long long int n) 3900000000LL,4000000000LL,4100000000LL,4200000000LL,4300000000LL,4400000000LL, 4500000000LL,4600000000LL,4700000000LL,4800000000LL,4900000000LL,5000000000LL}; - if(access(font1, R_OK) != 0) { - fprintf(stderr, "SARG: (grepday) Fontname: %s not found.\n",font1); - exit(1); - } - if(strcmp(GraphDaysBytesBarColor,"orange") == 0) { color1 = gdImageColorAllocate(im, 255, 233, 142); color2 = gdImageColorAllocate(im, 220, 163, 72); @@ -225,7 +218,7 @@ static void bar(int x1,long long int n) snprintf(v,6,"%s",fixnum(num,0)); - SARGgdImageStringFT(im,&brect[0],black,font1,6,0.0,x1-1,val-12,v); + SARGgdImageStringFT(im,&brect[0],black,GraphFont,6,0.0,x1-1,val-12,v); points[0].x = x1+17; points[0].y = val-5; @@ -268,10 +261,14 @@ void greport_day(const char *user) struct getwordstruct gwarea; struct getwordstruct gwarea1; - if(!Graphs) { + if(!Graphs || GraphFont[0]=='\0') { unlink(wdirname); return; } + if(access(GraphFont, R_OK) != 0) { + fprintf(stderr, "SARG: (grepday) Fontname: %s not found.\n",GraphFont); + exit(1); + } im = gdImageCreate(720, 480); @@ -330,7 +327,7 @@ void greport_day(const char *user) y=65; for(x=1; x<=31; x++) { sprintf(s,"%02d",x); - SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,y,437,s); + SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,y,437,s); y=y+20; } @@ -345,54 +342,54 @@ void greport_day(const char *user) subs(name,sizeof(name),"_","."); } - SARGgdImageStringFT(im,&brect[0],darkblue,font1,7,0.0,620,470,ftime); - if(ShowSargInfo) SARGgdImageStringFT(im,&brect[0],darkblue,font1,10,0.0,257,15,"SARG, "); - SARGgdImageStringFT(im,&brect[0],darkblue,font1,10,0.0,300,15,Title); + SARGgdImageStringFT(im,&brect[0],darkblue,GraphFont,7,0.0,620,470,ftime); + if(ShowSargInfo) SARGgdImageStringFT(im,&brect[0],darkblue,GraphFont,10,0.0,257,15,"SARG, "); + SARGgdImageStringFT(im,&brect[0],darkblue,GraphFont,10,0.0,300,15,Title); sprintf(warea,"%s: %s",text[89],period); - SARGgdImageStringFT(im,&brect[0],darkblue,font1,9,0.0,300,27,warea); + SARGgdImageStringFT(im,&brect[0],darkblue,GraphFont,9,0.0,300,27,warea); sprintf(warea,"%s: %s",text[90],name); - SARGgdImageStringFT(im,&brect[0],darkblue,font1,9,0.0,300,38,warea); - SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,418," 50K"); - SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,408,"250K"); - SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,398,"500K"); - SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,388," 1M"); - SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,378," 2M"); - SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,368," 3M"); - SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,358," 4M"); - SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,348," 5M"); - SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,338," 6M"); - SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,328," 7M"); - SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,318," 8M"); - SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,308," 9M"); - SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,298," 10M"); - SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,288," 15M"); - SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,278," 20M"); - SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,268," 30M"); - SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,258," 40M"); - SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,248," 50M"); - SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,238," 60M"); - SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,228," 70M"); - SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,218," 80M"); - SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,208," 90M"); - SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,198,"100M"); - SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,188,"200M"); - SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,178,"300M"); - SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,168,"400M"); - SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,158,"500M"); - SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,148,"600M"); - SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,138,"700M"); - SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,128,"800M"); - SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,118,"900M"); - SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,108," 1G"); - SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23, 98," 2G"); - SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23, 88," 3G"); - SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23, 78," 4G"); - SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23, 68," 5G"); + SARGgdImageStringFT(im,&brect[0],darkblue,GraphFont,9,0.0,300,38,warea); + SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,418," 50K"); + SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,408,"250K"); + SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,398,"500K"); + SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,388," 1M"); + SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,378," 2M"); + SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,368," 3M"); + SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,358," 4M"); + SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,348," 5M"); + SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,338," 6M"); + SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,328," 7M"); + SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,318," 8M"); + SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,308," 9M"); + SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,298," 10M"); + SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,288," 15M"); + SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,278," 20M"); + SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,268," 30M"); + SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,258," 40M"); + SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,248," 50M"); + SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,238," 60M"); + SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,228," 70M"); + SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,218," 80M"); + SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,208," 90M"); + SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,198,"100M"); + SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,188,"200M"); + SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,178,"300M"); + SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,168,"400M"); + SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,158,"500M"); + SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,148,"600M"); + SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,138,"700M"); + SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,128,"800M"); + SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,118,"900M"); + SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,108," 1G"); + SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23, 98," 2G"); + SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23, 88," 3G"); + SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23, 78," 4G"); + SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23, 68," 5G"); if(strcmp(datetimeby,"bytes") == 0) - SARGgdImageStringFT(im,&brect[0],black,font1,10,3.14/2,20,248,text[93]); + SARGgdImageStringFT(im,&brect[0],black,GraphFont,10,3.14/2,20,248,text[93]); else - SARGgdImageStringFT(im,&brect[0],black,font1,10,3.14/2,20,248,text[94]); - SARGgdImageStringFT(im,&brect[0],black,font1,10,0.0,330,460,text[127]); + SARGgdImageStringFT(im,&brect[0],black,GraphFont,10,3.14/2,20,248,text[94]); + SARGgdImageStringFT(im,&brect[0],black,GraphFont,10,0.0,330,460,text[127]); if (snprintf(graph,sizeof(graph),"%s/%s/graph_day.png",dirname,user)>=sizeof(graph)) { fprintf(stderr, "SARG: user name too long for: %s/%s/graph_day.png\n",dirname,user); diff --git a/include/conf.h b/include/conf.h index 3ceeb85..2e6f6ad 100755 --- a/include/conf.h +++ b/include/conf.h @@ -305,7 +305,6 @@ char DataFile[MAXLEN]; char DataFileDelimiter[3]; unsigned long int DataFileFields; char DataFileUrl[20]; -char SiteUserTimeDateType[10]; int ShowReadStatistics; char IndexSortOrder[5]; char DansGuardianConf[MAXLEN]; @@ -374,6 +373,7 @@ int LDAPProtocolVersion; char LDAPBaseSearch[255]; char LDAPFilterSearch[512]; char LDAPTargetAttr[64]; +char GraphFont[MAXLEN]; int idate; int smartfilter; diff --git a/include/info.h b/include/info.h index e0693c9..ab13bc8 100755 --- a/include/info.h +++ b/include/info.h @@ -1,3 +1,3 @@ -#define VERSION PACKAGE_VERSION" Feb-04-2010" +#define VERSION PACKAGE_VERSION" Feb-10-2010" #define PGM PACKAGE_NAME #define URL "http://sarg.sourceforge.net" diff --git a/log.c b/log.c index ae0ec60..20769a3 100644 --- a/log.c +++ b/log.c @@ -178,6 +178,7 @@ int main(int argc,char *argv[]) UseComma=0; strcpy(MailUtility,"mailx"); TopSitesNum=100; + TopUsersNum=0; UserIp=0; strcpy(TopuserSortField,"BYTES"); strcpy(UserSortField,"BYTES"); @@ -204,7 +205,6 @@ int main(int argc,char *argv[]) strcpy(DataFileDelimiter,";"); DataFileFields=DATA_FIELD_USER | DATA_FIELD_DATE | DATA_FIELD_TIME | DATA_FIELD_URL | DATA_FIELD_CONNECT | DATA_FIELD_BYTES | DATA_FIELD_IN_CACHE | DATA_FIELD_OUT_CACHE | DATA_FIELD_ELAPSED; - strcpy(SiteUserTimeDateType,"table"); ShowReadStatistics=1; strcpy(IndexSortOrder,"D"); ShowSargInfo=1; @@ -220,6 +220,11 @@ int main(int argc,char *argv[]) strcpy(Require,"require user admin %u"); set_download_suffix("7z,ace,arj,avi,bat,bin,bz2,bzip,cab,com,cpio,dll,doc,dot,exe,gz,iso,lha,lzh,mdb,mov,mp3,mpeg,mpg,mso,nrg,ogg,ppt,rar,rtf,shs,src,sys,tar,tgz,vcd,vob,wma,wmv,zip"); Graphs=1; +#if defined(FONTDIR) + strcpy(GraphFont,FONTDIR"/DejaVuSans.ttf"); +#else + GraphFont[0]='\0'; +#endif strcpy(Ulimit,"20000"); strcpy(NtlmUserFormat,"domainname+username"); IndexTree=INDEX_TREE_FILE; @@ -309,7 +314,7 @@ int main(int argc,char *argv[]) textdomain (PACKAGE_NAME); NAccessLog=0; - for(x=0; x<=MAXLOGS; x++) + for(x=0; x",fp_top3); #ifdef HAVE_GD - if(Graphs) { + if(Graphs && GraphFont[0]!='\0') { fprintf(fp_top3,"\"G\" ",user,ImageFile,text[126]); } #endif -- 2.39.5