Example #1
0
function settings()
{
    global $tabs_graphs, $settings_graphs, $current_user, $graph_views, $current_user;
    /* you cannot have per-user graph settings if cacti's user management is not turned on */
    if (read_config_option('auth_method') == 0) {
        raise_message(6);
        display_output_messages();
        return;
    }
    if ($_REQUEST['action'] == 'edit') {
        if (isset($_SERVER['HTTP_REFERER'])) {
            $timespan_sel_pos = strpos($_SERVER['HTTP_REFERER'], '&predefined_timespan');
            if ($timespan_sel_pos) {
                $_SERVER['HTTP_REFERER'] = substr($_SERVER['HTTP_REFERER'], 0, $timespan_sel_pos);
            }
        }
        $_SESSION['profile_referer'] = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : 'graph_view.php';
    }
    print "<form method='post' action='auth_profile.php'>\n";
    html_start_box('<strong>User Settings</strong>', '100%', '', '3', 'center', '');
    $current_user = db_fetch_row_prepared('SELECT * FROM user_auth WHERE id = ?', array($_SESSION['sess_user_id']));
    if (!sizeof($current_user)) {
        return;
    }
    /* file: user_admin.php, action: user_edit (host) */
    $fields_user = array('username' => array('method' => 'value', 'friendly_name' => 'User Name', 'description' => 'The login name for this user.', 'value' => '|arg1:username|', 'max_length' => '40', 'size' => '40'), 'full_name' => array('method' => 'textbox', 'friendly_name' => 'Full Name', 'description' => 'A more descriptive name for this user, that can include spaces or special characters.', 'value' => '|arg1:full_name|', 'max_length' => '120', 'size' => '60'), 'email_address' => array('method' => 'textbox', 'friendly_name' => 'E-Mail Address', 'description' => 'An E-Mail Address you be reached at.', 'value' => '|arg1:email_address|', 'max_length' => '60', 'size' => '60'));
    draw_edit_form(array('config' => array('no_form_tag' => true), 'fields' => inject_form_variables($fields_user, isset($current_user) ? $current_user : array())));
    html_end_box();
    if (is_view_allowed('graph_settings') == true) {
        if (read_config_option('auth_method') != 0) {
            $settings_graphs['tree']['default_tree_id']['sql'] = get_graph_tree_array(true);
        }
        html_start_box('<strong>Graph Settings</strong>', '100%', '', '3', 'center', '');
        while (list($tab_short_name, $tab_fields) = each($settings_graphs)) {
            $collapsible = true;
            print "<tr class='spacer tableHeader" . ($collapsible ? ' collapsible' : '') . "' id='row_{$tab_short_name}'><td colspan='2' style='cursor:pointer;' class='tableSubHeaderColumn'>" . $tabs_graphs[$tab_short_name] . ($collapsible ? "<div style='float:right;padding-right:4px;'><i class='fa fa-angle-double-up'></i></div>" : "") . "</td></tr>\n";
            $form_array = array();
            while (list($field_name, $field_array) = each($tab_fields)) {
                $form_array += array($field_name => $tab_fields[$field_name]);
                if (isset($field_array['items']) && is_array($field_array['items'])) {
                    while (list($sub_field_name, $sub_field_array) = each($field_array['items'])) {
                        if (graph_config_value_exists($sub_field_name, $_SESSION['sess_user_id'])) {
                            $form_array[$field_name]['items'][$sub_field_name]['form_id'] = 1;
                        }
                        $form_array[$field_name]['items'][$sub_field_name]['value'] = db_fetch_cell_prepared('SELECT value FROM settings_graphs WHERE name = ? AND user_id = ?', array($sub_field_name, $_SESSION['sess_user_id']));
                    }
                } else {
                    if (graph_config_value_exists($field_name, $_SESSION['sess_user_id'])) {
                        $form_array[$field_name]['form_id'] = 1;
                    }
                    $form_array[$field_name]['value'] = db_fetch_cell_prepared('SELECT value FROM settings_graphs WHERE name = ? AND user_id = ?', array($field_name, $_SESSION['sess_user_id']));
                }
            }
            draw_edit_form(array('config' => array('no_form_tag' => true), 'fields' => $form_array));
        }
        html_end_box();
    }
    ?>
	<script type="text/javascript">
	<!--
	var themeFonts=<?php 
    print read_config_option('font_method');
    ?>
;

	function graphSettings() {
		if (themeFonts == 1) {
				$('#row_fonts').hide();
				$('#row_custom_fonts').hide();
				$('#row_title_size').hide();
				$('#row_title_font').hide();
				$('#row_legend_size').hide();
				$('#row_legend_font').hide();
				$('#row_axis_size').hide();
				$('#row_axis_font').hide();
				$('#row_unit_size').hide();
				$('#row_unit_font').hide();
		}else{
			var custom_fonts = $('#custom_fonts').is(':checked');

			switch(custom_fonts) {
			case true:
				$('#row_fonts').show();
				$('#row_title_size').show();
				$('#row_title_font').show();
				$('#row_legend_size').show();
				$('#row_legend_font').show();
				$('#row_axis_size').show();
				$('#row_axis_font').show();
				$('#row_unit_size').show();
				$('#row_unit_font').show();
				break;
			case false:
				$('#row_fonts').show();
				$('#row_title_size').hide();
				$('#row_title_font').hide();
				$('#row_legend_size').hide();
				$('#row_legend_font').hide();
				$('#row_axis_size').hide();
				$('#row_axis_font').hide();
				$('#row_unit_size').hide();
				$('#row_unit_font').hide();
				break;
			}
		}

		if ($('#timespan_sel').is(':checked')) {
			$('#row_default_rra_id').hide();
			$('#row_default_timespan').show();
			$('#row_default_timeshift').show();
			$('#row_allow_graph_dates_in_future').show();
			$('#row_first_weekdayid').show();
			$('#row_day_shift_start').show();
			$('#row_day_shift_end').show();
		} else {
			$('#row_default_rra_id').show();
			$('#row_default_timespan').hide();
			$('#row_default_timeshift').hide();
			$('#row_allow_graph_dates_in_future').hide();
			$('#row_first_weekdayid').hide();
			$('#row_day_shift_start').hide();
			$('#row_day_shift_end').hide();
		}
	}

	$(function() {
		graphSettings();

		$('#navigation').show();
		$('#navigation_right').show();

		$('input[value="Save"]').unbind().click(function(event) {
			event.preventDefault();
			href='<?php 
    print $_SERVER['HTTP_REFERER'];
    ?>
';
			href=href+(href.indexOf('?') > 0 ? '&':'?')+'header=false';
			$.post('auth_profile.php?header=false', $('input, select, textarea').serialize()).done(function(data) {
				$.get('auth_profile.php?action=noreturn&header=false', function(data) {
					$('#main').html(data);
					applySkin();
				});
			});
		});

		$('input[value="Return"]').unbind().click(function(event) {
			console.log('The refer is:<?php 
    print $_SESSION['profile_referer'];
    ?>
');
			document.location = '<?php 
    print $_SESSION['profile_referer'];
    ?>
';
		});

		$('#timespan_sel').change(function() {
			graphSettings();
		});
	});

	-->
	</script>
	<?php 
    form_hidden_box('save_component_graph_config', '1', '');
    form_save_buttons(array(array('id' => 'return', 'value' => 'Return'), array('id' => 'save', 'value' => 'Save')));
}
Example #2
0
function settings() {
	global $colors, $tabs_graphs, $settings_graphs, $current_user, $graph_views, $current_user, $graph_tree_views;

	/* you cannot have per-user graph settings if cacti's user management is not turned on */
	if (read_config_option("auth_method") == 0) {
		raise_message(6);
		display_output_messages();
		return;
	}

	/* Find out whether this user has right here */
	if($current_user["graph_settings"] == "") {
		print "<strong><font size='+1' color='#FF0000'>YOU DO NOT HAVE RIGHTS TO CHANGE GRAPH SETTINGS</font></strong>";
		include_once("./include/bottom_footer.php");
		exit;
	}

	if (read_config_option("auth_method") != 0) {
		if ($current_user["policy_graphs"] == "1") {
			$sql_where = "where user_auth_tree.user_id is null";
		}elseif ($current_user["policy_graphs"] == "2") {
			$sql_where = "where user_auth_tree.user_id is not null";
		}

		$settings_graphs["tree"]["default_tree_id"]["sql"] = get_graph_tree_array(true);
	}

	print "<form method='post' action='graph_settings.php'>\n";

	html_graph_start_box(1, true);

	print "<tr bgcolor='#" . $colors["header"] . "'><td colspan='3'><table cellspacing='0' cellpadding='3' width='100%'><tr><td class='textHeaderDark'><strong>Graph Settings</strong></td></tr></table></td></tr>";

	while (list($tab_short_name, $tab_fields) = each($settings_graphs)) {
		?>
		<tr bgcolor='<?php print $colors["header_panel"];?>'>
			<td colspan='2' class='textSubHeaderDark' style='padding: 3px;'>
				<?php print $tabs_graphs[$tab_short_name];?>
			</td>
		</tr>
		<?php

		$form_array = array();

		while (list($field_name, $field_array) = each($tab_fields)) {
			$form_array += array($field_name => $tab_fields[$field_name]);

			if ((isset($field_array["items"])) && (is_array($field_array["items"]))) {
				while (list($sub_field_name, $sub_field_array) = each($field_array["items"])) {
					if (graph_config_value_exists($sub_field_name, $_SESSION["sess_user_id"])) {
						$form_array[$field_name]["items"][$sub_field_name]["form_id"] = 1;
					}

					$form_array[$field_name]["items"][$sub_field_name]["value"] =  db_fetch_cell("select value from settings_graphs where name='$sub_field_name' and user_id=" . $_SESSION["sess_user_id"]);
				}
			}else{
				if (graph_config_value_exists($field_name, $_SESSION["sess_user_id"])) {
					$form_array[$field_name]["form_id"] = 1;
				}

				$form_array[$field_name]["value"] = db_fetch_cell("select value from settings_graphs where name='$field_name' and user_id=" . $_SESSION["sess_user_id"]);
			}
		}

		draw_edit_form(
			array(
				"config" => array(
					"no_form_tag" => true
					),
				"fields" => $form_array
				)
			);
	}

	html_graph_end_box();

	print "<br>";

	if (isset($_SERVER["HTTP_REFERER"])) {
		$timespan_sel_pos = strpos($_SERVER["HTTP_REFERER"],"&predefined_timespan");
		if ($timespan_sel_pos) {
		   $_SERVER["HTTP_REFERER"] = substr($_SERVER["HTTP_REFERER"],0,$timespan_sel_pos);
		}
	}

	form_hidden_box("referer",(isset($_SERVER["HTTP_REFERER"]) ? $_SERVER["HTTP_REFERER"] : ""),"");
	form_hidden_box("save_component_graph_config","1","");
	form_save_button("graph_settings.php", "save");
}
Example #3
0
function draw_tree_dropdown($current_tree_id) {
	global $colors;

	$html = "";

	$tree_list = get_graph_tree_array();

	if (isset($_GET["tree_id"])) {
		$_SESSION["sess_view_tree_id"] = $current_tree_id;
	}

	/* if there is a current tree, make sure it still exists before going on */
	if ((!empty($_SESSION["sess_view_tree_id"])) && (db_fetch_cell("select id from graph_tree where id=" . $_SESSION["sess_view_tree_id"]) == "")) {
		$_SESSION["sess_view_tree_id"] = 0;
	}

	/* set a default tree if none is already selected */
	if (empty($_SESSION["sess_view_tree_id"])) {
		if (db_fetch_cell("select id from graph_tree where id=" . read_graph_config_option("default_tree_id")) > 0) {
			$_SESSION["sess_view_tree_id"] = read_graph_config_option("default_tree_id");
		}else{
			if (sizeof($tree_list) > 0) {
				$_SESSION["sess_view_tree_id"] = $tree_list[0]["id"];
			}
		}
	}

	/* make the dropdown list of trees */
	if (sizeof($tree_list) > 1) {
		$html ="<form name='form_tree_id'>
			<td valign='middle' height='30' bgcolor='#" . $colors["panel"] . "'>\n
				<table width='100%' cellspacing='0' cellpadding='0'>\n
					<tr>\n
						<td width='200' class='textHeader'>\n
							&nbsp;&nbsp;Select a Graph Hierarchy:&nbsp;\n
						</td>\n
						<td bgcolor='#" . $colors["panel"] . "'>\n
							<select name='cbo_tree_id' onChange='window.location=document.form_tree_id.cbo_tree_id.options[document.form_tree_id.cbo_tree_id.selectedIndex].value'>\n";

		foreach ($tree_list as $tree) {
			$html .= "<option value='graph_view.php?action=tree&tree_id=" . $tree["id"] . "'";
				if ($_SESSION["sess_view_tree_id"] == $tree["id"]) { $html .= " selected"; }
				$html .= ">" . $tree["name"] . "</option>\n";
			}

		$html .= "</select>\n";
		$html .= "</td></tr></table></td></form>\n";
	}elseif (sizeof($tree_list) == 1) {
		/* there is only one tree; use it */
		//print "	<td valign='middle' height='5' colspan='3' bgcolor='#" . $colors["panel"] . "'>";
	}

	return $html;
}
Example #4
0
function get_host_tree_array($where = "", $only_hosts = false)
{
    $leafs = array();
    $branchleafs = 0;
    $tree_list = get_graph_tree_array();
    /* auth check for hosts on the trees */
    if (read_config_option("global_auth") == "on") {
        $current_user = db_fetch_row("select policy_hosts from user_auth where id=" . $_SESSION["sess_user_id"]);
        $sql_join = "left join user_auth_perms on (host.id=user_auth_perms.item_id and user_auth_perms.type=3 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ")";
        if ($current_user["policy_hosts"] == "1") {
            $sql_where = "and !(user_auth_perms.user_id is not null and graph_tree_items.host_id > 0)";
        } elseif ($current_user["policy_hosts"] == "2") {
            $sql_where = "and !(user_auth_perms.user_id is null and graph_tree_items.host_id > 0)";
        }
    } else {
        $sql_join = "";
        $sql_where = "";
    }
    /* Only return monitor items */
    $sql_where .= " and ((host.disabled = '' and host.monitor = 'on') or (title != ''))";
    if (strstr($where, 'and') != $where) {
        $where = "and " . $where;
    }
    $sql_where .= $where . " ";
    if (sizeof($tree_list) > 0) {
        foreach ($tree_list as $tree) {
            $heirarchy = db_fetch_assoc("select\n\t\t\t\tgraph_tree_items.title,\n\t\t\t\tgraph_tree_items.order_key,\n\t\t\t\tgraph_tree_items.host_id,\n\t\t\t\tgraph_tree_items.host_grouping_type,\n\t\t\t\thost.id,\n\t\t\t\thost.description,\n\t\t\t\thost.status,\n\t\t\t\thost.hostname,\n\t\t\t\thost.cur_time,\n\t\t\t\thost.status_rec_date,\n\t\t\t\thost.status_fail_date,\n\t\t\t\thost.availability\n\t\t\t\tfrom graph_tree_items\n\t\t\t\tleft join host on (host.id=graph_tree_items.host_id)\n\t\t\t\t{$sql_join}\n\t\t\t\twhere graph_tree_items.graph_tree_id=" . $tree["id"] . "\n\t\t\t\t{$sql_where}\n\t\t\t\tand graph_tree_items.local_graph_id = 0\n\t\t\t\torder by graph_tree_items.order_key");
            if (sizeof($heirarchy) > 0) {
                if (!$only_hosts) {
                    $leafs[$branchleafs] = $tree;
                    $branchleafs++;
                }
                foreach ($heirarchy as $leaf) {
                    $leafs[$branchleafs] = $leaf;
                    $branchleafs++;
                }
            }
        }
    }
    return $leafs;
}
Example #5
0
function create_dhtml_tree()
{
    global $config;
    $dhtml_tree = array();
    $tree_list = get_graph_tree_array();
    if (sizeof($tree_list)) {
        foreach ($tree_list as $tree) {
            $dhtml_tree['tree:' . $tree['id']] = true;
        }
    }
    return $dhtml_tree;
}
Example #6
0
function settings() {
	global $colors, $tabs_graphs, $settings_graphs, $current_user, $current_user;

	/* you cannot have per-user graph settings if cacti's user management is not turned on */
	if (read_config_option("auth_method") == 0) {
		raise_message(6);
		display_output_messages();
		return;
	}

	/* Find out whether this user has right here */
	if($current_user["graph_settings"] == "") {
		print "<strong><font size='+1' color='#FF0000'>" . __("YOU DO NOT HAVE RIGHTS TO CHANGE GRAPH SETTINGS") . "</font></strong>";
		include_once(CACTI_BASE_PATH . "/include/bottom_footer.php");
		exit;
	}

	if (read_config_option("auth_method") != 0) {
		if ($current_user["policy_graphs"] == "1") {
			$sql_where = "where user_auth_tree.user_id is null";
		}elseif ($current_user["policy_graphs"] == "2") {
			$sql_where = "where user_auth_tree.user_id is not null";
		}

		$settings_graphs["tree"]["default_tree_id"]["sql"] = get_graph_tree_array(true);
	}

	/* draw the categories tabs on the top of the page */
	print "<form method='post' action='graph_settings.php'>\n";

	# the tabs
	print "<table width='100%' cellspacing='0' cellpadding='0' align='center'><tr><td><div class='tabs'>\n";
	if (sizeof($settings_graphs) > 0) {
		foreach (array_keys($settings_graphs) as $tab_short_name) {
			print "<div><a id='tab_" . clean_up_name($tabs_graphs[$tab_short_name]) . "' " . (($tab_short_name == "General") ? "class='tab tabSelected'" : "class='tab tabDefault'") . " onClick='selectTab(\"" . clean_up_name($tabs_graphs[$tab_short_name]) . "\")' href='#'>$tabs_graphs[$tab_short_name]</a></div>\n";
		}
	}
	print "</div></td></tr></table>\n";

	# the tab contents
	while (list($tab_short_name, $tab_fields) = each($settings_graphs)) {
		print "<table cellpadding='0' cellspacing='0' width='100%'><tr><td><div class='tab_settings' id='settings_" . clean_up_name($tabs_graphs[$tab_short_name]) . "'>\n";
		html_start_box("<strong>" . __("Graph Settings") . " (" . $tabs_graphs[$tab_short_name] . ")</strong>", "100", $colors["header"], 0, "center", "", false, "Tab_Settings_" . clean_up_name($tabs_graphs[$tab_short_name]));
		$header_items = array(__("Field"), __("Value"));
		print "<tr><td>";
		html_header($header_items, 2, true, "Header_Settings_" . clean_up_name($tabs_graphs[$tab_short_name]),'left wp100');

		$form_array = array();

		while (list($field_name, $field_array) = each($tab_fields)) {
			$form_array += array($field_name => $tab_fields[$field_name]);

			if ((isset($field_array["items"])) && (is_array($field_array["items"]))) {
				while (list($sub_field_name, $sub_field_array) = each($field_array["items"])) {
					if (graph_config_value_exists($sub_field_name, $_SESSION["sess_user_id"])) {
						$form_array[$field_name]["items"][$sub_field_name]["form_id"] = 1;
					}

					$form_array[$field_name]["items"][$sub_field_name]["value"] =  db_fetch_cell("select value from settings_graphs where name='$sub_field_name' and user_id=" . $_SESSION["sess_user_id"]);
				}
			}else{
				if (graph_config_value_exists($field_name, $_SESSION["sess_user_id"])) {
					$form_array[$field_name]["form_id"] = 1;
				}

				$form_array[$field_name]["value"] = db_fetch_cell("select value from settings_graphs where name='$field_name' and user_id=" . $_SESSION["sess_user_id"]);
			}
		}

		draw_edit_form(
			array(
				"config" => array("no_form_tag" => true),
				"fields" => $form_array
				)
		);

		print "</table></td></tr>";		/* end of html_header */
		html_end_box();
		print "</div></td></tr></table>\n";
	}

	if (isset($_SERVER["HTTP_REFERER"])) {
		$timespan_sel_pos = strpos($_SERVER["HTTP_REFERER"],"&predefined_timespan");
		if ($timespan_sel_pos) {
			$_SERVER["HTTP_REFERER"] = substr($_SERVER["HTTP_REFERER"],0,$timespan_sel_pos);
		}
	}

	form_hidden_box("referer", "graph_view.php","");
	form_hidden_box("save_component_graph_config","1","");

	form_save_button_alt("", "save", "save");

	?>
	<script type="text/javascript">
	<!--

	function selectTab(tab) {
		$('.tab_settings').hide();
		$('.tab').removeClass("tabSelected");
		$('.tab').addClass("tabDefault");
		$('#settings_'+tab).show();
		$('#tab_'+tab).removeClass("tabDefault");
		$('#tab_'+tab).addClass("tabSelected");
	}

	$().ready(function() {
		selectTab('General');
	});

	//-->
	</script>
	<?php

	include(CACTI_BASE_PATH . "/include/bottom_footer.php");
}
Example #7
0
function settings()
{
    global $tabs_graphs, $settings_graphs, $current_user, $graph_views, $current_user, $graph_tree_views;
    /* you cannot have per-user graph settings if cacti's user management is not turned on */
    if (read_config_option("auth_method") == 0) {
        raise_message(6);
        display_output_messages();
        return;
    }
    /* Find out whether this user has right here */
    if ($current_user["graph_settings"] == "") {
        print "<strong><font size='+1' color='#FF0000'>YOU DO NOT HAVE RIGHTS TO CHANGE GRAPH SETTINGS</font></strong>";
        include_once "./include/bottom_footer.php";
        exit;
    }
    if (read_config_option("auth_method") != 0) {
        if ($current_user["policy_graphs"] == "1") {
            $sql_where = "where user_auth_tree.user_id is null";
        } elseif ($current_user["policy_graphs"] == "2") {
            $sql_where = "where user_auth_tree.user_id is not null";
        }
        $settings_graphs["tree"]["default_tree_id"]["sql"] = get_graph_tree_array(true);
    }
    print "<form method='post' action='graph_settings.php'>\n";
    html_start_box("<strong>Graph Settings</strong>", "100%", "", "3", "center", "");
    while (list($tab_short_name, $tab_fields) = each($settings_graphs)) {
        ?>
		<tr>
			<td colspan='2' class='textSubHeaderDark' style='padding: 3px;'>
				<?php 
        print $tabs_graphs[$tab_short_name];
        ?>
			</td>
		</tr>
		<?php 
        $form_array = array();
        while (list($field_name, $field_array) = each($tab_fields)) {
            $form_array += array($field_name => $tab_fields[$field_name]);
            if (isset($field_array["items"]) && is_array($field_array["items"])) {
                while (list($sub_field_name, $sub_field_array) = each($field_array["items"])) {
                    if (graph_config_value_exists($sub_field_name, $_SESSION["sess_user_id"])) {
                        $form_array[$field_name]["items"][$sub_field_name]["form_id"] = 1;
                    }
                    $form_array[$field_name]["items"][$sub_field_name]["value"] = db_fetch_cell("select value from settings_graphs where name='{$sub_field_name}' and user_id=" . $_SESSION["sess_user_id"]);
                }
            } else {
                if (graph_config_value_exists($field_name, $_SESSION["sess_user_id"])) {
                    $form_array[$field_name]["form_id"] = 1;
                }
                $form_array[$field_name]["value"] = db_fetch_cell("select value from settings_graphs where name='{$field_name}' and user_id=" . $_SESSION["sess_user_id"]);
            }
        }
        draw_edit_form(array("config" => array("no_form_tag" => true), "fields" => $form_array));
    }
    html_end_box();
    ?>
	<script type="text/javascript">
	<!--

	function graphSettings() {
		var custom_fonts = document.getElementById('custom_fonts').checked;

		switch(custom_fonts) {
		case true:
			document.getElementById('row_title_size').style.display  = "";
			document.getElementById('row_title_font').style.display  = "";
			document.getElementById('row_legend_size').style.display = "";
			document.getElementById('row_legend_font').style.display = "";
			document.getElementById('row_axis_size').style.display   = "";
			document.getElementById('row_axis_font').style.display   = "";
			document.getElementById('row_unit_size').style.display   = "";
			document.getElementById('row_unit_font').style.display   = "";

			break;
		case false:
			document.getElementById('row_title_size').style.display  = "none";
			document.getElementById('row_title_font').style.display  = "none";
			document.getElementById('row_legend_size').style.display = "none";
			document.getElementById('row_legend_font').style.display = "none";
			document.getElementById('row_axis_size').style.display   = "none";
			document.getElementById('row_axis_font').style.display   = "none";
			document.getElementById('row_unit_size').style.display   = "none";
			document.getElementById('row_unit_font').style.display   = "none";

			break;
		}
	}

	function addLoadEvent(func) {
		var oldonload = window.onload;
		if (typeof window.onload != 'function') {
			window.onload = func;
		} else {
			window.onload = function() {
				if (oldonload) {
					oldonload();
				}
				func();
			}
		}
	}

	addLoadEvent(graphSettings);

	-->
	</script>
	<?php 
    print "<br>";
    if (isset($_SERVER["HTTP_REFERER"])) {
        $timespan_sel_pos = strpos($_SERVER["HTTP_REFERER"], "&predefined_timespan");
        if ($timespan_sel_pos) {
            $_SERVER["HTTP_REFERER"] = substr($_SERVER["HTTP_REFERER"], 0, $timespan_sel_pos);
        }
    }
    $_SESSION["graph_settings_referer"] = isset($_SERVER["HTTP_REFERER"]) ? $_SERVER["HTTP_REFERER"] : "graph_view.php";
    form_hidden_box("save_component_graph_config", "1", "");
    form_save_button("graph_settings.php", "save");
}
Example #8
0
function nmidSmokeping_create_dhtml_tree( $SmokePingServer )
{
	/* Record Start Time */
	list( $micro, $seconds ) = split( " ", microtime() );
	$start = $seconds + $micro;

	$dhtml_tree = array();

	$devices = array();

	$i = 0;

	$tree_list = get_graph_tree_array();

	if ( sizeof( $tree_list ) > 0 ) {
		foreach ( $tree_list as $tree ) {
			$i++;
			$heirarchy = db_fetch_assoc( "select
				graph_tree_items.id,
				graph_tree_items.title,
				graph_tree_items.order_key,
				graph_tree_items.host_id,
				graph_tree_items.host_grouping_type,
				host.description as hostname,
                host.hostname as ipaddress
				from graph_tree_items
				left join host on (host.id=graph_tree_items.host_id)
				where graph_tree_items.graph_tree_id=" . $tree[ "id" ] . "
				and graph_tree_items.local_graph_id = 0
				order by graph_tree_items.order_key" );

			$treeName = preg_replace( "/\s/", "_", $tree[ "name" ] );
			$treeName = preg_replace( "@/@", "-", $treeName );
			$treeName = preg_replace( "@\)@", "-", $treeName );
			$treeName = preg_replace( "@\(@", "-", $treeName );
			$treeName = preg_replace( "@\.@", "", $treeName );
			$treeName = preg_replace( "@\&@", "and", $treeName );
			$treeName = preg_replace( "@\,@", "and", $treeName );
			$treeName = preg_replace( "@\'@", "", $treeName );
			$treeName = preg_replace( "@\+@", "", $treeName );
			$treeName = preg_replace( "@\|@", "-", $treeName );
			$treeName = preg_replace( "@\ä@", "ae", $treeName );
			$treeName = preg_replace( "@\ö@", "oe", $treeName );
			$treeName = preg_replace( "@\ü@", "ue", $treeName );
			$treeName = preg_replace( "@\Ä@", "Ae", $treeName );
			$treeName = preg_replace( "@\Ö@", "Oe", $treeName );
			$treeName = preg_replace( "@\Ü@", "Ue", $treeName );
			$treeName = preg_replace( "@\Ç@", "C", $treeName );
			$treeName = preg_replace( "@\²@", "2", $treeName );
			$treeName = preg_replace( "/\\\/", "-", $treeName );
			$treeName = preg_replace( "@\[@", "_", $treeName );
			$treeName = preg_replace( "@\]@", "_", $treeName );
			$treeName = preg_replace( "/::/", "__", $treeName );

			$dhtml_tree[ $i ] = "+ " . $treeName . "\n" .
				"menu = " . $tree[ "name" ] . "\n" .
				"title = " . $tree[ "name" ] . "\n" .
				"\n";
			$current_tier     = $treeName;
			$tierArr          = array();
			if ( sizeof( $heirarchy ) > 0 ) {
				foreach ( $heirarchy as $leaf ) {
					$i++;
					$tier = tree_tier( $leaf[ "order_key" ] );

					if ( $leaf[ "host_id" ] > 0 ) {
						$nmid_data = db_fetch_assoc( "select nwmgmt_smokeping_server,nwmgmt_settings from host where id=" . $leaf[ "host_id" ] );
						if ( preg_match( "@$SmokePingServer@", $nmid_data[ 0 ][ "nwmgmt_smokeping_server" ] ) > 0 ) {
							if ( preg_match( "/^s1/", $nmid_data[ 0 ][ "nwmgmt_settings" ] ) > 0 ) {
								$tierString = '+';
								for ( $tierCount = 0; $tierCount < $tier; $tierCount++ ) {
									$tierString .= '+';
								}
								$host_text = preg_replace( "/\s/", "_", $leaf[ "hostname" ] );
								$host_text = preg_replace( "@/@", "-", $host_text );
								$host_text = preg_replace( "@\)@", "-", $host_text );
								$host_text = preg_replace( "@\(@", "-", $host_text );
								$host_text = preg_replace( "@\.@", "", $host_text );
								$host_text = preg_replace( "@\&@", "and", $host_text );
								$host_text = preg_replace( "@\,@", "and", $host_text );
								$host_text = preg_replace( "@\'@", "", $host_text );
								$host_text = preg_replace( "@\+@", "", $host_text );
								$host_text = preg_replace( "@\|@", "-", $host_text );
								$host_text = preg_replace( "@\ä@", "ae", $host_text );
								$host_text = preg_replace( "@\ö@", "oe", $host_text );
								$host_text = preg_replace( "@\ü@", "ue", $host_text );
								$host_text = preg_replace( "@\Ä@", "Ae", $host_text );
								$host_text = preg_replace( "@\Ö@", "Oe", $host_text );
								$host_text = preg_replace( "@\Ü@", "Ue", $host_text );
								$host_text = preg_replace( "@\Ç@", "C", $host_text );
								$host_text = preg_replace( "@\²@", "2", $host_text );
								$host_text = preg_replace( "/\\\/", "-", $host_text );
								if ( isset ( $devices[ $host_text ] ) ) {
									// nothing
								}
								else {
									$devices[ $host_text ] = TRUE;
									$dhtml_tree[ $i ]      = $tierString . ' ' . $host_text . "\n" .
										"menu = " . $leaf[ "hostname" ] . "\n" .
										"title = Device " . $leaf[ "hostname" ] . "\n" .
										"host = " . $leaf[ "ipaddress" ] . "\n" .
										"\n";
									$tierArr[ $tier ]      = $host_text;
									$url                   = $current_tier;
									for ( $counter = 1; $counter < $tier + 1; $counter++ ) {
										$url .= '.' . $tierArr[ $counter ];
									}
									db_execute( "UPDATE host SET nwmgmt_smokeping_path = \"$url\" WHERE id=" . $leaf[ "host_id" ] );
								}
							}
						}
					}
					else {
						$tierString = '+';
						for ( $tierCount = 0; $tierCount < $tier; $tierCount++ ) {
							$tierString .= '+';
						}
						$title = $leaf[ "title" ];

						$menu_text = preg_replace( "/\s/", "_", $title );
						$menu_text = preg_replace( "@/@", "-", $menu_text );
						$menu_text = preg_replace( "@\)@", "-", $menu_text );
						$menu_text = preg_replace( "@\(@", "-", $menu_text );
						$menu_text = preg_replace( "@\.@", "", $menu_text );
						$menu_text = preg_replace( "@\&@", "and", $menu_text );
						$menu_text = preg_replace( "@\,@", "and", $menu_text );
						$menu_text = preg_replace( "@\'@", "", $menu_text );
						$menu_text = preg_replace( "@\+@", "", $menu_text );
						$menu_text = preg_replace( "@\|@", "-", $menu_text );
						$menu_text = preg_replace( "@\ä@", "ae", $menu_text );
						$menu_text = preg_replace( "@\ö@", "oe", $menu_text );
						$menu_text = preg_replace( "@\ü@", "ue", $menu_text );
						$menu_text = preg_replace( "@\Ä@", "Ae", $menu_text );
						$menu_text = preg_replace( "@\Ö@", "Oe", $menu_text );
						$menu_text = preg_replace( "@\Ü@", "Ue", $menu_text );
						$menu_text = preg_replace( "@\Ç@", "C", $menu_text );
						$menu_text = preg_replace( "@\²@", "2", $menu_text );

						$title            = preg_replace( "@\'@", "\"", $title );
						$menu_text        = preg_replace( "/\\\/", "-", $menu_text );
						$dhtml_tree[ $i ] = $tierString . " " . $menu_text . "\n" .
							"menu = " . $title . "\n" .
							"title = Location/Devices in " . $title . "\n" .
							"\n";
						$tierArr[ $tier ] = $menu_text;

					}
				}
			}
		}
	}

	return $dhtml_tree;
}
Example #9
0
function settings()
{
    global $tabs_graphs, $settings_graphs, $current_user, $graph_views, $current_user;
    $current_user = db_fetch_row_prepared('SELECT * FROM user_auth WHERE id = ?', array($_SESSION['sess_user_id']));
    /* you cannot have per-user graph settings if cacti's user management is not turned on */
    if (read_config_option('auth_method') == 0) {
        raise_message(6);
        display_output_messages();
        return;
    }
    /* Find out whether this user has right here */
    if (!is_view_allowed('graph_settings')) {
        print "<strong><font class='txtErrorTextBox'>YOU DO NOT HAVE RIGHTS TO CHANGE GRAPH SETTINGS</font></strong>";
        bottom_footer();
        exit;
    }
    if (read_config_option('auth_method') != 0) {
        $settings_graphs['tree']['default_tree_id']['sql'] = get_graph_tree_array(true);
    }
    print "<form method='post' action='graph_settings.php'>\n";
    html_start_box('<strong>Graph Settings</strong>', '100%', '', '3', 'center', '');
    while (list($tab_short_name, $tab_fields) = each($settings_graphs)) {
        $collapsible = true;
        print "<tr class='spacer tableHeader" . ($collapsible ? ' collapsible' : '') . "' id='row_{$tab_short_name}'><td colspan='2' style='cursor:pointer;' class='tableSubHeaderColumn'>" . $tabs_graphs[$tab_short_name] . ($collapsible ? "<div style='float:right;padding-right:4px;'><i class='fa fa-angle-double-up'></i></div>" : "") . "</td></tr>\n";
        $form_array = array();
        while (list($field_name, $field_array) = each($tab_fields)) {
            $form_array += array($field_name => $tab_fields[$field_name]);
            if (isset($field_array['items']) && is_array($field_array['items'])) {
                while (list($sub_field_name, $sub_field_array) = each($field_array['items'])) {
                    if (graph_config_value_exists($sub_field_name, $_SESSION['sess_user_id'])) {
                        $form_array[$field_name]['items'][$sub_field_name]['form_id'] = 1;
                    }
                    $form_array[$field_name]['items'][$sub_field_name]['value'] = db_fetch_cell_prepared('SELECT value FROM settings_graphs WHERE name = ? AND user_id = ?', array($sub_field_name, $_SESSION['sess_user_id']));
                }
            } else {
                if (graph_config_value_exists($field_name, $_SESSION['sess_user_id'])) {
                    $form_array[$field_name]['form_id'] = 1;
                }
                $form_array[$field_name]['value'] = db_fetch_cell_prepared('SELECT value FROM settings_graphs WHERE name = ? AND user_id = ?', array($field_name, $_SESSION['sess_user_id']));
            }
        }
        draw_edit_form(array('config' => array('no_form_tag' => true), 'fields' => $form_array));
    }
    html_end_box();
    ?>
	<script type="text/javascript">
	<!--
	var themeFonts=<?php 
    print read_config_option('font_method');
    ?>
;

	function graphSettings() {
		if (themeFonts == 1) {
				$('#row_fonts').hide();
				$('#row_custom_fonts').hide();
				$('#row_title_size').hide();
				$('#row_title_font').hide();
				$('#row_legend_size').hide();
				$('#row_legend_font').hide();
				$('#row_axis_size').hide();
				$('#row_axis_font').hide();
				$('#row_unit_size').hide();
				$('#row_unit_font').hide();
		}else{
			var custom_fonts = $('#custom_fonts').is(':checked');

			switch(custom_fonts) {
			case true:
				$('#row_fonts').show();
				$('#row_title_size').show();
				$('#row_title_font').show();
				$('#row_legend_size').show();
				$('#row_legend_font').show();
				$('#row_axis_size').show();
				$('#row_axis_font').show();
				$('#row_unit_size').show();
				$('#row_unit_font').show();
				break;
			case false:
				$('#row_fonts').show();
				$('#row_title_size').hide();
				$('#row_title_font').hide();
				$('#row_legend_size').hide();
				$('#row_legend_font').hide();
				$('#row_axis_size').hide();
				$('#row_axis_font').hide();
				$('#row_unit_size').hide();
				$('#row_unit_font').hide();
				break;
			}
		}

		if ($('#timespan_sel').is(':checked')) {
			$('#row_default_rra_id').hide();
			$('#row_default_timespan').show();
			$('#row_default_timeshift').show();
			$('#row_allow_graph_dates_in_future').show();
			$('#row_first_weekdayid').show();
			$('#row_day_shift_start').show();
			$('#row_day_shift_end').show();
		} else {
			$('#row_default_rra_id').show();
			$('#row_default_timespan').hide();
			$('#row_default_timeshift').hide();
			$('#row_allow_graph_dates_in_future').hide();
			$('#row_first_weekdayid').hide();
			$('#row_day_shift_start').hide();
			$('#row_day_shift_end').hide();
		}
	}

	$(function() {
		graphSettings();

		$('#navigation').show();
		$('#navigation_right').show();

		$('input[value="Save"]').click(function(event) {
			event.preventDefault();
			href='<?php 
    print $_SERVER['HTTP_REFERER'];
    ?>
';
			href=href+(href.indexOf('?') > 0 ? '&':'?')+'header=false';
			$.post('graph_settings.php?header=false', $('input, select, textarea').serialize()).done(function(data) {
				document.location='<?php 
    print $_SERVER['HTTP_REFERER'];
    ?>
';
			});
		});

		$('#timespan_sel').change(function() {
			graphSettings();
		});
	});

	-->
	</script>
	<?php 
    if (isset($_SERVER['HTTP_REFERER'])) {
        $timespan_sel_pos = strpos($_SERVER['HTTP_REFERER'], '&predefined_timespan');
        if ($timespan_sel_pos) {
            $_SERVER['HTTP_REFERER'] = substr($_SERVER['HTTP_REFERER'], 0, $timespan_sel_pos);
        }
    }
    $_SESSION['graph_settings_referer'] = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : 'graph_view.php';
    form_hidden_box('save_component_graph_config', '1', '');
    form_save_button('graph_settings.php', 'save');
}
Example #10
0
function draw_tree_dropdown($current_tree_id)
{
    $html = '';
    $tree_list = get_graph_tree_array();
    if (isset($_GET['tree_id'])) {
        $_SESSION['sess_view_tree_id'] = $current_tree_id;
    }
    /* if there is a current tree, make sure it still exists before going on */
    if (!empty($_SESSION['sess_view_tree_id']) && db_fetch_cell('select id from graph_tree where id=' . $_SESSION['sess_view_tree_id']) == '') {
        $_SESSION['sess_view_tree_id'] = 0;
    }
    /* set a default tree if none is already selected */
    if (empty($_SESSION['sess_view_tree_id'])) {
        if (db_fetch_cell('select id from graph_tree where id=' . read_graph_config_option('default_tree_id')) > 0) {
            $_SESSION['sess_view_tree_id'] = read_graph_config_option('default_tree_id');
        } else {
            if (sizeof($tree_list) > 0) {
                $_SESSION['sess_view_tree_id'] = $tree_list[0]['id'];
            }
        }
    }
    /* make the dropdown list of trees */
    if (sizeof($tree_list) > 1) {
        $html = "<form name='form_tree_id' id='form_tree_id' action='graph_view.php'>\n\t\t\t<td valign='absmiddle' style='height:30px;' class='even'>\n\n\t\t\t\t<table width='100%' cellspacing='0' cellpadding='0'>\n\n\t\t\t\t\t<tr>\n\n\t\t\t\t\t\t<td width='200' class='textHeader'>\n\n\t\t\t\t\t\t\t&nbsp;&nbsp;Select a Graph Hierarchy:&nbsp;\n\n\t\t\t\t\t\t</td>\n\n\t\t\t\t\t\t<td class='even'>\n\n\t\t\t\t\t\t\t<select name='cbo_tree_id' onChange='window.location=document.form_tree_id.cbo_tree_id.options[document.form_tree_id.cbo_tree_id.selectedIndex].value'>\n";
        foreach ($tree_list as $tree) {
            $html .= "<option value='graph_view.php?action=tree&tree_id=" . $tree['id'] . "'";
            if ($_SESSION['sess_view_tree_id'] == $tree['id']) {
                $html .= ' selected';
            }
            $html .= '>' . $tree['name'] . "</option>\n";
        }
        $html .= "</select>\n";
        $html .= "</td></tr></table></td></form>\n";
    } elseif (sizeof($tree_list) == 1) {
        /* there is only one tree; use it */
    }
    return $html;
}
Example #11
0
/* get the start and end times for the graph */
$timespan = array();
$first_weekdayid = read_user_setting('first_weekdayid');
get_timespan($timespan, time(), get_request_var('timespan'), $first_weekdayid);
$graph_tree = $tree_id;
$html = '';
$out = '';
/* detect the next graph regardless of type */
get_next_graphid($graphpp, $filter, $graph_tree, $leaf_id);
switch (read_config_option('cycle_custom_graphs_type')) {
    case '0':
    case '1':
        /* will only use the filter for full rotation */
        break;
    case '2':
        $tree_list = get_graph_tree_array();
        if (sizeof($tree_list)) {
            $html = "<td><select id='tree_id' name='tree_id' onChange='newTree()' title='" . __('Select Tree to View') . "'>\n";
            foreach ($tree_list as $tree) {
                $html .= "<option value='" . $tree['id'] . "'" . ($graph_tree == $tree['id'] ? ' selected' : '') . '>' . title_trim($tree['name'], 30) . "</option>\n";
            }
            $html .= "</select>\n";
            $leaves = db_fetch_assoc("SELECT * FROM graph_tree_items WHERE title!='' AND graph_tree_id='{$graph_tree}' ORDER BY parent, position");
            if (sizeof($leaves)) {
                $html .= "<select id='leaf_id' name='leaf_id' onChange='newTree()' title='" . __('Select Tree Leaf to Display') . "'>\n";
                $html .= "<option value='-1'" . ($leaf_id == -1 ? ' selected' : '') . ">" . __('All Levels') . "</option>\n";
                $html .= "<option value='-2'" . ($leaf_id == -2 ? ' selected' : '') . ">" . __('Top Level') . "</option>\n";
                foreach ($leaves as $leaf) {
                    $html .= "<option value='" . $leaf['id'] . "'" . ($leaf_id == $leaf['id'] ? ' selected' : '') . '>' . $leaf['title'] . "</option>\n";
                }
                $html .= "</select>\n";
Example #12
0
function cycle_config_settings()
{
    global $tabs, $settings, $page_refresh_interval, $graph_timespans;
    global $cycle_width, $cycle_height, $cycle_cols, $cycle_graphs;
    /* check for an upgrade */
    plugin_cycle_check_config();
    if (isset($_SERVER['PHP_SELF']) && basename($_SERVER['PHP_SELF']) != 'settings.php') {
        return;
    }
    $tabs['cycle'] = __('Cycle');
    $treeList = array_rekey(get_graph_tree_array(null, true), 'id', 'name');
    $temp = array('cycle_header' => array('friendly_name' => __('Cycle Graphs'), 'method' => 'spacer'), 'cycle_delay' => array('friendly_name' => __('Delay Interval'), 'description' => __('This is the time in seconds before the next graph is displayed.'), 'method' => 'drop_array', 'default' => 60, 'array' => $page_refresh_interval), 'cycle_timespan' => array('friendly_name' => __('Graph Timespan'), 'description' => __('This is the default timespan that will be displayed on the page.'), 'method' => 'drop_array', 'default' => 5, 'array' => $graph_timespans), 'cycle_columns' => array('friendly_name' => __('Column Count'), 'description' => __('In Tree Mode this is the number of columns that will be used.'), 'method' => 'drop_array', 'default' => 2, 'array' => $cycle_cols), 'cycle_graphs' => array('friendly_name' => __('Number of Graphs per Page'), 'description' => __('Select the number of graphs to display per page'), 'method' => 'drop_array', 'default' => '4', 'array' => $cycle_graphs), 'cycle_height' => array('friendly_name' => __('Graph Height'), 'description' => __('This sets the graph height for the displayed graphs.'), 'method' => 'drop_array', 'default' => '100', 'array' => $cycle_height), 'cycle_width' => array('friendly_name' => __('Graph Width'), 'description' => __('This sets the graph width for the displayed graphs.'), 'method' => 'drop_array', 'default' => '400', 'array' => $cycle_width), 'cycle_font_size' => array('friendly_name' => __('Title Font Size'), 'description' => __('This is the font size in pixels for the title. (1 - 100)'), 'method' => 'textbox', 'default' => '8', 'max_length' => 3, 'size' => 4), 'cycle_font_face' => array('friendly_name' => __('Title Font Face'), 'description' => __('This is the font face for the title.'), 'method' => 'textbox', 'max_length' => 100), 'cycle_font_color' => array('friendly_name' => __('Title Font Color'), 'description' => __('This is the font color for the title.'), 'method' => 'drop_color', 'default' => '1'), 'cycle_legend' => array('friendly_name' => __('Display Legend'), 'description' => __('Check this to display legend.'), 'method' => 'checkbox', 'default' => ''), 'cycle_cheader' => array('friendly_name' => __('Predefined Rotations'), 'method' => 'spacer'), 'cycle_custom_graphs_type' => array('friendly_name' => __('Rotation Type'), 'description' => __('Select which method to use for custom graph rotation.  If you select \'Specific List\', you must define a list of graph id\'s'), 'method' => 'drop_array', 'default' => '1', 'array' => array(0 => __('Legacy (All)'), 1 => __('Specific List'), 2 => __('Tree Mode'))), 'cycle_custom_graphs_list' => array('friendly_name' => __('Custom Graph List'), 'description' => __('This must be a comma delimited list of graph id\'s to cycle through. For example \'1,2,3,4\''), 'method' => 'textbox', 'max_length' => 255), 'cycle_custom_graphs_tree' => array('friendly_name' => __('Default Tree'), 'description' => __('Select the graph tree to cycle if Tree Mode is selected'), 'method' => 'drop_array', 'default' => 'None', 'array' => $treeList));
    if (isset($settings['cycle'])) {
        $settings['cycle'] = array_merge($settings['cycle'], $temp);
    } else {
        $settings['cycle'] = $temp;
    }
}