From: Frédéric Marchal Date: Thu, 20 May 2010 20:16:35 +0000 (+0000) Subject: Output both graphs in a HTML file to display the two of them at the same time X-Git-Tag: v2.3-pre5~25 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7f2382f6f42ea7c13503348bb2ee1e59218edf91;p=thirdparty%2Fsarg.git Output both graphs in a HTML file to display the two of them at the same time --- diff --git a/css.c b/css.c index 619d4dd..b59d6d6 100644 --- a/css.c +++ b/css.c @@ -39,7 +39,7 @@ void css(FILE *fp_css) fprintf(fp_css,".logo {font-family:Verdana,Tahoma,Arial;font-size:11px;color:%s;text-align:center;vertical-align:middle;border:none;padding:0px;margin-bottom:5px;}\n",LogoTextColor); fprintf(fp_css,".logo th {padding:0px;}\n"); fprintf(fp_css,".logo img {vertical-align:middle;padding:0px;border:0px none;}\n"); - fprintf(fp_css,".body {font-family:%s;color:%s;background-color:%s;}\n",FontFace,TxColor,BgColor); + fprintf(fp_css,".body {font-family:%s;font-size:%s;color:%s;background-color:%s;background-image:url(%s);}\n",FontFace,TitleFontSize,TxColor,BgColor,BgImage); fprintf(fp_css,".info {font-family:%s;font-size:10px;text-align:center;margin-top:1em;margin-bottom:1em;}\n", FontFace); fprintf(fp_css,".info a:link,a:visited {font-family:%s;color:#0000FF;font-size:10px;text-decoration:none;}\n", FontFace); diff --git a/documentation/util.txt b/documentation/util.txt index 4ba961b..23c5d42 100644 --- a/documentation/util.txt +++ b/documentation/util.txt @@ -725,12 +725,25 @@ Get the size, in human readable form and kibibytes, of the content of a director - -/*! \fn void write_html_header(FILE *fp_ou, int depth, const char *title) -Write the HTML header of a HTML report file. The DTD correspond to a +/*! \fn void write_html_head(FILE *fp_ou, const char *page_title) +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 title The title of the page. +*/ + + + + + +/*! \fn void write_html_header(FILE *fp_ou, int depth, const char *title) +Write the HTML header of a HTML report file including the sarg logo and +the beginning of the header of the report. + +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. diff --git a/grepday.c b/grepday.c index 107b958..f0336af 100644 --- a/grepday.c +++ b/grepday.c @@ -99,6 +99,8 @@ struct PlotStruct const char *XLabel; //! The label to write on the Y axis. const char *YLabel; + //! The name of the output PNG file. + const char *pngfile; }; enum TextRefPos @@ -611,8 +613,8 @@ static void greport_plot(const struct userinfostruct *uinfo,struct PlotStruct *p } } - if (snprintf(graph,sizeof(graph),"%s/%s/graph_day.png",outdirname,uinfo->filename)>=sizeof(graph)) { - debuga(_("user name too long for %s/%s/graph_day.png\n"),outdirname,uinfo->filename); + if (snprintf(graph,sizeof(graph),"%s/%s/%s",outdirname,uinfo->filename,pdata->pngfile)>=sizeof(graph)) { + debuga(_("user name too long for %s/%s/%s\n"),outdirname,uinfo->filename,pdata->pngfile); exit(EXIT_FAILURE); } if((pngout=fopen(graph,"wb"))==NULL) { @@ -649,7 +651,7 @@ void greport_prepare(void) void greport_day(const struct userinfostruct *uinfo) { #ifdef HAVE_GD - FILE *fp_in; + FILE *fp_in, *fp_ou; char wdirname[MAXLEN]; char buf[MAXLEN]; char colsep; @@ -713,6 +715,17 @@ void greport_day(const struct userinfostruct *uinfo) fclose(fp_in); unlink(wdirname); + if (snprintf(wdirname,sizeof(wdirname),"%s/%s/graph.html",outdirname,uinfo->filename)>=sizeof(wdirname)) { + debuga(_("user name too long for %s/%s/%s\n"),outdirname,uinfo->filename,"graph.html"); + exit(EXIT_FAILURE); + } + if ((fp_ou=fopen(wdirname,"wt"))==NULL) { + debuga(_("(grepday) Cannot open output file %s\n"),wdirname); + exit(EXIT_FAILURE); + } + write_html_head(fp_ou,_("Graph report")); + + fputs("\n", fp_ou); if((datetimeby & DATETIME_BYTE)!=0) { memset(&pdata,0,sizeof(pdata)); pdata.datapoints=bytespoints; @@ -722,8 +735,11 @@ void greport_day(const struct userinfostruct *uinfo) pdata.ymax=5LL*1024LL*1024LL*1024LL; pdata.ytype=PTG_LogBin; pdata.YLabel=_("BYTES"); + pdata.pngfile="graph_day_byte.png"; greport_plot(uinfo,&pdata); - } else { + fprintf(fp_ou,"\n",pdata.pngfile); + } + if((datetimeby & DATETIME_ELAP)!=0) { memset(&pdata,0,sizeof(pdata)); pdata.datapoints=elappoints; pdata.npoints=31; @@ -732,8 +748,16 @@ void greport_day(const struct userinfostruct *uinfo) pdata.ymax=86400000; pdata.ytype=PTG_Time; pdata.YLabel=_("ELAPSED TIME"); + pdata.pngfile="graph_day_elap.png"; greport_plot(uinfo,&pdata); + fprintf(fp_ou,"\n",pdata.pngfile); } + fputs("
\"B\"/
\"E\"/
\n",fp_ou); + + if (write_html_trailer(fp_ou)<0) + debuga(_("Write error in file %s\n"),wdirname); + if (fclose(fp_ou)==EOF) + debuga(_("Failed to close file %s - %s\n"),wdirname,strerror(errno)); #endif //HAVE_GD return; diff --git a/include/defs.h b/include/defs.h index e742a42..81a85c9 100755 --- a/include/defs.h +++ b/include/defs.h @@ -210,6 +210,7 @@ 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 close_html_header(FILE *fp_ou); __attribute__((warn_unused_result)) int write_html_trailer(FILE *fp_ou); diff --git a/topuser.c b/topuser.c index a724247..f02c83e 100644 --- a/topuser.c +++ b/topuser.c @@ -271,7 +271,8 @@ void topuser(void) fputs("",fp_top3); #ifdef HAVE_GD if(Graphs && GraphFont[0]!='\0') { - fprintf(fp_top3,"\"G\" ",uinfo->filename,ImageFile,_("Graphic")); + //fprintf(fp_top3,"\"G\" ",uinfo->filename,ImageFile,_("Graphic")); + fprintf(fp_top3,"\"G\" ",uinfo->filename,ImageFile,_("Graphic")); } #endif fprintf(fp_top3,"\"T\"",uinfo->filename,uinfo->filename,ImageFile,_("date/time report")); diff --git a/util.c b/util.c index 13e9e27..8d2fcb4 100644 --- a/util.c +++ b/util.c @@ -1604,14 +1604,18 @@ void write_logo_image(FILE *fp_ou) fprintf(fp_ou, "
\"Logo\" %s
\n",LogoImage,Width,Height,LogoText); } -void write_html_header(FILE *fp_ou, int depth, const char *page_title) +void write_html_head(FILE *fp_ou, const char *page_title) { - //fputs("\n\n",fp_ou); fputs("\n\n",fp_ou); fprintf(fp_ou, "\n \n",CharSet); if (page_title) fprintf(fp_ou,"%s\n",page_title); css(fp_ou); - fprintf(fp_ou,"\n\n",FontFace,TitleFontSize,BgColor,BgImage); + fputs("\n\n",fp_ou); +} + +void write_html_header(FILE *fp_ou, int depth, const char *page_title) +{ + write_html_head(fp_ou,page_title); write_logo_image(fp_ou); show_sarg(fp_ou, depth); fprintf(fp_ou,"
\n\n",Title);
%s