]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Output both graphs in a HTML file to display the two of them at the same time
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Thu, 20 May 2010 20:16:35 +0000 (20:16 +0000)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Thu, 20 May 2010 20:16:35 +0000 (20:16 +0000)
css.c
documentation/util.txt
grepday.c
include/defs.h
topuser.c
util.c

diff --git a/css.c b/css.c
index 619d4ddc5fa9dcc65c89944c36cb0cb335ef22c1..b59d6d6f01efe0e67ddca1a8dac4f11779a7d4c9 100644 (file)
--- 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);
 
index 4ba961b18c09906000e02d49aa7b758ddec42486..23c5d42ae7abeee5d082d78b3d372480d3ada068 100644 (file)
@@ -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.
index 107b958f7ad655ec4fec1b28b3045900cb63f831..f0336af10b6e0a36c71f9fdfce06731f6cb62604 100644 (file)
--- 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("<table class=\"report\" cellpadding=\"0\" cellspacing=\"2\">\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,"<tr><td><img src=\"%s\" alt=\"B\"/></td></tr>\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,"<tr><td><img src=\"%s\" alt=\"E\"/></td></tr>\n",pdata.pngfile);
    }
+   fputs("</table>\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;
index e742a42b06fb5fb1142cdae7c54421795f552b56..81a85c9d354f6102184308c907364bab43eeb339 100755 (executable)
@@ -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);
index a724247923e8b47c3a20cbc1e85a250694922e5d..f02c83e987398086ae8d0205f5d780544deb32ad 100644 (file)
--- a/topuser.c
+++ b/topuser.c
@@ -271,7 +271,8 @@ void topuser(void)
          fputs("<td class=\"data2\">",fp_top3);
 #ifdef HAVE_GD
          if(Graphs && GraphFont[0]!='\0') {
-            fprintf(fp_top3,"<a href=\"%s/graph_day.png\"><img src=\"%s/graph.png\" title=\"%s\" alt=\"G\"></a>&nbsp;",uinfo->filename,ImageFile,_("Graphic"));
+            //fprintf(fp_top3,"<a href=\"%s/graph_day.png\"><img src=\"%s/graph.png\" title=\"%s\" alt=\"G\"></a>&nbsp;",uinfo->filename,ImageFile,_("Graphic"));
+            fprintf(fp_top3,"<a href=\"%s/graph.html\"><img src=\"%s/graph.png\" title=\"%s\" alt=\"G\"></a>&nbsp;",uinfo->filename,ImageFile,_("Graphic"));
          }
 #endif
          fprintf(fp_top3,"<a href=\"%s/d%s.html\"><img src=\"%s/datetime.png\" title=\"%s\" alt=\"T\"></a></td>",uinfo->filename,uinfo->filename,ImageFile,_("date/time report"));
diff --git a/util.c b/util.c
index 13e9e27ee8cbd9af01590f35d60de0f4f5cdf59c..8d2fcb412874d89722aeb0fd82ce52d1ada058a7 100644 (file)
--- a/util.c
+++ b/util.c
@@ -1604,14 +1604,18 @@ void write_logo_image(FILE *fp_ou)
       fprintf(fp_ou, "<div class=\"logo\"><img src=\"%s\" width=\"%s\" height=\"%s\" alt=\"Logo\">&nbsp;%s</div>\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("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<html>\n",fp_ou);
    fputs("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n<html>\n",fp_ou);
    fprintf(fp_ou, "<head>\n  <meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\">\n",CharSet);
    if (page_title) fprintf(fp_ou,"<title>%s</title>\n",page_title);
    css(fp_ou);
-   fprintf(fp_ou,"</head>\n<body style=\"font-family:%s;font-size:%s;background-color:%s;background-image:url(%s)\">\n",FontFace,TitleFontSize,BgColor,BgImage);
+   fputs("</head>\n<body>\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,"<div class=\"title\"><table cellpadding=\"0\" cellspacing=\"0\">\n<tr><th class=\"title_c\">%s</th></tr>\n",Title);