]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Fix some errors introduced by the previous patch for windows v2.3.2
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Wed, 23 Nov 2011 19:26:47 +0000 (19:26 +0000)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Wed, 23 Nov 2011 19:26:47 +0000 (19:26 +0000)
The changes made to make the realtime report compatible with windows
produced some errors on linux. This patch fixes those problems.

This fix also correctly sorts the entries by date and time whatever the
requested output date format is.

CMakeLists.txt
configure.in
realtime.c

index ac935a5a8fa62c42245b4f80210530215feac9cd..8869213402b3688e15788c4d6356e2bf6447bef0 100755 (executable)
@@ -1,7 +1,7 @@
 CMAKE_MINIMUM_REQUIRED (VERSION 2.6)
 PROJECT(sarg C)
 SET(sarg_VERSION 2)
-SET(sarg_REVISION "3.2-pre2")
+SET(sarg_REVISION "3.2")
 SET(sarg_BUILD "")
 SET(sarg_BUILDDATE "Nov-23-2011")
 
index 9b9a62070c6b1e7cd15166a77263f1614e2abfb9..854a94c5d787dab058f011eafe5bf704d7839e3a 100644 (file)
@@ -1,5 +1,5 @@
 dnl Process this file with autoconf to produce a configure script.
-AC_INIT([sarg],[2.3.2-pre2])
+AC_INIT([sarg],[2.3.2])
 AC_CONFIG_SRCDIR([log.c])
 AC_CONFIG_AUX_DIR(cfgaux)
 
@@ -75,7 +75,7 @@ AC_CHECK_HEADERS(stdio.h stdlib.h string.h strings.h sys/time.h time.h unistd.h
                dirent.h sys/types.h sys/socket.h netdb.h arpa/inet.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 locale.h \
-               execinfo.h ldap.h math.h libintl.h libgen.h stdbool.h getopt.h)
+               execinfo.h ldap.h math.h libintl.h libgen.h stdbool.h getopt.h fcntl.h)
 
 if test $ac_cv_header_getopt_h = "no" ; then
    AC_MSG_ERROR("getopt.h is required to compile sarg")
@@ -132,6 +132,7 @@ AC_CHECK_FUNCS(symlink)
 AC_CHECK_FUNCS(lstat)
 AC_CHECK_FUNCS(getnameinfo)
 AC_CHECK_FUNCS(getaddrinfo)
+AC_CHECK_FUNCS(mkstemp)
 
 dnl check for structure members
 AC_CHECK_MEMBER([struct sockaddr_storage.ss_len],[AC_DEFINE([HAVE_SOCKADDR_SA_LEN],1,[ss_len in sockaddr_storage])])
index 664480c34f82debc34a4147e015629333737ecbd..7652186977f9c268c596715ebc95fa08807be314 100755 (executable)
@@ -44,18 +44,28 @@ static void getlog(void)
        char template2[255]="/var/tmp/sargtpl2.XXXXXX";
        char cmd[512];
        char *buf;
-       int  fd1;
+       int  fd1,fd2;
        int cstatus;
        longline line;
 
        init_usertab(UserTabFile);
 
 #ifdef HAVE_MKSTEMP
+       fd2 = mkstemp(template2);
+       if (fd2 == -1) {
+               debuga(_("Cannot create a temporary file name to produce the report: %s\n"),strerror(errno));
+               exit(EXIT_FAILURE);
+       }
        fd1 = mkstemp(template1);
 #else
-       fd1=open(mktemp(template1),O_RDWR);
+       buf = mktemp(template2);
+       if (buf[0]=='\0') {
+               debuga(_("Cannot create a temporary file name to produce the report: %s\n"),strerror(errno));
+               exit(EXIT_FAILURE);
+       }
+       fd2 = -1;
+       fd1 = open(mktemp(template1),O_RDWR);
 #endif
