1<?php
2
3include_once "./functions.php";
4
5$cluster_designator = "Cluster Overview";
6
7///////////////////////////////////////////////////////////////////////////////
8// Determine which context we are in. Context is not specifically specified
9// so we have to figure it out ie. if vn(view_name) is present it's the views
10// context, if cluster name is specified without a hostname it's cluster etc.
11///////////////////////////////////////////////////////////////////////////////
12// Blocking malicious CGI input.
13$user['clustername'] = isset($_GET["c"]) ?
14    escapeshellcmd( clean_string( rawurldecode($_GET["c"]) ) ) : NULL;
15$user['gridname'] = isset($_GET["G"]) ?
16    escapeshellcmd( clean_string( rawurldecode($_GET["G"]) ) ) : NULL;
17
18$user['viewname'] = '';
19if ( isset($_GET["vn"]) &&  is_proper_view_name ($_GET["vn"]) ) {
20    $user['viewname'] = $_GET["vn"];
21}
22
23if($conf['case_sensitive_hostnames'] == 1) {
24    $user['hostname'] = isset($_GET["h"]) ?
25        escapeshellcmd( clean_string( rawurldecode($_GET["h"]) ) ) : NULL;
26} else {
27    $user['hostname'] = isset($_GET["h"]) ?
28        strtolower( escapeshellcmd( clean_string( rawurldecode($_GET["h"]) ) ) ) : NULL;
29}
30
31$user['range'] = isset( $_GET["r"] ) && in_array($_GET["r"], array_keys( $conf['time_ranges'] ) ) ?
32    escapeshellcmd( rawurldecode($_GET["r"])) : NULL;
33$user['metricname'] = isset($_GET["m"]) ?
34    escapeshellcmd( clean_string( rawurldecode($_GET["m"]) ) ) : NULL;
35$user['metrictitle'] = isset($_GET["ti"]) ?
36    escapeshellcmd( clean_string( rawurldecode($_GET["ti"]) ) ) : NULL;
37$user['sort'] = isset($_GET["s"]) ?
38    escapeshellcmd( clean_string( rawurldecode($_GET["s"]) ) ) : NULL;
39$user['controlroom'] = isset($_GET["cr"]) ?
40    escapeshellcmd( clean_string( rawurldecode($_GET["cr"]) ) ): NULL;
41# Default value set in conf.php, Allow URL to overrride
42if (isset($_GET["hc"]))
43    //TODO: shouldn't set $conf from user input.
44    $conf['hostcols'] = clean_number($_GET["hc"]);
45if (isset($_GET["mc"]))
46    $conf['metriccols'] = clean_number($_GET["mc"]);
47# Flag, whether or not to show a list of hosts
48$user['showhosts'] = isset($_GET["sh"]) ?
49    clean_number( $_GET["sh"] ) : NULL;
50# The 'p' variable specifies the verbosity level in the physical view.
51$user['physical'] = isset($_GET["p"]) ?
52    clean_number( $_GET["p"] ) : NULL;
53$user['tree'] = isset($_GET["t"]) ?
54    escapeshellcmd($_GET["t"] ) : NULL;
55# A custom range value for job graphs, in -sec.
56$user['jobrange'] = isset($_GET["jr"]) ?
57    clean_number( $_GET["jr"] ) : NULL;
58# A red vertical line for various events. Value specifies the event time.
59$user['jobstart'] = isset($_GET["js"]) ?
60    clean_number( $_GET["js"] ) : NULL;
61# custom start and end
62$user['cs'] = isset($_GET["cs"]) ?
63    escapeshellcmd(htmlentities($_GET["cs"])) : NULL;
64$user['ce'] = isset($_GET["ce"]) ?
65    escapeshellcmd(htmlentities($_GET["ce"])) : NULL;
66# Custom step, primarily for use in exporting the raw data from graph.php
67$user['step'] = isset($_GET["step"]) ?
68    clean_number( $_GET["step"] ) : NULL;
69# The direction we are travelling in the grid tree
70$user['gridwalk'] = isset($_GET["gw"]) ?
71    escapeshellcmd( clean_string( $_GET["gw"] ) ) : NULL;
72# Size of the host graphs in the cluster view
73$user['clustergraphsize'] = isset($_GET["z"]) && in_array( $_GET[ 'z' ], $conf['graph_sizes_keys'] ) ?
74    escapeshellcmd($_GET["z"]) : NULL;
75# A stack of grid parents. Prefer a GET variable, default to cookie.
76if (isset($_GET["gs"]) and $_GET["gs"])
77    $user['gridstack'] = explode( ">", rawurldecode( $_GET["gs"] ) );
78else if ( isset($_COOKIE['gs']) and $_COOKIE['gs'])
79    $user['gridstack'] = explode( ">", $_COOKIE["gs"] );
80
81if (isset($user['gridstack']) and $user['gridstack']) {
82   foreach( $user['gridstack'] as $key=>$value )
83      $user['gridstack'][ $key ] = clean_string( $value );
84}
85
86/////////////////////////////////////////////////////////////////////////////
87// Used with to limit hosts shown
88if ( isset($_GET['host_regex']) )
89  $user['host_regex'] = $_GET['host_regex'];
90
91if ( isset($_GET['max_graphs']) && is_numeric($_GET['max_graphs'] ) )
92  $user['max_graphs'] = $_GET['max_graphs'];
93
94/////////////////////////////////////////////////////////////////////////////
95
96$user['selected_tab'] = isset($_GET["tab"]) ? rawurldecode($_GET["tab"]) : 'm';
97
98$user['compare_hosts'] = ($user['selected_tab'] == 'ch') ? 1 : NULL;
99
100$user['decompose_graph'] = isset($_GET["dg"]) ? 1 : NULL;
101
102
103# Assume we are the first grid visited in the tree if there is no gridwalk
104# or gridstack is not well formed. Gridstack always has at least one element.
105if ( !isset($user['gridstack']) or !strstr($user['gridstack'][0], "http://"))
106    $initgrid = TRUE;
107
108# Default values
109if (!isset($conf['hostcols']) || !is_numeric($conf['hostcols'])) $conf['hostcols'] = 4;
110if (!isset($conf['metriccols']) || !is_numeric($conf['metriccols'])) $conf['metriccols'] = 2;
111if (!is_numeric($user['showhosts'])) $user['showhosts'] = 1;
112
113# Filters
114if(isset($_GET["choose_filter"]))
115{
116  $req_choose_filter = $_GET["choose_filter"];
117  $user['choose_filter'] = array();
118  foreach($req_choose_filter as $k_req => $v_req)
119  {
120    $k = escapeshellcmd( clean_string( rawurldecode ($k_req)));
121    $v = escapeshellcmd( clean_string( rawurldecode ($v_req)));
122    $user['choose_filter'][$k] = $v;
123  }
124}
125
126# Set context.
127#
128# WARNING WARNING WARNING WARNING. If you create another context
129# e.g. views, compare_hosts please make sure you add those to
130# get_ganglia.php and ganglia.php otherwise you may be making
131# requests to the gmetad any time you access it which will impact
132# performance read make it really slow
133$context = NULL;
134if(!$user['clustername'] && !$user['hostname'] && $user['controlroom']) {
135      $context = "control";
136} else if (isset($user['tree'])) {
137      $context = "tree";
138} else if ( $user['compare_hosts'] ) {
139      $context = "compare_hosts";
140} else if ( $user['decompose_graph'] ) {
141      $context = "decompose_graph";
142} else if ($user['selected_tab'] == 'v') {
143      $context = "views";
144} else if(!$user['clustername'] and !$user['gridname'] and !$user['hostname']) {
145      $context = "meta";
146} else if($user['gridname']) {
147      $context = "grid";
148} else if ($user['clustername'] and !$user['hostname'] and $user['physical']) {
149      $context = "physical";
150} else if ($user['clustername'] and !$user['hostname'] and !$user['showhosts']) {
151      $context = "cluster-summary";
152} else if($user['clustername'] and !$user['hostname']) {
153      $context = "cluster";
154} else if($user['clustername'] and $user['hostname'] and $user['physical']) {
155      $context = "node";
156} else if($user['clustername'] and $user['hostname']) {
157      $context = "host";
158}
159
160if (!$user['range'])
161    $user['range'] = $conf['default_time_range'];
162
163$end = "now";
164
165# $conf['time_ranges'] defined in conf.php
166if( $user['range'] == 'job' && isSet( $user['jobrange'] ) ) {
167    $start = $user['jobrange'];
168} else if( isSet( $conf['time_ranges'][ $user['range'] ] ) ) {
169    $start = $conf['time_ranges'][ $user['range'] ] * -1 . "s";
170} else {
171    $start = $conf['time_ranges'][ $conf['default_time_range'] ] * -1 . "s";
172}
173
174if ($user['cs'] or $user['ce'])
175    $user['range'] = "custom";
176
177if (!$user['metricname'])
178    $user['metricname'] = $conf['default_metric'];
179
180if (!$user['sort'])
181    $user['sort'] = "by name";
182
183# Since cluster context do not have the option to sort "by hosts down" or
184# "by hosts up", therefore change sort order to "descending" if previous
185# sort order is either "by hosts down" or "by hosts up"
186if ($context == "cluster") {
187    if ($user['sort'] == "by hosts up" || $user['sort'] == "by hosts down") {
188        $user['sort'] = "descending";
189    }
190}
191
192// TODO: temporary step until all scripts expect $user.
193extract( $user );
194
195# A hack for pre-2.5.0 ganglia data sources.
196$always_constant = array(
197   "swap_total" => 1,
198   "cpu_speed" => 1,
199   "swap_total" => 1
200);
201
202$always_timestamp = array(
203   "gmond_started" => 1,
204   "reported" => 1,
205   "sys_clock" => 1,
206   "boottime" => 1
207);
208
209# List of report graphs
210$reports = array(
211   "load_report" => "load_one",
212   "cpu_report" => 1,
213   "mem_report" => 1,
214   "network_report" => 1,
215   "packet_report" => 1
216);
217
218?>
219