Example #1
0
function api_device_save($id, $host_template_id, $description, $hostname, $snmp_community, $snmp_version, $snmp_username, $snmp_password, $snmp_port, $snmp_timeout, $disabled)
{
    /* fetch some cache variables */
    if (empty($id)) {
        $_host_template_id = 0;
    } else {
        $_host_template_id = db_fetch_cell("select host_template_id from host where id={$id}");
    }
    $save["id"] = $id;
    $save["host_template_id"] = form_input_validate($host_template_id, "host_template_id", "^[0-9]+\$", false, 3);
    $save["description"] = form_input_validate($description, "description", "", false, 3);
    $save["hostname"] = form_input_validate($hostname, "hostname", "", false, 3);
    $save["snmp_community"] = form_input_validate($snmp_community, "snmp_community", "", true, 3);
    $save["snmp_version"] = form_input_validate($snmp_version, "snmp_version", "", true, 3);
    $save["snmp_username"] = form_input_validate($snmp_username, "snmp_username", "", true, 3);
    $save["snmp_password"] = form_input_validate($snmp_password, "snmp_password", "", true, 3);
    $save["snmp_port"] = form_input_validate($snmp_port, "snmp_port", "^[0-9]+\$", false, 3);
    $save["snmp_timeout"] = form_input_validate($snmp_timeout, "snmp_timeout", "^[0-9]+\$", false, 3);
    $save["disabled"] = form_input_validate($disabled, "disabled", "", true, 3);
    $host_id = 0;
    if (!is_error_message()) {
        $host_id = sql_save($save, "host");
        if ($host_id) {
            raise_message(1);
            /* push out relavant fields to data sources using this host */
            push_out_host($host_id, 0);
            /* the host substitution cache is now stale; purge it */
            kill_session_var("sess_host_cache_array");
            /* update title cache for graph and data source */
            update_data_source_title_cache_from_host($host_id);
            update_graph_title_cache_from_host($host_id);
        } else {
            raise_message(2);
        }
        /* if the user changes the host template, add each snmp query associated with it */
        if ($host_template_id != $_host_template_id && !empty($host_template_id)) {
            $snmp_queries = db_fetch_assoc("select snmp_query_id from host_template_snmp_query where host_template_id={$host_template_id}");
            if (sizeof($snmp_queries) > 0) {
                foreach ($snmp_queries as $snmp_query) {
                    db_execute("replace into host_snmp_query (host_id,snmp_query_id,reindex_method) values ({$host_id}," . $snmp_query["snmp_query_id"] . "," . DATA_QUERY_AUTOINDEX_BACKWARDS_UPTIME . ")");
                    /* recache snmp data */
                    run_data_query($host_id, $snmp_query["snmp_query_id"]);
                }
            }
            $graph_templates = db_fetch_assoc("select graph_template_id from host_template_graph where host_template_id={$host_template_id}");
            if (sizeof($graph_templates) > 0) {
                foreach ($graph_templates as $graph_template) {
                    db_execute("replace into host_graph (host_id,graph_template_id) values ({$host_id}," . $graph_template["graph_template_id"] . ")");
                }
            }
        }
    }
    return $host_id;
}
function form_save()
{
    global $settings_graphs;
    while (list($tab_short_name, $tab_fields) = each($settings_graphs)) {
        while (list($field_name, $field_array) = each($tab_fields)) {
            if (isset($field_array["items"]) && is_array($field_array["items"])) {
                while (list($sub_field_name, $sub_field_array) = each($field_array["items"])) {
                    db_execute("replace into settings_graphs (user_id,name,value) values (" . $_SESSION["sess_user_id"] . ",'{$sub_field_name}', '" . (isset($_POST[$sub_field_name]) ? $_POST[$sub_field_name] : "") . "')");
                }
            } else {
                db_execute("replace into settings_graphs (user_id,name,value) values (" . $_SESSION["sess_user_id"] . ",'{$field_name}', '" . (isset($_POST[$field_name]) ? $_POST[$field_name] : "") . "')");
            }
        }
    }
    /* reset local settings cache so the user sees the new settings */
    kill_session_var("sess_graph_config_array");
    header("Location: " . $_POST["referer"]);
}
Example #3
0
function plugin_monitor_check_config()
{
    global $config;
    // Here we will check to ensure everything is configured
    monitor_check_upgrade();
    include_once $config['library_path'] . '/database.php';
    $r = read_config_option('monitor_refresh');
    $result = db_fetch_assoc("SELECT * FROM settings WHERE name='monitor_refresh'");
    if (!isset($result[0]['name'])) {
        $r = NULL;
    }
    if ($r == '' or $r < 1 or $r > 300) {
        if ($r == '') {
            $sql = "REPLACE INTO settings VALUES ('monitor_refresh','300')";
        } else {
            if ($r == NULL) {
                $sql = "INSERT INTO settings VALUES ('monitor_refresh','300')";
            } else {
                $sql = "UPDATE settings SET value = '300' WHERE name = 'monitor_refresh'";
            }
        }
        $result = db_execute($sql);
        kill_session_var('sess_config_array');
    }
    $r = read_config_option('monitor_width');
    $result = db_fetch_assoc("SELECT * FROM settings WHERE name='monitor_width'");
    if (!isset($result[0]['name'])) {
        $r = NULL;
    }
    if ($r == '' or $r < 1 or $r > 20) {
        if ($r == '') {
            $sql = "REPLACE INTO settings VALUES ('monitor_width','10')";
        } else {
            if ($r == NULL) {
                $sql = "INSERT INTO settings VALUES ('monitor_width','10')";
            } else {
                $sql = "UPDATE settings SET value = '10' WHERE name = 'monitor_width'";
            }
        }
        $result = db_execute($sql) or die(mysql_error());
        kill_session_var('sess_config_array');
    }
    return true;
}
Example #4
0
function form_save() {
	global $settings_graphs;

	while (list($tab_short_name, $tab_fields) = each($settings_graphs)) {
		while (list($field_name, $field_array) = each($tab_fields)) {
			if ((isset($field_array["items"])) && (is_array($field_array["items"]))) {
				while (list($sub_field_name, $sub_field_array) = each($field_array["items"])) {
					db_replace("settings_graphs",array("user_id"=>$_SESSION["sess_user_id"],"name"=>$sub_field_name,"value"=>(isset($_POST[$sub_field_name]) ? $_POST[$sub_field_name] : "")),array("user_id","name"),true);
				}
			}else{
				db_replace("settings_graphs",array("user_id"=>$_SESSION["sess_user_id"],"name"=>$field_name,"value"=>(isset($_POST[$field_name]) ? $_POST[$field_name] : "")),array("user_id","name"),true);
			}
		}
	}

	/* reset local settings cache so the user sees the new settings */
	kill_session_var("sess_graph_config_array");

	header("Location: " . $_POST["referer"]);
}
Example #5
0
function save() {

	$save = array();

	$save["id"] = array("type" => DB_TYPE_INTEGER, "value" => $_SESSION["sess_user_id"]);
	$save["current_theme"] = array("type" => DB_TYPE_STRING, "value" => form_input_validate($_POST["current_theme"], "current_theme", "", true, 3));

	if (!is_error_message()) {
		$user_id = api_user_save($save);

		if ($user_id) {
			/* user saved */
			raise_message(1);
			/* reset local settings cache so the user sees the new settings */
			kill_session_var("sess_current_theme");
		}else{
			/* error saving */
			raise_message(2);
		}
	}

	header("Location: user_settings.php");

}
Example #6
0
function form_save()
{
    global $settings_graphs, $cnn_id;
    while (list($tab_short_name, $tab_fields) = each($settings_graphs)) {
        while (list($field_name, $field_array) = each($tab_fields)) {
            if (isset($field_array["items"]) && is_array($field_array["items"])) {
                while (list($sub_field_name, $sub_field_array) = each($field_array["items"])) {
                    if (isset($_POST[$sub_field_name])) {
                        $value = $cnn_id->qstr(get_request_var_post($sub_field_name));
                        db_execute("REPLACE INTO settings_graphs (user_id,name,value) values (" . $_SESSION["sess_user_id"] . ",'{$sub_field_name}', " . $value . ")");
                    }
                }
            } else {
                if (isset($_POST[$field_name])) {
                    $value = $cnn_id->qstr($_POST[$field_name]);
                    db_execute("REPLACE INTO settings_graphs (user_id,name,value) values (" . $_SESSION["sess_user_id"] . ",'{$field_name}', " . $value . ")");
                }
            }
        }
    }
    /* reset local settings cache so the user sees the new settings */
    kill_session_var("sess_graph_config_array");
    header("Location: " . $_SESSION["graph_settings_referer"]);
}
Example #7
0
function debug_log_clear($type = "") {
	if ($type == "") {
		kill_session_var("debug_log");
	}else{
		if (isset($_SESSION["debug_log"])) {
			unset($_SESSION["debug_log"][$type]);
		}
	}
}
Example #8
0
function utilities_view_poller_cache()
{
    global $poller_actions;
    define("MAX_DISPLAY_PAGES", 21);
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_request("host_id"));
    input_validate_input_number(get_request_var_request("page"));
    input_validate_input_number(get_request_var_request("poller_action"));
    /* ==================================================== */
    /* clean up search filter */
    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 sort direction */
    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_poller_current_page");
        kill_session_var("sess_poller_host_id");
        kill_session_var("sess_poller_poller_action");
        kill_session_var("sess_poller_filter");
        unset($_REQUEST["page"]);
        unset($_REQUEST["filter"]);
        unset($_REQUEST["host_id"]);
        unset($_REQUEST["poller_action"]);
    }
    if (!empty($_SESSION["sess_poller_action"]) && !empty($_REQUEST["poller_action"])) {
        if ($_SESSION["sess_poller_poller_action"] != $_REQUEST["poller_action"]) {
            $_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_poller_current_page", "1");
    load_current_session_value("host_id", "sess_poller_host_id", "-1");
    load_current_session_value("poller_action", "sess_poller_poller_action", "-1");
    load_current_session_value("filter", "sess_poller_filter", "");
    load_current_session_value("sort_column", "sess_poller_sort_column", "data_template_data.name_cache");
    load_current_session_value("sort_direction", "sess_poller_sort_direction", "ASC");
    $_REQUEST['page_referrer'] = 'view_poller_cache';
    load_current_session_value('page_referrer', 'page_referrer', 'view_poller_cache');
    ?>
	<script type="text/javascript">
	<!--

	function applyPItemFilterChange(objForm) {
		strURL = '?poller_action=' + objForm.poller_action.value;
		strURL = strURL + '&host_id=' + objForm.host_id.value;
		strURL = strURL + '&filter=' + objForm.filter.value;
		strURL = strURL + '&action=view_poller_cache';
		document.location = strURL;
	}

	-->
	</script>
	<?php 
    html_start_box("<strong>Poller Cache Items</strong>", "100%", "", "3", "center", "");
    ?>
	<tr class='even noprint'>
		<td>
		<form name="form_pollercache" action="utilities.php">
			<table cellpadding="0" cellspacing="0">
				<tr>
					<td nowrap style='white-space: nowrap;' width="50">
						Host:&nbsp;
					</td>
					<td width="1">
						<select name="host_id" onChange="applyPItemFilterChange(document.form_pollercache)">
							<option value="-1"<?php 
    if (get_request_var_request("host_id") == "-1") {
        ?>
 selected<?php 
    }
    ?>
>Any</option>
							<option value="0"<?php 
    if (get_request_var_request("host_id") == "0") {
        ?>
 selected<?php 
    }
    ?>
>None</option>
							<?php 
    $hosts = db_fetch_assoc("select id,description,hostname from host order by description");
    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 ">" . $host["description"] . "</option>\n";
        }
    }
    ?>
						</select>
					</td>
					<td nowrap style='white-space: nowrap;' width="50">
						&nbsp;Action:&nbsp;
					</td>
					<td width="1">
						<select name="poller_action" onChange="applyPItemFilterChange(document.form_pollercache)">
							<option value="-1"<?php 
    if (get_request_var_request("poller_action") == '-1') {
        ?>
 selected<?php 
    }
    ?>
>Any</option>
							<option value="0"<?php 
    if (get_request_var_request("poller_action") == '0') {
        ?>
 selected<?php 
    }
    ?>
>SNMP</option>
							<option value="1"<?php 
    if (get_request_var_request("poller_action") == '1') {
        ?>
 selected<?php 
    }
    ?>
>Script</option>
							<option value="2"<?php 
    if (get_request_var_request("poller_action") == '2') {
        ?>
 selected<?php 
    }
    ?>
>Script Server</option>
						</select>
					</td>
					<td nowrap style='white-space: nowrap;' width="50">
						&nbsp;Search:&nbsp;
					</td>
					<td width="1">
						<input type="text" name="filter" size="40" value="<?php 
    print htmlspecialchars(get_request_var_request("filter"));
    ?>
