]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Merge squidguard_log.c and squidguard_report.c into one file
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Sun, 19 Jun 2011 19:34:15 +0000 (19:34 +0000)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Sun, 19 Jun 2011 19:34:15 +0000 (19:34 +0000)
The functions are renamed to make them less specific to squidGuard as
they are compatible with other redirectors.

CMakeLists.txt
Makefile.in
include/conf.h
include/defs.h
log.c
redirector.c [moved from squidguard_log.c with 72% similarity]
report.c
topuser.c

index 1a77f8ebb277efcfc48242b4ad133e1039848f89..a5767c5d9b3e106588bc6878709f8f83cffdbbb6 100755 (executable)
@@ -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)
 
index ef341fa8911ce1e48b694bcaa6fbf78e7a518b2b..332a58778a774ea7fdbfed4f3ce132efcd9a50d7 100644 (file)
@@ -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
 
index 4247761ad9ecca2c089f0827fadd8b370567069c..6a01414f6086c437366bc95f14b7f134bcb4126e 100755 (executable)
@@ -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;
index 7c9e508f8deaa2bf37271a7742e9d32851fe72a2..8003cccb33ed2ac7ff7d95c3a17a6e8894bf0dab 100755 (executable)
@@ -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 e4d6cd0226537ee15367ae577990859db2892bd9..bfa26c60064cbbe6bd65d4c8334d06f8f02eface 100644 (file)
--- 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;
similarity index 72%
rename from squidguard_log.c
rename to redirector.c
index e46141838f9226ed1451cbbff523303ef1e1a65d..b7cc4137b788a1bcaee35bca05ed4d81562ef196 100644 (file)
@@ -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("<tr><td class=\"header_c\">",fp_ou);
+       fprintf(fp_ou,_("Period: %s"),period.html);
+       fputs("</td></tr>\n",fp_ou);
+       fprintf(fp_ou,"<tr><th class=\"header_c\">%s</th></tr>\n",_("Redirector report"));
+       close_html_header(fp_ou);
+
+       fputs("<div class=\"report\"><table cellpadding=1 cellspacing=2>\n",fp_ou);
+       fprintf(fp_ou,"<tr><th class=\"header_l\">%s</th><th class=\"header_l\">%s</th><th class=\"header_l\">%s</th><th class=\"header_l\">%s</th><th class=\"header_l\">%s</th></tr>\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,"<tr><td class=\"data2\">%s</td><td class=\"data2\">%s</td>",uinfo->label,ip);
+               else
+                       fputs("<tr><td class=\"data2\"></td><td class=\"data2\"></td>",fp_ou);
+               fprintf(fp_ou,"<td class=\"data2\">%s-%s</td><td class=\"data2\">",data,hora);
+               output_html_link(fp_ou,url,100);
+               fprintf(fp_ou,"</td><td class=\"data2\">%s</td></tr>\n",rule);
+       }
+       fclose(fp_in);
+       longline_destroy(&line);
+
+       fputs("</table></div>\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;
+}
index d1d9a8c2f830db175e3a506b87740d7679841850..8dcc838bfc9ff8fed9cfdffe0ac995d88b22d394 100644 (file)
--- 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();
                }
index 4394eec9e09f9fac318b1bee9e2bd348b696a038..2e5d348152ad7f243f7791969adeec7bb2eb81c9 100644 (file)
--- a/topuser.c
+++ b/topuser.c
@@ -210,7 +210,7 @@ void topuser(void)
                if((ReportType & REPORT_TYPE_TOPSITES) != 0 && !Privacy) fprintf(fp_top3,"<tr><td class=\"link\" colspan=\"0\"><a href=\"topsites.html\">%s</a></td></tr>\n",_("Top sites"));
                if((ReportType & REPORT_TYPE_SITES_USERS) != 0 && !Privacy) fprintf(fp_top3,"<tr><td class=\"link\" colspan=\"0\"><a href=\"siteuser.html\">%s</a></td></tr>\n",_("Sites & Users"));
                if(dansguardian_count) fprintf(fp_top3,"<tr><td class=\"link\" colspan=\"0\"><a href=\"dansguardian.html\">%s</a></td></tr>\n",_("DansGuardian"));
-               if(squidguard_count) fprintf(fp_top3,"<tr><td class=\"link\" colspan=\"0\"><a href=\"redirector.html\">%s</a></td></tr>\n",_("Redirector"));
+               if(redirector_count) fprintf(fp_top3,"<tr><td class=\"link\" colspan=\"0\"><a href=\"redirector.html\">%s</a></td></tr>\n",_("Redirector"));
                if ((ReportType & REPORT_TYPE_DOWNLOADS) != 0 && download_count && !Privacy && ndownload) fprintf(fp_top3,"<tr><td class=\"link\" colspan=\"0\"><a href=\"download.html\">%s</a></td></tr>\n",_("Downloads"));
                if ((ReportType & REPORT_TYPE_DENIED) != 0 && denied_count && !Privacy) fprintf(fp_top3,"<tr><td class=\"link\" colspan=\"0\"><a href=\"denied.html\">%s</a></td></tr>\n",_("Denied accesses"));
                if ((ReportType & REPORT_TYPE_AUTH_FAILURES) != 0 && authfail_count && !Privacy) fprintf(fp_top3,"<tr><td class=\"link\" colspan=\"0\"><a href=\"authfail.html\">%s</a></td></tr>\n",_("Authentication Failures"));