From 9f93fec3532b47f5807f78921f463e57d879f7f7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fr=C3=A9d=C3=A9ric=20Marchal?= Date: Sun, 30 Oct 2011 14:42:42 +0000 Subject: [PATCH] Display some messages to understand why sarg isn't doing something One common class of questions from users is to ask why sarg isn't producing some kind of report. Considering the number of configuration parameters, it is not surprising that some users get lost. To help the users help themselves, the -z command line option has been enhanced to print messages indicating why sarg don't produce a report. --- CMakeLists.txt | 2 +- authfail.c | 1 + dansguardian_log.c | 2 ++ dansguardian_report.c | 1 + denied.c | 1 + documentation/util.txt | 23 ----------------------- download.c | 4 +++- html.c | 2 -- include/defs.h | 2 +- include/info.h | 2 +- log.c | 4 ++-- redirector.c | 5 ++++- report.c | 41 +++++++++++++++++++++++++++++++---------- siteuser.c | 4 +++- topsites.c | 4 +++- topuser.c | 1 + util.c | 21 +++++++++++++++++++-- 17 files changed, 74 insertions(+), 46 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4ec2ef5..24a870d 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ PROJECT(sarg C) SET(sarg_VERSION 2) SET(sarg_REVISION "3.2-pre2") SET(sarg_BUILD "") -SET(sarg_BUILDDATE "Sep-14-2011") +SET(sarg_BUILDDATE "Oct-30-2011") INCLUDE(AddFileDependencies) INCLUDE(CheckIncludeFile) diff --git a/authfail.c b/authfail.c index 219fe09..8e74f78 100644 --- a/authfail.c +++ b/authfail.c @@ -72,6 +72,7 @@ void authfail_report(void) if(authfail_count == 0) { unlink(tmp4); + if (debugz) debugaz(_("Authentication failures report not produced because it is empty\n")); return; } diff --git a/dansguardian_log.c b/dansguardian_log.c index 203d603..92764c0 100644 --- a/dansguardian_log.c +++ b/dansguardian_log.c @@ -77,6 +77,8 @@ void dansguardian_log(void) debuga(_("Maybe you have a broken record or garbage in your %s file\n"),DansGuardianConf); exit(EXIT_FAILURE); } + if (debug) debuga(_("Using the dansguardian log file \"%s\" found in your configuration file \"%s\"\n"), + loglocation,DansGuardianConf); break; } } diff --git a/dansguardian_report.c b/dansguardian_report.c index 60d83e1..0bf7b48 100644 --- a/dansguardian_report.c +++ b/dansguardian_report.c @@ -61,6 +61,7 @@ void dansguardian_report(void) snprintf(dansguardian_in,sizeof(dansguardian_in),"%s/dansguardian.log",tmp); if(!dansguardian_count) { unlink(dansguardian_in); + if (debugz) debugaz(_("Dansguardian report not generated because it is empty\n")); return; } diff --git a/denied.c b/denied.c index 3800600..ec8505c 100644 --- a/denied.c +++ b/denied.c @@ -65,6 +65,7 @@ void gen_denied_report(void) sprintf(denied_in,"%s/denied.log",tmp); if (!denied_count) { unlink(denied_in); + if (debugz) debugaz(_("Denied report not produced because it is empty\n")); return; } diff --git a/documentation/util.txt b/documentation/util.txt index 508d36b..cfdc9af 100644 --- a/documentation/util.txt +++ b/documentation/util.txt @@ -268,29 +268,6 @@ Get the name of the month according to the language file selected by the user. -/*! \fn void debuga(const char *msg,...) -Write a debug message to stderr. The message is prefixed by "SARG:" to identify its origin. - -\param msg The printf like message to format. -\param ... The arguments to format in the message. - -*/ - - - - - -/*! \fn void debugaz(const char *head, const char *msg) -Write a debug message to stderr with the value of a parameter. The message is prefixed by "SARG: (util)". - -\param head The name of the parameter. -\param msg The value of the parameter. -*/ - - - - - /*! \fn char *fixnum(long long int value, int n) Rewrite a number to make it more readable. The number may be written with the suffix K, M, G or T depending on its magnitude or the digits diff --git a/download.c b/download.c index 192b29b..b424a0a 100644 --- a/download.c +++ b/download.c @@ -60,8 +60,10 @@ void download_report(void) ouser2[0]='\0'; snprintf(report_in,sizeof(report_in),"%s/download.log",tmp); - if(access(report_in, R_OK) != 0) + if(access(report_in, R_OK) != 0) { + if (debugz) debugaz(_("Downloaded files report not generated as it is empty\n")); return; + } snprintf(report,sizeof(report),"%s/download.html",outdirname); diff --git a/html.c b/html.c index 14a2dbe..e77669e 100644 --- a/html.c +++ b/html.c @@ -62,8 +62,6 @@ void htmlrel(void) const struct userinfostruct *uinfo; userscan uscan; - if((ReportType & REPORT_TYPE_USERS_SITES) == 0) return; - if (snprintf(tmp2,sizeof(tmp2),"%s/sargtmp.unsort",tmp)>=sizeof(tmp2)) { debuga(_("File name too long: %s/sargtmp.unsort\n"),tmp); exit(EXIT_FAILURE); diff --git a/include/defs.h b/include/defs.h index 3931f57..9ddd29d 100755 --- a/include/defs.h +++ b/include/defs.h @@ -248,7 +248,7 @@ void output_html_string(FILE *fp_ou,const char *str,int maxlen); void output_html_url(FILE *fp_ou,const char *url); void output_html_link(FILE *fp_ou,const char *url,int maxlen); void debuga(const char *msg,...) __attribute__((format(printf,1,2))); -void debugaz(const char *head, const char *msg); +void debugaz(const char *msg,...) __attribute__((format(printf,1,2))); void my_lltoa(unsigned long long int n, char *s, int ssize, int len); char *get_size(const char *path, const char *file); void url_module(const char *url, char *w2); diff --git a/include/info.h b/include/info.h index 27b518a..c4acc1a 100755 --- a/include/info.h +++ b/include/info.h @@ -1,3 +1,3 @@ -#define VERSION PACKAGE_VERSION" Sep-14-2011" +#define VERSION PACKAGE_VERSION" Oct-30-2011" #define PGM PACKAGE_NAME #define URL "http://sarg.sourceforge.net" diff --git a/log.c b/log.c index 4e1265a..b1d14d2 100644 --- a/log.c +++ b/log.c @@ -1626,8 +1626,8 @@ int main(int argc,char *argv[]) } if(debugz){ - debugaz("data",dia); - debugaz("period",period.text); + debugaz(_("date=%s\n"),dia); + debugaz(_("period=%s\n"),period.text); } if(debug) diff --git a/redirector.c b/redirector.c index 34b5591..f85553f 100644 --- a/redirector.c +++ b/redirector.c @@ -277,8 +277,10 @@ void redirector_log(void) str2 = user; - if(SquidGuardConf[0] == '\0' && NRedirectorLogs == 0) + if(SquidGuardConf[0] == '\0' && NRedirectorLogs == 0) { + if (debugz) debugaz(_("No redirector logs provided to produce that kind of report\n")); return; + } sprintf(guard_in,"%s/redirector.unsort",tmp); sprintf(guard_ou,"%s/redirector.log",tmp); @@ -422,6 +424,7 @@ void redirector_report(void) sprintf(squidguard_in,"%s/redirector.log",tmp); if(!redirector_count) { unlink(squidguard_in); + if (debugz) debugaz(_("Redirector report not generated because it is empty\n")); return; } diff --git a/report.c b/report.c index c54bdc6..6dcee29 100644 --- a/report.c +++ b/report.c @@ -92,7 +92,7 @@ void gerarel(void) } if(debugz){ - debugaz("outdirname",outdirname); + debugaz(_("outdirname=%s\n"),outdirname); } if(UserAgentLog[0] != '\0' && email[0] == '\0') useragent(); @@ -349,15 +349,22 @@ void gerarel(void) fclose(fp_gen); if (puinfo && !indexonly) day_totalize(tmp,puinfo); - if (!indexonly) tmpsort(); + if (!indexonly) + tmpsort(); + else if (debugz) + debugaz(_("Only the index is generated as requested\n")); if(email[0] == '\0') { if (!indexonly) { - if((ReportType & REPORT_TYPE_DOWNLOADS) != 0) download_report(); + if((ReportType & REPORT_TYPE_DOWNLOADS) != 0) + download_report(); + else if (debugz) + debugaz(_("Downloaded files report not requested in report_type\n")); - if(DansGuardianConf[0] != '\0') { + if(DansGuardianConf[0] != '\0') dansguardian_log(); - } + else if (debugz) + debugaz(_("Dansguardian report not produced because no dansguardian configuration file was provided\n")); redirector_log(); } @@ -365,23 +372,37 @@ void gerarel(void) topuser(); if (!indexonly) { - if((ReportType & REPORT_TYPE_TOPSITES) != 0) topsites(); - - if((ReportType & REPORT_TYPE_SITES_USERS) != 0) siteuser(); + if((ReportType & REPORT_TYPE_TOPSITES) != 0) + topsites(); + else if (debugz) + debugaz(_("Top sites report not requested in report_type\n")); + + if((ReportType & REPORT_TYPE_SITES_USERS) != 0) + siteuser(); + else if (debugz) + debugaz(_("Sites & users report not requested in report_type\n")); if ((ReportType & REPORT_TYPE_DENIED) != 0) gen_denied_report(); + else if (debugz) + debugaz(_("Denied accesses report not requested in report_type\n")); if ((ReportType & REPORT_TYPE_AUTH_FAILURES) != 0) authfail_report(); + else if (debugz) + debugaz(_("Authentication failures report not requested in report_type\n")); if(smartfilter) smartfilter_report(); - if(DansGuardianConf[0] != '\0') dansguardian_report(); + if(DansGuardianConf[0] != '\0') + dansguardian_report(); redirector_report(); - if((ReportType & REPORT_TYPE_USERS_SITES) != 0) htmlrel(); + if((ReportType & REPORT_TYPE_USERS_SITES) != 0) + htmlrel(); + else if (debugz) + debugaz(_("User's detailed report not requested in report_type\n")); } make_index(); diff --git a/siteuser.c b/siteuser.c index 09c220b..02df1f6 100644 --- a/siteuser.c +++ b/siteuser.c @@ -50,8 +50,10 @@ void siteuser(void) struct generalitemstruct item; const struct userinfostruct *uinfo; - if(Privacy) + if(Privacy) { + if (debugz) debugaz(_("Sites and users report not generated because privacy option is on\n")); return; + } nsitesusers = 0; sprintf(general,"%s/sarg-general",outdirname); diff --git a/topsites.c b/topsites.c index 9ab48de..e361331 100644 --- a/topsites.c +++ b/topsites.c @@ -66,8 +66,10 @@ void topsites(void) longline line; struct generalitemstruct item; - if(Privacy) + if(Privacy) { + if (debugz) debugaz(_("Top sites report not produced because privacy option is on\n")); return; + } sprintf(general,"%s/sarg-general",outdirname); sprintf(sites,"%s/sarg-sites",outdirname); diff --git a/topuser.c b/topuser.c index 2e5d348..2148c85 100644 --- a/topuser.c +++ b/topuser.c @@ -222,6 +222,7 @@ void topuser(void) if ((ReportType & REPORT_TYPE_TOPUSERS) == 0) { fputs("\n\n",fp_top3); fclose (fp_top3); + if (debugz) debugaz(_("No top users report because it is not configured in report_type\n")); return; } diff --git a/util.c b/util.c index b99fd62..f664f6c 100644 --- a/util.c +++ b/util.c @@ -448,6 +448,12 @@ void name_month(char *month,int month_len) } +/*! +Write a debug message to stderr. The message is prefixed by "SARG:" to identify its origin. + +\param msg The printf like message to format. +\param ... The arguments to format in the message. +*/ void debuga(const char *msg,...) { va_list ap; @@ -459,9 +465,20 @@ void debuga(const char *msg,...) } -void debugaz(const char *head, const char *msg) +/*! +Write a debug message to stderr. The message is prefixed by "SARG: (info)". + +\param msg The printf like message to format. +\param ... The arguments to format in the message. +*/ +void debugaz(const char *msg,...) { - fprintf(stderr, "SARG: (util) %s=%s\n",head, msg); + va_list ap; + + fputs(_("SARG: (info) "),stderr); + va_start(ap,msg); + vfprintf(stderr,msg,ap); + va_end(ap); } -- 2.47.2