">
					</td>
					<td nowrap style='white-space: nowrap;'>
						&nbsp;<input type="submit" name="go" 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'>
			<input type='hidden' name='action' value='view_poller_cache'>
		</form>
		</td>
	</tr>
	<?php 
    html_end_box();
    /* form the 'where' clause for our main sql query */
    $sql_where = "WHERE poller_item.local_data_id=data_template_data.local_data_id";
    if (get_request_var_request("poller_action") != "-1") {
        $sql_where .= " AND poller_item.action='" . get_request_var_request("poller_action") . "'";
    }
    if (get_request_var_request("host_id") == "-1") {
        /* Show all items */
    } elseif (get_request_var_request("host_id") == "0") {
        $sql_where .= " AND poller_item.host_id=0";
    } elseif (!empty($_REQUEST["host_id"])) {
        $sql_where .= " AND poller_item.host_id=" . get_request_var_request("host_id");
    }
    if (strlen(get_request_var_request("filter"))) {
        $sql_where .= " AND (data_template_data.name_cache LIKE '%%" . get_request_var_request("filter") . "%%'\n\t\t\tOR host.description LIKE '%%" . get_request_var_request("filter") . "%%'\n\t\t\tOR poller_item.arg1 LIKE '%%" . get_request_var_request("filter") . "%%'\n\t\t\tOR poller_item.hostname LIKE '%%" . get_request_var_request("filter") . "%%'\n\t\t\tOR poller_item.rrd_path  LIKE '%%" . get_request_var_request("filter") . "%%')";
    }
    html_start_box("", "100%", "", "3", "center", "");
    $total_rows = db_fetch_cell("SELECT\n\t\tCOUNT(*)\n\t\tFROM data_template_data\n\t\tRIGHT JOIN (poller_item\n\t\tLEFT JOIN host\n\t\tON poller_item.host_id=host.id)\n\t\tON data_template_data.local_data_id=poller_item.local_data_id\n\t\t{$sql_where}");
    $poller_sql = "SELECT\n\t\tpoller_item.*,\n\t\tdata_template_data.name_cache,\n\t\thost.description\n\t\tFROM data_template_data\n\t\tRIGHT JOIN (poller_item\n\t\tLEFT JOIN host\n\t\tON poller_item.host_id=host.id)\n\t\tON data_template_data.local_data_id=poller_item.local_data_id\n\t\t{$sql_where}\n\t\tORDER BY " . get_request_var_request("sort_column") . " " . get_request_var_request("sort_direction") . ", action ASC\n\t\tLIMIT " . read_config_option("num_rows_data_source") * (get_request_var_request("page") - 1) . "," . read_config_option("num_rows_data_source");
    $poller_cache = db_fetch_assoc($poller_sql);
    $nav = html_nav_bar("utilities.php?action=view_poller_cache&host_id=" . get_request_var_request("host_id") . "&poller_action=" . get_request_var_request("poller_action"), MAX_DISPLAY_PAGES, get_request_var_request("page"), read_config_option("num_rows_data_source"), $total_rows, 3);
    print $nav;
    $display_text = array("data_template_data.name_cache" => array("Data Source Name", "ASC"), "nosort" => array("Details", "ASC"));
    html_header_sort($display_text, get_request_var_request("sort_column"), get_request_var_request("sort_direction"));
    $i = 0;
    if (sizeof($poller_cache) > 0) {
        foreach ($poller_cache as $item) {
            form_alternate_row();
            ?>
			<td width="375">
				<a class="linkEditMain" href="<?php 
            print htmlspecialchars("data_sources.php?action=ds_edit&id=" . $item["local_data_id"]);
            ?>
"><?php 
            print strlen(get_request_var_request("filter")) ? preg_replace("/(" . preg_quote(get_request_var_request("filter"), "/") . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", $item["name_cache"]) : $item["name_cache"];
            ?>
</a>
			</td>

			<td>
			<?php 
            if ($item["action"] == 0) {
                if ($item["snmp_version"] != 3) {
                    $details = "SNMP Version: " . $item["snmp_version"] . ", " . "Community: " . $item["snmp_community"] . ", " . "OID: " . (strlen(get_request_var_request("filter")) ? preg_replace("/(" . preg_quote(get_request_var_request("filter"), "/") . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", $item["arg1"]) : $item["arg1"]);
                } else {
                    $details = "SNMP Version: " . $item["snmp_version"] . ", " . "User: "******"snmp_username"] . ", OID: " . $item["arg1"];
                }
            } elseif ($item["action"] == 1) {
                $details = "Script: " . (strlen(get_request_var_request("filter")) ? preg_replace("/(" . preg_quote(get_request_var_request("filter"), "/") . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", $item["arg1"]) : $item["arg1"]);
            } else {
                $details = "Script Server: " . (strlen(get_request_var_request("filter")) ? preg_replace("/(" . preg_quote(get_request_var_request("filter"), "/") . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", $item["arg1"]) : $item["arg1"]);
            }
            print $details;
            ?>
			</td>
		</tr>
		<?php 
            form_alternate_row();
            ?>
			<td>
			</td>
			<td>
				RRD: <?php 
            print $item["rrd_path"];
            ?>
			</td>
		</tr>
		<?php 
            $i++;
        }
    }
    print $nav;
    html_end_box();
}
function import()
{
    global $colors, $hash_type_names;
    ?>
	<form method="post" action="templates_import.php" enctype="multipart/form-data">
	<?php 
    if (isset($_SESSION["import_debug_info"]) && is_array($_SESSION["import_debug_info"])) {
        html_start_box("<strong>Import Results</strong>", "100%", "aaaaaa", "3", "center", "");
        print "<tr bgcolor='#" . $colors["form_alternate1"] . "'><td><p class='textArea'>Cacti has imported the following items:</p>";
        while (list($type, $type_array) = each($_SESSION["import_debug_info"])) {
            print "<p><strong>" . $hash_type_names[$type] . "</strong></p>";
            while (list($index, $vals) = each($type_array)) {
                if ($vals["result"] == "success") {
                    $result_text = "<span style='color: green;'>[success]</span>";
                } else {
                    $result_text = "<span style='color: red;'>[fail]</span>";
                }
                if ($vals["type"] == "update") {
                    $type_text = "<span style='color: gray;'>[update]</span>";
                } else {
                    $type_text = "<span style='color: blue;'>[new]</span>";
                }
                print "<span style='font-family: monospace;'>{$result_text} " . $vals["title"] . " {$type_text}</span><br>\n";
                $dep_text = "";
                $there_are_dep_errors = false;
                if (isset($vals["dep"]) && sizeof($vals["dep"]) > 0) {
                    while (list($dep_hash, $dep_status) = each($vals["dep"])) {
                        if ($dep_status == "met") {
                            $dep_status_text = "<span style='color: navy;'>Found Dependency:</span>";
                        } else {
                            $dep_status_text = "<span style='color: red;'>Unmet Dependency:</span>";
                            $there_are_dep_errors = true;
                        }
                        $dep_text .= "<span style='font-family: monospace;'>&nbsp;&nbsp;&nbsp;+ {$dep_status_text} " . hash_to_friendly_name($dep_hash, true) . "</span><br>\n";
                    }
                }
                /* only print out dependency details if they contain errors; otherwise it would get too long */
                if ($there_are_dep_errors == true) {
                    print $dep_text;
                }
            }
        }
        print "</td></tr>";
        html_end_box();
        kill_session_var("import_debug_info");
    }
    html_start_box("<strong>Import Templates</strong>", "100%", $colors["header"], "3", "center", "");
    form_alternate_row_color($colors["form_alternate1"], $colors["form_alternate2"], 0);
    ?>
		<td width="50%">
			<font class="textEditTitle">Import Template from Local File</font><br>
			If the XML file containing template data is located on your local machine, select it here.
		</td>
		<td>
			<input type="file" name="import_file">
		</td>
	</tr>

	<?php 
    form_alternate_row_color($colors["form_alternate1"], $colors["form_alternate2"], 1);
    ?>
		<td width="50%">
			<font class="textEditTitle">Import Template from Text</font><br>
			If you have the XML file containing template data as text, you can paste it into this box to
			import it.
		</td>
		<td>
			<?php 
    form_text_area("import_text", "", "10\t", "50", "");
    ?>
		</td>
	</tr>

	<?php 
    form_alternate_row_color($colors["form_alternate1"], $colors["form_alternate2"], 0);
    ?>
		<td width="50%">
			<font class="textEditTitle">Import RRA Settings</font><br>
			Choose whether to allow Cacti to import custom RRA settings from imported templates or whether to use the defaults for this installation.
		</td>
		<td>
			<?php 
    form_radio_button("import_rra", 1, 1, "Use defaults for this installation (Recommended)", 1);
    echo "<br />";
    form_radio_button("import_rra", 1, 2, "Use custom RRA settings from the template", 1);
    ?>
		</td>
	</tr>

	<?php 
    form_hidden_box("save_component_import", "1", "");
    html_end_box();
    form_save_button("templates_import.php", "save");
}
Example #10
0
function item_edit() {
	global $colors, $struct_graph_item, $graph_item_types, $consolidation_functions;

	/* ================= input validation ================= */
	input_validate_input_number(get_request_var_request("id"));
	input_validate_input_number(get_request_var_request("local_graph_id"));
	input_validate_input_number(get_request_var_request("host_id"));
	/* ==================================================== */

	/* if the user pushed the 'clear' button */
	if (isset($_REQUEST["clear_x"])) {
		kill_session_var("sess_ds_host_id");

		unset($_REQUEST["host_id"]);
	}

	/* remember these search fields in session vars so we don't have to keep passing them around */
	load_current_session_value("filter", "sess_ds_filter", "");
	load_current_session_value("host_id", "sess_ds_host_id", "-1");

	$host = db_fetch_row("select hostname from host where id=" . $_REQUEST["host_id"]);

	html_start_box("<strong>Data Source by Host</strong> [host: " . (empty($host["hostname"]) ? "No Host" : $host["hostname"]) . "]", "98%", $colors["header"], "3", "center", "");

	include("./include/html/inc_graph_items_filter_table.php");

	html_end_box();

	if ($_REQUEST["host_id"] == "-1") {
		$sql_where = "";
	}elseif ($_REQUEST["host_id"] == "0") {
		$sql_where = " and data_local.host_id=0";
	}elseif (!empty($_REQUEST["host_id"])) {
		$sql_where = " and data_local.host_id=" . $_REQUEST["host_id"];
	}

	if (!empty($_REQUEST["id"])) {
		$template_item = db_fetch_row("select * from graph_templates_item where id=" . $_REQUEST["id"]);
		$host_id = db_fetch_cell("select host_id from graph_local where id=" . $_REQUEST["local_graph_id"]);
	}

	$header_label = "[edit graph: " . db_fetch_cell("select title_cache from graph_templates_graph where local_graph_id=" . $_REQUEST["local_graph_id"]) . "]";

	html_start_box("<strong>Graph Items</strong> $header_label", "98%", $colors["header"], "3", "center", "");

	/* by default, select the LAST DS chosen to make everyone's lives easier */
	if (!empty($_REQUEST["local_graph_id"])) {
		$default = db_fetch_row("select task_item_id from graph_templates_item where local_graph_id=" . $_REQUEST["local_graph_id"] . " order by sequence DESC");

		if (sizeof($default) > 0) {
			$struct_graph_item["task_item_id"]["default"] = $default["task_item_id"];
		}else{
			$struct_graph_item["task_item_id"]["default"] = 0;
		}

		/* modifications to the default graph items array */
		$struct_graph_item["task_item_id"]["sql"] = "select
			CONCAT_WS('',data_template_data.name_cache,' (',data_template_rrd.data_source_name,')') as name,
			data_template_rrd.id
			from data_template_data,data_template_rrd,data_local
			left join host on data_local.host_id=host.id
			where data_template_rrd.local_data_id=data_local.id
			and data_template_data.local_data_id=data_local.id
			" . (((!empty($host_id)) || (!empty($_REQUEST["host_id"]))) ? (!empty($host_id) ? " and data_local.host_id=$host_id" : " and data_local.host_id=" . $_REQUEST["host_id"]) : "") . "
			order by name";
	}

	$form_array = array();

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

		$form_array[$field_name]["value"] = (isset($template_item) ? $template_item[$field_name] : "");
		$form_array[$field_name]["form_id"] = (isset($template_item) ? $template_item["id"] : "0");

	}

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

	form_hidden_box("local_graph_id", $_REQUEST["local_graph_id"], "0");
	form_hidden_box("graph_template_item_id", (isset($template_item) ? $template_item["id"] : "0"), "");
	form_hidden_box("local_graph_template_item_id", (isset($template_item) ? $template_item["local_graph_template_item_id"] : "0"), "");
	form_hidden_box("graph_template_id", (isset($template_item) ? $template_item["graph_template_id"] : "0"), "");
	form_hidden_box("sequence", (isset($template_item) ? $template_item["sequence"] : "0"), "");
	form_hidden_box("_graph_type_id", (isset($template_item) ? $template_item["graph_type_id"] : "0"), "");
	form_hidden_box("save_component_item", "1", "");

	html_end_box();

	form_save_button("graphs.php?action=graph_edit&id=" . $_REQUEST["local_graph_id"]);
}
Example #11
0
File: host.php Project: MrWnn/cacti
function host()
{
    global $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('rows'));
    /* ==================================================== */
    /* clean up search string */
    if (isset($_REQUEST['filter'])) {
        $_REQUEST['filter'] = sanitize_search_string(get_request_var_request('filter'));
    }
    /* clean up sort_column */
    if (isset($_REQUEST['sort_column'])) {
        $_REQUEST['sort_column'] = sanitize_search_string(get_request_var_request('sort_column'));
    }
    /* clean up search string */
    if (isset($_REQUEST['sort_direction'])) {
        $_REQUEST['sort_direction'] = sanitize_search_string(get_request_var_request('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_default_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['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('rows', 'sess_default_rows', read_config_option('num_rows_table'));
    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['rows'] == -1) {
        $_REQUEST['rows'] = read_config_option('num_rows_table');
    }
    ?>
	<script type="text/javascript">
	<!--

	function applyFilter() {
		strURL = 'host.php?host_status=' + $('#host_status').val();
		strURL = strURL + '&host_template_id=' + $('#host_template_id').val();
		strURL = strURL + '&rows=' + $('#rows').val();
		strURL = strURL + '&filter=' + $('#filter').val();
		strURL = strURL + '&page=' + $('#page').val();
		strURL = strURL + '&header=false';
		$.get(strURL, function(data) {
			$('#main').html(data);
			applySkin();
		});
	}

	function clearFilter() {
		strURL = 'host.php?clear_x=1&header=false';
		$.get(strURL, function(data) {
			$('#main').html(data);
			applySkin();
		});
	}

	$(function(data) {
		$('#refresh').click(function() {
			applyFilter();
		});

		$('#clear').click(function() {
			clearFilter();
		});

		$('#form_devices').submit(function(event) {
			event.preventDefault();
			applyFilter();
		});
	});

	-->
	</script>
	<?php 
    html_start_box('<strong>Devices</strong>', '100%', '', '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')));
    ?>
	<tr class='even noprint'>
		<td>
		<form id='form_devices' name="form_devices" action="host.php">
			<table cellpadding="2" cellspacing="0">
				<tr>
					<td width='50'>
						Search
					</td>
					<td>
						<input id='filter' type="text" name="filter" size="25" value="<?php 
    print htmlspecialchars(get_request_var_request('filter'));
    ?>
" onChange='applyFilter()'>
					</td>
					<td>
						Template
					</td>
					<td>
						<select id='host_template_id' name="host_template_id" onChange="applyFilter()">
							<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 
    $host_templates = db_fetch_assoc('SELECT id, name FROM host_template ORDER BY name');
    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>
						Status
					</td>
					<td>
						<select id='host_status' name="host_status" onChange="applyFilter()">
							<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>
						Devices
					</td>
					<td>
						<select id='rows' name="rows" onChange="applyFilter()">
							<?php 
    if (sizeof($item_rows) > 0) {
        foreach ($item_rows as $key => $value) {
            print "<option value='" . $key . "'";
            if (get_request_var_request('rows') == $key) {
                print ' selected';
            }
            print '>' . htmlspecialchars($value) . "</option>\n";
        }
    }
    ?>
						</select>
					</td>
					<td>
						<input type="button" id='refresh' value="Go" title="Set/Refresh Filters">
					</td>
					<td>
						<input type="button" id='clear' name="clear_x" value="Clear" title="Clear Filters">
					</td>
				</tr>
			</table>
			<input type='hidden' id='page' name='page' value='<?php 
    print $_REQUEST['page'];
    ?>
'>
		</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');
    }
    /* print checkbox form for validation */
    print "<form name='chk' method='post' action='host.php'>\n";
    html_start_box('', '100%', '', '3', 'center', '');
    $total_rows = db_fetch_cell("SELECT\n\t\tCOUNT(host.id)\n\t\tFROM host\n\t\t{$sql_where}");
    $sortby = get_request_var_request('sort_column');
    if ($sortby == 'hostname') {
        $sortby = 'INET_ATON(hostname)';
    }
    $sql_query = "SELECT host.*, graphs, data_sources\n\t\tFROM host\n\t\tLEFT JOIN (SELECT host_id, COUNT(*) AS graphs FROM graph_local GROUP BY host_id) AS gl\n\t\tON host.id=gl.host_id\n\t\tLEFT JOIN (SELECT host_id, COUNT(*) AS data_sources FROM data_local GROUP BY host_id) AS dl\n\t\tON host.id=dl.host_id\n\t\t{$sql_where}\n\t\tGROUP BY host.id\n\t\tORDER BY " . $sortby . ' ' . get_request_var_request('sort_direction') . '
		LIMIT ' . get_request_var_request('rows') * (get_request_var_request('page') - 1) . ',' . get_request_var_request('rows');
    $hosts = db_fetch_assoc($sql_query);
    $nav = html_nav_bar('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'), MAX_DISPLAY_PAGES, get_request_var_request('page'), get_request_var_request('rows'), $total_rows, 13, 'Devices', 'page', 'main');
    print $nav;
    $display_text = array('description' => array('display' => 'Device Description', 'align' => 'left', 'sort' => 'ASC', 'tip' => 'The name by which this Device will be referred to.'), 'hostname' => array('display' => 'Hostname', 'align' => 'left', 'sort' => 'ASC', 'tip' => 'Either an IP address, or hostname.  If a hostname, it must be resolvable by either DNS, or from your hosts file.'), 'id' => array('display' => 'ID', 'align' => 'right', 'sort' => 'ASC', 'tip' => 'The internal database ID for this Device.  Useful when performing automation or debugging.'), 'graphs' => array('display' => 'Graphs', 'align' => 'right', 'sort' => 'ASC', 'tip' => 'The total number of Graphs generated from this Device.'), 'data_sources' => array('display' => 'Data Sources', 'align' => 'right', 'sort' => 'ASC', 'tip' => 'The total number of Data Sources generated from this Device.'), 'status' => array('display' => 'Status', 'align' => 'center', 'sort' => 'ASC', 'tip' => 'The monitoring status of the Device based upon ping results.  If this Device is a special type Device, by using the hostname "localhost", or due to the setting to not perform an Availability Check, it will always remain Up.  When using cmd.php data collector, a Device with no Graphs, is not pinged by the data collector and will remain in an "Unknown" state.'), 'status_rec_date' => array('display' => 'In State', 'align' => 'right', 'sort' => 'ASC', 'tip' => 'The amount of time that this Device has been in its current state.'), 'snmp_sysUpTimeInstance' => array('display' => 'Uptime', 'align' => 'right', 'sort' => 'ASC', 'tip' => 'The current amount of time that the host has been up.'), 'polling_time' => array('display' => 'Poll Time', 'align' => 'right', 'sort' => 'ASC', 'tip' => 'The the amount of time it takes to collect data from this Device.'), 'cur_time' => array('display' => 'Current (ms)', 'align' => 'right', 'sort' => 'DESC', 'tip' => 'The current ping time in milliseconds to reach the Device.'), 'avg_time' => array('display' => 'Average (ms)', 'align' => 'right', 'sort' => 'DESC', 'tip' => 'The average ping time in milliseconds to reach the Device since the counters were cleared for this Device.'), 'availability' => array('display' => 'Availability', 'align' => 'right', 'sort' => 'ASC', 'tip' => 'The availability percentage based upon ping results insce the counters were cleared for this Device.'));
    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) {
            if ($host['disabled'] == '' && ($host['status'] == HOST_RECOVERING || $host['status'] == HOST_UP) && ($host['availability_method'] != AVAIL_NONE && $host['availability_method'] != AVAIL_PING)) {
                $snmp_uptime = $host['snmp_sysUpTimeInstance'];
                $days = intval($snmp_uptime / (60 * 60 * 24 * 100));
                $remainder = $snmp_uptime % (60 * 60 * 24 * 100);
                $hours = intval($remainder / (60 * 60 * 100));
                $remainder = $remainder % (60 * 60 * 100);
                $minutes = intval($remainder / (60 * 100));
                $uptime = "{$days} d {$hours} h {$minutes} m";
            } else {
                $uptime = "N/A";
            }
            form_alternate_row('line' . $host['id'], true);
            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 class='filteredValue'>\\1</span>", htmlspecialchars($host['description'])) : htmlspecialchars($host['description'])) . '</a>', $host['id']);
            form_selectable_cell(strlen(get_request_var_request('filter')) ? preg_replace('/(' . preg_quote(get_request_var_request('filter'), '/') . ')/i', "<span class='filteredValue'>\\1</span>", htmlspecialchars($host['hostname'])) : htmlspecialchars($host['hostname']), $host['id']);
            form_selectable_cell($host['id'], $host['id'], '', 'text-align:right');
            form_selectable_cell(number_format($host['graphs']), $host['id'], '', 'text-align:right');
            form_selectable_cell(number_format($host['data_sources']), $host['id'], '', 'text-align:right');
            form_selectable_cell(get_colored_device_status($host['disabled'] == 'on' ? true : false, $host['status']), $host['id'], '', 'text-align:center');
            form_selectable_cell(get_timeinstate($host), $host['id'], '', 'text-align:right');
            form_selectable_cell($uptime, $host['id'], '', 'text-align:right');
            form_selectable_cell(round($host['polling_time'], 2), $host['id'], '', 'text-align:right');
            form_selectable_cell(round($host['cur_time'], 2), $host['id'], '', 'text-align:right');
            form_selectable_cell(round($host['avg_time'], 2), $host['id'], '', 'text-align:right');
            form_selectable_cell(round($host['availability'], 2) . ' %', $host['id'], '', 'text-align:right');
            form_checkbox_cell($host['description'], $host['id']);
            form_end_row();
        }
        /* put the nav bar on the bottom as well */
        print $nav;
    } else {
        print "<tr class='tableRow'><td colspan='11'><em>No Devices</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";
}
Example #12
0
/** function syslog_request_validation()
 *  This is a generic funtion for this page that makes sure that
 *  we have a good request.  We want to protect against people who
 *  like to create issues with Cacti.
*/
function syslog_request_validation($current_tab)
{
    global $title, $colors, $rows, $config, $reset_multi;
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_request("rows"));
    input_validate_input_number(get_request_var_request("removal"));
    input_validate_input_number(get_request_var_request("refresh"));
    input_validate_input_number(get_request_var_request("page"));
    input_validate_input_number(get_request_var_request("trimval"));
    input_validate_input_number(get_request_var_request("id"));
    /* ==================================================== */
    /* clean up filter string */
    if (isset($_REQUEST["filter"])) {
        $_REQUEST["filter"] = sanitize_search_string(get_request_var_request("filter"));
    }
    /* clean up facility string */
    if (isset($_REQUEST["efacility"])) {
        $_REQUEST["efacility"] = sanitize_search_string(get_request_var_request("efacility"));
    }
    /* clean up priority string */
    if (isset($_REQUEST["elevel"])) {
        $_REQUEST["elevel"] = sanitize_search_string(get_request_var_request("elevel"));
    }
    /* clean up sort solumn */
    if (isset($_REQUEST["sort_column"])) {
        $_REQUEST["sort_column"] = sanitize_search_string(get_request_var_request("sort_column"));
    }
    /* clean up sort direction */
    if (isset($_REQUEST["sort_direction"])) {
        $_REQUEST["sort_direction"] = sanitize_search_string(get_request_var_request("sort_direction"));
    }
    if ($current_tab != "alerts" && isset($_REQUEST["host"]) && $_REQUEST["host"][0] == -1) {
        kill_session_var("sess_syslog_" . $current_tab . "_hosts");
        unset($_REQUEST["host"]);
    }
    api_plugin_hook_function('syslog_request_val');
    /* if the user pushed the 'clear' button */
    if (isset($_REQUEST["button_clear_x"])) {
        kill_session_var("sess_syslog_" . $current_tab . "_hosts");
        kill_session_var("sess_syslog_" . $current_tab . "_rows");
        kill_session_var("sess_syslog_" . $current_tab . "_trimval");
        kill_session_var("sess_syslog_" . $current_tab . "_removal");
        kill_session_var("sess_syslog_" . $current_tab . "_refresh");
        kill_session_var("sess_syslog_" . $current_tab . "_page");
        kill_session_var("sess_syslog_" . $current_tab . "_filter");
        kill_session_var("sess_syslog_" . $current_tab . "_efacility");
        kill_session_var("sess_syslog_" . $current_tab . "_elevel");
        kill_session_var("sess_syslog__id");
        kill_session_var("sess_syslog_" . $current_tab . "_sort_column");
        kill_session_var("sess_syslog_" . $current_tab . "_sort_direction");
        $_REQUEST["page"] = 1;
        unset($_REQUEST["hosts"]);
        unset($_REQUEST["rows"]);
        unset($_REQUEST["trimval"]);
        unset($_REQUEST["removal"]);
        unset($_REQUEST["refresh"]);
        unset($_REQUEST["page"]);
        unset($_REQUEST["filter"]);
        unset($_REQUEST["efacility"]);
        unset($_REQUEST["elevel"]);
        unset($_REQUEST["id"]);
        unset($_REQUEST["sort_column"]);
        unset($_REQUEST["sort_direction"]);
        $reset_multi = true;
    } else {
        /* if any of the settings changed, reset the page number */
        $changed = 0;
        $changed += syslog_check_changed("hosts", "sess_syslog_" . $current_tab . "_hosts");
        $changed += syslog_check_changed("predefined_timespan", "sess_current_timespan");
        $changed += syslog_check_changed("date1", "sess_current_date1");
        $changed += syslog_check_changed("date2", "sess_current_date2");
        $changed += syslog_check_changed("rows", "sess_syslog_" . $current_tab . "_rows");
        $changed += syslog_check_changed("removal", "sess_syslog_" . $current_tab . "_removal");
        $changed += syslog_check_changed("refresh", "sess_syslog_" . $current_tab . "_refresh");
        $changed += syslog_check_changed("filter", "sess_syslog_" . $current_tab . "_filter");
        $changed += syslog_check_changed("efacility", "sess_syslog_" . $current_tab . "_efacility");
        $changed += syslog_check_changed("elevel", "sess_syslog_" . $current_tab . "_elevel");
        $changed += syslog_check_changed("sort_column", "sess_syslog_" . $current_tab . "_sort_column");
        $changed += syslog_check_changed("sort_direction", "sess_syslog_" . $current_tab . "_sort_direction");
        if ($changed) {
            $_REQUEST["page"] = "1";
        }
        $reset_multi = false;
    }
    /* remember search fields in session vars */
    load_current_session_value("page", "sess_syslog_" . $current_tab . "_page", "1");
    load_current_session_value("rows", "sess_syslog_" . $current_tab . "_rows", read_config_option("num_rows_syslog"));
    load_current_session_value("trimval", "sess_syslog_" . $current_tab . "_trimval", "75");
    load_current_session_value("refresh", "sess_syslog_" . $current_tab . "_refresh", read_config_option("syslog_refresh"));
    load_current_session_value("removal", "sess_syslog_" . $current_tab . "_removal", "-1");
    load_current_session_value("filter", "sess_syslog_" . $current_tab . "_filter", "");
    load_current_session_value("efacility", "sess_syslog_" . $current_tab . "_efacility", "0");
    load_current_session_value("elevel", "sess_syslog_" . $current_tab . "_elevel", "0");
    load_current_session_value("hosts", "sess_syslog_" . $current_tab . "_hosts", "0");
    load_current_session_value("sort_column", "sess_syslog_" . $current_tab . "_sort_column", "logtime");
    load_current_session_value("sort_direction", "sess_syslog_" . $current_tab . "_sort_direction", "DESC");
    if (isset($_REQUEST["host"])) {
        $_SESSION["sess_syslog_" . $current_tab . "_hosts"] = $_REQUEST["host"];
    } else {
        if (isset($_SESSION["sess_syslog_" . $current_tab . "_hosts"])) {
            $_REQUEST["host"] = $_SESSION["sess_syslog_" . $current_tab . "_hosts"];
        } else {
            $_REQUEST["host"][0] = "0";
            /* default value */
        }
    }
}
Example #13
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 
    html_start_box("<strong>Devices</strong>", "100%", $colors["header"], "3", "center", "host.php?action=edit&host_template_id=" . get_request_var_request("host_template_id") . "&host_status=" . get_request_var_request("host_status"));
    ?>
	<tr bgcolor="<?php 
    print $colors["panel"];
    ?>
