"list hosts" action: Add action to list all hosts.
[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 print_one_host (const char *host, /* {{{ */
39     __attribute__((unused)) void *user_data)
40 {
41   char host_html[128];
42
43   strncpy (host_html, host, sizeof (host_html));
44   host_html[sizeof (host_html) - 1] = 0;
45   html_escape_buffer (host_html, sizeof (host_html));
46
47   printf ("      <li class=\"host\"><a href=\"%s?action=search;q=host:%s\">"
48       "%s</a></li>\n",
49       script_name (), host_html, host_html);
50
51   return (0);
52 } /* }}} int print_one_host */
53
54 static int print_all_hosts (__attribute__((unused)) void *user_data) /* {{{ */
55 {
56   printf ("    <ul class=\"host_list\">\n");
57   gl_foreach_host (print_one_host, /* user_data = */ NULL);
58   printf ("    </ul>\n");
59
60   return (0);
61 } /* }}} int print_all_hosts */
62
63 int action_list_hosts (void) /* {{{ */
64 {
65   gl_update ();
66
67   page_callbacks_t pg_callbacks = PAGE_CALLBACKS_INIT;
68   char title[512];
69
70   strncpy (title, "List of all hosts", sizeof (title));
71   title[sizeof (title) - 1] = 0;
72
73   pg_callbacks.top_right = html_print_search_box;
74   pg_callbacks.middle_center = print_all_hosts;
75
76   html_print_page (title, &pg_callbacks, /* user data = */ NULL);
77
78   return (0);
79 } /* }}} int action_list_hosts */
80
81 /* vim: set sw=2 sts=2 et fdm=marker : */