graph_db.c \
hosts_db.c \
hosts_sort.c \
+html.c \
http.c \
localip.c \
ncache.c \
str.h queue.h tree.h
err.o: err.c darkstat.h config.h conv.h err.h pidfile.h
graph_db.o: graph_db.c cap.h conv.h darkstat.h config.h db.h acct.h \
- decode.h err.h str.h html.h graph_db.h now.h
+ decode.h err.h str.h html.h http.h graph_db.h now.h
hosts_db.o: hosts_db.c darkstat.h config.h conv.h decode.h dns.h err.h \
hosts_db.h str.h db.h html.h ncache.h now.h
hosts_sort.o: hosts_sort.c darkstat.h config.h hosts_db.h str.h err.h
+html.o: html.c darkstat.h config.h str.h http.h
http.o: http.c darkstat.h config.h http.h conv.h hosts_db.h str.h \
graph_db.h err.h queue.h now.h stylecss.h graphjs.h
localip.o: localip.c darkstat.h config.h conv.h decode.h err.h localip.h
#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"
return 1;
}
+static void cb_headers(struct str *buf)
+{
+ str_appendf(buf, "<script src=\"%s%s\" type=\"text/javascript\">"
+ "</script>\n", base_url, "graph.js");
+}
+
/* ---------------------------------------------------------------------------
* Web interface: front page!
*/
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", interface, cb_headers);
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? */
"</div>\n"
);
- str_append(buf, html_footer);
+ html_close(buf);
return (buf);
}
#define NEXT "next page >>>"
#define FULL "full table"
- str_append(buf, html_header_1);
- str_appendf(buf, " <title>darkstat3: Hosts (%s)</title>\n", interface);
- str_append(buf, html_header_2);
- str_appendf(buf, "<h2 class=\"pageheader\">Hosts (%s)</h2>\n", interface);
+ html_open(buf, "Hosts", interface, NULL);
format_table(buf, hosts_db, start, sort, full);
/* <prev | full | stats | next> */
str_append(buf, " | " NEXT);
str_append(buf, "<br/>\n");
- str_append(buf, html_footer);
+
+ html_close(buf);
done:
if (qs_start != NULL) free(qs_start);
if (qs_sort != NULL) free(qs_sort);
/* Overview. */
buf = str_make();
- str_append(buf, html_header_1);
- str_appendf(buf, " <title>%s</title>\n", ip);
- str_append(buf, html_header_2);
- str_appendf(buf, "<h2>%s</h2>\n", ip);
+ html_open(buf, ip, interface, NULL);
if (strcmp(ip, canonical) != 0)
str_appendf(buf, "(canonically <b>%s</b>)\n", canonical);
str_appendf(buf,
str_append(buf, "<h3>IP protocols</h3>\n");
format_table(buf, h->u.host.ip_protos, 0,TOTAL,0);
- str_append(buf, html_footer);
+ html_close(buf);
return (buf);
}
--- /dev/null
+/* darkstat 3
+ *
+ * html.c: HTML header/footer templating for web interface.
+ * copyright (c) 2006 Ben Stewart.
+ * copyright (c) 2010 Malte S. Stretz.
+ *
+ * You may use, modify and redistribute this file under the terms of the
+ * GNU General Public License version 2. (see COPYING.GPL)
+ */
+
+#include "darkstat.h"
+#include "str.h"
+#include "http.h"
+
+
+void html_open(struct str *buf, const char *title, const char *interface,
+ void (*header_callback)(struct str *buf))
+{
+ str_append(buf, "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n"
+ " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
+ "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
+ "<head>\n");
+ str_appendf(buf, "<title>%s (darkstat3 : %s)</title>\n"
+ "<meta name=\"generator\" content=\"%s\" />\n", title, interface,
+ PACKAGE_STRING);
+ str_appendf(buf, "<link rel=\"stylesheet\" href=\"%s%s\" type=\"text/css\"/>\n",
+ base_url, "style.css");
+ if (header_callback != NULL)
+ header_callback(buf);
+
+ str_append(buf, "</head>\n"
+ "<body>\n"
+ "<div class=\"menu\">\n"
+ "<ul class=\"menu\">\n");
+ str_appendf(buf, "<li class=\"label\">%s</li>\n"
+ "<li><a href=\"%s\">graphs</a></li>\n"
+ "<li><a href=\"%shosts/\">hosts</a></li>\n"
+ "<li><a href=\"http://dmr.ath.cx/net/darkstat/\">homepage</a></li>\n",
+ PACKAGE_STRING, base_url, base_url);
+ str_append(buf, "</ul>\n"
+ "</div>\n"
+ "<div class=\"content\">\n");
+ str_appendf(buf, "<h2 class=\"pageheader\">%s</h2>\n", title);
+}
+
+void html_close(struct str *buf)
+{
+ str_append(buf,
+ "</div>\n"
+ "</body>\n"
+ "</html>\n"
+ );
+}
+
+
+/* vim:set ts=4 sw=4 tw=78 expandtab: */
/* darkstat 3
*
- * html.h: HTML header/footer for web interface.
+ * html.h: HTML header/footer templating for web interface.
* copyright (c) 2006 Ben Stewart.
- *
- * You may use, modify and redistribute this file under the terms of the
- * GNU General Public License version 2. (see COPYING.GPL)
+ * copyright (c) 2010 Malte S. Stretz.
*/
#ifndef __DARKSTAT_HTML_H
#define __DARKSTAT_HTML_H
#include "config.h" /* for PACKAGE_STRING */
-static const char html_header_1[] =
-"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n"
-" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
-"<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
-"<head>\n"
-" <link rel=\"stylesheet\" href=\"/style.css\" type=\"text/css\"/>\n";
-
-static const char html_header_2[] =
-"</head>\n"
-"<body>\n"
-"<div class=\"menu\">\n"
- "<ul class=\"menu\">\n"
- "<li class=\"label\">" PACKAGE_STRING "</li>"
- "<li><a href=\"/\">graphs</a></li>"
- "<li><a href=\"/hosts/\">hosts</a></li>"
- "<li><a href=\"http://dmr.ath.cx/net/darkstat/\">homepage</a></li>"
- "</ul>\n"
-"</div>\n"
-"<div class=\"content\">\n";
-
-static const char html_footer[] =
-"</div>\n"
-"</body>\n"
-"</html>\n";
+void html_open(struct str *buf, const char *title, const char *interface,
+ void (*header_callback)(struct str *buf));
+void html_close(struct str *buf);
#endif
/* vim:set ts=3 sw=3 tw=78 expandtab: */
#include <unistd.h>
#include <zlib.h>
+const char *base_url = "/";
+
static const char mime_type_xml[] = "text/xml";
static const char mime_type_html[] = "text/html; charset=us-ascii";
static const char mime_type_css[] = "text/css";
#include <sys/select.h>
#include <netinet/in.h>
+extern const char *base_url;
+
+void http_init_base(const char *path);
void http_init(const char * bindaddr, const unsigned short bindport,
const int max_conn);
void http_fd_set(fd_set *recv_set, fd_set *send_set, int *max_fd,
hosts_db.c \
hosts_db.h \
hosts_sort.c \
+html.c \
html.h \
http.c \
http.h \