Exemple #1
0
function graph()
{
    global $colors, $graph_actions, $item_rows;
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_request("host_id"));
    input_validate_input_number(get_request_var_request("graph_rows"));
    input_validate_input_number(get_request_var_request("template_id"));
    input_validate_input_number(get_request_var_request("page"));
    /* ==================================================== */
    /* clean up search string */
    if (isset($_REQUEST["filter"])) {
        $_REQUEST["filter"] = sanitize_search_string(get_request_var("filter"));
    }
    /* clean up sort_column string */
    if (isset($_REQUEST["sort_column"])) {
        $_REQUEST["sort_column"] = sanitize_search_string(get_request_var("sort_column"));
    }
    /* clean up sort_direction string */
    if (isset($_REQUEST["sort_direction"])) {
        $_REQUEST["sort_direction"] = sanitize_search_string(get_request_var("sort_direction"));
    }
    /* if the user pushed the 'clear' button */
    if (isset($_REQUEST["clear_x"])) {
        kill_session_var("sess_graph_current_page");
        kill_session_var("sess_graph_filter");
        kill_session_var("sess_graph_sort_column");
        kill_session_var("sess_graph_sort_direction");
        kill_session_var("sess_graph_host_id");
        kill_session_var("sess_graph_rows");
        kill_session_var("sess_graph_template_id");
        unset($_REQUEST["page"]);
        unset($_REQUEST["filter"]);
        unset($_REQUEST["sort_column"]);
        unset($_REQUEST["sort_direction"]);
        unset($_REQUEST["host_id"]);
        unset($_REQUEST["graph_rows"]);
        unset($_REQUEST["template_id"]);
    }
    /* remember these search fields in session vars so we don't have to keep passing them around */
    load_current_session_value("page", "sess_graph_current_page", "1");
    load_current_session_value("filter", "sess_graph_filter", "");
    load_current_session_value("sort_column", "sess_graph_sort_column", "title_cache");
    load_current_session_value("sort_direction", "sess_graph_sort_direction", "ASC");
    load_current_session_value("host_id", "sess_graph_host_id", "-1");
    load_current_session_value("graph_rows", "sess_graph_rows", read_config_option("num_rows_graph"));
    load_current_session_value("template_id", "sess_graph_template_id", "-1");
    /* if the number of rows is -1, set it to the default */
    if (get_request_var_request("graph_rows") == -1) {
        $_REQUEST["graph_rows"] = read_config_option("num_rows_graph");
    }
    ?>
	<script type="text/javascript">
	<!--

	function applyGraphsFilterChange(objForm) {
		strURL = '?host_id=' + objForm.host_id.value;
		strURL = strURL + '&graph_rows=' + objForm.graph_rows.value;
		strURL = strURL + '&filter=' + objForm.filter.value;
		strURL = strURL + '&template_id=' + objForm.template_id.value;
		document.location = strURL;
	}

	-->
	</script>
	<?php 
    /* modify for multi user start */
    if (check_resource_count(RESOURCE_GRAPH) == TRUE) {
        html_start_box("<strong>Graph Management</strong>", "100%", $colors["header"], "3", "center", "graphs.php?action=graph_edit&host_id=" . htmlspecialchars(get_request_var_request("host_id")));
    } else {
        html_start_box("<strong>Graph Management</strong>", "100%", $colors["header"], "3", "center", "");
    }
    ?>
	<tr bgcolor="#<?php 
    print $colors["panel"];
    ?>
">
		<td>
			<form name="form_graph_id" action="graphs.php">
			<table cellpadding="1" cellspacing="0">
				<tr>
					<td width="50">
						Host:&nbsp;
					</td>
					<td width="1">
						<select name="host_id" onChange="applyGraphsFilterChange(document.form_graph_id)">
							<option value="-1"<?php 
    if (get_request_var_request("host_id") == "-1") {
        ?>
 selected<?php 
    }
    ?>
>Any</option>
                            <?php 
    /* modify for multi user start */
    if ($_SESSION["permission"] == ACCESS_ADMINISTRATOR) {
        ?>
							<option value="0"<?php 
        if (get_request_var_request("host_id") == "0") {
            ?>
 selected<?php 
        }
        ?>
>None</option>
							<?php 
    }
    if ($_SESSION["permission"] <= ACCESS_ADMINISTRATOR) {
        $hosts = db_fetch_assoc("\r\n                                    SELECT host.id,CONCAT_WS('',host.description,' (',host.hostname,')') as name FROM host \r\n                                        INNER JOIN user_auth_perms ON host.id = user_auth_perms.item_id AND user_auth_perms.user_id = '" . $_SESSION["sess_user_id"] . "' AND user_auth_perms.type = '3' \r\n                                    ORDER BY host.description,host.hostname");
    } else {
        if (read_config_option("auth_method") != 0) {
            /* get policy information for the sql where clause */
            $current_user = db_fetch_row("select * from user_auth where id=" . $_SESSION["sess_user_id"]);
            $sql_where = get_graph_permissions_sql($current_user["policy_graphs"], $current_user["policy_hosts"], $current_user["policy_graph_templates"]);
            $hosts = db_fetch_assoc("SELECT DISTINCT host.id, CONCAT_WS('',host.description,' (',host.hostname,')') as name\r\n\t\t\t\t\t\t\t\t\tFROM (graph_templates_graph,host)\r\n\t\t\t\t\t\t\t\t\tLEFT JOIN graph_local ON (graph_local.host_id=host.id)\r\n\t\t\t\t\t\t\t\t\tLEFT JOIN graph_templates ON (graph_templates.id=graph_local.graph_template_id)\r\n\t\t\t\t\t\t\t\t\tLEFT JOIN user_auth_perms ON ((graph_templates_graph.local_graph_id=user_auth_perms.item_id and user_auth_perms.type=1 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (host.id=user_auth_perms.item_id and user_auth_perms.type=3 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (graph_templates.id=user_auth_perms.item_id and user_auth_perms.type=4 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . "))\r\n\t\t\t\t\t\t\t\t\tWHERE graph_templates_graph.local_graph_id=graph_local.id\r\n\t\t\t\t\t\t\t\t\t" . (empty($sql_where) ? "" : "and {$sql_where}") . "\r\n\t\t\t\t\t\t\t\t\tORDER BY name");
        } else {
            $hosts = db_fetch_assoc("SELECT DISTINCT host.id, CONCAT_WS('',host.description,' (',host.hostname,')') as name\r\n\t\t\t\t\t\t\t\t\tFROM host\r\n\t\t\t\t\t\t\t\t\tORDER BY name");
        }
    }
    /* modify for multi user end */
    if (sizeof($hosts) > 0) {
        foreach ($hosts as $host) {
            print "<option value='" . $host["id"] . "'";
            if (get_request_var_request("host_id") == $host["id"]) {
                print " selected";
            }
            print ">" . title_trim(htmlspecialchars($host["name"]), 40) . "</option>\n";
        }
    }
    ?>
						</select>
					</td>
					<td width="70">
						&nbsp;Template:&nbsp;
					</td>
					<td width="1">
						<select name="template_id" onChange="applyGraphsFilterChange(document.form_graph_id)">
							<option value="-1"<?php 
    if (get_request_var_request("template_id") == "-1") {
        ?>
 selected<?php 
    }
    ?>
>Any</option>
                            <?php 
    /* modify for multi user start */
    if ($_SESSION["permission"] == ACCESS_ADMINISTRATOR) {
        ?>
							<option value="0"<?php 
        if (get_request_var_request("template_id") == "0") {
            ?>
 selected<?php 
        }
        ?>
>None</option>
							<?php 
    }
    if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
        $templates = db_fetch_assoc("\r\n                                    SELECT DISTINCT graph_templates.id, graph_templates.name FROM graph_templates\r\n                                        LEFT JOIN graph_local ON graph_templates.id = graph_local.graph_template_id\r\n                                        INNER JOIN host ON graph_local.host_id = host.id\r\n                                        INNER JOIN user_auth_perms ON host.id = user_auth_perms.item_id AND user_auth_perms.user_id = '" . $_SESSION["sess_user_id"] . "' AND user_auth_perms.type = '3'\r\n                                    ORDER BY graph_templates.name");
    } else {
        if (read_config_option("auth_method") != 0) {
            $templates = db_fetch_assoc("SELECT DISTINCT graph_templates.id, graph_templates.name\r\n\t\t\t\t\t\t\t\t\tFROM (graph_templates_graph,graph_local)\r\n\t\t\t\t\t\t\t\t\tLEFT JOIN host ON (host.id=graph_local.host_id)\r\n\t\t\t\t\t\t\t\t\tLEFT JOIN graph_templates ON (graph_templates.id=graph_local.graph_template_id)\r\n\t\t\t\t\t\t\t\t\tLEFT JOIN user_auth_perms ON ((graph_templates_graph.local_graph_id=user_auth_perms.item_id and user_auth_perms.type=1 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (host.id=user_auth_perms.item_id and user_auth_perms.type=3 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . ") OR (graph_templates.id=user_auth_perms.item_id and user_auth_perms.type=4 and user_auth_perms.user_id=" . $_SESSION["sess_user_id"] . "))\r\n\t\t\t\t\t\t\t\t\tWHERE graph_templates_graph.local_graph_id=graph_local.id\r\n\t\t\t\t\t\t\t\t\tAND graph_templates.id IS NOT NULL\r\n\t\t\t\t\t\t\t\t\t" . (empty($sql_where) ? "" : "AND {$sql_where}") . "\r\n\t\t\t\t\t\t\t\t\tORDER BY name");
        } else {
            $templates = db_fetch_assoc("SELECT DISTINCT graph_templates.id, graph_templates.name\r\n\t\t\t\t\t\t\t\t\tFROM graph_templates\r\n\t\t\t\t\t\t\t\t\tORDER BY name");
        }
    }
    /* modify for multi user end */
    if (sizeof($templates) > 0) {
        foreach ($templates as $template) {
            print "<option value='" . $template["id"] . "'";
            if (get_request_var_request("template_id") == $template["id"]) {
                print " selected";
            }
            print ">" . title_trim(htmlspecialchars($template["name"]), 40) . "</option>\n";
        }
    }
    ?>
						</select>
					</td>
					<td width="120" nowrap style='white-space: nowrap;'>
						&nbsp;<input type="submit" value="Go" title="Set/Refresh Filters">
						<input type="submit" name="clear_x" value="Clear" title="Clear Filters">
					</td>
				</tr>
			</table>
			<table cellpadding="1" cellspacing="0">
				<tr>
					<td width="50">
						Search:&nbsp;
					</td>
					<td>
						<input type="text" name="filter" size="40" value="<?php 
    print htmlspecialchars(get_request_var_request("filter"));
    ?>
">
					</td>
					<td nowrap style='white-space: nowrap;' width="50">
						Rows per Page:&nbsp;
					</td>
					<td width="1">
						<select name="graph_rows" onChange="applyGraphsFilterChange(document.form_graph_id)">
							<option value="-1"<?php 
    if (get_request_var_request("graph_rows") == "-1") {
        ?>
 selected<?php 
    }
    ?>
