Example #1
0
function host() {
	global $colors, $device_actions;

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

	/* 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_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["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("sort_column", "sess_host_sort_column", "description");
	load_current_session_value("sort_direction", "sess_host_sort_direction", "ASC");

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

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

	html_end_box();

	/* form the 'where' clause for our main sql query */
	if (strlen($_REQUEST["filter"])) {
		$sql_where = "where (host.hostname like '%%" . $_REQUEST["filter"] . "%%' OR host.description like '%%" . $_REQUEST["filter"] . "%%')";
	}else{
		$sql_where = "";
	}

	if ($_REQUEST["host_status"] == "-1") {
		/* Show all items */
	}elseif ($_REQUEST["host_status"] == "-2") {
		$sql_where .= (strlen($sql_where) ? " and host.disabled='on'" : "where host.disabled='on'");
	}elseif ($_REQUEST["host_status"] == "-3") {
		$sql_where .= (strlen($sql_where) ? " and host.disabled=''" : "where host.disabled=''");
	}elseif ($_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=" . $_REQUEST["host_status"] . " AND host.disabled = '')" : "where (host.status=" . $_REQUEST["host_status"] . " AND host.disabled = '')");
	}

	if ($_REQUEST["host_template_id"] == "-1") {
		/* Show all items */
	}elseif ($_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=" . $_REQUEST["host_template_id"] : "where host.host_template_id=" . $_REQUEST["host_template_id"]);
	}

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

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

	$sortby = $_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
                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 " . $sortby . " " . $_REQUEST["sort_direction"] . "
		LIMIT " . (read_config_option("num_rows_device")*($_REQUEST["page"]-1)) . "," . read_config_option("num_rows_device");

	//print $sql_query;

	$hosts = db_fetch_assoc($sql_query);

	/* 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"] . "&host_status=" . $_REQUEST["host_status"]);

	$nav = "<tr bgcolor='#" . $colors["header"] . "'>
			<td colspan='9'>
				<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"] . "&host_status=" . $_REQUEST["host_status"] . "&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"] . "&host_status=" . $_REQUEST["host_status"] . "&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;

	$display_text = array(
		"description" => array("Description", "ASC"),
		"nosort1" => array("Graphs", "ASC"),
		"nosort2" => array("Data Sources", "ASC"),
		"status" => array("Status", "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, $_REQUEST["sort_column"], $_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($_REQUEST["filter"]) ? eregi_replace("(" . preg_quote($_REQUEST["filter"]) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $host["description"]) : $host["description"]) . "</a>", $host["id"], 250);
			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((strlen($_REQUEST["filter"]) ? eregi_replace("(" . preg_quote($_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);
}
function mactrack_format_device_row($device, $actions = false)
{
    global $config, $colors, $mactrack_device_types;
    /* viewer level */
    if ($actions) {
        $row = "<a href='" . htmlspecialchars($config['url_path'] . "plugins/mactrack/mactrack_interfaces.php?device_id=" . $device['device_id'] . "&issues=0&page=1") . "'><img src='" . $config['url_path'] . "plugins/mactrack/images/view_interfaces.gif' alt='' onMouseOver='style.cursor=\"pointer\"' title='View Interfaces' align='middle' border='0'></a>";
        /* admin level */
        if (mactrack_authorized(2121)) {
            if ($device["disabled"] == '') {
                $row .= "<img id='r_" . $device["device_id"] . "' src='" . $config['url_path'] . "plugins/mactrack/images/rescan_device.gif' alt='' onMouseOver='style.cursor=\"pointer\"' onClick='scan_device(" . $device["device_id"] . ")' title='Rescan Device' align='middle' border='0'>";
            } else {
                $row .= "<img src='" . $config['url_path'] . "plugins/mactrack/images/view_none.gif' alt='' align='middle' border='0'>";
            }
        }
        print "<td style='width:40px;'>" . $row . "</td>";
        //, $device["device_id"]);
    }
    form_selectable_cell("<a class='linkEditMain' href='mactrack_devices.php?action=edit&device_id=" . $device['device_id'] . "'>" . (strlen($_REQUEST['filter']) ? preg_replace("/(" . preg_quote($_REQUEST['filter']) . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", $device['device_name']) : $device['device_name']) . "</a>", $device["device_id"]);
    form_selectable_cell($device["site_name"], $device["device_id"]);
    form_selectable_cell(get_colored_device_status($device["disabled"] == "on" ? true : false, $device["snmp_status"]), $device["device_id"]);
    form_selectable_cell(strlen($_REQUEST["filter"]) ? preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", $device["hostname"]) : $device["hostname"], $device["device_id"]);
    form_selectable_cell($device["device_type"] == '' ? 'Not Detected' : $device["device_type"], $device["device_id"]);
    form_selectable_cell($device["scan_type"] == "1" ? "N/A" : $device["ips_total"], $device["device_id"]);
    form_selectable_cell($device["scan_type"] == "3" ? "N/A" : $device["ports_total"], $device["device_id"]);
    form_selectable_cell($device["scan_type"] == "3" ? "N/A" : $device["ports_active"], $device["device_id"]);
    form_selectable_cell($device["scan_type"] == "3" ? "N/A" : $device["ports_trunk"], $device["device_id"]);
    form_selectable_cell($device["scan_type"] == "3" ? "N/A" : $device["macs_active"], $device["device_id"]);
    form_selectable_cell(number_format($device["last_runduration"], 1), $device["device_id"]);
    form_checkbox_cell($device["device_name"], $device["device_id"]);
    form_end_row();
}
Example #3
0
function hosts($header_label)
{
    global $assoc_actions, $item_rows;
    /* ================= input validation and session storage ================= */
    $filters = array('rows' => array('filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1'), 'page' => array('filter' => FILTER_VALIDATE_INT, 'default' => '1'), 'filter' => array('filter' => FILTER_CALLBACK, 'pageset' => true, 'default' => '', 'options' => array('options' => 'sanitize_search_string')), 'sort_column' => array('filter' => FILTER_CALLBACK, 'default' => 'description', 'options' => array('options' => 'sanitize_search_string')), 'sort_direction' => array('filter' => FILTER_CALLBACK, 'default' => 'ASC', 'options' => array('options' => 'sanitize_search_string')), 'associated' => array('filter' => FILTER_CALLBACK, 'default' => 'true', 'options' => array('options' => 'sanitize_search_string')), 'host_template_id' => array('filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1'));
    validate_store_request_vars($filters, 'sess_nlh');
    /* ================= input validation ================= */
    /* if the number of rows is -1, set it to the default */
    if (get_request_var('rows') == -1) {
        $rows = read_config_option('num_rows_table');
    } else {
        $rows = get_request_var('rows');
    }
    html_start_box(__('Associated Devices') . ' ' . htmlspecialchars($header_label), '100%', '', '3', 'center', '');
    ?>
	<tr class='even'>
		<td>
		<form id='form_devices' method='post' action='notify_lists.php'>
			<table class='filterTable'>
				<tr>
					<td>
						<?php 
    print __('Search');
    ?>
					</td>
					<td>
						<input type='text' id='filter' size='25' value='<?php 
    print htmlspecialchars(get_request_var('filter'));
    ?>
' onChange='applyFilter()'>
					</td>
					<td>
						<?php 
    print __('Type');
    ?>
					</td>
					<td>
						<select id='host_template_id' onChange='applyFilter()'>
							<option value='-1'<?php 
    if (get_request_var('host_template_id') == '-1') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('Any');
    ?>
</option>
							<option value='0'<?php 
    if (get_request_var('host_template_id') == '0') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('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('host_template_id') == $host_template['id']) {
                print ' selected';
            }
            print '>' . htmlspecialchars($host_template['name']) . "</option>\n";
        }
    }
    ?>
						</select>
					</td>
					<td>
						<?php 
    print __('Devices');
    ?>
					</td>
					<td>
						<select id='rows' onChange='applyFilter()'>
							<option value='-1'<?php 
    if (get_request_var('rows') == '-1') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('Default');
    ?>
</option>
							<?php 
    if (sizeof($item_rows) > 0) {
        foreach ($item_rows as $key => $value) {
            print "<option value='" . $key . "'";
            if (get_request_var('rows') == $key) {
                print ' selected';
            }
            print '>' . htmlspecialchars($value) . "</option>\n";
        }
    }
    ?>
						</select>
					</td>
					<td>
						<input type='checkbox' id='associated' onChange='applyFilter()' <?php 
    print get_request_var('associated') == 'true' || get_request_var('associated') == 'on' ? 'checked' : '';
    ?>
>
					</td>
					<td>
						<label for='associated'><?php 
    print __('Associated');
    ?>
</label>
					</td>
					<td>
						<input type='button' value='<?php 
    print __('Go');
    ?>
' onClick='applyFilter()' title='<?php 
    print __('Set/Refresh Filters');
    ?>
'>
					</td>
					<td nowrap>
						<input type='button' name='clearf' value='<?php 
    print __('Clear');
    ?>
' onClick='clearFilter()' title='<?php 
    print __('Clear Filters');
    ?>
'>
					</td>
				</tr>
			</table>
			<input type='hidden' id='page' value='<?php 
    print get_filter_request_var('page');
    ?>
'>
			<input type='hidden' name='action' value='edit'>
			<input type='hidden' id='id' value='<?php 
    print get_filter_request_var('id');
    ?>
'>
		</form>
		<script type='text/javascript'>

		function applyFilter() {
			strURL  = '?header=false&action=edit&id=<?php 
    print get_request_var('id');
    ?>
'
			strURL += '&rows=' + $('#rows').val();
			strURL += '&host_template_id=' + $('#host_template_id').val();
			strURL += '&associated=' + $('#associated').is(':checked');
			strURL += '&filter=' + $('#filter').val();
			loadPageNoHeader(strURL);
		}

		function clearFilter() {
			strURL = 'notify_lists.php?header=false&action=edit&id=<?php 
    print get_request_var('id');
    ?>
&clearf=true'
			loadPageNoHeader(strURL);
		}

		$(function() {
			$('#form_devices').submit(function(event) {
				event.preventDefault();
				applyFilter();
			});
		});
	
		</script>
		</td>
	</tr>
	<?php 
    html_end_box();
    /* form the 'where' clause for our main sql query */
    if (strlen(get_request_var('filter'))) {
        $sql_where = "WHERE (host.hostname LIKE '%" . get_request_var('filter') . "%' OR host.description LIKE '%" . get_request_var('filter') . "%')";
    } else {
        $sql_where = '';
    }
    if (get_request_var('host_template_id') == '-1') {
        /* Show all items */
    } elseif (get_request_var('host_template_id') == '0') {
        $sql_where .= (strlen($sql_where) ? ' AND ' : 'WHERE ') . ' host.host_template_id=0';
    } elseif (!isempty_request_var('host_template_id')) {
        $sql_where .= (strlen($sql_where) ? ' AND ' : 'WHERE ') . ' host.host_template_id=' . get_request_var('host_template_id');
    }
    if (get_request_var('associated') == 'false') {
        /* Show all items */
    } else {
        $sql_where .= (strlen($sql_where) ? ' AND ' : 'WHERE ') . ' (host.thold_send_email>1 AND host.thold_host_email=' . get_request_var('id') . ')';
    }
    $total_rows = db_fetch_cell("select\n\t\tCOUNT(host.id)\n\t\tfrom host\n\t\t{$sql_where}");
    $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 {$sql_where}\n\t\tLIMIT " . $rows * (get_request_var('page') - 1) . ',' . $rows;
    $hosts = db_fetch_assoc($sql_query);
    $nav = html_nav_bar('notify_lists.php?action=edit&id=' . get_request_var('id'), MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, 10, __('Devices'), 'page', 'main');
    form_start('notify_lists.php', 'chk');
    print $nav;
    html_start_box('', '100%', '', '3', 'center', '');
    $display_text = array(__('Description'), __('ID'), __('Associated Lists'), __('Graphs'), __('Data Sources'), __('Status'), __('Hostname'));
    html_header_checkbox($display_text);
    if (sizeof($hosts)) {
        foreach ($hosts as $host) {
            form_alternate_row('line' . $host['id'], true);
            form_selectable_cell(filter_value($host['description'], get_request_var('filter')), $host['id'], 250);
            form_selectable_cell(round($host['id'], 2), $host['id']);
            if ($host['thold_send_email'] == 0) {
                form_selectable_cell('<span style="color:blue;font-weight:bold;">' . __('Disabled') . '</span>', $host['id']);
            } elseif ($host['thold_send_email'] == 1) {
                form_selectable_cell('<span style="color:purple;font-weight:bold;">' . __('Global List') . '</span>', $host['id']);
            } elseif ($host['thold_host_email'] == get_request_var('id')) {
                if ($host['thold_send_email'] == 2) {
                    form_selectable_cell('<span style="color:green;font-weight:bold;">' . __('Current List Only') . '</span>', $host['id']);
                } else {
                    form_selectable_cell('<span style="color:green;font-weight:bold;">' . __('Current and Global List(s)') . '</span>', $host['id']);
                }
            } elseif ($host['thold_host_email'] == '0') {
                form_selectable_cell('<span style="color:green;font-weight:bold;">' . __('None') . '</span>', $host['id']);
            } else {
                form_selectable_cell('<span style="color:red;font-weight:bold;">' . db_fetch_cell('SELECT name FROM plugin_notification_lists WHERE id=' . get_request_var('id')) . '</span>', $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(filter_value($host['hostname'], get_request_var('filter')), $host['id']);
            form_checkbox_cell($host['description'], $host['id']);
            form_end_row();
        }
    } else {
        print '<tr><td><em>' . __('No Associated Devices Found') . '</em></td></tr>';
    }
    html_end_box(false);
    if (sizeof($hosts)) {
        print $nav;
    }
    form_hidden_box('tab', 'hosts', '');
    form_hidden_box('id', get_request_var('id'), '');
    form_hidden_box('save_associate', '1', '');
    draw_actions_dropdown($assoc_actions);
    form_end();
}
Example #4
0
function tholds_old()
{
    global $colors, $assoc_actions, $item_rows;
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_request("host_template_id"));
    input_validate_input_number(get_request_var_request("rows"));
    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_request("filter"));
    }
    /* clean up associated string */
    if (isset($_REQUEST["associated"])) {
        $_REQUEST["associated"] = sanitize_search_string(get_request_var_request("associated"));
    }
    /* if the user pushed the 'clear' button */
    if (isset($_REQUEST["clearf"])) {
        kill_session_var("sess_nlh_current_page");
        kill_session_var("sess_nlh_filter");
        kill_session_var("sess_nlh_host_template_id");
        kill_session_var("sess_nlh_rows");
        kill_session_var("sess_nlh_associated");
        unset($_REQUEST["page"]);
        unset($_REQUEST["filter"]);
        unset($_REQUEST["associated"]);
        unset($_REQUEST["host_template_id"]);
        unset($_REQUEST["rows"]);
    }
    /* remember these search fields in session vars so we don't have to keep passing them around */
    load_current_session_value("page", "sess_nlh_current_page", "1");
    load_current_session_value("filter", "sess_nlh_filter", "");
    load_current_session_value("associated", "sess_nlh_associated", "true");
    load_current_session_value("host_template_id", "sess_nlh_host_template_id", "-1");
    load_current_session_value("rows", "sess_nlh_rows", read_config_option("num_rows_device"));
    /* if the number of rows is -1, set it to the default */
    if ($_REQUEST["rows"] == -1) {
        $_REQUEST["rows"] = read_config_option("num_rows_device");
    }
    ?>
	<script type="text/javascript">
	<!--

	function applyViewDeviceFilterChange(objForm) {
		strURL = '?action=edit&id=<?php 
    print get_request_var_request('id');
    ?>
&rows=' + objForm.rows.value;
		strURL = strURL + '&host_template_id=' + objForm.host_template_id.value;
		strURL = strURL + '&associated=' + objForm.associated.checked;
		strURL = strURL + '&filter=' + objForm.filter.value;
		document.location = strURL;
	}

	function clearViewDeviceFilterChange(objForm) {
		strURL = '?action=edit&id=<?php 
    print get_request_var_request('id');
    ?>
&clearf=true'
		document.location = strURL;
	}

	-->
	</script>
	<?php 
    html_start_box("<strong>Associated Devices</strong>", "100%", $colors["header"], "3", "center", "");
    ?>
	<tr bgcolor="#<?php 
    print $colors["panel"];
    ?>
">
		<td>
		<form name="form_devices" method="post" action="notify_lists.php">
			<table cellpadding="0" cellspacing="0">
				<tr>
					<td nowrap style='white-space: nowrap;' width="50">
						&nbsp;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 ">" . htmlspecialchars($host_template["name"]) . "</option>\n";
        }
    }
    ?>
						</select>
					</td>
					<td nowrap style='white-space: nowrap;' width="20">
						&nbsp;Search:&nbsp;
					</td>
					<td width="1">
						<input type="text" name="filter" size="20" value="<?php 
    print htmlspecialchars(get_request_var_request("filter"));
    ?>
" onChange="applyViewDeviceFilterChange(document.form_devices)">
					</td>
					<td nowrap style='white-space: nowrap;' width="50">
						&nbsp;Rows:&nbsp;
					</td>
					<td width="1">
						<select name="rows" onChange="applyViewDeviceFilterChange(document.form_devices)">
							<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='checkbox' name='associated' id='associated' onChange='applyViewDeviceFilterChange(document.form_devices)' <?php 
    print $_REQUEST['associated'] == 'true' || $_REQUEST['associated'] == 'on' ? 'checked' : '';
    ?>
>
					</td>
					<td>
						<label for='associated'>Associated</label>
					</td>
					<td nowrap>
						&nbsp;<input type="button" value="Go" onClick='applyViewDeviceFilterChange(document.form_devices)' title="Set/Refresh Filters">
					</td>
					<td nowrap>
						<input type="button" name="clearf" value="Clear" onClick='clearViewDeviceFilterChange(document.form_devices)' title="Clear Filters">
					</td>
				</tr>
			</table>
			<input type='hidden' name='page' value='1'>
			<input type='hidden' name='tab' value='hosts'>
			<input type='hidden' name='action' value='edit'>
			<input type='hidden' name='id' value='<?php 
    print get_request_var_request('id');
    ?>