">
		<form name="form_devices">
		<td>
			<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 
    $host_templates = db_fetch_assoc("select id,name from host_template order by name");
    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 ">" . $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 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 ">" . $value . "</option>\n";
        }
    }
    ?>
						</select>
					</td>
					<td nowrap>
						&nbsp;<input type="image" src="images/button_go.gif" alt="Go" border="0" align="absmiddle">
						<input type="image" src="images/button_clear.gif" name="clear" alt="Clear" border="0" align="absmiddle">
					</td>
				</tr>
			</table>
		</td>
		<input type='hidden' name='page' value='1'>
		</form>
	</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");
    }
    html_start_box("", "100%", $colors["header"], "3", "center", "");
    $total_rows = db_fetch_cell("select\n\t\tCOUNT(host.id)\n\t\tfrom host\n\t\t{$sql_where}");
    $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");
    $sql_query = "SELECT *\n\t\tFROM host\n\t\t{$sql_where}\n\t\tORDER BY " . $sortby . " " . get_request_var_request("sort_direction") . "\n\t\tLIMIT " . get_request_var_request("host_rows") * (get_request_var_request("page") - 1) . "," . get_request_var_request("host_rows");
    $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"] . "'>\n\t\t\t<td colspan='11'>\n\t\t\t\t<table width='100%' cellspacing='0' cellpadding='0' border='0'>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td align='left' class='textHeaderDark'>\n\t\t\t\t\t\t\t<strong>&lt;&lt; ";
    if (get_request_var_request("page") > 1) {
        $nav .= "<a class='linkOverDark' href='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>\n\t\t\t\t\t\t</td>\n\n\t\t\t\t\t\t<td align='center' class='textHeaderDark'>\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}]\n\t\t\t\t\t\t</td>\n\n\t\t\t\t\t\t<td align='right' class='textHeaderDark'>\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='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>\n\t\t\t\t\t\t</td>\n\n\t\t\t\t\t</tr>\n\t\t\t\t</table>\n\t\t\t</td>\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_event_count" => array("Event Count", "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"));
    $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='host.php?action=edit&id=" . $host["id"] . "'>" . (strlen(get_request_var_request("filter")) ? eregi_replace("(" . preg_quote(get_request_var_request("filter")) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $host["description"]) : $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"]);
            form_selectable_cell(get_colored_device_status($host["disabled"] == "on" ? true : false, $host["status"]), $host["id"]);
            form_selectable_cell(round($host["status_event_count"], 2), $host["id"]);
            form_selectable_cell(strlen(get_request_var_request("filter")) ? eregi_replace("(" . preg_quote(get_request_var_request("filter")) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $host["hostname"]) : $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";
}
Example #14
0
function template()
{
    global $colors, $graph_actions;
    /* ================= input validation ================= */
    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_template_current_page");
        kill_session_var("sess_graph_template_filter");
        kill_session_var("sess_graph_template_sort_column");
        kill_session_var("sess_graph_template_sort_direction");
        unset($_REQUEST["page"]);
        unset($_REQUEST["filter"]);
        unset($_REQUEST["sort_column"]);
        unset($_REQUEST["sort_direction"]);
    }
    /* remember these search fields in session vars so we don't have to keep passing them around */
    load_current_session_value("page", "sess_graph_template_current_page", "1");
    load_current_session_value("filter", "sess_graph_template_filter", "");
    load_current_session_value("sort_column", "sess_graph_template_sort_column", "name");
    load_current_session_value("sort_direction", "sess_graph_template_sort_direction", "ASC");
    html_start_box("<strong>Graph Templates</strong>", "100%", $colors["header"], "3", "center", "graph_templates.php?action=template_edit");
    ?>
	<tr bgcolor="<?php 
    print $colors["panel"];
    ?>
">
		<form name="form_host_template">
		<td>
			<table width="100%" cellpadding="0" cellspacing="0">
				<tr>
					<td nowrap style='white-space: nowrap;' width="50">
						Search:&nbsp;
					</td>
					<td width="1">
						<input type="text" name="filter" size="40" value="<?php 
    print get_request_var_request("filter");
    ?>
">
					</td>
					<td nowrap style='white-space: nowrap;'>
						&nbsp;<input type="image" src="images/button_go.gif" alt="Go" border="0" align="absmiddle">
						<input type="image" src="images/button_clear.gif" name="clear" alt="Clear" border="0" align="absmiddle">
					</td>
				</tr>
			</table>
		</td>
		<input type='hidden' name='page' value='1'>
		</form>
	</tr>
	<?php 
    html_end_box();
    /* form the 'where' clause for our main sql query */
    $sql_where = "WHERE (graph_templates.name LIKE '%%" . get_request_var_request("filter") . "%%')";
    html_start_box("", "100%", $colors["header"], "3", "center", "");
    $total_rows = db_fetch_cell("SELECT\n\t\tCOUNT(graph_templates.id)\n\t\tFROM graph_templates\n\t\t{$sql_where}");
    $template_list = db_fetch_assoc("SELECT\n\t\tgraph_templates.id,graph_templates.name\n\t\tFROM graph_templates\n\t\t{$sql_where}\n\t\tORDER BY " . get_request_var_request("sort_column") . " " . get_request_var_request("sort_direction") . " LIMIT " . read_config_option("num_rows_device") * (get_request_var_request("page") - 1) . "," . read_config_option("num_rows_device"));
    /* generate page list */
    $url_page_select = get_page_list(get_request_var_request("page"), MAX_DISPLAY_PAGES, read_config_option("num_rows_device"), $total_rows, "graph_templates.php?filter=" . get_request_var_request("filter"));
    $nav = "<tr bgcolor='#" . $colors["header"] . "'>\n\t\t<td colspan='7'>\n\t\t\t<table width='100%' cellspacing='0' cellpadding='0' border='0'>\n\t\t\t\t<tr>\n\t\t\t\t\t<td align='left' class='textHeaderDark'>\n\t\t\t\t\t\t<strong>&lt;&lt; ";
    if (get_request_var_request("page") > 1) {
        $nav .= "<a class='linkOverDark' href='graph_templates.php?filter=" . get_request_var_request("filter") . "&page=" . (get_request_var_request("page") - 1) . "'>";
    }
    $nav .= "Previous";
    if (get_request_var_request("page") > 1) {
        $nav .= "</a>";
    }
    $nav .= "</strong>\n\t\t\t\t\t</td>\n\n\t\t\t\t\t<td align='center' class='textHeaderDark'>\n\t\t\t\t\t\tShowing Rows " . (read_config_option("num_rows_device") * (get_request_var_request("page") - 1) + 1) . " to " . ($total_rows < read_config_option("num_rows_device") || $total_rows < read_config_option("num_rows_device") * get_request_var_request("page") ? $total_rows : read_config_option("num_rows_device") * get_request_var_request("page")) . " of {$total_rows} [{$url_page_select}]\n\t\t\t\t\t</td>\n\n\t\t\t\t\t<td align='right' class='textHeaderDark'>\n\t\t\t\t\t\t<strong>";
    if (get_request_var_request("page") * read_config_option("num_rows_device") < $total_rows) {
        $nav .= "<a class='linkOverDark' href='graph_templates.php?filter=" . get_request_var_request("filter") . "&page=" . (get_request_var_request("page") + 1) . "'>";
    }
    $nav .= "Next";
    if (get_request_var_request("page") * read_config_option("num_rows_device") < $total_rows) {
        $nav .= "</a>";
    }
    $nav .= " &gt;&gt;</strong>\n\t\t\t\t\t</td>\n\n\t\t\t\t</tr>\n\t\t\t</table>\n\t\t</td>\n\t\t</tr>\n";
    print $nav;
    $display_text = array("name" => array("Template Title", "ASC"));
    html_header_sort_checkbox($display_text, get_request_var_request("sort_column"), get_request_var_request("sort_direction"));
    $i = 0;
    if (sizeof($template_list) > 0) {
        foreach ($template_list as $template) {
            form_alternate_row_color($colors["alternate"], $colors["light"], $i, 'line' . $template["id"]);
            $i++;
            form_selectable_cell("<a class='linkEditMain' href='graph_templates.php?action=template_edit&id=" . $template["id"] . "'>" . (strlen(get_request_var_request("filter")) ? eregi_replace("(" . preg_quote(get_request_var_request("filter")) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $template["name"]) : $template["name"]) . "</a>", $template["id"]);
            form_checkbox_cell($template["name"], $template["id"]);
            form_end_row();
        }
        print $nav;
    } else {
        print "<tr><td><em>No Graph Templates</em></td></tr>\n";
    }
    html_end_box(false);
    /* draw the dropdown containing a list of available actions for this form */
    draw_actions_dropdown($graph_actions);
    print "</form>\n";
}
Example #15
0
										}

										$upgrade_results .= "<p class='code'>" . (($status == 0) ? $fail_text : $success_text) . nl2br($sql) . "</p>\n";

										/* if there are one or more failures, make a note because we are going to print
										out a warning to the user later on */
										if ($status == 0) {
											$failed_sql_query = true;
										}

										$current_version = $version;
									}
								}
							}

							kill_session_var("sess_sql_install_cache");
						}else{
							print "<em>No SQL queries have been executed.</em>";
						}

						if ($failed_sql_query == true) {
							print "<p><strong><font color='#FF0000'>WARNING:</font></strong> One or more of the SQL queries needed to
								upgraded your Cacti installation has failed. Please see below for more details. Your
								Cacti MySQL user must have <strong>SELECT, INSERT, UPDATE, DELETE, ALTER, CREATE, and DROP</strong>
								permissions. You should try executing the failed queries as 'root' to ensure that you do not have
								a permissions problem.</p>\n";
						}

						print $upgrade_results;
						?>
Example #16
0
function snmpagent_utilities_run_eventlog()
{
    global $item_rows;
    define("MAX_DISPLAY_PAGES", 21);
    $severity_levels = array(SNMPAGENT_EVENT_SEVERITY_LOW => 'LOW', SNMPAGENT_EVENT_SEVERITY_MEDIUM => 'MEDIUM', SNMPAGENT_EVENT_SEVERITY_HIGH => 'HIGH', SNMPAGENT_EVENT_SEVERITY_CRITICAL => 'CRITICAL');
    $severity_colors = array(SNMPAGENT_EVENT_SEVERITY_LOW => '#00FF00', SNMPAGENT_EVENT_SEVERITY_MEDIUM => '#FFFF00', SNMPAGENT_EVENT_SEVERITY_HIGH => '#FF0000', SNMPAGENT_EVENT_SEVERITY_CRITICAL => '#FF00FF');
    $receivers = db_fetch_assoc("SELECT DISTINCT manager_id, hostname FROM snmpagent_notifications_log INNER JOIN snmpagent_managers ON snmpagent_managers.id = snmpagent_notifications_log.manager_id");
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_request("receiver"));
    if (!in_array(get_request_var_request("severity"), array_keys($severity_levels)) && get_request_var_request("severity") != '-1' && get_request_var_request("severity") != "") {
        die_html_input_error();
    }
    input_validate_input_number(get_request_var_request("page"));
    input_validate_input_number(get_request_var_request("rows"));
    /* ==================================================== */
    /* clean up search filter */
    if (isset($_REQUEST["filter"])) {
        $_REQUEST["filter"] = sanitize_search_string(get_request_var("filter"));
    }
    if (isset($_REQUEST["purge_x"])) {
        db_execute("TRUNCATE table snmpagent_notifications_log;");
        /* reset filters */
        $_REQUEST["clear_x"] = true;
    }
    /* if the user pushed the 'clear' button */
    if (isset($_REQUEST["clear_x"])) {
        kill_session_var("sess_snmpagent__logs_receiver");
        kill_session_var("sess_snmpagent__logs_severity");
        kill_session_var("sess_snmpagent__logs_current_page");
        kill_session_var("sess_snmpagent__logs_filter");
        kill_session_var("sess_default_rows");
        unset($_REQUEST["receiver"]);
        unset($_REQUEST["severity"]);
        unset($_REQUEST["page"]);
        unset($_REQUEST["filter"]);
        unset($_REQUEST["rows"]);
    }
    /* reset the current page if the user changed the severity */
    if (isset($_SESSION["sess_snmpagent__logs_severity"]) && get_request_var_request("severity") != $_SESSION["sess_snmpagent__logs_severity"]) {
        kill_session_var("sess_snmpagent__logs_current_page");
        unset($_REQUEST["page"]);
    }
    /* remember these search fields in session vars so we don't have to keep passing them around */
    load_current_session_value("receiver", "sess_snmpagent__logs_receiver", "-1");
    load_current_session_value("page", "sess_snmpagent__logs_current_page", "1");
    load_current_session_value("severity", "sess_snmpagent__logs_severity", "-1");
    load_current_session_value("filter", "sess_snmpagent__logs_filter", "");
    load_current_session_value('rows', 'sess_default_rows', read_config_option('num_rows_table'));
    /* if the number of rows is -1, set it to the default */
    if ($_REQUEST["rows"] == -1) {
        $_REQUEST["rows"] = read_config_option("num_rows_table");
    }
    $_REQUEST['page_referrer'] = 'view_snmpagent_events';
    load_current_session_value('page_referrer', 'page_referrer', 'view_snmpagent_events');
    ?>
	<script type="text/javascript">
	<!--

	function applyFilter() {
		strURL = 'utilities.php?action=view_snmpagent_events';
		strURL = strURL + '&severity=' + $('#severity').val();
		strURL = strURL + '&receiver=' + $('#receiver').val();
		strURL = strURL + '&rows=' + $('#rows').val();
		strURL = strURL + '&filter=' + $('#filter').val();
		strURL = strURL + '&page=' + $('#page').val();
		strURL = strURL + '&header=false';
		$.get(strURL, function(data) {
			$('#main').html(data);
			applySkin();
		});
	}

	function clearFilter() {
		strURL = 'utilities.php?action=view_snmpagent_events&clear_x=1&header=false';
		$.get(strURL, function(data) {
			$('#main').html(data);
			applySkin();
		});
	}

	$(function(data) {
		$('#refresh').click(function() {
			applyFilter();
		});

		$('#clear').click(function() {
			clearFilter();
		});

		$('#form_snmpagent_notifications').submit(function(event) {
			event.preventDefault();
			applyFilter();
		});
	});

	-->
	</script>

	<?php 
    html_start_box("<strong>SNMPAgent Notification Log</strong>", "100%", "", "3", "center", "");
    ?>
	<tr class='even noprint'>
		<td>
			<form id='form_snmpagent_notifications' name="form_snmpagent_notifications" action="utilities.php">
				<table cellpadding="2" cellspacing="0">
					<tr>
						<td>
							Severity:
						</td>
						<td>
							<select id="severity" name="severity" onChange="applyFilter()">
								<option value="-1"<?php 
    if (get_request_var_request("severity") == "-1") {
        ?>
 selected<?php 
    }
    ?>
