From: Frédéric Marchal Date: Sun, 19 Jun 2011 19:34:15 +0000 (+0000) Subject: Merge squidguard_log.c and squidguard_report.c into one file X-Git-Tag: v2.3.2~50 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=330b1c527a95ba11a293877f7c273864bc452b94;p=thirdparty%2Fsarg.git Merge squidguard_log.c and squidguard_report.c into one file The functions are renamed to make them less specific to squidGuard as they are compatible with other redirectors. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 1a77f8e..a5767c5 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,7 +51,7 @@ SET(SRC util.c log.c report.c topuser.c email.c sort.c html.c useragent.c exclude.c convlog.c totday.c repday.c datafile.c indexonly.c splitlog.c lastlog.c topsites.c siteuser.c css.c smartfilter.c denied.c authfail.c charset.c - squidguard_log.c squidguard_report.c auth.c download.c grepday.c + redirector.c auth.c download.c grepday.c dansguardian_log.c dansguardian_report.c realtime.c btree_cache.c usertab.c userinfo.c longline.c url.c) diff --git a/Makefile.in b/Makefile.in index ef341fa..332a587 100644 --- a/Makefile.in +++ b/Makefile.in @@ -36,7 +36,7 @@ SRCS = util.c log.c report.c topuser.c email.c sort.c html.c \ useragent.c exclude.c convlog.c totday.c repday.c datafile.c\ indexonly.c splitlog.c lastlog.c topsites.c siteuser.c css.c \ smartfilter.c denied.c authfail.c charset.c \ - squidguard_log.c squidguard_report.c auth.c download.c grepday.c \ + redirector.c auth.c download.c grepday.c \ dansguardian_log.c dansguardian_report.c realtime.c btree_cache.c \ usertab.c userinfo.c longline.c url.c diff --git a/include/conf.h b/include/conf.h index 4247761..6a01414 100755 --- a/include/conf.h +++ b/include/conf.h @@ -439,7 +439,7 @@ int denied_count; int download_count; int authfail_count; int dansguardian_count; -int squidguard_count; +int redirector_count; int useragent_count; int limit_flag; int z1, z2, z3; diff --git a/include/defs.h b/include/defs.h index 7c9e508..8003ccc 100755 --- a/include/defs.h +++ b/include/defs.h @@ -153,6 +153,10 @@ void make_index(void); // realtime.c void realtime(void); +// redirector.c +void redirector_log(void); +void redirector_report(void); + // repday.c void report_day(const struct userinfostruct *user); @@ -175,12 +179,6 @@ void sort_labels(const char **label,const char **order); // splitlog.c void splitlog(const char *arq, const char *df, int dfrom, int duntil, int convert, const char *splitprefix); -// squidguard_log.c -void squidguard_log(void); - -// squidguard_report.c -void squidguard_report(void); - // topsites.c void topsites(void); diff --git a/log.c b/log.c index e4d6cd0..bfa26c6 100644 --- a/log.c +++ b/log.c @@ -332,7 +332,7 @@ int main(int argc,char *argv[]) download_count=0; authfail_count=0; dansguardian_count=0; - squidguard_count=0; + redirector_count=0; useragent_count=0; DeniedReportLimit=10; AuthfailReportLimit=10; diff --git a/squidguard_log.c b/redirector.c similarity index 72% rename from squidguard_log.c rename to redirector.c index e461418..b7cc413 100644 --- a/squidguard_log.c +++ b/redirector.c @@ -251,7 +251,7 @@ static void read_log(const char *wentp, FILE *fp_ou,int dfrom,int duntil) fprintf(fp_ou,"%s\n",source); else fprintf(fp_ou,"%s\n",list); - squidguard_count++; + redirector_count++; } fclose(fp_in); longline_destroy(&line); @@ -259,7 +259,7 @@ static void read_log(const char *wentp, FILE *fp_ou,int dfrom,int duntil) } -void squidguard_log(void) +void redirector_log(void) { FILE *fp_ou = NULL, *fp_guard = NULL; char buf[MAXLEN]; @@ -381,3 +381,158 @@ void squidguard_log(void) } return; } + +void redirector_report(void) +{ + FILE *fp_in = NULL, *fp_ou = NULL; + + char *buf; + char *url; + char squidguard_in[MAXLEN]; + char report[MAXLEN]; + char ip[45]; + char rule[255]; + char oip[45]; + char user[MAXLEN]; + char ouser[MAXLEN]; + char data[15]; + char hora[15]; + char ouser2[255]; + char oname[MAXLEN]; + bool z=false; + int count=0; + long long int data2; + bool new_user; + struct getwordstruct gwarea; + const struct userinfostruct *uinfo; + struct tm t; + longline line; + + ouser[0]='\0'; + ouser2[0]='\0'; + + sprintf(squidguard_in,"%s/redirector.log",tmp); + if(!redirector_count) { + unlink(squidguard_in); + return; + } + + snprintf(report,sizeof(report),"%s/redirector.html",outdirname); + + if((fp_in=fopen(squidguard_in,"r"))==NULL) { + debuga(_("(squidguard) Cannot open log file %s\n"),squidguard_in); + exit(EXIT_FAILURE); + } + + if((fp_ou=fopen(report,"w"))==NULL) { + debuga(_("(squidguard) Cannot open log file %s\n"),report); + exit(EXIT_FAILURE); + } + + if ((line=longline_create())==NULL) { + debuga(_("Not enough memory to read the processed redirector log\n")); + exit(EXIT_FAILURE); + } + + write_html_header(fp_ou,(IndexTree == INDEX_TREE_DATE) ? 3 : 1,_("Redirector report"),HTML_JS_NONE); + fputs("",fp_ou); + fprintf(fp_ou,_("Period: %s"),period.html); + fputs("\n",fp_ou); + fprintf(fp_ou,"%s\n",_("Redirector report")); + close_html_header(fp_ou); + + fputs("
\n",fp_ou); + fprintf(fp_ou,"\n",_("USERID"),_("IP/NAME"),_("DATE/TIME"),_("ACCESSED SITE"),_("RULE")); + + while((buf=longline_read(fp_in,line))!=NULL) { + getword_start(&gwarea,buf); + if (getword(user,sizeof(user),&gwarea,'\t')<0) { + debuga(_("Invalid user in file %s\n"),squidguard_in); + exit(EXIT_FAILURE); + } + if (getword_atoll(&data2,&gwarea,'\t')<0) { + debuga(_("Invalid date in file %s\n"),squidguard_in); + exit(EXIT_FAILURE); + } + if (getword(hora,sizeof(hora),&gwarea,'\t')<0) { + debuga(_("Invalid time in file %s\n"),squidguard_in); + exit(EXIT_FAILURE); + } + if (getword(ip,sizeof(ip),&gwarea,'\t')<0) { + debuga(_("Invalid IP address in file %s\n"),squidguard_in); + exit(EXIT_FAILURE); + } + if (getword_ptr(buf,&url,&gwarea,'\t')<0) { + debuga(_("Invalid URL in file %s\n"),squidguard_in); + exit(EXIT_FAILURE); + } + if (getword(rule,sizeof(rule),&gwarea,'\n')<0) { + debuga(_("Invalid rule in file %s\n"),squidguard_in); + exit(EXIT_FAILURE); + } + + uinfo=userinfo_find_from_id(user); + if (!uinfo) { + debuga(_("Unknown user ID %s in file %s\n"),user,squidguard_in); + exit(EXIT_FAILURE); + } + + computedate(data2/10000,(data2/100)%10,data2%100,&t); + strftime(data,sizeof(data),"%x",&t); + + new_user=false; + if(!z) { + strcpy(ouser,user); + strcpy(oip,ip); + strcpy(oname,ip); + if (Ip2Name && !uinfo->id_is_ip) ip2name(oname,sizeof(oname)); + z=true; + new_user=true; + } else { + if(strcmp(ouser,user) != 0) { + strcpy(ouser,user); + new_user=true; + } + if(strcmp(oip,ip) != 0) { + strcpy(oip,ip); + strcpy(oname,ip); + if (Ip2Name && !uinfo->id_is_ip) ip2name(oname,sizeof(oname)); + new_user=true; + } + } + + if(SquidGuardReportLimit) { + if(strcmp(ouser2,uinfo->label) == 0) { + count++; + } else { + count=1; + strcpy(ouser2,uinfo->label); + } + if(count >= SquidGuardReportLimit) + continue; + } + + if (new_user) + fprintf(fp_ou,"",uinfo->label,ip); + else + fputs("",fp_ou); + fprintf(fp_ou,"\n",rule); + } + fclose(fp_in); + longline_destroy(&line); + + fputs("
%s%s%s%s%s
%s%s
%s-%s",data,hora); + output_html_link(fp_ou,url,100); + fprintf(fp_ou,"%s
\n",fp_ou); + if (write_html_trailer(fp_ou)<0) + debuga(_("Write error in file %s\n"),report); + if (fclose(fp_ou)==EOF) + debuga(_("Failed to close file %s - %s\n"),report,strerror(errno)); + + if (unlink(squidguard_in)) { + debuga(_("Cannot delete %s - %s\n"),squidguard_in,strerror(errno)); + exit(EXIT_FAILURE); + } + + return; +} diff --git a/report.c b/report.c index d1d9a8c..8dcc838 100644 --- a/report.c +++ b/report.c @@ -359,7 +359,7 @@ void gerarel(void) dansguardian_log(); } - squidguard_log(); + redirector_log(); } topuser(); @@ -376,7 +376,7 @@ void gerarel(void) if(DansGuardianConf[0] != '\0') dansguardian_report(); - squidguard_report(); + redirector_report(); if((ReportType & REPORT_TYPE_USERS_SITES) != 0) htmlrel(); } diff --git a/topuser.c b/topuser.c index 4394eec..2e5d348 100644 --- a/topuser.c +++ b/topuser.c @@ -210,7 +210,7 @@ void topuser(void) if((ReportType & REPORT_TYPE_TOPSITES) != 0 && !Privacy) fprintf(fp_top3,"%s\n",_("Top sites")); if((ReportType & REPORT_TYPE_SITES_USERS) != 0 && !Privacy) fprintf(fp_top3,"%s\n",_("Sites & Users")); if(dansguardian_count) fprintf(fp_top3,"%s\n",_("DansGuardian")); - if(squidguard_count) fprintf(fp_top3,"%s\n",_("Redirector")); + if(redirector_count) fprintf(fp_top3,"%s\n",_("Redirector")); if ((ReportType & REPORT_TYPE_DOWNLOADS) != 0 && download_count && !Privacy && ndownload) fprintf(fp_top3,"%s\n",_("Downloads")); if ((ReportType & REPORT_TYPE_DENIED) != 0 && denied_count && !Privacy) fprintf(fp_top3,"%s\n",_("Denied accesses")); if ((ReportType & REPORT_TYPE_AUTH_FAILURES) != 0 && authfail_count && !Privacy) fprintf(fp_top3,"%s\n",_("Authentication Failures"));