YOU DO NOT HAVE RIGHTS FOR TREE VIEW"; exit;
}
/* if cacti's builtin authentication is turned on then make sure to take
graph permissions into account here. if a user does not have rights to a
particular graph; do not show it. they will get an access denied message
if they try and view the graph directly. */
$access_denied = false;
$tree_parameters = array();
print "
";
print " ";
if (read_config_option("global_auth") == "on") {
/* take tree permissions into account here, if the user does not have permission
give an "access denied" message */
$user_auth = db_fetch_row("select user_id from user_auth_tree where tree_id=" . $_SESSION["sess_view_tree_id"] . " and user_id=" . $_SESSION["sess_user_id"]);
if ($current_user["graph_policy"] == "1") {
if (sizeof($user_auth) > 0) { $access_denied = true; }
}elseif ($current_user["graph_policy"] == "2") {
if (sizeof($user_auth) == 0) { $access_denied = true; }
}
if ($access_denied == true) {
print "ACCESS DENIED"; exit;
}
}
grow_graph_tree($_SESSION["sess_view_tree_id"], (!empty($start_branch) ? $start_branch : 0), $_SESSION["sess_user_id"], $tree_parameters);
print "
";
break;
case 'preview':
define("ROWS_PER_PAGE", 10);
$sql_or = "";
if ($current_user["show_preview"] == "") {
print "YOU DO NOT HAVE RIGHTS FOR PREVIEW VIEW"; exit;
}
if (isset($_REQUEST["host_id"])) {
$_SESSION["sess_graph_view_host"] = $_REQUEST["host_id"];
$_REQUEST["page"] = "1";
}elseif (isset($_SESSION["sess_graph_view_host"])) {
$_REQUEST["host_id"] = $_SESSION["sess_graph_view_host"];
}else{
$_REQUEST["host_id"] = "0"; /* default value */
}
if (isset($_REQUEST["filter"])) {
$_SESSION["sess_graph_view_filter"] = $_REQUEST["filter"];
$_REQUEST["page"] = "1";
}elseif (isset($_SESSION["sess_graph_view_filter"])) {
$_REQUEST["filter"] = $_SESSION["sess_graph_view_filter"];
}else{
$_REQUEST["filter"] = ""; /* default value */
}
/* restore the page num from the session var if it is currently stored */
if (isset($_REQUEST["page"])) {
$_SESSION["sess_graph_view_current_page"] = $_REQUEST["page"];
}elseif (isset($_SESSION["sess_graph_view_current_page"])) {
$_REQUEST["page"] = $_SESSION["sess_graph_view_current_page"];
}else{
$_REQUEST["page"] = "1"; /* default value */
}
/* graph permissions */
if (read_config_option("global_auth") == "on") {
if ($current_user["graph_policy"] == "1") {
$sql_where = "where user_auth_graph.user_id is null";
}elseif ($current_user["graph_policy"] == "2") {
$sql_where = "where user_auth_graph.user_id is not null";
}
$sql_join = "left join user_auth_graph on (graph_templates_graph.local_graph_id=user_auth_graph.local_graph_id and user_auth_graph.user_id=" . $_SESSION["sess_user_id"] . ")";
}
/* the user select a bunch of graphs of the 'list' view and wants them dsplayed here */
if (isset($_GET["style"])) {
if ($_GET["style"] == "selective") {
$i = 0;
while (list($var, $val) = each($_GET)) {
if (ereg('^graph_([0-9]+)$', $var, $matches)) {
$graph_array[$i] = $matches[1];
$i++;
}
}
if (sizeof($graph_array) > 0) {
/* build sql string including each graph the user checked */
$sql_or = "and " . array_to_sql_or($graph_array, "graph_templates_graph.local_graph_id");
/* clear the filter vars so they don't affect our results */
$_REQUEST["filter"] = "";
$_REQUEST["host_id"] = "0";
$set_rra_id = $_GET["rra_id"];
}
}
}
if (empty($_REQUEST["host_id"])) {
$sql_base = "from graph_templates_graph
$sql_join
$sql_where
" . (empty($sql_where) ? "where" : "and") . " graph_templates_graph.local_graph_id > 0
and graph_templates_graph.title like '%%" . $_REQUEST["filter"] . "%%'
$sql_or";
}else{
$sql_base = "from graph_templates_graph
left join graph_templates on graph_templates_graph.graph_template_id=graph_templates.id
left join graph_local on graph_templates_graph.local_graph_id=graph_local.id
left join graph_templates_item on graph_local.id=graph_templates_item.local_graph_id
left join data_template_rrd on graph_templates_item.task_item_id=data_template_rrd.id
left join data_local on data_template_rrd.local_data_id=data_local.id
$sql_join
$sql_where
" . (empty($sql_where) ? "where" : "and") . " data_local.host_id=" . $_REQUEST["host_id"] . "
and graph_templates_graph.local_graph_id>0
and graph_templates_graph.title like '%%" . $_REQUEST["filter"] . "%%'
group by graph_templates_graph.id";
}
$total_rows = count(db_fetch_assoc("select
graph_templates_graph.local_graph_id
$sql_base"));
$graphs = db_fetch_assoc("select
graph_templates_graph.local_graph_id,
graph_templates_graph.title
$sql_base
order by graph_templates_graph.title
limit " . (ROWS_PER_PAGE*($_REQUEST["page"]-1)) . "," . ROWS_PER_PAGE);
print "
";
break;
case 'list':
include_once("include/form.php");
if ($current_user["show_list"] == "") {
print "YOU DO NOT HAVE RIGHTS FOR LIST VIEW"; exit;
}
/* graph permissions */
if (read_config_option("global_auth") == "on") {
if ($current_user["graph_policy"] == "1") {
$sql_where = "where user_auth_graph.user_id is null";
}elseif ($current_user["graph_policy"] == "2") {
$sql_where = "where user_auth_graph.user_id is not null";
}
$graphs = db_fetch_assoc("select
graph_templates_graph.local_graph_id,
graph_templates_graph.title,
graph_templates_graph.height,
graph_templates_graph.width
from graph_templates_graph
left join user_auth_graph on (graph_templates_graph.local_graph_id=user_auth_graph.local_graph_id and user_auth_graph.user_id=" . $_SESSION["sess_user_id"] . ")
$sql_where
and graph_templates_graph.local_graph_id > 0
order by graph_templates_graph.title");
}else{
$graphs = db_fetch_assoc("select
local_graph_id,title,height,width
from graph_templates_graph
where local_graph_id > 0
order by title");
}
print "\n";
break;
}
print "