From: Frédéric Marchal Date: Sun, 21 Nov 2010 08:19:10 +0000 (+0000) Subject: Improve javascript inclusion in HTML files X-Git-Tag: v2.3.2~129 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2e96438d96ab4c15ede022d415e36e971e812738;p=thirdparty%2Fsarg.git Improve javascript inclusion in HTML files The javascript to sort the table is not always included in every report. It is now loaded only when necessary. The path to the javascript to include in the HTML report may be relative to the output_dir. The code allows for the future use of more javascripts to be loaded on demand by some pages. --- diff --git a/authfail.c b/authfail.c index 9f1ad28..be63469 100644 --- a/authfail.c +++ b/authfail.c @@ -90,7 +90,7 @@ void authfail_report(void) exit(EXIT_FAILURE); } - write_html_header(fp_ou,(IndexTree == INDEX_TREE_DATE) ? 3 : 1,_("Authentication Failures")); + write_html_header(fp_ou,(IndexTree == INDEX_TREE_DATE) ? 3 : 1,_("Authentication Failures"),HTML_JS_NONE); fputs("",fp_ou); fprintf(fp_ou,_("Period: %s"),period.html); fputs("\n",fp_ou); diff --git a/dansguardian_report.c b/dansguardian_report.c index 1662e48..e1e3b3f 100644 --- a/dansguardian_report.c +++ b/dansguardian_report.c @@ -69,7 +69,7 @@ void dansguardian_report(void) exit(EXIT_FAILURE); } - write_html_header(fp_ou,(IndexTree == INDEX_TREE_DATE) ? 3 : 1,_("DansGuardian")); + write_html_header(fp_ou,(IndexTree == INDEX_TREE_DATE) ? 3 : 1,_("DansGuardian"),HTML_JS_NONE); fputs("",fp_ou); fprintf(fp_ou,_("Period: %s"),period.html); fputs("\n",fp_ou); diff --git a/denied.c b/denied.c index 36f35f4..553a622 100644 --- a/denied.c +++ b/denied.c @@ -81,7 +81,7 @@ void gen_denied_report(void) exit(EXIT_FAILURE); } - write_html_header(fp_ou,(IndexTree == INDEX_TREE_DATE) ? 3 : 1,_("Denied")); + write_html_header(fp_ou,(IndexTree == INDEX_TREE_DATE) ? 3 : 1,_("Denied"),HTML_JS_NONE); fputs("",fp_ou); fprintf(fp_ou,_("Period: %s"),period.html); fputs("\n",fp_ou); diff --git a/documentation/util.txt b/documentation/util.txt index 41772b2..70a5b8c 100644 --- a/documentation/util.txt +++ b/documentation/util.txt @@ -725,13 +725,16 @@ Get the size, in human readable form and kibibytes, of the content of a director -/*! \fn void write_html_head(FILE *fp_ou, const char *page_title) +/*! \fn void write_html_head(FILE *fp_ou,int depth, const char *page_title,int javascript) Write the header of the HTML document. The DTD corresponds to a transitional HTML version 4.01. The title of the document is taken from the global variable ::Title. \param fp_ou The file to which the HTML header is written. +\param depth How deep is the page in the directory tree. The path of the relative javascripts is adjusted accordingly. \param title The title of the page. +\param javascript Which javascript to include in the page. Is a combination of the following bits: + \arg HTML_JS_SORTTABLE */ @@ -747,6 +750,8 @@ The header of the report must be closed by a call to close_html_header(). \param fp_ou The file to which the HTML header is written. \param depth How deep is the page in the directory tree. The depth is passed to show_sarg(). \param title The title of the page. +\param javascript Which javascript to include in the page. Is a combination of bits. +See \see write_html_header() for the possible values. */ diff --git a/download.c b/download.c index 60b4fe5..10739e9 100644 --- a/download.c +++ b/download.c @@ -76,7 +76,7 @@ void download_report(void) exit(EXIT_FAILURE); } - write_html_header(fp_ou,(IndexTree == INDEX_TREE_DATE) ? 3 : 1,_("Downloads")); + write_html_header(fp_ou,(IndexTree == INDEX_TREE_DATE) ? 3 : 1,_("Downloads"),HTML_JS_NONE); fputs("",fp_ou); fprintf(fp_ou,_("Period: %s"),period.html); fputs("\n",fp_ou); diff --git a/grepday.c b/grepday.c index 8c39043..5d09f79 100644 --- a/grepday.c +++ b/grepday.c @@ -723,7 +723,7 @@ void greport_day(const struct userinfostruct *uinfo) debuga(_("(grepday) Cannot open output file %s\n"),wdirname); exit(EXIT_FAILURE); } - write_html_head(fp_ou,_("Graph report")); + write_html_head(fp_ou,(IndexTree == INDEX_TREE_DATE) ? 4 : 2,_("Graph report"),HTML_JS_NONE); fputs("\n", fp_ou); if((datetimeby & DATETIME_BYTE)!=0) { diff --git a/html.c b/html.c index b84093a..1ee5751 100644 --- a/html.c +++ b/html.c @@ -225,7 +225,7 @@ void htmlrel(void) exit(EXIT_FAILURE); } - write_html_header(fp_ou,(IndexTree == INDEX_TREE_DATE) ? 4 : 2,_("User report")); + write_html_header(fp_ou,(IndexTree == INDEX_TREE_DATE) ? 4 : 2,_("User report"),HTML_JS_SORTTABLE); fprintf(fp_ou,"\n",_("Period"),period.html); fprintf(fp_ou,"\n",_("User"),uinfo->label); fputs("
%s: %s
%s: %s
",fp_ou); diff --git a/include/conf.h b/include/conf.h index 0113364..f3d4cb0 100755 --- a/include/conf.h +++ b/include/conf.h @@ -262,6 +262,11 @@ int mkstemps(char *template, int suffixlen); #define USER_SORT_CONNECT 0x0008UL #define USER_SORT_TIME 0x0010UL +//! Value to exclude all the javascripts from the html page. +#define HTML_JS_NONE 0x0000 +//! Bit to include sorttable.js in the html plage. +#define HTML_JS_SORTTABLE 0x0001 + struct periodstruct { //! The first date of the period. diff --git a/include/defs.h b/include/defs.h index ee237f9..ef18bb7 100755 --- a/include/defs.h +++ b/include/defs.h @@ -212,8 +212,8 @@ void fixendofline(char *str); void show_info(FILE *fp_ou); void show_sarg(FILE *fp_ou, int depth); void write_logo_image(FILE *fp_ou); -void write_html_head(FILE *fp_ou, const char *page_title); -void write_html_header(FILE *fp_ou, int depth, const char *title); +void write_html_head(FILE *fp_ou, int depth, const char *page_title,int javascript); +void write_html_header(FILE *fp_ou, int depth, const char *title,int javascript); void close_html_header(FILE *fp_ou); __attribute__((warn_unused_result)) int write_html_trailer(FILE *fp_ou); void output_html_string(FILE *fp_ou,const char *str,int maxlen); diff --git a/index.c b/index.c index 25daa19..2fc7235 100644 --- a/index.c +++ b/index.c @@ -138,7 +138,7 @@ static void make_date_index(void) debuga(_("(index) Cannot open file %s - %s\n"),yearindex,strerror(errno)); exit(EXIT_FAILURE); } - write_html_header(fp_ou,0,ngettext("SARG report","SARG reports",nyears)); + write_html_header(fp_ou,0,ngettext("SARG report","SARG reports",nyears),HTML_JS_NONE); close_html_header(fp_ou); fputs("
\n\n",fp_ou); fprintf(fp_ou,"\n",_("YEAR"),_("SIZE")); @@ -185,7 +185,7 @@ static void make_date_index(void) exit(EXIT_FAILURE); } snprintf(title,sizeof(title),ngettext("SARG: report for %04d","SARG: reports for %04d",nmonths),year); - write_html_header(fp_ou2,1,title); + write_html_header(fp_ou2,1,title,HTML_JS_NONE); close_html_header(fp_ou2); fputs("
%s%s
\n\n",fp_ou2); fprintf(fp_ou2,"\n",_("YEAR"),_("MONTH")); @@ -246,7 +246,7 @@ static void make_date_index(void) exit(EXIT_FAILURE); } snprintf(title,sizeof(title),ngettext("SARG: report for %04d/%02d","SARG: reports for %04d/%02d",ndays),year,month); - write_html_header(fp_ou3,2,title); + write_html_header(fp_ou3,2,title,HTML_JS_NONE); close_html_header(fp_ou3); fputs("
%s/%s
\n\n",fp_ou3); fprintf(fp_ou3,"\n",_("YEAR"),_("MONTH"),_("DAYS")); @@ -410,7 +410,7 @@ static void make_file_index(void) debuga(_("(index) Cannot open file %s\n"),wdir); exit(EXIT_FAILURE); } - write_html_header(fp_ou,0,ngettext("SARG report","SARG reports",nsort)); + write_html_header(fp_ou,0,ngettext("SARG report","SARG reports",nsort),HTML_JS_SORTTABLE); close_html_header(fp_ou); fputs("
%s/%s/%s
\n",_("Period"),period.html); fprintf(fp_ou,"\n",_("User"),uinfo->label); close_html_header(fp_ou); diff --git a/report.c b/report.c index 814c278..6f49e6d 100644 --- a/report.c +++ b/report.c @@ -278,7 +278,7 @@ void gerarel(void) sprintf(httplink,"%s",FontSize,accurl,accurl); */ - write_html_header(fp_tt,(IndexTree == INDEX_TREE_DATE) ? 4 : 2,_("Site access report")); + write_html_header(fp_tt,(IndexTree == INDEX_TREE_DATE) ? 4 : 2,_("Site access report"),HTML_JS_NONE); fprintf(fp_tt,"\n",_("Period"),period.html); fprintf(fp_tt,"\n",_("User"),uinfo->label); fputs("\n",fp_ou); diff --git a/squidguard_report.c b/squidguard_report.c index 36b1f30..31aadb1 100644 --- a/squidguard_report.c +++ b/squidguard_report.c @@ -80,7 +80,7 @@ void squidguard_report(void) exit(EXIT_FAILURE); } - write_html_header(fp_ou,(IndexTree == INDEX_TREE_DATE) ? 3 : 1,_("Redirector report")); + write_html_header(fp_ou,(IndexTree == INDEX_TREE_DATE) ? 3 : 1,_("Redirector report"),HTML_JS_NONE); fputs("\n",fp_ou); diff --git a/topsites.c b/topsites.c index 0cea0a5..98d76ae 100644 --- a/topsites.c +++ b/topsites.c @@ -185,7 +185,7 @@ void topsites(void) exit(EXIT_FAILURE); } - write_html_header(fp_ou,(IndexTree == INDEX_TREE_DATE) ? 3 : 1,_("Top sites")); + write_html_header(fp_ou,(IndexTree == INDEX_TREE_DATE) ? 3 : 1,_("Top sites"),HTML_JS_SORTTABLE); fputs("\n",fp_ou); diff --git a/topuser.c b/topuser.c index d4245f1..2ecb87c 100644 --- a/topuser.c +++ b/topuser.c @@ -178,7 +178,7 @@ void topuser(void) } snprintf(title,sizeof(title),_("SARG report for %s"),period.text); - write_html_header(fp_top3,(IndexTree == INDEX_TREE_DATE) ? 3 : 1,title); + write_html_header(fp_top3,(IndexTree == INDEX_TREE_DATE) ? 3 : 1,title,HTML_JS_SORTTABLE); fputs("\n",fp_top3); diff --git a/useragent.c b/useragent.c index a26bce5..a0f967c 100644 --- a/useragent.c +++ b/useragent.c @@ -157,7 +157,7 @@ void useragent(void) if(debug) debuga(_("Making Useragent report\n")); - write_html_header(fp_ht,(IndexTree == INDEX_TREE_DATE) ? 3 : 1,_("Squid Useragent's Report")); + write_html_header(fp_ht,(IndexTree == INDEX_TREE_DATE) ? 3 : 1,_("Squid Useragent's Report"),HTML_JS_NONE); fprintf(fp_ht,"\n",_("Squid Useragent's Report")); fprintf(fp_ht,"\n",_("Period"),idate,fdate); close_html_header(fp_ht); diff --git a/util.c b/util.c index a0bb63c..84c85db 100644 --- a/util.c +++ b/util.c @@ -1600,20 +1600,28 @@ void write_logo_image(FILE *fp_ou) fprintf(fp_ou, "
\"Logo\" %s
\n",LogoImage,Width,Height,LogoText); } -void write_html_head(FILE *fp_ou, const char *page_title) +void write_html_head(FILE *fp_ou, int depth, const char *page_title,int javascript) { + int i; + fputs("\n\n",fp_ou); fprintf(fp_ou, "\n \n",CharSet); if (page_title) fprintf(fp_ou,"%s\n",page_title); css(fp_ou); - if (SortTableJs[0]) - fprintf(fp_ou,"\n",SortTableJs); + if ((javascript & HTML_JS_SORTTABLE)!=0 && SortTableJs[0]) { + fputs("\n",fp_ou); + } fputs("\n\n",fp_ou); } -void write_html_header(FILE *fp_ou, int depth, const char *page_title) +void write_html_header(FILE *fp_ou, int depth, const char *page_title,int javascript) { - write_html_head(fp_ou,page_title); + write_html_head(fp_ou,depth,page_title,javascript); write_logo_image(fp_ou); show_sarg(fp_ou, depth); fprintf(fp_ou,"
%s: %s
%s: %s
%s: %s
%s: %s
",fp_tt); diff --git a/sarg.conf b/sarg.conf index 7bee126..1a2877b 100644 --- a/sarg.conf +++ b/sarg.conf @@ -698,8 +698,14 @@ # TAG: sorttable path # The full path to a javascript script to dynamically sort the tables. # The path is the path a browser must follow to find the script. +# +# If the path starts with "../" then it is assumed to be a relative +# path and sarg adds as many "../" as necessary to locate the js script from +# the output directory. Therefore, ../../sorttable.js searches for the javascript +# one level above output_dir. +# # If this entry is set, each sortable table will have the "sortable" class set. # You may have a look at http://www.kryogenix.org/code/browser/sorttable/ -# for such as implementation. +# for the implementation on which sarg is based. # # sorttable /sorttable.js diff --git a/siteuser.c b/siteuser.c index e1e6c28..48bf876 100644 --- a/siteuser.c +++ b/siteuser.c @@ -79,7 +79,7 @@ void siteuser(void) exit(EXIT_FAILURE); } - write_html_header(fp_ou,(IndexTree == INDEX_TREE_DATE) ? 3 : 1,_("Sites & Users")); + write_html_header(fp_ou,(IndexTree == INDEX_TREE_DATE) ? 3 : 1,_("Sites & Users"),HTML_JS_SORTTABLE); fputs("
",fp_ou); fprintf(fp_ou,_("Period: %s"),period.html); fputs("
",fp_ou); fprintf(fp_ou,_("Period: %s"),period.html); fputs("
",fp_ou); fprintf(fp_ou,_("Period: %s"),period.html); fputs("
",fp_top3); fprintf(fp_top3,_("Period: %s"),period.html); fputs("
%s
%s: %s - %s
\n\n",Title);
%s