>Default</option>
							<?php 
    if (sizeof($item_rows) > 0) {
        foreach ($item_rows as $key => $value) {
            print "<option value='" . $key . "'";
            if (get_request_var_request("graph_rows") == $key) {
                print " selected";
            }
            print ">" . htmlspecialchars($value) . "</option>\n";
        }
    }
    ?>
						</select>
					</td>
				</tr>
			</table>
			<input type='hidden' name='page' value='1'>
			</form>
		</td>
	</tr>
	<?php 
    html_end_box();
    /* form the 'where' clause for our main sql query */
    if (strlen(get_request_var_request("filter"))) {
        $sql_where = " AND (graph_templates_graph.title_cache like '%%" . get_request_var_request("filter") . "%%'" . " OR graph_templates.name like '%%" . get_request_var_request("filter") . "%%')";
    } else {
        $sql_where = "";
    }
    if (get_request_var_request("host_id") == "-1") {
        /* Show all items */
    } elseif (get_request_var_request("host_id") == "0") {
        $sql_where .= " AND graph_local.host_id=0";
    } elseif (!empty($_REQUEST["host_id"])) {
        $sql_where .= " AND graph_local.host_id=" . get_request_var_request("host_id");
    }
    if (get_request_var_request("template_id") == "-1") {
        /* Show all items */
    } elseif (get_request_var_request("template_id") == "0") {
        $sql_where .= " AND graph_templates_graph.graph_template_id=0";
    } elseif (!empty($_REQUEST["template_id"])) {
        $sql_where .= " AND graph_templates_graph.graph_template_id=" . get_request_var_request("template_id");
    }
    /* allow plugins to modify sql_where */
    $sql_where .= api_plugin_hook_function('graphs_sql_where', $sql_where);
    /* print checkbox form for validation */
    print "<form name='chk' method='post' action='graphs.php'>\n";
    html_start_box("", "100%", $colors["header"], "3", "center", "");
    /* modify for multi user start */
    $sql_join = "";
    if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
        $sql_join = "\r\n        \tINNER JOIN host ON graph_local.host_id = host.id\r\n            INNER JOIN user_auth_perms ON host.id = user_auth_perms.item_id AND user_auth_perms.user_id = '" . $_SESSION["sess_user_id"] . "' AND user_auth_perms.type = '3'";
    }
    $total_rows = db_fetch_cell("SELECT\r\n\t\tDISTINCT(COUNT(graph_templates_graph.id))\r\n\t\tFROM (graph_local,graph_templates_graph)\r\n\t\tLEFT JOIN graph_templates ON (graph_local.graph_template_id=graph_templates.id)\r\n        {$sql_join}\r\n\t\tWHERE graph_local.id=graph_templates_graph.local_graph_id\r\n\t\t{$sql_where}");
    $graph_list = db_fetch_assoc("SELECT DISTINCT\r\n\t\tgraph_templates_graph.id,\r\n\t\tgraph_templates_graph.local_graph_id,\r\n\t\tgraph_templates_graph.height,\r\n\t\tgraph_templates_graph.width,\r\n\t\tgraph_templates_graph.title_cache,\r\n\t\tgraph_templates.name,\r\n\t\tgraph_local.host_id\r\n\t\tFROM (graph_local,graph_templates_graph)\r\n\t\tLEFT JOIN graph_templates ON (graph_local.graph_template_id=graph_templates.id)\r\n        {$sql_join}\r\n\t\tWHERE graph_local.id=graph_templates_graph.local_graph_id\r\n\t\t{$sql_where}\r\n\t\tORDER BY " . $_REQUEST["sort_column"] . " " . get_request_var_request("sort_direction") . " LIMIT " . get_request_var_request("graph_rows") * (get_request_var_request("page") - 1) . "," . get_request_var_request("graph_rows"));
    /* modify for multi user end */
    /* generate page list */
    $url_page_select = get_page_list(get_request_var_request("page"), MAX_DISPLAY_PAGES, get_request_var_request("graph_rows"), $total_rows, "graphs.php?filter=" . get_request_var_request("filter") . "&host_id=" . get_request_var_request("host_id"));
    $nav = "<tr bgcolor='#" . $colors["header"] . "'>\r\n\t\t\t<td colspan='5'>\r\n\t\t\t\t<table width='100%' cellspacing='0' cellpadding='0' border='0'>\r\n\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t<td align='left' class='textHeaderDark'>\r\n\t\t\t\t\t\t\t<strong>&lt;&lt; ";
    if (get_request_var_request("page") > 1) {
        $nav .= "<a class='linkOverDark' href='" . htmlspecialchars("graphs.php?filter=" . get_request_var_request("filter") . "&host_id=" . get_request_var_request("host_id") . "&page=" . (get_request_var_request("page") - 1)) . "'>";
    }
    $nav .= "Previous";
    if (get_request_var_request("page") > 1) {
        $nav .= "</a>";
    }
    $nav .= "</strong>\r\n\t\t\t\t\t\t</td>\n\r\n\t\t\t\t\t\t<td align='center' class='textHeaderDark'>\r\n\t\t\t\t\t\t\tShowing Rows " . (get_request_var_request("graph_rows") * (get_request_var_request("page") - 1) + 1) . " to " . ($total_rows < get_request_var_request("graph_rows") || $total_rows < get_request_var_request("graph_rows") * get_request_var_request("page") ? $total_rows : get_request_var_request("graph_rows") * get_request_var_request("page")) . " of {$total_rows} [{$url_page_select}]\r\n\t\t\t\t\t\t</td>\n\r\n\t\t\t\t\t\t<td align='right' class='textHeaderDark'>\r\n\t\t\t\t\t\t\t<strong>";
    if (get_request_var_request("page") * get_request_var_request("graph_rows") < $total_rows) {
        $nav .= "<a class='linkOverDark' href='" . htmlspecialchars("graphs.php?filter=" . get_request_var_request("filter") . "&host_id=" . get_request_var_request("host_id") . "&page=" . (get_request_var_request("page") + 1)) . "'>";
    }
    $nav .= "Next";
    if (get_request_var_request("page") * get_request_var_request("graph_rows") < $total_rows) {
        $nav .= "</a>";
    }
    $nav .= " &gt;&gt;</strong>\r\n\t\t\t\t\t\t</td>\n\r\n\t\t\t\t\t</tr>\r\n\t\t\t\t</table>\r\n\t\t\t</td>\r\n\t\t</tr>\n";
    print $nav;
    $display_text = array("title_cache" => array("Graph Title", "ASC"), "local_graph_id" => array("ID", "ASC"), "name" => array("Template Name", "ASC"), "height" => array("Size", "ASC"));
    html_header_sort_checkbox($display_text, get_request_var_request("sort_column"), get_request_var_request("sort_direction"), false);
    $i = 0;
    if (sizeof($graph_list) > 0) {
        foreach ($graph_list as $graph) {
            /* we're escaping strings here, so no need to escape them on form_selectable_cell */
            $template_name = empty($graph["name"]) ? "<em>None</em>" : htmlspecialchars($graph["name"]);
            form_alternate_row_color($colors["alternate"], $colors["light"], $i, 'line' . $graph["local_graph_id"]);
            $i++;
            form_selectable_cell("<a class='linkEditMain' href='" . htmlspecialchars("graphs.php?action=graph_edit&id=" . $graph["local_graph_id"]) . "' title='" . htmlspecialchars($graph["title_cache"]) . "'>" . (get_request_var_request("filter") != "" ? preg_replace("/(" . preg_quote(get_request_var_request("filter")) . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", title_trim(htmlspecialchars($graph["title_cache"]), read_config_option("max_title_graph"))) : title_trim(htmlspecialchars($graph["title_cache"]), read_config_option("max_title_graph"))) . "</a>", $graph["local_graph_id"]);
            form_selectable_cell($graph["local_graph_id"], $graph["local_graph_id"]);
            form_selectable_cell(get_request_var_request("filter") != "" ? preg_replace("/(" . preg_quote(get_request_var_request("filter")) . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", $template_name) : $template_name, $graph["local_graph_id"]);
            form_selectable_cell($graph["height"] . "x" . $graph["width"], $graph["local_graph_id"]);
            form_checkbox_cell($graph["title_cache"], $graph["local_graph_id"]);
            form_end_row();
        }
        /* put the nav bar on the bottom as well */
        print $nav;
    } else {
        print "<tr><td><em>No Graphs Found</em></td></tr>";
    }
    html_end_box(false);
    /* add a list of tree names to the actions dropdown */
    add_tree_names_to_actions_array();
    /* draw the dropdown containing a list of available actions for this form */
    draw_actions_dropdown($graph_actions);
    print "</form>\n";
}
Exemple #2
0
 | but WITHOUT ANY WARRANTY; without even the implied warranty of          |
 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           |
 | GNU General Public License for more details.                            |
 +-------------------------------------------------------------------------+
 | Cacti: The Complete RRDTool-based Graphing Solution                     |
 +-------------------------------------------------------------------------+
 | This code is designed, written, and maintained by the Cacti Group. See  |
 | about.php and/or the AUTHORS file for specific developer information.   |
 +-------------------------------------------------------------------------+
 | http://www.cacti.net/                                                   |
 +-------------------------------------------------------------------------+
*/
chdir('../../');
include_once './include/auth.php';
/* modify for multi user start */
if (!check_resource_count(RESOURCE_THOLD)) {
    access_denied();
}
/* modify for multi user end */
$host = $graph = $ds = $dt = '';
if (isset($_REQUEST['hostid']) && $_REQUEST['hostid'] != '') {
    input_validate_input_number($_REQUEST['hostid']);
    /* modify for multi user start */
    if (!check_host($_REQUEST['hostid'])) {
        access_denied();
    }
    /* modify for multi user end */
    $host = $_REQUEST['hostid'];
} else {
    $host = 0;
}
Exemple #3
0
if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
    $form_array["notify_warning"]["sql"] = "SELECT plugin_notification_lists.id, plugin_notification_lists.name FROM plugin_notification_lists \r\n                INNER JOIN user_auth ON plugin_notification_lists.name = CONCAT(user_auth.username,'_warning') AND user_auth.id = '" . $_SESSION["sess_user_id"] . "'";
    $form_array["notify_alert"]["sql"] = "SELECT plugin_notification_lists.id, plugin_notification_lists.name FROM plugin_notification_lists \r\n                INNER JOIN user_auth ON plugin_notification_lists.name = CONCAT(user_auth.username,'_alert') AND user_auth.id = '" . $_SESSION["sess_user_id"] . "'";
}
/* modify for multi user end */
if (read_config_option("thold_disable_legacy") != 'on') {
    $extra = array('notify_accounts' => array('friendly_name' => 'Notify accounts', 'method' => 'drop_multi', 'description' => 'This is a listing of accounts that will be notified when this threshold is breached.<br><br><br><br>', 'array' => $send_notification_array, 'sql' => $sql), 'notify_extra' => array('friendly_name' => 'Alert Emails', 'method' => 'textarea', 'textarea_rows' => 3, 'textarea_cols' => 50, 'description' => 'You may specify here extra Emails to receive alerts for this data source (comma separated)', 'value' => isset($thold_item_data['notify_extra']) ? $thold_item_data['notify_extra'] : ''), 'notify_warning_extra' => array('friendly_name' => 'Warning Emails', 'method' => 'textarea', 'textarea_rows' => 3, 'textarea_cols' => 50, 'description' => 'You may specify here extra Emails to receive warnings for this data source (comma separated)', 'value' => isset($thold_item_data['notify_warning_extra']) ? $thold_item_data['notify_warning_extra'] : ''));
    $form_array += $extra;
} else {
    $extra = array('notify_accounts' => array('method' => 'hidden', 'value' => 'ignore'), 'notify_extra' => array('method' => 'hidden', 'value' => isset($thold_item_data['notify_extra']) ? $thold_item_data['notify_extra'] : ''), 'notify_warning_extra' => array('method' => 'hidden', 'value' => isset($thold_item_data['notify_warning_extra']) ? $thold_item_data['notify_warning_extra'] : ''));
    $form_array += $extra;
}
draw_edit_form(array('config' => array('no_form_tag' => true), 'fields' => $form_array + array('data_template_rrd_id' => array('method' => 'hidden', 'value' => isset($template_rrd) ? $template_rrd['id'] : '0'), 'hostid' => array('method' => 'hidden', 'value' => $hostid), 'rra' => array('method' => 'hidden', 'value' => $rra))));
html_end_box();
/* modify for multi user start */
if (check_resource_count(RESOURCE_THOLD) == TRUE || db_fetch_cell("SELECT thold_data.data_id FROM thold_data WHERE thold_data.data_id = '" . $_GET['view_rrd'] . "'")) {
    form_save_button('thold.php?rra=' . $rra . '&view_rrd=' . $_GET['view_rrd'], 'save');
}
/* modify for multi user end */
unset($template_data_rrds);
?>
<!-- Make it look intelligent :) -->
<script type="text/javascript">
	function Template_EnableDisable() {
		var _f = document.THold;
		var status = _f.template_enabled.checked;
		_f.name.disabled = status;
		_f.thold_type.disabled = status;
		_f.thold_hi.disabled = status;
		_f.thold_low.disabled = status;
		_f.thold_fail_trigger.disabled = status;
Exemple #4
0
function graphs()
{
    global $colors;
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_request("host_id"));
    input_validate_input_number(get_request_var_request("graph_type"));
    /* ==================================================== */
    /* modify for multi user start */
    if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
        if ($_REQUEST["host_id"] == "") {
            $_REQUEST["host_id"] = db_fetch_cell("\r\n                SELECT host.id FROM host\r\n                    INNER JOIN user_auth_perms ON host.id = user_auth_perms.item_id AND user_auth_perms.user_id = '" . $_SESSION["sess_user_id"] . "' AND user_auth_perms.type = '3'\r\n                ORDER BY host.id LIMIT 1");
        }
    }
    if (!check_host($_REQUEST["host_id"])) {
        access_denied();
    }
    /* modify for multi user end */
    /* clean up search string */
    if (isset($_REQUEST["filter"])) {
        $_REQUEST["filter"] = sanitize_search_string(get_request_var("filter"));
    }
    /* if the user pushed the 'clear' button */
    if (isset($_REQUEST["clear_x"])) {
        kill_session_var("sess_graphs_new_filter");
        unset($_REQUEST["filter"]);
        $changed = true;
    } else {
        /* if any of the settings changed, reset the page number */
        $changed = false;
        $changed += check_changed("host_id", "sess_graphs_new_host_id");
        $changed += check_changed("graph_type", "sess_graphs_new_graph_type");
        $changed += check_changed("filter", "sess_graphs_new_filter");
    }
    load_current_session_value("host_id", "sess_graphs_new_host_id", db_fetch_cell("select id from host order by description,hostname limit 1"));
    load_current_session_value("graph_type", "sess_graphs_new_graph_type", read_config_option("default_graphs_new_dropdown"));
    load_current_session_value("filter", "sess_graphs_new_filter", "");
    $host = db_fetch_row("select id,description,hostname,host_template_id from host where id=" . $_REQUEST["host_id"]);
    $row_limit = read_config_option("num_rows_data_query");
    $debug_log = debug_log_return("new_graphs");
    if (!empty($debug_log)) {
        debug_log_clear("new_graphs");
        if (read_config_option("cacti_popup_messages") == "on") {
            ?>
		<div id='message'>
			<?php 
            print "<table align='center' style='width:100%;background-color:#" . $colors["header"] . ";'><tr><td style='align:center;padding:3px;font-weight:bold;font-size:10pt;text-align:center;'>Graphs Created</td><td style='width:1px;align:right;'><input type='button' value='Clear' onClick='javascript:document.getElementById(\"message\").style.display=\"none\"' style='align=right;'></td></tr></table>";
            ?>
			<?php 
            print "<table align='left' style='width:100%;'><tr><td><ul style='text-align:left;white-space:nowrap;color:#000000;padding:2px 10px;margin:10px;'>" . $debug_log . "</ul></td></tr></table>";
            ?>
		</div>
		<?php 
        } else {
            ?>
		<table width='100%' style='background-color: #f5f5f5; border: 1px solid #bbbbbb;' align='center'>
			<tr bgcolor="<?php 
            print $colors["light"];
            ?>
">
				<td style="padding: 3px; font-family: monospace;">
					<ul style='margin:0px 5px;padding-left:10px'><?php 
            print $debug_log;
            ?>
</ul>
				</td>
			</tr>
		</table>
		<br><?php 
        }
    }
    ?>
	<script type="text/javascript">
	<!--
	<?php 
    if (read_config_option("cacti_popup_messages") == "on") {
        ?>
	var obj = document.getElementById('message');

	if (obj) {
		if (window.innerHeight) {
			height = window.innerHeight;
			width  = window.innerWidth;
		}else{
			height = document.body.clientHeight;
			width  = document.body.clientWidth;
		}
		obj.style.position = "absolute";
		obj.style.padding = "0px";
		obj.style.display = "";
		obj.style.overflow = "auto";
		obj.style.color = "#FFFFFF";
		obj.style.backgroundColor = "#<?php 
        print $colors["light"];
        ?>
";
		obj.style.border = "1px solid #<?php 
        print $colors["header"];
        ?>
";
		cw = obj.offsetWidth;
		// Adjust for IE6
		if (!cw) cw = 150;
		ch = obj.offsetHeight;
		obj.style.top = '65px';
		obj.style.left = ((width/2) - (cw/2) - 88)+'px';
	}
	<?php 
    }
    ?>

	function applyGraphsNewFilterChange(objForm) {
		strURL = '?graph_type=' + objForm.graph_type.value;
		strURL = strURL + '&host_id=' + objForm.host_id.value;
		strURL = strURL + '&filter=' + objForm.filter.value;;
		document.location = strURL;
	}

	-->
	</script>
	<form name="form_graphs_new" action="graphs_new.php">
	<table width="100%" cellpadding="4" align="center">
		<tr>
			<td nowrap style='white-space: nowrap;' width="30%" class="textInfo">
				<?php 
    print htmlspecialchars($host["description"]);
    ?>
 (<?php 
    print htmlspecialchars($host["hostname"]);
    ?>
)
			</td>
			<td align="left" class="textInfo" colspan="2" style="color: #aaaaaa;">
				<?php 
    if (!empty($host["host_template_id"])) {
        print htmlspecialchars(db_fetch_cell("select name from host_template where id=" . $host["host_template_id"]));
    }
    ?>
			</td>
		</tr>
	</table>
	<table width="100%" cellpadding="0" align="center">
		<tr>
			<td nowrap style='white-space: nowrap;' width="55" class="textArea">
				Host:&nbsp;
			</td>
			<td width="1">
				<select name="host_id" onChange="applyGraphsNewFilterChange(document.form_graphs_new)">
				<?php 
    /* modify for multi user start */
    if ($_SESSION["permission"] <= ACCESS_ADMINISTRATOR) {
        $hosts = db_fetch_assoc("\r\n                        SELECT host.id,CONCAT_WS('',host.description,' (',host.hostname,')') as name FROM host \r\n                            INNER JOIN user_auth_perms ON host.id = user_auth_perms.item_id AND user_auth_perms.user_id = '" . $_SESSION["sess_user_id"] . "' AND user_auth_perms.type = '3'\r\n                        ORDER BY host.description,host.hostname");
    } else {
        $hosts = db_fetch_assoc("select id,CONCAT_WS('',description,' (',hostname,')') as name from host order by description,hostname");
    }
    /* modify for multi user end */
    if (sizeof($hosts) > 0) {
        foreach ($hosts as $item) {
            print "<option value='" . $item["id"] . "'";
            if ($_REQUEST["host_id"] == $item["id"]) {
                print " selected";
            }
            print ">" . htmlspecialchars($item["name"]) . "</option>\n";
        }
    }
    ?>
				</select>
			</td>
			<td nowrap style='white-space: nowrap;' width="100" class="textArea">
				&nbsp;Graph Types:&nbsp;
			</td>
			<td width="1">
				<select name="graph_type" onChange="applyGraphsNewFilterChange(document.form_graphs_new)">
				<option value="-2"<?php 
    if ($_REQUEST["graph_type"] == "-2") {
        ?>
 selected<?php 
    }
    ?>
>All</option>
				<option value="-1"<?php 
    if ($_REQUEST["graph_type"] == "-1") {
        ?>
 selected<?php 
    }
    ?>
>Graph Template Based</option>
				<?php 
    $snmp_queries = db_fetch_assoc("SELECT\r\n\t\t\t\t\tsnmp_query.id,\r\n\t\t\t\t\tsnmp_query.name,\r\n\t\t\t\t\tsnmp_query.xml_path\r\n\t\t\t\t\tFROM (snmp_query,host_snmp_query)\r\n\t\t\t\t\tWHERE host_snmp_query.snmp_query_id=snmp_query.id\r\n\t\t\t\t\tAND host_snmp_query.host_id=" . $host["id"] . "\r\n\t\t\t\t\tORDER BY snmp_query.name");
    if (sizeof($snmp_queries) > 0) {
        foreach ($snmp_queries as $query) {
            print "<option value='" . $query["id"] . "'";
            if ($_REQUEST["graph_type"] == $query["id"]) {
                print " selected";
            }
            print ">" . $query["name"] . "</option>\n";
        }
    }
    ?>
				</select>
			</td>
			<td nowrap style='white-space: nowrap;' class="textInfo" align="left" valign="top">
				<span style="white-space: nowrap; color: #c16921;">*</span><a href="<?php 
    print htmlspecialchars("host.php?action=edit&id=" . $_REQUEST["host_id"]);
    ?>
">Edit this Host</a><br>
                <?php 
    /* modify for multi user start */
    if (check_resource_count(RESOURCE_HOST) == TRUE) {
        ?>
				<span style="white-space: nowrap; color: #c16921;">*</span><a href="<?php 
        print htmlspecialchars("host.php?action=edit");
        ?>
">Create New Host</a><br>
				<?php 
    }
    if ($_SESSION["permission"] == ACCESS_ADMINISTRATOR) {
        api_plugin_hook('graphs_new_top_links');
    }
    /* modify for multi user end */
    ?>
			</td>
		</tr>
	</table>
	<?php 
    if ($_REQUEST["graph_type"] > 0) {
        ?>
	<table width="100%" cellpadding="0" align="center">
		<tr>
			<td nowrap style='white-space: nowrap;' width="55" class="textArea">
				Search:&nbsp;
			</td>
			<td nowrap style='white-space: nowrap;' width="200">
				<input type="text" name="filter" size="30" value="<?php 
        print htmlspecialchars(get_request_var_request("filter"));
        ?>
">
			</td>
			<td align="left" nowrap style='white-space: nowrap;'>
				&nbsp;<input type="submit" value="Go" title="Set/Refresh Filters">
				<input type="submit" name="clear_x" value="Clear" title="Clear Filters">
			</td>
		</tr>
	</table>
	<?php 
    } else {
        form_hidden_box("filter", $_REQUEST["filter"], "");
    }
    ?>
	</form>

	<form name="chk" method="post" action="graphs_new.php">
	<?php 
    $total_rows = sizeof(db_fetch_assoc("select graph_template_id from host_graph where host_id=" . $_REQUEST["host_id"]));
    $i = 0;
    if ($changed) {
        foreach ($snmp_queries as $query) {
            kill_session_var("sess_graphs_new_page" . $query["id"]);
            unset($_REQUEST["page" . $query["id"]]);
            load_current_session_value("page" . $query["id"], "sess_graphs_new_page" . $query["id"], "1");
        }
    }
    if ($_REQUEST["graph_type"] > 0) {
        load_current_session_value("page" . $_REQUEST["graph_type"], "sess_graphs_new_page" . $_REQUEST["graph_type"], "1");
    } else {
        if ($_REQUEST["graph_type"] == -2) {
            foreach ($snmp_queries as $query) {
                load_current_session_value("page" . $query["id"], "sess_graphs_new_page" . $query["id"], "1");
            }
        }
    }
    $script = "<script type='text/javascript'>\nvar gt_created_graphs = new Array();\nvar created_graphs = new Array()\n";
    if ($_REQUEST["graph_type"] < 0) {
        html_start_box("<strong>Graph Templates</strong>", "100%", $colors["header"], "3", "center", "");
        print "\t<tr bgcolor='#" . $colors["header_panel"] . "'>\r\n\t\t\t\t<td class='textSubHeaderDark'>Graph Template Name</td>\r\n\t\t\t\t<td width='1%' align='center' bgcolor='#819bc0' style='" . get_checkbox_style() . "'><input type='checkbox' style='margin: 0px;' name='all_cg' title='Select All' onClick='SelectAll(\"cg\",this.checked);gt_update_selection_indicators();'></td>\n\r\n\t\t\t</tr>\n";
        $graph_templates = db_fetch_assoc("SELECT\r\n\t\t\tgraph_templates.id AS graph_template_id,\r\n\t\t\tgraph_templates.name AS graph_template_name\r\n\t\t\tFROM (host_graph,graph_templates)\r\n\t\t\tWHERE host_graph.graph_template_id=graph_templates.id\r\n\t\t\tAND host_graph.host_id=" . $_REQUEST["host_id"] . "\r\n\t\t\tORDER BY graph_templates.name");
        $template_graphs = db_fetch_assoc("SELECT\r\n\t\t\tgraph_local.graph_template_id\r\n\t\t\tFROM (graph_local,host_graph)\r\n\t\t\tWHERE graph_local.graph_template_id=host_graph.graph_template_id\r\n\t\t\tAND graph_local.host_id=host_graph.host_id\r\n\t\t\tAND graph_local.host_id=" . $host["id"] . "\r\n\t\t\tGROUP BY graph_local.graph_template_id");
        if (sizeof($template_graphs) > 0) {
            $script .= "var gt_created_graphs = new Array(";
            $cg_ctr = 0;
            foreach ($template_graphs as $template_graph) {
                $script .= ($cg_ctr > 0 ? "," : "") . "'" . $template_graph["graph_template_id"] . "'";
                $cg_ctr++;
            }
            $script .= ")\n";
        }
        /* create a row for each graph template associated with the host template */
        if (sizeof($graph_templates) > 0) {
            foreach ($graph_templates as $graph_template) {
                $query_row = $graph_template["graph_template_id"];
                print "<tr id='gt_line{$query_row}' bgcolor='#" . ($i % 2 == 0 ? "ffffff" : $colors["light"]) . "'>";
                $i++;
                print "\t\t<td onClick='gt_select_line(" . $graph_template["graph_template_id"] . ");'>\r\n\t\t\t\t\t\t<span id='gt_text{$query_row}" . "_0'><strong>Create:</strong> " . htmlspecialchars($graph_template["graph_template_name"]) . "</span>\r\n\t\t\t\t\t</td>\r\n\t\t\t\t\t<td align='right'>\r\n\t\t\t\t\t\t<input type='checkbox' name='cg_{$query_row}' id='cg_{$query_row}' onClick='gt_update_selection_indicators();'>\r\n\t\t\t\t\t</td>\r\n\t\t\t\t</tr>";
            }
        }
        $script .= "gt_update_deps(1);\n";
        /* modify for multi user start */
        $sql_where = "";
        if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
            $sql_where = "AND graph_templates.name NOT LIKE '%@system'";
        }
        $available_graph_templates = db_fetch_assoc("SELECT\r\n\t\t\tgraph_templates.id, graph_templates.name\r\n\t\t\tFROM snmp_query_graph RIGHT JOIN graph_templates\r\n\t\t\tON (snmp_query_graph.graph_template_id = graph_templates.id)\r\n\t\t\tWHERE (((snmp_query_graph.name) Is Null)) {$sql_where} ORDER BY graph_templates.name");
        /* modify for multi user end */
        /* create a row at the bottom that lets the user create any graph they choose */
        print "\t<tr bgcolor='#" . ($i % 2 == 0 ? "ffffff" : $colors["light"]) . "'>\r\n\t\t\t\t<td colspan='2' width='60' nowrap>\r\n\t\t\t\t\t<strong>Create:</strong>&nbsp;";
        form_dropdown("cg_g", $available_graph_templates, "name", "id", "", "(Select a graph type to create)", "", "textArea");
        print "\t\t</td>\r\n\t\t\t</tr>";
        html_end_box();
    }
    if ($_REQUEST["graph_type"] != -1) {
        $snmp_queries = db_fetch_assoc("SELECT\r\n\t\t\tsnmp_query.id,\r\n\t\t\tsnmp_query.name,\r\n\t\t\tsnmp_query.xml_path\r\n\t\t\tFROM (snmp_query,host_snmp_query)\r\n\t\t\tWHERE host_snmp_query.snmp_query_id=snmp_query.id\r\n\t\t\tAND host_snmp_query.host_id=" . $host["id"] . ($_REQUEST["graph_type"] != -2 ? " AND snmp_query.id=" . $_REQUEST["graph_type"] : '') . "\r\n\t\t\tORDER BY snmp_query.name");
        if (sizeof($snmp_queries) > 0) {
            foreach ($snmp_queries as $snmp_query) {
                unset($total_rows);
                if (!$changed) {
                    $page = $_REQUEST["page" . $snmp_query["id"]];
                } else {
                    $page = 1;
                }
                $xml_array = get_data_query_array($snmp_query["id"]);
                $num_input_fields = 0;
                $num_visible_fields = 0;
                if ($xml_array != false) {
                    /* loop through once so we can find out how many input fields there are */
                    reset($xml_array["fields"]);
                    while (list($field_name, $field_array) = each($xml_array["fields"])) {
                        if ($field_array["direction"] == "input") {
                            $num_input_fields++;
                            if (!isset($total_rows)) {
                                $total_rows = db_fetch_cell("SELECT count(*) FROM host_snmp_cache WHERE host_id=" . $host["id"] . " and snmp_query_id=" . $snmp_query["id"] . " AND field_name='{$field_name}'");
                            }
                        }
                    }
                }
                if (!isset($total_rows)) {
                    $total_rows = 0;
                }
                $snmp_query_graphs = db_fetch_assoc("SELECT snmp_query_graph.id,snmp_query_graph.name FROM snmp_query_graph WHERE snmp_query_graph.snmp_query_id=" . $snmp_query["id"] . " ORDER BY snmp_query_graph.name");
                if (sizeof($snmp_query_graphs) > 0) {
                    foreach ($snmp_query_graphs as $snmp_query_graph) {
                        $created_graphs = db_fetch_assoc("SELECT DISTINCT\r\n\t\t\t\t\t\tdata_local.snmp_index\r\n\t\t\t\t\t\tFROM (data_local,data_template_data)\r\n\t\t\t\t\t\tLEFT JOIN data_input_data ON (data_template_data.id=data_input_data.data_template_data_id)\r\n\t\t\t\t\t\tLEFT JOIN data_input_fields ON (data_input_data.data_input_field_id=data_input_fields.id)\r\n\t\t\t\t\t\tWHERE data_local.id=data_template_data.local_data_id\r\n\t\t\t\t\t\tAND data_input_fields.type_code='output_type'\r\n\t\t\t\t\t\tAND data_input_data.value='" . $snmp_query_graph["id"] . "'\r\n\t\t\t\t\t\tAND data_local.host_id=" . $host["id"]);
                        $script .= "created_graphs[" . $snmp_query_graph["id"] . "] = new Array(";
                        $cg_ctr = 0;
                        if (sizeof($created_graphs) > 0) {
                            foreach ($created_graphs as $created_graph) {
                                $script .= ($cg_ctr > 0 ? "," : "") . "'" . encode_data_query_index($created_graph["snmp_index"]) . "'";
                                $cg_ctr++;
                            }
                        }
                        $script .= ")\n";
                    }
                }
                print "\t<table width='100%' style='background-color: #" . $colors["form_alternate2"] . "; border: 1px solid #" . $colors["header"] . ";' align='center' cellpadding='3' cellspacing='0'>\n\r\n\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t<td bgcolor='#" . $colors["header"] . "' colspan='" . ($num_input_fields + 1) . "'>\r\n\t\t\t\t\t\t\t<table  cellspacing='0' cellpadding='0' width='100%' >\r\n\t\t\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t\t\t<td class='textHeaderDark'>\r\n\t\t\t\t\t\t\t\t\t\t<strong>Data Query</strong> [" . $snmp_query["name"] . "]\r\n\t\t\t\t\t\t\t\t\t</td>\r\n\t\t\t\t\t\t\t\t\t<td align='right' nowrap>\r\n\t\t\t\t\t\t\t\t\t\t<a href='" . htmlspecialchars("graphs_new.php?action=query_reload&id=" . $snmp_query["id"] . "&host_id=" . $host["id"]) . "'><img src='images/reload_icon_small.gif' title='Reload Associated Query' alt='' border='0' align='middle'></a>\r\n\t\t\t\t\t\t\t\t\t</td>\r\n\t\t\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t\t</table>\r\n\t\t\t\t\t\t</td>\r\n\t\t\t\t\t</tr>";
                if ($xml_array != false) {
                    $html_dq_header = "";
                    $snmp_query_indexes = array();
                    reset($xml_array["fields"]);
                    /* if there is a where clause, get the matching snmp_indexes */
                    $sql_where = "";
                    if (strlen($_REQUEST["filter"])) {
                        $sql_where = "";
                        $indexes = db_fetch_assoc("SELECT DISTINCT snmp_index\r\n\t\t\t\t\t\tFROM host_snmp_cache\r\n\t\t\t\t\t\tWHERE field_value LIKE '%%" . $_REQUEST["filter"] . "%%'\r\n\t\t\t\t\t\tAND snmp_query_id=" . $snmp_query["id"] . "\r\n\t\t\t\t\t\tAND host_id=" . $host["id"]);
                        if (sizeof($indexes)) {
                            foreach ($indexes as $index) {
                                if (strlen($sql_where)) {
                                    $sql_where .= ", '" . $index["snmp_index"] . "'";
                                } else {
                                    $sql_where .= " AND snmp_index IN('" . $index["snmp_index"] . "'";
                                }
                            }
                            $sql_where .= ")";
                        }
                    }
                    if (strlen($_REQUEST["filter"]) == 0 || strlen($_REQUEST["filter"]) && sizeof($indexes)) {
                        /* determine the sort order */
                        if (isset($xml_array["index_order_type"])) {
                            if ($xml_array["index_order_type"] == "numeric") {
                                $sql_order = "ORDER BY CAST(snmp_index AS unsigned)";
                            } else {
                                if ($xml_array["index_order_type"] == "alphabetic") {
                                    $sql_order = "ORDER BY snmp_index";
                                } else {
                                    if ($xml_array["index_order_type"] == "natural") {
                                        $sql_order = "ORDER BY INET_ATON(snmp_index)";
                                    } else {
                                        $sql_order = "";
                                    }
                                }
                            }
                        } else {
                            $sql_order = "";
                        }
                        /* get the unique field values from the database */
                        $field_names = db_fetch_assoc("SELECT DISTINCT field_name\r\n\t\t\t\t\t\tFROM host_snmp_cache\r\n\t\t\t\t\t\tWHERE host_id=" . $host["id"] . "\r\n\t\t\t\t\t\tAND snmp_query_id=" . $snmp_query["id"]);
                        /* build magic query */
                        $sql_query = "SELECT host_id, snmp_query_id, snmp_index";
                        $num_visible_fields = sizeof($field_names);
                        $i = 0;
                        if (sizeof($field_names) > 0) {
                            foreach ($field_names as $column) {
                                $field_name = $column["field_name"];
                                $sql_query .= ", MAX(CASE WHEN field_name='{$field_name}' THEN field_value ELSE NULL END) AS '{$field_name}'";
                                $i++;
                            }
                        }
                        $sql_query .= " FROM host_snmp_cache\r\n\t\t\t\t\t\tWHERE host_id=" . $host["id"] . "\r\n\t\t\t\t\t\tAND snmp_query_id=" . $snmp_query["id"] . "\r\n\t\t\t\t\t\t{$sql_where}\r\n\t\t\t\t\t\tGROUP BY host_id, snmp_query_id, snmp_index\r\n\t\t\t\t\t\t{$sql_order}\r\n\t\t\t\t\t\tLIMIT " . $row_limit * ($page - 1) . "," . $row_limit;
                        $rows_query = "SELECT host_id, snmp_query_id, snmp_index\r\n\t\t\t\t\t\tFROM host_snmp_cache\r\n\t\t\t\t\t\tWHERE host_id=" . $host["id"] . "\r\n\t\t\t\t\t\tAND snmp_query_id=" . $snmp_query["id"] . "\r\n\t\t\t\t\t\t{$sql_where}\r\n\t\t\t\t\t\tGROUP BY host_id, snmp_query_id, snmp_index";
                        $snmp_query_indexes = db_fetch_assoc($sql_query);
                        $total_rows = sizeof(db_fetch_assoc($rows_query));
                        if (($page - 1) * $row_limit > $total_rows) {
                            $page = 1;
                            $_REQUEST["page" . $query["id"]] = $page;
                            load_current_session_value("page" . $query["id"], "sess_graphs_new_page" . $query["id"], "1");
                        }
                        if ($total_rows > $row_limit) {
                            /* generate page list */
                            $url_page_select = get_page_list($page, MAX_DISPLAY_PAGES, $row_limit, $total_rows, "graphs_new.php?", "page" . $snmp_query["id"]);
                            $nav = "<tr bgcolor='#" . $colors["header"] . "' class='noprint'>\r\n\t\t\t\t\t\t\t\t\t<td colspan='15'>\r\n\t\t\t\t\t\t\t\t\t\t<table width='100%' cellspacing='0' cellpadding='0' border='0'>\r\n\t\t\t\t\t\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t\t\t\t\t\t<td align='left' class='textHeaderDark'>\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t<strong>&lt;&lt; ";
                            if ($page > 1) {
                                $nav .= "<a class='linkOverDark' href='" . htmlspecialchars("graphs_new.php?page" . $snmp_query["id"] . "=" . ($page - 1)) . "'>";
                            }
                            $nav .= "Previous";
                            if ($page > 1) {
                                $nav .= "</a>";
                            }
                            $nav .= "</strong>\r\n\t\t\t\t\t\t\t\t\t\t\t\t</td>\n\r\n\t\t\t\t\t\t\t\t\t\t\t\t<td align='center' class='textHeaderDark'>\r\n\t\t\t\t\t\t\t\t\t\t\t\t\tShowing Rows " . ($row_limit * ($page - 1) + 1) . " to " . ($total_rows < $row_limit || $total_rows < $row_limit * $page ? $total_rows : $row_limit * $page) . " of {$total_rows} [{$url_page_select}]\r\n\t\t\t\t\t\t\t\t\t\t\t\t</td>\n\r\n\t\t\t\t\t\t\t\t\t\t\t\t<td align='right' class='textHeaderDark'>\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t<strong>";
                            if ($page * $row_limit < $total_rows) {
                                $nav .= "<a class='linkOverDark' href='" . htmlspecialchars("graphs_new.php?page" . $snmp_query["id"] . "=" . ($page + 1)) . "'>";
                            }
                            $nav .= "Next";
                            if ($page * $row_limit < $total_rows) {
                                $nav .= "</a>";
                            }
                            $nav .= " &gt;&gt;</strong>\r\n\t\t\t\t\t\t\t\t\t\t\t\t</td>\n\r\n\t\t\t\t\t\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t\t\t\t\t</table>\r\n\t\t\t\t\t\t\t\t\t</td>\r\n\t\t\t\t\t\t\t\t</tr>\n";
                            print $nav;
                        }
                        while (list($field_name, $field_array) = each($xml_array["fields"])) {
                            if ($field_array["direction"] == "input" && sizeof($field_names)) {
                                foreach ($field_names as $row) {
                                    if ($row["field_name"] == $field_name) {
                                        $html_dq_header .= "<td style='height:1px;'><strong><font color='#" . $colors["header_text"] . "'>" . $field_array["name"] . "</font></strong></td>\n";
                                        break;
                                    }
                                }
                            }
                        }
                        if (!sizeof($snmp_query_indexes)) {
                            print "<tr bgcolor='#" . $colors["form_alternate1"] . "'><td>This data query returned 0 rows, perhaps there was a problem executing this\r\n\t\t\t\t\t\t\tdata query. You can <a href='" . htmlspecialchars("host.php?action=query_verbose&id=" . $snmp_query["id"] . "&host_id=" . $host["id"]) . "'>run this data\r\n\t\t\t\t\t\t\tquery in debug mode</a> to get more information.</td></tr>\n";
                        } else {
                            print "\t<tr bgcolor='#" . $colors["header_panel"] . "'>\r\n\t\t\t\t\t\t\t\t{$html_dq_header}\r\n\t\t\t\t\t\t\t\t<td width='1%' align='center' bgcolor='#819bc0' style='" . get_checkbox_style() . "'><input type='checkbox' style='margin: 0px;' name='all_" . $snmp_query["id"] . "' title='Select All' onClick='SelectAll(\"sg_" . $snmp_query["id"] . "\",this.checked);dq_update_selection_indicators();'></td>\n\r\n\t\t\t\t\t\t\t</tr>\n";
                        }
                        $row_counter = 0;
                        $column_counter = 0;
                        $fields = array_rekey($field_names, "field_name", "field_name");
                        if (sizeof($snmp_query_indexes) > 0) {
                            foreach ($snmp_query_indexes as $row) {
                                $query_row = $snmp_query["id"] . "_" . encode_data_query_index($row["snmp_index"]);
                                print "<tr id='line{$query_row}' bgcolor='#" . ($row_counter % 2 == 0 ? "ffffff" : $colors["light"]) . "'>";
                                $i++;
                                $column_counter = 0;
                                reset($xml_array["fields"]);
                                while (list($field_name, $field_array) = each($xml_array["fields"])) {
                                    if ($field_array["direction"] == "input") {
                                        if (in_array($field_name, $fields)) {
                                            if (isset($row[$field_name])) {
                                                print "<td onClick='dq_select_line(" . $snmp_query["id"] . ",\"" . encode_data_query_index($row["snmp_index"]) . "\");'><span id='text{$query_row}" . "_" . $column_counter . "'>" . (strlen($_REQUEST["filter"]) ? preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", $row[$field_name]) : $row[$field_name]) . "</span></td>";
                                            } else {
                                                print "<td onClick='dq_select_line(" . $snmp_query["id"] . ",\"" . encode_data_query_index($row["snmp_index"]) . "\");'><span id='text{$query_row}" . "_" . $column_counter . "'></span></td>";
                                            }
                                            $column_counter++;
                                        }
                                    }
                                }
                                print "<td align='right'>";
                                print "<input type='checkbox' name='sg_{$query_row}' id='sg_{$query_row}' onClick='dq_update_selection_indicators();'>";
                                print "</td>";
                                print "</tr>\n";
                                $row_counter++;
                            }
                        }
                        if ($total_rows > $row_limit) {
                            print $nav;
                        }
                    } else {
                        print "<tr bgcolor='#" . $colors["form_alternate1"] . "'><td colspan='2' style='color: red; font-size: 12px; font-weight: bold;'>Search Returned no Rows.</td></tr>\n";
                    }
                } else {
                    print "<tr bgcolor='#" . $colors["form_alternate1"] . "'><td colspan='2' style='color: red; font-size: 12px; font-weight: bold;'>Error in data query.</td></tr>\n";
                }
                print "</table>";
                /* draw the graph template drop down here */
                $data_query_graphs = db_fetch_assoc("select snmp_query_graph.id,snmp_query_graph.name from snmp_query_graph where snmp_query_graph.snmp_query_id=" . $snmp_query["id"] . " order by snmp_query_graph.name");
                if (sizeof($data_query_graphs) == 1) {
                    echo "<input type='hidden' id='sgg_" . $snmp_query["id"] . "' name='sgg_" . $snmp_query["id"] . "' value='" . $data_query_graphs[0]["id"] . "'>\n";
                } elseif (sizeof($data_query_graphs) > 1) {
                    print "\t<table align='center' width='100%'>\r\n\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t<td width='1' valign='top'>\r\n\t\t\t\t\t\t\t\t<img src='images/arrow.gif' alt=''>&nbsp;\r\n\t\t\t\t\t\t\t</td>\r\n\t\t\t\t\t\t\t<td align='right'>\r\n\t\t\t\t\t\t\t\t<span style='font-size: 12px; font-style: italic;'>Select a graph type:</span>&nbsp;\r\n\t\t\t\t\t\t\t\t<select name='sgg_" . $snmp_query["id"] . "' id='sgg_" . $snmp_query["id"] . "' onChange='dq_update_deps(" . $snmp_query["id"] . "," . (isset($column_counter) ? $column_counter : "") . ");'>\r\n\t\t\t\t\t\t\t\t\t";
                    html_create_list($data_query_graphs, "name", "id", "0");
                    print "\r\n\t\t\t\t\t\t\t\t</select>\r\n\t\t\t\t\t\t\t</td>\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t</table>";
                }
                print "<br>";
                $script .= "dq_update_deps(" . $snmp_query["id"] . "," . $num_visible_fields . ");\n";
            }
        }
    }
    if (strlen($script)) {
        $script .= "</script>\n";
        print $script;
    }
    form_hidden_box("save_component_graph", "1", "");
    form_hidden_box("host_id", $host["id"], "0");
    form_hidden_box("host_template_id", $host["host_template_id"], "0");
    if (isset($_SERVER["HTTP_REFERER"]) && !substr_count($_SERVER["HTTP_REFERER"], "graphs_new")) {
        $_REQUEST["returnto"] = basename($_SERVER["HTTP_REFERER"]);
    }
    load_current_session_value("returnto", "sess_graphs_new_returnto", "");
    /* modify for multi user start */
    if (check_resource_count(RESOURCE_GRAPH) && check_resource_count(RESOURCE_DATA)) {
        form_save_button($_REQUEST["returnto"]);
    }
    /* modify for multi user end */
    print "<script type='text/javascript'>dq_update_selection_indicators();</script>\n";
    print "<script type='text/javascript'>gt_update_selection_indicators();</script>\n";
}
Exemple #5
0
function host()
{
    global $colors, $device_actions, $item_rows;
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_request("host_template_id"));
    input_validate_input_number(get_request_var_request("page"));
    input_validate_input_number(get_request_var_request("host_status"));
    input_validate_input_number(get_request_var_request("host_rows"));
    /* ==================================================== */
    /* clean up search string */
    if (isset($_REQUEST["filter"])) {
        $_REQUEST["filter"] = sanitize_search_string(get_request_var("filter"));
    }
    /* clean up sort_column */
    if (isset($_REQUEST["sort_column"])) {
        $_REQUEST["sort_column"] = sanitize_search_string(get_request_var("sort_column"));
    }
    /* clean up search string */
    if (isset($_REQUEST["sort_direction"])) {
        $_REQUEST["sort_direction"] = sanitize_search_string(get_request_var("sort_direction"));
    }
    /* if the user pushed the 'clear' button */
    if (isset($_REQUEST["clear_x"])) {
        kill_session_var("sess_device_current_page");
        kill_session_var("sess_device_filter");
        kill_session_var("sess_device_host_template_id");
        kill_session_var("sess_host_status");
        kill_session_var("sess_host_rows");
        kill_session_var("sess_host_sort_column");
        kill_session_var("sess_host_sort_direction");
        unset($_REQUEST["page"]);
        unset($_REQUEST["filter"]);
        unset($_REQUEST["host_template_id"]);
        unset($_REQUEST["host_status"]);
        unset($_REQUEST["host_rows"]);
        unset($_REQUEST["sort_column"]);
        unset($_REQUEST["sort_direction"]);
    }
    if (!empty($_SESSION["sess_host_status"]) && !empty($_REQUEST["host_status"])) {
        if ($_SESSION["sess_host_status"] != $_REQUEST["host_status"]) {
            $_REQUEST["page"] = 1;
        }
    }
    /* remember these search fields in session vars so we don't have to keep passing them around */
    load_current_session_value("page", "sess_device_current_page", "1");
    load_current_session_value("filter", "sess_device_filter", "");
    load_current_session_value("host_template_id", "sess_device_host_template_id", "-1");
    load_current_session_value("host_status", "sess_host_status", "-1");
    load_current_session_value("host_rows", "sess_host_rows", read_config_option("num_rows_device"));
    load_current_session_value("sort_column", "sess_host_sort_column", "description");
    load_current_session_value("sort_direction", "sess_host_sort_direction", "ASC");
    /* if the number of rows is -1, set it to the default */
    if ($_REQUEST["host_rows"] == -1) {
        $_REQUEST["host_rows"] = read_config_option("num_rows_device");
    }
    ?>
	<script type="text/javascript">
	<!--

	function applyViewDeviceFilterChange(objForm) {
		strURL = '?host_status=' + objForm.host_status.value;
		strURL = strURL + '&host_template_id=' + objForm.host_template_id.value;
		strURL = strURL + '&host_rows=' + objForm.host_rows.value;
		strURL = strURL + '&filter=' + objForm.filter.value;
		document.location = strURL;
	}

	-->
	</script>
	<?php 
    /* modify for multi user start */
    if (check_resource_count(RESOURCE_HOST) == TRUE) {
        html_start_box("<strong>Devices</strong>", "100%", $colors["header"], "3", "center", "host.php?action=edit&host_template_id=" . htmlspecialchars(get_request_var_request("host_template_id")) . "&host_status=" . htmlspecialchars(get_request_var_request("host_status")));
    } else {
        html_start_box("<strong>Devices</strong>", "100%", $colors["header"], "3", "center", "");
    }
    /* modify for multi user end */
    ?>
	<tr bgcolor="#<?php 
    print $colors["panel"];
    ?>
">
		<td>
		<form name="form_devices" action="host.php">
			<table width="100%" cellpadding="0" cellspacing="0">
				<tr>
					<td nowrap style='white-space: nowrap;' width="50">
						Type:&nbsp;
					</td>
					<td width="1">
						<select name="host_template_id" onChange="applyViewDeviceFilterChange(document.form_devices)">
							<option value="-1"<?php 
    if (get_request_var_request("host_template_id") == "-1") {
        ?>
 selected<?php 
    }
    ?>
>Any</option>
							<option value="0"<?php 
    if (get_request_var_request("host_template_id") == "0") {
        ?>
 selected<?php 
    }
    ?>
>None</option>
							<?php 
    if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
        $host_templates = db_fetch_assoc("\r\n                                    SELECT DISTINCT host_template.id,host_template.name FROM host_template\r\n                                      INNER JOIN host ON host_template.id = host.host_template_id\r\n                                      INNER JOIN user_auth_perms ON host.id = user_auth_perms.item_id AND user_auth_perms.user_id = '" . $_SESSION["sess_user_id"] . "' AND user_auth_perms.type = '3'\r\n                                    ORDER BY host_template.name");
    } else {
        $host_templates = db_fetch_assoc("select id,name from host_template order by name");
    }
    /* modify for multi user end */
    if (sizeof($host_templates) > 0) {
        foreach ($host_templates as $host_template) {
            print "<option value='" . $host_template["id"] . "'";
            if (get_request_var_request("host_template_id") == $host_template["id"]) {
                print " selected";
            }
            print ">" . htmlspecialchars($host_template["name"]) . "</option>\n";
        }
    }
    ?>
						</select>
					</td>
					<td nowrap style='white-space: nowrap;' width="50">
						&nbsp;Status:&nbsp;
					</td>
					<td width="1">
						<select name="host_status" onChange="applyViewDeviceFilterChange(document.form_devices)">
							<option value="-1"<?php 
    if (get_request_var_request("host_status") == "-1") {
        ?>
 selected<?php 
    }
    ?>
