]> git.ipfire.org Git - thirdparty/sarg.git/blobdiff - smartfilter.c
More messages merged to reduce the number of messages to translate.
[thirdparty/sarg.git] / smartfilter.c
index 32661dae29b3afec4bbc867d50cbd6f78843ad46..df900f2f9639e63cf1e45b457127d9865699145e 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * SARG Squid Analysis Report Generator      http://sarg.sourceforge.net
- *                                                            1998, 2011
+ *                                                            1998, 2013
  *
  * SARG donations:
  *      please look at http://sarg.sourceforge.net/donations.php
@@ -44,23 +44,34 @@ void smartfilter_report(void)
        char data[15];
        char hora[15];
        char smartcat[256];
-       char smartheader[15];
        char ftime[128];
        char smartuser[MAXLEN];
-       int  fuser=0;
        int cstatus;
        struct getwordstruct gwarea;
        const struct userinfostruct *uinfo;
 
        ouser[0]='\0';
 
-       strcpy(smartheader,_("SmartFilter"));
-       strup(smartheader);
-
-       sprintf(smart_in,"%s/smartfilter.unsort",outdirname);
-       sprintf(sites,"%s/sarg-sites",outdirname);
-       sprintf(smart_ou,"%s/smartfilter.log",outdirname);
-       sprintf(report,"%s/smartfilter.html",outdirname);
+       if (snprintf(smart_in,sizeof(smart_in),"%s/smartfilter.int_unsort",tmp)>=sizeof(smart_in)) {
+               debuga(_("Path too long: "));
+               debuga_more("%s/smartfilter.int_unsort\n",tmp);
+               exit(EXIT_FAILURE);
+       }
+       if (snprintf(sites,sizeof(sites),"%s/sarg-sites",outdirname)>=sizeof(sites)) {
+               debuga(_("Path too long: "));
+               debuga_more("%s/sarg-sites\n",outdirname);
+               exit(EXIT_FAILURE);
+       }
+       if (snprintf(smart_ou,sizeof(smart_ou),"%s/smartfilter.int_log",tmp)>=sizeof(smart_ou)) {
+               debuga(_("Path too long: "));
+               debuga_more("%s/smartfilter.int_log\n",tmp);
+               exit(EXIT_FAILURE);
+       }
+       if (snprintf(report,sizeof(report),"%s/smartfilter.html",outdirname)>=sizeof(report)) {
+               debuga(_("Path too long: "));
+               debuga_more("%s/smartfilter.html\n",outdirname);
+               exit(EXIT_FAILURE);
+       }
 
        if (snprintf(csort,sizeof(csort),"sort -n -t \"\t\" -k 1,1 -k 2,2 -k 3,3 -o \"%s\" \"%s\"",smart_ou,smart_in)>=sizeof(csort)) {
                debuga(_("cannot build the sort command to sort file %s\n"),smart_in);
@@ -73,17 +84,17 @@ void smartfilter_report(void)
                exit(EXIT_FAILURE);
        }
        if((fp_in=fopen(smart_ou,"r"))==NULL) {
-               debuga(_("(smartfilter) Cannot open log file %s\n"),smart_ou);
+               debuga(_("Cannot open file \"%s\": %s\n"),smart_ou,strerror(errno));
                debuga(_("sort command: %s\n"),csort);
                exit(EXIT_FAILURE);
        }