'>
		</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_template_id") == "-1") {
        /* Show all items */
    } elseif (get_request_var_request("host_template_id") == "0") {
        $sql_where .= (strlen($sql_where) ? " AND " : "WHERE ") . " host.host_template_id=0";
    } elseif (!empty($_REQUEST["host_template_id"])) {
        $sql_where .= (strlen($sql_where) ? " AND " : "WHERE ") . " host.host_template_id=" . get_request_var_request("host_template_id");
    }
    if (get_request_var_request("associated") == "false") {
        /* Show all items */
    } else {
        $sql_where .= (strlen($sql_where) ? " AND " : "WHERE ") . " (host.thold_send_email>1 AND host.thold_host_email=" . get_request_var_request("id") . ")";
    }
    /* print checkbox form for validation */
    print "<form name='chk' method='post' action='notify_lists.php?action=edit&tab=hosts&id=" . get_request_var_request("id") . "'>\n";
    html_start_box("", "100%", $colors["header"], "3", "center", "");
    $total_rows = db_fetch_cell("SELECT\n\t\tCOUNT(*)\n\t\tFROM host\n\t\t{$sql_where}");
    $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 {$sql_where} \n\t\tLIMIT " . get_request_var_request("rows") * (get_request_var_request("page") - 1) . "," . get_request_var_request("rows");
    $hosts = db_fetch_assoc($sql_query);
    /* generate page list */
    if ($total_rows > 0) {
        $url_page_select = get_page_list(get_request_var_request("page"), MAX_DISPLAY_PAGES, get_request_var_request("rows"), $total_rows, "notify_lists.php?action=edit&tab=hosts&id=" . get_request_var_request('id'));
        $nav = "<tr bgcolor='#" . $colors["header"] . "'>\n\t\t\t\t<td colspan='8'>\n\t\t\t\t\t<table width='100%' cellspacing='0' cellpadding='0' border='0'>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td align='left' class='textHeaderDark'>\n\t\t\t\t\t\t\t\t<strong>&lt;&lt; ";
        if (get_request_var_request("page") > 1) {
            $nav .= "<a class='linkOverDark' href='" . htmlspecialchars("notify_lists.php?action=edit&id=" . get_request_var_request("id") . "&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\t</td>\n\n\t\t\t\t\t\t\t<td align='center' class='textHeaderDark'>\n\t\t\t\t\t\t\t\tShowing Rows " . (get_request_var_request("rows") * (get_request_var_request("page") - 1) + 1) . " to " . ($total_rows < read_config_option("num_rows_device") || $total_rows < get_request_var_request("rows") * get_request_var_request("page") ? $total_rows : get_request_var_request("rows") * get_request_var_request("page")) . " of {$total_rows} [{$url_page_select}]\n\t\t\t\t\t\t\t</td>\n\n\t\t\t\t\t\t\t<td align='right' class='textHeaderDark'>\n\t\t\t\t\t\t\t\t\t\t<strong>";
        if (get_request_var_request("page") * get_request_var_request("rows") < $total_rows) {
            $nav .= "<a class='linkOverDark' href='" . htmlspecialchars("notify_lists.php?action=edit&id=" . get_request_var_request("id") . "&page=" . (get_request_var_request("page") + 1)) . "'>";
        }
        $nav .= "Next";
        if (get_request_var_request("page") * get_request_var_request("rows") < $total_rows) {
            $nav .= "</a>";
        }
        $nav .= " &gt;&gt;</strong>\n\t\t\t\t\t\t\t</td>\n\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</table>\n\t\t\t\t</td>\n\t\t\t</tr>\n";
    } else {
        $nav = "<tr bgcolor='#" . $colors["header"] . "'>\n\t\t\t\t<td colspan='8'>\n\t\t\t\t\t<table width='100%' cellspacing='0' cellpadding='0' border='0'>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td align='center' class='textHeaderDark'>\n\t\t\t\t\t\t\t\tNo Rows Found\n\t\t\t\t\t\t\t</td>\n\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</table>\n\t\t\t\t</td>\n\t\t\t</tr>\n";
    }
    print $nav;
    $display_text = array("Description", "ID", "Associated Lists", "Graphs", "Data Sources", "Status", "Hostname");
    html_header_checkbox($display_text);
    $i = 0;
    if (sizeof($hosts)) {
        foreach ($hosts as $host) {
            form_alternate_row_color($colors["alternate"], $colors["light"], $i, 'line' . $host["id"]);
            $i++;
            form_selectable_cell(strlen(get_request_var_request("filter")) ? preg_replace("/(" . preg_quote(get_request_var_request("filter")) . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", htmlspecialchars($host["description"])) : htmlspecialchars($host["description"]), $host["id"], 250);
            form_selectable_cell(round($host["id"], 2), $host["id"]);
            if ($host['thold_send_email'] == 0) {
                form_selectable_cell('<span style="color:blue;font-weight:bold;">Disabled</span>', $host['id']);
            } elseif ($host['thold_send_email'] == 1) {
                form_selectable_cell('<span style="color:purple;font-weight:bold;">Global List</span>', $host['id']);
            } elseif ($host['thold_host_email'] == get_request_var_request('id')) {
                if ($host['thold_send_email'] == 2) {
                    form_selectable_cell('<span style="color:green;font-weight:bold;">Current List Only</span>', $host['id']);
                } else {
                    form_selectable_cell('<span style="color:green;font-weight:bold;">Current and Global List(s)</span>', $host['id']);
                }
            } elseif ($host['thold_host_email'] == '0') {
                form_selectable_cell('<span style="color:green;font-weight:bold;">None</span>', $host['id']);
            } else {
                form_selectable_cell('<span style="color:red;font-weight:bold;">' . db_fetch_cell("SELECT name FROM plugin_notification_lists WHERE id=" . get_request_var_request('id')) . '</span>', $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(strlen(get_request_var_request("filter")) ? preg_replace("/(" . preg_quote(get_request_var_request("filter")) . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", htmlspecialchars($host["hostname"])) : htmlspecialchars($host["hostname"]), $host["id"]);
            form_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 Associated Hosts Found</em></td></tr>";
    }
    html_end_box(false);
    form_hidden_box("action", "edit");
    form_hidden_box("id", get_request_var_request("id"));
    form_hidden_box("save_associate", "1");
    /* draw the dropdown containing a list of available actions for this form */
    draw_actions_dropdown($assoc_actions);
    print "</form>\n";
}
Example #5
0
function device() {
	global $colors, $item_rows;
	require(CACTI_BASE_PATH . "/include/device/device_arrays.php");

	/* ================= input validation ================= */
	input_validate_input_number(get_request_var_request("template_id"));
	input_validate_input_number(get_request_var_request("page"));
	input_validate_input_number(get_request_var_request("status"));
	input_validate_input_number(get_request_var_request("rows"));
	input_validate_input_number(get_request_var_request("poller"));
	input_validate_input_number(get_request_var_request("site"));
	/* ==================================================== */

	/* 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");
		if (!substr_count($_SERVER["REQUEST_URI"], "/device_templates.php")) {
			kill_session_var("sess_device_template_id");
		}
		kill_session_var("sess_device_status");
		kill_session_var("sess_device_rows");
		kill_session_var("sess_device_poller");
		kill_session_var("sess_device_site");
		kill_session_var("sess_device_sort_column");
		kill_session_var("sess_device_sort_direction");

		unset($_REQUEST["page"]);
		unset($_REQUEST["filter"]);
		if (!substr_count($_SERVER["REQUEST_URI"], "/device_templates.php")) {
			unset($_REQUEST["template_id"]);
		}
		unset($_REQUEST["status"]);
		unset($_REQUEST["poller"]);
		unset($_REQUEST["site"]);
		unset($_REQUEST["rows"]);
		unset($_REQUEST["sort_column"]);
		unset($_REQUEST["sort_direction"]);
	}

	/* let's see if someone changed an important setting */
	$changed  = FALSE;
	$changed += check_changed("filter",      "sess_device_filter");
	$changed += check_changed("template_id", "sess_device_template_id");
	$changed += check_changed("status",      "sess_device_status");
	$changed += check_changed("rows",        "sess_device_rows");
	$changed += check_changed("poller",      "sess_device_poller");
	$changed += check_changed("site",        "sess_device_site");
	$changed += check_changed("device_id",	 "sess_ds_device_id");

	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_device_current_page", "1");
	load_current_session_value("filter", "sess_device_filter", "");
	load_current_session_value("template_id", "sess_device_template_id", "-1");
	load_current_session_value("status", "sess_device_status", "-1");
	load_current_session_value("rows", "sess_device_rows", "-1");
	load_current_session_value("poller", "sess_device_poller", "-1");
	load_current_session_value("site", "sess_device_site", "-1");
	load_current_session_value("sort_column", "sess_device_sort_column", "description");
	load_current_session_value("sort_direction", "sess_device_sort_direction", "ASC");

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

	function clearDeviceFilterChange(objForm) {
		<?php print (isset($_REQUEST["tab"]) ? "strURL = '?template_id=" . $_REQUEST["template_id"] . "&id=" . $_REQUEST["template_id"] . "&action=edit&amp;action=edit&tab=" . $_REQUEST["tab"] . "';" : "strURL = '?template_id=-1';");?>
		strURL = strURL + '&filter=';
		strURL = strURL + '&rows=-1';
		document.location = strURL;
	}

	function applyDeviceFilterChange(objForm) {
		if (objForm.template_id.value) {
			strURL = '?template_id=' + objForm.template_id.value;
			strURL = strURL + '&filter=' + objForm.filter.value;
		}else{
			strURL = '?filter=' + objForm.filter.value;
		}
		strURL = strURL + '&status=' + objForm.status.value;
		strURL = strURL + '&rows=' + objForm.rows.value;
		strURL = strURL + '&poller=' + objForm.poller.value;
		strURL = strURL + '&site=' + objForm.site.value;
		<?php print (isset($_REQUEST["tab"]) ? "strURL = strURL + '&id=' + objForm.template_id.value + '&action=edit&action=edit&tab=" . $_REQUEST["tab"] . "';" : "");?>
		document.location = strURL;
	}

	-->
	</script>
	<?php

	html_start_box("<strong>" . __("Devices") . "</strong>", "100", $colors["header"], "3", "center", "devices.php?action=edit&template_id=" . $_REQUEST["template_id"] . "&status=" . $_REQUEST["status"], true);
	?>
	<tr class='rowAlternate2'>
		<td>
			<form action="devices.php" name="form_devices" method="post">
			<table cellpadding="0" cellspacing="3">
				<tr>
					<td class="nw50">
						&nbsp;<?php print __("Type:");?>&nbsp;
					</td>
					<td class="w1">
						<select name="template_id" onChange="applyDeviceFilterChange(document.form_devices)">
							<option value="-1"<?php if (get_request_var_request("template_id") == "-1") {?> selected<?php }?>><?php print __("Any");?></option>
							<option value="0"<?php if (get_request_var_request("template_id") == "0") {?> selected<?php }?>><?php print __("None");?></option>
							<?php
							$device_templates = db_fetch_assoc("select id,name from device_template order by name");

							if (sizeof($device_templates) > 0) {
							foreach ($device_templates as $device_template) {
								print "<option value='" . $device_template["id"] . "'"; if (get_request_var_request("template_id") == $device_template["id"]) { print " selected"; } print ">" . $device_template["name"] . "</option>\n";
							}
							}
							?>
						</select>
					</td>
					<td class="nw50">
						&nbsp;<?php print __("Status:");?>&nbsp;
					</td>
					<td class="w1">
						<select name="status" onChange="applyDeviceFilterChange(document.form_devices)">
							<option value="-1"<?php if (get_request_var_request("status") == "-1") {?> selected<?php }?>><?php print __("Any");?></option>
							<option value="-3"<?php if (get_request_var_request("status") == "-3") {?> selected<?php }?>><?php print __("Enabled");?></option>
							<option value="-2"<?php if (get_request_var_request("status") == "-2") {?> selected<?php }?>><?php print __("Disabled");?></option>
							<option value="-4"<?php if (get_request_var_request("status") == "-4") {?> selected<?php }?>><?php print __("Not Up");?></option>
							<option value="3"<?php if (get_request_var_request("status") == "3") {?> selected<?php }?>><?php print __("Up");?></option>
							<option value="1"<?php if (get_request_var_request("status") == "1") {?> selected<?php }?>><?php print __("Down");?></option>
							<option value="2"<?php if (get_request_var_request("status") == "2") {?> selected<?php }?>><?php print __("Recovering");?></option>
							<option value="0"<?php if (get_request_var_request("status") == "0") {?> selected<?php }?>><?php print __("Unknown");?></option>
						</select>
					</td>
					<td class="nw50">
						&nbsp;<?php print __("Rows:");?>&nbsp;
					</td>
					<td class="w1">
						<select name="rows" onChange="applyDeviceFilterChange(document.form_devices)">
							<option value="-1"<?php if (get_request_var_request("rows") == "-1") {?> selected<?php }?>><?php print __("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 ">" . $value . "</option>\n";
							}
							}
							?>
						</select>
					</td>
				</tr>
			</table>
			<table cellpadding="0" cellspacing="3">
				<tr>
					<td class="nw50">
						&nbsp;<?php print __("Site:");?>&nbsp;
					</td>
					<td class="w1">
						<select name="site" onChange="applyDeviceFilterChange(document.form_devices)">
							<option value="-1"<?php if (get_request_var_request("site") == "-1") {?> selected<?php }?>><?php print __("All");?></option>
							<option value="0"<?php if (get_request_var_request("site") == "0") {?> selected<?php }?>><?php print __("Not Defined");?></option>
							<?php
							$sites = db_fetch_assoc("select id,name from sites order by name");

							if (sizeof($sites)) {
							foreach ($sites as $site) {
								print "<option value='" . $site["id"] . "'"; if (get_request_var_request("site") == $site["id"]) { print " selected"; } print ">" . $site["name"] . "</option>\n";
							}
							}
							?>
						</select>
					</td>
					<td class="nw50">
						&nbsp;<?php print __("Poller:");?>&nbsp;
					</td>
					<td class="w1">
						<select name="poller" onChange="applyDeviceFilterChange(document.form_devices)">
							<option value="-1"<?php if (get_request_var_request("poller") == "-1") {?> selected<?php }?>><?php print __("All");?></option>
							<option value="0"<?php if (get_request_var_request("poller") == "0") {?> selected<?php }?>><?php print __("System Default");?></option>
							<?php
							$pollers = db_fetch_assoc("select id,description AS name from poller order by description");

							if (sizeof($pollers)) {
							foreach ($pollers as $poller) {
								print "<option value='" . $poller["id"] . "'"; if (get_request_var_request("poller") == $poller["id"]) { print " selected"; } print ">" . $poller["name"] . "</option>\n";
							}
							}
							?>
						</select>
					</td>
					<td class="nw50">
						&nbsp;<?php print __("Search:");?>&nbsp;
					</td>
					<td class="w1">
						<input type="text" name="filter" size="20" value="<?php print $_REQUEST["filter"];?>">
					</td>
					<td class="nw120">
						&nbsp;<input type="submit" Value="<?php print __("Go");?>" name="go" align="middle">
						<input type="button" Value="<?php print __("Clear");?>" name="clear_x" align="middle" onClick="clearDeviceFilterChange(document.form_devices)">
					</td>
				</tr>
			</table>
			<div><input type='hidden' name='page' value='1'></div>
			</form>
		</td>
	</tr>
	<?php
	html_end_box(false);

	/* form the 'where' clause for our main sql query */
	if (strlen(get_request_var_request("filter"))) {
		$sql_where = "where (device.hostname like '%%" . $_REQUEST["filter"] . "%%' OR device.description like '%%" . $_REQUEST["filter"] . "%%')";
	}else{
		$sql_where = "";
	}

	if (get_request_var_request("status") == "-1") {
		/* Show all items */
	}elseif (get_request_var_request("status") == "-2") {
		$sql_where .= (strlen($sql_where) ? " and device.disabled='on'" : "where device.disabled='on'");
	}elseif (get_request_var_request("status") == "-3") {
		$sql_where .= (strlen($sql_where) ? " and device.disabled=''" : "where device.disabled=''");
	}elseif (get_request_var_request("status") == "-4") {
		$sql_where .= (strlen($sql_where) ? " and (device.status!='3' or device.disabled='on')" : "where (device.status!='3' or device.disabled='on')");
	}else {
		$sql_where .= (strlen($sql_where) ? " and (device.status=" . $_REQUEST["status"] . " AND device.disabled = '')" : "where (device.status=" . $_REQUEST["status"] . " AND device.disabled = '')");
	}

	if (get_request_var_request("template_id") == "-1") {
		/* Show all items */
	}elseif (get_request_var_request("template_id") == "0") {
		$sql_where .= (strlen($sql_where) ? " and device.device_template_id=0" : "where device.device_template_id=0");
	}elseif (!empty($_REQUEST["template_id"])) {
		$sql_where .= (strlen($sql_where) ? " and device.device_template_id=" . $_REQUEST["template_id"] : "where device.device_template_id=" . $_REQUEST["template_id"]);
	}

	if (get_request_var_request("poller") == "-1") {
		/* Show all items */
	}elseif (get_request_var_request("poller") == "0") {
		$sql_where .= (strlen($sql_where) ? " and device.poller_id=0" : "where device.poller_id=0");
	}elseif (!empty($_REQUEST["poller"])) {
		$sql_where .= (strlen($sql_where) ? " and device.poller_id=" . $_REQUEST["poller"] : "where device.poller_id=" . $_REQUEST["poller"]);
	}

	if (get_request_var_request("site") == "-1") {
		/* Show all items */
	}elseif (get_request_var_request("site") == "0") {
		$sql_where .= (strlen($sql_where) ? " and device.site_id=0" : "where device.site_id=0");
	}elseif (!empty($_REQUEST["site"])) {
		$sql_where .= (strlen($sql_where) ? " and device.site_id=" . $_REQUEST["site"] : "where device.site_id=" . $_REQUEST["site"]);
	}

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

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

	if (get_request_var_request("rows") == "-1") {
		$rows = read_config_option("num_rows_device");
	}else{
		$rows = get_request_var_request("rows");
	}

	$sortby = $_REQUEST["sort_column"];
	if ($sortby=="hostname") {
		$sortby = "INET_ATON(hostname)";
	}

	$device_graphs       = array_rekey(db_fetch_assoc("SELECT device_id, count(*) as graphs FROM graph_local GROUP BY device_id"), "device_id", "graphs");
	$device_data_sources = array_rekey(db_fetch_assoc("SELECT device_id, count(*) as data_sources FROM data_local GROUP BY device_id"), "device_id", "data_sources");

	$sql_query = "SELECT device.*, poller.description AS poller, sites.name AS site
		FROM device
		LEFT JOIN poller
		ON device.poller_id=poller.id
		LEFT JOIN sites
		ON device.site_id=sites.id
		$sql_where
		ORDER BY " . $sortby . " " . get_request_var_request("sort_direction") . "
		LIMIT " . ($rows*(get_request_var_request("page")-1)) . "," . $rows;

	//print $sql_query;

	$devices = db_fetch_assoc($sql_query);

	/* generate page list navigation */
	$nav = html_create_nav($_REQUEST["page"], MAX_DISPLAY_PAGES, $rows, $total_rows, 13, "devices.php");

	print $nav;
	html_end_box(false);

	$display_text = array(
		"description" => array(__("Description"), "ASC"),
		"device.hostname" => array(__("Hostname"), "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"),
		"cur_time" => array(__("Current (ms)"), "DESC"),
		"avg_time" => array(__("Average (ms)"), "DESC"),
		"availability" => array(__("Availability"), "ASC"),
		"polling_time" => array(__("Poll Time"), "DESC"));

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

	if (sizeof($devices) > 0) {
		foreach ($devices as $device) {
			$spanextra = "";
			if($device["disabled"] != CHECKED && $device["status"] == DEVICE_DOWN) {
				$date = __date("D, " . date_time_format() . " T", strtotime($device['status_fail_date']));
				$spanextra = 'title="' . __("Down since %s with error: '%s'", $date, $device['status_last_error']) . '"';
			}

			form_alternate_row_color('line' . $device["id"], true);
			form_selectable_cell("<a style='white-space:nowrap;' class='linkEditMain' href='" . htmlspecialchars("devices.php?action=edit&id=" . $device["id"]) . "'>" .
				(strlen($_REQUEST["filter"]) ? preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span class=\"filter\">\\1</span>", $device["description"]) : $device["description"]) . "</a>", $device["id"]);
			form_selectable_cell((strlen($_REQUEST["filter"]) ? preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span class=\"filter\">\\1</span>", $device["hostname"]) : $device["hostname"]), $device["id"]);
			form_selectable_cell(round(($device["id"]), 2), $device["id"]);
			form_selectable_cell((isset($device_graphs[$device["id"]]) ? $device_graphs[$device["id"]] : 0), $device["id"]);
			form_selectable_cell((isset($device_data_sources[$device["id"]]) ? $device_data_sources[$device["id"]] : 0), $device["id"]);
			form_selectable_cell( "<span $spanextra>".get_colored_device_status(($device["disabled"] == CHECKED ? true : false), $device["status"]) . "</span>", $device["id"]);
			form_selectable_cell(round(($device["status_event_count"]), 2), $device["id"]);
			form_selectable_cell(round(($device["cur_time"]), 2), $device["id"]);
			form_selectable_cell(round(($device["avg_time"]), 2), $device["id"]);
			form_selectable_cell(round($device["availability"], 2), $device["id"]);
			form_selectable_cell(round($device["polling_time"], 2), $device["id"]);
			form_checkbox_cell($device["description"], $device["id"]);
			form_end_row();
		}

		form_end_table();

		/* put the nav bar on the bottom as well */
		print $nav;
	}else{
		print "<tr><td><em>" . __("No Hosts") . "</em></td></tr>";
	}

	print "</table>\n";

	/* add a list of tree names to the actions dropdown */
	$device_actions = array_merge($device_actions, api_tree_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";
}
function mactrack_view_devices() {
	global $title, $report, $colors, $mactrack_search_types, $mactrack_device_types, $rows_selector, $config, $item_rows;

	/* ================= input validation ================= */
	input_validate_input_number(get_request_var_request("site_id"));
	input_validate_input_number(get_request_var_request("device_id"));
	input_validate_input_number(get_request_var_request("type_id"));
	input_validate_input_number(get_request_var_request("device_type_id"));
	input_validate_input_number(get_request_var_request("status"));
	input_validate_input_number(get_request_var_request("page"));
	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("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"]) || isset($_REQUEST["reset"])) {
		kill_session_var("sess_mactrack_view_device_current_page");
		kill_session_var("sess_mactrack_view_device_filter");
		kill_session_var("sess_mactrack_view_device_site_id");
		kill_session_var("sess_mactrack_view_device_type_id");
		kill_session_var("sess_mactrack_view_device_rows");
		kill_session_var("sess_mactrack_view_device_device_type_id");
		kill_session_var("sess_mactrack_view_device_status");
		kill_session_var("sess_mactrack_view_device_sort_column");
		kill_session_var("sess_mactrack_view_device_sort_direction");

		$_REQUEST["page"] = 1;

		if (isset($_REQUEST["clear_x"])) {
			unset($_REQUEST["filter"]);
			unset($_REQUEST["site_id"]);
			unset($_REQUEST["type_id"]);
			unset($_REQUEST["rows"]);
			unset($_REQUEST["device_type_id"]);
			unset($_REQUEST["status"]);
			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("filter", "sess_mactrack_view_device_filter");
		$changed += mactrack_check_changed("site_id", "sess_mactrack_view_device_site_id");
		$changed += mactrack_check_changed("rows", "sess_mactrack_view_device_rows");
		$changed += mactrack_check_changed("type_id", "sess_mactrack_view_device_type_id");
		$changed += mactrack_check_changed("device_type_id", "sess_mactrack_view_device_device_type_id");
		$changed += mactrack_check_changed("status", "sess_mactrack_view_device_status");

		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_view_device_current_page", "1");
	load_current_session_value("filter",         "sess_mactrack_view_device_filter", "");
	load_current_session_value("site_id",        "sess_mactrack_view_device_site_id", "-1");
	load_current_session_value("type_id",        "sess_mactrack_view_device_type_id", "-1");
	load_current_session_value("device_type_id", "sess_mactrack_view_device_device_type_id", "-1");
	load_current_session_value("status",         "sess_mactrack_view_device_status", "-1");
	load_current_session_value("rows",           "sess_mactrack_view_device_rows", "-1");
	load_current_session_value("sort_column",    "sess_mactrack_view_device_sort_column", "site_name");
	load_current_session_value("sort_direction", "sess_mactrack_view_device_sort_direction", "ASC");

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

	if (defined("URL_PATH")) {
		$webroot = URL_PATH;
	}else{
		$webroot = $config["url_path"];
	}

	mactrack_tabs();
	mactrack_view_header();
	mactrack_device_filter2();
	mactrack_view_footer();
	html_start_box("", "100%", $colors["header"], "3", "center", "");

	$sql_where = "";

	$devices = mactrack_view_get_device_records($sql_where, $row_limit);

	$total_rows = db_fetch_cell("SELECT
		COUNT(mac_track_devices.device_id)
		FROM mac_track_sites
		RIGHT JOIN mac_track_devices ON mac_track_devices.site_id = mac_track_sites.site_id
		LEFT JOIN mac_track_device_types ON (mac_track_device_types.device_type_id=mac_track_devices.device_type_id)
		$sql_where");

	/* generate page list */
	$url_page_select = get_page_list($_REQUEST["page"], MAX_DISPLAY_PAGES, $row_limit, $total_rows, "mactrack_view_devices.php?report=devices");

	if (isset($config["base_path"])) {
		if ($total_rows > 0) {
			$nav = "<tr bgcolor='#" . $colors["header"] . "'>
					<td colspan='13'>
						<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_devices.php?report=devices&page=" . ($_REQUEST["page"]-1) . "'>"; } $nav .= "Previous"; if ($_REQUEST["page"] > 1) { $nav .= "</a>"; } $nav .= "</strong>
								</td>\n
								<td align='center' class='textHeaderDark'>
									Showing 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]") . "
								</td>\n
								<td align='right' class='textHeaderDark'>
									<strong>"; if (($_REQUEST["page"] * $row_limit) < $total_rows) { $nav .= "<a class='linkOverDark' href='mactrack_view_devices.php?report=devices&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";
		}
	}else{
		$nav = html_create_nav($_REQUEST["page"], MAX_DISPLAY_PAGES, $row_limit, $total_rows, 13, "mactrack_view_sites.php");
	}

	print $nav;

	$display_text = array(
		"nosort" => array("Actions", ""),
		"device_name" => array("Device Name", "ASC"),
		"site_name" => array("Site Name", "ASC"),
		"snmp_status" => array("Status", "ASC"),
		"hostname" => array("Hostname", "ASC"),
		"device_type" => array("Device Type", "ASC"),
		"ips_total" => array("Total IP's", "DESC"),
		"ports_total" => array("User Ports", "DESC"),
		"ports_active" => array("User Ports Up", "DESC"),
		"ports_trunk" => array("Trunk Ports", "DESC"),
		"macs_active" => array("Active Macs", "DESC"),
		"vlans_total" => array("Total VLAN's", "DESC"),
		"last_runduration" => array("Last Duration", "DESC"));

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

	$i = 0;
	if (sizeof($devices) > 0) {
		foreach ($devices as $device) {
			$hostinfo["hostname"] = $device["hostname"];
			$hostinfo["user"]     = $device["user_name"];
			switch($device["term_type"]) {
			case 0:
				$hostinfo["transport"] = "none";
				break;
			case 1:
				$hostinfo["transport"] = "telnet";
				break;
			case 2:
				$hostinfo["transport"] = "ssh";
				break;
			case 3:
				$hostinfo["transport"] = "http";
				break;
			case 4:
				$hostinfo["transport"] = "https";
				break;
			}

			form_alternate_row_color($colors["alternate"],$colors["light"],$i); $i++;
				?>
				<td width=100>
					<?php if (mactrack_authorized(2121)) {?>
					<a href='<?php print $webroot . "plugins/mactrack/mactrack_devices.php?action=edit&device_id=" . $device['device_id'];?>' title='Edit Device'><img border='0' src='<?php print $webroot;?>plugins/mactrack/images/edit_object.png'></a>
					<?php api_plugin_hook_function('remote_link', $hostinfo); } ?>
					<?php if ($device["host_id"] > 0) {?>
					<a href='<?php print $webroot . "plugins/mactrack/mactrack_view_graphs.php?action=preview&report=graphs&style=selective&graph_list=&host_id=" . $device["host_id"] . "&graph_template_id=0&filter=";?>' title='View Graphs'><img border='0' src='<?php print $webroot;?>plugins/mactrack/images/view_graphs.gif'></a>
					<?php }else{?>
					<img title='Device Not Mapped to Cacti Device' border='0' src='<?php print $webroot;?>plugins/mactrack/images/view_graphs_disabled.gif'>
					<?php }?>
					<a href='<?php print $webroot . "plugins/mactrack/mactrack_view_macs.php?report=macs&reset&device_id=-1&scan_date=3&site_id=" . $_REQUEST["site_id"] . "&device_id=" . $device['device_id'];?>' title='View MAC Addresses'><img border='0' src='<?php print $webroot;?>plugins/mactrack/images/view_macs.gif'></a>
					<a href='<?php print $webroot . "plugins/mactrack/mactrack_view_interfaces.php?report=interfaces&reset&site=" . $_REQUEST["site_id"] . "&device=" . $device['device_id'];?>' title='View Interfaces'><img border='0' src='<?php print $webroot;?>plugins/mactrack/images/view_interfaces.gif'></a>
				</td>
				<td width=150>
					<?php print "<strong>" . (strlen($_REQUEST["filter"]) ? preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", $device["device_name"]) : $device["device_name"]) . "</strong>";?>
				</td>
				<td><?php print (strlen($_REQUEST["filter"]) ? preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", $device["site_name"]) : $device["site_name"]);?></td>
				<td><?php print get_colored_device_status(($device["disabled"] == "on" ? true : false), $device["snmp_status"]);?></td>
				<td><?php print (strlen($_REQUEST["filter"]) ? preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", $device["hostname"]) : $device["hostname"]);?></td>
				<td><?php print $device["device_type"];?></td>
				<td><?php print ($device["scan_type"] == "1" ? "N/A" : $device["ips_total"]);?></td>
				<td><?php print ($device["scan_type"] == "3" ? "N/A" : $device["ports_total"]);?></td>
				<td><?php print ($device["scan_type"] == "3" ? "N/A" : $device["ports_active"]);?></td>
				<td><?php print ($device["scan_type"] == "3" ? "N/A" : $device["ports_trunk"]);?></td>
				<td><?php print ($device["scan_type"] == "3" ? "N/A" : $device["macs_active"]);?></td>
				<td><?php print ($device["scan_type"] == "3" ? "N/A" : $device["vlans_total"]);?></td>
				<td><?php print number_format($device["last_runduration"], 1);?></td>
			</tr>
			<?php
		}
	}else{
		print "<tr><td colspan='10'><em>No MacTrack Devices</em></td></tr>";
	}

	print $nav;

	html_end_box(false);

	mactrack_display_stats();
}
Example #7
0
function hmib_devices()
{
    global $config, $item_rows;
    /* ================= input validation and session storage ================= */
    $filters = array('rows' => array('filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1'), 'page' => array('filter' => FILTER_VALIDATE_INT, 'default' => '1'), 'template' => array('filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1'), 'process' => array('filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1'), 'status' => array('filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1'), 'type' => array('filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1'), 'sort_column' => array('filter' => FILTER_CALLBACK, 'default' => 'description', 'options' => array('options' => 'sanitize_search_string')), 'sort_direction' => array('filter' => FILTER_CALLBACK, 'default' => 'ASC', 'options' => array('options' => 'sanitize_search_string')));
    validate_store_request_vars($filters, 'sess_hmib_devices');
    /* ================= input validation ================= */
    ?>
	<script type='text/javascript'>
	function applyFilter(objForm) {
		strURL  = '?action=devices';
		strURL += '&type='     + $('#type').val();
		strURL += '&status='   + $('#status').val();
		strURL += '&process='  + $('#process').val();
		strURL += '&template=' + $('#template').val();
		strURL += '&filter='   + $('#filter').val();
		strURL += '&rows='     + $('#rows').val();
		strURL += '&page='     + $('#page').val();
		strURL += '&header=false';
		loadPageNoHeader(strURL);
	}

	function clearFilter() {
		strURL = '?action=devices&clear=true&header=false';
		loadPageNoHeader(strURL);
	}

	$(function() {
		$('#devices').submit(function(event) {
			event.preventDefault();
			applyFilter();
		});
	});
	</script>
	<?php 
    html_start_box(__('Device Filter'), '100%', '', '3', 'center', '');
    ?>
	<tr class='even'>
		<td>
			<form id='devices' action='hmib.php?action=devices'>
			<table class='filterTable'>
				<tr>
					<td style='white-space:nowrap;width:55px;'>
						<?php 
    print __('OS Type');
    ?>
					</td>
					<td>
						<select id='type' onChange='applyFilter()'>
							<option value='-1'<?php 
    if (get_request_var('type') == '-1') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('All');
    ?>
</option>
							<?php 
    $types = db_fetch_assoc("SELECT DISTINCT id, CONCAT_WS('', name, ' [', version, ']') AS name\n\t\t\t\t\t\t\t\tFROM plugin_hmib_hrSystemTypes AS hrst\n\t\t\t\t\t\t\t\tINNER JOIN plugin_hmib_hrSystem AS hrs\n\t\t\t\t\t\t\t\tON hrst.id=hrs.host_type\n\t\t\t\t\t\t\t\tWHERE name!='' ORDER BY name");
    if (sizeof($types)) {
        foreach ($types as $t) {
            echo "<option value='" . $t['id'] . "' " . (get_request_var('type') == $t['id'] ? 'selected' : '') . '>' . $t['name'] . '</option>';
        }
    }
    ?>
						</select>
					</td>
					<td>
						<?php 
    print __('Template');
    ?>
					</td>
					<td>
						<select id='template' onChange='applyFilter()'>
							<option value='-1'<?php 
    if (get_request_var('template') == '-1') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('All');
    ?>
</option>
							<?php 
    $templates = db_fetch_assoc('SELECT DISTINCT ht.id, ht.name
								FROM host_template AS ht
								INNER JOIN host
								ON ht.id=host.host_template_id
								INNER JOIN plugin_hmib_hrSystem AS hrs
								ON host.id=hrs.host_id
								ORDER BY name');
    if (sizeof($templates)) {
        foreach ($templates as $t) {
            echo "<option value='" . $t['id'] . "' " . (get_request_var('template') == $t['id'] ? 'selected' : '') . '>' . $t['name'] . '</option>';
        }
    }
    ?>
						</select>
					</td>
					<td>
						<?php 
    print __('Process');
    ?>
					</td>
					<td>
						<select id='process' onChange='applyFilter()'>
							<option value='-1'<?php 
    if (get_request_var('process') == '-1') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('All');
    ?>
</option>
							<?php 
    $processes = db_fetch_assoc("SELECT DISTINCT name FROM plugin_hmib_hrSWRun WHERE name!='' ORDER BY name");
    if (sizeof($processes)) {
        foreach ($processes as $p) {
            echo "<option value='" . $p['name'] . "' " . (get_request_var('process') == $p['name'] ? 'selected' : '') . '>' . $p['name'] . '</option>';
        }
    }
    ?>
						</select>
					</td>
					<td>
						<input type='button' onClick='applyFilter(document.devices)' value='<?php 
    print __('Go');
    ?>
'>
					</td>
					<td>
						<input type='button' onClick='clearFilter()' value='<?php 
    print __('Clear');
    ?>
'>
					</td>
				</tr>
			</table>
			<table class='filterTable'>
				<tr>
					<td style='width:55px;'>
						<?php 
    print __('Search');
    ?>
					</td>
					<td>
						<input type='textbox' size='25' id='filter' value='<?php 
    print get_request_var('filter');
    ?>
'>
					</td>
					<td>
						<?php 
    print __('Status');
    ?>
					</td>
					<td>
						<select id='status' onChange='applyFilter()'>
							<option value='-1'<?php 
    if (get_request_var('type') == '-1') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('All');
    ?>
</option>
							<?php 
    $statuses = db_fetch_assoc('SELECT DISTINCT status
								FROM host
								INNER JOIN plugin_hmib_hrSystem
								ON host.id=plugin_hmib_hrSystem.host_id');
    $statuses = array_merge($statuses, array('-2' => array('status' => '-2')));
    if (sizeof($statuses)) {
        foreach ($statuses as $s) {
            switch ($s['status']) {
                case '0':
                    $status = __('Unknown');
                    break;
                case '1':
                    $status = __('Down');
                    break;
                case '2':
                    $status = __('Recovering');
                    break;
                case '3':
                    $status = __('Up');
                    break;
                case '-2':
                    $status = __('Disabled');
                    break;
            }
            echo "<option value='" . $s['status'] . "' " . (get_request_var('status') == $s['status'] ? 'selected' : '') . '>' . $status . '</option>';
        }
    }
    ?>
						</select>
					</td>
					<td>
						<?php 
    print __('Devices');
    ?>
					</td>
					<td>
						<select id='rows' onChange='applyFilter()'>
							<option value='-1'<?php 
    if (get_request_var('rows') == '-1') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('Default');
    ?>
</option>
							<?php 
    if (sizeof($item_rows)) {
        foreach ($item_rows as $key => $name) {
            echo "<option value='" . $key . "' " . (get_request_var('rows') == $key ? 'selected' : '') . '>' . $name . '</option>';
        }
    }
    ?>
						</select>
					</td>
				</tr>
			</table>
			<input type='hidden' id='page' value='<?php 
    print get_request_var('page');
    ?>
'>
			</form>
		</td>
	</tr>
	<?php 
    html_end_box();
    if (get_request_var('rows') == '-1') {
        $num_rows = read_config_option('num_rows_table');
    } else {
        $num_rows = get_request_var('rows');
    }
    $limit = ' LIMIT ' . $num_rows * (get_request_var('page') - 1) . ',' . $num_rows;
    $sql_where = '';
    if (get_request_var('template') != '-1') {
        $sql_where .= (strlen($sql_where) ? ' AND' : 'WHERE') . ' host.host_template_id=' . get_request_var('template');
    }
    if (get_request_var('status') != '-1') {
        $sql_where .= (strlen($sql_where) ? ' AND' : 'WHERE') . ' hrs.host_status=' . get_request_var('status');
    }
    if (get_request_var('type') != '-1') {
        $sql_where .= (strlen($sql_where) ? ' AND' : 'WHERE') . ' hrs.host_type=' . get_request_var('type');
    }
    if (get_request_var('process') != '' && get_request_var('process') != '-1') {
        $sql_join = 'INNER JOIN plugin_hmib_hrSWRun AS hrswr ON host.id=hrswr.host_id';
        $sql_where .= (strlen($sql_where) ? ' AND' : 'WHERE') . " hrswr.name='" . get_request_var('process') . "'";
    } else {
        $sql_join = '';
    }
    if (get_request_var('filter') != '') {
        $sql_where .= (strlen($sql_where) ? ' AND' : 'WHERE') . " host.description LIKE '%" . get_request_var('filter') . "%' OR\n\t\t\thost.hostname LIKE '%" . get_request_var('filter') . "%'";
    }
    $sql = "SELECT hrs.*, host.hostname, host.description, host.disabled\n\t\tFROM plugin_hmib_hrSystem AS hrs\n\t\tINNER JOIN host ON host.id=hrs.host_id\n\t\t{$sql_join}\n\t\t{$sql_where}\n\t\tORDER BY " . get_request_var('sort_column') . ' ' . get_request_var('sort_direction') . ' ' . $limit;
    $rows = db_fetch_assoc($sql);
    $total_rows = db_fetch_cell("SELECT COUNT(*)\n\t\tFROM plugin_hmib_hrSystem AS hrs\n\t\tINNER JOIN host ON host.id=hrs.host_id\n\t\t{$sql_join}\n\t\t{$sql_where}");
    $nav = html_nav_bar('hmib.php?action=devices', MAX_DISPLAY_PAGES, get_request_var('page'), $num_rows, $total_rows, 16, __('Devices'), 'page', 'main');
    print $nav;
    html_start_box('', '100%', '', '3', 'center', '');
    $display_text = array('nosort' => array('display' => __('Actions'), 'sort' => 'ASC', 'align' => 'left'), 'description' => array('display' => __('Hostname'), 'sort' => 'ASC', 'align' => 'left'), 'host_status' => array('display' => __('Status'), 'sort' => 'DESC', 'align' => 'right'), 'uptime' => array('display' => __('Uptime(d:h:m)'), 'sort' => 'DESC', 'align' => 'right'), 'users' => array('display' => __('Users'), 'sort' => 'DESC', 'align' => 'right'), 'cpuPercent' => array('display' => __('CPU %'), 'sort' => 'DESC', 'align' => 'right'), 'numCpus' => array('display' => __('CPUs'), 'sort' => 'DESC', 'align' => 'right'), 'processes' => array('display' => __('Processes'), 'sort' => 'DESC', 'align' => 'right'), 'memSize' => array('display' => __('Total Mem'), 'sort' => 'DESC', 'align' => 'right'), 'memUsed' => array('display' => __('Used Mem'), 'sort' => 'DESC', 'align' => 'right'), 'swapSize' => array('display' => __('Total Swap'), 'sort' => 'DESC', 'align' => 'right'), 'swapUsed' => array('display' => __('Used Swap'), 'sort' => 'DESC', 'align' => 'right'));
    html_header_sort($display_text, get_request_var('sort_column'), get_request_var('sort_direction'), false, 'hmib.php?action=devices');
    /* set some defaults */
    $url = $config['url_path'] . 'plugins/hmib/hmib.php';
    $proc = $config['url_path'] . 'plugins/hmib/images/cog.png';
    $host = $config['url_path'] . 'plugins/hmib/images/server.png';
    $hardw = $config['url_path'] . 'plugins/hmib/images/view_hardware.gif';
    $inven = $config['url_path'] . 'plugins/hmib/images/view_inventory.gif';
    $storage = $config['url_path'] . 'plugins/hmib/images/drive.png';
    $dashboard = $config['url_path'] . 'plugins/hmib/images/view_dashboard.gif';
    $graphs = $config['url_path'] . 'plugins/hmib/images/view_graphs.gif';
    $nographs = $config['url_path'] . 'plugins/hmib/images/view_graphs_disabled.gif';
    $htdq = db_fetch_cell("SELECT id \n\t\tFROM snmp_query \n\t\tWHERE hash='137aeab842986a76cf5bdef41b96c9a3'");
    $hcpudq = db_fetch_cell("SELECT id \n\t\tFROM snmp_query \n\t\tWHERE hash='0d1ab53fe37487a5d0b9e1d3ee8c1d0d'");
    $hugt = db_fetch_cell("SELECT id \n\t\tFROM graph_templates \n\t\tWHERE hash='e8462bbe094e4e9e814d4e681671ea82'");
    $hpgt = db_fetch_cell("SELECT id \n\t\tFROM graph_templates \n\t\tWHERE hash='62205afbd4066e5c4700338841e3901e'");
    if (sizeof($rows)) {
        foreach ($rows as $row) {
            $days = intval($row['uptime'] / (60 * 60 * 24 * 100));
            $remainder = $row['uptime'] % (60 * 60 * 24 * 100);
            $hours = intval($remainder / (60 * 60 * 100));
            $remainder = $remainder % (60 * 60 * 100);
            $minutes = intval($remainder / (60 * 100));
            $found = db_fetch_cell('SELECT COUNT(*) FROM graph_local WHERE host_id=' . $row['host_id']);
            form_alternate_row();
            echo "<td width='120'>";
            //echo "<a style='padding:1px;' href='" . htmlspecialchars("$url?action=dashboard&reset=1&device=" . $row["host_id"]) . "'><img src='$dashboard' title='View Dashboard' align='absmiddle'></a>";
            echo "<a style='padding:1px;' href='" . htmlspecialchars("{$url}?action=storage&reset=1&device=" . $row['host_id']) . "'><img src='{$storage}' title='" . __('View Storage') . "' align='absmiddle' alt=''></a>";
            echo "<a style='padding:1px;' href='" . htmlspecialchars("{$url}?action=hardware&reset=1&device=" . $row['host_id']) . "'><img src='{$hardw}' title='" . __('View Hardware') . "' align='absmiddle' alt=''></a>";
            echo "<a style='padding:1px;' href='" . htmlspecialchars("{$url}?action=running&reset=1&device=" . $row['host_id']) . "'><img src='{$proc}' title='" . __('View Processes') . "' align='absmiddle' alt=''></a>";
            echo "<a style='padding:1px;' href='" . htmlspecialchars("{$url}?action=software&reset=1&device=" . $row['host_id']) . "'><img src='{$inven}' title='" . __('View Software Inventory') . "' align='absmiddle' alt=''></a>";
            if ($found) {
                echo "<a style='padding:1px;' href='" . htmlspecialchars("{$url}?action=graphs&reset=1&host_id=" . $row['host_id'] . "&style=selective&graph_add=&graph_list=&graph_template_id=0&filter=") . "'><img  src='{$graphs}' title='" . __('View Graphs') . "' align='absmiddle' alt=''></a>";
            } else {
                echo "<img src='{$nographs}' title='" . __('No Graphs Defined') . "' align='absmiddle' alt=''>";
            }
            $graph_cpu = hmib_get_graph_url($hcpudq, 0, $row['host_id'], '', $row['numCpus'], false);
            $graph_cpup = hmib_get_graph_url($hcpudq, 0, $row['host_id'], '', round($row['cpuPercent'], 2) . ' %', false);
            $graph_users = hmib_get_graph_template_url($hugt, 0, $row['host_id'], $row['host_status'] < 2 ? 'N/A' : $row['users'], false);
            $graph_aproc = hmib_get_graph_template_url($hpgt, 0, $row['host_id'], $row['host_status'] < 2 ? 'N/A' : $row['processes'], false);
            if (api_plugin_user_realm_auth('host.php')) {
                $host_url = "<a href='" . htmlspecialchars($config['url_path'] . 'host.php?action=edit&id=' . $row['host_id']) . "' title='" . __('Edit Device') . "'>" . $row['hostname'] . '</a>';
            } else {
                $host_url = $row['hostname'];
            }
            echo '</td>';
            echo "<td class='nowrap left'>" . $row['description'] . ' [' . $host_url . ']' . '</td>';
            echo "<td class='nowrap right'>" . get_colored_device_status($row['disabled'] == 'on' ? true : false, $row['host_status']) . '</td>';
            echo "<td class='nowrap right'>" . hmib_format_uptime($days, $hours, $minutes) . '</td>';
            echo "<td class='nowrap right'>" . $graph_users . '</td>';
            echo "<td class='nowrap right'>" . ($row['host_status'] < 2 ? 'N/A' : $graph_cpup) . '</td>';
            echo "<td class='nowrap right'>" . ($row['host_status'] < 2 ? 'N/A' : $graph_cpu) . '</td>';
            echo "<td class='nowrap right'>" . $graph_aproc . '</td>';
            echo "<td class='nowrap right'>" . hmib_memory($row['memSize']) . '</td>';
            echo "<td class='nowrap right'>" . ($row['host_status'] < 2 ? 'N/A' : round($row['memUsed'], 0)) . ' %</td>';
            echo "<td class='nowrap right'>" . hmib_memory($row['swapSize']) . '</td>';
            echo "<td class='nowrap right'>" . ($row['host_status'] < 2 ? 'N/A' : round($row['swapUsed'], 0)) . ' %</td>';
        }
        echo '</tr>';
    } else {
        print '<tr><td><em>' . __('No Devices Found') . '</em></td></tr>';
    }
    html_end_box(false);
    if (sizeof($rows)) {
        print $nav;
    }
}
Example #8
0
function thold_hosts($header_label)
{
    global $assoc_actions, $item_rows;
    /* ================= input validation and session storage ================= */
    get_filter_request_var('id');
    $filters = array('rows' => array('filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1'), 'page' => array('filter' => FILTER_VALIDATE_INT, 'default' => '1'), 'filter' => array('filter' => FILTER_CALLBACK, 'pageset' => true, 'default' => '', 'options' => array('options' => 'sanitize_search_string')), 'sort_column' => array('filter' => FILTER_CALLBACK, 'default' => 'description', 'options' => array('options' => 'sanitize_search_string')), 'sort_direction' => array('filter' => FILTER_CALLBACK, 'default' => 'ASC', 'options' => array('options' => 'sanitize_search_string')), 'host_template_id' => array('filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1'), 'associated' => array('filter' => FILTER_CALLBACK, 'default' => 'true', 'options' => array('options' => 'sanitize_search_string')));
    validate_store_request_vars($filters, 'sess_maint');
    /* ================= input validation ================= */
    /* if the number of rows is -1, set it to the default */
    if (get_request_var('rows') == '-1') {
        $rows = read_config_option('num_rows_table');
    } else {
        $rows = get_request_var('rows');
    }
    ?>
	<script type='text/javascript'>
	function applyFilter() {
		strURL  = 'maint.php?tab=hosts&action=edit&id=<?php 
    print get_request_var('id');
    ?>
'
		strURL += '&rows=' + $('#rows').val();
		strURL += '&host_template_id=' + $('#host_template_id').val();
		strURL += '&associated=' + $('#associated').is(':checked');
		strURL += '&filter=' + $('#filter').val();
		strURL += '&header=false';
		loadPageNoHeader(strURL);
	}

	function clearFilter() {
		strURL = 'maint.php?tab=hosts&action=edit&id=<?php 
    print get_request_var('id');
    ?>
&clear=true&header=false'
		loadPageNoHeader(strURL);
	}
	</script>
	<?php 
    html_start_box(__('Associated Devices %s', htmlspecialchars($header_label)), '100%', '', '3', 'center', '');
    ?>
	<tr class='even'>
		<td>
		<form name='form_devices' method='post' action='maint.php?action=edit&tab=hosts'>
			<table class='filterTable'>
				<tr>
					<td>
						<?php 
    print __('Search');
    ?>
					</td>
					<td>
						<input type='text' id='filter' size='25' value='<?php 
    print htmlspecialchars(get_request_var('filter'));
    ?>
' onChange='applyFilter()'>
					</td>
					<td>
						<?php 
    print __('Type');
    ?>
					</td>
					<td>
						<select id='host_template_id' onChange='applyFilter()'>
							<option value='-1'<?php 
    if (get_request_var('host_template_id') == '-1') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('Any');
    ?>
</option>
							<option value='0'<?php 
    if (get_request_var('host_template_id') == '0') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('None');
    ?>
</option>
							<?php 
    $host_templates = db_fetch_assoc('SELECT DISTINCT ht.id, ht.name 
								FROM host_template AS ht
								INNER JOIN host AS h
								ON h.host_template_id=ht.id 
								ORDER BY ht.name');
    if (sizeof($host_templates) > 0) {
        foreach ($host_templates as $host_template) {
            print "<option value='" . $host_template['id'] . "'";
            if (get_request_var('host_template_id') == $host_template['id']) {
                print ' selected';
            }
            print '>' . htmlspecialchars($host_template['name']) . "</option>\n";
        }
    }
    ?>
						</select>
					</td>
					<td>
						<?php 
    print __('Devices');
    ?>
					</td>
					<td>
						<select id='rows' onChange='applyFilter()'>
							<option value='-1'<?php 
    if (get_request_var('rows') == '-1') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('Default');
    ?>
</option>
							<?php 
    if (sizeof($item_rows) > 0) {
        foreach ($item_rows as $key => $value) {
            print "<option value='" . $key . "'";
            if (get_request_var('rows') == $key) {
                print ' selected';
            }
            print '>' . htmlspecialchars($value) . "</option>\n";
        }
    }
    ?>
						</select>
					</td>
					<td>
						<input type='checkbox' id='associated' onChange='applyFilter()' <?php 
    print get_request_var('associated') == 'true' || get_request_var('associated') == 'on' ? 'checked' : '';
    ?>
>
					</td>
					<td>
						<label for='associated'><?php 
    print __('Associated');
    ?>
</label>
					</td>
					<td>
						<input type='button' value='<?php 
    print __('Go');
    ?>
' onClick='applyFilter()' title='<?php 
    print __('Set/Refresh Filters');
    ?>
'>
					</td>
					<td>
						<input type='button' name='clear' value='<?php 
    print __('Clear');
    ?>
' onClick='clearFilter()' title='<?php 
    print __('Clear Filters');
    ?>
'>
					</td>
				</tr>
			</table>
			<input type='hidden' id='page' value='<?php 
    print get_request_var('page');
    ?>
'>
			<input type='hidden' id='id' value='<?php 
    print get_request_var('id');
    ?>
'>
		</form>
		</td>
	</tr>
	<?php 
    html_end_box();
    /* form the 'where' clause for our main sql query */
    if (strlen(get_request_var('filter'))) {
        $sql_where = "WHERE (h.hostname LIKE '%" . get_request_var('filter') . "%' \n\t\t\tOR h.description LIKE '%" . get_request_var('filter') . "%')";
    } else {
        $sql_where = '';
    }
    if (get_request_var('host_template_id') == '-1') {
        /* Show all items */
    } elseif (get_request_var('host_template_id') == '0') {
        $sql_where .= (strlen($sql_where) ? ' AND ' : 'WHERE ') . ' h.host_template_id=0';
    } elseif (!isempty_request_var('host_template_id')) {
        $sql_where .= (strlen($sql_where) ? ' AND ' : 'WHERE ') . ' h.host_template_id=' . get_request_var('host_template_id');
    }
    if (get_request_var('associated') == 'false') {
        /* Show all items */
    } else {
        $sql_where .= (strlen($sql_where) ? ' AND ' : 'WHERE ') . ' type=1 AND schedule=' . get_request_var('id');
    }
    if (get_request_var('id')) {
        $total_rows = db_fetch_cell("SELECT\n\t\t\tCOUNT(DISTINCT h.id)\n\t\t\tFROM host AS h\n\t\t\tLEFT JOIN (SELECT DISTINCT host_id FROM thold_data) AS td \n\t\t\tON h.id=td.host_id\n\t\t\tLEFT JOIN plugin_maint_hosts AS pmh\n\t\t\tON h.id=pmh.host\n\t\t\tAND pmh.schedule=" . get_request_var('id') . "\n\t\t\t{$sql_where}");
    } else {
        $total_rows = 0;
    }
    $sortby = get_request_var('sort_column');
    if ($sortby == 'hostname') {
        $sortby = 'INET_ATON(hostname)';
    }
    if (get_request_var('id')) {
        $sql_query = 'SELECT h.*, pmh.type, graphs, data_sources, tholds, 
			(SELECT schedule FROM plugin_maint_hosts WHERE host=h.id AND schedule=' . get_request_var('id') . ") AS associated \n\t\t\tFROM host as h\n\t\t\tLEFT JOIN (SELECT COUNT(id) AS tholds, host_id FROM thold_data GROUP BY host_id) AS td\n\t\t\tON td.host_id=h.id\n\t\t\tLEFT JOIN (SELECT COUNT(id) AS graphs, host_id FROM graph_local GROUP BY host_id) AS gl\n\t\t\tON gl.host_id=h.id\n\t\t\tLEFT JOIN (SELECT COUNT(id) AS data_sources, host_id FROM data_local GROUP BY host_id) AS dl\n\t\t\ton dl.host_id=h.id\n\t\t\tLEFT JOIN plugin_maint_hosts AS pmh\n\t\t\tON pmh.host=h.id\n\t\t\tAND pmh.schedule=" . get_request_var('id') . "\n\t\t\t{$sql_where} \n\t\t\tGROUP BY h.id\n\t        ORDER BY " . $sortby . ' ' . get_request_var('sort_direction') . '
			LIMIT ' . $rows * (get_request_var('page') - 1) . ',' . $rows;
        $hosts = db_fetch_assoc($sql_query);
    } else {
        $hosts = array();
    }
    $display_text = array('description' => array('display' => __('Description'), 'align' => 'left', 'sort' => 'ASC'), 'id' => array('display' => __('ID'), 'align' => 'right', 'sort' => 'asc'), 'nosort' => array('display' => __('Associated Schedules'), 'align' => 'left', 'sort' => ''), 'graphs' => array('display' => __('Graphs'), 'align' => 'right', 'sort' => 'desc'), 'data_sources' => array('display' => __('Data Sources'), 'align' => 'right', 'sort' => 'desc'), 'tholds' => array('display' => __('Thresholds'), 'align' => 'right', 'sort' => 'desc'), 'nosort1' => array('display' => __('Status'), 'align' => 'center', 'sort' => ''), 'hostname' => array('display' => __('Hostname'), 'align' => 'left', 'sort' => 'desc'));
    /* generate page list */
    $nav = html_nav_bar('maint.php?action=edit&tab=hosts&id=' . get_request_var('id'), MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, 13, __('Devices'), 'page', 'main');
    form_start('maint.php', 'chk');
    print $nav;
    html_start_box('', '100%', '', '3', 'center', '');
    html_header_sort_checkbox($display_text, get_request_var('sort_column'), get_request_var('sort_direction'), false, 'maint.php?action=edit&tab=hosts&id=' . get_request_var('id'));
    if (sizeof($hosts)) {
        foreach ($hosts as $host) {
            form_alternate_row('line' . $host['id']);
            form_selectable_cell(strlen(get_request_var('filter')) ? preg_replace('/(' . preg_quote(get_request_var('filter')) . ')/i', "<span class='filteredValue'>\\1</span>", htmlspecialchars($host['description'])) : htmlspecialchars($host['description']), $host['id'], 250);
            form_selectable_cell(number_format_i18n($host['id']), $host['id'], '', 'text-align:right');
            if ($host['associated'] != '') {
                $names = '<span class="deviceUp">' . __('Current Schedule') . '</span>';
            } else {
                $names = '';
            }
            if (sizeof($lists = db_fetch_assoc('SELECT name FROM plugin_maint_schedules INNER JOIN plugin_maint_hosts ON plugin_maint_schedules.id=plugin_maint_hosts.schedule WHERE type=1 AND host=' . $host['id'] . ' AND plugin_maint_schedules.id != ' . get_request_var('id')))) {
                foreach ($lists as $name) {
                    $names .= (strlen($names) ? ', ' : '') . "<span class='deviceRecovering'>" . $name['name'] . '</span>';
                }
            }
            if ($names == '') {
                form_selectable_cell('<span class="deviceUnknown">' . __('No Schedules') . '</span>', $host['id']);
            } else {
                form_selectable_cell($names, $host['id']);
            }
            form_selectable_cell(number_format_i18n($host['graphs']), $host['id'], '', 'text-align:right');
            form_selectable_cell(number_format_i18n($host['data_sources']), $host['id'], '', 'text-align:right');
            form_selectable_cell(number_format_i18n($host['tholds']), $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(strlen(get_request_var('filter')) ? preg_replace('/(' . preg_quote(get_request_var('filter')) . ')/i', "<span class='filteredValue'>\\1</span>", htmlspecialchars($host['hostname'])) : htmlspecialchars($host['hostname']), $host['id']);
            form_checkbox_cell($host['description'], $host['id']);
            form_end_row();
        }
    } else {
        print "<tr><td colspan='8'><em>" . __('No Associated Devices Found') . "</em></td></tr>";
    }
    html_end_box(false);
    if (sizeof($hosts)) {
        print $nav;
    }
    form_hidden_box('id', get_request_var('id'), '');
    form_hidden_box('save_hosts', '1', '');
    /* draw the dropdown containing a list of available actions for this form */
    draw_actions_dropdown($assoc_actions);
    form_end();
}
Example #9
0
function host()
{
    $current_page = get_get_var_number("page", "1");
    $menu_items = array("remove" => "Remove", "duplicate" => "Duplicate", "enable" => "Enable", "disable" => "Disable", "clear_stats" => "Clear Statistics", "change_snmp_opts" => "Change SNMP Options", "change_avail_opts" => "Change Availability Options", "change_poller" => "Change Poller");
    $filter_array = array();
    /* search field: device template */
    if (isset_get_var("search_device_template")) {
        $filter_array["=host_template_id"] = get_get_var("search_device_template");
    }
    /* search field: device status */
    if (isset_get_var("search_status")) {
        $filter_array["=status"] = get_get_var("search_status");
    }
    /* search field: filter (searches device description and hostname) */
    if (isset_get_var("search_filter")) {
        $filter_array["%filter"] = array("hostname" => get_get_var("search_filter"), "description" => get_get_var("search_filter"));
    }
    /* get a list of all devices on this page */
    $devices = api_device_list($filter_array, "description", "asc", read_config_option("num_rows_device") * ($current_page - 1), read_config_option("num_rows_device"));
    /* get the total number of devices on all pages */
    $total_rows = api_device_total_get($filter_array);
    /* generate page list */
    $url_string = build_get_url_string(array("search_device_template", "search_status", "search_filter"));
    $url_page_select = get_page_list($current_page, MAX_DISPLAY_PAGES, read_config_option("num_rows_device"), $total_rows, "devices.php" . $url_string . ($url_string == "" ? "?" : "&") . "page=|PAGE_NUM|");
    form_start("devices.php");
    $box_id = "1";
    html_start_box("<strong>" . _("Devices") . "</strong>", "devices.php?action=edit", $url_page_select);
    html_header_checkbox(array(_("Description"), _("Status"), _("Hostname"), _("Current (ms)"), _("Average (ms)"), _("Availability")), $box_id);
    $i = 0;
    if (sizeof($devices) > 0) {
        foreach ($devices as $host) {
            ?>
			<tr class="item" id="box-<?php 
            echo $box_id;
            ?>
-row-<?php 
            echo $host["id"];
            ?>
" onClick="display_row_select('<?php 
            echo $box_id;
            ?>
',document.forms[0],'box-<?php 
            echo $box_id;
            ?>
-row-<?php 
            echo $host["id"];
            ?>
', 'box-<?php 
            echo $box_id;
            ?>
-chk-<?php 
            echo $host["id"];
            ?>
')" onMouseOver="display_row_hover('box-<?php 
            echo $box_id;
            ?>
-row-<?php 
            echo $host["id"];
            ?>
')" onMouseOut="display_row_clear('box-<?php 
            echo $box_id;
            ?>
-row-<?php 
            echo $host["id"];
            ?>
')">
				<td class="title">
					<a onClick="display_row_block('box-<?php 
            echo $box_id;
            ?>
-row-<?php 
            echo $host["id"];
            ?>
')" href="devices.php?action=edit&id=<?php 
            echo $host["id"];
            ?>
"><span id="box-<?php 
            echo $box_id;
            ?>
-text-<?php 
            echo $host["id"];
            ?>
"><?php 
            echo html_highlight_words(get_get_var("search_filter"), $host["description"]);
            ?>
</span></a>
				</td>
				<td>
					<?php 
            echo get_colored_device_status($host["disabled"] == "on" ? true : false, $host["status"]);
            ?>
				</td>
				<td>
					<?php 
            echo html_highlight_words(get_get_var("search_filter"), $host["hostname"]);
            ?>
				</td>
				<td>
					<?php 
            echo round($host["cur_time"], 2);
            ?>
				</td>
				<td>
					<?php 
            echo round($host["avg_time"], 2);
            ?>
				</td>
				<td>
					<?php 
            echo round($host["availability"], 2);
            ?>
%
				</td>
				<td class="checkbox" align="center">
					<input type='checkbox' name='box-<?php 
            echo $box_id;
            ?>
-chk-<?php 
            echo $host["id"];
            ?>
' id='box-<?php 
            echo $box_id;
            ?>
-chk-<?php 
            echo $host["id"];
            ?>
' title="<?php 
            echo $host["description"];
            ?>
">
				</td>
			</tr>
			<?php 
        }
    } else {
        ?>
		<tr class="empty">
			<td colspan="6">
				No devices found.
			</td>
		</tr>
		<?php 
    }
    html_box_toolbar_draw($box_id, "0", "6", sizeof($filter_array) == 0 ? HTML_BOX_SEARCH_INACTIVE : HTML_BOX_SEARCH_ACTIVE, $url_page_select);
    html_end_box(false);
    html_box_actions_menu_draw($box_id, "0", $menu_items);
    html_box_actions_area_create($box_id);
    form_hidden_box("action_post", "device_list");
    form_end();
    /* fill in the list of available device templates for the search dropdown */
    $search_device_templates = array();
    $search_device_templates["-1"] = "Any";
    $search_device_templates["0"] = "None";
    $search_device_templates += array_rekey(api_device_template_list(), "id", "name");
    /* fill in the list of available host status types for the search dropdown */
    $search_host_status_types = array();
    $search_host_status_types["-1"] = "Any";
    $search_host_status_types["-2"] = "Disabled";
    $search_host_status_types += api_device_status_type_list();
    ?>

	<script language="JavaScript">
	<!--
	function action_area_handle_type(box_id, type, parent_div, parent_form) {
		if (type == 'remove') {
			parent_div.appendChild(document.createTextNode('Are you sure you want to remove these devices?'));
			parent_div.appendChild(action_area_generate_selected_rows(box_id));

			parent_div.appendChild(action_area_generate_input('radio', 'box-' + box_id + '-remove_type', '1'));
			parent_div.appendChild(document.createTextNode('Leave all graphs and data sources untouched. Data sources will be disabled however.'));
			parent_div.appendChild(action_area_generate_break());

			_elm_rt_input = action_area_generate_input('radio', 'box-' + box_id + '-remove_type', '2');
			_elm_rt_input.checked = true;
			parent_div.appendChild(_elm_rt_input);
			parent_div.appendChild(document.createTextNode("Delete all associated graphs and data sources."));

			action_area_update_header_caption(box_id, 'Remove Device');
			action_area_update_submit_caption(box_id, 'Remove');
			action_area_update_selected_rows(box_id, parent_form);
		}else if (type == 'duplicate') {
			parent_div.appendChild(document.createTextNode('Are you sure you want to duplicate these devices?'));
			parent_div.appendChild(action_area_generate_selected_rows(box_id));
			parent_div.appendChild(action_area_generate_input('text', 'box-' + box_id + '-action-area-txt1', ''));

			action_area_update_header_caption(box_id, 'Duplicate Devices');
			action_area_update_submit_caption(box_id, 'Duplicate');
			action_area_update_selected_rows(box_id, parent_form);
		}else if (type == 'enable') {
			parent_div.appendChild(document.createTextNode('Are you sure you want to enable these devices?'));
			parent_div.appendChild(action_area_generate_selected_rows(box_id));

			action_area_update_header_caption(box_id, 'Enable Devices');
			action_area_update_submit_caption(box_id, 'Enable');
			action_area_update_selected_rows(box_id, parent_form);
		}else if (type == 'disable') {
			parent_div.appendChild(document.createTextNode('Are you sure you want to disable these devices?'));
			parent_div.appendChild(action_area_generate_selected_rows(box_id));

			action_area_update_header_caption(box_id, 'Disable Devices');
			action_area_update_submit_caption(box_id, 'Disable');
			action_area_update_selected_rows(box_id, parent_form);
		}else if (type == 'clear_stats') {
			parent_div.appendChild(document.createTextNode('Are you sure you want to clear polling statistics for these devices?'));
			parent_div.appendChild(action_area_generate_selected_rows(box_id));

			action_area_update_header_caption(box_id, 'Clear Polling Statistics');
			action_area_update_submit_caption(box_id, 'Clear');
			action_area_update_selected_rows(box_id, parent_form);
		}else if (type == 'search') {
			_elm_dt_input = action_area_generate_select('box-' + box_id + '-search_device_template');
			<?php 
    echo get_js_dropdown_code('_elm_dt_input', $search_device_templates, isset_get_var("search_device_template") ? get_get_var("search_device_template") : "-1");
    ?>

			_elm_ds_input = action_area_generate_select('box-' + box_id + '-search_status');
			<?php 
    echo get_js_dropdown_code('_elm_ds_input', $search_host_status_types, isset_get_var("search_status") ? get_get_var("search_status") : "-1");
    ?>

			_elm_ht_input = action_area_generate_input('text', 'box-' + box_id + '-search_filter', '<?php 
    echo get_get_var("search_filter");
    ?>
');
			_elm_ht_input.size = '30';

			parent_div.appendChild(action_area_generate_search_field(_elm_dt_input, 'Device Template', true, false));
			parent_div.appendChild(action_area_generate_search_field(_elm_ds_input, 'Device Status', false, false));
			parent_div.appendChild(action_area_generate_search_field(_elm_ht_input, 'Filter', false, true));

			action_area_update_header_caption(box_id, 'Search');
			action_area_update_submit_caption(box_id, 'Search');
		}
	}
	-->
	</script>

	<?php 
}
function mactrack_format_device_row($device, $actions = false)
{
    global $config, $mactrack_device_types;
    /* viewer level */
    if ($actions) {
        $row = "<a href='" . htmlspecialchars($config['url_path'] . 'plugins/mactrack/mactrack_interfaces.php?device_id=' . $device['device_id'] . '&issues=0&page=1') . "'><img src='" . $config['url_path'] . "plugins/mactrack/images/view_interfaces.gif' alt='' title='" . __('View Interfaces') . "' align='middle' border='0'></a>";
        /* admin level */
        if (api_user_realm_auth('mactrack_sites.php')) {
            if ($device['disabled'] == '') {
                $row .= "<img id='r_" . $device['device_id'] . "' src='" . $config['url_path'] . "plugins/mactrack/images/rescan_device.gif' alt='' onClick='scan_device(" . $device['device_id'] . ")' title='" . __('Rescan Device') . "' align='middle' border='0'>";
            } else {
                $row .= "<img src='" . $config['url_path'] . "plugins/mactrack/images/view_none.gif' alt='' align='middle' border='0'>";
            }
        }
        print "<td style='width:40px;'>" . $row . "</td>";
    }
    form_selectable_cell(filter_value($device['device_name'], get_request_var('filter'), "mactrack_devices.php?action=edit&device_id=" . $device['device_id']), $device['device_id']);
    form_selectable_cell($device['site_name'], $device['device_id']);
    form_selectable_cell(get_colored_device_status($device['disabled'] == 'on' ? true : false, $device['snmp_status']), $device['device_id']);
    form_selectable_cell(filter_value($device['hostname'], get_request_var('filter')), $device['device_id']);
    form_selectable_cell($device['device_type'] == '' ? __('Not Detected') : $device['device_type'], $device['device_id']);
    form_selectable_cell($device['scan_type'] == '1' ? __('N/A') : $device['ips_total'], $device['device_id']);
    form_selectable_cell($device['scan_type'] == '3' ? __('N/A') : $device['ports_total'], $device['device_id']);
    form_selectable_cell($device['scan_type'] == '3' ? __('N/A') : $device['ports_active'], $device['device_id']);
    form_selectable_cell($device['scan_type'] == '3' ? __('N/A') : $device['ports_trunk'], $device['device_id']);
    form_selectable_cell($device['scan_type'] == '3' ? __('N/A') : $device['macs_active'], $device['device_id']);
    form_selectable_cell(number_format($device['last_runduration'], 1), $device['device_id']);
    form_checkbox_cell($device['device_name'], $device['device_id']);
    form_end_row();
}
function mactrack_view_devices()
{
    global $title, $report, $mactrack_search_types, $mactrack_device_types, $rows_selector, $config, $item_rows;
    mactrack_device_request_validation();
    if (get_request_var('rows') == -1) {
        $row_limit = read_config_option('num_rows_table');
    } elseif (get_request_var('rows') == -2) {
        $row_limit = 999999;
    } else {
        $row_limit = get_request_var('rows');
    }
    $webroot = $config['url_path'] . '/plugins/mactrack/';
    mactrack_tabs();
    html_start_box($title, '100%', '', '3', 'center', '');
    mactrack_device_filter2();
    html_end_box();
    $sql_where = '';
    $devices = mactrack_view_get_device_records($sql_where, $row_limit);
    $total_rows = db_fetch_cell("SELECT\n\t\tCOUNT(mac_track_devices.device_id)\n\t\tFROM mac_track_sites\n\t\tRIGHT JOIN mac_track_devices ON mac_track_devices.site_id = mac_track_sites.site_id\n\t\tLEFT JOIN mac_track_device_types ON (mac_track_device_types.device_type_id=mac_track_devices.device_type_id)\n\t\t{$sql_where}");
    $nav = html_nav_bar('mactrack_view_devices.php?report=devices', MAX_DISPLAY_PAGES, get_request_var('page'), $row_limit, $total_rows, 13, __('Devices'));
    print $nav;
    html_start_box('', '100%', '', '3', 'center', '');
    $display_text = array('nosort' => array(__('Actions'), ''), 'device_name' => array(__('Device Name'), 'ASC'), 'site_name' => array(__('Site Name'), 'ASC'), 'snmp_status' => array(__('Status'), 'ASC'), 'hostname' => array(__('Hostname'), 'ASC'), 'device_type' => array(__('Device Type'), 'ASC'), 'ips_total' => array(__('Total IP\'s'), 'DESC'), 'ports_total' => array(__('User Ports'), 'DESC'), 'ports_active' => array(__('User Ports Up'), 'DESC'), 'ports_trunk' => array(__('Trunk Ports'), 'DESC'), 'macs_active' => array(__('Active Macs'), 'DESC'), 'vlans_total' => array(__('Total VLAN\'s'), 'DESC'), 'last_runduration' => array(__('Last Duration'), 'DESC'));
    html_header_sort($display_text, get_request_var('sort_column'), get_request_var('sort_direction'));
    $i = 0;
    if (sizeof($devices) > 0) {
        foreach ($devices as $device) {
            $hostinfo['hostname'] = $device['hostname'];
            $hostinfo['user'] = $device['user_name'];
            switch ($device['term_type']) {
                case 0:
                    $hostinfo['transport'] = 'none';
                    break;
                case 1:
                    $hostinfo['transport'] = 'telnet';
                    break;
                case 2:
                    $hostinfo['transport'] = 'ssh';
                    break;
                case 3:
                    $hostinfo['transport'] = 'http';
                    break;
                case 4:
                    $hostinfo['transport'] = 'https';
                    break;
            }
            form_alternate_row();
            ?>
				<td width=100>
					<?php 
            if (api_user_realm_auth('mactrack_sites.php')) {
                ?>
					<a href='<?php 
                print htmlspecialchars($webroot . 'mactrack_devices.php?action=edit&device_id=' . $device['device_id']);
                ?>
' title='<?php 
                print __('Edit Device');
                ?>
'><img border='0' src='<?php 
                print $webroot;
                ?>
images/edit_object.png'></a>
					<?php 
                api_plugin_hook_function('remote_link', $hostinfo);
            }
            ?>
					<?php 
            if ($device['host_id'] > 0) {
                ?>
					<a href='<?php 
                print htmlspecialchars($webroot . 'mactrack_view_graphs.php?action=preview&report=graphs&style=selective&graph_list=&host=' . $device['host_id'] . '&graph_template_id=0&filter=');
                ?>
' title='<?php 
                print __('View Graphs');
                ?>
'><img border='0' src='<?php 
                print $webroot;
                ?>
images/view_graphs.gif'></a>
					<?php 
            } else {
                ?>
					<img title='<?php 
                print __('Device Not Mapped to Cacti Device');
                ?>
' border='0' src='<?php 
                print $webroot;
                ?>
images/view_graphs_disabled.gif'>
					<?php 
            }
            ?>
					<a href='<?php 
            print htmlspecialchars($webroot . 'mactrack_view_macs.php?report=macs&reset&device_id=-1&scan_date=3&site_id=' . get_request_var('site_id') . '&device_id=' . $device['device_id']);
            ?>
' title='<?php 
            print __('View MAC Addresses');
            ?>
'><img border='0' src='<?php 
            print $webroot;
            ?>
images/view_macs.gif'></a>
					<a href='<?php 
            print htmlspecialchars($webroot . 'mactrack_view_interfaces.php?report=interfaces&reset&site=' . get_request_var('site_id') . '&device=' . $device['device_id']);
            ?>
' title='<?php 
            print __('View Interfaces');
            ?>
'><img border='0' src='<?php 
            print $webroot;
            ?>
images/view_interfaces.gif'></a>
				</td>
				<td class='hyperLink'>
					<?php 
            print filter_value($device['device_name'], get_request_var('filter'));
            ?>
				</td>
				<td><?php 
            print filter_value($device['site_name'], get_request_var('filter'));
            ?>
				<td><?php 
            print get_colored_device_status($device['disabled'] == 'on' ? true : false, $device['snmp_status']);
            ?>
</td>
				<td><?php 
            print filter_value($device['hostname'], get_request_var('filter'));
            ?>
				<td><?php 
            print $device['device_type'];
            ?>
</td)>
				<td><?php 
            print $device['scan_type'] == '1' ? __('N/A') : number_format_i18n($device['ips_total']);
            ?>
</td>
				<td><?php 
            print $device['scan_type'] == '3' ? __('N/A') : number_format_i18n($device['ports_total']);
            ?>
</td>
				<td><?php 
            print $device['scan_type'] == '3' ? __('N/A') : number_format_i18n($device['ports_active']);
            ?>
</td>
				<td><?php 
            print $device['scan_type'] == '3' ? __('N/A') : number_format_i18n($device['ports_trunk']);
            ?>
</td>
				<td><?php 
            print $device['scan_type'] == '3' ? __('N/A') : number_format_i18n($device['macs_active']);
            ?>
</td>
				<td><?php 
            print $device['scan_type'] == '3' ? __('N/A') : number_format_i18n($device['vlans_total']);
            ?>
</td>
				<td><?php 
            print number_format($device['last_runduration'], 1);
            ?>
</td>
			</tr>
			<?php 
        }
    } else {
        print '<tr><td colspan="10"><em>' . __('No MacTrack Devices') . '</em></td></tr>';
    }
    html_end_box(false);
    if (sizeof($devices)) {
        print $nav;
        mactrack_display_stats();
    }
}
Example #12
0
function host()
{
    global $colors, $device_actions;
    /* ================= 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"));
    /* ==================================================== */
    /* 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_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["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("sort_column", "sess_host_sort_column", "description");
    load_current_session_value("sort_direction", "sess_host_sort_direction", "ASC");
    html_start_box("<strong>Devices</strong>", "98%", $colors["header"], "3", "center", "host.php?action=edit&host_template_id=" . $_REQUEST["host_template_id"] . "&host_status=" . $_REQUEST["host_status"]);
    include "./include/html/inc_device_filter_table.php";
    html_end_box();
    /* form the 'where' clause for our main sql query */
    $sql_where = "where (host.hostname like '%%" . $_REQUEST["filter"] . "%%' OR host.description like '%%" . $_REQUEST["filter"] . "%%')";
    if ($_REQUEST["host_status"] == "-1") {
        /* Show all items */
    } elseif ($_REQUEST["host_status"] == "-2") {
        $sql_where .= " and host.disabled='on'";
    } elseif ($_REQUEST["host_status"] == "-3") {
        $sql_where .= " and host.disabled=''";
    } else {
        $sql_where .= " and (host.status=" . $_REQUEST["host_status"] . " AND host.disabled = '')";
    }
    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\n\t\tCOUNT(host.id)\n\t\tfrom host\n\t\t{$sql_where}");
    $sortby = $_REQUEST["sort_column"];
    if ($sortby == "hostname") {
        $sortby = "INET_ATON(hostname)";
    }
    $hosts = db_fetch_assoc("SELECT\n\t\thost.id,\n\t\thost.disabled,\n\t\thost.status,\n\t\thost.hostname,\n\t\thost.description,\n\t\thost.min_time,\n\t\thost.max_time,\n\t\thost.cur_time,\n\t\thost.avg_time,\n\t\thost.availability\n\t\tFROM host\n\t\t{$sql_where}\n\t\tORDER BY " . $sortby . " " . $_REQUEST["sort_direction"] . "\n\t\tLIMIT " . 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"] . "&host_status=" . $_REQUEST["host_status"]);
    $nav = "<tr bgcolor='#" . $colors["header"] . "'>\n\t\t\t<td colspan='7'>\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='host.php?filter=" . $_REQUEST["filter"] . "&host_template_id=" . $_REQUEST["host_template_id"] . "&host_status=" . $_REQUEST["host_status"] . "&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_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}]\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_device") < $total_rows) {
        $nav .= "<a class='linkOverDark' href='host.php?filter=" . $_REQUEST["filter"] . "&host_template_id=" . $_REQUEST["host_template_id"] . "&host_status=" . $_REQUEST["host_status"] . "&page=" . ($_REQUEST["page"] + 1) . "'>";
    }
    $nav .= "Next";
    if ($_REQUEST["page"] * read_config_option("num_rows_device") < $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"), "status" => array("Status", "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, $_REQUEST["sort_column"], $_REQUEST["sort_direction"]);
    $i = 0;
    if (sizeof($hosts) > 0) {
        foreach ($hosts as $host) {
            form_alternate_row_color($colors["alternate"], $colors["light"], $i);
            $i++;
            ?>
				<td width=250>
					<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 eregi_replace("(" . preg_quote($_REQUEST["filter"]) . ")", "<span style='background-color: #F8D93D;'>\\1</span>", $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);
    /* 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);
}
Example #13
0
function graph_perms_edit($tab, $header_label)
{
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_request('id'));
    /* ==================================================== */
    $sql_where = '';
    $sql_join = '';
    $limit = '';
    $sql_having = '';
    $policy_array = array(1 => 'Allow', 2 => 'Deny');
    if (!empty($_REQUEST['id'])) {
        $policy = db_fetch_row_prepared('SELECT policy_graphs, policy_trees, policy_hosts, policy_graph_templates 
			FROM user_auth 
			WHERE id = ?', array(get_request_var_request('id')));
    } else {
        $policy = array('policy_graphs' => '1', 'policy_trees' => '1', 'policy_hosts' => '1', 'policy_graph_templates' => '1');
    }
    switch ($tab) {
        case 'permsg':
            process_graph_request_vars();
            graph_filter($header_label);
            /* print checkbox form for validation */
            print "<form name='policy' method='post' action='user_admin.php'>\n";
            /* box: device permissions */
            html_start_box('<strong>Default Graph Policy</strong>', '100%', '', '3', 'center', '');
            ?>
		<tr class='even'>
			<td><table cellspacing="0" cellpadding="2"><tr>
			<td style="white-space:nowrap;" width="120">Default Graph Policy for this User</td>
			<td width="10"> 
				<?php 
            form_dropdown('policy_graphs', $policy_array, '', '', $policy['policy_graphs'], '', '');
            ?>
			</td>
			<td>
				<input type="submit" name="update_policy" value="Update">
				<input type="hidden" name="tab" value="<?php 
            print $tab;
            ?>
">
				<input type="hidden" name="id" value="<?php 
            print get_request_var_request('id');
            ?>
">
			</td>
			</tr></table></td>
		</tr>
		<?php 
            html_end_box();
            print "</form>\n";
            /* if the number of rows is -1, set it to the default */
            if ($_REQUEST['rows'] == -1) {
                $rows = read_config_option('num_rows_table');
            } else {
                $rows = $_REQUEST['rows'];
            }
            /* print checkbox form for validation */
            print "<form name='chk' method='post' action='" . htmlspecialchars('user_admin.php?action=user_edit&tab=permsg&id=' . get_request_var_request('id')) . "'>\n";
            html_start_box('', '100%', '', '3', 'center', '');
            $user = $_SESSION['sess_user_id'];
            if (read_config_option('graph_auth_method') == 1) {
                $sql_operator = 'OR';
            } else {
                $sql_operator = 'AND';
            }
            $limit = 'LIMIT ' . $rows * (get_request_var_request('page') - 1) . ',' . $rows;
            /* get policies for all groups and user */
            $policies = db_fetch_assoc_prepared("SELECT uag.id, 'group' AS type, uag.name, \n\t\t\tpolicy_graphs, policy_hosts, policy_graph_templates \n\t\t\tFROM user_auth_group AS uag\n\t\t\tINNER JOIN user_auth_group_members AS uagm\n\t\t\tON uag.id = uagm.group_id\n\t\t\tWHERE uag.enabled = 'on' AND uagm.user_id = ?", array($user));
            $policies[] = db_fetch_row_prepared("SELECT id, 'user' AS type, 'user' AS name, \n\t\t\tpolicy_graphs, policy_hosts, policy_graph_templates \n\t\t\tFROM user_auth WHERE id = ?", array($user));
            /* form the 'where' clause for our main sql query */
            if (strlen(get_request_var_request('filter'))) {
                $sql_where = "WHERE (gtg.title_cache LIKE '%%" . get_request_var_request('filter') . "%%' AND gtg.local_graph_id > 0)";
            } else {
                $sql_where = 'WHERE (gtg.local_graph_id > 0)';
            }
            if (get_request_var_request('graph_template_id') == '-1') {
                /* Show all items */
            } elseif (get_request_var_request('graph_template_id') == '0') {
                $sql_where .= (strlen($sql_where) ? ' AND ' : 'WHERE ') . ' gtg.graph_template_id=0';
            } elseif (!empty($_REQUEST['graph_template_id'])) {
                $sql_where .= (strlen($sql_where) ? ' AND ' : 'WHERE ') . ' gtg.graph_template_id=' . get_request_var_request('graph_template_id');
            }
            $i = 1;
            $user_perm = '';
            $sql_select = '';
            foreach ($policies as $policy) {
                if ($policy['type'] == 'user' && $user_perm == '') {
                    $user_perm = $i;
                }
                if (get_request_var_request('associated') == 'false') {
                    if ($policy['policy_graphs'] == 1) {
                        $sql_having .= (strlen($sql_having) ? ' OR' : '') . " (user{$i} IS NULL";
                    } else {
                        $sql_having .= (strlen($sql_having) ? ' OR' : '') . " (user{$i}=" . $policy['id'];
                    }
                }
                $sql_join .= 'LEFT JOIN user_auth_' . ($policy['type'] == 'user' ? '' : 'group_') . "perms AS uap{$i} ON (gl.id=uap{$i}.item_id AND uap{$i}.type=1) ";
                $sql_select .= (strlen($sql_select) ? ', ' : '') . "uap{$i}." . $policy['type'] . "_id AS user{$i}";
                $i++;
                if (get_request_var_request('associated') == 'false') {
                    if ($policy['policy_hosts'] == 1) {
                        $sql_having .= " OR (user{$i} IS NULL";
                    } else {
                        $sql_having .= " OR (user{$i}=" . $policy['id'];
                    }
                }
                $sql_join .= 'LEFT JOIN user_auth_' . ($policy['type'] == 'user' ? '' : 'group_') . "perms AS uap{$i} ON (gl.host_id=uap{$i}.item_id AND uap{$i}.type=3) ";
                $sql_select .= (strlen($sql_select) ? ', ' : '') . "uap{$i}." . $policy['type'] . "_id AS user{$i}";
                $i++;
                if (get_request_var_request('associated') == 'false') {
                    if ($policy['policy_graph_templates'] == 1) {
                        $sql_having .= " {$sql_operator} user{$i} IS NULL))";
                    } else {
                        $sql_having .= " {$sql_operator} user{$i}=" . $policy['id'] . '))';
                    }
                }
                $sql_join .= 'LEFT JOIN user_auth_' . ($policy['type'] == 'user' ? '' : 'group_') . "perms AS uap{$i} ON (gl.graph_template_id=uap{$i}.item_id AND uap{$i}.type=4) ";
                $sql_select .= (strlen($sql_select) ? ', ' : '') . "uap{$i}." . $policy['type'] . "_id AS user{$i}";
                $i++;
            }
            if (strlen($sql_having)) {
                $sql_having = 'HAVING ' . $sql_having;
            }
            $graphs = db_fetch_assoc("SELECT gtg.local_graph_id, h.description, gt.name AS template_name, \n\t\t\tgtg.title_cache, gtg.width, gtg.height, gl.snmp_index, gl.snmp_query_id,\n\t\t\t{$sql_select}\n\t\t\tFROM graph_templates_graph AS gtg \n\t\t\tINNER JOIN graph_local AS gl \n\t\t\tON gl.id = gtg.local_graph_id \n\t\t\tLEFT JOIN graph_templates AS gt \n\t\t\tON gt.id = gl.graph_template_id \n\t\t\tLEFT JOIN host AS h \n\t\t\tON h.id = gl.host_id \n\t\t\t{$sql_join}\n\t\t\t{$sql_where}\n\t\t\t{$sql_having}\n\t\t\tORDER BY gtg.title_cache\n\t\t\t{$limit}");
            $total_rows = db_fetch_cell("SELECT COUNT(*)\n\t\t\tFROM (\n\t\t\t\tSELECT {$sql_select}\n\t\t\t\tFROM graph_templates_graph AS gtg \n\t\t\t\tINNER JOIN graph_local AS gl \n\t\t\t\tON gl.id = gtg.local_graph_id \n\t\t\t\tLEFT JOIN graph_templates AS gt \n\t\t\t\tON gt.id = gl.graph_template_id \n\t\t\t\tLEFT JOIN host AS h \n\t\t\t\tON h.id = gl.host_id \n\t\t\t\t{$sql_join}\n\t\t\t\t{$sql_where}\n\t\t\t\t{$sql_having}\n\t\t\t) AS rows");
            //print '<pre>';print_r($graphs);print '</pre>';
            $nav = html_nav_bar('user_admin.php?action=user_edit&tab=permsg&id=' . get_request_var_request('id'), MAX_DISPLAY_PAGES, get_request_var_request('page'), $rows, $total_rows, 11, 'Graphs', 'page', 'main');
            print $nav;
            $display_text = array('Graph Title', 'ID', 'Effective Policy');
            html_header_checkbox($display_text, false);
            if (sizeof($graphs)) {
                foreach ($graphs as $g) {
                    form_alternate_row('line' . $g['local_graph_id'], true);
                    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($g['title_cache'])) : htmlspecialchars($g['title_cache']), $g['local_graph_id']);
                    form_selectable_cell($g['local_graph_id'], $g['local_graph_id']);
                    form_selectable_cell(get_permission_string($g, $policies), $g['local_graph_id']);
                    form_checkbox_cell($g['title_cache'], $g['local_graph_id']);
                    form_end_row();
                }
                /* put the nav bar on the bottom as well */
                print $nav;
            } else {
                print '<tr><td><em>No Matching Graphs Found</em></td></tr>';
            }
            html_end_box(false);
            form_hidden_box('action', 'user_edit', '');
            form_hidden_box('tab', $tab, '');
            form_hidden_box('id', get_request_var_request('id'), '');
            form_hidden_box('associate_graph', '1', '');
            if ($policy['policy_graphs'] == 1) {
                $assoc_actions = array(1 => 'Revoke Access', 2 => 'Grant Access');
            } else {
                $assoc_actions = array(1 => 'Grant Access', 2 => 'Revoke Access');
            }
            /* draw the dropdown containing a list of available actions for this form */
            draw_actions_dropdown($assoc_actions);
            print '</form>';
            break;
        case 'permsgr':
            process_group_request_vars();
            group_filter($header_label);
            /* if the number of rows is -1, set it to the default */
            if ($_REQUEST['rows'] == -1) {
                $rows = read_config_option('num_rows_table');
            } else {
                $rows = $_REQUEST['rows'];
            }
            /* form the 'where' clause for our main sql query */
            /* form the 'where' clause for our main sql query */
            if (strlen(get_request_var_request('filter'))) {
                $sql_where = "WHERE ((uag.name LIKE '%" . get_request_var_request('filter') . "%') OR (uag.description LIKE '%" . get_request_var_request('filter') . "%'))";
            } else {
                $sql_where = '';
            }
            if (get_request_var_request('associated') != 'false') {
                /* Show all items */
            } else {
                $sql_where .= (strlen($sql_where) ? ' AND ' : 'WHERE ') . ' uagm.user_id=' . get_request_var_request('id', 0);
            }
            /* print checkbox form for validation */
            print "<form name='chk' method='post' action='" . htmlspecialchars('user_admin.php?action=user_edit&tab=permsd&id=' . get_request_var_request('id')) . "'>\n";
            html_start_box('', '100%', '', '3', 'center', '');
            $total_rows = db_fetch_cell("SELECT\n\t\t\tCOUNT(uag.id)\n\t\t\tFROM user_auth_group AS uag\n\t\t\tLEFT JOIN user_auth_group_members AS uagm\n\t\t\tON uag.id = uagm.group_id\n\t\t\t{$sql_where}");
            $sql_query = "SELECT uag.*, uagm.user_id\n\t\t\tFROM user_auth_group AS uag\n\t\t\tLEFT JOIN user_auth_group_members AS uagm\n\t\t\tON uag.id = uagm.group_id\n\t\t\t{$sql_where} \n\t\t\tORDER BY name\n\t\t\tLIMIT " . $rows * (get_request_var_request('page') - 1) . ',' . $rows;
            $groups = db_fetch_assoc($sql_query);
            $nav = html_nav_bar('user_admin.php?action=user_edit&tab=permsgr&id=' . get_request_var_request('id'), MAX_DISPLAY_PAGES, get_request_var_request('page'), $rows, $total_rows, 11, 'Devices', 'page', 'main');
            print $nav;
            $display_text = array('Name', 'Description', 'Member', 'ID', 'Policies (Graph/Device/Template)', 'Enabled');
            html_header_checkbox($display_text, false);
            if (sizeof($groups)) {
                foreach ($groups as $g) {
                    form_alternate_row('line' . $g['id'], true);
                    form_selectable_cell("<a class='linkEditMain' href='user_group_admin.php?action=edit&id=" . $g['id'] . "'>" . (strlen(get_request_var_request('filter')) ? preg_replace('/(' . preg_quote(get_request_var_request('filter')) . ')/i', "<span class='filteredValue'>\\1</span>", htmlspecialchars($g['name'])) : htmlspecialchars($g['name'])) . '</a>', $g['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($g['description'])) : htmlspecialchars($g['description']), $g['id']);
                    form_selectable_cell($g['user_id'] > 0 ? 'Member' : 'Non Member', $g['id']);
                    form_selectable_cell($g['id'], $g['id']);
                    form_selectable_cell(($g['policy_graphs'] == 1 ? 'ALLOW' : 'DENY') . '/' . ($g['policy_hosts'] == 1 ? 'ALLOW' : 'DENY') . '/' . ($g['policy_graph_templates'] == 1 ? 'ALLOW' : 'DENY'), $g['id']);
                    form_selectable_cell($g['enabled'] == 'on' ? 'Enabled' : 'Disabled', $g['id']);
                    form_checkbox_cell($g['name'], $g['id']);
                    form_end_row();
                }
                /* put the nav bar on the bottom as well */
                print $nav;
            } else {
                print '<tr><td><em>No Matching User Groups Found</em></td></tr>';
            }
            html_end_box(false);
            form_hidden_box('action', 'user_edit', '');
            form_hidden_box('tab', $tab, '');
            form_hidden_box('id', get_request_var_request('id'), '');
            form_hidden_box('associate_groups', '1', '');
            $assoc_actions = array(1 => 'Assign Membership', 2 => 'Remove Membership');
            /* draw the dropdown containing a list of available actions for this form */
            draw_actions_dropdown($assoc_actions);
            print '</form>';
            break;
        case 'permsd':
            process_device_request_vars();
            device_filter($header_label);
            /* print checkbox form for validation */
            print "<form name='policy' method='post' action='user_admin.php'>\n";
            /* box: device permissions */
            html_start_box('<strong>Default Device Policy</strong>', '100%', '', '3', 'center', '');
            ?>
		<tr class='even'>
			<td><table cellspacing="0" cellpadding="2"><tr>
			<td style="white-space:nowrap;" width="120">Default Device Policy for this User</td>
			<td width="10"> 
				<?php 
            form_dropdown('policy_hosts', $policy_array, '', '', $policy['policy_hosts'], '', '');
            ?>
			</td>
			<td>
				<input type="submit" name="update_policy" value="Update">
				<input type="hidden" name="tab" value="<?php 
            print $tab;
            ?>
">
				<input type="hidden" name="id" value="<?php 
            print get_request_var_request('id');
            ?>
">
			</td>
			</tr></table></td>
		</tr>
		<?php 
            html_end_box();
            print "</form>\n";
            /* if the number of rows is -1, set it to the default */
            if ($_REQUEST['rows'] == -1) {
                $rows = read_config_option('num_rows_table');
            } else {
                $rows = $_REQUEST['rows'];
            }
            /* form the 'where' clause for our main sql query */
            /* 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_template_id') == '-1') {
                /* Show all items */
            } elseif (get_request_var_request('host_template_id') == '0') {
                $sql_where .= (strlen($sql_where) ? ' AND ' : 'WHERE ') . ' host.host_template_id=0';
            } elseif (!empty($_REQUEST['host_template_id'])) {
                $sql_where .= (strlen($sql_where) ? ' AND ' : 'WHERE ') . ' host.host_template_id=' . get_request_var_request('host_template_id');
            }
            if (get_request_var_request('associated') == 'false') {
                /* Show all items */
            } else {
                $sql_where .= (strlen($sql_where) ? ' AND ' : 'WHERE ') . ' user_auth_perms.user_id=' . get_request_var_request('id', 0);
            }
            /* print checkbox form for validation */
            print "<form name='chk' method='post' action='" . htmlspecialchars('user_admin.php?action=user_edit&tab=permsd&id=' . get_request_var_request('id')) . "'>\n";
            html_start_box('', '100%', '', '3', 'center', '');
            $total_rows = db_fetch_cell("SELECT\n\t\t\tCOUNT(host.id)\n\t\t\tFROM host\n\t\t\tLEFT JOIN user_auth_perms \n\t\t\tON (host.id = user_auth_perms.item_id AND user_auth_perms.type = 3)\n\t\t\t{$sql_where}");
            $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 host.*, user_auth_perms.user_id\n\t\t\tFROM host \n\t\t\tLEFT JOIN user_auth_perms \n\t\t\tON (host.id = user_auth_perms.item_id AND user_auth_perms.type = 3)\n\t\t\t{$sql_where} \n\t\t\tORDER BY description\n\t\t\tLIMIT " . $rows * (get_request_var_request('page') - 1) . ',' . $rows;
            $hosts = db_fetch_assoc($sql_query);
            $nav = html_nav_bar('user_admin.php?action=user_edit&tab=permsd&id=' . get_request_var_request('id'), MAX_DISPLAY_PAGES, get_request_var_request('page'), $rows, $total_rows, 11, 'Devices', 'page', 'main');
            print $nav;
            $display_text = array('Description', 'ID', 'Effective Policy', 'Graphs', 'Data Sources', 'Status', 'Hostname');
            html_header_checkbox($display_text, false);
            if (sizeof($hosts)) {
                foreach ($hosts as $host) {
                    form_alternate_row('line' . $host['id'], true);
                    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['description'])) : htmlspecialchars($host['description']), $host['id']);
                    form_selectable_cell(round($host['id'], 2), $host['id']);
                    if (empty($host['user_id']) || $host['user_id'] == NULL) {
                        if ($policy['policy_hosts'] == 1) {
                            form_selectable_cell('<span style="color:green;font-weight:bold;">Access Granted</span>', $host['id']);
                        } else {
                            form_selectable_cell('<span style="color:red;font-weight:bold;">Access Restricted</span>', $host['id']);
                        }
                    } else {
                        if ($policy['policy_hosts'] == 1) {
                            form_selectable_cell('<span style="color:red;font-weight:bold;">Access Restricted</span>', $host['id']);
                        } else {
                            form_selectable_cell('<span style="color:green;font-weight:bold;">Access Granted</span>', $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(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_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 Matching Devices Found</em></td></tr>';
            }
            html_end_box(false);
            form_hidden_box('action', 'user_edit', '');
            form_hidden_box('tab', $tab, '');
            form_hidden_box('id', get_request_var_request('id'), '');
            form_hidden_box('associate_host', '1', '');
            if ($policy['policy_hosts'] == 1) {
                $assoc_actions = array(1 => 'Revoke Access', 2 => 'Grant Access');
            } else {
                $assoc_actions = array(1 => 'Grant Access', 2 => 'Revoke Access');
            }
            /* draw the dropdown containing a list of available actions for this form */
            draw_actions_dropdown($assoc_actions);
            print '</form>';
            break;
        case 'permste':
            process_template_request_vars();
            template_filter($header_label);
            /* print checkbox form for validation */
            print "<form name='policy' method='post' action='user_admin.php'>\n";
            /* box: device permissions */
            html_start_box('<strong>Default Graph Template Policy</strong>', '100%', '', '3', 'center', '');
            ?>
		<tr class='even'>
			<td><table cellspacing="0" cellpadding="2"><tr>
			<td style="white-space:nowrap;" width="120">Default Graph Template Policy for this User</td>
			<td width="10"> 
				<?php 
            form_dropdown('policy_graph_templates', $policy_array, '', '', $policy['policy_graph_templates'], '', '');
            ?>
			</td>
			<td>
				<input type="submit" name="update_policy" value="Update">
				<input type="hidden" name="tab" value="<?php 
            print $tab;
            ?>
">
				<input type="hidden" name="id" value="<?php 
            print get_request_var_request('id');
            ?>
">
			</td>
			</tr></table></td>
		</tr>
		<?php 
            html_end_box();
            print "</form>\n";
            /* if the number of rows is -1, set it to the default */
            if ($_REQUEST['rows'] == -1) {
                $rows = read_config_option('num_rows_table');
            } else {
                $rows = $_REQUEST['rows'];
            }
            /* form the 'where' clause for our main sql query */
            if (strlen(get_request_var_request('filter'))) {
                $sql_where = "WHERE (gt.name LIKE '%%" . get_request_var_request('filter') . "%%')";
            } else {
                $sql_where = '';
            }
            if (get_request_var_request('associated') == 'false') {
                /* Show all items */
            } else {
                $sql_where .= (strlen($sql_where) ? ' AND ' : 'WHERE ') . ' (user_auth_perms.type=4 AND user_auth_perms.user_id=' . get_request_var_request('id', 0) . ')';
            }
            /* print checkbox form for validation */
            print "<form name='chk' method='post' action='" . htmlspecialchars('user_admin.php?action=user_edit&tab=permste&id=' . get_request_var_request('id')) . "'>\n";
            html_start_box('', '100%', '', '3', 'center', '');
            $total_rows = db_fetch_cell("SELECT\n\t\t\tCOUNT(gt.id)\n\t\t\tFROM graph_templates AS gt\n\t\t\tINNER JOIN graph_local AS gl\n\t\t\tON gt.id = gl.graph_template_id\n\t\t\tLEFT JOIN user_auth_perms \n\t\t\tON (gt.id = user_auth_perms.item_id AND user_auth_perms.type = 4)\n\t\t\t{$sql_where}\n\t\t\tGROUP BY gl.graph_template_id");
            $sql_query = "SELECT gt.id, gt.name, count(*) AS totals, user_auth_perms.user_id\n\t\t\tFROM graph_templates AS gt\n\t\t\tINNER JOIN graph_local AS gl\n\t\t\tON gt.id = gl.graph_template_id\n\t\t\tLEFT JOIN user_auth_perms \n\t\t\tON (gt.id = user_auth_perms.item_id AND user_auth_perms.type = 4)\n\t\t\t{$sql_where} \n\t\t\tGROUP BY gl.graph_template_id\n\t\t\tORDER BY name\n\t\t\tLIMIT " . $rows * (get_request_var_request('page') - 1) . ',' . $rows;
            $graphs = db_fetch_assoc($sql_query);
            $nav = html_nav_bar('user_admin.php?action=user_edit&tab=permste&id=' . get_request_var_request('id'), MAX_DISPLAY_PAGES, get_request_var_request('page'), $rows, $total_rows, 11, 'Graph Templates', 'page', 'main');
            print $nav;
            $display_text = array('Template Name', 'ID', 'Effective Policy', 'Total Graphs');
            html_header_checkbox($display_text, false);
            if (sizeof($graphs)) {
                foreach ($graphs as $g) {
                    form_alternate_row('line' . $g['id'], true);
                    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($g['name'])) : htmlspecialchars($g['name']), $g['id']);
                    form_selectable_cell($g['id'], $g['id']);
                    if (empty($g['user_id']) || $g['user_id'] == NULL) {
                        if ($policy['policy_graph_templates'] == 1) {
                            form_selectable_cell('<span style="color:green;font-weight:bold;">Access Granted</span>', $g['id']);
                        } else {
                            form_selectable_cell('<span style="color:red;font-weight:bold;">Access Restricted</span>', $g['id']);
                        }
                    } else {
                        if ($policy['policy_graph_templates'] == 1) {
                            form_selectable_cell('<span style="color:red;font-weight:bold;">Access Restricted</span>', $g['id']);
                        } else {
                            form_selectable_cell('<span style="color:green;font-weight:bold;">Access Granted</span>', $g['id']);
                        }
                    }
                    form_selectable_cell($g['totals'], $g['id']);
                    form_checkbox_cell($g['name'], $g['id']);
                    form_end_row();
                }
                /* put the nav bar on the bottom as well */
                print $nav;
            } else {
                print '<tr><td><em>No Matching Graph Templates Found</em></td></tr>';
            }
            html_end_box(false);
            form_hidden_box('action', 'user_edit', '');
            form_hidden_box('tab', $tab, '');
            form_hidden_box('id', get_request_var_request('id'), '');
            form_hidden_box('associate_template', '1', '');
            if ($policy['policy_graph_templates'] == 1) {
                $assoc_actions = array(1 => 'Revoke Access', 2 => 'Grant Access');
            } else {
                $assoc_actions = array(1 => 'Grant Access', 2 => 'Revoke Access');
            }
            /* draw the dropdown containing a list of available actions for this form */
            draw_actions_dropdown($assoc_actions);
            print '</form>';
            break;
        case 'permstr':
            process_tree_request_vars();
            tree_filter($header_label);
            /* print checkbox form for validation */
            print "<form name='policy' method='post' action='user_admin.php'>\n";
            /* box: device permissions */
            html_start_box('<strong>Default Tree Policy</strong>', '100%', '', '3', 'center', '');
            ?>
		<tr class='even'>
			<td><table cellspacing="0" cellpadding="2"><tr>
			<td style="white-space:nowrap;" width="120">Default Tree Policy for this User</td>
			<td width="10"> 
				<?php 
            form_dropdown('policy_trees', $policy_array, '', '', $policy['policy_trees'], '', '');
            ?>
			</td>
			<td>
				<input type="submit" name="update_policy" value="Update">
				<input type="hidden" name="tab" value="<?php 
            print $tab;
            ?>
">
				<input type="hidden" name="id" value="<?php 
            print get_request_var_request('id');
            ?>
">
			</td>
			</tr></table></td>
		</tr>
		<?php 
            html_end_box();
            print "</form>\n";
            /* if the number of rows is -1, set it to the default */
            if ($_REQUEST['rows'] == -1) {
                $rows = read_config_option('num_rows_table');
            } else {
                $rows = $_REQUEST['rows'];
            }
            /* form the 'where' clause for our main sql query */
            if (strlen(get_request_var_request('filter'))) {
                $sql_where = "WHERE (gt.name LIKE '%%" . get_request_var_request('filter') . "%%')";
            } else {
                $sql_where = '';
            }
            if (get_request_var_request('associated') == 'false') {
                /* showing all rows */
            } else {
                $sql_where .= (strlen($sql_where) ? ' AND ' : 'WHERE ') . ' (user_auth_perms.type=2 AND user_auth_perms.user_id=' . get_request_var_request('id', 0) . ')';
            }
            /* print checkbox form for validation */
            print "<form name='chk' method='post' action='" . htmlspecialchars('user_admin.php?action=user_edit&tab=permstr&id=' . get_request_var_request('id')) . "'>\n";
            html_start_box('', '100%', '', '3', 'center', '');
            $total_rows = db_fetch_cell("SELECT\n\t\t\tCOUNT(gt.id)\n\t\t\tFROM graph_tree AS gt\n\t\t\tLEFT JOIN user_auth_perms \n\t\t\tON (gt.id = user_auth_perms.item_id AND user_auth_perms.type = 2)\n\t\t\t{$sql_where}");
            $sql_query = "SELECT gt.id, gt.name, user_auth_perms.user_id\n\t\t\tFROM graph_tree AS gt\n\t\t\tLEFT JOIN user_auth_perms \n\t\t\tON (gt.id = user_auth_perms.item_id AND user_auth_perms.type = 2)\n\t\t\t{$sql_where} \n\t\t\tORDER BY name\n\t\t\tLIMIT " . $rows * (get_request_var_request('page') - 1) . ',' . $rows;
            $trees = db_fetch_assoc($sql_query);
            $nav = html_nav_bar('user_admin.php?action=user_edit&tab=permstr&id=' . get_request_var_request('id'), MAX_DISPLAY_PAGES, get_request_var_request('page'), $rows, $total_rows, 11, 'Trees', 'page', 'main');
            print $nav;
            $display_text = array('Tree Name', 'ID', 'Effective Policy');
            html_header_checkbox($display_text, false);
            if (sizeof($trees)) {
                foreach ($trees as $t) {
                    form_alternate_row('line' . $t['id'], true);
                    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($t['name'])) : htmlspecialchars($t['name']), $t['id']);
                    form_selectable_cell($t['id'], $t['id']);
                    if (empty($t['user_id']) || $t['user_id'] == NULL) {
                        if ($policy['policy_graphs'] == 1) {
                            form_selectable_cell('<span style="color:green;font-weight:bold;">Access Granted</span>', $t['id']);
                        } else {
                            form_selectable_cell('<span style="color:red;font-weight:bold;">Access Restricted</span>', $t['id']);
                        }
                    } else {
                        if ($policy['policy_graphs'] == 1) {
                            form_selectable_cell('<span style="color:red;font-weight:bold;">Access Restricted</span>', $t['id']);
                        } else {
                            form_selectable_cell('<span style="color:green;font-weight:bold;">Access Granted</span>', $t['id']);
                        }
                    }
                    form_checkbox_cell($t['name'], $t['id']);
                    form_end_row();
                }
                /* put the nav bar on the bottom as well */
                print $nav;
            } else {
                print '<tr><td><em>No Matching Trees Found</em></td></tr>';
            }
            html_end_box(false);
            form_hidden_box('action', 'user_edit', '');
            form_hidden_box('tab', $tab, '');
            form_hidden_box('id', get_request_var_request('id'), '');
            form_hidden_box('associate_tree', '1', '');
            if ($policy['policy_graph_templates'] == 1) {
                $assoc_actions = array(1 => 'Revoke Access', 2 => 'Grant Access');
            } else {
                $assoc_actions = array(1 => 'Grant Access', 2 => 'Revoke Access');
            }
            /* draw the dropdown containing a list of available actions for this form */
            draw_actions_dropdown($assoc_actions);
            print '</form>';
            break;
    }
}
Example #14
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 #15
0
function mikrotik_devices()
{
    global $config, $colors, $item_rows;
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_request("status"));
    input_validate_input_number(get_request_var_request("page"));
    input_validate_input_number(get_request_var_request("rows"));
    /* ==================================================== */
    /* 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"));
    }
    /* clean up filter string */
    if (isset($_REQUEST["filter"])) {
        $_REQUEST["filter"] = sanitize_search_string(get_request_var("filter"));
    }
    if (isset($_REQUEST["reset"])) {
        kill_session_var("sess_mikrotik_device_sort_column");
        kill_session_var("sess_mikrotik_device_sort_direction");
        kill_session_var("sess_mikrotik_device_status");
        kill_session_var("sess_mikrotik_device_filter");
        kill_session_var("sess_mikrotik_device_rows");
        kill_session_var("sess_mikrotik_device_current_page");
    } elseif (isset($_REQUEST["clear"])) {
        kill_session_var("sess_mikrotik_device_sort_column");
        kill_session_var("sess_mikrotik_device_sort_direction");
        kill_session_var("sess_mikrotik_device_status");
        kill_session_var("sess_mikrotik_device_filter");
        kill_session_var("sess_mikrotik_device_rows");
        kill_session_var("sess_mikrotik_device_current_page");
        unset($_REQUEST["sort_column"]);
        unset($_REQUEST["sort_direction"]);
        unset($_REQUEST["status"]);
        unset($_REQUEST["filter"]);
        unset($_REQUEST["rows"]);
        unset($_REQUEST["page"]);
    } else {
        /* if any of the settings changed, reset the page number */
        $changed = false;
        $changed += mikrotik_check_changed("status", "sess_mikrotik_device_status");
        $changed += mikrotik_check_changed("fitler", "sess_mikrotik_device_filter");
        $changed += mikrotik_check_changed("rows", "sess_mikrotik_device_rows");
        if ($changed) {
            $_REQUEST["page"] = "1";
        }
    }
    load_current_session_value("page", "sess_mikrotik_device_current_page", "1");
    load_current_session_value("rows", "sess_mikrotik_device_rows", "-1");
    load_current_session_value("sort_column", "sess_mikrotik_device_sort_column", "description");
    load_current_session_value("sort_direction", "sess_mikrotik_device_sort_direction", "ASC");
    load_current_session_value("status", "sess_mikrotik_device_status", "-1");
    load_current_session_value("filter", "sess_mikrotik_device_filter", "");
    ?>
	<script type="text/javascript">
	<!--
	function applyHostFilter(objForm) {
		strURL = '?action=devices';
		strURL = strURL + '&status='   + objForm.status.value;
		strURL = strURL + '&filter='   + objForm.filter.value;
		strURL = strURL + '&rows='     + objForm.rows.value;
		document.location = strURL;
	}

	function clearHosts() {
		strURL = '?action=devices&clear=';
		document.location = strURL;
	}
	-->
	</script>
	<?php 
    html_start_box("<strong>Device Filter</strong>", "100%", $colors["header"], "3", "center", "");
    ?>
	<tr bgcolor="#<?php 
    print $colors["panel"];
    ?>
">
		<td>
			<form name="devices" action="mikrotik.php?action=devices">
			<table cellpadding="0" cellspacing="0">
				<tr>
					<td nowrap style='white-space: nowrap;' width="60">
						&nbsp;Status:&nbsp;
					</td>
					<td width="1">
						<select name="status" onChange="applyHostFilter(document.devices)">
							<option value="-1"<?php 
    if (get_request_var_request("type") == "-1") {
        ?>
 selected<?php 
    }
    ?>
>All</option>
							<?php 
    $statuses = db_fetch_assoc("SELECT DISTINCT status\n\t\t\t\t\t\t\t\tFROM host\n\t\t\t\t\t\t\t\tINNER JOIN plugin_mikrotik_system\n\t\t\t\t\t\t\t\tON host.id=plugin_mikrotik_system.host_id");
    $statuses = array_merge($statuses, array("-2" => array("status" => "-2")));
    if (sizeof($statuses)) {
        foreach ($statuses as $s) {
            switch ($s["status"]) {
                case "0":
                    $status = "Unknown";
                    break;
                case "1":
                    $status = "Down";
                    break;
                case "2":
                    $status = "Recovering";
                    break;
                case "3":
                    $status = "Up";
                    break;
                case "-2":
                    $status = "Disabled";
                    break;
            }
            echo "<option value='" . $s["status"] . "' " . (get_request_var_request("status") == $s["status"] ? "selected" : "") . ">" . $status . "</option>";
        }
    }
    ?>
						</select>
					</td>
					<td nowrap style='white-space: nowrap;' width="60">
						&nbsp;Rows:&nbsp;
					</td>
					<td width="1">
						<select name="rows" onChange="applyHostFilter(document.devices)">
							<option value="-1"<?php 
    if (get_request_var_request("rows") == "-1") {
        ?>
 selected<?php 
    }
    ?>
>Default</option>
							<?php 
    if (sizeof($item_rows)) {
        foreach ($item_rows as $key => $name) {
            echo "<option value='" . $key . "' " . (get_request_var_request("rows") == $key ? "selected" : "") . ">" . $name . "</option>";
        }
    }
    ?>
						</select>
					</td>
					<td nowrap style='white-space: nowrap;' width="60">
						&nbsp;Search:&nbsp;
					</td>
					<td>
						<input type='text' size='40' name='filter' value='<?php 
    print get_request_var_request("filter");
    ?>
'>
					</td>
					<td nowrap>
						<input type="button" onClick="applyHostFilter(document.devices)" value="Go" border="0">
					</td>
					<td nowrap>
						<input type="button" onClick="clearHosts()" value="Clear" name="clear" border="0">
					</td>
				</tr>
			</table>
			<input type='hidden' name='action' value='devices'>
			</form>
		</td>
	</tr>
	<?php 
    html_end_box();
    html_start_box("", "100%", $colors["header"], "3", "center", "");
    if ($_REQUEST["rows"] == "-1") {
        $num_rows = read_config_option("num_rows_device");
    } else {
        $num_rows = get_request_var_request("rows");
    }
    $limit = " LIMIT " . $num_rows * (get_request_var_request("page") - 1) . "," . $num_rows;
    $sql_where = "";
    if ($_REQUEST["status"] != "-1") {
        $sql_where .= (strlen($sql_where) ? " AND" : "WHERE") . " hrs.host_status=" . $_REQUEST["status"];
    }
    $sql_join = "";
    if ($_REQUEST["filter"] != "") {
        $sql_where .= (strlen($sql_where) ? " AND" : "WHERE") . " host.description LIKE '%" . $_REQUEST["filter"] . "%' OR\n\t\t\thost.hostname LIKE '%" . $_REQUEST["filter"] . "%'";
    }
    $sql = "SELECT hrs.*, host.hostname, host.description, host.disabled\n\t\tFROM plugin_mikrotik_system AS hrs\n\t\tINNER JOIN host ON host.id=hrs.host_id\n\t\t{$sql_join}\n\t\t{$sql_where}\n\t\tORDER BY " . get_request_var_request("sort_column") . " " . get_request_var_request("sort_direction") . " " . $limit;
    //echo $sql;
    $rows = db_fetch_assoc($sql);
    $total_rows = db_fetch_cell("SELECT COUNT(*)\n\t\tFROM plugin_mikrotik_system AS hrs\n\t\tINNER JOIN host ON host.id=hrs.host_id\n\t\t{$sql_join}\n\t\t{$sql_where}");
    if ($total_rows > 0) {
        /* generate page list */
        $url_page_select = get_page_list(get_request_var_request("page"), MAX_DISPLAY_PAGES, $num_rows, $total_rows, "mikrotik.php" . "?action=devices");
        $nav = "<tr bgcolor='#" . $colors["header"] . "'>\n\t\t\t<td colspan='16'>\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='" . htmlspecialchars("mikrotik.php" . "?action=devices&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 " . ($num_rows * (get_request_var_request("page") - 1) + 1) . " to " . ($total_rows < $num_rows || $total_rows < $num_rows * get_request_var_request("page") ? $total_rows : $num_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") * $num_rows < $total_rows) {
            $nav .= "<a class='linkOverDark' href='" . htmlspecialchars("mikrotik.php" . "?action=devices&page=" . (get_request_var_request("page") + 1)) . "'>";
        }
        $nav .= "Next";
        if (get_request_var_request("page") * $num_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";
    } else {
        $nav = "<tr bgcolor='#" . $colors["header"] . "'>\n\t\t\t<td colspan='16'>\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='center' class='textHeaderDark'>\n\t\t\t\t\t\t\tNo Rows Found\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("nosort" => array("Actions", array("ASC", "left")), "description" => array("Name", array("ASC", "left")), "host_status" => array("Status", array("DESC", "right")), "uptime" => array("Uptime(d:h:m)", array("DESC", "right")), "users" => array("Users", array("DESC", "right")), "cpuPercent" => array("CPU %", array("DESC", "right")), "numCpus" => array("CPUs", array("DESC", "right")), "processes" => array("Processes", array("DESC", "right")), "memSize" => array("Total Mem", array("DESC", "right")), "memUsed" => array("Used Mem", array("DESC", "right")), "diskSize" => array("Total Disk", array("DESC", "right")), "diskUsed" => array("Used Disk", array("DESC", "right")));
    mikrotik_header_sort($display_text, get_request_var_request("sort_column"), get_request_var_request("sort_direction"), "action=devices");
    /* set some defaults */
    $url = $config["url_path"] . "plugins/mikrotik/mikrotik.php";
    $users = $config["url_path"] . "plugins/mikrotik/images/view_users.gif";
    $host = $config["url_path"] . "plugins/mikrotik/images/view_hosts.gif";
    $trees = $config["url_path"] . "plugins/mikrotik/images/view_trees.gif";
    $dashboard = $config["url_path"] . "plugins/mikrotik/images/view_dashboard.gif";
    $graphs = $config["url_path"] . "plugins/mikrotik/images/view_graphs.gif";
    $nographs = $config["url_path"] . "plugins/mikrotik/images/view_graphs_disabled.gif";
    $hcpudq = read_config_option("mikrotik_dq_host_cpu");
    $i = 0;
    if (sizeof($rows)) {
        foreach ($rows as $row) {
            $days = intval($row["uptime"] / (60 * 60 * 24 * 100));
            $remainder = $row["uptime"] % (60 * 60 * 24 * 100);
            $hours = intval($remainder / (60 * 60 * 100));
            $remainder = $remainder % (60 * 60 * 100);
            $minutes = intval($remainder / (60 * 100));
            $found = db_fetch_cell("SELECT COUNT(*) FROM graph_local WHERE host_id=" . $row["host_id"]);
            form_alternate_row_color($colors["alternate"], $colors["light"], $i);
            $i++;
            echo "<td width='100' align='left'>";
            //echo "<a style='padding:1px;' href='" . htmlspecialchars("$url?action=dashboard&reset=1&device=" . $row["host_id"]) . "'><img src='$dashboard' title='View Dashboard' align='absmiddle' border='0'></a>";
            echo "<a style='padding:1px;' href='" . htmlspecialchars("{$url}?action=users&reset=1&device=" . $row["host_id"]) . "'><img src='{$users}' title='View Users' align='absmiddle' border='0'></a>";
            echo "<a style='padding:1px;' href='" . htmlspecialchars("{$url}?action=trees&reset=1&device=" . $row["host_id"]) . "'><img src='{$trees}' title='View Queue Trees' align='absmiddle' border='0'></a>";
            if ($found) {
                echo "<a style='padding:1px;' href='" . htmlspecialchars("{$url}?action=graphs&reset=1&host=" . $row["host_id"] . "&style=selective&graph_add=&graph_list=&graph_template_id=0&filter=") . "'><img  src='{$graphs}' title='View Graphs' align='absmiddle' border='0'></a>";
            } else {
                echo "<img src='{$nographs}' title='No Graphs Defined' align='absmiddle' border='0'>";
            }
            $graph_cpu = mikrotik_get_graph_url($hcpudq, $row["host_id"], "", $row["numCpus"], false);
            $graph_cpup = mikrotik_get_graph_template_url(read_config_option("mikrotik_gt_cpu"), $row["host_id"], round($row["cpuPercent"], 2), false);
            $graph_users = mikrotik_get_graph_template_url(read_config_option("mikrotik_gt_users"), $row["host_id"], $row["users"], false);
            $graph_aproc = mikrotik_get_graph_template_url(read_config_option("mikrotik_gt_processes"), $row["host_id"], $row["host_status"] < 2 ? "N/A" : $row["processes"], false);
            $graph_disk = mikrotik_get_graph_template_url(read_config_option("mikrotik_gt_disk"), $row["host_id"], $row["host_status"] < 2 ? "N/A" : round($row["diskUsed"], 2), false);
            $graph_mem = mikrotik_get_graph_template_url(read_config_option("mikrotik_gt_memory"), $row["host_id"], $row["host_status"] < 2 ? "N/A" : round($row["memUsed"], 2), false);
            $graph_upt = mikrotik_get_graph_template_url(read_config_option("mikrotik_gt_uptime"), $row["host_id"], $row["host_status"] < 2 ? "N/A" : mikrotik_format_uptime($days, $hours, $minutes), false);
            if (api_plugin_user_realm_auth('host.php')) {
                $host_url = "<a href='" . htmlspecialchars($config["url_path"] . "host.php?action=edit&id=" . $row["host_id"]) . "' title='Edit Hosts'>" . $row["hostname"] . "</a>";
            } else {
                $host_url = $row["hostname"];
            }
            echo "</td>";
            echo "<td style='white-space:nowrap;' align='left' width='200'><strong>" . $row["description"] . "</strong> [" . $host_url . "]" . "</td>";
            echo "<td style='white-space:nowrap;' align='right'>" . get_colored_device_status($row["disabled"] == "on" ? true : false, $row["host_status"]) . "</td>";
            echo "<td style='white-space:nowrap;' align='right'>" . $graph_upt . "</td>";
            echo "<td style='white-space:nowrap;' align='right'>" . $graph_users . "</td>";
            echo "<td style='white-space:nowrap;' align='right'>" . ($row["host_status"] < 2 ? "N/A" : $graph_cpup) . "</td>";
            echo "<td style='white-space:nowrap;' align='right'>" . ($row["host_status"] < 2 ? "N/A" : $graph_cpu) . "</td>";
            echo "<td style='white-space:nowrap;' align='right'>" . $graph_aproc . "</td>";
            echo "<td style='white-space:nowrap;' align='right'>" . mikrotik_memory($row["memSize"]) . "</td>";
            echo "<td style='white-space:nowrap;' align='right'>" . $graph_mem . " %</td>";
            echo "<td style='white-space:nowrap;' align='right'>" . mikrotik_memory($row["diskSize"]) . "</td>";
            echo "<td style='white-space:nowrap;' align='right'>" . $graph_disk . " %</td>";
        }
        echo "</tr>";
        print $nav;
    } else {
        print "<tr><td><em>No Devices Found</em></td></tr>";
    }
    html_end_box();
}
Example #16
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);
}
Example #17
0
function mikrotik_devices()
{
    global $config, $colors, $item_rows;
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_request('status'));
    input_validate_input_number(get_request_var_request('page'));
    input_validate_input_number(get_request_var_request('rows'));
    /* ==================================================== */
    /* 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 */
    if (isset($_REQUEST['sort_direction'])) {
        $_REQUEST['sort_direction'] = sanitize_search_string(get_request_var_request('sort_direction'));
    }
    /* clean up filter string */
    if (isset($_REQUEST['filter'])) {
        $_REQUEST['filter'] = sanitize_search_string(get_request_var_request('filter'));
    }
    if (isset($_REQUEST['reset'])) {
        kill_session_var('sess_mikrotik_device_sort_column');
        kill_session_var('sess_mikrotik_device_sort_direction');
        kill_session_var('sess_mikrotik_device_status');
        kill_session_var('sess_mikrotik_device_filter');
        kill_session_var('sess_default_rows');
        kill_session_var('sess_mikrotik_device_current_page');
    } elseif (isset($_REQUEST['clear'])) {
        kill_session_var('sess_mikrotik_device_sort_column');
        kill_session_var('sess_mikrotik_device_sort_direction');
        kill_session_var('sess_mikrotik_device_status');
        kill_session_var('sess_mikrotik_device_filter');
        kill_session_var('sess_default_rows');
        kill_session_var('sess_mikrotik_device_current_page');
        unset($_REQUEST['sort_column']);
        unset($_REQUEST['sort_direction']);
        unset($_REQUEST['status']);
        unset($_REQUEST['filter']);
        unset($_REQUEST['rows']);
        unset($_REQUEST['page']);
    } else {
        /* if any of the settings changed, reset the page number */
        $changed = false;
        $changed += mikrotik_check_changed('status', 'sess_mikrotik_device_status');
        $changed += mikrotik_check_changed('filter', 'sess_mikrotik_device_filter');
        $changed += mikrotik_check_changed('rows', 'sess_default_rows');
        if ($changed) {
            $_REQUEST['page'] = '1';
        }
    }
    load_current_session_value('page', 'sess_mikrotik_device_current_page', '1');
    load_current_session_value('rows', 'sess_default_rows', read_config_option('num_rows_table'));
    load_current_session_value('sort_column', 'sess_mikrotik_device_sort_column', 'description');
    load_current_session_value('sort_direction', 'sess_mikrotik_device_sort_direction', 'ASC');
    load_current_session_value('status', 'sess_mikrotik_device_status', '-1');
    load_current_session_value('filter', 'sess_mikrotik_device_filter', '');
    ?>
	<script type='text/javascript'>
	function applyFilter() {
		strURL  = '?action=devices';
		strURL += '&status='   + $('#status').val();
		strURL += '&filter='   + $('#filter').val();
		strURL += '&rows='     + $('#rows').val();
		strURL += '&header=false';
		loadPageNoHeader(strURL);
	}

	function clearFilter() {
		strURL  = '?action=devices&clear=&header=false';
		loadPageNoHeader(strURL);
	}

	$(function() {
		$('#form_devices').submit(function(event) {
			event.preventDefault();
			applyFilter();
		});
	});
	</script>
	<?php 
    html_start_box('<strong>Device Filter</strong>', '100%', $colors['header'], '3', 'center', '');
    ?>
	<tr class='even noprint'>
		<td>
		<form id='form_devices' action='mikrotik.php?action=devices'>
			<table class='filterTable'>
				<tr>
					<td>
						Search
					</td>
					<td>
						<input id='filter' type='text' size='25' value='<?php 
    print get_request_var_request('filter');
    ?>
'>
					</td>
					<td>
						Status
					</td>
					<td>
						<select id='status' onChange='applyFilter()'>
							<option value='-1'<?php 
    if (get_request_var_request('type') == '-1') {
        ?>
 selected<?php 
    }
    ?>
>All</option>
							<?php 
    $statuses = db_fetch_assoc('SELECT DISTINCT status
								FROM host
								INNER JOIN plugin_mikrotik_system
								ON host.id=plugin_mikrotik_system.host_id');
    $statuses = array_merge($statuses, array('-2' => array('status' => '-2')));
    if (sizeof($statuses)) {
        foreach ($statuses as $s) {
            switch ($s['status']) {
                case '0':
                    $status = 'Unknown';
                    break;
                case '1':
                    $status = 'Down';
                    break;
                case '2':
                    $status = 'Recovering';
                    break;
                case '3':
                    $status = 'Up';
                    break;
                case '-2':
                    $status = 'Disabled';
                    break;
            }
            echo "<option value='" . $s['status'] . "' " . (get_request_var_request('status') == $s['status'] ? 'selected' : '') . '>' . $status . '</option>';
        }
    }
    ?>
						</select>
					</td>
					<td>
						Devices
					</td>
					<td>
						<select id='rows' onChange='applyFilter()'>
							<option value='-1'<?php 
    if (get_request_var_request('rows') == '-1') {
        ?>
 selected<?php 
    }
    ?>
>Default</option>
							<?php 
    if (sizeof($item_rows)) {
        foreach ($item_rows as $key => $name) {
            echo "<option value='" . $key . "' " . (get_request_var_request('rows') == $key ? 'selected' : '') . '>' . $name . '</option>';
        }
    }
    ?>
						</select>
					</td>
					<td>
						<input id='refresh' type='button' onClick='applyFilter()' value='Go'>
					</td>
					<td>
						<input id='clear' type='button' onClick='clearFilter()' value='Clear'>
					</td>
				</tr>
			</table>
			<input type='hidden' id='page' name='page' value='<?php 
    print $_REQUEST['page'];
    ?>
'>
			</form>
		</td>
	</tr>
	<?php 
    html_end_box();
    html_start_box('', '100%', $colors['header'], '3', 'center', '');
    if ($_REQUEST['rows'] == '-1') {
        $num_rows = read_config_option('num_rows_table');
    } else {
        $num_rows = get_request_var_request('rows');
    }
    $limit = ' LIMIT ' . $num_rows * (get_request_var_request('page') - 1) . ',' . $num_rows;
    $sql_where = '';
    if ($_REQUEST['status'] != '-1') {
        $sql_where .= (strlen($sql_where) ? ' AND' : 'WHERE') . ' hrs.host_status=' . $_REQUEST['status'];
    }
    $sql_join = '';
    if ($_REQUEST['filter'] != '') {
        $sql_where .= (strlen($sql_where) ? ' AND' : 'WHERE') . " h.description LIKE '%" . $_REQUEST['filter'] . "%' OR\n\t\t\th.hostname LIKE '%" . $_REQUEST['filter'] . "%'";
    }
    $sql = "SELECT hrs.*, h.hostname, h.description, h.disabled, trees.trees, queues.queues\n\t\tFROM plugin_mikrotik_system AS hrs\n\t\tINNER JOIN host AS h \n\t\tON h.id=hrs.host_id\n\t\tLEFT JOIN (SELECT host_id AS hid, count(*) AS trees FROM plugin_mikrotik_trees GROUP BY host_id) AS trees\n\t\tON trees.hid=hrs.host_id\n\t\tLEFT JOIN (SELECT host_id AS hid, count(*) AS queues FROM plugin_mikrotik_queues GROUP BY host_id) AS queues\n\t\tON queues.hid=hrs.host_id\n\t\t{$sql_join}\n\t\t{$sql_where}\n\t\tORDER BY " . get_request_var_request("sort_column") . " " . get_request_var_request("sort_direction") . " " . $limit;
    //echo $sql;
    $rows = db_fetch_assoc($sql);
    $total_rows = db_fetch_cell("SELECT COUNT(*)\n\t\tFROM plugin_mikrotik_system AS hrs\n\t\tINNER JOIN host AS h\n\t\tON h.id=hrs.host_id\n\t\t{$sql_join}\n\t\t{$sql_where}");
    $nav = html_nav_bar('mikrotik.php?action=devices', MAX_DISPLAY_PAGES, get_request_var_request('page'), $num_rows, $total_rows, 15, 'Devices', 'page', 'main');
    print $nav;
    $display_text = array('nosort' => array('display' => 'Actions', 'sort' => 'ASC', 'align' => 'left'), 'description' => array('display' => 'Name', 'sort' => 'ASC', 'align' => 'left'), 'host_status' => array('display' => 'Status', 'sort' => 'DESC', 'align' => 'center'), 'firmwareVersion' => array('display' => 'FW Ver', 'sort' => 'DESC', 'align' => 'right'), 'licVersion' => array('display' => 'Lic Ver', 'sort' => 'DESC', 'align' => 'right'), 'uptime' => array('display' => 'Uptime(d:h:m)', 'sort' => 'DESC', 'align' => 'right'), 'trees' => array('display' => 'Trees', 'sort' => 'DESC', 'align' => 'right'), 'users' => array('display' => 'Users', 'sort' => 'DESC', 'align' => 'right'), 'cpuPercent' => array('display' => 'CPU %', 'sort' => 'DESC', 'align' => 'right'), 'numCpus' => array('display' => 'CPUs', 'sort' => 'DESC', 'align' => 'right'), 'processes' => array('display' => 'Processes', 'sort' => 'DESC', 'align' => 'right'), 'memSize' => array('display' => 'Total Mem', 'sort' => 'DESC', 'align' => 'right'), 'memUsed' => array('display' => 'Used Mem', 'sort' => 'DESC', 'align' => 'right'), 'diskSize' => array('display' => 'Total Disk', 'sort' => 'DESC', 'align' => 'right'), 'diskUsed' => array('display' => 'Used Disk', 'sort' => 'DESC', 'align' => 'right'));
    html_header_sort($display_text, get_request_var_request('sort_column'), get_request_var_request('sort_direction'), 'false');
    /* set some defaults */
    $url = $config['url_path'] . 'plugins/mikrotik/mikrotik.php';
    $users = $config['url_path'] . 'plugins/mikrotik/images/view_users.gif';
    $usersn = $config['url_path'] . 'plugins/mikrotik/images/view_users_none.gif';
    $host = $config['url_path'] . 'plugins/mikrotik/images/view_hosts.gif';
    $trees = $config['url_path'] . 'plugins/mikrotik/images/view_trees.gif';
    $treesn = $config['url_path'] . 'plugins/mikrotik/images/view_trees_none.gif';
    $queues = $config['url_path'] . 'plugins/mikrotik/images/view_queues.gif';
    $queuesn = $config['url_path'] . 'plugins/mikrotik/images/view_queues_none.gif';
    $interfaces = $config['url_path'] . 'plugins/mikrotik/images/view_interfaces.gif';
    $dashboard = $config['url_path'] . 'plugins/mikrotik/images/view_dashboard.gif';
    $graphs = $config['url_path'] . 'plugins/mikrotik/images/view_graphs.gif';
    $nographs = $config['url_path'] . 'plugins/mikrotik/images/view_graphs_disabled.gif';
    $hcpudq = read_config_option('mikrotik_dq_host_cpu');
    if (sizeof($rows)) {
        foreach ($rows as $row) {
            $days = intval($row['uptime'] / (60 * 60 * 24 * 100));
            $remainder = $row['uptime'] % (60 * 60 * 24 * 100);
            $hours = intval($remainder / (60 * 60 * 100));
            $remainder = $remainder % (60 * 60 * 100);
            $minutes = intval($remainder / (60 * 100));
            $found = db_fetch_cell('SELECT COUNT(*) FROM graph_local WHERE host_id=' . $row['host_id']);
            form_alternate_row();
            echo "<td style='white-space:nowrap;min-width:115px;text-align:left;'>";
            //echo "<a style='padding:1px;' href='" . htmlspecialchars("$url?action=dashboard&reset=1&device=" . $row["host_id"]) . "'><img src='$dashboard' title='View Dashboard' align='absmiddle' border='0'></a>";
            if ($row['users'] > 0) {
                echo "<a class='hyperLink' href='" . htmlspecialchars("{$url}?action=users&reset=1&device=" . $row['host_id']) . "'><img src='{$users}' title='View Users' align='absmiddle' border='0' alt=''></a>";
            } else {
                echo "<img style='border:0px;padding:3px;' src='{$usersn}' title='No Users Found' align='absmiddle' alt=''>";
            }
            if ($row['queues'] > 0) {
                echo "<a class='hyperLink' href='" . htmlspecialchars("{$url}?action=queues&reset=1&device=" . $row['host_id']) . "'><img src='{$queues}' title='View Simple Queue' align='absmiddle' border='0' alt=''></a>";
            } else {
                echo "<img style='border:0px;padding:3px;' src='{$queuesn}' title='No Simple Queues Found' align='absmiddle' alt=''>";
            }
            if ($row['trees'] > 0) {
                echo "<a class='hyperLink' href='" . htmlspecialchars("{$url}?action=trees&reset=1&device=" . $row['host_id']) . "'><img src='{$trees}' title='View Queue Trees' align='absmiddle' border='0' alt=''></a>";
            } else {
                echo "<img style='border:0px;padding:3px;' src='{$treesn}' title='No Queue Trees Found' align='absmiddle' alt=''>";
            }
            echo "<a class='hyperLink' href='" . htmlspecialchars("{$url}?action=interfaces&reset=1&device=" . $row['host_id']) . "'><img src='{$interfaces}' title='View Interfaces' align='absmiddle' border='0' alt=''></a>";
            if ($found) {
                echo "<a class='hyperLink' href='" . htmlspecialchars("{$url}?action=graphs&reset=1&host_id=" . $row['host_id'] . "&style=selective&graph_add=&graph_list=&graph_template_id=0&filter=") . "'><img  src='{$graphs}' title='View Graphs' align='absmiddle' border='0' alt=''></a>";
            } else {
                echo "<img src='{$nographs}' title='No Graphs Defined' align='absmiddle' border='0'>";
            }
            $graph_cpu = mikrotik_get_graph_url($hcpudq, $row['host_id'], '', $row['numCpus'], false);
            $graph_cpup = mikrotik_get_graph_template_url(mikrotik_template_by_hash('7df474393f58bae8e8d6b85f10efad71'), $row['host_id'], round($row['cpuPercent'], 2), false);
            $graph_users = mikrotik_get_graph_template_url(mikrotik_template_by_hash('99e37ff13139f586d257ba9a637d7340'), $row['host_id'], empty($rows['users']) ? '-' : $row['users'], false);
            $graph_aproc = mikrotik_get_graph_template_url(mikrotik_template_by_hash('e797d967db24fd86341a8aa8c60fa9e0'), $row['host_id'], $row['host_status'] < 2 ? 'N/A' : $row['processes'], false);
            $graph_disk = mikrotik_get_graph_template_url(mikrotik_template_by_hash('0ece13b90785aa04d1f554a093685948'), $row['host_id'], $row['host_status'] < 2 ? 'N/A' : round($row['diskUsed'], 2), false);
            $graph_mem = mikrotik_get_graph_template_url(mikrotik_template_by_hash('4396ae857c4f9bc5ed1f26b5361e42d9'), $row['host_id'], $row['host_status'] < 2 ? 'N/A' : round($row['memUsed'], 2), false);
            $graph_upt = mikrotik_get_graph_template_url(mikrotik_template_by_hash('7d8dc3050621a2cb937cac3895bc5d5b'), $row['host_id'], $row['host_status'] < 2 ? 'N/A' : mikrotik_format_uptime($days, $hours, $minutes), false);
            if (api_plugin_user_realm_auth('host.php')) {
                $host_url = "<a class='hyperLink' href='" . htmlspecialchars($config['url_path'] . 'host.php?action=edit&id=' . $row['host_id']) . "' title='Edit Hosts'>" . $row['hostname'] . '</a>';
            } else {
                $host_url = $row['hostname'];
            }
            echo '</td>';
            echo "<td style='text-align:left;white-space:nowrap;'><strong>" . (strlen($_REQUEST['filter']) ? preg_replace('/(' . preg_quote(get_request_var_request('filter'), '/') . ')/i', "<span class='filteredValue'>\\1</span>", $row['description'] . '</strong> [' . $host_url . ']') : $row['description'] . '</strong> [' . $host_url . ']') . '</td>';
            echo "<td style='text-align:center;'>" . get_colored_device_status($row['disabled'] == 'on' ? true : false, $row['host_status']) . '</td>';
            echo "<td style='text-align:right;'>" . $row['firmwareVersion'] . '</td>';
            echo "<td style='text-align:right;'>" . $row['licVersion'] . '</td>';
            echo "<td style='text-align:right;'>" . $graph_upt . '</td>';
            echo "<td style='text-align:right;'>" . (!empty($row['trees']) ? $row['trees'] : '-') . '</td>';
            echo "<td style='text-align:right;'>" . $graph_users . '</td>';
            echo "<td style='text-align:right;'>" . ($row['host_status'] < 2 ? 'N/A' : $graph_cpup) . '</td>';
            echo "<td style='text-align:right;'>" . ($row['host_status'] < 2 ? 'N/A' : $graph_cpu) . '</td>';
            echo "<td style='text-align:right;'>" . $graph_aproc . '</td>';
            echo "<td style='text-align:right;'>" . mikrotik_memory($row['memSize']) . '</td>';
            echo "<td style='text-align:right;'>" . $graph_mem . ' %</td>';
            echo "<td style='text-align:right;'>" . mikrotik_memory($row['diskSize']) . '</td>';
            echo "<td style='text-align:right;'>" . $graph_disk . ' %</td>';
            form_end_row();
        }
        print $nav;
    } else {
        print '<tr><td colspan="5"><em>No Devices Found</em></td></tr>';
    }
    html_end_box();
}
Example #18
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 #19
0
function user_group_graph_perms_edit($tab, $header_label)
{
    global $config, $assoc_actions;
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_request('id'));
    /* ==================================================== */
    $policy_array = array(1 => 'Allow', 2 => 'Deny');
    if (!empty($_REQUEST['id'])) {
        $policy = db_fetch_row_prepared('SELECT policy_graphs, policy_trees, policy_hosts, policy_graph_templates FROM user_auth_group WHERE id = ?', array(get_request_var_request('id')));
    }
    switch ($tab) {
        case 'permsg':
            process_graph_request_vars();
            graph_filter($header_label);
            /* print checkbox form for validation */
            print "<form name='policy' method='post' action='user_group_admin.php'>\n";
            /* box: device permissions */
            html_start_box('<strong>Default Graph Policy</strong>', '100%', '', '3', 'center', '');
            ?>
		<tr class='odd'>
			<td><table cellpadding="2" cellspacing="0"><tr>
			<td style="white-space:nowrap;" width="120">Default Graph policy for this User Group</td>
			<td width="10"> 
				<?php 
            form_dropdown('policy_graphs', $policy_array, '', '', $policy['policy_graphs'], '', '');
            ?>
			</td>
			<td>
				<input type="submit" name="update_policy" value="Update">
				<input type="hidden" name="tab" value="<?php 
            print $tab;
            ?>
">
				<input type="hidden" name="id" value="<?php 
            print get_request_var_request('id');
            ?>
">
			</td>
			</tr></table></td>
		</tr>
		<?php 
            html_end_box();
            print "</form>\n";
            /* if the number of rows is -1, set it to the default */
            if ($_REQUEST['rows'] == -1) {
                $rows = read_config_option('num_rows_table');
            } else {
                $rows = $_REQUEST['rows'];
            }
            /* form the 'where' clause for our main sql query */
            if (strlen(get_request_var_request('filter'))) {
                $sql_where = "WHERE (gtg.title_cache LIKE '%%" . get_request_var_request('filter') . "%%' AND gtg.local_graph_id>0)";
            } else {
                $sql_where = 'WHERE (gtg.local_graph_id>0)';
            }
            if (get_request_var_request('graph_template_id') == '-1') {
                /* Show all items */
            } elseif (get_request_var_request('graph_template_id') == '0') {
                $sql_where .= (strlen($sql_where) ? ' AND ' : 'WHERE ') . ' gtg.graph_template_id=0';
            } elseif (!empty($_REQUEST['graph_template_id'])) {
                $sql_where .= (strlen($sql_where) ? ' AND ' : 'WHERE ') . ' gtg.graph_template_id=' . get_request_var_request('graph_template_id');
            }
            if (get_request_var_request('associated') == 'false') {
                /* Show all items */
            } else {
                $sql_where .= (strlen($sql_where) ? ' AND ' : 'WHERE ') . ' (user_auth_group_perms.type=1 AND user_auth_group_perms.group_id=' . get_request_var_request('id', 0) . ')';
            }
            /* print checkbox form for validation */
            print "<form name='chk' method='post' action='" . htmlspecialchars('user_group_admin.php?action=edit&tab=permsg&id=' . get_request_var_request('id')) . "'>\n";
            html_start_box('', '100%', '', '3', 'center', '');
            $total_rows = db_fetch_cell("select\n\t\t\tCOUNT(gtg.id)\n\t\t\tFROM graph_templates_graph AS gtg\n\t\t\tLEFT JOIN user_auth_group_perms \n\t\t\tON (gtg.local_graph_id = user_auth_group_perms.item_id AND user_auth_group_perms.type = 1)\n\t\t\t{$sql_where}");
            $sql_query = "SELECT gtg.local_graph_id, gtg.title_cache, user_auth_group_perms.group_id\n\t\t\tFROM graph_templates_graph AS gtg\n\t\t\tLEFT JOIN user_auth_group_perms \n\t\t\tON (gtg.local_graph_id=user_auth_group_perms.item_id AND user_auth_group_perms.type=1)\n\t\t\t{$sql_where} \n\t\t\tORDER BY title_cache\n\t\t\tLIMIT " . $rows * (get_request_var_request('page') - 1) . ',' . $rows;
            $graphs = db_fetch_assoc($sql_query);
            $nav = html_nav_bar('user_group_admin.php?action=edit&tab=permsg&id=' . get_request_var_request('id'), MAX_DISPLAY_PAGES, get_request_var_request('page'), $rows, $total_rows, 7, 'Graphs', 'page', 'main');
            print $nav;
            $display_text = array('Graph Title', 'ID', 'Effective Policy');
            html_header_checkbox($display_text, false);
            if (sizeof($graphs)) {
                foreach ($graphs as $g) {
                    form_alternate_row('line' . $g['local_graph_id'], true);
                    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($g['title_cache'])) : htmlspecialchars($g['title_cache']), $g['local_graph_id'], 250);
                    form_selectable_cell($g['local_graph_id'], $g['local_graph_id']);
                    if (empty($g['group_id']) || $g['group_id'] == NULL) {
                        if ($policy['policy_graphs'] == 1) {
                            form_selectable_cell('<span style="color:green;font-weight:bold;">Access Granted</span>', $g['local_graph_id']);
                        } else {
                            form_selectable_cell('<span style="color:red;font-weight:bold;">Access Restricted</span>', $g['local_graph_id']);
                        }
                    } else {
                        if ($policy['policy_graphs'] == 1) {
                            form_selectable_cell('<span style="color:red;font-weight:bold;">Access Restricted</span>', $g['local_graph_id']);
                        } else {
                            form_selectable_cell('<span style="color:green;font-weight:bold;">Access Granted</span>', $g['local_graph_id']);
                        }
                    }
                    form_checkbox_cell($g['title_cache'], $g['local_graph_id']);
                    form_end_row();
                }
                /* put the nav bar on the bottom as well */
                print $nav;
            } else {
                print '<tr><td><em>No Matching Graphs Found</em></td></tr>';
            }
            html_end_box(false);
            form_hidden_box('action', 'edit', '');
            form_hidden_box('tab', $tab, '');
            form_hidden_box('id', get_request_var_request('id'), '');
            form_hidden_box('associate_graph', '1', '');
            if ($policy['policy_graphs'] == 1) {
                $assoc_actions = array(1 => 'Revoke Access', 2 => 'Grant Access');
            } else {
                $assoc_actions = array(1 => 'Grant Access', 2 => 'Revoke Access');
            }
            /* draw the dropdown containing a list of available actions for this form */
            draw_actions_dropdown($assoc_actions);
            print '</form>';
            break;
        case 'permsd':
            process_device_request_vars();
            device_filter($header_label);
            /* print checkbox form for validation */
            print "<form name='policy' method='post' action='user_group_admin.php'>\n";
            /* box: device permissions */
            html_start_box('<strong>Default Device Policy</strong>', '100%', '', '3', 'center', '');
            ?>
		<tr class='even'>
			<td><table cellspacing="0" cellpadding="2"><tr>
			<td style="white-space:nowrap;" width="120">Default Graph policy for this User Group</td>
			<td width="10"> 
				<?php 
            form_dropdown('policy_hosts', $policy_array, '', '', $policy['policy_hosts'], '', '');
            ?>
			</td>
			<td>
				<input type="submit" name="update_policy" value="Update">
				<input type="hidden" name="tab" value="<?php 
            print $tab;
            ?>
">
				<input type="hidden" name="id" value="<?php 
            print get_request_var_request('id');
            ?>
">
			</td>
			</tr></table></td>
		</tr>
		<?php 
            html_end_box();
            print "</form>\n";
            /* if the number of rows is -1, set it to the default */
            if ($_REQUEST['rows'] == -1) {
                $rows = read_config_option('num_rows_table');
            } else {
                $rows = $_REQUEST['rows'];
            }
            /* form the 'where' clause for our main sql query */
            /* 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_template_id') == '-1') {
                /* Show all items */
            } elseif (get_request_var_request('host_template_id') == '0') {
                $sql_where .= (strlen($sql_where) ? ' AND ' : 'WHERE ') . ' host.host_template_id=0';
            } elseif (!empty($_REQUEST['host_template_id'])) {
                $sql_where .= (strlen($sql_where) ? ' AND ' : 'WHERE ') . ' host.host_template_id=' . get_request_var_request('host_template_id');
            }
            if (get_request_var_request('associated') == 'false') {
                /* Show all items */
            } else {
                $sql_where .= (strlen($sql_where) ? ' AND ' : 'WHERE ') . ' user_auth_group_perms.group_id=' . get_request_var_request('id', 0);
            }
            /* print checkbox form for validation */
            print "<form name='chk' method='post' action='" . htmlspecialchars('user_group_admin.php?action=edit&tab=permsd&id=' . get_request_var_request('id')) . "'>\n";
            html_start_box('', '100%', '', '3', 'center', '');
            $total_rows = db_fetch_cell("SELECT\n\t\t\tCOUNT(host.id)\n\t\t\tFROM host\n\t\t\tLEFT JOIN user_auth_group_perms \n\t\t\tON (host.id = user_auth_group_perms.item_id AND user_auth_group_perms.type = 3)\n\t\t\t{$sql_where}");
            $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 host.*, user_auth_group_perms.group_id\n\t\t\tFROM host \n\t\t\tLEFT JOIN user_auth_group_perms \n\t\t\tON (host.id=user_auth_group_perms.item_id AND user_auth_group_perms.type=3)\n\t\t\t{$sql_where} \n\t\t\tORDER BY description\n\t\t\tLIMIT " . $rows * (get_request_var_request('page') - 1) . ',' . $rows;
            $hosts = db_fetch_assoc($sql_query);
            $nav = html_nav_bar('user_group_admin.php?action=edit&tab=permsd&id=' . get_request_var_request('id'), MAX_DISPLAY_PAGES, get_request_var_request('page'), $rows, $total_rows, 11, 'Devices', 'page', 'main');
            print $nav;
            $display_text = array('Description', 'ID', 'Effective Policy', 'Graphs', 'Data Sources', 'Status', 'Hostname');
            html_header_checkbox($display_text, false);
            if (sizeof($hosts)) {
                foreach ($hosts as $host) {
                    form_alternate_row('line' . $host['id'], true);
                    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['description'])) : htmlspecialchars($host['description']), $host['id'], 250);
                    form_selectable_cell(round($host['id'], 2), $host['id']);
                    if (empty($host['group_id']) || $host['group_id'] == NULL) {
                        if ($policy['policy_hosts'] == 1) {
                            form_selectable_cell('<span style="color:green;font-weight:bold;">Access Granted</span>', $host['id']);
                        } else {
                            form_selectable_cell('<span style="color:red;font-weight:bold;">Access Restricted</span>', $host['id']);
                        }
                    } else {
                        if ($policy['policy_hosts'] == 1) {
                            form_selectable_cell('<span style="color:red;font-weight:bold;">Access Restricted</span>', $host['id']);
                        } else {
                            form_selectable_cell('<span style="color:green;font-weight:bold;">Access Granted</span>', $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(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_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 Matching Devices Found</em></td></tr>';
            }
            html_end_box(false);
            form_hidden_box('action', 'edit', '');
            form_hidden_box('tab', $tab, '');
            form_hidden_box('id', get_request_var_request('id'), '');
            form_hidden_box('associate_host', '1', '');
            if ($policy['policy_hosts'] == 1) {
                $assoc_actions = array(1 => 'Revoke Access', 2 => 'Grant Access');
            } else {
                $assoc_actions = array(1 => 'Grant Access', 2 => 'Revoke Access');
            }
            /* draw the dropdown containing a list of available actions for this form */
            draw_actions_dropdown($assoc_actions);
            print "</form>\n";
            break;
        case 'permste':
            process_template_request_vars();
            template_filter($header_label);
            /* print checkbox form for validation */
            print "<form name='policy' method='post' action='user_group_admin.php'>\n";
            /* box: device permissions */
            html_start_box('<strong>Default Graph Template Policy</strong>', '100%', '', '3', 'center', '');
            ?>
		<tr class='even'>
			<td><table cellspacing="0" cellpadding="2"><tr>
			<td style="white-space:nowrap;" width="120">Default Graph Template Template policy for this User Group</td>
			<td width="10"> 
				<?php 
            form_dropdown('policy_graph_templates', $policy_array, '', '', $policy['policy_graph_templates'], '', '');
            ?>
			</td>
			<td>
				<input type="submit" name="update_policy" value="Update">
				<input type="hidden" name="tab" value="<?php 
            print $tab;
            ?>
">
				<input type="hidden" name="id" value="<?php 
            print get_request_var_request('id');
            ?>
">
			</td>
			</tr></table></td>
		</tr>
		<?php 
            html_end_box();
            print "</form>\n";
            /* if the number of rows is -1, set it to the default */
            if ($_REQUEST['rows'] == -1) {
                $rows = read_config_option('num_rows_table');
            } else {
                $rows = $_REQUEST['rows'];
            }
            /* form the 'where' clause for our main sql query */
            /* form the 'where' clause for our main sql query */
            if (strlen(get_request_var_request('filter'))) {
                $sql_where = "WHERE (gt.name LIKE '%%" . get_request_var_request('filter') . "%%')";
            } else {
                $sql_where = '';
            }
            if (get_request_var_request('associated') == 'false') {
                /* Show all items */
            } else {
                $sql_where .= (strlen($sql_where) ? ' AND ' : 'WHERE ') . ' (user_auth_group_perms.type=4 AND user_auth_group_perms.group_id=' . get_request_var_request('id', 0) . ')';
            }
            /* print checkbox form for validation */
            print "<form name='chk' method='post' action='" . htmlspecialchars('user_group_admin.php?action=edit&tab=permste&id=' . get_request_var_request('id')) . "'>\n";
            html_start_box('', '100%', '', '3', 'center', '');
            $total_rows = db_fetch_cell("SELECT\n\t\t\tCOUNT(gt.id)\n\t\t\tFROM graph_templates AS gt\n\t\t\tINNER JOIN graph_local AS gl\n\t\t\tON gt.id = gl.graph_template_id\n\t\t\tLEFT JOIN user_auth_group_perms \n\t\t\tON (gt.id = user_auth_group_perms.item_id AND user_auth_group_perms.type = 4)\n\t\t\t{$sql_where}\n\t\t\tGROUP BY gl.graph_template_id");
            $sql_query = "SELECT gt.id, gt.name, count(*) AS totals, user_auth_group_perms.group_id\n\t\t\tFROM graph_templates AS gt\n\t\t\tINNER JOIN graph_local AS gl\n\t\t\tON gt.id = gl.graph_template_id\n\t\t\tLEFT JOIN user_auth_group_perms \n\t\t\tON (gt.id = user_auth_group_perms.item_id AND user_auth_group_perms.type = 4)\n\t\t\t{$sql_where} \n\t\t\tGROUP BY gl.graph_template_id\n\t\t\tORDER BY name\n\t\t\tLIMIT " . $rows * (get_request_var_request('page') - 1) . ',' . $rows;
            $graphs = db_fetch_assoc($sql_query);
            $nav = html_nav_bar('user_group_admin.php?action=edit&tab=permste&id=' . get_request_var_request('id'), MAX_DISPLAY_PAGES, get_request_var_request('page'), $rows, $total_rows, 11, 'Graph Templates', 'page', 'main');
            print $nav;
            $display_text = array('Template Name', 'ID', 'Effective Policy', 'Total Graphs');
            html_header_checkbox($display_text, false);
            if (sizeof($graphs)) {
                foreach ($graphs as $g) {
                    form_alternate_row('line' . $g['id'], true);
                    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($g['name'])) : htmlspecialchars($g['name']), $g['id'], 250);
                    form_selectable_cell($g['id'], $g['id']);
                    if (empty($g['group_id']) || $g['group_id'] == NULL) {
                        if ($policy['policy_graph_templates'] == 1) {
                            form_selectable_cell('<span style="color:green;font-weight:bold;">Access Granted</span>', $g['id']);
                        } else {
                            form_selectable_cell('<span style="color:red;font-weight:bold;">Access Restricted</span>', $g['id']);
                        }
                    } else {
                        if ($policy['policy_graph_templates'] == 1) {
                            form_selectable_cell('<span style="color:red;font-weight:bold;">Access Restricted</span>', $g['id']);
                        } else {
                            form_selectable_cell('<span style="color:green;font-weight:bold;">Access Granted</span>', $g['id']);
                        }
                    }
                    form_selectable_cell($g['totals'], $g['id']);
                    form_checkbox_cell($g['name'], $g['id']);
                    form_end_row();
                }
                /* put the nav bar on the bottom as well */
                print $nav;
            } else {
                print '<tr><td><em>No Matching Graph Templates Found</em></td></tr>';
            }
            html_end_box(false);
            form_hidden_box('action', 'edit', '');
            form_hidden_box('tab', $tab, '');
            form_hidden_box('id', get_request_var_request('id'), '');
            form_hidden_box('associate_template', '1', '');
            if ($policy['policy_graph_templates'] == 1) {
                $assoc_actions = array(1 => 'Revoke Access', 2 => 'Grant Access');
            } else {
                $assoc_actions = array(1 => 'Grant Access', 2 => 'Revoke Access');
            }
            /* draw the dropdown containing a list of available actions for this form */
            draw_actions_dropdown($assoc_actions);
            print '</form>';
            break;
        case 'permstr':
            process_tree_request_vars();
            tree_filter($header_label);
            /* print checkbox form for validation */
            print "<form name='policy' method='post' action='user_group_admin.php'>\n";
            /* box: device permissions */
            html_start_box('<strong>Default Tree Policy</strong>', '100%', '', '3', 'center', '');
            ?>
		<tr class='even'>
			<td><table cellspacing="0" cellpadding="2"><tr>
			<td style="white-space:nowrap;" width="120">Default Tree policy for this User Group</td>
			<td width="10"> 
				<?php 
            form_dropdown('policy_trees', $policy_array, '', '', $policy['policy_trees'], '', '');
            ?>
			</td>
			<td>
				<input type="submit" name="update_policy" value="Update">
				<input type="hidden" name="tab" value="<?php 
            print $tab;
            ?>
">
				<input type="hidden" name="id" value="<?php 
            print get_request_var_request('id');
            ?>
">
			</td>
			</tr></table></td>
		</tr>
		<?php 
            html_end_box();
            print "</form>\n";
            /* if the number of rows is -1, set it to the default */
            if ($_REQUEST['rows'] == -1) {
                $rows = read_config_option('num_rows_table');
            } else {
                $rows = $_REQUEST['rows'];
            }
            /* form the 'where' clause for our main sql query */
            if (strlen(get_request_var_request('filter'))) {
                $sql_where = "WHERE (gt.name LIKE '%%" . get_request_var_request('filter') . "%%')";
            } else {
                $sql_where = '';
            }
            if (get_request_var_request('associated') == 'false') {
                /* Show all items */
            } else {
                $sql_where .= (strlen($sql_where) ? ' AND ' : 'WHERE ') . ' (user_auth_group_perms.type=2 AND user_auth_group_perms.group_id=' . get_request_var_request('id', 0) . ')';
            }
            /* print checkbox form for validation */
            print "<form name='chk' method='post' action='" . htmlspecialchars('user_group_admin.php?action=edit&tab=permstr&id=' . get_request_var_request('id')) . "'>\n";
            html_start_box('', '100%', '', '3', 'center', '');
            $total_rows = db_fetch_cell("SELECT\n\t\t\tCOUNT(gt.id)\n\t\t\tFROM graph_tree AS gt\n\t\t\tLEFT JOIN user_auth_group_perms \n\t\t\tON (gt.id = user_auth_group_perms.item_id AND user_auth_group_perms.type = 2)\n\t\t\t{$sql_where}");
            $sql_query = "SELECT gt.id, gt.name, user_auth_group_perms.group_id\n\t\t\tFROM graph_tree AS gt\n\t\t\tLEFT JOIN user_auth_group_perms \n\t\t\tON (gt.id = user_auth_group_perms.item_id AND user_auth_group_perms.type = 2)\n\t\t\t{$sql_where} \n\t\t\tORDER BY name\n\t\t\tLIMIT " . $rows * (get_request_var_request('page') - 1) . ',' . $rows;
            $trees = db_fetch_assoc($sql_query);
            $nav = html_nav_bar('user_group_admin.php?action=edit&tab=permstr&id=' . get_request_var_request('id'), MAX_DISPLAY_PAGES, get_request_var_request('page'), $rows, $total_rows, 11, 'Trees', 'page', 'main');
            print $nav;
            $display_text = array('Tree Name', 'ID', 'Effective Policy');
            html_header_checkbox($display_text, false);
            if (sizeof($trees)) {
                foreach ($trees as $t) {
                    form_alternate_row('line' . $t['id'], true);
                    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($t['name'])) : htmlspecialchars($t['name']), $t['id'], 250);
                    form_selectable_cell($t['id'], $t['id']);
                    if (empty($t['group_id']) || $t['group_id'] == NULL) {
                        if ($policy['policy_trees'] == 1) {
                            form_selectable_cell('<span style="color:green;font-weight:bold;">Access Granted</span>', $t['id']);
                        } else {
                            form_selectable_cell('<span style="color:red;font-weight:bold;">Access Restricted</span>', $t['id']);
                        }
                    } else {
                        if ($policy['policy_trees'] == 1) {
                            form_selectable_cell('<span style="color:red;font-weight:bold;">Access Restricted</span>', $t['id']);
                        } else {
                            form_selectable_cell('<span style="color:green;font-weight:bold;">Access Granted</span>', $t['id']);
                        }
                    }
                    form_checkbox_cell($t['name'], $t['id']);
                    form_end_row();
                }
                /* put the nav bar on the bottom as well */
                print $nav;
            } else {
                print '<tr><td><em>No Matching Trees Found</em></td></tr>';
            }
            html_end_box(false);
            form_hidden_box('action', 'edit', '');
            form_hidden_box('tab', $tab, '');
            form_hidden_box('id', get_request_var_request('id'), '');
            form_hidden_box('associate_tree', '1', '');
            if ($policy['policy_graph_templates'] == 1) {
                $assoc_actions = array(1 => 'Revoke Access', 2 => 'Grant Access');
            } else {
                $assoc_actions = array(1 => 'Grant Access', 2 => 'Revoke Access');
            }
            /* draw the dropdown containing a list of available actions for this form */
            draw_actions_dropdown($assoc_actions);
            print '</form>';
            break;
    }
}