share/collection.js: Keep visibility when redrawing graphs.
[collection4.git] / src / action_list_hosts.c
1 /**
2  * collection4 - action_list_hosts.c
3  * Copyright (C) 2010  Florian octo Forster
4  * 
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  * 
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  * 
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA  02110-1301  USA
19  *
20  * Authors:
21  *   Florian octo Forster <ff at octo.it>
22  **/
23
24 #include <stdlib.h>
25 #include <stdio.h>
26 #include <string.h>
27 #include <errno.h>
28
29 #include "action_list_hosts.h"
30 #include "common.h"
31 #include "graph.h"
32 #include "graph_list.h"
33 #include "utils_cgi.h"
34
35 #include <fcgiapp.h>
36 #include <fcgi_stdio.h>
37
38 static int left_menu (__attribute__((unused)) void *user_data) /* {{{ */
39 {
40   printf ("\n<ul class=\"menu left\">\n"
41       "  <li><a href=\"%s?action=search\">Search</a></li>\n"
42       "  <li><a href=\"%s?action=list_graphs\">All graphs</a></li>\n"
43       "</ul>\n",
44       script_name (), script_name ());
45
46   return (0);
47 } /* }}} int left_menu */
48
49 static int print_one_host (const char *host, /* {{{ */
50     __attribute__((unused)) void *user_data)
51 {
52   char host_html[128];
53
54   strncpy (host_html, host, sizeof (host_html));
55   host_html[sizeof (host_html) - 1] = 0;
56   html_escape_buffer (host_html, sizeof (host_html));
57
58   printf ("      <li class=\"host\"><a href=\"%s?action=search;q=host:%s\">"
59       "%s</a></li>\n",
60       script_name (), host_html, host_html);
61
62   return (0);
63 } /* }}} int print_one_host */
64
65 static int print_all_hosts (__attribute__((unused)) void *user_data) /* {{{ */
66 {
67   printf ("    <ul class=\"host_list\">\n");
68   gl_foreach_host (print_one_host, /* user_data = */ NULL);
69   printf ("    </ul>\n");
70
71   return (0);
72 } /* }}} int print_all_hosts */
73
74 int action_list_hosts (void) /* {{{ */
75 {
76   page_callbacks_t pg_callbacks = PAGE_CALLBACKS_INIT;
77   char title[512];
78
79   strncpy (title, "List of all hosts", sizeof (title));
80   title[sizeof (title) - 1] = 0;
81
82   pg_callbacks.top_right = html_print_search_box;
83   pg_callbacks.middle_left = left_menu;
84   pg_callbacks.middle_center = print_all_hosts;
85
86   html_print_page (title, &pg_callbacks, /* user data = */ NULL);
87
88   return (0);
89 } /* }}} int action_list_hosts */
90
91 /* vim: set sw=2 sts=2 et fdm=marker : */