-       if (unlink(smart_in)) {
-               debuga(_("Cannot delete %s - %s\n"),smart_in,strerror(errno));
+       if (!KeepTempLog && unlink(smart_in)) {
+               debuga(_("Cannot delete \"%s\": %s\n"),smart_in,strerror(errno));
                exit(EXIT_FAILURE);
        }
 
        if((fp_ou=fopen(report,"w"))==NULL) {
-               debuga(_("(smartfilter) Cannot open log file %s\n"),report);
+               debuga(_("Cannot open file \"%s\": %s\n"),report,strerror(errno));
                exit(EXIT_FAILURE);
        }
 
@@ -105,7 +116,7 @@ void smartfilter_report(void)
        fputs("<tr><td></td></tr>\n",fp_ou);
        fputs("<tr><td></td></tr>\n",fp_ou);
        fputs("<tr><td></td></tr>\n",fp_ou);
-       fprintf(fp_ou,"<tr><th bgcolor=%s><font size=\"%s\">%s</font></th><th bgcolor=\"%s\"><font size=\"%s\">%s</font></th><th bgcolor=\"%s\"><font size=\"%s\">%s</font></th><th bgcolor=\"%s\"><font size=\"%s\">%s</font></th><th bgcolor=\"%s\"><font size=\"%s\">%s</font></th></tr>\n",HeaderBgColor,FontSize,_("USERID"),HeaderBgColor,FontSize,_("IP/NAME"),HeaderBgColor,FontSize,_("DATE/TIME"),HeaderBgColor,FontSize,_("ACCESSED SITE"),HeaderBgColor,FontSize,smartheader);
+       fprintf(fp_ou,"<tr><th bgcolor=%s><font size=\"%s\">%s</font></th><th bgcolor=\"%s\"><font size=\"%s\">%s</font></th><th bgcolor=\"%s\"><font size=\"%s\">%s</font></th><th bgcolor=\"%s\"><font size=\"%s\">%s</font></th><th bgcolor=\"%s\"><font size=\"%s\">%s</font></th></tr>\n",HeaderBgColor,FontSize,_("USERID"),HeaderBgColor,FontSize,_("IP/NAME"),HeaderBgColor,FontSize,_("DATE/TIME"),HeaderBgColor,FontSize,_("ACCESSED SITE"),HeaderBgColor,FontSize,_("SMARTFILTER"));
 
        while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
                getword_start(&gwarea,buf);
@@ -124,21 +135,25 @@ void smartfilter_report(void)
                if(strcmp(ouser,user) != 0) {
                        strcpy(ouser,user);
                        sprintf(smartuser,"%s/denied_%s.html",outdirname,uinfo->filename);
-                       if(fuser) {
-                               fuser=0;
+                       if (fp_user) {
                                fputs("</table>\n",fp_user);
                                if(ShowSargInfo) {
-                                       zdate(ftime, sizeof(ftime), DateFormat);
-                                       fprintf(fp_user,"<br><br><div align=\"center\"><font size=\"-2\">%s <a href=\"%s\">%s-%s</a> %s %s</font></div>\n",_("Generated by"),URL,PGM,VERSION,_("on"),ftime);
+                                       zdate(ftime, sizeof(ftime), df);
+                                       fputs("<br><br><div align=\"center\"><font size=\"-2\">",fp_user);
+                                       fprintf(fp_user,_("Generated by <a href=\"%s\">%s-%s</a> on %s"),URL,PGM,VERSION,ftime);
+                                       fputs("</font></div>\n",fp_user);
                                }
                                fputs("</body>\n</html>\n",fp_user);
-                               fclose(fp_user);
+                               if (fclose(fp_user)==EOF) {
+                                       debuga(_("Write error in \"%s\": %s\n"),smartuser,strerror(errno));
+                                       exit(EXIT_FAILURE);
+                               }
+                               fp_user=NULL;
                        }
                        if ((fp_user = fopen(smartuser, "a")) == 0) {
-                               debuga(_("(smartfilter) Cannot open file %s\n"),smartuser);
+                               debuga(_("Cannot open file \"%s\": %s\n"),smartuser,strerror(errno));
                                exit(EXIT_FAILURE);
                        }
-                       fuser=1;
 
                        fputs("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"",fp_ou);
                        fputs(" \"http://www.w3.org/TR/html4/loose.dtd\">\n",fp_ou);
@@ -172,7 +187,7 @@ void smartfilter_report(void)
                        fputs("<tr><td></td></tr>\n",fp_user);
                        fputs("<tr><td></td></tr>\n",fp_user);
                        fputs("<tr><td></td></tr>\n",fp_user);
-                       fprintf(fp_user,"<tr><th bgcolor=%s><font size=%s>%s</font></th><th bgcolor=%s><font size=%s>%s</font></th><th bgcolor=%s><font size=%s>%s</font></th><th bgcolor=%s><font size=%s>%s</font></th><th bgcolor=%s><font size=%s>%s</font></th></tr>\n",HeaderBgColor,FontSize,_("USERID"),HeaderBgColor,FontSize,_("IP/NAME"),HeaderBgColor,FontSize,_("DATE/TIME"),HeaderBgColor,FontSize,_("ACCESSED SITE"),HeaderBgColor,FontSize,smartheader);
+                       fprintf(fp_user,"<tr><th bgcolor=%s><font size=%s>%s</font></th><th bgcolor=%s><font size=%s>%s</font></th><th bgcolor=%s><font size=%s>%s</font></th><th bgcolor=%s><font size=%s>%s</font></th><th bgcolor=%s><font size=%s>%s</font></th></tr>\n",HeaderBgColor,FontSize,_("USERID"),HeaderBgColor,FontSize,_("IP/NAME"),HeaderBgColor,FontSize,_("DATE/TIME"),HeaderBgColor,FontSize,_("ACCESSED SITE"),HeaderBgColor,FontSize,_("SMARTFILTER"));
                }
                fprintf(fp_user,"<tr><td bgcolor=%s align=center><font size=%s>%s</font></td><td bgcolor=%s align=center><font size=%s>%s</font></td><td bgcolor=%s align=center><font size=%s>%s-%s</font></td><td bgcolor=%s><font size=%s>%s</font></td><td bgcolor=%s><font size=%s>%s</font></td></th>\n",TxBgColor,FontSize,uinfo->label,TxBgColor,FontSize,ip,TxBgColor,FontSize,data,hora,TxBgColor,FontSize,url,TxBgColor,FontSize,smartcat);
 
@@ -182,21 +197,36 @@ void smartfilter_report(void)
        fputs("</table>\n",fp_ou);
 
        if(ShowSargInfo) {
-               zdate(ftime, sizeof(ftime), DateFormat);
-               fprintf(fp_ou,"<br><br><div align=\"center\"><font size=\"-2\">%s <a href=\"%s\">%s-%s</a> %s %s</font></div>\n",_("Generated by"),URL,PGM,VERSION,_("on"),ftime);
+               zdate(ftime, sizeof(ftime), df);
+               fputs("<br><br><div align=\"center\"><font size=\"-2\">",fp_ou);
+               fprintf(fp_ou,_("Generated by <a href=\"%s\">%s-%s</a> on %s"),URL,PGM,VERSION,ftime);
+               fputs("</font></div>\n",fp_ou);
        }
 
        fputs("</body>\n</html>\n",fp_user);
 
-       fclose(fp_ou);
+       if (fclose(fp_ou)==EOF) {
+               debuga(_("Write error in \"%s\": %s\n"),report,strerror(errno));
+               exit(EXIT_FAILURE);
+       }
        if(fp_user) {
                fputs("</table>\n",fp_user);
                if(ShowSargInfo) {
-                       zdate(ftime, sizeof(ftime), DateFormat);
-                       fprintf(fp_user,"<br><br><div align=\"center\"><font size=\"-2\">%s <a href=\"%s\">%s-%s</a> %s %s</font></div>\n",_("Generated by"),URL,PGM,VERSION,_("on"),ftime);
+                       zdate(ftime, sizeof(ftime), df);
+                       fputs("<br><br><div align=\"center\"><font size=\"-2\">",fp_user);
+                       fprintf(fp_user,_("Generated by <a href=\"%s\">%s-%s</a> on %s"),URL,PGM,VERSION,ftime);
+                       fputs("</font></div>\n",fp_user);
                }
                fputs("</body>\n</html>\n",fp_user);
-               fclose(fp_user);
+               if (fclose(fp_user)==EOF) {
+                       debuga(_("Write error in \"%s\": %s\n"),smartuser,strerror(errno));
+                       exit(EXIT_FAILURE);
+               }
+       }
+
+       if (!KeepTempLog && unlink(smart_ou)) {
+               debuga(_("Cannot delete \"%s\": %s\n"),smart_ou,strerror(errno));
+               exit(EXIT_FAILURE);
        }
 
        return;