-       mktemp(template2);
 
        if((fd1 == -1 ) || ((tmp = fdopen (fd1, "w+" )) == NULL)  ) {    /* failure, bail out */
                debuga(_("(realtime) mkstemp error - %s\n"),strerror(errno));
@@ -83,7 +93,8 @@ static void getlog(void)
        fclose(tmp);
        longline_destroy(&line);
 
-       if (snprintf(cmd,sizeof(cmd),"sort -t \"\t\" -r -k 1,1 -k 2,2 -o \"%s\" \"%s\"",template2,template1)>=sizeof(cmd)) {
+       if (fd2!=-1) close(fd2);//not safe at all but good enough for now.
+       if (snprintf(cmd,sizeof(cmd),"sort -t \"\t\" -r -n -k 1,1 -o \"%s\" \"%s\"",template2,template1)>=sizeof(cmd)) {
                debuga(_("Sort command too long when sorting file \"%s\" to \"%s\"\n"),template1,template2);
                exit(EXIT_FAILURE);
        }
@@ -102,10 +113,7 @@ static void getlog(void)
 
 static int getdata(char *rec, FILE *ftmp)
 {
-       time_t tt;
-       struct tm *t;
-       char dat[128];
-       char tbuf[128];
+       int dat;
        char typ[128];
        char warea[MAXLEN];
        char user[MAX_USER_LEN];
@@ -114,10 +122,14 @@ static int getdata(char *rec, FILE *ftmp)
        struct getwordstruct gwarea;
 
        getword_start(&gwarea,rec);
-       if (getword(dat,sizeof(dat),&gwarea,' ')<0) {
+       if (getword_atoi(&dat,&gwarea,'.')<0) {
                debuga(_("The time stamp at column 1 is too long\n"));
                return(-1);
        }
+       if (getword_skip(10,&gwarea,' ')<0) {
+               debuga(_("The time stamp decimal part at column 1 is too long\n"));
+               return(-1);
+       }
        if (getword(warea,sizeof(warea),&gwarea,' ')<0) {
                debuga(_("The connection duration at column 2 is too long\n"));
                return(-1);
@@ -177,22 +189,17 @@ static int getdata(char *rec, FILE *ftmp)
        if(strncmp(user,"-",1) == 0 && RealtimeUnauthRec==REALTIME_UNAUTH_REC_IGNORE)
                return(0);
 
-       tt=atoi(dat);
-       t=localtime(&tt);
-       if(strncmp(DateFormat,"u",1) == 0)
-               strftime(tbuf, sizeof(tbuf), "%Y-%m-%d\t%H:%M", t);
-       else if(strncmp(DateFormat,"e",1) == 0)
-               strftime(tbuf, sizeof(tbuf), "%d-%m-%Y\t%H:%M", t);
-
-       fprintf(ftmp,"%s\t%s\t%s\t%s\t%s\n",tbuf,ip,user,url,typ);
+       fprintf(ftmp,"%d\t%s\t%s\t%s\t%s\n",dat,ip,user,url,typ);
        return(0);
 }
 
 static void datashow(const char *tmp)
 {
        FILE *fin;
-       char dat[128];
-       char tim[128];
+       time_t tt;
+       struct tm *t;
+       char tbuf[128];
+       int dat;
        char *buf;
        char *url;
        char *ourl=NULL;
@@ -221,29 +228,25 @@ static void datashow(const char *tmp)
        while((buf=longline_read(fin,line))!=NULL) {
                fixendofline(buf);
                getword_start(&gwarea,buf);
-               if (getword(dat,sizeof(dat),&gwarea,'\t')<0) {
-                       debuga(_("Maybe you have a broken record or garbage in your %s file\n"),tmp);
-                       exit(EXIT_FAILURE);
-               }
-               if (getword(tim,sizeof(tim),&gwarea,'\t')<0) {
-                       debuga(_("Maybe you have a broken record or garbage in your %s file\n"),tmp);
+               if (getword_atoi(&dat,&gwarea,'\t')<0) {
+                       debuga(_("Invalid time column in file %s\n"),tmp);
                        exit(EXIT_FAILURE);
                }
                if (getword(ip,sizeof(ip),&gwarea,'\t')<0) {
-                       debuga(_("Maybe you have a broken record or garbage in your %s file\n"),tmp);
+                       debuga(_("Invalid IP address in file %s\n"),tmp);
                        exit(EXIT_FAILURE);
                }
                if (getword(user,sizeof(user),&gwarea,'\t')<0) {
-                       debuga(_("Maybe you have a broken record or garbage in your %s file\n"),tmp);
+                       debuga(_("Invalid user name in file %s\n"),tmp);
                        exit(EXIT_FAILURE);
                }
-               if(strlen(dat) < 3 || strlen(user) < 1) continue;
+               if (strlen(user) < 1) continue;
                if (getword_ptr(buf,&url,&gwarea,'\t')<0) {
-                       debuga(_("Maybe you have a broken url in your %s file\n"),tmp);
+                       debuga(_("Invalid URL in file %s\n"),tmp);
                        exit(EXIT_FAILURE);
                }
                if (getword(typ,sizeof(typ),&gwarea,'\t')<0) {
-                       debuga(_("Maybe you have a broken record or garbage in your %s file\n"),tmp);
+                       debuga(_("Invalid access type in file %s\n"),tmp);
                        exit(EXIT_FAILURE);
                }
                if(strstr(RealtimeTypes,typ) == 0)
@@ -259,7 +262,14 @@ static void datashow(const char *tmp)
                        ip2name(u2,sizeof(u2));
                user_find(name, sizeof(name), u2);
 
-               printf("<tr><td class=\"data\">%s %s</td><td class=\"data3\">%s</td><td class=\"data3\">%s</td><td class=\"data3\">%s</td><td class=\"data2\"><a href=\"http://%s\">%s</td></tr>\n",dat,tim,ip,name,typ,url,url);
+               tt=(time_t)dat;
+               t=localtime(&tt);
+               if(DateFormat[0]=='u')
+                       strftime(tbuf, sizeof(tbuf), "%Y-%m-%d %H:%M", t);
+               else if(DateFormat[0]=='e')
+                       strftime(tbuf, sizeof(tbuf), "%d-%m-%Y %H:%M", t);
+               
+               printf("<tr><td class=\"data\">%s</td><td class=\"data3\">%s</td><td class=\"data3\">%s</td><td class=\"data3\">%s</td><td class=\"data2\"><a href=\"http://%s\">%s</td></tr>\n",tbuf,ip,name,typ,url,url);
                strcpy(ouser,user);
 
                url_len=strlen(url);