>Any</option>
							<option value="-3"<?php 
    if (get_request_var_request("host_status") == "-3") {
        ?>
 selected<?php 
    }
    ?>
>Enabled</option>
							<option value="-2"<?php 
    if (get_request_var_request("host_status") == "-2") {
        ?>
 selected<?php 
    }
    ?>
>Disabled</option>
							<option value="-4"<?php 
    if (get_request_var_request("host_status") == "-4") {
        ?>
 selected<?php 
    }
    ?>
>Not Up</option>
							<option value="3"<?php 
    if (get_request_var_request("host_status") == "3") {
        ?>
 selected<?php 
    }
    ?>
>Up</option>
							<option value="1"<?php 
    if (get_request_var_request("host_status") == "1") {
        ?>
 selected<?php 
    }
    ?>
>Down</option>
							<option value="2"<?php 
    if (get_request_var_request("host_status") == "2") {
        ?>
 selected<?php 
    }
    ?>
>Recovering</option>
							<option value="0"<?php 
    if (get_request_var_request("host_status") == "0") {
        ?>
 selected<?php 
    }
    ?>
>Unknown</option>
						</select>
					</td>
					<td nowrap style='white-space: nowrap;' width="20">
						&nbsp;Search:&nbsp;
					</td>
					<td width="1">
						<input type="text" name="filter" size="20" value="<?php 
    print htmlspecialchars(get_request_var_request("filter"));
    ?>
