]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Don't abort on squidGuard log errors
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Thu, 29 Dec 2011 15:05:34 +0000 (15:05 +0000)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Thu, 29 Dec 2011 15:05:34 +0000 (15:05 +0000)
squidGuard sometime wraps the url in the log file and sarg used to abort
the whole report generation. This patch merely issue a warning but keep
producing the report.

The report contains a warning indicating how many lines were ignored
from the original log file.

css.c
redirector.c

diff --git a/css.c b/css.c
index 811ba005aae7fa1afc12d63bd890b8f5597085da..ddecaae23cb574acc06c44ba5a7485e51211bfe9 100644 (file)
--- a/css.c
+++ b/css.c
@@ -67,6 +67,9 @@ void css_content(FILE *fp_css)
        fprintf(fp_css,".link a:link,a:visited {font-family:%s;font-size:%s;color:#0000FF;text-decoration:none;}\n", FontFace, FontSize);
 
        fprintf(fp_css,"a > img {border:none;}\n");
+       
+       fputs(".warn {margin:0.5em;}\n",fp_css);
+       fprintf(fp_css,".warn > span {padding:0.5em;border:2px solid black;background-color:orange;font-family:%s;font-size:%s;}\n",FontFace,FontSize);
 
        if (SortTableJs[0]) {
                fprintf(fp_css,".sorttable_nosort {cursor:default !important;}\n");
index f85553fdb5b97f266c4004a66788b06336ecd6f9..b8ab00de98fbd0987dec757b6559ebbe614abf1d 100644 (file)
 static char **files_done = NULL;
 static int nfiles_done = 0;
 
+//! The number of invalid lines found in the redirector report.
+static int RedirectorErrors=0;
 
-static void read_log(const char *wentp, FILE *fp_ou,int dfrom,int duntil)
+static void parse_log(FILE *fp_ou,char *buf)
 {
-       FILE *fp_in = NULL;
-       char *buf;
        char leks[5], sep[2], res[MAXLEN];
        char hour[15];
        char source[128], list[128];
@@ -45,11 +45,184 @@ static void read_log(const char *wentp, FILE *fp_ou,int dfrom,int duntil)
        long long int lmon, lday, lyear;
        int mon, day, year;
        int  idata=0;
-       int  i;
        bool id_is_ip;
        struct getwordstruct gwarea;
        struct getwordstruct gwarea1;
        struct userinfostruct *uinfo;
+
+       getword_start(&gwarea,buf);
+       if(RedirectorLogFormat[0] != '\0') {
+               getword_start(&gwarea1,RedirectorLogFormat);
+               leks[0]='\0';
+               if (getword(leks,sizeof(leks),&gwarea1,'#')<0) {
+                       debuga(_("Invalid \"redirector_log_format\" option in your sarg.conf (too many characters before first tag)\n"));
+                       exit(EXIT_FAILURE);
+               }
+               year=0;
+               mon=0;
+               day=0;
+               hour[0]='\0';
+               source[0]='\0';
+               list[0]='\0';
+               ip[0]='\0';
+               user[0]='\0';
+               full_url[0]='\0';
+               while(strcmp(leks,"end") != 0) {
+                       if (getword(leks,sizeof(leks),&gwarea1,'#')<0) {
+                               debuga(_("Invalid \"redirector_log_format\" option in your sarg.conf (missing # at end of tag)\n"));
+                               exit(EXIT_FAILURE);
+                       }
+                       if (getword(sep,sizeof(sep),&gwarea1,'#')<0) {
+                               debuga(_("Invalid \"redirector_log_format\" option in your sarg.conf (too many characters in column separator)\n"));
+                               exit(EXIT_FAILURE);
+                       }
+                       if(strcmp(leks,"end") != 0) {
+                               if (getword_limit(res,sizeof(res),&gwarea,sep[0])<0) {
+                                       debuga(_("Parsing of tag \"%s\" in redirector log %s returned no result\n"),leks,wentp);
+                                       RedirectorErrors++;
+                                       return;
+                               }
+                               if(strcmp(leks,"year") == 0) {
+                                       year=atoi(res);
+                               } else if(strcmp(leks,"mon") == 0) {
+                                       mon=atoi(res);
+                               } else if(strcmp(leks,"day") == 0) {
+                                       day=atoi(res);
+                               } else if(strcmp(leks,"hour") == 0) {
+                                       if (strlen(res)>=sizeof(hour)) {
+                                               debuga(_("Hour string too long in redirector log file %s\n"),wentp);
+                                               RedirectorErrors++;
+                                               return;
+                                       }
+                                       strcpy(hour,res);
+                               } else if(strcmp(leks,"source") == 0) {
+                                       if (strlen(res)>=sizeof(source)) {
+                                               debuga(_("Banning source name too long in redirector log file %s\n"),wentp);
+                                               RedirectorErrors++;
+                                               return;
+                                       }
+                                       strcpy(source,res);
+                               } else if(strcmp(leks,"list") == 0) {
+                                       if (strlen(res)>=sizeof(list)) {
+                                               debuga(_("Banning list name too long in redirector log file %s\n"),wentp);
+                                               RedirectorErrors++;
+                                               return;
+                                       }
+                                       strcpy(list,res);
+                               } else if(strcmp(leks,"ip") == 0) {
+                                       if (strlen(res)>=sizeof(ip)) {
+                                               debuga(_("IP address too long in redirector log file %s\n"),wentp);
+                                               RedirectorErrors++;
+                                               return;
+                                       }
+                                       strcpy(ip,res);
+                               } else if(strcmp(leks,"user") == 0) {
+                                       if (strlen(res)>=sizeof(user)) {
+                                               debuga(_("User ID too long in redirector log file %s\n"),wentp);
+                                               RedirectorErrors++;
+                                               return;
+                                       }
+                                       strcpy(user,res);
+                               } else if(strcmp(leks,"url") == 0) {
+                                       if (strlen(res)>=sizeof(full_url)) {
+                                               debuga(_("URL too long in redirector log file %s\n"),wentp);
+                                               RedirectorErrors++;
+                                               return;
+                                       }
+                                       strcpy(full_url,res);
+                               }
+                       }
+               }
+       } else {
+               if (getword_atoll(&lyear,&gwarea,'-')<0 || getword_atoll(&lmon,&gwarea,'-')<0 ||
+                               getword_atoll(&lday,&gwarea,' ')<0) {
+                       debuga(_("Invalid date found in file %s\n"),wentp);
+                       RedirectorErrors++;
+                       return;
+               }
+               year=(int)lyear;
+               mon=(int)lmon;
+               day=(int)lday;
+               if (getword(hour,sizeof(hour),&gwarea,' ')<0) {
+                       debuga(_("Invalid time found in file %s\n"),wentp);
+                       RedirectorErrors++;
+                       return;
+               }
+               if (getword_skip(MAXLEN,&gwarea,'(')<0 || getword(source,sizeof(source),&gwarea,'/')<0) {
+                       debuga(_("Invalid redirected source in file %s\n"),wentp);
+                       RedirectorErrors++;
+                       return;
+               }
+               if (getword(list,sizeof(list),&gwarea,'/')<0) {
+                       debuga(_("Invalid redirected list in file %s\n"),wentp);
+                       RedirectorErrors++;
+                       return;
+               }
+               if (getword_skip(MAXLEN,&gwarea,' ')<0 || getword_limit(full_url,sizeof(full_url),&gwarea,' ')<0) {
+                       debuga(_("Invalid URL in file %s\n"),wentp);
+                       RedirectorErrors++;
+                       return;
+               }
+               if (getword(ip,sizeof(ip),&gwarea,'/')<0) {
+                       debuga(_("Invalid source IP in file %s\n"),wentp);
+                       RedirectorErrors++;
+                       return;
+               }
+               if (getword_skip(MAXLEN,&gwarea,' ')<0 || getword(user,sizeof(user),&gwarea,' ')<0) {
+                       debuga(_("Invalid user in file %s\n"),wentp);
+                       RedirectorErrors++;
+                       return;
+               }
+       }
+       url=process_url(full_url,false);
+
+       //sprintf(warea,"%04d%02d%02d",year,mon,day);
+
+       if(RedirectorFilterOutDate) {
+               idata = year*10000+mon*100+day;
+               if(idata < dfrom || idata > duntil)
+                       return;
+       }
+
+       if(UserIp) {
+               strcpy(user,ip);
+               id_is_ip=true;
+       } else {
+               id_is_ip=false;
+               if(strcmp(user,"-") == 0 || strcmp(user," ") == 0 || strcmp(user,"") == 0) {
+                       if(RecordsWithoutUser == RECORDWITHOUTUSER_IP) {
+                               strcpy(user,ip);
+                               id_is_ip=true;
+                       }
+                       if(RecordsWithoutUser == RECORDWITHOUTUSER_IGNORE)
+                               return;
+                       if(RecordsWithoutUser == RECORDWITHOUTUSER_EVERYBODY)
+                               strcpy(user,"everybody");
+               }
+       }
+       uinfo=userinfo_find_from_id(user);
+       if (!uinfo) {
+               uinfo=userinfo_create(user);
+               uinfo->id_is_ip=id_is_ip;
+               uinfo->no_report=true;
+               if(Ip2Name && id_is_ip) ip2name(user,sizeof(user));
+               user_find(uinfo->label,MAX_USER_LEN, user);
+       }
+       fprintf(fp_ou,"%s\t%04d%02d%02d\t%s\t%s\t%s\t",uinfo->id,year,mon,day,hour,ip,url);
+       if (source[0] && list[0])
+               fprintf(fp_ou,"%s/%s\n",source,list);
+       else if (source[0])
+               fprintf(fp_ou,"%s\n",source);
+       else
+               fprintf(fp_ou,"%s\n",list);
+       redirector_count++;
+}
+
+static void read_log(const char *wentp, FILE *fp_ou,int dfrom,int duntil)
+{
+       FILE *fp_in = NULL;
+       char *buf;
+       int  i;
        longline line;
 
        if(debug) {
@@ -100,158 +273,7 @@ static void read_log(const char *wentp, FILE *fp_ou,int dfrom,int duntil)
        }
 
        while ((buf=longline_read(fp_in,line)) != NULL) {
-               getword_start(&gwarea,buf);
-               if(RedirectorLogFormat[0] != '\0') {
-                       getword_start(&gwarea1,RedirectorLogFormat);
-                       leks[0]='\0';
-                       if (getword(leks,sizeof(leks),&gwarea1,'#')<0) {
-                               debuga(_("Invalid \"redirector_log_format\" option in your sarg.conf (too many characters before first tag)\n"));
-                               exit(EXIT_FAILURE);
-                       }
-                       year=0;
-                       mon=0;
-                       day=0;
-                       hour[0]='\0';
-                       source[0]='\0';
-                       list[0]='\0';
-                       ip[0]='\0';
-                       user[0]='\0';
-                       full_url[0]='\0';
-                       while(strcmp(leks,"end") != 0) {
-                               if (getword(leks,sizeof(leks),&gwarea1,'#')<0) {
-                                       debuga(_("Invalid \"redirector_log_format\" option in your sarg.conf (missing # at end of tag)\n"));
-                                       exit(EXIT_FAILURE);
-                               }
-                               if (getword(sep,sizeof(sep),&gwarea1,'#')<0) {
-                                       debuga(_("Invalid \"redirector_log_format\" option in your sarg.conf (too many characters in column separator)\n"));
-                                       exit(EXIT_FAILURE);
-                               }
-                               if(strcmp(leks,"end") != 0) {
-                                       if (getword_limit(res,sizeof(res),&gwarea,sep[0])<0) {
-                                               debuga(_("Parsing of tag \"%s\" in redirector log %s returned no result\n"),leks,wentp);
-                                               exit(EXIT_FAILURE);
-                                       }
-                                       if(strcmp(leks,"year") == 0) {
-                                               year=atoi(res);
-                                       } else if(strcmp(leks,"mon") == 0) {
-                                               mon=atoi(res);
-                                       } else if(strcmp(leks,"day") == 0) {
-                                               day=atoi(res);
-                                       } else if(strcmp(leks,"hour") == 0) {
-                                               if (strlen(res)>=sizeof(hour)) {
-                                                       debuga(_("Hour string too long in redirector log file %s\n"),wentp);
-                                                       exit(EXIT_FAILURE);
-                                               }
-                                               strcpy(hour,res);
-                                       } else if(strcmp(leks,"source") == 0) {
-                                               if (strlen(res)>=sizeof(source)) {
-                                                       debuga(_("Banning source name too long in redirector log file %s\n"),wentp);
-                                                       exit(EXIT_FAILURE);
-                                               }
-                                               strcpy(source,res);
-                                       } else if(strcmp(leks,"list") == 0) {
-                                               if (strlen(res)>=sizeof(list)) {
-                                                       debuga(_("Banning list name too long in redirector log file %s\n"),wentp);
-                                                       exit(EXIT_FAILURE);
-                                               }
-                                               strcpy(list,res);
-                                       } else if(strcmp(leks,"ip") == 0) {
-                                               if (strlen(res)>=sizeof(ip)) {
-                                                       debuga(_("IP address too long in redirector log file %s\n"),wentp);
-                                                       exit(EXIT_FAILURE);
-                                               }
-                                               strcpy(ip,res);
-                                       } else if(strcmp(leks,"user") == 0) {
-                                               if (strlen(res)>=sizeof(user)) {
-                                                       debuga(_("User ID too long in redirector log file %s\n"),wentp);
-                                                       exit(EXIT_FAILURE);
-                                               }
-                                               strcpy(user,res);
-                                       } else if(strcmp(leks,"url") == 0) {
-                                               if (strlen(res)>=sizeof(full_url)) {
-                                                       debuga(_("URL too long in redirector log file %s\n"),wentp);
-                                                       exit(EXIT_FAILURE);
-                                               }
-                                               strcpy(full_url,res);
-                                       }
-                               }
-                       }
-               } else {
-                       if (getword_atoll(&lyear,&gwarea,'-')<0 || getword_atoll(&lmon,&gwarea,'-')<0 ||
-                           getword_atoll(&lday,&gwarea,' ')<0) {
-                               debuga(_("Invalid date found in file %s\n"),wentp);
-                               exit(EXIT_FAILURE);
-                       }
-                       year=(int)lyear;
-                       mon=(int)lmon;
-                       day=(int)lday;
-                       if (getword(hour,sizeof(hour),&gwarea,' ')<0) {
-                               debuga(_("Invalid time found in file %s\n"),wentp);
-                               exit(EXIT_FAILURE);
-                       }
-                       if (getword_skip(MAXLEN,&gwarea,'(')<0 || getword(source,sizeof(source),&gwarea,'/')<0) {
-                               debuga(_("Invalid redirected source in file %s\n"),wentp);
-                               exit(EXIT_FAILURE);
-                       }
-                       if (getword(list,sizeof(list),&gwarea,'/')<0) {
-                               debuga(_("Invalid redirected list in file %s\n"),wentp);
-                               exit(EXIT_FAILURE);
-                       }
-                       if (getword_skip(MAXLEN,&gwarea,' ')<0 || getword_limit(full_url,sizeof(full_url),&gwarea,' ')<0) {
-                               debuga(_("Invalid URL in file %s\n"),wentp);
-                               exit(EXIT_FAILURE);
-                       }
-                       if (getword(ip,sizeof(ip),&gwarea,'/')<0) {
-                               debuga(_("Invalid source IP in file %s\n"),wentp);
-                               exit(EXIT_FAILURE);
-                       }
-                       if (getword_skip(MAXLEN,&gwarea,' ')<0 || getword(user,sizeof(user),&gwarea,' ')<0) {
-                               debuga(_("Invalid user in file %s\n"),wentp);
-                               exit(EXIT_FAILURE);
-                       }
-               }
-               url=process_url(full_url,false);
-
-               //sprintf(warea,"%04d%02d%02d",year,mon,day);
-
-               if(RedirectorFilterOutDate) {
-                       idata = year*10000+mon*100+day;
-                       if(idata < dfrom || idata > duntil)
-                               continue;
-               }
-
-               if(UserIp) {
-                       strcpy(user,ip);
-                       id_is_ip=true;
-               } else {
-                       id_is_ip=false;
-                       if(strcmp(user,"-") == 0 || strcmp(user," ") == 0 || strcmp(user,"") == 0) {
-                               if(RecordsWithoutUser == RECORDWITHOUTUSER_IP) {
-                                       strcpy(user,ip);
-                                       id_is_ip=true;
-                               }
-                               if(RecordsWithoutUser == RECORDWITHOUTUSER_IGNORE)
-                                       continue;
-                               if(RecordsWithoutUser == RECORDWITHOUTUSER_EVERYBODY)
-                                       strcpy(user,"everybody");
-                       }
-               }
-               uinfo=userinfo_find_from_id(user);
-               if (!uinfo) {
-                       uinfo=userinfo_create(user);
-                       uinfo->id_is_ip=id_is_ip;
-                       uinfo->no_report=true;
-                       if(Ip2Name && id_is_ip) ip2name(user,sizeof(user));
-                       user_find(uinfo->label,MAX_USER_LEN, user);
-               }
-               fprintf(fp_ou,"%s\t%04d%02d%02d\t%s\t%s\t%s\t",uinfo->id,year,mon,day,hour,ip,url);
-               if (source[0] && list[0])
-                       fprintf(fp_ou,"%s/%s\n",source,list);
-               else if (source[0])
-                       fprintf(fp_ou,"%s\n",source);
-               else
-                       fprintf(fp_ou,"%s\n",list);
-               redirector_count++;
+               parse_log(fp_ou,buf);
        }
        fclose(fp_in);
        longline_destroy(&line);
@@ -539,7 +561,16 @@ void redirector_report(void)
        if(count>SquidGuardReportLimit && SquidGuardReportLimit>0)
                show_ignored_redirector(fp_ou,count-SquidGuardReportLimit);
 
-       fputs("</table></div>\n",fp_ou);
+       fputs("</table>\n",fp_ou);
+       
+       if (RedirectorErrors>0)
+       {
+               fputs("<div class=\"warn\"><span>",fp_ou);
+               fprintf(fp_ou,ngettext("%d error found in the log file. Some entries may be missing.","%d errors found in the log file. Some entries may be missing.",RedirectorErrors),RedirectorErrors);
+               fputs("</span></div>\n",fp_ou);
+       }
+       
+       fputs("</div>\n",fp_ou);
        if (write_html_trailer(fp_ou)<0)
                debuga(_("Write error in file %s\n"),report);
        if (fclose(fp_ou)==EOF)