File: html.c

package info (click to toggle)
darkstat 3.0.715-1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 816 kB
  • sloc: ansic: 6,542; sh: 355; makefile: 172; php: 15
file content (70 lines) | stat: -rw-r--r-- 1,914 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* 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 "config.h"
#include "str.h"
#include "html.h"
#include "opt.h"

#include <assert.h>

static const char *relpaths[] = {
    ".",
    "..",
    "../.."
};

void html_open(struct str *buf, const char *title,
    const unsigned int path_depth, const int want_graph_js)
{
    const char *root;
    assert(path_depth < (sizeof(relpaths)/sizeof(*relpaths)));
    root = relpaths[path_depth];

    str_appendf(buf,
        "<!DOCTYPE html>\n"
        "<html>\n"
        "<head>\n"
         "<title>%s (darkstat3 %s)</title>\n"
         "<meta name=\"generator\" content=\"" PACKAGE_STRING "\">\n"
         "<meta name=\"robots\" content=\"noindex, noarchive\">\n"
         "<link rel=\"stylesheet\" href=\"%s/style.css\" type=\"text/css\">\n"
        , title, opt_interface, root);

    if (want_graph_js)
        str_appendf(buf,
            "<script src=\"%s/graph.js\" type=\"text/javascript\"></script>\n"
            , root);

    str_appendf(buf,
        "</head>\n"
        "<body>\n"
        "<div class=\"menu\">\n"
        "<ul class=\"menu\">" /* no whitespace (newlines) in list */
         "<li class=\"label\">" PACKAGE_STRING "</li>"
         "<li><a href=\"%s/\">graphs</a></li>"
         "<li><a href=\"%s/hosts/\">hosts</a></li>"
         "<li><a href=\"" PACKAGE_URL "\">homepage</a></li>"
        "</ul>\n"
        "</div>\n"
        "<div class=\"content\">\n"
         "<h2 class=\"pageheader\">%s</h2>\n"
        , root, root, 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: */