From: Frédéric Marchal Date: Sun, 15 Jul 2012 12:34:52 +0000 (+0200) Subject: Keep temporary files in place for inspection X-Git-Tag: v2.3.3~43 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=11767c6a54b6fa5bac8308aef639b0be7ce2afb5;p=thirdparty%2Fsarg.git Keep temporary files in place for inspection Add a command line option and a configuration tag to leave the temporary files in place when sarg terminates. The feature is for debugging purpose. It cannot be used for production. --- diff --git a/authfail.c b/authfail.c index b390202..8e3b958 100644 --- a/authfail.c +++ b/authfail.c @@ -71,7 +71,9 @@ void authfail_report(void) snprintf(tmp4,sizeof(tmp4),"%s/authfail.int_unsort",tmp); if(authfail_count == 0) { - unlink(tmp4); + if (!KeepTempLog && unlink(tmp4)) { + debuga(_("Cannot delete \"%s\": %s\n"),tmp4,strerror(errno)); + } if (debugz) debugaz(_("Authentication failures report not produced because it is empty\n")); return; } @@ -91,8 +93,8 @@ void authfail_report(void) debuga(_("sort command: %s\n"),csort); exit(EXIT_FAILURE); } - if (unlink(tmp4)) { - debuga(_("Cannot delete %s - %s\n"),tmp4,strerror(errno)); + if (!KeepTempLog && unlink(tmp4)) { + debuga(_("Cannot delete \"%s\": %s\n"),tmp4,strerror(errno)); exit(EXIT_FAILURE); } @@ -204,8 +206,8 @@ void authfail_report(void) if (fclose(fp_ou)==EOF) debuga(_("Failed to close file %s - %s\n"),report,strerror(errno)); - if (unlink(authfail_in)) { - debuga(_("Cannot delete %s - %s\n"),authfail_in,strerror(errno)); + if (!KeepTempLog && unlink(authfail_in)) { + debuga(_("Cannot delete \"%s\": %s\n"),authfail_in,strerror(errno)); exit(EXIT_FAILURE); } diff --git a/dansguardian_log.c b/dansguardian_log.c index be13b86..69e37b6 100644 --- a/dansguardian_log.c +++ b/dansguardian_log.c @@ -154,8 +154,8 @@ void dansguardian_log(void) debuga(_("sort command: %s\n"),tmp6); exit(EXIT_FAILURE); } - if (unlink(guard_in)) { - debuga(_("Cannot delete %s - %s\n"),guard_in,strerror(errno)); + if (!KeepTempLog && unlink(guard_in)) { + debuga(_("Cannot delete \"%s\": %s\n"),guard_in,strerror(errno)); exit(EXIT_FAILURE); } } diff --git a/dansguardian_report.c b/dansguardian_report.c index f326226..4405a81 100644 --- a/dansguardian_report.c +++ b/dansguardian_report.c @@ -60,7 +60,8 @@ void dansguardian_report(void) snprintf(dansguardian_in,sizeof(dansguardian_in),"%s/dansguardian.int_log",tmp); if(!dansguardian_count) { - unlink(dansguardian_in); + if (!KeepTempLog && unlink(dansguardian_in)) + debuga(_("Cannot delete \"%s\": %s\n"),dansguardian_in,strerror(errno)); if (debugz) debugaz(_("Dansguardian report not generated because it is empty\n")); return; } @@ -169,8 +170,8 @@ void dansguardian_report(void) if (fclose(fp_ou)==EOF) debuga(_("Failed to close file %s - %s\n"),report,strerror(errno)); - if (unlink(dansguardian_in)) { - debuga(_("Cannot delete %s - %s\n"),dansguardian_in,strerror(errno)); + if (!KeepTempLog && unlink(dansguardian_in)) { + debuga(_("Cannot delete \"%s\": %s\n"),dansguardian_in,strerror(errno)); exit(EXIT_FAILURE); } diff --git a/denied.c b/denied.c index 8b76517..76b71af 100644 --- a/denied.c +++ b/denied.c @@ -64,7 +64,8 @@ void gen_denied_report(void) sprintf(denied_in,"%s/denied.int_log",tmp); if (!denied_count) { - unlink(denied_in); + if (!KeepTempLog && unlink(denied_in)) + debuga(_("Cannot delete \"%s\": %s\n"),denied_in,strerror(errno)); if (debugz) debugaz(_("Denied report not produced because it is empty\n")); return; } @@ -176,8 +177,8 @@ void gen_denied_report(void) if (fclose(fp_ou)<0) debuga(_("Failed to close file %s - %s\n"),report,strerror(errno)); - if (unlink(denied_in)==-1) - debuga(_("Failed to delete the file \"%s\" after processing it - %s\n"),denied_in,strerror(errno)); + if (!KeepTempLog && unlink(denied_in)==-1) + debuga(_("Cannot delete \"%s\": %s\n"),denied_in,strerror(errno)); return; } diff --git a/download.c b/download.c index 83b4191..d914782 100644 --- a/download.c +++ b/download.c @@ -75,8 +75,8 @@ static void download_sort(const char *report_in) debuga(_("Path too long for %s/download.int_unsort\n"),tmp); exit(EXIT_FAILURE); } - if (unlink(csort)) { - debuga(_("Cannot delete %s - %s\n"),csort,strerror(errno)); + if (!KeepTempLog && unlink(csort)) { + debuga(_("Cannot delete \"%s\": %s\n"),csort,strerror(errno)); exit(EXIT_FAILURE); } } @@ -230,8 +230,8 @@ void download_report(void) if (fclose(fp_ou)==EOF) debuga(_("Failed to close file %s - %s\n"),report,strerror(errno)); - if (unlink(report_in)) { - debuga(_("Cannot delete %s - %s\n"),report_in,strerror(errno)); + if (!KeepTempLog && unlink(report_in)) { + debuga(_("Cannot delete \"%s\": %s\n"),report_in,strerror(errno)); exit(EXIT_FAILURE); } diff --git a/email.c b/email.c index df4f931..e8b0286 100644 --- a/email.c +++ b/email.c @@ -142,8 +142,8 @@ int geramail(const char *dirname, int debug, const char *outdir, const char *ema exit(EXIT_FAILURE); } - if (unlink(top2)) { - debuga(_("Cannot delete %s - %s\n"),top2,strerror(errno)); + if (!KeepTempLog && unlink(top2)) { + debuga(_("Cannot delete \"%s\": %s\n"),top2,strerror(errno)); exit(EXIT_FAILURE); } @@ -253,8 +253,8 @@ int geramail(const char *dirname, int debug, const char *outdir, const char *ema #endif fclose(fp_top1); - if (unlink(top1)) { - debuga(_("Cannot delete %s - %s\n"),top1,strerror(errno)); + if (!KeepTempLog && unlink(top1)) { + debuga(_("Cannot delete \"%s\": %s\n"),top1,strerror(errno)); exit(EXIT_FAILURE); } diff --git a/getconf.c b/getconf.c index efa1fe6..e338310 100644 --- a/getconf.c +++ b/getconf.c @@ -748,6 +748,8 @@ static void parmtest(char *buf) if (getparam_string("sorttable",buf,SortTableJs,sizeof(SortTableJs))>0) return; if (getparam_string("hostalias",buf,HostAliasFile,sizeof(HostAliasFile))>0) return; + + if (getparam_bool("keep_temp_log",buf,&KeepTempLog)>0) return; if(strstr(buf,"squid24") != 0) { squid24=true; diff --git a/grepday.c b/grepday.c index 42935f1..84ad311 100644 --- a/grepday.c +++ b/grepday.c @@ -683,7 +683,8 @@ void greport_day(const struct userinfostruct *uinfo) return; } if(!Graphs || GraphFont[0]=='\0') { - unlink(wdirname); + if (!KeepTempLog && unlink(wdirname)) + debuga(_("Cannot delete \"%s\": %s\n"),wdirname,strerror(errno)); return; } @@ -724,8 +725,8 @@ void greport_day(const struct userinfostruct *uinfo) } } fclose(fp_in); - if (unlink(wdirname)) { - debuga(_("Cannot delete %s - %s\n"),wdirname,strerror(errno)); + if (!KeepTempLog && unlink(wdirname)) { + debuga(_("Cannot delete \"%s\": %s\n"),wdirname,strerror(errno)); exit(EXIT_FAILURE); } diff --git a/html.c b/html.c index 08ab1f6..4ca7bca 100644 --- a/html.c +++ b/html.c @@ -487,13 +487,13 @@ void htmlrel(void) longline_destroy(&line); if (iprel && arqip[0]) { - if (unlink(arqip)) { - debuga(_("Cannot delete %s - %s\n"),arqip,strerror(errno)); + if (!KeepTempLog && unlink(arqip)) { + debuga(_("Cannot delete \"%s\": %s\n"),arqip,strerror(errno)); exit(EXIT_FAILURE); } } - if (unlink(arqin)) { - debuga(_("Cannot delete %s - %s\n"),arqin,strerror(errno)); + if (!KeepTempLog && unlink(arqin)) { + debuga(_("Cannot delete \"%s\": %s\n"),arqin,strerror(errno)); exit(EXIT_FAILURE); } diff --git a/include/conf.h b/include/conf.h index b87558d..70cb4a2 100755 --- a/include/conf.h +++ b/include/conf.h @@ -475,6 +475,8 @@ int nrepday; int ndownload; int ntopuser; bool squid24; +//! \c True to keep the temporary files for inspection. +bool KeepTempLog; long long int nocost; float cost; diff --git a/log.c b/log.c index 6bc1b68..923a797 100644 --- a/log.c +++ b/log.c @@ -348,6 +348,7 @@ int main(int argc,char *argv[]) squid24=false; dfrom=0; duntil=0; + KeepTempLog=false; bzero(IncludeUsers, sizeof(IncludeUsers)); bzero(ExcludeString, sizeof(ExcludeString)); @@ -362,7 +363,7 @@ int main(int argc,char *argv[]) strcpy(Title,_("Squid User Access Report")); - while((ch = getopt_long_only(argc, argv, "a:b:c:d:e:f:g:u:l:L:o:s:t:w:P:hijmnprvxyz",long_options,&option_index)) != -1){ + while((ch = getopt_long_only(argc, argv, "a:b:c:d:e:f:g:hikl:L:mno:P:prs:t:u:vw:xyz",long_options,&option_index)) != -1){ switch(ch) { case 0: @@ -401,6 +402,9 @@ int main(int argc,char *argv[]) case 'i': iprel=true; break; + case 'k': + KeepTempLog=true; + break; case 'l': if (NAccessLog>=MAXLOGS) { debuga(_("Too many log files passed on command line with option -l.\n")); @@ -669,6 +673,7 @@ int main(int argc,char *argv[]) if(strcmp(df,"w") == 0) debuga(_(" Date format (-g) = Sites & Users (yyyy/ww)\n")); debuga(_(" IP report (-i) = %s\n"),(iprel) ? _("Yes") : _("No")); + debuga(_(" Keep temporary files (-k) = %s\n"),(KeepTempLog) ? _("Yes") : _("No")); for (iarq=0 ; iarq\n\n\n\n"); fclose(fin); - if (unlink(tmp)) { - debuga(_("Cannot delete %s - %s\n"),tmp,strerror(errno)); + if (!KeepTempLog && unlink(tmp)) { + debuga(_("Cannot delete \"%s\": %s\n"),tmp,strerror(errno)); exit(EXIT_FAILURE); } fflush(NULL); diff --git a/redirector.c b/redirector.c index 1fd6339..87051a6 100644 --- a/redirector.c +++ b/redirector.c @@ -398,8 +398,8 @@ void redirector_log(void) exit(EXIT_FAILURE); } - if (unlink(guard_in)) { - debuga(_("Cannot delete %s - %s\n"),guard_in,strerror(errno)); + if (!KeepTempLog && unlink(guard_in)) { + debuga(_("Cannot delete \"%s\": %s\n"),guard_in,strerror(errno)); exit(EXIT_FAILURE); } return; @@ -444,7 +444,8 @@ void redirector_report(void) snprintf(squidguard_in,sizeof(squidguard_in),"%s/redirector.int_log",tmp); if(!redirector_count) { - unlink(squidguard_in); + if (!KeepTempLog && unlink(squidguard_in)) + debuga(_("Cannot delete \"%s\": %s\n"),squidguard_in,strerror(errno)); if (debugz) debugaz(_("Redirector report not generated because it is empty\n")); return; } @@ -575,8 +576,8 @@ void redirector_report(void) 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)); + if (!KeepTempLog && unlink(squidguard_in)) { + debuga(_("Cannot delete \"%s\": %s\n"),squidguard_in,strerror(errno)); exit(EXIT_FAILURE); } diff --git a/report.c b/report.c index 4ede8ab..39a9d00 100644 --- a/report.c +++ b/report.c @@ -331,8 +331,8 @@ void gerarel(void) debuga(_("Failed to close temporary file for user %s - %s\n"),uinfo->filename,strerror(errno)); fp_tmp=NULL; } - if (unlink(tmp3)) { - debuga(_("Cannot delete %s - %s\n"),tmp3,strerror(errno)); + if (!KeepTempLog && unlink(tmp3)) { + debuga(_("Cannot delete \"%s\": %s\n"),tmp3,strerror(errno)); exit(EXIT_FAILURE); } } diff --git a/sarg.conf b/sarg.conf index 3e786c9..52c83f3 100644 --- a/sarg.conf +++ b/sarg.conf @@ -789,3 +789,14 @@ # re:/\.dropbox\.com(:443)?/ dropbox # re:/([\w-]+)\.(\w*[a-zA-Z]\w*)(?::\d+)?$/\1.\2 #hostalias /usr/local/sarg/hostalias + +# TAG: keep_temp_log yes|no +# Keep temporary files created by sarg to produce its reports. The normal +# operation mode is to delete those files when they are not necessary any more. +# +# Never leave that option to "yes" for normal operation as temporary files +# left over by previous run can be included in subsequent reports. +# +# Use this option only to diagnose a problem with your reports. A better +# alternative is to run sarg from the command line with optino -k. +#keep_temp_log no diff --git a/siteuser.c b/siteuser.c index 84410b4..1904afe 100644 --- a/siteuser.c +++ b/siteuser.c @@ -180,8 +180,8 @@ void siteuser(void) } if (ourl) free(ourl); - if (unlink(general2)) { - debuga(_("Cannot delete %s - %s\n"),general2,strerror(errno)); + if (!KeepTempLog && unlink(general2)) { + debuga(_("Cannot delete \"%s\": %s\n"),general2,strerror(errno)); exit(EXIT_FAILURE); } diff --git a/smartfilter.c b/smartfilter.c index ad73eb5..d461f70 100644 --- a/smartfilter.c +++ b/smartfilter.c @@ -85,8 +85,8 @@ void smartfilter_report(void) 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); } diff --git a/sort.c b/sort.c index e660fda..b35d7a2 100644 --- a/sort.c +++ b/sort.c @@ -85,8 +85,8 @@ void tmpsort(const struct userinfostruct *uinfo) debuga(_("sort command: %s\n"),csort); exit(EXIT_FAILURE); } - if (unlink(arqin)) { - debuga(_("Cannot delete %s - %s\n"),arqin,strerror(errno)); + if (!KeepTempLog && unlink(arqin)) { + debuga(_("Cannot delete \"%s\": %s\n"),arqin,strerror(errno)); exit(EXIT_FAILURE); } @@ -135,8 +135,8 @@ void sort_users_log(const char *tmp, int debug,struct userinfostruct *uinfo) debuga(_("user name too long for %s/%s.unsort\n"),tmp,user); exit(EXIT_FAILURE); } - if (unlink(csort)) { - debuga(_("Cannot delete %s - %s\n"),csort,strerror(errno)); + if (!KeepTempLog && unlink(csort)) { + debuga(_("Cannot delete \"%s\": %s\n"),csort,strerror(errno)); exit(EXIT_FAILURE); } diff --git a/topsites.c b/topsites.c index 5906763..6b0949b 100644 --- a/topsites.c +++ b/topsites.c @@ -174,8 +174,8 @@ void topsites(void) } #endif - if (unlink(general2)) { - debuga(_("Cannot delete %s - %s\n"),general2,strerror(errno)); + if (!KeepTempLog && unlink(general2)) { + debuga(_("Cannot delete \"%s\": %s\n"),general2,strerror(errno)); exit(EXIT_FAILURE); } @@ -210,8 +210,8 @@ void topsites(void) exit(EXIT_FAILURE); } - if (unlink(general3)) { - debuga(_("Cannot delete %s - %s\n"),general3,strerror(errno)); + if (!KeepTempLog && unlink(general3)) { + debuga(_("Cannot delete \"%s\": %s\n"),general3,strerror(errno)); exit(EXIT_FAILURE); } diff --git a/topuser.c b/topuser.c index eb7c5bd..efeb607 100644 --- a/topuser.c +++ b/topuser.c @@ -201,8 +201,8 @@ void topuser(void) exit(EXIT_FAILURE); } - if (unlink(top2)) { - debuga(_("Cannot delete %s - %s\n"),top2,strerror(errno)); + if (!KeepTempLog && unlink(top2)) { + debuga(_("Cannot delete \"%s\": %s\n"),top2,strerror(errno)); exit(EXIT_FAILURE); } @@ -356,7 +356,7 @@ void topuser(void) } else { sprintf(val1,"%s/d%s.html",outdirname,uinfo->filename); if (unlink(val1)) { - debuga(_("Cannot delete %s - %s\n"),val1,strerror(errno)); + debuga(_("Cannot delete \"%s\": %s\n"),val1,strerror(errno)); exit(EXIT_FAILURE); } } @@ -411,8 +411,8 @@ void topuser(void) topcount++; } fclose(fp_top1); - if (unlink(top1)) { - debuga(_("Cannot delete %s - %s\n"),top1,strerror(errno)); + if (!KeepTempLog && unlink(top1)) { + debuga(_("Cannot delete \"%s\": %s\n"),top1,strerror(errno)); exit(EXIT_FAILURE); } longline_destroy(&line); diff --git a/useragent.c b/useragent.c index fa000b5..4770d5c 100644 --- a/useragent.c +++ b/useragent.c @@ -148,8 +148,8 @@ void useragent(void) exit(EXIT_FAILURE); } - if (unlink(tmp3)) { - debuga(_("Cannot delete %s - %s\n"),tmp3,strerror(errno)); + if (!KeepTempLog && unlink(tmp3)) { + debuga(_("Cannot delete \"%s\": %s\n"),tmp3,strerror(errno)); exit(EXIT_FAILURE); } @@ -231,8 +231,8 @@ void useragent(void) exit(EXIT_FAILURE); } - if (unlink(tmp2)) { - debuga(_("Cannot delete %s - %s\n"),tmp2,strerror(errno)); + if (!KeepTempLog && unlink(tmp2)) { + debuga(_("Cannot delete \"%s\": %s\n"),tmp2,strerror(errno)); exit(EXIT_FAILURE); } @@ -279,8 +279,8 @@ void useragent(void) exit(EXIT_FAILURE); } - if (unlink(tmp3)) { - debuga(_("Cannot delete %s - %s\n"),tmp3,strerror(errno)); + if (!KeepTempLog && unlink(tmp3)) { + debuga(_("Cannot delete \"%s\": %s\n"),tmp3,strerror(errno)); exit(EXIT_FAILURE); } @@ -300,8 +300,8 @@ void useragent(void) exit(EXIT_FAILURE); } - if (unlink(tmp2)) { - debuga(_("Cannot delete %s - %s\n"),tmp2,strerror(errno)); + if (!KeepTempLog && unlink(tmp2)) { + debuga(_("Cannot delete \"%s\": %s\n"),tmp2,strerror(errno)); exit(EXIT_FAILURE); } @@ -333,8 +333,8 @@ void useragent(void) if (fclose(fp_ht)==EOF) debuga(_("Failed to close file %s - %s\n"),hfile,strerror(errno)); - if (unlink(tmp3)) { - debuga(_("Cannot delete %s - %s\n"),tmp3,strerror(errno)); + if (!KeepTempLog && unlink(tmp3)) { + debuga(_("Cannot delete \"%s\": %s\n"),tmp3,strerror(errno)); exit(EXIT_FAILURE); }