]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Fix a sorting issue in the DansGuardian log
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Wed, 14 Sep 2011 07:35:05 +0000 (07:35 +0000)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Wed, 14 Sep 2011 07:35:05 +0000 (07:35 +0000)
Times with a one digit hour must be sorted before the times with two
digits. To fix this issue, a padding zero is prefixed to the hour if it
contains only one digit.

Thanks to Iain Lopata for the patch.

CMakeLists.txt
dansguardian_log.c
include/info.h

index c4b5b211dc4a272ef1c93fd817306d99e0b8f1f8..4ec2ef572ef41a88fdff350ceeeaec7de283e095 100755 (executable)
@@ -3,7 +3,7 @@ PROJECT(sarg C)
 SET(sarg_VERSION 2)
 SET(sarg_REVISION "3.2-pre2")
 SET(sarg_BUILD "")
-SET(sarg_BUILDDATE "Sep-02-2011")
+SET(sarg_BUILDDATE "Sep-14-2011")
 
 INCLUDE(AddFileDependencies)
 INCLUDE(CheckIncludeFile)
index 3b27f4b5ee4205a363bf2efe9e7264cb60628d31..203d603aacf94a26c2d817d301e3cbc183e8d8cb 100644 (file)
@@ -35,7 +35,8 @@ void dansguardian_log(void)
        char guard_ou[MAXLEN];
        char loglocation[MAXLEN] = "/var/log/dansguardian/access.log";
        int year, mon, day;
-       char hour[15];
+       int hour;
+       char minsec[15];
        char user[MAXLEN], code1[255], code2[255];
        char ip[45];
        char *url;
@@ -93,9 +94,23 @@ void dansguardian_log(void)
                        continue;
                getword_start(&gwarea,buf);
                if (getword_atoi(&year,&gwarea,'.')<0 || getword_atoi(&mon,&gwarea,'.')<0 ||
-                   getword_atoi(&day,&gwarea,' ')<0 || getword(hour,sizeof(hour),&gwarea,' ')<0 ||
-                   getword(user,sizeof(user),&gwarea,' ')<0 || getword(ip,sizeof(ip),&gwarea,' ')<0 ||
-                   getword_skip(MAXLEN,&gwarea,'/')<0 || getword_skip(MAXLEN,&gwarea,'/')<0) {
+                   getword_atoi(&day,&gwarea,' ')<0) {
+                       debuga(_("Invalid date found in your dansguardian log file %s\n"),loglocation);
+                       exit(EXIT_FAILURE);
+               }
+               if (getword_atoi(&hour,&gwarea,':')<0 || getword(minsec,sizeof(minsec),&gwarea,' ')<0) {
+                       debuga(_("Invalid time found in your dansguardian log file %s\n"),loglocation);
+                       exit(EXIT_FAILURE);
+               }
+               if (getword(user,sizeof(user),&gwarea,' ')<0) {
+                       debuga(_("Invalid user found in your dansguardian log file %s\n"),loglocation);
+                       exit(EXIT_FAILURE);
+               }
+               if (getword(ip,sizeof(ip),&gwarea,' ')<0) {
+                       debuga(_("Invalid IP address found in your dansguardian log file %s\n"),loglocation);
+                       exit(EXIT_FAILURE);
+               }
+               if (getword_skip(MAXLEN,&gwarea,'/')<0 || getword_skip(MAXLEN,&gwarea,'/')<0) {
                        debuga(_("Maybe you have a broken record or garbage in your %s file\n"),loglocation);
                        exit(EXIT_FAILURE);
                }
@@ -119,7 +134,7 @@ void dansguardian_log(void)
                        strcpy(user,ip);
                        ip[0]='\0';
                }
-               fprintf(fp_ou,"%s\t%d\t%s\t%s\t%s\t%s\t%s\n",user,idata,hour,ip,url,code1,code2);
+               fprintf(fp_ou,"%s\t%d\t%02d:%s\t%s\t%s\t%s\t%s\n",user,idata,hour,minsec,ip,url,code1,code2);
                dansguardian_count++;
        }
 
index 8981c4ccb1f75bfd41477d6d153a186f77ef89af..27b518adbf641f33da2895dec35192e497dd4dc5 100755 (executable)
@@ -1,3 +1,3 @@
-#define VERSION PACKAGE_VERSION" Sep-02-2011"
+#define VERSION PACKAGE_VERSION" Sep-14-2011"
 #define PGM PACKAGE_NAME
 #define URL "http://sarg.sourceforge.net"