">
					</td>
					<td nowrap style='white-space: nowrap;' width="50">
						&nbsp;Rows per Page:&nbsp;
					</td>
					<td width="1">
						<select name="host_rows" onChange="applyViewDeviceFilterChange(document.form_devices)">
							<option value="-1"<?php 
    if (get_request_var_request("host_rows") == "-1") {
        ?>
 selected<?php 
    }
    ?>
>Default</option>
							<?php 
    if (sizeof($item_rows) > 0) {
        foreach ($item_rows as $key => $value) {
            print "<option value='" . $key . "'";
            if (get_request_var_request("host_rows") == $key) {
                print " selected";
            }
            print ">" . htmlspecialchars($value) . "</option>\n";
        }
    }
    ?>
						</select>
					</td>
					<td nowrap>
						&nbsp;<input type="submit" value="Go" title="Set/Refresh Filters">
						<input type="submit" name="clear_x" value="Clear" title="Clear Filters">
					</td>
				</tr>
			</table>
			<input type='hidden' name='page' value='1'>
		</form>
		</td>
	</tr>
	<?php 
    html_end_box();
    /* form the 'where' clause for our main sql query */
    if (strlen(get_request_var_request("filter"))) {
        $sql_where = "where (host.hostname like '%%" . get_request_var_request("filter") . "%%' OR host.description like '%%" . get_request_var_request("filter") . "%%')";
    } else {
        $sql_where = "";
    }
    if (get_request_var_request("host_status") == "-1") {
        /* Show all items */
    } elseif (get_request_var_request("host_status") == "-2") {
        $sql_where .= strlen($sql_where) ? " and host.disabled='on'" : "where host.disabled='on'";
    } elseif (get_request_var_request("host_status") == "-3") {
        $sql_where .= strlen($sql_where) ? " and host.disabled=''" : "where host.disabled=''";
    } elseif (get_request_var_request("host_status") == "-4") {
        $sql_where .= strlen($sql_where) ? " and (host.status!='3' or host.disabled='on')" : "where (host.status!='3' or host.disabled='on')";
    } else {
        $sql_where .= strlen($sql_where) ? " and (host.status=" . get_request_var_request("host_status") . " AND host.disabled = '')" : "where (host.status=" . get_request_var_request("host_status") . " AND host.disabled = '')";
    }
    if (get_request_var_request("host_template_id") == "-1") {
        /* Show all items */
    } elseif (get_request_var_request("host_template_id") == "0") {
        $sql_where .= strlen($sql_where) ? " and host.host_template_id=0" : "where host.host_template_id=0";
    } elseif (!empty($_REQUEST["host_template_id"])) {
        $sql_where .= strlen($sql_where) ? " and host.host_template_id=" . get_request_var_request("host_template_id") : "where host.host_template_id=" . get_request_var_request("host_template_id");
    }
    /* modify for multi user start */
    $sql_join = "";
    if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
        $sql_join = "INNER JOIN user_auth_perms ON host.id = user_auth_perms.item_id AND user_auth_perms.user_id = '" . $_SESSION["sess_user_id"] . "' AND user_auth_perms.type = '3'";
    }
    /* modify for multi user end */
    /* print checkbox form for validation */
    print "<form name='chk' method='post' action='host.php'>\n";
    html_start_box("", "100%", $colors["header"], "3", "center", "");
    /* modify for multi user start */
    $total_rows = db_fetch_cell("select\r\n\t\tCOUNT(host.id)\r\n\t\tfrom host\r\n        {$sql_join}\r\n\t\t{$sql_where}");
    /* modify for multi user end */
    $sortby = get_request_var_request("sort_column");
    if ($sortby == "hostname") {
        $sortby = "INET_ATON(hostname)";
    }
    $host_graphs = array_rekey(db_fetch_assoc("SELECT host_id, count(*) as graphs FROM graph_local GROUP BY host_id"), "host_id", "graphs");
    $host_data_sources = array_rekey(db_fetch_assoc("SELECT host_id, count(*) as data_sources FROM data_local GROUP BY host_id"), "host_id", "data_sources");
    /* modify for multi user start */
    $sql_query = "SELECT host.*\r\n\t\tFROM host\r\n\t\t{$sql_join}\r\n\t\t{$sql_where}\r\n\t\tORDER BY " . $sortby . " " . get_request_var_request("sort_direction") . "\r\n\t\tLIMIT " . get_request_var_request("host_rows") * (get_request_var_request("page") - 1) . "," . get_request_var_request("host_rows");
    /* modify for multi user end */
    $hosts = db_fetch_assoc($sql_query);
    /* generate page list */
    $url_page_select = get_page_list(get_request_var_request("page"), MAX_DISPLAY_PAGES, get_request_var_request("host_rows"), $total_rows, "host.php?filter=" . get_request_var_request("filter") . "&host_template_id=" . get_request_var_request("host_template_id") . "&host_status=" . get_request_var_request("host_status"));
    $nav = "<tr bgcolor='#" . $colors["header"] . "'>\r\n\t\t\t<td colspan='11'>\r\n\t\t\t\t<table width='100%' cellspacing='0' cellpadding='0' border='0'>\r\n\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t<td align='left' class='textHeaderDark'>\r\n\t\t\t\t\t\t\t<strong>&lt;&lt; ";
    if (get_request_var_request("page") > 1) {
        $nav .= "<a class='linkOverDark' href='" . htmlspecialchars("host.php?filter=" . get_request_var_request("filter") . "&host_template_id=" . get_request_var_request("host_template_id") . "&host_status=" . get_request_var_request("host_status") . "&page=" . (get_request_var_request("page") - 1)) . "'>";
    }
    $nav .= "Previous";
    if (get_request_var_request("page") > 1) {
        $nav .= "</a>";
    }
    $nav .= "</strong>\r\n\t\t\t\t\t\t</td>\n\r\n\t\t\t\t\t\t<td align='center' class='textHeaderDark'>\r\n\t\t\t\t\t\t\tShowing Rows " . (get_request_var_request("host_rows") * (get_request_var_request("page") - 1) + 1) . " to " . ($total_rows < read_config_option("num_rows_device") || $total_rows < get_request_var_request("host_rows") * get_request_var_request("page") ? $total_rows : get_request_var_request("host_rows") * get_request_var_request("page")) . " of {$total_rows} [{$url_page_select}]\r\n\t\t\t\t\t\t</td>\n\r\n\t\t\t\t\t\t<td align='right' class='textHeaderDark'>\r\n\t\t\t\t\t\t\t<strong>";
    if (get_request_var_request("page") * get_request_var_request("host_rows") < $total_rows) {
        $nav .= "<a class='linkOverDark' href='" . htmlspecialchars("host.php?filter=" . get_request_var_request("filter") . "&host_template_id=" . get_request_var_request("host_template_id") . "&host_status=" . get_request_var_request("host_status") . "&page=" . (get_request_var_request("page") + 1)) . "'>";
    }
    $nav .= "Next";
    if (get_request_var_request("page") * get_request_var_request("host_rows") < $total_rows) {
        $nav .= "</a>";
    }
    $nav .= " &gt;&gt;</strong>\r\n\t\t\t\t\t\t</td>\n\r\n\t\t\t\t\t</tr>\r\n\t\t\t\t</table>\r\n\t\t\t</td>\r\n\t\t</tr>\n";
    print $nav;
    $display_text = array("description" => array("Description", "ASC"), "id" => array("ID", "ASC"), "nosort1" => array("Graphs", "ASC"), "nosort2" => array("Data Sources", "ASC"), "status" => array("Status", "ASC"), "status_rec_date" => array("In State", "ASC"), "hostname" => array("Hostname", "ASC"), "cur_time" => array("Current (ms)", "DESC"), "avg_time" => array("Average (ms)", "DESC"), "availability" => array("Availability", "ASC"));
    html_header_sort_checkbox($display_text, get_request_var_request("sort_column"), get_request_var_request("sort_direction"), false);
    $i = 0;
    if (sizeof($hosts) > 0) {
        foreach ($hosts as $host) {
            form_alternate_row_color($colors["alternate"], $colors["light"], $i, 'line' . $host["id"]);
            $i++;
            form_selectable_cell("<a class='linkEditMain' href='" . htmlspecialchars("host.php?action=edit&id=" . $host["id"]) . "'>" . (strlen(get_request_var_request("filter")) ? preg_replace("/(" . preg_quote(get_request_var_request("filter")) . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", htmlspecialchars($host["description"])) : htmlspecialchars($host["description"])) . "</a>", $host["id"], 250);
            form_selectable_cell(round($host["id"], 2), $host["id"]);
            form_selectable_cell(isset($host_graphs[$host["id"]]) ? $host_graphs[$host["id"]] : 0, $host["id"]);
            form_selectable_cell(isset($host_data_sources[$host["id"]]) ? $host_data_sources[$host["id"]] : 0, $host["id"]);
            /* modify for multi user start */
            form_selectable_cell(get_colored_device_status($host["disabled"] == "on" || $host["disabled"] == "ps" ? $host["disabled"] : false, $host["status"]), $host["id"]);
            /* modify for multi user end */
            form_selectable_cell(get_timeinstate($host), $host["id"]);
            form_selectable_cell(strlen(get_request_var_request("filter")) ? preg_replace("/(" . preg_quote(get_request_var_request("filter")) . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", htmlspecialchars($host["hostname"])) : htmlspecialchars($host["hostname"]), $host["id"]);
            form_selectable_cell(round($host["cur_time"], 2), $host["id"]);
            form_selectable_cell(round($host["avg_time"], 2), $host["id"]);
            form_selectable_cell(round($host["availability"], 2), $host["id"]);
            form_checkbox_cell($host["description"], $host["id"]);
            form_end_row();
        }
        /* put the nav bar on the bottom as well */
        print $nav;
    } else {
        print "<tr><td><em>No Hosts</em></td></tr>";
    }
    html_end_box(false);
    /* add a list of tree names to the actions dropdown */
    add_tree_names_to_actions_array();
    /* draw the dropdown containing a list of available actions for this form */
    draw_actions_dropdown($device_actions);
    print "</form>\n";
}
Exemple #6
0
function ds()
{
    global $colors, $ds_actions, $item_rows;
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_request("ds_rows"));
    input_validate_input_number(get_request_var_request("host_id"));
    input_validate_input_number(get_request_var_request("template_id"));
    input_validate_input_number(get_request_var_request("method_id"));
    input_validate_input_number(get_request_var_request("page"));
    /* ==================================================== */
    /* clean up search string */
    if (isset($_REQUEST["filter"])) {
        $_REQUEST["filter"] = sanitize_search_string(get_request_var("filter"));
    }
    /* clean up sort_column string */
    if (isset($_REQUEST["sort_column"])) {
        $_REQUEST["sort_column"] = sanitize_search_string(get_request_var("sort_column"));
    }
    /* clean up sort_direction string */
    if (isset($_REQUEST["sort_direction"])) {
        $_REQUEST["sort_direction"] = sanitize_search_string(get_request_var("sort_direction"));
    }
    /* if the user pushed the 'clear' button */
    if (isset($_REQUEST["clear_x"])) {
        kill_session_var("sess_ds_current_page");
        kill_session_var("sess_ds_filter");
        kill_session_var("sess_ds_sort_column");
        kill_session_var("sess_ds_sort_direction");
        kill_session_var("sess_ds_rows");
        kill_session_var("sess_ds_host_id");
        kill_session_var("sess_ds_template_id");
        kill_session_var("sess_ds_method_id");
        unset($_REQUEST["page"]);
        unset($_REQUEST["filter"]);
        unset($_REQUEST["sort_column"]);
        unset($_REQUEST["sort_direction"]);
        unset($_REQUEST["ds_rows"]);
        unset($_REQUEST["host_id"]);
        unset($_REQUEST["template_id"]);
        unset($_REQUEST["method_id"]);
    }
    /* remember these search fields in session vars so we don't have to keep passing them around */
    load_current_session_value("page", "sess_ds_current_page", "1");
    load_current_session_value("filter", "sess_ds_filter", "");
    load_current_session_value("sort_column", "sess_ds_sort_column", "name_cache");
    load_current_session_value("sort_direction", "sess_ds_sort_direction", "ASC");
    load_current_session_value("ds_rows", "sess_ds_rows", read_config_option("num_rows_data_source"));
    load_current_session_value("host_id", "sess_ds_host_id", "-1");
    load_current_session_value("template_id", "sess_ds_template_id", "-1");
    load_current_session_value("method_id", "sess_ds_method_id", "-1");
    $host = db_fetch_row("select hostname from host where id=" . get_request_var_request("host_id"));
    /* if the number of rows is -1, set it to the default */
    if (get_request_var_request("ds_rows") == -1) {
        $_REQUEST["ds_rows"] = read_config_option("num_rows_data_source");
    }
    ?>
	<script type="text/javascript">
	<!--

	function applyDSFilterChange(objForm) {
		strURL = '?host_id=' + objForm.host_id.value;
		strURL = strURL + '&filter=' + objForm.filter.value;
		strURL = strURL + '&ds_rows=' + objForm.ds_rows.value;
		strURL = strURL + '&template_id=' + objForm.template_id.value;
		strURL = strURL + '&method_id=' + objForm.method_id.value;
		document.location = strURL;
	}

	-->
	</script>
	<?php 
    /* modify for multi user start */
    if (check_resource_count(RESOURCE_DATA) == TRUE) {
        html_start_box("<strong>Data Sources</strong> [host: " . (empty($host["hostname"]) ? "No Host" : htmlspecialchars($host["hostname"])) . "]", "100%", $colors["header"], "3", "center", "data_sources.php?action=ds_edit&host_id=" . get_request_var_request("host_id"));
    } else {
        html_start_box("<strong>Data Sources</strong> [host: " . (empty($host["hostname"]) ? "No Host" : htmlspecialchars($host["hostname"])) . "]", "100%", $colors["header"], "3", "center", "");
    }
    /* modify for multi user end */
    ?>
	<tr bgcolor="#<?php 
    print $colors["panel"];
    ?>
">
		<td>
		<form name="form_data_sources" action="data_sources.php">
			<table cellpadding="1" cellspacing="0">
				<tr>
					<td width="50">
						Host:&nbsp;
					</td>
					<td>
						<select name="host_id" onChange="applyDSFilterChange(document.form_data_sources)">
							<option value="-1"<?php 
    if (get_request_var_request("host_id") == "-1") {
        ?>
 selected<?php 
    }
    ?>
>Any</option>
                            <?php 
    /* modify for multi user start */
    if ($_SESSION["permission"] == ACCESS_ADMINISTRATOR) {
        ?>
							<option value="0"<?php 
        if (get_request_var_request("host_id") == "0") {
            ?>
 selected<?php 
        }
        ?>
>None</option>
							<?php 
    }
    if ($_SESSION["permission"] <= ACCESS_ADMINISTRATOR) {
        $hosts = db_fetch_assoc("\r\n                                    SELECT host.id,CONCAT_WS('',host.description,' (',host.hostname,')') as name FROM host \r\n                                        INNER JOIN user_auth_perms ON host.id = user_auth_perms.item_id AND user_auth_perms.user_id = '" . $_SESSION["sess_user_id"] . "' AND user_auth_perms.type = '3' \r\n                                    ORDER BY host.description,host.hostname");
    } else {
        $hosts = db_fetch_assoc("select id,CONCAT_WS('',description,' (',hostname,')') as name from host order by description,hostname");
    }
    /* modify for multi user end */
    if (sizeof($hosts) > 0) {
        foreach ($hosts as $host) {
            print "<option value='" . $host["id"] . "'";
            if (get_request_var_request("host_id") == $host["id"]) {
                print " selected";
            }
            print ">" . title_trim(htmlspecialchars($host["name"]), 40) . "</option>\n";
        }
    }
    ?>

						</select>
					</td>
					<td width="50">
						&nbsp;Template:&nbsp;
					</td>
					<td width="1">
						<select name="template_id" onChange="applyDSFilterChange(document.form_data_sources)">
							<option value="-1"<?php 
    if (get_request_var_request("template_id") == "-1") {
        ?>
 selected<?php 
    }
    ?>
>Any</option>
                            <?php 
    /* modify for multi user start */
    if ($_SESSION["permission"] == ACCESS_ADMINISTRATOR) {
        ?>
							<option value="0"<?php 
        if (get_request_var_request("template_id") == "0") {
            ?>
 selected<?php 
        }
        ?>
>None</option>
							<?php 
    }
    if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
        $templates = db_fetch_assoc("\r\n                                    SELECT DISTINCT data_template.id, data_template.name FROM data_template\r\n                                        INNER JOIN data_template_data ON data_template.id = data_template_data.data_template_id\r\n                                        INNER JOIN data_local ON data_template_data.local_data_id = data_local.id\r\n                                        INNER JOIN host ON data_local.host_id = host.id\r\n                                        INNER JOIN user_auth_perms ON host.id = user_auth_perms.item_id AND user_auth_perms.user_id = '" . $_SESSION["sess_user_id"] . "' AND user_auth_perms.type = '3'\r\n                                    WHERE data_template_data.local_data_id > 0\r\n                                    ORDER BY data_template.name");
    } else {
        $templates = db_fetch_assoc("SELECT DISTINCT data_template.id, data_template.name\r\n\t\t\t\t\t\t\t\tFROM data_template\r\n\t\t\t\t\t\t\t\tINNER JOIN data_template_data\r\n\t\t\t\t\t\t\t\tON data_template.id=data_template_data.data_template_id\r\n\t\t\t\t\t\t\t\tWHERE data_template_data.local_data_id>0\r\n\t\t\t\t\t\t\t\tORDER BY data_template.name");
    }
    /* modify for multi user end */
    if (sizeof($templates) > 0) {
        foreach ($templates as $template) {
            print "<option value='" . $template["id"] . "'";
            if (get_request_var_request("template_id") == $template["id"]) {
                print " selected";
            }
            print ">" . title_trim(htmlspecialchars($template["name"]), 40) . "</option>\n";
        }
    }
    ?>

						</select>
					</td>
					<td nowrap style='white-space: nowrap;'>
						&nbsp;<input type="submit" value="Go" title="Set/Refresh Filters">
						<input type="submit" name="clear_x" value="Clear" title="Clear Filters">
					</td>
				</tr>
				<tr>
					<td width="50">
						Method:&nbsp;
					</td>
					<td width="1">
						<select name="method_id" onChange="applyDSFilterChange(document.form_data_sources)">
							<option value="-1"<?php 
    if (get_request_var_request("method_id") == "-1") {
        ?>
 selected<?php 
    }
    ?>
>Any</option>
                            <?php 
    /* modify for multi user start */
    if ($_SESSION["permission"] == ACCESS_ADMINISTRATOR) {
        ?>
							<option value="0"<?php 
        if (get_request_var_request("method_id") == "0") {
            ?>
 selected<?php 
        }
        ?>
>None</option>
							<?php 
    }
    if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
        $methods = db_fetch_assoc("\r\n                                    SELECT DISTINCT data_input.id, data_input.name FROM data_input\r\n                                        INNER JOIN data_template_data ON data_input.id = data_template_data.data_input_id\r\n                                        INNER JOIN data_local ON data_template_data.local_data_id = data_local.id\r\n                                        INNER JOIN host ON data_local.host_id = host.id\r\n                                        INNER JOIN user_auth_perms ON host.id = user_auth_perms.item_id AND user_auth_perms.user_id = '" . $_SESSION["sess_user_id"] . "' AND user_auth_perms.type = '3'\r\n                                    WHERE data_template_data.local_data_id > 0\r\n                                    ORDER BY data_input.name");
    } else {
        $methods = db_fetch_assoc("SELECT DISTINCT data_input.id, data_input.name\r\n\t\t\t\t\t\t\t\tFROM data_input\r\n\t\t\t\t\t\t\t\tINNER JOIN data_template_data\r\n\t\t\t\t\t\t\t\tON data_input.id=data_template_data.data_input_id\r\n\t\t\t\t\t\t\t\tWHERE data_template_data.local_data_id>0\r\n\t\t\t\t\t\t\t\tORDER BY data_input.name");
    }
    /* modify for multi user end */
    if (sizeof($methods) > 0) {
        foreach ($methods as $method) {
            print "<option value='" . $method["id"] . "'";
            if (get_request_var_request("method_id") == $method["id"]) {
                print " selected";
            }
            print ">" . title_trim(htmlspecialchars($method["name"]), 40) . "</option>\n";
        }
    }
    ?>
						</select>
					</td>
					<td nowrap style='white-space: nowrap;' width="50">
						&nbsp;Rows per Page:&nbsp;
					</td>
					<td width="1">
						<select name="ds_rows" onChange="applyDSFilterChange(document.form_data_sources)">
							<option value="-1"<?php 
    if (get_request_var_request("ds_rows") == "-1") {
        ?>
 selected<?php 
    }
    ?>
>Default</option>
							<?php 
    if (sizeof($item_rows) > 0) {
        foreach ($item_rows as $key => $value) {
            print "<option value='" . $key . "'";
            if (get_request_var_request("ds_rows") == $key) {
                print " selected";
            }
            print ">" . htmlspecialchars($value) . "</option>\n";
        }
    }
    ?>
						</select>
					</td>
				</tr>
			</table>
			<table cellpadding="1" cellspacing="0">
				<tr>
					<td width="50">
						Search:&nbsp;
					</td>
					<td width="1">
						<input type="text" name="filter" size="40" value="<?php 
    print htmlspecialchars(get_request_var_request("filter"));
    ?>
">
					</td>
				</tr>
			</table>
			<input type='hidden' name='page' value='1'>
		</form>
		</td>
	</tr>
	<?php 
    html_end_box();
    /* form the 'where' clause for our main sql query */
    if (strlen(get_request_var_request("filter"))) {
        $sql_where1 = "AND (data_template_data.name_cache like '%%" . get_request_var_request("filter") . "%%'" . " OR data_template_data.local_data_id like '%%" . get_request_var_request("filter") . "%%'" . " OR data_template.name like '%%" . get_request_var_request("filter") . "%%'" . " OR data_input.name like '%%" . get_request_var_request("filter") . "%%')";
        $sql_where2 = "AND (data_template_data.name_cache like '%%" . get_request_var_request("filter") . "%%'" . " OR data_template.name like '%%" . get_request_var_request("filter") . "%%')";
    } else {
        $sql_where1 = "";
        $sql_where2 = "";
    }
    if (get_request_var_request("host_id") == "-1") {
        /* Show all items */
    } elseif (get_request_var_request("host_id") == "0") {
        $sql_where1 .= " AND data_local.host_id=0";
        $sql_where2 .= " AND data_local.host_id=0";
    } elseif (!empty($_REQUEST["host_id"])) {
        $sql_where1 .= " AND data_local.host_id=" . get_request_var_request("host_id");
        $sql_where2 .= " AND data_local.host_id=" . get_request_var_request("host_id");
    }
    if (get_request_var_request("template_id") == "-1") {
        /* Show all items */
    } elseif (get_request_var_request("template_id") == "0") {
        $sql_where1 .= " AND data_template_data.data_template_id=0";
        $sql_where2 .= " AND data_template_data.data_template_id=0";
    } elseif (!empty($_REQUEST["host_id"])) {
        $sql_where1 .= " AND data_template_data.data_template_id=" . get_request_var_request("template_id");
        $sql_where2 .= " AND data_template_data.data_template_id=" . get_request_var_request("template_id");
    }
    if (get_request_var_request("method_id") == "-1") {
        /* Show all items */
    } elseif (get_request_var_request("method_id") == "0") {
        $sql_where1 .= " AND data_template_data.data_input_id=0";
        $sql_where2 .= " AND data_template_data.data_input_id=0";
    } elseif (!empty($_REQUEST["method_id"])) {
        $sql_where1 .= " AND data_template_data.data_input_id=" . get_request_var_request("method_id");
        $sql_where2 .= " AND data_template_data.data_input_id=" . get_request_var_request("method_id");
    }
    /* modify for multi user start */
    $sql_join = "";
    if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
        $sql_join = "\r\n        \tINNER JOIN host ON data_local.host_id = host.id\r\n            INNER JOIN user_auth_perms ON host.id = user_auth_perms.item_id AND user_auth_perms.user_id = '" . $_SESSION["sess_user_id"] . "' AND user_auth_perms.type = '3'";
    }
    $total_rows = sizeof(db_fetch_assoc("SELECT DISTINCT \r\n\t\tdata_local.id\r\n\t\tFROM (data_local,data_template_data)\r\n\t\tLEFT JOIN data_input\r\n\t\tON (data_input.id=data_template_data.data_input_id)\r\n\t\tLEFT JOIN data_template\r\n\t\tON (data_local.data_template_id=data_template.id)\r\n        {$sql_join}\r\n\t\tWHERE data_local.id=data_template_data.local_data_id\r\n\t\t{$sql_where1}"));
    $poller_intervals = array_rekey(db_fetch_assoc("SELECT DISTINCT data_template_data.local_data_id AS id,\r\n\t\tMin(data_template_data.rrd_step*rra.steps) AS poller_interval\r\n\t\tFROM data_template\r\n\t\tINNER JOIN (data_local\r\n\t\tINNER JOIN ((data_template_data_rra\r\n\t\tINNER JOIN data_template_data ON data_template_data_rra.data_template_data_id=data_template_data.id)\r\n\t\tINNER JOIN rra ON data_template_data_rra.rra_id = rra.id) ON data_local.id = data_template_data.local_data_id) ON data_template.id = data_template_data.data_template_id\r\n\t\t{$sql_join} \r\n\t\t{$sql_where2}\r\n\t\tGROUP BY data_template_data.local_data_id"), "id", "poller_interval");
    $data_sources = db_fetch_assoc("SELECT DISTINCT \r\n\t\tdata_template_data.local_data_id,\r\n\t\tdata_template_data.name_cache,\r\n\t\tdata_template_data.active,\r\n\t\tdata_input.name as data_input_name,\r\n\t\tdata_template.name as data_template_name,\r\n\t\tdata_local.host_id\r\n\t\tFROM (data_local,data_template_data)\r\n\t\tLEFT JOIN data_input\r\n\t\tON (data_input.id=data_template_data.data_input_id)\r\n\t\tLEFT JOIN data_template\r\n\t\tON (data_local.data_template_id=data_template.id)\r\n\t\t{$sql_join}\r\n\t\tWHERE data_local.id=data_template_data.local_data_id\r\n\t\t{$sql_where1}\r\n\t\tORDER BY " . get_request_var_request("sort_column") . " " . get_request_var_request("sort_direction") . " LIMIT " . get_request_var_request("ds_rows") * (get_request_var_request("page") - 1) . "," . get_request_var_request("ds_rows"));
    /* modify for multi user end */
    print "<form name='chk' method='post' action='data_sources.php'>\n";
    html_start_box("", "100%", $colors["header"], "3", "center", "");
    /* generate page list */
    $url_page_select = get_page_list(get_request_var_request("page"), MAX_DISPLAY_PAGES, get_request_var_request("ds_rows"), $total_rows, "data_sources.php?filter=" . get_request_var_request("filter") . "&host_id=" . get_request_var_request("host_id"));
    $nav = "<tr bgcolor='#" . $colors["header"] . "'>\r\n\t\t\t<td colspan='7'>\r\n\t\t\t\t<table width='100%' cellspacing='0' cellpadding='0' border='0'>\r\n\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t<td align='left' class='textHeaderDark'>\r\n\t\t\t\t\t\t\t<strong>&lt;&lt; ";
    if (get_request_var_request("page") > 1) {
        $nav .= "<a class='linkOverDark' href='" . htmlspecialchars("data_sources.php?filter=" . get_request_var_request("filter") . "&host_id=" . get_request_var_request("host_id") . "&page=" . (get_request_var_request("page") - 1)) . "'>";
    }
    $nav .= "Previous";
    if (get_request_var_request("page") > 1) {
        $nav .= "</a>";
    }
    $nav .= "</strong>\r\n\t\t\t\t\t\t</td>\n\r\n\t\t\t\t\t\t<td align='center' class='textHeaderDark'>\r\n\t\t\t\t\t\t\tShowing Rows " . (get_request_var_request("ds_rows") * (get_request_var_request("page") - 1) + 1) . " to " . ($total_rows < get_request_var_request("ds_rows") || $total_rows < get_request_var_request("ds_rows") * get_request_var_request("page") ? $total_rows : get_request_var_request("ds_rows") * get_request_var_request("page")) . " of {$total_rows} [{$url_page_select}]\r\n\t\t\t\t\t\t</td>\n\r\n\t\t\t\t\t\t<td align='right' class='textHeaderDark'>\r\n\t\t\t\t\t\t\t<strong>";
    if (get_request_var_request("page") * get_request_var_request("ds_rows") < $total_rows) {
        $nav .= "<a class='linkOverDark' href='" . htmlspecialchars("data_sources.php?filter=" . get_request_var_request("filter") . "&host_id=" . get_request_var_request("host_id") . "&page=" . (get_request_var_request("page") + 1)) . "'>";
    }
    $nav .= "Next";
    if (get_request_var_request("page") * get_request_var_request("ds_rows") < $total_rows) {
        $nav .= "</a>";
    }
    $nav .= " &gt;&gt;</strong>\r\n\t\t\t\t\t\t</td>\n\r\n\t\t\t\t\t</tr>\r\n\t\t\t\t</table>\r\n\t\t\t</td>\r\n\t\t</tr>\n";
    print $nav;
    $display_text = array("name_cache" => array("Name", "ASC"), "local_data_id" => array("ID", "ASC"), "data_input_name" => array("Data Input Method", "ASC"), "nosort" => array("Poller Interval", "ASC"), "active" => array("Active", "ASC"), "data_template_name" => array("Template Name", "ASC"));
    html_header_sort_checkbox($display_text, get_request_var_request("sort_column"), get_request_var_request("sort_direction"), false);
    $i = 0;
    if (sizeof($data_sources) > 0) {
        foreach ($data_sources as $data_source) {
            $data_source["data_template_name"] = htmlspecialchars($data_source["data_template_name"]);
            $data_name_cache = title_trim(htmlspecialchars($data_source["name_cache"]), read_config_option("max_title_data_source"));
            if (trim(get_request_var_request("filter") != "")) {
                $data_source['data_input_name'] = preg_replace("/(" . preg_quote(get_request_var_request("filter")) . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", htmlspecialchars($data_source['data_input_name']));
                $data_source['data_template_name'] = preg_replace("/(" . preg_quote(get_request_var_request("filter")) . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", $data_source['data_template_name']);
                $data_name_cache = preg_replace("/(" . preg_quote(get_request_var_request("filter")) . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", $data_name_cache);
            }
            /* keep copy of data source for comparison */
            $data_source_orig = $data_source;
            /* modify for multi user start */
            if ($_SESSION["permission"] > ACCESS_NORMAL_USER) {
                $data_source = api_plugin_hook_function('data_sources_table', $data_source);
            }
            /* modify for multi user end */
            /* we're escaping strings here, so no need to escape them on form_selectable_cell */
            if ($data_source_orig["data_template_name"] != $data_source["data_template_name"]) {
                /* was changed by plugin, plugin has to take care for html-escaping */
                $data_template_name = empty($data_source["data_template_name"]) ? "<em>None</em>" : $data_source["data_template_name"];
            } else {
                /* we take care of html-escaping */
                $data_template_name = empty($data_source["data_template_name"]) ? "<em>None</em>" : htmlspecialchars($data_source["data_template_name"]);
            }
            if ($data_source_orig["data_input_name"] != $data_source["data_input_name"]) {
                /* was changed by plugin, plugin has to take care for html-escaping */
                $data_input_name = empty($data_source["data_input_name"]) ? "<em>None</em>" : $data_source["data_input_name"];
            } else {
                /* we take care of html-escaping */
                $data_input_name = empty($data_source["data_input_name"]) ? "<em>External</em>" : htmlspecialchars($data_source["data_input_name"]);
            }
            $poller_interval = isset($poller_intervals[$data_source["local_data_id"]]) ? $poller_intervals[$data_source["local_data_id"]] : 0;
            form_alternate_row_color($colors["alternate"], $colors["light"], $i, 'line' . $data_source["local_data_id"]);
            $i++;
            form_selectable_cell("<a class='linkEditMain' href='" . htmlspecialchars("data_sources.php?action=ds_edit&id=" . $data_source["local_data_id"]) . "' title='" . $data_source["name_cache"] . "'>" . (get_request_var_request("filter") != "" ? preg_replace("/(" . preg_quote(get_request_var_request("filter")) . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", title_trim(htmlspecialchars($data_source["name_cache"]), read_config_option("max_title_data_source"))) : title_trim(htmlspecialchars($data_source["name_cache"]), read_config_option("max_title_data_source"))) . "</a>", $data_source["local_data_id"]);
            form_selectable_cell($data_source['local_data_id'], $data_source['local_data_id']);
            form_selectable_cell(get_request_var_request("filter") != "" ? preg_replace("/(" . preg_quote(get_request_var_request("filter")) . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", $data_input_name) : $data_input_name, $data_source["local_data_id"]);
            form_selectable_cell(get_poller_interval($poller_interval), $data_source["local_data_id"]);
            form_selectable_cell($data_source['active'] == "on" ? "Yes" : "No", $data_source["local_data_id"]);
            form_selectable_cell(get_request_var_request("filter") != "" ? preg_replace("/(" . preg_quote(get_request_var_request("filter")) . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", $data_template_name) : $data_template_name, $data_source["local_data_id"]);
            form_checkbox_cell($data_source["name_cache"], $data_source["local_data_id"]);
            form_end_row();
        }
        /* put the nav bar on the bottom as well */
        print $nav;
    } else {
        print "<tr><td><em>No Data Sources</em></td></tr>";
    }
    html_end_box(false);
    /* draw the dropdown containing a list of available actions for this form */
    draw_actions_dropdown($ds_actions);
    print "</form>\n";
}
Exemple #7
0
function tree_edit()
{
    global $colors, $fields_tree_edit;
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var("id"));
    /* ==================================================== */
    /* clean up subaction */
    if (isset($_REQUEST["subaction"])) {
        $_REQUEST["subaction"] = sanitize_search_string(get_request_var("subaction"));
    }
    /* modify for multi user start */
    $public_tree = FALSE;
    if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
        if ($_GET["id"] == $_SESSION["public_tree_id"]) {
            $public_tree = TRUE;
            $fields_tree_edit["sort_type"]["method"] = "hidden";
        } else {
            $_GET["id"] = $_SESSION["private_tree_id"];
        }
        $tree = db_fetch_row("select * from graph_tree where id=" . $_GET["id"]);
        $header_label = "[edit: " . htmlspecialchars($tree["name"]) . "]";
        $fields_tree_edit["name"]["method"] = "";
    } else {
        if (!empty($_GET["id"])) {
            $tree = db_fetch_row("select * from graph_tree where id=" . $_GET["id"]);
            $header_label = "[edit: " . htmlspecialchars($tree["name"]) . "]";
        } else {
            $header_label = "[new]";
        }
    }
    /* modify for multi user end */
    html_start_box("<strong>Graph Trees</strong> {$header_label}", "100%", $colors["header"], "3", "center", "");
    draw_edit_form(array("config" => array(), "fields" => inject_form_variables($fields_tree_edit, isset($tree) ? $tree : array())));
    html_end_box();
    if (!empty($_GET["id"])) {
        /* modify for multi user start */
        if (check_resource_count(RESOURCE_GRAPH, TRUE) == TRUE && $_GET["id"] == $_SESSION["private_tree_id"] || $_SESSION["permission"] == ACCESS_ADMINISTRATOR) {
            html_start_box("<strong>Tree Items</strong>", "100%", $colors["header"], "3", "center", "tree.php?action=item_edit&tree_id=" . htmlspecialchars($tree["id"]) . "&parent_id=0");
        } else {
            html_start_box("<strong>Tree Items</strong>", "100%", $colors["header"], "3", "center", "");
        }
        /* modify for multi user end */
        ?>
		<td>
		<input type='button' onClick='return document.location="tree.php?action=edit&id=<?php 
        print htmlspecialchars(get_request_var("id"));
        ?>
&subaction=expand_all"' value='Expand All' title='Expand All Trees'>
		<input type='button' onClick='return document.location="tree.php?action=edit&id=<?php 
        print htmlspecialchars(get_request_var("id"));
        ?>
&subaction=collapse_all"' value='Collapse All' title='Collapse All Trees'></a>
		</td>
		<?php 
        print "<tr bgcolor='#" . $colors["header_panel"] . "'>";
        DrawMatrixHeaderItem("Item", $colors["header_text"], 1);
        DrawMatrixHeaderItem("Value", $colors["header_text"], 1);
        DrawMatrixHeaderItem("&nbsp;", $colors["header_text"], 2);
        print "</tr>";
        grow_edit_graph_tree($_GET["id"], "", "");
        html_end_box();
    }
    /* modify for multi user start */
    if ($_SESSION["permission"] == ACCESS_ADMINISTRATOR || $public_tree == FALSE) {
        form_save_button("tree.php", "return");
    }
    /* modify for multi user end */
}
Exemple #8
0
function list_tholds()
{
    global $colors, $thold_bgcolors, $config, $hostid;
    $thold_actions = array(1 => 'Delete', 2 => 'Disable', 3 => 'Enable', 4 => 'Reapply Suggested Names');
    thold_request_validation();
    $statefilter = '';
    if (isset($_REQUEST['state'])) {
        if ($_REQUEST['state'] == '-1') {
            $statefilter = '';
        } else {
            if ($_REQUEST['state'] == '0') {
                $statefilter = "thold_data.thold_enabled='off'";
            }
            if ($_REQUEST['state'] == '2') {
                $statefilter = "thold_data.thold_enabled='on'";
            }
            if ($_REQUEST['state'] == '1') {
                $statefilter = '(thold_data.thold_alert!=0 OR thold_data.bl_alert>0)';
            }
            if ($_REQUEST['state'] == '3') {
                $statefilter = '((thold_data.thold_alert!=0 AND thold_data.thold_fail_count >= thold_data.thold_fail_trigger) OR (thold_data.bl_alert>0 AND thold_data.bl_fail_count >= thold_data.bl_fail_trigger))';
            }
        }
    }
    $alert_num_rows = read_config_option('alert_num_rows');
    if ($alert_num_rows < 1 || $alert_num_rows > 999) {
        db_execute("REPLACE INTO settings VALUES ('alert_num_rows', 30)");
        /* pull it again so it updates the cache */
        $alert_num_rows = read_config_option('alert_num_rows', true);
    }
    include $config['include_path'] . '/top_header.php';
    $sql_where = '';
    $sort = $_REQUEST['sort_column'];
    $limit = ' LIMIT ' . $alert_num_rows * ($_REQUEST['page'] - 1) . ",{$alert_num_rows}";
    if (!empty($_REQUEST['hostid']) && $_REQUEST['hostid'] != 'ALL') {
        $sql_where .= (!strlen($sql_where) ? 'WHERE ' : ' AND ') . "thold_data.host_id = " . $_REQUEST['hostid'];
    }
    if (!empty($_REQUEST['template']) && $_REQUEST['template'] != 'ALL') {
        $sql_where .= (!strlen($sql_where) ? 'WHERE ' : ' AND ') . "thold_data.data_template = " . $_REQUEST['template'];
    }
    if ($statefilter != '') {
        $sql_where .= (!strlen($sql_where) ? 'WHERE ' : ' AND ') . "{$statefilter}";
    }
    /* modify for multi user start */
    if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
        $sql = "\r\n            SELECT thold_data.* FROM thold_data\r\n                INNER JOIN user_auth_perms ON thold_data.host_id = user_auth_perms.item_id AND user_auth_perms.user_id = '" . $_SESSION["sess_user_id"] . "' AND user_auth_perms.type = '3'\r\n            {$sql_where}\r\n            ORDER BY {$sort} " . $_REQUEST['sort_direction'] . $limit;
    } else {
        $current_user = db_fetch_row('SELECT * FROM user_auth WHERE id=' . $_SESSION['sess_user_id']);
        $sql_where .= (!strlen($sql_where) ? 'WHERE ' : ' AND ') . get_graph_permissions_sql($current_user['policy_graphs'], $current_user['policy_hosts'], $current_user['policy_graph_templates']);
        $sql = "SELECT * FROM thold_data\r\n\t\tLEFT JOIN user_auth_perms on ((thold_data.graph_id=user_auth_perms.item_id and user_auth_perms.type=1 and user_auth_perms.user_id=" . $_SESSION['sess_user_id'] . ") OR (thold_data.host_id=user_auth_perms.item_id and user_auth_perms.type=3 and user_auth_perms.user_id=" . $_SESSION['sess_user_id'] . ") OR (thold_data.graph_template=user_auth_perms.item_id and user_auth_perms.type=4 and user_auth_perms.user_id=" . $_SESSION['sess_user_id'] . "))\r\n\t\t{$sql_where}\r\n\t\tORDER BY {$sort} " . $_REQUEST['sort_direction'] . $limit;
    }
    /* modify for multi user end */
    $result = db_fetch_assoc($sql);
    /* modify for multi user start */
    if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
        $hostresult = db_fetch_assoc("\r\n            SELECT host.id, host.description, host.hostname FROM host \r\n                INNER JOIN thold_data ON host.id = thold_data.host_id \r\n                INNER JOIN user_auth_perms ON host.id = user_auth_perms.item_id AND user_auth_perms.user_id = '" . $_SESSION["sess_user_id"] . "' AND user_auth_perms.type = '3'");
        $data_templates = db_fetch_assoc("\r\n            SELECT DISTINCT data_template.id, data_template.name FROM data_template\r\n                INNER JOIN thold_data ON thold_data.data_template = data_template.id\r\n                INNER JOIN host ON thold_data.host_id = host.id\r\n                INNER JOIN user_auth_perms ON host.id = user_auth_perms.item_id AND user_auth_perms.user_id = '" . $_SESSION["sess_user_id"] . "' AND user_auth_perms.type = '3'\r\n            ORDER BY data_template.name");
    } else {
        $sql_where_hid = 'WHERE ' . get_graph_permissions_sql($current_user['policy_graphs'], $current_user['policy_hosts'], $current_user['policy_graph_templates']);
        $hostresult = db_fetch_assoc("SELECT DISTINCT host.id, host.description, host.hostname\r\n\t\tFROM host\r\n\t\tINNER JOIN thold_data ON (host.id = thold_data.host_id)\r\n\t\tLEFT JOIN user_auth_perms on (thold_data.host_id=user_auth_perms.item_id and user_auth_perms.type=3 and user_auth_perms.user_id=" . $_SESSION['sess_user_id'] . ")\r\n\t\t{$sql_where_hid}\r\n\t\tORDER BY description");
        $data_templates = db_fetch_assoc("SELECT DISTINCT data_template.id, data_template.name\r\n\t\tFROM data_template\r\n\t\tINNER JOIN thold_data ON (thold_data.data_template = data_template.id)\r\n\t\tORDER BY data_template.name");
    }
    /* modify for multi user end */
    ?>
	<script type="text/javascript">
	<!--
	function applyTHoldFilterChange(objForm) {
		strURL = '?hostid=' + objForm.hostid.value;
		strURL = strURL + '&state=' + objForm.state.value;
		strURL = strURL + '&template=' + objForm.template.value;
		document.location = strURL;
	}
	-->
	</script>
	<?php 
    /* modify for multi user start */
    if (check_resource_count(RESOURCE_THOLD) == TRUE) {
        html_start_box('<strong>Threshold Management</strong>', '100%', $colors['header'], '3', 'center', 'thold_add.php');
    } else {
        html_start_box('<strong>Threshold Management</strong>', '100%', $colors['header'], '3', 'center', '');
    }
    /* modify for multi user end */
    ?>
	<tr bgcolor='#<?php 
    print $colors["panel"];
    ?>
' class='noprint'>
		<td class='noprint'>
			<form name='listthold' action='listthold.php' method='post'>
			<table cellpadding='0' cellspacing='0'>
				<tr class='noprint'>
					<td width='1'>
						&nbsp;Host:&nbsp;
					</td>
					<td width='1'>
						<select name='hostid' onChange='applyTHoldFilterChange(document.listthold)'>
							<option value='ALL'>Any</option>
							<?php 
    foreach ($hostresult as $row) {
        echo "<option value='" . $row['id'] . "'" . (isset($_REQUEST['hostid']) && $row['id'] == $_REQUEST['hostid'] ? ' selected' : '') . '>' . $row['description'] . ' - (' . $row['hostname'] . ')' . '</option>';
    }
    ?>
						</select>
					</td>
					<td width='1'>
						&nbsp;Template:&nbsp;
					</td>
					<td width='1'>
						<select name='template' onChange='applyTHoldFilterChange(document.listthold)'>
							<option value='ALL'>Any</option>
							<?php 
    foreach ($data_templates as $row) {
        echo "<option value='" . $row['id'] . "'" . (isset($_REQUEST['template']) && $row['id'] == $_REQUEST['template'] ? ' selected' : '') . '>' . $row['name'] . '</option>';
    }
    ?>
						</select>
					</td>
					<td width='1'>
						&nbsp;State:&nbsp;
					</td>
					<td width='1'>
						<select name='state' onChange='applyTHoldFilterChange(document.listthold)'>
							<option value='-1'<?php 
    if ($_REQUEST["state"] == "-1") {
        ?>
 selected<?php 
    }
    ?>
>All</option>
							<option value='1'<?php 
    if ($_REQUEST["state"] == "1") {
        ?>
 selected<?php 
    }
    ?>
>Breached</option>
							<option value='3'<?php 
    if ($_REQUEST["state"] == "3") {
        ?>
 selected<?php 
    }
    ?>
>Triggered</option>
							<option value='2'<?php 
    if ($_REQUEST["state"] == "2") {
        ?>
 selected<?php 
    }
    ?>
>Enabled</option>
							<option value='0'<?php 
    if ($_REQUEST["state"] == "0") {
        ?>
 selected<?php 
    }
    ?>
>Disabled</option>
						</select>
					</td>
					<td nowrap style='white-space: nowrap;'>
						&nbsp;<input type='submit' name='clear' value='Clear' title='Return to Defaults'>
					</td>
				</tr>
			</table>
			<input type='hidden' name='search' value='search'>
			</form>
		</td>
	</tr>
	<?php 
    html_end_box();
    define('MAX_DISPLAY_PAGES', 21);
    /* modify for multi user start */
    if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) {
        $total_rows = db_fetch_cell("\r\n            SELECT COUNT(thold_data.id) FROM thold_data\r\n                INNER JOIN user_auth_perms ON thold_data.host_id = user_auth_perms.item_id AND user_auth_perms.user_id = '" . $_SESSION["sess_user_id"] . "' AND user_auth_perms.type = '3'\r\n            {$sql_where}");
    } else {
        $total_rows = count(db_fetch_assoc("SELECT thold_data.id\r\n\t\tFROM thold_data\r\n\t\tLEFT JOIN user_auth_perms\r\n\t\tON ((thold_data.graph_id=user_auth_perms.item_id\r\n\t\tAND user_auth_perms.type=1\r\n\t\tAND user_auth_perms.user_id=" . $_SESSION['sess_user_id'] . ")\r\n\t\tOR (thold_data.host_id=user_auth_perms.item_id\r\n\t\tAND user_auth_perms.type=3\r\n\t\tAND user_auth_perms.user_id=" . $_SESSION['sess_user_id'] . ")\r\n\t\tOR (thold_data.graph_template=user_auth_perms.item_id\r\n\t\tAND user_auth_perms.type=4\r\n\t\tAND user_auth_perms.user_id=" . $_SESSION['sess_user_id'] . "))\r\n\t\t{$sql_where}"));
    }
    /* modify for multi user end */
    $url_page_select = get_page_list($_REQUEST['page'], MAX_DISPLAY_PAGES, $alert_num_rows, $total_rows, 'listthold.php?');
    /* print checkbox form for validation */
    print "<form name='chk' method='post' action='listthold.php'>\n";
    html_start_box('', '100%', $colors['header'], '4', 'center', '');
    if ($total_rows) {
        $nav = "<tr bgcolor='#" . $colors['header'] . "'>\r\n\t\t\t\t<td colspan='12'>\r\n\t\t\t\t\t<table width='100%' cellspacing='0' cellpadding='0' border='0'>\r\n\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t<td align='left' class='textHeaderDark'>\r\n\t\t\t\t\t\t\t\t<strong>&lt;&lt; ";
        if ($_REQUEST["page"] > 1) {
            $nav .= "<a class='linkOverDark' href='" . htmlspecialchars("listthold.php?page=" . ($_REQUEST["page"] - 1)) . "'>";
        }
        $nav .= "Previous";
        if ($_REQUEST["page"] > 1) {
            $nav .= "</a>";
        }
        $nav .= "</strong>\r\n\t\t\t\t\t\t\t</td>\n\r\n\t\t\t\t\t\t\t<td align='center' class='textHeaderDark'>\r\n\t\t\t\t\t\t\t\tShowing Rows " . ($alert_num_rows * ($_REQUEST["page"] - 1) + 1) . " to " . ($total_rows < $alert_num_rows || $total_rows < $alert_num_rows * $_REQUEST["page"] ? $total_rows : $alert_num_rows * $_REQUEST["page"]) . " of {$total_rows} [{$url_page_select}]\r\n\t\t\t\t\t\t\t</td>\n\r\n\t\t\t\t\t\t\t<td align='right' class='textHeaderDark'>\r\n\t\t\t\t\t\t\t\t<strong>";
        if ($_REQUEST["page"] * $alert_num_rows < $total_rows) {
            $nav .= "<a class='linkOverDark' href='" . htmlspecialchars("listthold.php?page=" . ($_REQUEST["page"] + 1)) . "'>";
        }
        $nav .= "Next";
        if ($_REQUEST["page"] * $alert_num_rows < $total_rows) {
            $nav .= "</a>";
        }
        $nav .= " &gt;&gt;</strong>\r\n\t\t\t\t\t\t\t</td>\n\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t</table>\r\n\t\t\t\t</td>\r\n\t\t\t</tr>\n";
    } else {
        $nav = "<tr bgcolor='#" . $colors['header'] . "'>\r\n\t\t\t\t<td colspan='12'>\r\n\t\t\t\t\t<table width='100%' cellspacing='0' cellpadding='0' border='0'>\r\n\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t<td align='center' class='textHeaderDark'>\r\n\t\t\t\t\t\t\t\tNo Rows Found\r\n\t\t\t\t\t\t\t</td>\n\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t</table>\r\n\t\t\t\t</td>\r\n\t\t\t</tr>\n";
    }
    print $nav;
    $display_text = array('name' => array('Name', 'ASC'), 'thold_type' => array('Type', 'ASC'), 'thold_hi' => array('High', 'ASC'), 'thold_low' => array('Low', 'ASC'), 'nosort3' => array('Trigger', ''), 'nosort4' => array('Duration', ''), 'repeat_alert' => array('Repeat', 'ASC'), 'lastread' => array('Current', 'ASC'), 'thold_alert' => array('Triggered', 'ASC'), 'thold_enabled' => array('Enabled', 'ASC'));
    html_header_sort_checkbox($display_text, $_REQUEST['sort_column'], $_REQUEST['sort_direction'], false);
    $timearray = array(1 => '5 Minutes', 2 => '10 Minutes', 3 => '15 Minutes', 4 => '20 Minutes', 6 => '30 Minutes', 8 => '45 Minutes', 12 => 'Hour', 24 => '2 Hours', 36 => '3 Hours', 48 => '4 Hours', 72 => '6 Hours', 96 => '8 Hours', 144 => '12 Hours', 288 => '1 Day', 576 => '2 Days', 2016 => '1 Week', 4032 => '2 Weeks', 8640 => '1 Month');
    $c = 0;
    $i = 0;
    $types = array('High/Low', 'Baseline Deviation', 'Time Based');
    if (count($result)) {
        foreach ($result as $row) {
            $c++;
            $grapharr = db_fetch_row('SELECT DISTINCT graph_templates_item.local_graph_id
						FROM graph_templates_item, data_template_rrd
						WHERE (data_template_rrd.local_data_id=' . $row['rra_id'] . ' AND data_template_rrd.id=graph_templates_item.task_item_id)');
            $graph_id = $grapharr['local_graph_id'];
            $alertstat = 'no';
            $bgcolor = 'green';
            if ($row['thold_type'] == 0) {
                if ($row['thold_alert'] != 0) {
                    $alertstat = 'yes';
                    if ($row['thold_fail_count'] >= $row['thold_fail_trigger']) {
                        $bgcolor = 'red';
                    } elseif ($row['thold_warning_fail_count'] >= $row['thold_warning_fail_trigger']) {
                        $bgcolor = 'warning';
                    } else {
                        $bgcolor = 'yellow';
                    }
                }
            } elseif ($row['thold_type'] == 2) {
                if ($row['thold_alert'] != 0) {
                    $alertstat = 'yes';
                    if ($row['thold_fail_count'] >= $row['time_fail_trigger']) {
                        $bgcolor = 'red';
                    } elseif ($row['thold_warning_fail_count'] >= $row['time_warning_fail_trigger']) {
                        $bgcolor = 'warning';
                    } else {
                        $bgcolor = 'yellow';
                    }
                }
            } else {
                if ($row['bl_alert'] == 1) {
                    $alertstat = 'baseline-LOW';
                    $bgcolor = $row['bl_fail_count'] >= $row['bl_fail_trigger'] ? 'orange' : 'yellow';
                } elseif ($row['bl_alert'] == 2) {
                    $alertstat = 'baseline-HIGH';
                    $bgcolor = $row['bl_fail_count'] >= $row['bl_fail_trigger'] ? 'orange' : 'yellow';
                }
            }
            if ($row['thold_enabled'] == 'off') {
                form_alternate_row_color($thold_bgcolors['grey'], $thold_bgcolors['grey'], $i, 'line' . $row["id"]);
                $i++;
            } else {
                form_alternate_row_color($thold_bgcolors[$bgcolor], $thold_bgcolors[$bgcolor], $i, 'line' . $row["id"]);
                $i++;
            }
            form_selectable_cell("<a class='linkEditMain' href='" . htmlspecialchars("thold.php?rra=" . $row['rra_id'] . "&view_rrd=" . $row['data_id']) . "'>" . ($row['name'] != '' ? $row['name'] : $row['name_cache'] . " [" . $row['data_source_name'] . ']') . '</a>', $row['id']);
            form_selectable_cell($types[$row['thold_type']], $row["id"]);
            switch ($row['thold_type']) {
                case 0:
                    form_selectable_cell(thold_format_number($row['thold_hi']), $row["id"]);
                    form_selectable_cell(thold_format_number($row['thold_low']), $row["id"]);
                    form_selectable_cell("<i>" . plugin_thold_duration_convert($row['rra_id'], $row['thold_fail_trigger'], 'alert') . "</i>", $row["id"]);
                    form_selectable_cell("", $row["id"]);
                    break;
                case 1:
                    form_selectable_cell(thold_format_number($row['thold_hi']), $row["id"]);
                    form_selectable_cell(thold_format_number($row['thold_low']), $row["id"]);
                    form_selectable_cell("<i>" . plugin_thold_duration_convert($row['rra_id'], $row['bl_fail_trigger'], 'alert') . "</i>", $row["id"]);
                    form_selectable_cell($timearray[$row['bl_ref_time_range'] / 300], $row["id"]);
                    break;
                case 2:
                    form_selectable_cell(thold_format_number($row['time_hi']), $row["id"]);
                    form_selectable_cell(thold_format_number($row['time_low']), $row["id"]);
                    form_selectable_cell("<i>" . $row['time_fail_trigger'] . " Triggers</i>", $row["id"]);
                    form_selectable_cell(plugin_thold_duration_convert($row['rra_id'], $row['time_fail_length'], 'time'), $row["id"]);
                    break;
                default:
                    form_selectable_cell("", $row["id"]);
                    form_selectable_cell("", $row["id"]);
                    form_selectable_cell("", $row["id"]);
                    form_selectable_cell("", $row["id"]);
            }
            form_selectable_cell($row['repeat_alert'] == '' ? '' : plugin_thold_duration_convert($row['rra_id'], $row['repeat_alert'], 'repeat'), $row["id"]);
            form_selectable_cell(thold_format_number($row['lastread']), $row["id"]);
            form_selectable_cell($alertstat, $row["id"]);
            form_selectable_cell($row['thold_enabled'] == 'off' ? "Disabled" : "Enabled", $row["id"]);
            form_checkbox_cell($row['name'], $row['id']);
            form_end_row();
        }
    } else {
        form_alternate_row_color($colors['alternate'], $colors['light'], 0);
        print '<td colspan=12><center>No Thresholds</center></td></tr>';
    }
    print $nav;
    html_end_box(false);
    thold_legend();
    draw_actions_dropdown($thold_actions);
    if (isset($hostid) && $hostid != '') {
        print "<input type=hidden name=hostid value={$hostid}>";
    }
    print "</form>\n";
    include_once $config['include_path'] . '/bottom_footer.php';
}