#!/usr/bin/perl # Copyright (C) 2008 Florian octo Forster # # This program is free software; you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by the Free Software # Foundation; only version 2 of the License is applicable. # # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more # details. # # You should have received a copy of the GNU General Public License along with # this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. use strict; use warnings; use lib ('../lib'); use utf8; use FindBin ('$RealBin'); use CGI (':cgi'); use CGI::Carp ('fatalsToBrowser'); use HTML::Entities ('encode_entities'); use Data::Dumper; use Collectd::Graph::Config (qw(gc_read_config gc_get_scalar)); use Collectd::Graph::TypeLoader (qw(tl_load_type)); use Collectd::Graph::Common (qw(get_files_from_directory get_all_hosts get_timespan_selection get_selected_files get_host_selection get_plugin_selection flush_files)); use Collectd::Graph::Type (); our $Debug = param ('debug') ? 1 : 0; our $TimeSpans = { Hour => 3600, Day => 86400, Week => 7 * 86400, Month => 31 * 86400, Year => 366 * 86400 }; my $action = param ('action') || 'list_hosts'; our %Actions = ( list_hosts => \&action_list_hosts, show_selection => \&action_show_selection ); if (!exists ($Actions{$action})) { print STDERR "No such action: $action\n"; exit 1; } gc_read_config ("$RealBin/../etc/collection.conf"); $Actions{$action}->(); exit (0); sub can_handle_xhtml { my %types = (); if (!defined $ENV{'HTTP_ACCEPT'}) { return; } for (split (',', $ENV{'HTTP_ACCEPT'})) { my $type = lc ($_); my $q = 1.0; if ($type =~ m#^([^;]+);q=([0-9\.]+)$#) { $type = $1; $q = 0.0 + $2; } $types{$type} = $q; } if (!defined ($types{'application/xhtml+xml'})) { return; } elsif (!defined ($types{'text/html'})) { return (1); } elsif ($types{'application/xhtml+xml'} < $types{'text/html'}) { return; } else { return (1); } } # can_handle_xhtml {my $html_started; sub start_html { return if ($html_started); my $end; my $begin; my $timespan; $end = time (); $timespan = get_timespan_selection (); $begin = $end - $timespan; if (can_handle_xhtml ()) { print < HTML } else { print < HTML } print < collection.cgi, Version 3