>Any</option>
								<?php 
    foreach ($severity_levels as $level => $name) {
        print "<option value='" . $level . "'";
        if (get_request_var_request("severity") == $level) {
            print " selected";
        }
        print ">" . $name . "</option>\n";
    }
    ?>
							</select>
						</td>
						<td>
							Receiver:
						</td>
						<td width="1">
							<select id="receiver" name="receiver" onChange="applyFilter()">
								<option value="-1"<?php 
    if (get_request_var_request("receiver") == "-1") {
        ?>
 selected<?php 
    }
    ?>
>Any</option>
								<?php 
    foreach ($receivers as $receiver) {
        print "<option value='" . $receiver["manager_id"] . "'";
        if (get_request_var_request("receiver") == $receiver["manager_id"]) {
            print " selected";
        }
        print ">" . $receiver["hostname"] . "</option>\n";
    }
    ?>
							</select>
						</td>
						<td>
							Search:
						</td>
						<td>
							<input id='filter' type="text" name="filter" size="25" value="<?php 
    print htmlspecialchars(get_request_var_request("filter"));
    ?>
" onChange='applyFilter()'>
						</td>
						<td>
							Rows:
						</td>
						<td>
							<select id='rows' name="rows" onChange="applyFilter()">
								<option value="-1"<?php 
    if (get_request_var_request("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("rows") == $key) {
                print " selected";
            }
            print ">" . htmlspecialchars($value) . "</option>\n";
        }
    }
    ?>
							</select>
						</td>
						<td>
							<input type="submit" id="refresh" name="go" value="Go" title="Set/Refresh Filters">
							<input type="submit" id="clear" name="clear_x" value="Clear" title="Clear Filters">
							<input type="submit" id="purge" name="purge_x" value="Purge" title="Purge Notification Log">
						</td>
					</tr>
				</table>
				<input type='hidden' id='page' name='page' value='<?php 
    print $_REQUEST['page'];
    ?>
