]> git.ipfire.org Git - thirdparty/sarg.git/blobdiff - dansguardian_log.c
Fix HTML output
[thirdparty/sarg.git] / dansguardian_log.c
index e8876df96a4f2a1b4fd5c7b6056c3fc6f6d4fbf1..1e89cf6936942848c01391bfcfe16aec3449a941 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * AUTHOR: Pedro Lineu Orso                         pedro.orso@gmail.com
- *                                                            1998, 2008
+ *                                                            1998, 2010
  * SARG Squid Analysis Report Generator      http://sarg.sourceforge.net
  *
  * SARG donations:
@@ -24,6 +24,7 @@
  */
 
 #include "include/conf.h"
+#include "include/defs.h"
 
 void dansguardian_log(void)
 {
@@ -39,6 +40,7 @@ void dansguardian_log(void)
    char wdata[127];
    int  idata=0;
    int cstatus;
+   struct getwordstruct gwarea;
 
    bzero(day, 3);
    bzero(mon, 4);
@@ -76,8 +78,7 @@ void dansguardian_log(void)
    sprintf(guard_ou,"%s/dansguardian.log",tmp);
 
    if(access(DansGuardianConf, R_OK) != 0) {
-      sprintf(msg,"Cannot open DansGuardian config file: %s",DansGuardianConf);
-      debuga(msg);
+      debuga("Cannot open DansGuardian config file: %s",DansGuardianConf);
       exit(1);
    }
 
@@ -86,22 +87,18 @@ void dansguardian_log(void)
       exit(1);
    }
 
-#if defined(HAVE_FOPEN64)
-   if((fp_ou=fopen64(guard_in,"a"))==NULL) {
-#else
-   if((fp_ou=fopen(guard_in,"a"))==NULL) {
-#endif
+   if((fp_ou=MY_FOPEN(guard_in,"a"))==NULL) {
       fprintf(stderr, "SARG: (dansguardian) %s: %s\n",text[8],guard_in);
       exit(1);
    }
 
    while(fgets(buf,sizeof(buf),fp_guard)!=NULL) {
-      if(strstr(buf,"\n") != 0)
-         buf[strlen(buf)-1]='\0';
-      if(strncmp(buf,"#",1) == 0)
+      fixendofline(buf);
+      if(buf[0]=='#')
          continue;
       if(strstr(buf,"loglocation ") != 0) {
-         if (getword(loglocation,sizeof(loglocation),buf,'\'')<0 || getword(loglocation,sizeof(loglocation),buf,'\'')<0) {
+         getword_start(&gwarea,buf);
+         if (getword_skip(MAXLEN,&gwarea,'\'')<0 || getword(loglocation,sizeof(loglocation),&gwarea,'\'')<0) {
             printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",DansGuardianConf);
             exit(1);
          }
@@ -110,40 +107,36 @@ void dansguardian_log(void)
    }
 
    if(debug) {
-      strcpy(buf,text[7]);
-      if (getword(urly,sizeof(urly),buf,' ')<0 || getword(href,sizeof(href),buf,' ')<0) {
+      getword_start(&gwarea,text[7]);
+      if (getword(urly,sizeof(urly),&gwarea,' ')<0 || getword(href,sizeof(href),&gwarea,' ')<0) {
          printf("SARG: Maybe you have a broken record or garbage in your %s entry.\n",text[7]);
          exit(1);
       }
-      sprintf(msg,"%s DansGuardian %s: %s",urly,buf,loglocation);
-      debuga(msg);
+      debuga("%s DansGuardian %s: %s",urly,gwarea.current,loglocation);
    }
-   
-#if defined(HAVE_FOPEN64)
-   if((fp_in=fopen64(loglocation,"r"))==NULL) {
-#else
-   if((fp_in=fopen(loglocation,"r"))==NULL) {
-#endif
+
+   if((fp_in=MY_FOPEN(loglocation,"r"))==NULL) {
       fprintf(stderr, "SARG: (dansguardian) %s: %s\n",text[8],loglocation);
       exit(1);
    }
+
    while(fgets(buf,sizeof(buf),fp_in) != NULL) {
       if(strstr(buf," *DENIED* ") == 0)
          continue;
-      if (getword(year,sizeof(year),buf,'.')<0 || getword(mon,sizeof(mon),buf,'.')<0 ||
-          getword(day,sizeof(day),buf,' ')<0 || getword(hour,sizeof(hour),buf,' ')<0 ||
-          getword(user,sizeof(user),buf,' ')<0 || getword(ip,sizeof(ip),buf,' ')<0 ||
-          getword(url,sizeof(url),buf,'/')<0 || getword(url,sizeof(url),buf,'/')<0 ||
-          getword(url,sizeof(url),buf,' ')<0 || getword(code1,sizeof(code1),buf,' ')<0 ||
-          getword(code1,sizeof(code1),buf,' ')<0 || getword(code2,sizeof(code2),buf,' ')<0) {
+      getword_start(&gwarea,buf);
+      if (getword(year,sizeof(year),&gwarea,'.')<0 || getword(mon,sizeof(mon),&gwarea,'.')<0 ||
+          getword(day,sizeof(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(url,sizeof(url),&gwarea,' ')<0 || getword_skip(255,&gwarea,' ')<0 ||
+          getword(code1,sizeof(code1),&gwarea,' ')<0 || getword(code2,sizeof(code2),&gwarea,' ')<0) {
          printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",loglocation);
          exit(1);
       }
       sprintf(wdata,"%s%02d%s",year,atoi(mon),day);
       idata = atoi(wdata);
 
-      if(strcmp(DansguardianIgnoreDate,"on") == 0) {
+      if(DansguardianIgnoreDate) {
          if(idata < dfrom && idata > duntil)
             continue;
       }
@@ -152,7 +145,7 @@ void dansguardian_log(void)
          strcpy(user,ip);
          bzero(ip, 30);
       }
-      fprintf(fp_ou,"%s %d %s %s %s %s %s\n",user,idata,hour,ip,url,code1,code2);
+      fprintf(fp_ou,"%s\t%d\t%s\t%s\t%s\t%s\t%s\n",user,idata,hour,ip,url,code1,code2);
       dansguardian_count++;
    }
 
@@ -160,12 +153,10 @@ void dansguardian_log(void)
    if(fp_guard) fclose(fp_guard);
    if(fp_ou) fclose(fp_ou);
 
-   if(debug) {
-      sprintf(msg,"%s: %s",text[54],guard_ou);
-      debuga(msg);
-   }
+   if(debug)
+      debuga("%s: %s",text[54],guard_ou);
 
-   sprintf(tmp6,"sort -k 1,1 -k 2,2 -k 4,4 '%s' -o '%s'",guard_in, guard_ou);
+   sprintf(tmp6,"sort -k 1,1 -k 2,2 -k 4,4 \"%s\" -o \"%s\"",guard_in, guard_ou);
    cstatus=system(tmp6);
    if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
       fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus));