]> git.ipfire.org Git - thirdparty/sarg.git/blobdiff - squidguard_log.c
Mass commit of all the changes made between version 2.1 and 2.2.5. See ChangeLog...
[thirdparty/sarg.git] / squidguard_log.c
index bf5eb116046e8e5f645107a54c7579133cfb1520..59e378cc34439dc616800912f4aa54652da75f48 100644 (file)
 
 #include "include/conf.h"
 
+static char **files_done = NULL;
+static int nfiles_done = 0;
+
+
 void read_log(char *wentp, FILE *fp_ou)
 {
    FILE *fp_in = NULL;
@@ -34,6 +38,7 @@ void read_log(char *wentp, FILE *fp_ou)
    char list[MAXLEN];
    char wdata[127];
    int  idata=0;
+   int  i;
 
    if(debug) {
       strcpy(buf,text[7]);
@@ -42,6 +47,44 @@ void read_log(char *wentp, FILE *fp_ou)
       sprintf(msg,"%s squidGuard %s: %s",urly,buf,wentp);
       debuga(msg);
    }
+
+   /* With squidGuard, you can log groups in only one log file.
+      We must parse each log files only one time.  Example :
+      dest porn {
+          domainlist porn/domains
+          urllist    porn/urls
+          log file1.log
+      }
+      dest aggressive {
+          domainlist aggressive/domains
+          urllist    aggressive/urls
+          log file2.log
+      }
+      dest audio-video {
+          domainlist audio-video/domains
+          urllist    audio-video/urls
+          log file1.log
+      }
+   */
+   for (i=0; i<nfiles_done; i++)
+      if (!strcmp(wentp, files_done[i])) return;
+   
+   nfiles_done++;
+   files_done = realloc(files_done, nfiles_done*sizeof(char *));
+   if (!files_done) {
+       perror("parse squidGuard - realloc");
+       exit(EXIT_FAILURE);
+   }
+   files_done[nfiles_done-1] = strdup(wentp);
+   if (!files_done[nfiles_done-1]) {
+       perror("parse squidGuard - strdup");
+       exit(EXIT_FAILURE);
+   }
+
+   if ((fp_in=fopen(wentp,"r"))==NULL) {
+         fprintf(stderr, "SARG: (squidguard) %s: %s\n",text[8],wentp);
+       exit(1);
+   }
    
    if ((fp_in=fopen(wentp,"r"))==NULL) {
       fprintf(stderr, "SARG: (squidguard) %s: %s\n",text[8],wentp);
@@ -128,6 +171,8 @@ int squidguard_log()
    char ip[30];
    int  x, y;
 
+   str2 = user;
+
    if(strlen(SquidGuardConf) < 1 && strlen(SquidGuardLogAlternate) < 1)
      return;
 
@@ -147,28 +192,28 @@ int squidguard_log()
 
    if(strcmp(SquidguardIgnoreDate,"on") == 0) {
       if(strcmp(df,"e") == 0) {
-         strncpy(day,periodo,2);
-         strncpy(mon,periodo+2,3);
-         strncpy(year,periodo+5,4);
+         strncpy(day,period,2);
+         strncpy(mon,period+2,3);
+         strncpy(year,period+5,4);
          conv_month(mon);
          sprintf(warea,"%s%s%s",year,mon,day);
          dfrom=atoi(warea);
-         strncpy(day,periodo+10,2);
-         strncpy(mon,periodo+12,3);
-         strncpy(year,periodo+15,4);
+         strncpy(day,period+10,2);
+         strncpy(mon,period+12,3);
+         strncpy(year,period+15,4);
          conv_month(mon);
          sprintf(warea,"%s%s%s",year,mon,day);
          duntil=atoi(warea);
       } else {
-         strncpy(day,periodo+7,2);
-         strncpy(mon,periodo+4,3);
-         strncpy(year,periodo,4);
+         strncpy(day,period+7,2);
+         strncpy(mon,period+4,3);
+         strncpy(year,period,4);
          conv_month(mon);
          sprintf(warea,"%s%s%s",year,mon,day);
          dfrom=atoi(warea);
-         strncpy(day,periodo+17,2);
-         strncpy(mon,periodo+14,3);
-         strncpy(year,periodo+10,4);
+         strncpy(day,period+17,2);
+         strncpy(mon,period+14,3);
+         strncpy(year,period+10,4);
          conv_month(mon);
          sprintf(warea,"%s%s%s",year,mon,day);
          duntil=atoi(warea);
@@ -198,12 +243,25 @@ int squidguard_log()
             str=str+3;
             str2[0]='\0';
             y=0;
+            while(*str == ' ')
+              str++;
+           if (str == (char *) strstr(str, "anonymous"))
+               str+=9;
+
             for (x=0; x<=strlen(str); x++) {
                if (str[x] != ' ' && str[x] != '\t') {
                   str2[y] = str[x];
                   y++;
                }
             }
+            if(strchr(str2,' ') != 0) {
+               getword(warea,str2,' ');
+               strcpy(str2,warea);
+            }
+            if(strchr(str2,'#') != 0) {
+               getword(warea,str2,'#');
+               strcpy(str2,warea);
+            }
             sprintf(wentp,"%s/%s",logdir,str2);
             read_log(wentp,fp_ou);
          }