94631e18ecac576739a11a03626bdb1bc86e4b6f
[darkstat] / html.c
1 /* darkstat 3
2 *
3 * html.c: HTML header/footer templating for web interface.
4 * copyright (c) 2006 Ben Stewart.
5 * copyright (c) 2010 Malte S. Stretz.
6 *
7 * You may use, modify and redistribute this file under the terms of the
8 * GNU General Public License version 2. (see COPYING.GPL)
9 */
10
11 #include "darkstat.h"
12 #include "str.h"
13 #include "http.h"
14
15
16 void html_open(struct str *buf, const char *title, const char *interface,
17 void (*header_callback)(struct str *buf))
18 {
19 str_append(buf, "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n"
20 " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
21 "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
22 "<head>\n");
23 str_appendf(buf, "<title>%s (darkstat3 : %s)</title>\n"
24 "<meta name=\"generator\" content=\"%s\" />\n", title, interface,
25 PACKAGE_STRING);
26 str_appendf(buf, "<link rel=\"stylesheet\" href=\"%s%s\" type=\"text/css\"/>\n",
27 base_url, "style.css");
28 if (header_callback != NULL)
29 header_callback(buf);
30
31 str_append(buf, "</head>\n"
32 "<body>\n"
33 "<div class=\"menu\">\n"
34 "<ul class=\"menu\">\n");
35 str_appendf(buf, "<li class=\"label\">%s</li>\n"
36 "<li><a href=\"%s\">graphs</a></li>\n"
37 "<li><a href=\"%shosts/\">hosts</a></li>\n"
38 "<li><a href=\"http://dmr.ath.cx/net/darkstat/\">homepage</a></li>\n",
39 PACKAGE_STRING, base_url, base_url);
40 str_append(buf, "</ul>\n"
41 "</div>\n"
42 "<div class=\"content\">\n");
43 str_appendf(buf, "<h2 class=\"pageheader\">%s</h2>\n", title);
44 }
45
46 void html_close(struct str *buf)
47 {
48 str_append(buf,
49 "</div>\n"
50 "</body>\n"
51 "</html>\n"
52 );
53 }
54
55
56 /* vim:set ts=4 sw=4 tw=78 expandtab: */