Drop interface from html_open, use global opt_interface.
[darkstat] / graph_db.c
index 580f8ba..e0daa53 100644 (file)
@@ -8,7 +8,6 @@
  */
 
 #include <sys/types.h>
-#include <netinet/in.h> /* for in_addr_t (db.h needs it) */
 
 #include "cap.h"
 #include "conv.h"
@@ -17,7 +16,8 @@
 #include "acct.h"
 #include "err.h"
 #include "str.h"
-#include "html.h" /* FIXME: should be pushed into a .c file? */
+#include "html.h"
+#include "http.h"
 #include "graph_db.h"
 #include "now.h"
 
@@ -28,8 +28,6 @@
 #define GRAPH_WIDTH "320"
 #define GRAPH_HEIGHT "200"
 
-extern const char *interface;
-
 struct graph {
    uint64_t *in, *out;
    unsigned int offset; /* i.e. seconds start at 0, days start at 1 */
@@ -313,16 +311,9 @@ html_front_page(void)
    char start_when[100];
 
    buf = str_make();
-   str_append(buf, html_header_1);
-   str_appendf(buf, "<title>" PACKAGE_STRING " : graphs (%s)</title>\n",
-               interface);
-   str_append(buf, "<script src=\"graph.js\" type=\"text/javascript\">"
-                   "</script>\n");
-   str_append(buf, html_header_2);
-   str_appendf(buf, "<h2 class=\"pageheader\">Graphs (%s)</h2>\n", interface);
+   html_open(buf, "Graphs", /*want_graph_js=*/1);
 
    str_append(buf, "<p>\n");
-
    str_append(buf, "<b>Running for</b> <span id=\"rf\">");
    rf = length_of_time(now - start_time);
    /* FIXME: use a more monotonic clock perhaps? */
@@ -334,15 +325,15 @@ html_front_page(void)
       "%Y-%m-%d %H:%M:%S %Z%z", localtime(&start_time)) != 0)
       str_appendf(buf, "<b>, since</b> %s", start_when);
 
-   str_appendf(buf,"<b>.</b><br/>\n"
+   str_appendf(buf,"<b>.</b><br>\n"
       "<b>Total</b> <span id=\"tb\">%'qu</span> <b>bytes, "
       "in</b> <span id=\"tp\">%'qu</span> <b>packets.</b> "
       "(<span id=\"pc\">%'u</span> <b>captured,</b> "
-      "<span id=\"pd\">%'u</span> <b>dropped)</b><br/>\n"
+      "<span id=\"pd\">%'u</span> <b>dropped)</b><br>\n"
       "</p>\n",
-      total_bytes,
-      total_packets,
-      pkts_recv, pkts_drop);
+      acct_total_bytes,
+      acct_total_packets,
+      cap_pkts_recv, cap_pkts_drop);
 
    str_append(buf,
       "<div id=\"graphs\">\n"
@@ -352,7 +343,7 @@ html_front_page(void)
       "var graph_width = " GRAPH_WIDTH ";\n"
       "var graph_height = " GRAPH_HEIGHT ";\n"
       "var bar_gap = 1;\n"
-      "var graphs_uri = \"/graphs.xml\";\n"
+      "var graphs_uri = \"graphs.xml\";\n"
       "var graphs = [\n"
    );
 
@@ -375,7 +366,7 @@ html_front_page(void)
       "</div>\n"
    );
 
-   str_append(buf, html_footer);
+   html_close(buf);
    return (buf);
 }
 
@@ -389,7 +380,7 @@ xml_graphs(void)
    struct str *buf = str_make(), *rf;
 
    str_appendf(buf, "<graphs tp=\"%qu\" tb=\"%qu\" pc=\"%u\" pd=\"%u\" rf=\"",
-      total_packets, total_bytes, pkts_recv, pkts_drop);
+      acct_total_packets, acct_total_bytes, cap_pkts_recv, cap_pkts_drop);
    rf = length_of_time(now - start_time);
    str_appendstr(buf, rf);
    str_free(rf);