X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=contrib%2Fcollection3%2Fbin%2Findex.cgi;h=e28e98572238e04e6e1e9ea52a6a8d565e88b1e2;hb=56c7b21899e44b57b5031a21ca3652b30f4fc1aa;hp=b0001d267a8e3bdeae1fc92623d7c303f6fb4a02;hpb=41f141639046a261063cf346fe7f89cd4cb9cc59;p=collectd.git diff --git a/contrib/collection3/bin/index.cgi b/contrib/collection3/bin/index.cgi index b0001d26..e28e9857 100755 --- a/contrib/collection3/bin/index.cgi +++ b/contrib/collection3/bin/index.cgi @@ -20,6 +20,7 @@ use warnings; use lib ('../lib'); use utf8; +use Carp (qw(cluck confess)); use FindBin ('$RealBin'); use CGI (':cgi'); use CGI::Carp ('fatalsToBrowser'); @@ -27,10 +28,11 @@ use HTML::Entities ('encode_entities'); use Data::Dumper; -use Collectd::Graph::TypeLoader (qw(tl_read_config tl_load_type)); +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)); + get_plugin_selection flush_files)); use Collectd::Graph::Type (); our $Debug = param ('debug') ? 1 : 0; @@ -57,7 +59,7 @@ if (!exists ($Actions{$action})) exit 1; } -tl_read_config ("$RealBin/../etc/collection3.conf"); +gc_read_config ("$RealBin/../etc/collection.conf"); $Actions{$action}->(); exit (0); @@ -107,6 +109,14 @@ 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 <collection.cgi, Version 3 + - + HTML $html_started = 1; }} @@ -150,6 +161,28 @@ sub end_html HTML } +sub contains_invalid_chars +{ + my $str = shift; + + for (split (m//, $str)) + { + my $n = ord ($_); + + # Whitespace is allowed. + if (($n >= 9) && ($n <= 13)) + { + next; + } + elsif ($n < 32) + { + return (1); + } + } + + return; +} + sub show_selector { my $timespan_selection = get_timespan_selection (); @@ -164,6 +197,7 @@ sub show_selector HTML for (sort (keys %$host_selection)) { + next if contains_invalid_chars ($_); my $host = encode_entities ($_); my $selected = $host_selection->{$_} ? ' selected="selected"' @@ -176,6 +210,7 @@ HTML HTML for (sort (keys %$plugin_selection)) { + next if contains_invalid_chars ($_); my $plugin = encode_entities ($_); my $selected = $plugin_selection->{$_} ? ' selected="selected"' @@ -188,6 +223,7 @@ HTML HTML for (sort { $TimeSpans->{$a} <=> $TimeSpans->{$b} } (keys (%$TimeSpans))) { + next if contains_invalid_chars ($_); my $name = encode_entities ($_); my $value = $TimeSpans->{$_}; my $selected = ($value == $timespan_selection) @@ -214,6 +250,7 @@ sub action_list_hosts for (sort @hosts) { my $url = encode_entities (script_name () . "?action=show_selection;hostname=$_"); + next if contains_invalid_chars ($_); my $name = encode_entities ($_); print qq#
  • $name
  • \n#; } @@ -261,25 +298,35 @@ sub action_show_selection start_html (); show_selector (); - my $ident = {}; - my $all_files; + my $timespan; + my $types = {}; + my $id_counter = 0; + $all_files = get_selected_files (); + $timespan = get_timespan_selection (); if ($Debug) { print "
    ", Data::Dumper->Dump ([$all_files], ['all_files']), "
    \n"; } + # Send FLUSH command to the daemon if necessary and possible. + flush_files ($all_files, + begin => time () - $timespan, + end => time (), + addr => gc_get_scalar ('UnixSockAddr', undef), + interval => gc_get_scalar ('Interval', 10)); + for (@$all_files) { my $file = $_; my $type = ucfirst (lc ($file->{'type'})); - $type =~ s/[^A-Za-z_]//g; - $type =~ s/_([A-Za-z])/\U$1\E/g; + $type =~ s/[^A-Za-z0-9_]//g; + $type =~ s/_([A-Za-z0-9])/\U$1\E/g; if (!defined ($types->{$type})) { @@ -301,17 +348,50 @@ sub action_show_selection my $type = $_; my $graphs_num = $types->{$type}->getGraphsNum (); - my $timespan = get_timespan_selection (); - for (my $i = 0; $i < $graphs_num; $i++) { my $args = $types->{$type}->getGraphArgs ($i); my $url = encode_entities ("graph.cgi?$args;begin=-$timespan"); + my $id = sprintf ("graph%04i", $id_counter++); print " \n"; print " $type\n" if ($i == 0); - - print qq# \n#; + print < +
    +
    + A graph +
    +
    +
    -
    +
    +
    +
    +
    +
    +
    H
    +
    D
    +
    W
    +
    M
    +
    Y
    +
    !
    +
    +
    +
    + +EOF + # print qq# \n#; print " \n"; } }