'>
			</form>
		</td>
	</tr>
	<?php 
    html_end_box();
    $sql_where = " 1";
    /* filter by severity */
    if (get_request_var_request("receiver") != "-1") {
        $sql_where .= " AND snmpagent_notifications_log.manager_id='" . get_request_var_request("receiver") . "'";
    }
    /* filter by severity */
    if (get_request_var_request("severity") == "-1") {
        /* Show all items */
    } elseif (!empty($_REQUEST["severity"])) {
        $sql_where .= " AND snmpagent_notifications_log.severity='" . get_request_var_request("severity") . "'";
    }
    /* filter by search string */
    if (get_request_var_request("filter") != "") {
        $sql_where .= " AND (`varbinds` LIKE '%%" . get_request_var_request("filter") . "%%')";
    }
    $sql_where .= ' ORDER by `time` DESC';
    $sql_query = "SELECT snmpagent_notifications_log.*, snmpagent_managers.hostname, snmpagent_cache.description FROM snmpagent_notifications_log\n\t\t\t\t\t INNER JOIN snmpagent_managers ON snmpagent_managers.id = snmpagent_notifications_log.manager_id\n\t\t\t\t\t LEFT JOIN snmpagent_cache ON snmpagent_cache.name = snmpagent_notifications_log.notification\n\t\t\t\t\t WHERE {$sql_where} LIMIT " . read_config_option("num_rows_data_source") * (get_request_var_request("page") - 1) . "," . read_config_option("num_rows_data_source");
    /* print checkbox form for validation */
    print "<form name='chk' method='post' action='managers.php'>\n";
    html_start_box("", "100%", "", "3", "center", "");
    $total_rows = db_fetch_cell("SELECT COUNT(*) FROM snmpagent_notifications_log WHERE {$sql_where}");
    $logs = db_fetch_assoc($sql_query);
    /* generate page list */
    $nav = html_nav_bar("utilities.php?action=view_snmpagent_events&severity=" . get_request_var_request("severity") . "&receiver=" . get_request_var_request("receiver") . "&filter=" . get_request_var_request("filter"), MAX_DISPLAY_PAGES, get_request_var_request("page"), get_request_var_request("rows"), $total_rows, 11, '', 'page', 'main');
    print $nav;
    html_header(array(" ", "Time", "Receiver", "Notification", "Varbinds"));
    if (sizeof($logs) > 0) {
        foreach ($logs as $item) {
            $varbinds = strlen(get_request_var_request("filter")) ? preg_replace("/(" . preg_quote(get_request_var_request("filter"), "/") . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", $item["varbinds"]) : $item["varbinds"];
            form_alternate_row('line' . $item["id"], false);
            print "<td title='Severity Level: " . $severity_levels[$item["severity"]] . "' style='width:10px;background-color: " . $severity_colors[$item["severity"]] . ";border-top:1px solid white;border-bottom:1px solid white;'></td>";
            print "<td style='white-space: nowrap;'>" . date("Y/m/d H:i:s", $item["time"]) . "</td>";
            print "<td>" . $item["hostname"] . "</td>";
            if ($item["description"]) {
                print '<td><a href="#" title="<div class=\'header\'>' . $item["notification"] . '</div><div class=\'content preformatted\'>' . $item["description"] . '</div>" class="tooltip">' . $item["notification"] . '</a></td>';
            } else {
                print "<td>{$item["notification"]}</td>";
            }
            print "<td>{$varbinds}</td>";
            form_end_row();
        }
        print $nav;
    } else {
        print "<tr><td><em>No SNMP Notification Log Entries</em></td></tr>";
    }
    html_end_box();
    ?>

	<script language="javascript" type="text/javascript" >
		$('.tooltip').tooltip({
			track: true,
			position: { collision: "flipfit" },
			content: function() { return $(this).attr('title'); }
		});
	</script>
	<?php 
}
Example #17
0
function template()
{
    global $host_actions, $item_rows;
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_request('page'));
    input_validate_input_number(get_request_var_request('rows'));
    /* ==================================================== */
    /* clean up has_hosts string */
    if (isset($_REQUEST['has_hosts'])) {
        $_REQUEST['has_hosts'] = sanitize_search_string(get_request_var_request('has_hosts'));
    }
    /* clean up search string */
    if (isset($_REQUEST['filter'])) {
        $_REQUEST['filter'] = sanitize_search_string(get_request_var_request('filter'));
    }
    /* clean up sort_column */
    if (isset($_REQUEST['sort_column'])) {
        $_REQUEST['sort_column'] = sanitize_search_string(get_request_var_request('sort_column'));
    }
    /* clean up sort_direction string */
    if (isset($_REQUEST['sort_direction'])) {
        $_REQUEST['sort_direction'] = sanitize_search_string(get_request_var_request('sort_direction'));
    }
    /* if the user pushed the 'clear' button */
    if (isset($_REQUEST['clear_x'])) {
        kill_session_var('sess_host_template_current_page');
        kill_session_var('sess_host_template_hosts');
        kill_session_var('sess_host_template_filter');
        kill_session_var('sess_default_rows');
        kill_session_var('sess_host_template_sort_column');
        kill_session_var('sess_host_template_sort_direction');
        unset($_REQUEST['page']);
        unset($_REQUEST['has_hosts']);
        unset($_REQUEST['filter']);
        unset($_REQUEST['rows']);
        unset($_REQUEST['sort_column']);
        unset($_REQUEST['sort_direction']);
    } else {
        $changed = 0;
        $changed += check_changed('has_hosts', 'sess_host_template_has_hosts');
        $changed += check_changed('rows', 'sess_default_rows');
        $changed += check_changed('filter', 'sess_host_template_filter');
        if ($changed) {
            $_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_host_template_current_page', '1');
    load_current_session_value('has_hosts', 'sess_host_template_has_hosts', 'true');
    load_current_session_value('filter', 'sess_host_template_filter', '');
    load_current_session_value('sort_column', 'sess_host_template_sort_column', 'name');
    load_current_session_value('sort_direction', 'sess_host_template_sort_direction', 'ASC');
    load_current_session_value('rows', 'sess_default_rows', read_config_option('num_rows_table'));
    display_output_messages();
    html_start_box('<strong>Device Templates</strong>', '100%', '', '3', 'center', 'host_templates.php?action=edit');
    ?>
	<tr class='even noprint'>
		<td>
		<form id="form_host_template" action="host_templates.php">
			<table cellpadding="2" cellspacing="0" border="0">
				<tr>
					<td width="50">
						Search
					</td>
					<td>
						<input id='filter' type="text" name="filter" size="25" value="<?php 
    print htmlspecialchars(get_request_var_request('filter'));
    ?>
">
					</td>
					<td style='white-space:nowrap;'>
						Device Templates
					</td>
					<td>
						<select id='rows' name="rows" onChange="applyFilter()">
							<?php 
    if (sizeof($item_rows) > 0) {
        foreach ($item_rows as $key => $value) {
            print "<option value='" . $key . "'";
            if (get_request_var_request('rows') == $key) {
                print ' selected';
            }
            print '>' . htmlspecialchars($value) . "</option>\n";
        }
    }
    ?>
						</select>
					</td>
					<td>
						<input type="checkbox" id='has_hosts' <?php 
    print $_REQUEST['has_hosts'] == 'true' ? 'checked' : '';
    ?>
>
					</td>
					<td>
						<label for='has_hosts' style='white-space:nowrap;'>Has Devices</label>
					</td>
					<td>
						<input type="button" id='refresh' value="Go" title="Set/Refresh Filters">
					</td>
					<td>
						<input type="button" id='clear' name="clear_x" value="Clear" title="Clear Filters">
					</td>
				</tr>
			</table>
		<input type='hidden' id='page' name='page' value='<?php 
    print $_REQUEST['page'];
    ?>
'>
		</form>
		</td>
		<script type='text/javascript'>
		function applyFilter() {
			strURL = 'host_templates.php?filter='+$('#filter').val()+'&rows='+$('#rows').val()+'&page='+$('#page').val()+'&has_hosts='+$('#has_hosts').is(':checked')+'&header=false';
			$.get(strURL, function(data) {
				$('#main').html(data);
				applySkin();
			});
		}

		function clearFilter() {
			strURL = 'host_templates.php?clear_x=1&header=false';
			$.get(strURL, function(data) {
				$('#main').html(data);
				applySkin();
			});
		}

		$(function() {
			$('#refresh, #has_hosts').click(function() {
				applyFilter();
			});

			$('#clear').click(function() {
				clearFilter();
			});
	
			$('#form_host_template').submit(function(event) {
				event.preventDefault();
				applyFilter();
			});
		});
		</script>
	</tr>
	<?php 
    html_end_box();
    /* form the 'where' clause for our main sql query */
    if (strlen($_REQUEST['filter'])) {
        $sql_where = "WHERE (host_template.name LIKE '%%" . get_request_var_request('filter') . "%%')";
    } else {
        $sql_where = '';
    }
    /* print checkbox form for validation */
    print "<form name='chk' method='post' action='host_templates.php'>\n";
    html_start_box('', '100%', '', '3', 'center', '');
    if ($_REQUEST['has_hosts'] == 'true') {
        $sql_having = 'HAVING hosts>0';
    } else {
        $sql_having = '';
    }
    $total_rows = db_fetch_cell("SELECT COUNT(rows)\n\t\tFROM (\n\t\t\tSELECT\n\t\t\tCOUNT(host_template.id) AS rows, COUNT(DISTINCT host.id) AS hosts\n\t\t\tFROM host_template\n\t\t\tLEFT JOIN host ON host.host_template_id=host_template.id\n\t\t\t{$sql_where}\n\t\t\tGROUP BY host_template.id\n\t\t\t{$sql_having}\n\t\t) AS rs");
    $template_list = db_fetch_assoc("SELECT\n\t\thost_template.id,host_template.name, COUNT(DISTINCT host.id) AS hosts\n\t\tFROM host_template\n\t\tLEFT JOIN host ON host.host_template_id=host_template.id\n\t\t{$sql_where}\n\t\tGROUP BY host_template.id\n\t\t{$sql_having}\n\t\tORDER BY " . get_request_var_request('sort_column') . ' ' . get_request_var_request('sort_direction') . ' LIMIT ' . get_request_var_request('rows') * (get_request_var_request('page') - 1) . ',' . get_request_var_request('rows'));
    $nav = html_nav_bar('host_templates.php?filter=' . get_request_var_request('filter'), MAX_DISPLAY_PAGES, get_request_var_request('page'), get_request_var_request('rows'), $total_rows, 5, 'Device Templates', 'page', 'main');
    print $nav;
    $display_text = array('name' => array('display' => 'Device Template Name', 'align' => 'left', 'sort' => 'ASC', 'tip' => 'The name of this Device Template.'), "nosort" => array('display' => 'Deletable', 'align' => 'right', 'sort' => '', 'tip' => 'Device Templates in use can not be Deleted.  In use is defined as being referenced by a Device.'), 'hosts' => array('display' => 'Devices Using', 'align' => 'right', 'sort' => 'DESC', 'tip' => 'The number of Devices using this Device Template.'), 'host_template.id' => array('display' => 'ID', 'align' => 'right', 'sort' => 'ASC', 'tip' => 'The internal database ID for this Device Template.  Useful when performing automation or debugging.'));
    html_header_sort_checkbox($display_text, get_request_var_request('sort_column'), get_request_var_request('sort_direction'), false);
    $i = 0;
    if (sizeof($template_list) > 0) {
        foreach ($template_list as $template) {
            if ($template['hosts'] > 0) {
                $disabled = true;
            } else {
                $disabled = false;
            }
            form_alternate_row('line' . $template['id'], true, $disabled);
            form_selectable_cell("<a class='linkEditMain' href='" . htmlspecialchars('host_templates.php?action=edit&id=' . $template['id']) . "'>" . (strlen(get_request_var_request('filter')) ? preg_replace('/(' . preg_quote(get_request_var_request('filter'), '/') . ')/i', "<span class='filteredValue'>\\1</span>", htmlspecialchars($template['name'])) : htmlspecialchars($template['name'])) . '</a>', $template['id']);
            form_selectable_cell($disabled ? 'No' : 'Yes', $template['id'], '', 'text-align:right');
            form_selectable_cell(number_format($template['hosts']), $template['id'], '', 'text-align:right');
            form_selectable_cell($template['id'], $template['id'], '', 'text-align:right');
            form_checkbox_cell($template['name'], $template['id'], $disabled);
            form_end_row();
        }
        /* put the nav bar on the bottom as well */
        print $nav;
    } else {
        print "<tr class='tableRow'><td colspan='4'><em>No Device Templates</em></td></tr>\n";
    }
    html_end_box(false);
    /* draw the dropdown containing a list of available actions for this form */
    draw_actions_dropdown($host_actions);
    print "</form>\n";
}
Example #18
0
	/* reset the page counter to '1' if a search in initiated */
	if (isset($_REQUEST["filter"])) {
		$_REQUEST["page"] = "1";
	}

	load_current_session_value("host_id", "sess_graph_view_list_host", "0");
	load_current_session_value("graph_template_id", "sess_graph_view_list_graph_template", "0");
	load_current_session_value("filter", "sess_graph_view_list_filter", "");
	load_current_session_value("page", "sess_graph_view_list_current_page", "");

	/* if the user pushed the 'clear' button */
	if (isset($_REQUEST["clear_x"])) {
		kill_session_var("sess_graph_view_list_current_page");
		kill_session_var("sess_graph_view_list_filter");
		kill_session_var("sess_graph_view_list_host");
		kill_session_var("sess_graph_view_list_graph_template");

		unset($_REQUEST["page"]);
		unset($_REQUEST["filter"]);
		unset($_REQUEST["host_id"]);
		unset($_REQUEST["graph_template_id"]);
		unset($_REQUEST["graph_list"]);
		unset($_REQUEST["graph_add"]);
		unset($_REQUEST["graph_remove"]);

	}

	/* make sure we have a page set */
	if (! isset($_REQUEST["page"])) {
		$_REQUEST["page"] = 1;
	}
Example #19
0
function template()
{
    global $ds_actions;
    /* ================= input validation ================= */
    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_data_template_current_page");
        kill_session_var("sess_data_template_filter");
        kill_session_var("sess_data_template_sort_column");
        kill_session_var("sess_data_template_sort_direction");
        unset($_REQUEST["page"]);
        unset($_REQUEST["filter"]);
        unset($_REQUEST["sort_column"]);
        unset($_REQUEST["sort_direction"]);
    }
    /* remember these search fields in session vars so we don't have to keep passing them around */
    load_current_session_value("page", "sess_data_template_current_page", "1");
    load_current_session_value("filter", "sess_data_template_filter", "");
    load_current_session_value("sort_column", "sess_data_template_sort_column", "name");
    load_current_session_value("sort_direction", "sess_data_template_sort_direction", "ASC");
    html_start_box("<strong>Data Templates</strong>", "100%", "", "3", "center", "data_templates.php?action=template_edit");
    ?>
	<tr class='even noprint'>
		<td>
		<form name="form_data_template" action="data_templates.php">
			<table width="100%" cellpadding="0" cellspacing="0">
				<tr>
					<td nowrap style='white-space: nowrap;' 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>
					<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>
			</table>
			<input type='hidden' name='page' value='1'>
		</form>
		</td>
	</tr>
	<?php 
    html_end_box();
    /* form the 'where' clause for our main sql query */
    $sql_where = "WHERE data_template.id=data_template_data.data_template_id AND data_template_data.local_data_id=0";
    $rows_where = "";
    if (strlen($_REQUEST['filter'])) {
        $sql_where .= " AND (data_template.name like '%%" . get_request_var_request("filter") . "%%')";
        $rows_where = "WHERE (data_template.name like '%%" . get_request_var_request("filter") . "%%')";
    }
    /* print checkbox form for validation */
    print "<form name='chk' method='post' action='data_templates.php'>\n";
    html_start_box("", "100%", "", "3", "center", "");
    $total_rows = db_fetch_cell("SELECT\n\t\tCOUNT(data_template.id)\n\t\tFROM data_template\n\t\t{$rows_where}");
    $template_list = db_fetch_assoc("SELECT\n\t\tdata_template.id,\n\t\tdata_template.name,\n\t\tdata_input.name AS data_input_method,\n\t\tdata_template_data.active AS active\n\t\tFROM (data_template,data_template_data)\n\t\tLEFT JOIN data_input\n\t\tON (data_template_data.data_input_id = data_input.id)\n\t\t{$sql_where}\n\t\tGROUP BY data_template.id\n\t\tORDER BY " . get_request_var_request("sort_column") . " " . get_request_var_request("sort_direction") . " LIMIT " . read_config_option("num_rows_device") * (get_request_var_request("page") - 1) . "," . read_config_option("num_rows_device"));
    $nav = html_nav_bar("data_templates.php?filter=" . get_request_var_request("filter"), MAX_DISPLAY_PAGES, get_request_var_request("page"), read_config_option("num_rows_device"), $total_rows, 5);
    print $nav;
    $display_text = array("name" => array("Template Name", "ASC"), "id" => array("ID", "ASC"), "data_input_method" => array("Data Input Method", "ASC"), "active" => array("Status", "ASC"));
    html_header_sort_checkbox($display_text, get_request_var_request("sort_column"), get_request_var_request("sort_direction"), false);
    if (sizeof($template_list) > 0) {
        foreach ($template_list as $template) {
            form_alternate_row('line' . $template["id"], true);
            form_selectable_cell("<a class='linkEditMain' href='" . htmlspecialchars("data_templates.php?action=template_edit&id=" . $template["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($template["name"])) : htmlspecialchars($template["name"])) . "</a>", $template["id"]);
            form_selectable_cell($template['id'], $template["id"]);
            form_selectable_cell(empty($template["data_input_method"]) ? "<em>None</em>" : htmlspecialchars($template["data_input_method"]), $template["id"]);
            form_selectable_cell($template["active"] == "on" ? "Active" : "Disabled", $template["id"]);
            form_checkbox_cell($template["name"], $template["id"]);
            form_end_row();
        }
        /* put the nav bar on the bottom as well */
        print $nav;
    } else {
        print "<tr><td><em>No Data Templates</em></td></tr>\n";
    }
    html_end_box(false);
    /* draw the dropdown containing a list of available actions for this form */
    draw_actions_dropdown($ds_actions);
    print "</form>\n";
}
Example #20
0
function data_query() {
	global $colors, $dq_actions;

	/* 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_data_queries_filter");
		kill_session_var("sess_data_queries_sort_column");
		kill_session_var("sess_data_queries_sort_direction");

		unset($_REQUEST["page"]);
		unset($_REQUEST["filter"]);
		unset($_REQUEST["sort_column"]);
		unset($_REQUEST["sort_direction"]);
		$_REQUEST["page"] = 1;
	}

	/* remember these search fields in session vars so we don't have to keep passing them around */
	load_current_session_value("sort_column", "sess_data_queries_sort_column", "name");
	load_current_session_value("sort_direction", "sess_data_queries_sort_direction", "ASC");
	load_current_session_value("page", "sess_data_queries_current_page", "1");
	load_current_session_value("filter", "sess_data_queries_filter", "");

	html_start_box("<strong>Data Queries</strong>", "100%", $colors["header"], "3", "center", "data_queries.php?action=edit");

	?>
	<tr bgcolor="<?php print $colors["panel"];?>" class="noprint">
		<form name="form_graph_id" method="get">
		<td class="noprint">
			<table width="100%" cellpadding="0" cellspacing="0">
				<tr class="noprint">
					<td nowrap style='white-space: nowrap;' width="50">
						Search:&nbsp;
					</td>
					<td width="1">
						<input type="text" name="filter" size="40" value="<?php print get_request_var_request("filter");?>">
					</td>
					<td nowrap style='white-space: nowrap;'>
						&nbsp;<input type="image" src="images/button_go.gif" alt="Go" border="0" align="absmiddle">
						<input type="image" src="images/button_clear.gif" name="clear" alt="Clear" border="0" align="absmiddle">
					</td>
				</tr>
			</table>
		</td>
		<input type='hidden' name='page' value='1'>
		</form>
	</tr>
	<?php

	html_end_box();

	html_start_box("", "100%", $colors["header"], "3", "center", "");

	/* form the 'where' clause for our main sql query */
	if (strlen(get_request_var_request("filter"))) {
		$sql_where = "where (snmp_query.name like '%%" . get_request_var_request("filter") . "%%' OR data_input.name like '%%" . get_request_var_request("filter") . "%%')";
	}else{
		$sql_where = "";
	}

	$total_rows = db_fetch_cell("SELECT
		count(*)
		FROM snmp_query INNER JOIN data_input ON (snmp_query.data_input_id=data_input.id)
		$sql_where");

	$snmp_queries = db_fetch_assoc("SELECT
		snmp_query.id,
		snmp_query.name,
		data_input.name AS data_input_method
		FROM snmp_query INNER JOIN data_input ON (snmp_query.data_input_id=data_input.id)
		$sql_where
		ORDER BY " . get_request_var_request("sort_column") . " " . get_request_var_request("sort_direction") . "
		LIMIT " . (read_config_option("num_rows_device")*(get_request_var_request("page")-1)) . "," . read_config_option("num_rows_device"));

	/* generate page list */
	$url_page_select = get_page_list(get_request_var_request("page"), MAX_DISPLAY_PAGES, read_config_option("num_rows_device"), $total_rows, "data_queries.php?filter=" . get_request_var_request("filter"));

	$nav = "<tr bgcolor='#" . $colors["header"] . "'>
			<td colspan='7'>
				<table width='100%' cellspacing='0' cellpadding='0' border='0'>
					<tr>
						<td align='left' class='textHeaderDark'>
							<strong>&lt;&lt; "; if (get_request_var_request("page") > 1) { $nav .= "<a class='linkOverDark' href='data_queries.php?filter=" . get_request_var_request("filter") . "&page=" . (get_request_var_request("page")-1) . "'>"; } $nav .= "Previous"; if (get_request_var_request("page") > 1) { $nav .= "</a>"; } $nav .= "</strong>
						</td>\n
						<td align='center' class='textHeaderDark'>
							Showing Rows " . ((read_config_option("num_rows_device")*(get_request_var_request("page")-1))+1) . " to " . ((($total_rows < read_config_option("num_rows_device")) || ($total_rows < (read_config_option("num_rows_device")*get_request_var_request("page")))) ? $total_rows : (read_config_option("num_rows_device")*get_request_var_request("page"))) . " of $total_rows [$url_page_select]
						</td>\n
						<td align='right' class='textHeaderDark'>
							<strong>"; if ((get_request_var_request("page") * read_config_option("num_rows_device")) < $total_rows) { $nav .= "<a class='linkOverDark' href='data_queries.php?filter=" . get_request_var_request("filter") . "&page=" . (get_request_var_request("page")+1) . "'>"; } $nav .= "Next"; if ((get_request_var_request("page") * read_config_option("num_rows_device")) < $total_rows) { $nav .= "</a>"; } $nav .= " &gt;&gt;</strong>
						</td>\n
					</tr>
				</table>
			</td>
		</tr>\n";

	print $nav;

	$display_text = array(
		"name" => array("Name", "ASC"),
		"data_input_method" => array("Data Input Method", "ASC"));

	html_header_sort_checkbox($display_text, get_request_var_request("sort_column"), get_request_var_request("sort_direction"));

	$i = 0;
	if (sizeof($snmp_queries) > 0) {
		foreach ($snmp_queries as $snmp_query) {
			form_alternate_row_color($colors["alternate"],$colors["light"],$i, 'line' . $snmp_query["id"]); $i++;
			form_selectable_cell("<a class='linkEditMain' href='data_queries.php?action=edit&id=" . $snmp_query["id"] . "'>" . (strlen(get_request_var_request("filter")) ? eregi_replace("(" . preg_quote(get_request_var_request("filter")) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $snmp_query["name"]) : $snmp_query["name"]) . "</a>", $snmp_query["id"]);
			form_selectable_cell((strlen(get_request_var_request("filter")) ? eregi_replace("(" . preg_quote(get_request_var_request("filter")) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $snmp_query["data_input_method"]) : $snmp_query["data_input_method"]), $snmp_query["id"]);
			form_checkbox_cell($snmp_query["name"], $snmp_query["id"]);
			form_end_row();
		}

		print $nav;
	}else{
		print "<tr><td><em>No Data Queries</em></td></tr>";
	}

	html_end_box();

	/* draw the dropdown containing a list of available actions for this form */
	draw_actions_dropdown($dq_actions);
}
Example #21
0
function &import_xml_data(&$xml_data, $import_custom_rra_settings, $rra_array = array())
{
    global $config, $hash_type_codes, $hash_version_codes;
    include_once $config["library_path"] . "/xml.php";
    $info_array = array();
    $xml_array = xml2array($xml_data);
    if (sizeof($xml_array) == 0) {
        raise_message(7);
        /* xml parse error */
        return $info_array;
    }
    while (list($hash, $hash_array) = each($xml_array)) {
        /* parse information from the hash */
        $parsed_hash = parse_xml_hash($hash);
        /* invalid/wrong hash */
        if ($parsed_hash == false) {
            return $info_array;
        }
        if (isset($dep_hash_cache[$parsed_hash["type"]])) {
            array_push($dep_hash_cache[$parsed_hash["type"]], $parsed_hash);
        } else {
            $dep_hash_cache[$parsed_hash["type"]] = array($parsed_hash);
        }
    }
    $hash_cache = array();
    /* the order of the $hash_type_codes array is ordered such that the items
    	with the most dependencies are last and the items with no dependencies are first.
    	this means dependencies will just magically work themselves out :) */
    reset($hash_type_codes);
    while (list($type, $code) = each($hash_type_codes)) {
        /* do we have any matches for this type? */
        if (isset($dep_hash_cache[$type])) {
            /* yes we do. loop through each match for this type */
            for ($i = 0; $i < count($dep_hash_cache[$type]); $i++) {
                $hash_array = $xml_array["hash_" . $hash_type_codes[$dep_hash_cache[$type][$i]["type"]] . $hash_version_codes[$dep_hash_cache[$type][$i]["version"]] . $dep_hash_cache[$type][$i]["hash"]];
                switch ($type) {
                    case 'graph_template':
                        $hash_cache += xml_to_graph_template($dep_hash_cache[$type][$i]["hash"], $hash_array, $hash_cache, $dep_hash_cache[$type][$i]["version"]);
                        break;
                    case 'data_template':
                        $hash_cache += xml_to_data_template($dep_hash_cache[$type][$i]["hash"], $hash_array, $hash_cache, $import_custom_rra_settings, $rra_array);
                        break;
                    case 'host_template':
                        $hash_cache += xml_to_host_template($dep_hash_cache[$type][$i]["hash"], $hash_array, $hash_cache);
                        break;
                    case 'data_input_method':
                        $hash_cache += xml_to_data_input_method($dep_hash_cache[$type][$i]["hash"], $hash_array, $hash_cache);
                        break;
                    case 'data_query':
                        $hash_cache += xml_to_data_query($dep_hash_cache[$type][$i]["hash"], $hash_array, $hash_cache);
                        break;
                    case 'gprint_preset':
                        $hash_cache += xml_to_gprint_preset($dep_hash_cache[$type][$i]["hash"], $hash_array, $hash_cache);
                        break;
                    case 'cdef':
                        $hash_cache += xml_to_cdef($dep_hash_cache[$type][$i]["hash"], $hash_array, $hash_cache);
                        break;
                    case 'round_robin_archive':
                        if ($import_custom_rra_settings === true) {
                            $hash_cache += xml_to_round_robin_archive($dep_hash_cache[$type][$i]["hash"], $hash_array, $hash_cache);
                        }
                        break;
                }
                if (isset($_SESSION["import_debug_info"])) {
                    $info_array[$type][isset($info_array[$type]) ? count($info_array[$type]) : 0] = $_SESSION["import_debug_info"];
                }
                kill_session_var("import_debug_info");
            }
        }
    }
    return $info_array;
}
Example #22
0
function thold_add_graphs_action_execute()
{
    global $config;
    include_once $config['base_path'] . '/plugins/thold/thold_functions.php';
    $host_id = get_filter_request_var('host_id');
    $local_graph_id = get_filter_request_var('local_data_id');
    $thold_template_id = get_filter_request_var('thold_template_id');
    $message = '';
    $template = db_fetch_row_prepared('SELECT * FROM thold_template WHERE id = ?', array($thold_template_id));
    $temp = db_fetch_row_prepared('SELECT dtr.*
		 FROM data_template_rrd AS dtr
		 LEFT JOIN graph_templates_item AS gti
		 ON gti.task_item_id=dtr.id
		 LEFT JOIN graph_local AS gl
		 ON gl.id=gti.local_graph_id
		 WHERE gl.id = ?', array($local_graph_id));
    $data_template_id = $temp['data_template_id'];
    $local_data_id = $temp['local_data_id'];
    $data_source = db_fetch_row_prepared('SELECT * FROM data_local WHERE id = ?', array($local_data_id));
    $data_template_id = $data_source['data_template_id'];
    /* allow duplicate thresholds, but only from differing templates */
    $existing = db_fetch_assoc('SELECT id
		FROM thold_data
		WHERE local_data_id=' . $local_data_id . '
		AND data_template_rrd_id=' . $data_template_id . '
		AND thold_template_id=' . $template['id'] . " AND template_enabled='on'");
    if (count($existing) == 0 && count($template)) {
        if ($local_graph_id) {
            $rrdlookup = db_fetch_cell("SELECT id FROM data_template_rrd WHERE local_data_id={$local_data_id} ORDER BY id LIMIT 1");
            $grapharr = db_fetch_row("SELECT graph_template_id FROM graph_templates_item WHERE task_item_id={$rrdlookup} AND local_graph_id = {$local_graph_id}");
            $desc = db_fetch_cell_prepared('SELECT name_cache FROM data_template_data WHERE local_data_id = ? LIMIT 1', array($local_data_id));
            $data_source_name = $template['data_source_name'];
            $insert = array();
            $name = thold_format_name($template, $local_graph_id, $local_data_id, $data_source_name);
            $insert['name'] = $name;
            $insert['host_id'] = $data_source['host_id'];
            $insert['local_data_id'] = $local_data_id;
            $insert['local_graph_id'] = $local_graph_id;
            $insert['data_template_id'] = $data_template_id;
            $insert['graph_template_id'] = $grapharr['graph_template_id'];
            $insert['thold_hi'] = $template['thold_hi'];
            $insert['thold_low'] = $template['thold_low'];
            $insert['thold_fail_trigger'] = $template['thold_fail_trigger'];
            $insert['thold_enabled'] = $template['thold_enabled'];
            $insert['thold_warning_hi'] = $template['thold_warning_hi'];
            $insert['thold_warning_low'] = $template['thold_warning_low'];
            $insert['thold_warning_fail_trigger'] = $template['thold_warning_fail_trigger'];
            $insert['bl_ref_time_range'] = $template['bl_ref_time_range'];
            $insert['bl_pct_down'] = $template['bl_pct_down'];
            $insert['bl_pct_up'] = $template['bl_pct_up'];
            $insert['bl_fail_trigger'] = $template['bl_fail_trigger'];
            $insert['bl_alert'] = $template['bl_alert'];
            $insert['repeat_alert'] = $template['repeat_alert'];
            $insert['notify_extra'] = $template['notify_extra'];
            $insert['cdef'] = $template['cdef'];
            $insert['thold_template_id'] = $template['id'];
            $insert['template_enabled'] = 'on';
            $rrdlist = db_fetch_assoc("SELECT id, data_input_field_id\n\t\t\t\tFROM data_template_rrd\n\t\t\t\tWHERE local_data_id='{$local_data_id}'\n\t\t\t\tAND data_source_name='{$data_source_name}'");
            $int = array('id', 'data_template_id', 'data_source_id', 'thold_fail_trigger', 'bl_ref_time_range', 'bl_pct_down', 'bl_pct_up', 'bl_fail_trigger', 'bl_alert', 'repeat_alert', 'cdef');
            foreach ($rrdlist as $rrdrow) {
                $data_rrd_id = $rrdrow['id'];
                $insert['data_template_rrd_id'] = $data_rrd_id;
                $existing = db_fetch_assoc("SELECT id\n\t\t\t\t\tFROM thold_data\n\t\t\t\t\tWHERE local_data_id='{$local_data_id}'\n\t\t\t\t\tAND data_template_rrd_id='{$data_rrd_id}'\n\t\t\t\t\tAND thold_template_id='" . $template['id'] . "' AND template_enabled='on'");
                if (count($existing) == 0) {
                    $insert['id'] = 0;
                    $id = sql_save($insert, 'thold_data');
                    if ($id) {
                        thold_template_update_threshold($id, $insert['template']);
                        $l = db_fetch_assoc("SELECT name FROM data_template where id={$data_template_id}");
                        $tname = $l[0]['name'];
                        $name = $data_source_name;
                        if ($rrdrow['data_input_field_id'] != 0) {
                            $l = db_fetch_assoc('SELECT name FROM data_input_fields where id=' . $rrdrow['data_input_field_id']);
                            $name = $l[0]['name'];
                        }
                        plugin_thold_log_changes($id, 'created', " {$tname} [{$name}]");
                        $message .= "Created threshold for the Graph '<i>{$tname}</i>' using the Data Source '<i>{$name}</i>'<br>";
                    }
                }
            }
        }
    }
    if (strlen($message)) {
        $_SESSION['thold_message'] = "<font size=-2>{$message}</font>";
    } else {
        $_SESSION['thold_message'] = "<font size=-2>" . __('Threshold(s) Already Exists - No Thresholds Created') . "</font>";
    }
    raise_message('thold_message');
    if (isset($_SESSION['graph_return'])) {
        $return_to = $_SESSION['graph_return'];
        unset($_SESSION['graph_return']);
        kill_session_var('graph_return');
        header('Location: ' . $return_to . (strpos($return_to, '?') !== false ? '&' : '?') . 'header=false');
    } else {
        header('Location:' . $config['url_path'] . 'plugins/thold/thold.php?header=false');
    }
}
Example #23
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

	html_start_box("<strong>Graph Management</strong>", "100%", $colors["header"], "3", "center", "graphs.php?action=graph_edit&host_id=" . get_request_var_request("host_id"));

	?>
	<tr bgcolor="<?php print $colors["panel"];?>">
		<form name="form_graph_id">
		<td>
			<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>
							<option value="0"<?php if (get_request_var_request("host_id") == "0") {?> selected<?php }?>>None</option>
							<?php
							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
									FROM (graph_templates_graph,host)
									LEFT JOIN graph_local ON (graph_local.host_id=host.id)
									LEFT JOIN graph_templates ON (graph_templates.id=graph_local.graph_template_id)
									LEFT 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"] . "))
									WHERE graph_templates_graph.local_graph_id=graph_local.id
									" . (empty($sql_where) ? "" : "and $sql_where") . "
									ORDER BY name");
							}else{
								$hosts = db_fetch_assoc("SELECT DISTINCT host.id, CONCAT_WS('',host.description,' (',host.hostname,')') as name
									FROM host
									ORDER BY name");
							}

							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($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>
							<option value="0"<?php if (get_request_var_request("template_id") == "0") {?> selected<?php }?>>None</option>
							<?php
							if (read_config_option("auth_method") != 0) {
								$templates = db_fetch_assoc("SELECT DISTINCT graph_templates.id, graph_templates.name
									FROM (graph_templates_graph,graph_local)
									LEFT JOIN host ON (host.id=graph_local.host_id)
									LEFT JOIN graph_templates ON (graph_templates.id=graph_local.graph_template_id)
									LEFT 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"] . "))
									WHERE graph_templates_graph.local_graph_id=graph_local.id
									AND graph_templates.id IS NOT NULL
									" . (empty($sql_where) ? "" : "AND $sql_where") . "
									ORDER BY name");
							}else{
								$templates = db_fetch_assoc("SELECT DISTINCT graph_templates.id, graph_templates.name
									FROM graph_templates
									ORDER BY name");
							}

							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($template["name"], 40) . "</option>\n";
							}
							}
							?>
						</select>
					</td>
					<td width="120" nowrap style='white-space: nowrap;'>
						&nbsp;<input type="image" src="images/button_go.gif" alt="Go" border="0" align="absmiddle">
						<input type="image" src="images/button_clear.gif" name="clear" alt="Clear" border="0" align="absmiddle">
					</td>
				</tr>
			</table>
			<table cellpadding="1" cellspacing="0">
				<tr>
					<td width="50">
						&nbsp;Search:&nbsp;
					</td>
					<td>
						<input type="text" name="filter" size="40" value="<?php print 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 ">" . $value . "</option>\n";
							}
							}
							?>
						</select>
					</td>
				</tr>
			</table>
		</td>
		<input type='hidden' name='page' value='1'>
		</form>
	</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");
	}

	html_start_box("", "100%", $colors["header"], "3", "center", "");

	$total_rows = db_fetch_cell("SELECT
		COUNT(graph_templates_graph.id)
		FROM (graph_local,graph_templates_graph)
		LEFT JOIN graph_templates ON (graph_local.graph_template_id=graph_templates.id)
		WHERE graph_local.id=graph_templates_graph.local_graph_id
		$sql_where");

	$graph_list = db_fetch_assoc("SELECT
		graph_templates_graph.id,
		graph_templates_graph.local_graph_id,
		graph_templates_graph.height,
		graph_templates_graph.width,
		graph_templates_graph.title_cache,
		graph_templates.name,
		graph_local.host_id
		FROM (graph_local,graph_templates_graph)
		LEFT JOIN graph_templates ON (graph_local.graph_template_id=graph_templates.id)
		WHERE graph_local.id=graph_templates_graph.local_graph_id
		$sql_where
		ORDER 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"));

	/* 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"] . "'>
			<td colspan='5'>
				<table width='100%' cellspacing='0' cellpadding='0' border='0'>
					<tr>
						<td align='left' class='textHeaderDark'>
							<strong>&lt;&lt; "; if (get_request_var_request("page") > 1) { $nav .= "<a class='linkOverDark' href='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>
						</td>\n
						<td align='center' class='textHeaderDark'>
							Showing 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]
						</td>\n
						<td align='right' class='textHeaderDark'>
							<strong>"; if ((get_request_var_request("page") * get_request_var_request("graph_rows")) < $total_rows) { $nav .= "<a class='linkOverDark' href='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>
						</td>\n
					</tr>
				</table>
			</td>
		</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"));

	$i = 0;
	if (sizeof($graph_list) > 0) {
		foreach ($graph_list as $graph) {
			$template_name = ((empty($graph["name"])) ? "<em>None</em>" : $graph["name"]);
			form_alternate_row_color($colors["alternate"], $colors["light"], $i, 'line' . $graph["local_graph_id"]); $i++;
			form_selectable_cell("<a class='linkEditMain' href='graphs.php?action=graph_edit&id=" . $graph["local_graph_id"] . "' title='" . htmlspecialchars($graph["title_cache"]) . "'>" . ((get_request_var_request("filter") != "") ? eregi_replace("(" . preg_quote(get_request_var_request("filter")) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", title_trim($graph["title_cache"], read_config_option("max_title_graph"))) : title_trim($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") != "") ? eregi_replace("(" . preg_quote(get_request_var_request("filter")) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $template_name) : $template_name) . "</a>", $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";
}
Example #24
0
function api_device_save($id, $host_template_id, $description, $hostname, $snmp_community, $snmp_version,
	$snmp_username, $snmp_password, $snmp_port, $snmp_timeout, $disabled,
	$availability_method, $ping_method, $ping_port, $ping_timeout, $ping_retries,
	$notes, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context) {

	/* fetch some cache variables */
	if (empty($id)) {
		$_host_template_id = 0;
	}else{
		$_host_template_id = db_fetch_cell("select host_template_id from host where id=$id");
	}

	$save["id"] = $id;
	$save["host_template_id"]     = form_input_validate($host_template_id, "host_template_id", "^[0-9]+$", false, 3);
	$save["description"]          = form_input_validate($description, "description", "", false, 3);
	$save["hostname"]             = form_input_validate($hostname, "hostname", "", false, 3);
	$save["notes"]                = form_input_validate($notes, "notes", "", true, 3);

	$save["snmp_version"]         = form_input_validate($snmp_version, "snmp_version", "", true, 3);
	$save["snmp_community"]       = form_input_validate($snmp_community, "snmp_community", "", true, 3);

	$save["snmp_username"]        = form_input_validate($snmp_username, "snmp_username", "", true, 3);
	$save["snmp_password"]        = form_input_validate($snmp_password, "snmp_password", "", true, 3);
	$save["snmp_auth_protocol"]   = form_input_validate($snmp_auth_protocol, "snmp_auth_protocol", "", true, 3);
	$save["snmp_priv_passphrase"] = form_input_validate($snmp_priv_passphrase, "snmp_priv_passphrase", "", true, 3);
	$save["snmp_priv_protocol"]   = form_input_validate($snmp_priv_protocol, "snmp_priv_protocol", "", true, 3);
	$save["snmp_context"]         = form_input_validate($snmp_context, "snmp_context", "", true, 3);

	$save["snmp_port"]            = form_input_validate($snmp_port, "snmp_port", "^[0-9]+$", false, 3);
	$save["snmp_timeout"]         = form_input_validate($snmp_timeout, "snmp_timeout", "^[0-9]+$", false, 3);

	$save["disabled"]             = form_input_validate($disabled, "disabled", "", true, 3);

	$save["availability_method"]  = form_input_validate($availability_method, "availability_method", "^[0-9]+$", false, 3);
	$save["ping_method"]          = form_input_validate($ping_method, "ping_method", "^[0-9]+$", false, 3);
	$save["ping_port"]            = form_input_validate($ping_port, "ping_port", "^[0-9]+$", true, 3);
	$save["ping_timeout"]         = form_input_validate($ping_timeout, "ping_timeout", "^[0-9]+$", true, 3);
	$save["ping_retries"]         = form_input_validate($ping_retries, "ping_retries", "^[0-9]+$", true, 3);

	$host_id = 0;

	if (!is_error_message()) {
		$host_id = sql_save($save, "host");

		if ($host_id) {
			raise_message(1);

			/* push out relavant fields to data sources using this host */
			push_out_host($host_id, 0);

			/* the host substitution cache is now stale; purge it */
			kill_session_var("sess_host_cache_array");

			/* update title cache for graph and data source */
			update_data_source_title_cache_from_host($host_id);
			update_graph_title_cache_from_host($host_id);
		}else{
			raise_message(2);
		}

		/* if the user changes the host template, add each snmp query associated with it */
		if (($host_template_id != $_host_template_id) && (!empty($host_template_id))) {
			$snmp_queries = db_fetch_assoc("select snmp_query_id from host_template_snmp_query where host_template_id=$host_template_id");

			if (sizeof($snmp_queries) > 0) {
			foreach ($snmp_queries as $snmp_query) {
				db_replace("host_snmp_query",array("host_id"=>$host_id,"snmp_query_id"=>$snmp_query["snmp_query_id"],"reindex_method"=>DATA_QUERY_AUTOINDEX_BACKWARDS_UPTIME),array("host_id","snmp_query_id"),true);

				/* recache snmp data */
				run_data_query($host_id, $snmp_query["snmp_query_id"]);
			}
			}

			$graph_templates = db_fetch_assoc("select graph_template_id from host_template_graph where host_template_id=$host_template_id");

			if (sizeof($graph_templates) > 0) {
			foreach ($graph_templates as $graph_template) {
				db_replace("host_graph",array("host_id"=>$host_id,"graph_template_id"=>$graph_template["graph_template_id"]),array("host_id","graph_template_id"),true);
			}
			}
		}
	}

	return $host_id;
}
Example #25
0
function graphs()
{
    global $item_rows;
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_request('host_id'));
    input_validate_input_number(get_request_var_request('graph_type'));
    input_validate_input_number(get_request_var_request('rows'));
    /* ==================================================== */
    /* clean up search string */
    if (isset($_REQUEST['filter'])) {
        $_REQUEST['filter'] = sanitize_search_string(get_request_var_request('filter'));
    }
    /* if the user pushed the 'clear' button */
    if (isset($_REQUEST['clear_x'])) {
        kill_session_var('sess_graphs_new_filter');
        kill_session_var('sess_default_rows');
        unset($_REQUEST['filter']);
        unset($_REQUEST['rows']);
        $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');
        $changed += check_changed('rows', 'sess_default_rows');
    }
    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', '');
    load_current_session_value('rows', 'sess_default_rows', read_config_option('num_rows_table'));
    if (!empty($_REQUEST['host_id'])) {
        $host = db_fetch_row_prepared('SELECT id, description, hostname, host_template_id FROM host WHERE id = ?', array($_REQUEST['host_id']));
        $header = ' [ ' . htmlspecialchars($host['description']) . ' (' . htmlspecialchars($host['hostname']) . ') ' . (!empty($host['host_template_id']) ? htmlspecialchars(db_fetch_cell_prepared('SELECT name FROM host_template WHERE id = ?', array($host['host_template_id']))) : '') . ' ]';
    } else {
        $host = array();
        $header = 'None Host Type';
    }
    $row_limit = get_request_var_request('rows');
    html_start_box("<strong>New Graphs for</strong> {$header}", '100%', '', '3', 'center', '');
    form_alternate_row();
    print '<td class="even">';
    ?>
	<script type='text/javascript'>
	<!--

	function applyFilter() {
		strURL = '?graph_type=' + $('#graph_type').val();
		strURL = strURL + '&host_id=' + $('#host_id').val();
		strURL = strURL + '&filter=' + $('#filter').val();;
		strURL = strURL + '&rows=' + $('#rows').val();;
		document.location = strURL;
	}

	-->
	</script>
	<form name='form_graphs_new' action='graphs_new.php'>
	<table width='100%' cellpadding='2' cellspacing='0' border='0' align='left'>
		<tr>
			<?php 
    print html_host_filter($_REQUEST['host_id']);
    ?>
			<td style='white-space:nowrap;' width='1'>
				Graph Types
			</td>
			<td width='1'>
				<select id='graph_type' name='graph_type' onChange='applyFilter()'>
					<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_prepared('SELECT
						snmp_query.id,
						snmp_query.name,
						snmp_query.xml_path
						FROM (snmp_query, host_snmp_query)
						WHERE host_snmp_query.snmp_query_id = snmp_query.id
						AND host_snmp_query.host_id = ?
						ORDER BY snmp_query.name', array($host['id']));
    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 width='50'>
				Rows
			</td>
			<td>
				<select id='rows' name='rows' onChange='applyFilter()'>
					<?php 
    if (sizeof($item_rows) > 0) {
        foreach ($item_rows as $key => $value) {
            print "<option value='" . $key . "'";
            if (get_request_var_request('rows') == $key) {
                print ' selected';
            }
            print '>' . htmlspecialchars($value) . "</option>\n";
        }
    }
    ?>
				</select>
			</td>
			<td rowspan='3' class='textInfo' align='right' valign='top'>
				<span class='linkMarker'>*</span><a class='hyperLink' href='<?php 
    print htmlspecialchars('host.php?action=edit&id=' . $_REQUEST['host_id']);
    ?>
'>Edit this Device</a><br>
				<span class='linkMarker'>*</span><a class='hyperLink' href='<?php 
    print htmlspecialchars('host.php?action=edit');
    ?>
'>Create New Device</a><br>
				<?php 
    api_plugin_hook('graphs_new_top_links');
    ?>
			</td>
		</tr>
		<tr style='<?php 
    if ($_REQUEST['graph_type'] <= 0) {
        ?>
display:none;<?php 
    }
    ?>
'>
			<td width='50'>
				Search
			</td>
			<td style='white-space:nowrap;'>
				<input id='filter' type='text' name='filter' size='25' value='<?php 
    print htmlspecialchars(get_request_var_request('filter'));
    ?>
'>
			</td>
			<td colspan='3' style='white-space:nowrap;'>
				<input type='submit' value='Go' title='Set/Refresh Filters'>
				<input type='submit' name='clear_x' value='Clear' title='Clear Filters'>
			</td>
		</tr>
	</table>
	</form>
	</td>
	</tr>

	<?php 
    html_end_box();
    ?>

	<form name='chk' method='post' action='graphs_new.php'>
	<?php 
    $total_rows = sizeof(db_fetch_assoc_prepared('SELECT graph_template_id FROM host_graph WHERE host_id = ?', array($_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%', '', '3', 'center', '');
        print "<tr class='tableHeader'>\n\t\t\t\t<td class='tableSubHeaderColumn'>Graph Template Name</td>\n\t\t\t\t<td width='1%' align='center' class='tableSubHeaderCheckbox' style='" . get_checkbox_style() . "'><input type='checkbox' style='margin: 0px;' name='all_cg' title='Select All' onClick='SelectAll(\"sg\",this.checked);'></td>\n\n\t\t\t</tr>\n";
        $graph_templates = db_fetch_assoc_prepared('SELECT
			graph_templates.id AS graph_template_id,
			graph_templates.name AS graph_template_name
			FROM (host_graph, graph_templates)
			WHERE host_graph.graph_template_id = graph_templates.id
			AND host_graph.host_id = ?
			ORDER BY graph_templates.name', array($_REQUEST['host_id']));
        if (!empty($_REQUEST['host_id'])) {
            $template_graphs = db_fetch_assoc_prepared('SELECT
				graph_local.graph_template_id
				FROM (graph_local, host_graph)
				WHERE graph_local.graph_template_id = host_graph.graph_template_id
				AND graph_local.host_id = host_graph.host_id
				AND graph_local.host_id = ?
				GROUP BY graph_local.graph_template_id', array($host['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}' class='selectable " . ($i % 2 == 0 ? 'odd' : 'even') . "'>";
                $i++;
                print "<td>\n\t\t\t\t\t\t<span id='gt_text{$query_row}" . "_0'>" . htmlspecialchars($graph_template['graph_template_name']) . "</span>\n\t\t\t\t\t</td>\n\t\t\t\t\t<td align='right' class='checkbox'>\n\t\t\t\t\t\t<input type='checkbox' name='cg_{$query_row}' id='cg_{$query_row}'>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>";
            }
        }
        html_end_box();
        html_start_box('', '100%', '', '3', 'center', '');
        $available_graph_templates = db_fetch_assoc('SELECT
			graph_templates.id, graph_templates.name
			FROM snmp_query_graph RIGHT JOIN graph_templates
			ON (snmp_query_graph.graph_template_id = graph_templates.id)
			WHERE (((snmp_query_graph.name) Is Null)) ORDER BY graph_templates.name');
        /* create a row at the bottom that lets the user create any graph they choose */
        print "\t<tr class='even'>\n\t\t\t\t<td width='1'><i>Create</i></td>\n\t\t\t\t<td align='left'>";
        form_dropdown('cg_g', $available_graph_templates, 'name', 'id', '', '(Select a graph type to create)', '', 'textArea');
        print '</td>
			</tr>';
        html_end_box();
    }
    if ($_REQUEST['graph_type'] != -1 && !empty($_REQUEST['host_id'])) {
        $snmp_queries = db_fetch_assoc('SELECT
			snmp_query.id,
			snmp_query.name,
			snmp_query.xml_path
			FROM (snmp_query,host_snmp_query)
			WHERE host_snmp_query.snmp_query_id=snmp_query.id
			AND host_snmp_query.host_id=' . $host['id'] . ($_REQUEST['graph_type'] != -2 ? ' AND snmp_query.id=' . $_REQUEST['graph_type'] : '') . '
			ORDER 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_prepared('SELECT count(*) FROM host_snmp_cache WHERE host_id = ? AND snmp_query_id = ? AND field_name = ?', array($host['id'], $snmp_query['id'], $field_name));
                            }
                        }
                    }
                }
                if (!isset($total_rows)) {
                    $total_rows = 0;
                }
                $snmp_query_graphs = db_fetch_assoc_prepared('SELECT snmp_query_graph.id,snmp_query_graph.name FROM snmp_query_graph WHERE snmp_query_graph.snmp_query_id = ? ORDER BY snmp_query_graph.name', array($snmp_query['id']));
                if (sizeof($snmp_query_graphs) > 0) {
                    foreach ($snmp_query_graphs as $snmp_query_graph) {
                        $created_graphs = db_fetch_assoc_prepared("SELECT DISTINCT\n\t\t\t\t\t\tdata_local. snmp_index\n\t\t\t\t\t\tFROM (data_local, data_template_data)\n\t\t\t\t\t\tLEFT JOIN data_input_data ON (data_template_data.id = data_input_data.data_template_data_id)\n\t\t\t\t\t\tLEFT JOIN data_input_fields ON (data_input_data.data_input_field_id = data_input_fields.id)\n\t\t\t\t\t\tWHERE data_local.id = data_template_data.local_data_id\n\t\t\t\t\t\tAND data_input_fields.type_code = 'output_type'\n\t\t\t\t\t\tAND data_input_data.value = ?\n\t\t\t\t\t\tAND data_local.host_id = ?", array($snmp_query_graph['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%' class='cactiTable' align='center' cellpadding='3' cellspacing='0'>\n\n\t\t\t\t\t<tr class='cactiTableTitle'>\n\t\t\t\t\t\t<td colspan='" . ($num_input_fields + 1) . "'>\n\t\t\t\t\t\t\t<table  cellspacing='0' cellpadding='0' width='100%' >\n\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t<td class='textHeaderDark'>\n\t\t\t\t\t\t\t\t\t\t<strong>Data Query</strong> [" . $snmp_query['name'] . "]\n\t\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t\t\t<td align='right' nowrap>\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='absmiddle'></a>\n\t\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t</table>\n\t\t\t\t\t\t</td>\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\n\t\t\t\t\t\tFROM host_snmp_cache\n\t\t\t\t\t\tWHERE field_value LIKE '%%" . $_REQUEST['filter'] . "%%'\n\t\t\t\t\t\tAND snmp_query_id=" . $snmp_query['id'] . "\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_prepared('SELECT DISTINCT field_name
						FROM host_snmp_cache
						WHERE host_id = ?
						AND snmp_query_id = ?', array($host['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
						WHERE host_id=' . $host['id'] . '
						AND snmp_query_id=' . $snmp_query['id'] . "\n\t\t\t\t\t\t{$sql_where}\n\t\t\t\t\t\tGROUP BY host_id, snmp_query_id, snmp_index\n\t\t\t\t\t\t{$sql_order}\n\t\t\t\t\t\tLIMIT " . $row_limit * ($page - 1) . ',' . $row_limit;
                        $rows_query = 'SELECT host_id, snmp_query_id, snmp_index
						FROM host_snmp_cache
						WHERE host_id=' . $host['id'] . '
						AND snmp_query_id=' . $snmp_query['id'] . "\n\t\t\t\t\t\t{$sql_where}\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');
                        }
                        $nav = html_nav_bar('graphs_new.php', MAX_DISPLAY_PAGES, $page, $row_limit, $total_rows, 15, 'Items', 'page' . $snmp_query['id']);
                        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 class='tableSubHeaderColumn'>" . $field_array['name'] . "</td>\n";
                                        break;
                                    }
                                }
                            }
                        }
                        if (!sizeof($snmp_query_indexes)) {
                            print "<tr class='odd'><td>This Data Query returned 0 rows, perhaps there was a problem executing this\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 Query in debug mode</a> to get more information.</td></tr>\n";
                        } else {
                            print "<tr class='tableHeader'>\n\t\t\t\t\t\t\t\t{$html_dq_header}\n\t\t\t\t\t\t\t\t<td width='1%' align='center' class='tableSubHeaderCheckbox' 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)'></td>\n\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}' class='selectable " . ($row_counter % 2 == 0 ? 'odd' : 'even') . "'>";
                                $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><span id='text{$query_row}" . '_' . $column_counter . "'>" . (strlen($_REQUEST['filter']) ? preg_replace('/(' . preg_quote($_REQUEST['filter']) . ')/i', "<span class='filteredValue'>\\1</span>", $row[$field_name]) : $row[$field_name]) . '</span></td>';
                                            } else {
                                                print "<td><span id='text{$query_row}" . '_' . $column_counter . "'></span></td>";
                                            }
                                            $column_counter++;
                                        }
                                    }
                                }
                                print "<td class='checkbox' align='right'>";
                                print "<input type='checkbox' name='sg_{$query_row}' id='sg_{$query_row}'>";
                                print '</td>';
                                print "</tr>\n";
                                $row_counter++;
                            }
                        }
                        if ($total_rows > $row_limit) {
                            print $nav;
                        }
                    } else {
                        print "<tr class='odd'><td class='textError'>Search Returned no Rows.</td></tr>\n";
                    }
                } else {
                    print "<tr class='odd'><td class='textError'>Error in data query.</td></tr>\n";
                }
                print '</table>';
                /* draw the graph template drop down here */
                $data_query_graphs = db_fetch_assoc_prepared('SELECT snmp_query_graph.id, snmp_query_graph.name FROM snmp_query_graph WHERE snmp_query_graph.snmp_query_id = ? ORDER BY snmp_query_graph.name', array($snmp_query['id']));
                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%'>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td width='100%' valign='middle'>\n\t\t\t\t\t\t\t\t<img src='images/arrow.gif' align='absmiddle' alt=''>\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t<td style='white-space:nowrap;font-style: italic;'' align='right'>\n\t\t\t\t\t\t\t\tSelect a Graph Type to Create\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t<td align='right'>\n\t\t\t\t\t\t\t\t<select name='sgg_" . $snmp_query['id'] . "' id='sgg_" . $snmp_query['id'] . "' onChange='dqUpdateDeps(" . $snmp_query['id'] . ',' . (isset($column_counter) ? $column_counter : '') . ");'>\n\t\t\t\t\t\t\t\t\t";
                    html_create_list($data_query_graphs, 'name', 'id', '0');
                    print "\n\t\t\t\t\t\t\t\t</select>\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</table>\n";
                }
                print '<br>';
                $script .= 'dqUpdateDeps(' . $snmp_query['id'] . ',' . $num_visible_fields . ");\n";
            }
        }
    }
    if (strlen($script)) {
        $script .= "</script>\n";
        print $script;
    }
    form_hidden_box('save_component_graph', '1', '');
    if (!empty($_REQUEST['host_id'])) {
        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', '');
    form_save_button($_REQUEST['returnto']);
}
Example #26
0
function syslog_alerts()
{
    global $colors, $syslog_actions, $config, $message_types, $severities;
    include dirname(__FILE__) . "/config.php";
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_request("id"));
    input_validate_input_number(get_request_var_request("page"));
    input_validate_input_number(get_request_var_request("enabled"));
    input_validate_input_number(get_request_var_request("rows"));
    /* ==================================================== */
    /* clean up filter */
    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 sort direction */
    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"])) {
        kill_session_var("sess_syslog_alerts_page");
        kill_session_var("sess_syslog_alerts_rows");
        kill_session_var("sess_syslog_alerts_filter");
        kill_session_var("sess_syslog_alerts_enabled");
        kill_session_var("sess_syslog_alerts_sort_column");
        kill_session_var("sess_syslog_alerts_sort_direction");
        $_REQUEST["page"] = 1;
        unset($_REQUEST["filter"]);
        unset($_REQUEST["enabled"]);
        unset($_REQUEST["rows"]);
        unset($_REQUEST["sort_column"]);
        unset($_REQUEST["sort_direction"]);
    } else {
        /* if any of the settings changed, reset the page number */
        $changed = 0;
        $changed += syslog_check_changed("filter", "sess_syslog_alerts_filter");
        $changed += syslog_check_changed("enabled", "sess_syslog_alerts_enabled");
        $changed += syslog_check_changed("rows", "sess_syslog_alerts_rows");
        $changed += syslog_check_changed("sort_column", "sess_syslog_alerts_sort_column");
        $changed += syslog_check_changed("sort_direction", "sess_syslog_alerts_sort_direction");
        if ($changed) {
            $_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_syslog_alerts_paage", "1");
    load_current_session_value("rows", "sess_syslog_alerts_rows", "-1");
    load_current_session_value("enabled", "sess_syslog_alerts_enabled", "-1");
    load_current_session_value("filter", "sess_syslog_alerts_filter", "");
    load_current_session_value("sort_column", "sess_syslog_alerts_sort_column", "name");
    load_current_session_value("sort_direction", "sess_syslog_alerts_sort_direction", "ASC");
    html_start_box("<strong>Syslog Alert Filters</strong>", "100%", $colors["header"], "3", "center", "syslog_alerts.php?action=edit");
    syslog_filter();
    html_end_box();
    html_start_box("", "100%", $colors["header"], "3", "center", "");
    $sql_where = "";
    if ($_REQUEST["rows"] == "-1") {
        $row_limit = read_config_option("num_rows_syslog");
    } elseif ($_REQUEST["rows"] == -2) {
        $row_limit = 999999;
    } else {
        $row_limit = $_REQUEST["rows"];
    }
    $alerts = syslog_get_alert_records($sql_where, $row_limit);
    $rows_query_string = "SELECT COUNT(*)\n\t\tFROM `" . $syslogdb_default . "`.`syslog_alert`\n\t\t{$sql_where}";
    $total_rows = syslog_db_fetch_cell($rows_query_string);
    ?>
	<script type="text/javascript">
	<!--
	function applyChange(objForm) {
		strURL = '?enabled=' + objForm.enabled.value;
		strURL = strURL + '&filter=' + objForm.filter.value;
		strURL = strURL + '&rows=' + objForm.rows.value;
		document.location = strURL;
	}
	-->
	</script>
	<?php 
    /* generate page list */
    $url_page_select = get_page_list($_REQUEST["page"], MAX_DISPLAY_PAGES, $row_limit, $total_rows, "syslog_alerts.php?filter=" . $_REQUEST["filter"]);
    if ($total_rows > 0) {
        $nav = "<tr bgcolor='#" . $colors["header"] . "'>\n\t\t\t\t\t<td colspan='13'>\n\t\t\t\t\t\t<table width='100%' cellspacing='0' cellpadding='0' border='0'>\n\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t<td align='left' class='textHeaderDark'>\n\t\t\t\t\t\t\t\t\t<strong>&lt;&lt; ";
        if ($_REQUEST["page"] > 1) {
            $nav .= "<a class='linkOverDark' href='syslog_alerts.php?report=arp&page=" . ($_REQUEST["page"] - 1) . "'>";
        }
        $nav .= "Previous";
        if ($_REQUEST["page"] > 1) {
            $nav .= "</a>";
        }
        $nav .= "</strong>\n\t\t\t\t\t\t\t\t</td>\n\n\t\t\t\t\t\t\t\t<td align='center' class='textHeaderDark'>\n\t\t\t\t\t\t\t\t\tShowing Rows " . ($total_rows == 0 ? "None" : $row_limit * ($_REQUEST["page"] - 1) + 1 . " to " . ($total_rows < $row_limit || $total_rows < $row_limit * $_REQUEST["page"] ? $total_rows : $row_limit * $_REQUEST["page"]) . " of {$total_rows} [{$url_page_select}]") . "\n\t\t\t\t\t\t\t\t</td>\n\n\t\t\t\t\t\t\t\t<td align='right' class='textHeaderDark'>\n\t\t\t\t\t\t\t\t\t<strong>";
        if ($_REQUEST["page"] * $row_limit < $total_rows) {
            $nav .= "<a class='linkOverDark' href='syslog_alerts.php?report=arp&page=" . ($_REQUEST["page"] + 1) . "'>";
        }
        $nav .= "Next";
        if ($_REQUEST["page"] * $row_limit < $total_rows) {
            $nav .= "</a>";
        }
        $nav .= " &gt;&gt;</strong>\n\t\t\t\t\t\t\t\t</td>\n\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t</table>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n";
    } else {
        $nav = "<tr bgcolor='#" . $colors["header"] . "' class='noprint'>\n\t\t\t\t\t<td colspan='22'>\n\t\t\t\t\t\t<table width='100%' cellspacing='0' cellpadding='0' border='0'>\n\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t<td align='center' class='textHeaderDark'>\n\t\t\t\t\t\t\t\t\tNo Rows Found\n\t\t\t\t\t\t\t\t</td>\n\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t</table>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n";
    }
    print $nav;
    $display_text = array("name" => array("Alert<br>Name", "ASC"), "severity" => array("<br>Severity", "ASC"), "method" => array("<br>Method", "ASC"), "num" => array("Threshold<br>Count", "ASC"), "enabled" => array("<br>Enabled", "ASC"), "type" => array("Match<br>Type", "ASC"), "message" => array("Search<br>String", "ASC"), "email" => array("E-Mail<br>Addresses", "DESC"), "date" => array("Last<br>Modified", "ASC"), "user" => array("By<br>User", "DESC"));
    html_header_sort_checkbox($display_text, $_REQUEST["sort_column"], $_REQUEST["sort_direction"]);
    $i = 0;
    if (sizeof($alerts) > 0) {
        foreach ($alerts as $alert) {
            form_alternate_row_color($colors["alternate"], $colors["light"], $i, 'line' . $alert["id"]);
            $i++;
            form_selectable_cell("<a class='linkEditMain' href='" . $config['url_path'] . "plugins/syslog/syslog_alerts.php?action=edit&id=" . $alert["id"] . "'>" . ($_REQUEST["filter"] != "" ? eregi_replace("(" . preg_quote($_REQUEST["filter"]) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $alert["name"]) : $alert["name"]) . "</a>", $alert["id"]);
            form_selectable_cell($severities[$alert["severity"]], $alert["id"]);
            form_selectable_cell($alert["method"] == 1 ? "Threshold" : "Individual", $alert["id"]);
            form_selectable_cell($alert["method"] == 1 ? $alert["num"] : "N/A", $alert["id"]);
            form_selectable_cell($alert["enabled"] == "on" ? "Yes" : "No", $alert["id"]);
            form_selectable_cell($message_types[$alert["type"]], $alert["id"]);
            form_selectable_cell(title_trim($alert["message"], 60), $alert["id"]);
            form_selectable_cell(substr_count($alert["email"], ",") ? "Multiple" : $alert["email"], $alert["id"]);
            form_selectable_cell(date("Y-m-d H:i:s", $alert["date"]), $alert["id"]);
            form_selectable_cell($alert["user"], $alert["id"]);
            form_checkbox_cell($alert["name"], $alert["id"]);
            form_end_row();
        }
    } else {
        print "<tr><td colspan='4'><em>No Syslog Alerts Defined</em></td></tr>";
    }
    html_end_box(false);
    /* draw the dropdown containing a list of available actions for this form */
    draw_actions_dropdown($syslog_actions);
}
Example #27
0
	}

	/* don't even bother with the guest code if we're already logged in */
	if ((isset($guest_account)) && (empty($_SESSION["sess_user_id"]))) {
		$guest_user_id = db_fetch_cell("select id from user_auth where username='******'");

		/* cannot find guest user */
		if (!empty($guest_user_id)) {
			$_SESSION["sess_user_id"] = $guest_user_id;
		}
	}

	/* if we are a guest user in a non-guest area, wipe credentials */
	if (!empty($_SESSION["sess_user_id"])) {
		if ((!isset($guest_account)) && (db_fetch_cell("select id from user_auth where username='******'") == $_SESSION["sess_user_id"])) {
			kill_session_var("sess_user_id");
		}
	}

	if (empty($_SESSION["sess_user_id"])) {
		include("./auth_login.php");
		exit;
	}elseif (!empty($_SESSION["sess_user_id"])) {
		$realm_id = 0;

		if (isset($user_auth_realm_filenames{basename($_SERVER["PHP_SELF"])})) {
			$realm_id = $user_auth_realm_filenames{basename($_SERVER["PHP_SELF"])};
		}

		if ((!db_fetch_assoc("select
			user_auth_realm.realm_id
Example #28
0
function host() {
	global $colors, $device_actions;

	/* 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");

		unset($_REQUEST["page"]);
		unset($_REQUEST["filter"]);
		unset($_REQUEST["host_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_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");

	html_start_box("<strong>Devices</strong>", "98%", $colors["header"], "3", "center", "host.php?action=edit&host_template_id=" . $_REQUEST["host_template_id"]);

	include("./include/html/inc_device_filter_table.php");

	html_end_box();

	/* form the 'where' clause for our main sql query */
	$sql_where = "where host.description like '%%" . $_REQUEST["filter"] . "%%'";

	if ($_REQUEST["host_template_id"] == "-1") {
		/* Show all items */
	}elseif ($_REQUEST["host_template_id"] == "0") {
		$sql_where .= " and host.host_template_id=0";
	}elseif (!empty($_REQUEST["host_template_id"])) {
		$sql_where .= " and host.host_template_id=" . $_REQUEST["host_template_id"];
	}

	html_start_box("", "98%", $colors["header"], "3", "center", "");

	$total_rows = db_fetch_cell("select
		COUNT(host.id)
		from host
		$sql_where");

	$hosts = db_fetch_assoc("select
		host.id,
		host.disabled,
		host.status,
		host.hostname,
		host.description,
		host.min_time,
		host.max_time,
		host.cur_time,
		host.avg_time,
		host.availability
		from host
		$sql_where
		order by host.description
		limit " . (read_config_option("num_rows_device")*($_REQUEST["page"]-1)) . "," . read_config_option("num_rows_device"));

	/* generate page list */
	$url_page_select = get_page_list($_REQUEST["page"], MAX_DISPLAY_PAGES, read_config_option("num_rows_device"), $total_rows, "host.php?filter=" . $_REQUEST["filter"] . "&host_template_id=" . $_REQUEST["host_template_id"]);

	$nav = "<tr bgcolor='#" . $colors["header"] . "'>
			<td colspan='7'>
				<table width='100%' cellspacing='0' cellpadding='0' border='0'>
					<tr>
						<td align='left' class='textHeaderDark'>
							<strong>&lt;&lt; "; if ($_REQUEST["page"] > 1) { $nav .= "<a class='linkOverDark' href='host.php?filter=" . $_REQUEST["filter"] . "&host_template_id=" . $_REQUEST["host_template_id"] . "&page=" . ($_REQUEST["page"]-1) . "'>"; } $nav .= "Previous"; if ($_REQUEST["page"] > 1) { $nav .= "</a>"; } $nav .= "</strong>
						</td>\n
						<td align='center' class='textHeaderDark'>
							Showing Rows " . ((read_config_option("num_rows_device")*($_REQUEST["page"]-1))+1) . " to " . ((($total_rows < read_config_option("num_rows_device")) || ($total_rows < (read_config_option("num_rows_device")*$_REQUEST["page"]))) ? $total_rows : (read_config_option("num_rows_device")*$_REQUEST["page"])) . " of $total_rows [$url_page_select]
						</td>\n
						<td align='right' class='textHeaderDark'>
							<strong>"; if (($_REQUEST["page"] * read_config_option("num_rows_device")) < $total_rows) { $nav .= "<a class='linkOverDark' href='host.php?filter=" . $_REQUEST["filter"] . "&host_template_id=" . $_REQUEST["host_template_id"] . "&page=" . ($_REQUEST["page"]+1) . "'>"; } $nav .= "Next"; if (($_REQUEST["page"] * read_config_option("num_rows_device")) < $total_rows) { $nav .= "</a>"; } $nav .= " &gt;&gt;</strong>
						</td>\n
					</tr>
				</table>
			</td>
		</tr>\n";

	print $nav;

	html_header_checkbox(array("Description", "Status", "Hostname", "Current (ms)", "Average (ms)", "Availability"));

	$i = 0;
	if (sizeof($hosts) > 0) {
		foreach ($hosts as $host) {
			form_alternate_row_color($colors["alternate"],$colors["light"],$i); $i++;
				?>
				<td width=200>
					<a class="linkEditMain" href="host.php?action=edit&id=<?php print $host["id"];?>"><?php print eregi_replace("(" . preg_quote($_REQUEST["filter"]) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $host["description"]);?></a>
				</td>
				<td>
					<?php print get_colored_device_status(($host["disabled"] == "on" ? true : false), $host["status"]);?>
				</td>
				<td>
					<?php print $host["hostname"];?>
				</td>
				<td>
					<?php print round(($host["cur_time"]), 2);?>
				</td>
				<td>
					<?php print round(($host["avg_time"]), 2);?>
				</td>
				<td>
					<?php print round($host["availability"], 2);?>%
				</td>
				<td style="<?php print get_checkbox_style();?>" width="1%" align="right">
					<input type='checkbox' style='margin: 0px;' name='chk_<?php print $host["id"];?>' title="<?php print $host["description"];?>">
				</td>
			</tr>
			<?php
		}

		/* 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);

	/* draw the dropdown containing a list of available actions for this form */
	draw_actions_dropdown($device_actions);
}
function mactrack_view() {
	global $title, $colors, $mactrack_rows, $config;

	/* ================= input validation ================= */
	input_validate_input_number(get_request_var_request("rows"));
	input_validate_input_number(get_request_var_request("page"));
	input_validate_input_number(get_request_var_request("issues"));
	input_validate_input_number(get_request_var_request("bwusage"));
	input_validate_input_number(get_request_var_request("device"));
	input_validate_input_number(get_request_var_request("site"));
	input_validate_input_number(get_request_var_request("type"));
	/* ==================================================== */

	/* clean up filter */
	if (isset($_REQUEST["filter"])) {
		$_REQUEST["filter"] = sanitize_search_string(get_request_var("filter"));
	}

	/* clean up totals */
	if (isset($_REQUEST["totals"])) {
		$_REQUEST["totals"] = sanitize_search_string(get_request_var("totals"));
	}

	/* clean up */
	if (isset($_REQUEST["sort_column"])) {
		$_REQUEST["sort_column"] = sanitize_search_string(get_request_var("sort_column"));
	}

	/* clean up */
	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"]) || isset($_REQUEST["reset"])) {
		kill_session_var("sess_mactrack_int_current_page");
		kill_session_var("sess_mactrack_int_rows");
		kill_session_var("sess_mactrack_int_totals");
		kill_session_var("sess_mactrack_int_device_id");
		kill_session_var("sess_mactrack_int_state");
		kill_session_var("sess_mactrack_int_site");
		kill_session_var("sess_mactrack_int_device");
		kill_session_var("sess_mactrack_int_issues");
		kill_session_var("sess_mactrack_int_bwusage");
		kill_session_var("sess_mactrack_int_type");
		kill_session_var("sess_mactrack_int_period");
		kill_session_var("sess_mactrack_int_filter");
		kill_session_var("sess_mactrack_int_sort_column");
		kill_session_var("sess_mactrack_int_sort_direction");

		$_REQUEST["page"] = 1;

		if (isset($_REQUEST["clear_x"])) {
			unset($_REQUEST["device_id"]);
			unset($_REQUEST["totals"]);
			unset($_REQUEST["state"]);
			unset($_REQUEST["site"]);
			unset($_REQUEST["totals"]);
			unset($_REQUEST["device"]);
			unset($_REQUEST["issues"]);
			unset($_REQUEST["bwusage"]);
			unset($_REQUEST["type"]);
			unset($_REQUEST["period"]);
			unset($_REQUEST["filter"]);
			unset($_REQUEST["rows"]);
			unset($_REQUEST["sort_column"]);
			unset($_REQUEST["sort_direction"]);
		}
	}else{
		/* if any of the settings changed, reset the page number */
		$changed = 0;
		$changed += mactrack_check_changed("device_id", "sess_mactrack_int_device_id");
		$changed += mactrack_check_changed("site", "sess_mactrack_int_site");
		$changed += mactrack_check_changed("totals", "sess_mactrack_int_totals");
		$changed += mactrack_check_changed("device", "sess_mactrack_int_device");
		$changed += mactrack_check_changed("issues", "sess_mactrack_int_issues");
		$changed += mactrack_check_changed("bwusage", "sess_mactrack_int_bwusage");
		$changed += mactrack_check_changed("type", "sess_mactrack_int_type");
		$changed += mactrack_check_changed("period", "sess_mactrack_int_period");
		$changed += mactrack_check_changed("filter", "sess_mactrack_int_filter");
		$changed += mactrack_check_changed("rows", "sess_mactrack_int_rows");
		$changed += mactrack_check_changed("sort_column", "sess_mactrack_int_sort_column");
		$changed += mactrack_check_changed("sort_direction", "sess_mactrack_int_sort_direction");

		if ($changed) {
			$_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_mactrack_int_current_page", "1");
	load_current_session_value("totals", "sess_mactrack_int_totals", "on");
	load_current_session_value("rows", "sess_mactrack_int_rows", read_config_option("num_rows_device"));
	load_current_session_value("device_id", "sess_mactrack_int_device_id", "-1");
	load_current_session_value("site", "sess_mactrack_int_site", "-1");
	load_current_session_value("issues", "sess_mactrack_int_issues", "-3");
	load_current_session_value("bwusage", "sess_mactrack_int_bwusage", read_config_option("mactrack_interface_high"));
	load_current_session_value("type", "sess_mactrack_int_type", "-1");
	load_current_session_value("device", "sess_mactrack_int_device", "-1");
	load_current_session_value("period", "sess_mactrack_int_period", "-2");
	load_current_session_value("filter", "sess_mactrack_int_filter", "");
	load_current_session_value("sort_column", "sess_mactrack_int_sort_column", "device_name");
	load_current_session_value("sort_direction", "sess_mactrack_int_sort_direction", "DESC");

	include_once("./plugins/mactrack/general_header.php");
	print "<script type='text/javascript' src='" . $config["url_path"] . "plugins/mactrack/mactrack.js'></script>";

	$sql_where  = "";

	if ($_REQUEST["rows"] == -1) {
		$row_limit = read_config_option("num_rows_device");
	}elseif ($_REQUEST["rows"] == -2) {
		$row_limit = 99999999;
	}else{
		$row_limit = $_REQUEST["rows"];
	}

	$stats = mactrack_get_records($sql_where, TRUE, $row_limit);

	mactrack_tabs();
	html_start_box("<strong>Scanned Device Interfaces</strong>", "100%", $colors["header"], "3", "center", "");
	mactrack_filter_table();
	html_end_box();
	
	//Last device restart:
	if ($_REQUEST["device"]!=-1){
		html_start_box("", "100%", $colors["header"], "3", "center", "");
		print "<tr>";
		if (sizeof($stats)>0)
			$last_run_time = max(strtotime($stats[0]["last_up_time"]),strtotime($stats[0]["last_down_time"]));
		else 
			$last_run_time = read_config_option("mt_last_run_time", TRUE);
		$diff = strtotime("now") - $last_run_time;
		$upTime = ($stats[0]["sysUptime"]/100) + $diff;
		$days      = intval($upTime / (60*60*24));
		$remainder = $upTime % (60*60*24);
		$hours     = intval($remainder / (60*60));
		$remainder = $remainder % (60*60);
		$minutes   = intval($remainder / (60));
		$upTime    = $days . "d:" . $hours . "h:" . $minutes . "m";
		print "<td style='text-align:right'><strong>Last device restart:</strong> ".$upTime."</td>"; 
		print "</tr>";
		html_end_box(false);
	}
	
	html_start_box("", "100%", $colors["header"], "3", "center", "");

	$rows_query_string = "SELECT COUNT(*)
		FROM mac_track_interfaces
		INNER JOIN mac_track_devices
		ON mac_track_interfaces.device_id=mac_track_devices.device_id
		INNER JOIN mac_track_device_types
		ON mac_track_device_types.device_type_id=mac_track_devices.device_type_id
		$sql_where";

	//echo $rows_query_string;

	$total_rows = db_fetch_cell($rows_query_string);

	/* generate page list */
	if ($total_rows > 0) {
		$url_page_select = get_page_list($_REQUEST["page"], MAX_DISPLAY_PAGES, $row_limit, $total_rows, "mactrack_view_interfaces.php?report=interfaces");

		$nav = "<tr bgcolor='#" . $colors["header"] . "' class='noprint'>
					<td colspan='22'>
						<table width='100%' cellspacing='0' cellpadding='0' border='0'>
							<tr>
							<td align='left' class='textHeaderDark'>
									<strong>&lt;&lt; "; if ($_REQUEST["page"] > 1) { $nav .= "<a class='linkOverDark' href='mactrack_view_interfaces.php?page=" . ($_REQUEST["page"]-1) . "'>"; } $nav .= "Previous"; if ($_REQUEST["page"] > 1) { $nav .= "</a>"; } $nav .= "</strong>
								</td>\n
								<td align='center' class='textHeaderDark'>
									Showing Rows " . (($row_limit*($_REQUEST["page"]-1))+1) . " to " . ((($total_rows < $row_limit) || ($total_rows < ($row_limit*$_REQUEST["page"]))) ? $total_rows : ($row_limit*$_REQUEST["page"])) . " of $total_rows [$url_page_select]
								</td>\n
								<td align='right' class='textHeaderDark'>
									<strong>"; if (($_REQUEST["page"] * $row_limit) < $total_rows) { $nav .= "<a class='linkOverDark' href='mactrack_view_interfaces.php?page=" . ($_REQUEST["page"]+1) . "'>"; } $nav .= "Next"; if (($_REQUEST["page"] * $row_limit) < $total_rows) { $nav .= "</a>"; } $nav .= " &gt;&gt;</strong>
								</td>\n
							</tr>
						</table>
					</td>
				</tr>\n";
	}else{
		$nav = "<tr bgcolor='#" . $colors["header"] . "' class='noprint'>
					<td colspan='22'>
						<table width='100%' cellspacing='0' cellpadding='0' border='0'>
							<tr>
								<td align='center' class='textHeaderDark'>
									No Rows Found
								</td>\n
							</tr>
						</table>
					</td>
				</tr>\n";
	}

	print $nav;

	$display_text = mactrack_display_array();

	html_header_sort($display_text, $_REQUEST["sort_column"], $_REQUEST["sort_direction"]);

	$i = 0;
	if (sizeof($stats) > 0) {
		//$stats = order_by_name($stats);
		foreach ($stats as $stat) {
			/* find the background color and enclose it */
			$bgc = mactrack_int_row_color($stat);
			if ($bgc) {
				print "<tr id='row_" . $stat["device_id"] . "_" . $stat["ifName"] . "' style='background-color:#$bgc;'>\n"; $i++;
			}else{
				if (($i % 2) == 1) {
					$current_color = $colors["alternate"];
				}else{
					$current_color = $colors["light"];
				}
				print "<tr id='row_" . $stat["device_id"] . "' style='background-color:#$bgc;'>\n"; $i++;
			}
			print mactrack_format_interface_row($stat);
		}

	}else{
		print "<tr><td colspan='7'><em>No Scanner Devices Found</em></td></tr>";
	}

	/* put the nav bar on the bottom as well */
	print $nav;

	html_end_box(false);
	html_start_box("", "100%", $colors["header"], "3", "center", "");
	print "<tr>";
	mactrack_legend_row("mt_int_up_bgc", "Interface Up");
	mactrack_legend_row("mt_int_up_wo_alias_bgc", "No Alias");
	mactrack_legend_row("mt_int_errors_bgc", "Errors Present");
	mactrack_legend_row("mt_int_discards_bgc", "Discards Present");
	mactrack_legend_row("mt_int_unmapped_bgc", "Unmapped to Tree");
	mactrack_legend_row("mt_int_no_graph_bgc", "No Graphs");
	mactrack_legend_row("mt_int_no_device_bgc", "Not Integrated");
	mactrack_legend_row("mt_int_down_bgc", "Interface Down");
	print "</tr>";
	html_end_box(false);

	mactrack_display_stats();

	print "<div id='response'></div>";
	print "<script>
    	function printreport(id){
			if (id==-1 ||typeof id == 'undefined')
				alert('To generate the report, you must select one device.');
			else
         		window.open('https://monitorizacion.urjc.es/cacti/plugins/mactrack/pdfreport.php?did='+id, '_blank');
    	}
	</script>";
	include_once("./include/bottom_footer.php");
}
Example #30
0
function ds()
{
    global $colors, $ds_actions;
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_request("host_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_host_id");
        unset($_REQUEST["page"]);
        unset($_REQUEST["filter"]);
        unset($_REQUEST["sort_column"]);
        unset($_REQUEST["sort_direction"]);
        unset($_REQUEST["host_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("host_id", "sess_ds_host_id", "-1");
    $host = db_fetch_row("select hostname from host where id=" . $_REQUEST["host_id"]);
    html_start_box("<strong>Data Sources</strong> [host: " . (empty($host["hostname"]) ? "No Host" : $host["hostname"]) . "]", "100%", $colors["header"], "3", "center", "data_sources.php?action=ds_edit&host_id=" . $_REQUEST["host_id"]);
    include "./include/html/inc_data_source_filter_table.php";
    html_end_box();
    /* form the 'where' clause for our main sql query */
    if (strlen($_REQUEST["filter"])) {
        $sql_where = "AND (data_template_data.name_cache like '%%" . $_REQUEST["filter"] . "%%'" . " OR data_template.name like '%%" . $_REQUEST["filter"] . "%%'" . " OR data_input.name like '%%" . $_REQUEST["filter"] . "%%')";
    } else {
        $sql_where = "";
    }
    if ($_REQUEST["host_id"] == "-1") {
        /* Show all items */
    } elseif ($_REQUEST["host_id"] == "0") {
        $sql_where .= " AND data_local.host_id=0";
    } elseif (!empty($_REQUEST["host_id"])) {
        $sql_where .= " AND data_local.host_id=" . $_REQUEST["host_id"];
    }
    $total_rows = sizeof(db_fetch_assoc("SELECT\n\t\tdata_local.id\n\t\tFROM (data_local,data_template_data)\n\t\tLEFT JOIN data_input\n\t\tON (data_input.id=data_template_data.data_input_id)\n\t\tLEFT JOIN data_template\n\t\tON (data_local.data_template_id=data_template.id)\n\t\tWHERE data_local.id=data_template_data.local_data_id\n\t\t{$sql_where}"));
    $poller_intervals = array_rekey(db_fetch_assoc("SELECT data_template_data.local_data_id AS id,\n\t\tMin(data_template_data.rrd_step*rra.steps) AS poller_interval\n\t\tFROM data_template\n\t\tINNER JOIN (data_local\n\t\tINNER JOIN ((data_template_data_rra\n\t\tINNER JOIN data_template_data ON data_template_data_rra.data_template_data_id=data_template_data.id)\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\n\t\t{$sql_where}\n\t\tGROUP BY data_template_data.local_data_id"), "id", "poller_interval");
    $data_sources = db_fetch_assoc("SELECT\n\t\tdata_template_data.local_data_id,\n\t\tdata_template_data.name_cache,\n\t\tdata_template_data.active,\n\t\tdata_input.name as data_input_name,\n\t\tdata_template.name as data_template_name,\n\t\tdata_local.host_id\n\t\tFROM (data_local,data_template_data)\n\t\tLEFT JOIN data_input\n\t\tON (data_input.id=data_template_data.data_input_id)\n\t\tLEFT JOIN data_template\n\t\tON (data_local.data_template_id=data_template.id)\n\t\tWHERE data_local.id=data_template_data.local_data_id\n\t\t{$sql_where}\n\t\tORDER BY " . $_REQUEST['sort_column'] . " " . $_REQUEST['sort_direction'] . " LIMIT " . read_config_option("num_rows_data_source") * ($_REQUEST["page"] - 1) . "," . read_config_option("num_rows_data_source"));
    html_start_box("", "100%", $colors["header"], "3", "center", "");
    /* generate page list */
    $url_page_select = get_page_list($_REQUEST["page"], MAX_DISPLAY_PAGES, read_config_option("num_rows_data_source"), $total_rows, "data_sources.php?filter=" . $_REQUEST["filter"] . "&host_id=" . $_REQUEST["host_id"]);
    $nav = "<tr bgcolor='#" . $colors["header"] . "'>\n\t\t\t<td colspan='6'>\n\t\t\t\t<table width='100%' cellspacing='0' cellpadding='0' border='0'>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td align='left' class='textHeaderDark'>\n\t\t\t\t\t\t\t<strong>&lt;&lt; ";
    if ($_REQUEST["page"] > 1) {
        $nav .= "<a class='linkOverDark' href='data_sources.php?filter=" . $_REQUEST["filter"] . "&host_id=" . $_REQUEST["host_id"] . "&page=" . ($_REQUEST["page"] - 1) . "'>";
    }
    $nav .= "Previous";
    if ($_REQUEST["page"] > 1) {
        $nav .= "</a>";
    }
    $nav .= "</strong>\n\t\t\t\t\t\t</td>\n\n\t\t\t\t\t\t<td align='center' class='textHeaderDark'>\n\t\t\t\t\t\t\tShowing Rows " . (read_config_option("num_rows_data_source") * ($_REQUEST["page"] - 1) + 1) . " to " . ($total_rows < read_config_option("num_rows_data_source") || $total_rows < read_config_option("num_rows_data_source") * $_REQUEST["page"] ? $total_rows : read_config_option("num_rows_data_source") * $_REQUEST["page"]) . " of {$total_rows} [{$url_page_select}]\n\t\t\t\t\t\t</td>\n\n\t\t\t\t\t\t<td align='right' class='textHeaderDark'>\n\t\t\t\t\t\t\t<strong>";
    if ($_REQUEST["page"] * read_config_option("num_rows_data_source") < $total_rows) {
        $nav .= "<a class='linkOverDark' href='data_sources.php?filter=" . $_REQUEST["filter"] . "&host_id=" . $_REQUEST["host_id"] . "&page=" . ($_REQUEST["page"] + 1) . "'>";
    }
    $nav .= "Next";
    if ($_REQUEST["page"] * read_config_option("num_rows_data_source") < $total_rows) {
        $nav .= "</a>";
    }
    $nav .= " &gt;&gt;</strong>\n\t\t\t\t\t\t</td>\n\n\t\t\t\t\t</tr>\n\t\t\t\t</table>\n\t\t\t</td>\n\t\t</tr>\n";
    print $nav;
    $display_text = array("name_cache" => array("Name", "ASC"), "data_input_name" => array("Data Input Method", "ASC"), "nosort" => array("Poller<br>Interval", "ASC"), "active" => array("Active", "ASC"), "data_template_name" => array("Template Name", "ASC"));
    html_header_sort_checkbox($display_text, $_REQUEST["sort_column"], $_REQUEST["sort_direction"]);
    $i = 0;
    if (sizeof($data_sources) > 0) {
        foreach ($data_sources as $data_source) {
            $data_template_name = empty($data_source["data_template_name"]) ? "<em>None</em>" : $data_source["data_template_name"];
            $data_input_name = empty($data_source["data_input_name"]) ? "<em>External</em>" : $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='data_sources.php?action=ds_edit&id=" . $data_source["local_data_id"] . "'>" . ($_REQUEST["filter"] != "" ? eregi_replace("(" . preg_quote($_REQUEST["filter"]) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", title_trim(htmlentities($data_source["name_cache"]), read_config_option("max_title_data_source"))) : title_trim(htmlentities($data_source["name_cache"]), read_config_option("max_title_data_source"))) . "</a>", $data_source["local_data_id"]);
            form_selectable_cell(($_REQUEST["filter"] != "" ? eregi_replace("(" . preg_quote($_REQUEST["filter"]) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $data_input_name) : $data_input_name) . "</a>", $data_source["local_data_id"]);
            form_selectable_cell(get_poller_interval($poller_interval), $data_source["local_data_id"]);
            form_selectable_cell($data_source['active'], $data_source["local_data_id"]);
            form_selectable_cell(($_REQUEST["filter"] != "" ? eregi_replace("(" . preg_quote($_REQUEST["filter"]) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $data_source['data_template_name']) : $data_source['data_template_name']) . "</a>", $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";
}