1 # Copyright (C) 2002 Stanislav Sinyagin
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
17 # $Id: AdmInfo.pm,v 1.1 2010-12-27 00:03:44 ivan Exp $
18 # Stanislav Sinyagin <ssinyagin@yahoo.com>
20 package Torrus::Renderer::AdmInfo;
24 use Torrus::ConfigTree;
32 'leaf-type' => {'rrd-def' => {'rrd-ds' => undef,
36 'rrd-cdef' => {'rpn-expr' => undef}},
39 my %rrdmulti_params = ( 'ds-names' => undef );
41 my %collector_params =
43 'storage-type' => {'rrd' => {
47 'rrd-def' => {'rrd-ds' => undef,
49 'rrd-create-dstype' => undef,
50 'rrd-create-rra' => undef,
51 'rrd-create-heartbeat' => undef,
53 'enabled' => {'rrd-create-hw-rralen' => undef},
56 'collector-type' => undef,
57 'collector-period' => undef,
58 'collector-timeoffset' => undef,
59 'collector-instance' => undef,
60 'collector-instance-hashstring' => undef,
61 'collector-scale' => undef,
62 'collector-dispersed-timeoffset' => {
64 'yes' => {'collector-timeoffset-min' => undef,
65 'collector-timeoffset-max' => undef,
66 'collector-timeoffset-step' => undef,
67 'collector-timeoffset-hashstring' => undef}}
72 ('ds-type' => {'rrd-file' => \%rrd_params,
73 'rrd-multigraph' => \%rrdmulti_params,
74 'collector' => \%collector_params},
75 'rrgraph-views' => undef,
76 'rrd-scaling-base' => undef,
77 'graph-logarithmic' => undef,
78 'graph-rigid-boundaries' => undef,
79 'graph-ignore-decorations' => undef,
83 my %param_categories =
85 'collector-dispersed-timeoffset' => 'Collector',
86 'collector-period' => 'Collector',
87 'collector-scale' => 'Collector',
88 'collector-timeoffset' => 'Collector',
89 'collector-timeoffset-hashstring' => 'Collector',
90 'collector-timeoffset-max' => 'Collector',
91 'collector-timeoffset-min' => 'Collector',
92 'collector-timeoffset-step' => 'Collector',
93 'collector-type' => 'Collector',
94 'collector-instance' => 'Collector',
95 'collector-instance-hashstring' => 'Collector',
96 'data-dir' => 'Storage',
97 'data-file' => 'Storage',
98 'ds-names' => 'Multigraph',
99 'ds-type' => 'Common Parameters',
100 'graph-ignore-decorations' => 'Display',
101 'graph-logarithmic' => 'Display',
102 'graph-rigid-boundaries' => 'Display',
103 'leaf-type' => 'Common Parameters',
104 'nodeid' => 'Common Parameters',
105 'rpn-expr' => 'RRD CDEF Paramters',
107 'rrd-create-dstype' => 'RRD',
108 'rrd-create-heartbeat' => 'RRD',
109 'rrd-create-hw-rralen' => 'RRD',
110 'rrd-create-rra' => 'RRD',
112 'rrd-hwpredict' => 'RRD',
113 'rrd-scaling-base' => 'RRD',
114 'rrgraph-views' => 'Display',
115 'storage-type' => 'Storage'
119 # Load additional validation, configurable from
120 # torrus-config.pl and torrus-siteconfig.pl
122 foreach my $mod ( @Torrus::Renderer::loadAdmInfo )
124 eval( 'require ' . $mod );
126 eval( '&' . $mod . '::initAdmInfo( \%leaf_params, \%param_categories )' );
131 # All our methods are imported by Torrus::Renderer;
136 my $config_tree = shift;
141 if( $self->may_display_adminfo( $config_tree, $token ) )
143 $self->{'adminfo'} = $self->retrieve_adminfo( $config_tree, $token );
144 my @ret = $self->render_html( $config_tree, $token, $view, $outfile );
145 delete $self->{'adminfo'};
150 if( not open(OUT, ">$outfile") )
152 Error("Cannot open $outfile for writing: $!");
157 print OUT "Cannot display admin information\n";
161 return (300+time(), 'text/plain');
166 sub may_display_adminfo
169 my $config_tree = shift;
172 if( $config_tree->isLeaf( $token ) )
174 # hasPrivilege is imported from Torrus::Renderer::HTML
175 if( $self->hasPrivilege( $config_tree->treeName(),
189 my $config_tree = shift;
193 my @namemaps = ( \%leaf_params );
195 while( scalar( @namemaps ) > 0 )
197 my @next_namemaps = ();
199 foreach my $namemap ( @namemaps )
201 foreach my $paramkey ( keys %{$namemap} )
203 my $pname = $paramkey;
205 my $pval = $config_tree->getNodeParam( $token, $pname );
206 if( defined( $pval ) )
208 if( ref( $namemap->{$paramkey} ) )
210 if( exists $namemap->{$paramkey}->{$pval} )
212 if( defined $namemap->{$paramkey}->{$pval} )
214 push( @next_namemaps,
215 $namemap->{$paramkey}->{$pval} );
220 my $category = $param_categories{$pname};
221 if( not defined( $category ) )
225 $ret->{$category}{$pname} = $pval;
229 @namemaps = @next_namemaps;
240 # indent-tabs-mode: nil
241 # perl-indent-level: 4