2d2b7f757f81adf756188c5b2f1de727eee59362
[darkstat-debian] / 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 "config.h"
12 #include "str.h"
13 #include "html.h"
14 #include "opt.h"
15
16 #include <assert.h>
17
18 static const char *relpaths[] = {
19 ".",
20 "..",
21 "../.."
22 };
23
24 void html_open(struct str *buf, const char *title,
25 const unsigned int path_depth, const int want_graph_js)
26 {
27 const char *root;
28 assert(path_depth < (sizeof(relpaths)/sizeof(*relpaths)));
29 root = relpaths[path_depth];
30
31 str_appendf(buf,
32 "<!DOCTYPE html>\n"
33 "<html>\n"
34 "<head>\n"
35 "<title>%s (darkstat3 %s)</title>\n"
36 "<meta name=\"generator\" content=\"" PACKAGE_STRING "\">\n"
37 "<meta name=\"robots\" content=\"noindex, noarchive\">\n"
38 "<link rel=\"stylesheet\" href=\"%s/style.css\" type=\"text/css\">\n"
39 , title, opt_interface, root);
40
41 if (want_graph_js)
42 str_appendf(buf,
43 "<script src=\"%s/graph.js\" type=\"text/javascript\"></script>\n"
44 , root);
45
46 str_appendf(buf,
47 "</head>\n"
48 "<body>\n"
49 "<div class=\"menu\">\n"
50 "<ul class=\"menu\">" /* no whitespace (newlines) in list */
51 "<li class=\"label\">" PACKAGE_STRING "</li>"
52 "<li><a href=\"%s/\">graphs</a></li>"
53 "<li><a href=\"%s/hosts/\">hosts</a></li>"
54 "<li><a href=\"" PACKAGE_URL "\">homepage</a></li>"
55 "</ul>\n"
56 "</div>\n"
57 "<div class=\"content\">\n"
58 "<h2 class=\"pageheader\">%s</h2>\n"
59 , root, root, title);
60 }
61
62 void html_close(struct str *buf)
63 {
64 str_append(buf,
65 "</div>\n"
66 "</body>\n"
67 "</html>\n");
68 }
69
70 /* vim:set ts=4 sw=4 tw=78 expandtab: */