Example #1
0
function draw_edit_form($array)
{
    if (sizeof($array) > 0) {
        while (list($top_branch, $top_children) = each($array)) {
            if ($top_branch == "config") {
                $config_array = $top_children;
            } elseif ($top_branch == "fields") {
                $fields_array = $top_children;
            }
        }
    }
    $i = 0;
    if (sizeof($fields_array) > 0) {
        while (list($field_name, $field_array) = each($fields_array)) {
            if ($i == 0) {
                if (!isset($config_array["no_form_tag"])) {
                    print "<tr style='display:none;'><td><form method='post' autocomplete='off' action='" . (isset($config_array["post_to"]) ? $config_array["post_to"] : basename($_SERVER["PHP_SELF"])) . "'" . (isset($config_array["form_name"]) ? " name='" . $config_array["form_name"] . "'" : "") . (isset($config_array["enctype"]) ? " enctype='" . $config_array["enctype"] . "'" : "") . "></td></tr>\n";
                }
            }
            if ($field_array["method"] == "hidden") {
                form_hidden_box($field_name, $field_array["value"], isset($field_array["default"]) ? $field_array["default"] : "");
            } elseif ($field_array["method"] == "hidden_zero") {
                form_hidden_box($field_name, $field_array["value"], "0");
            } elseif ($field_array["method"] == "spacer") {
                if (isset($field_array['collapsible']) && $field_array['collapsible'] == 'true') {
                    $collapsible = true;
                } else {
                    $collapsible = false;
                }
                print "<tr class='spacer tableHeader" . ($collapsible ? ' collapsible' : '') . "' id='row_{$field_name}'><td colspan='2' style='cursor:pointer;' class='tableSubHeaderColumn'>" . $field_array["friendly_name"] . ($collapsible ? "<div style='float:right;padding-right:4px;'><i class='fa fa-angle-double-up'></i></div>" : "") . "</td></tr>\n";
            } else {
                if (isset($config_array["force_row_color"])) {
                    print "<tr class='even-alternate'>";
                } else {
                    form_alternate_row('row_' . $field_name);
                }
                print "<td width='" . (isset($config_array["left_column_width"]) ? $config_array["left_column_width"] : "50%") . "'>\n<font class='textEditTitle'>" . $field_array["friendly_name"] . "</font><br>\n";
                if (isset($field_array["sub_checkbox"])) {
                    form_checkbox($field_array["sub_checkbox"]["name"], $field_array["sub_checkbox"]["value"], $field_array["sub_checkbox"]["friendly_name"], isset($field_array["sub_checkbox"]["default"]) ? $field_array["sub_checkbox"]["default"] : "", isset($field_array["sub_checkbox"]["form_id"]) ? $field_array["sub_checkbox"]["form_id"] : "", isset($field_array["sub_checkbox"]["class"]) ? $field_array["sub_checkbox"]["class"] : "", isset($field_array["sub_checkbox"]["on_change"]) ? $field_array["sub_checkbox"]["on_change"] : "");
                }
                print (isset($field_array["description"]) ? $field_array["description"] : "") . "</td>\n";
                print "<td>";
                draw_edit_control($field_name, $field_array);
                print "</td>\n</tr>\n";
            }
            $i++;
        }
    }
}
Example #2
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 #3
0
function graphs()
{
    global $item_rows;
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_request('host_id'));
    input_validate_input_number(get_request_var_request('graph_type'));
    input_validate_input_number(get_request_var_request('rows'));
    /* ==================================================== */
    /* clean up search string */
    if (isset($_REQUEST['filter'])) {
        $_REQUEST['filter'] = sanitize_search_string(get_request_var_request('filter'));
    }
    /* if the user pushed the 'clear' button */
    if (isset($_REQUEST['clear_x'])) {
        kill_session_var('sess_graphs_new_filter');
        kill_session_var('sess_default_rows');
        unset($_REQUEST['filter']);
        unset($_REQUEST['rows']);
        $changed = true;
    } else {
        /* if any of the settings changed, reset the page number */
        $changed = false;
        $changed += check_changed('host_id', 'sess_graphs_new_host_id');
        $changed += check_changed('graph_type', 'sess_graphs_new_graph_type');
        $changed += check_changed('filter', 'sess_graphs_new_filter');
        $changed += check_changed('rows', 'sess_default_rows');
    }
    load_current_session_value('host_id', 'sess_graphs_new_host_id', db_fetch_cell('SELECT id FROM host ORDER BY description, hostname LIMIT 1'));
    load_current_session_value('graph_type', 'sess_graphs_new_graph_type', read_config_option('default_graphs_new_dropdown'));
    load_current_session_value('filter', 'sess_graphs_new_filter', '');
    load_current_session_value('rows', 'sess_default_rows', read_config_option('num_rows_table'));
    if (!empty($_REQUEST['host_id'])) {
        $host = db_fetch_row_prepared('SELECT id, description, hostname, host_template_id FROM host WHERE id = ?', array($_REQUEST['host_id']));
        $header = ' [ ' . htmlspecialchars($host['description']) . ' (' . htmlspecialchars($host['hostname']) . ') ' . (!empty($host['host_template_id']) ? htmlspecialchars(db_fetch_cell_prepared('SELECT name FROM host_template WHERE id = ?', array($host['host_template_id']))) : '') . ' ]';
    } else {
        $host = array();
        $header = 'None Host Type';
    }
    $row_limit = get_request_var_request('rows');
    html_start_box("<strong>New Graphs for</strong> {$header}", '100%', '', '3', 'center', '');
    form_alternate_row();
    print '<td class="even">';
    ?>
	<script type='text/javascript'>
	<!--

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

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

	<?php 
    html_end_box();
    ?>

	<form name='chk' method='post' action='graphs_new.php'>
	<?php 
    $total_rows = sizeof(db_fetch_assoc_prepared('SELECT graph_template_id FROM host_graph WHERE host_id = ?', array($_REQUEST['host_id'])));
    $i = 0;
    if ($changed) {
        foreach ($snmp_queries as $query) {
            kill_session_var('sess_graphs_new_page' . $query['id']);
            unset($_REQUEST['page' . $query['id']]);
            load_current_session_value('page' . $query['id'], 'sess_graphs_new_page' . $query['id'], '1');
        }
    }
    if ($_REQUEST['graph_type'] > 0) {
        load_current_session_value('page' . $_REQUEST['graph_type'], 'sess_graphs_new_page' . $_REQUEST['graph_type'], '1');
    } else {
        if ($_REQUEST['graph_type'] == -2) {
            foreach ($snmp_queries as $query) {
                load_current_session_value('page' . $query['id'], 'sess_graphs_new_page' . $query['id'], '1');
            }
        }
    }
    $script = "<script type='text/javascript'>\nvar gt_created_graphs = new Array();\nvar created_graphs = new Array()\n";
    if ($_REQUEST['graph_type'] < 0) {
        html_start_box('<strong>Graph Templates</strong>', '100%', '', '3', 'center', '');
        print "<tr class='tableHeader'>\n\t\t\t\t<td class='tableSubHeaderColumn'>Graph Template Name</td>\n\t\t\t\t<td width='1%' align='center' class='tableSubHeaderCheckbox' style='" . get_checkbox_style() . "'><input type='checkbox' style='margin: 0px;' name='all_cg' title='Select All' onClick='SelectAll(\"sg\",this.checked);'></td>\n\n\t\t\t</tr>\n";
        $graph_templates = db_fetch_assoc_prepared('SELECT
			graph_templates.id AS graph_template_id,
			graph_templates.name AS graph_template_name
			FROM (host_graph, graph_templates)
			WHERE host_graph.graph_template_id = graph_templates.id
			AND host_graph.host_id = ?
			ORDER BY graph_templates.name', array($_REQUEST['host_id']));
        if (!empty($_REQUEST['host_id'])) {
            $template_graphs = db_fetch_assoc_prepared('SELECT
				graph_local.graph_template_id
				FROM (graph_local, host_graph)
				WHERE graph_local.graph_template_id = host_graph.graph_template_id
				AND graph_local.host_id = host_graph.host_id
				AND graph_local.host_id = ?
				GROUP BY graph_local.graph_template_id', array($host['id']));
            if (sizeof($template_graphs) > 0) {
                $script .= 'var gt_created_graphs = new Array(';
                $cg_ctr = 0;
                foreach ($template_graphs as $template_graph) {
                    $script .= ($cg_ctr > 0 ? ',' : '') . "'" . $template_graph['graph_template_id'] . "'";
                    $cg_ctr++;
                }
                $script .= ")\n";
            }
        }
        /* create a row for each graph template associated with the host template */
        if (sizeof($graph_templates) > 0) {
            foreach ($graph_templates as $graph_template) {
                $query_row = $graph_template['graph_template_id'];
                print "<tr id='gt_line{$query_row}' class='selectable " . ($i % 2 == 0 ? 'odd' : 'even') . "'>";
                $i++;
                print "<td>\n\t\t\t\t\t\t<span id='gt_text{$query_row}" . "_0'>" . htmlspecialchars($graph_template['graph_template_name']) . "</span>\n\t\t\t\t\t</td>\n\t\t\t\t\t<td align='right' class='checkbox'>\n\t\t\t\t\t\t<input type='checkbox' name='cg_{$query_row}' id='cg_{$query_row}'>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>";
            }
        }
        html_end_box();
        html_start_box('', '100%', '', '3', 'center', '');
        $available_graph_templates = db_fetch_assoc('SELECT
			graph_templates.id, graph_templates.name
			FROM snmp_query_graph RIGHT JOIN graph_templates
			ON (snmp_query_graph.graph_template_id = graph_templates.id)
			WHERE (((snmp_query_graph.name) Is Null)) ORDER BY graph_templates.name');
        /* create a row at the bottom that lets the user create any graph they choose */
        print "\t<tr class='even'>\n\t\t\t\t<td width='1'><i>Create</i></td>\n\t\t\t\t<td align='left'>";
        form_dropdown('cg_g', $available_graph_templates, 'name', 'id', '', '(Select a graph type to create)', '', 'textArea');
        print '</td>
			</tr>';
        html_end_box();
    }
    if ($_REQUEST['graph_type'] != -1 && !empty($_REQUEST['host_id'])) {
        $snmp_queries = db_fetch_assoc('SELECT
			snmp_query.id,
			snmp_query.name,
			snmp_query.xml_path
			FROM (snmp_query,host_snmp_query)
			WHERE host_snmp_query.snmp_query_id=snmp_query.id
			AND host_snmp_query.host_id=' . $host['id'] . ($_REQUEST['graph_type'] != -2 ? ' AND snmp_query.id=' . $_REQUEST['graph_type'] : '') . '
			ORDER BY snmp_query.name');
        if (sizeof($snmp_queries) > 0) {
            foreach ($snmp_queries as $snmp_query) {
                unset($total_rows);
                if (!$changed) {
                    $page = $_REQUEST['page' . $snmp_query['id']];
                } else {
                    $page = 1;
                }
                $xml_array = get_data_query_array($snmp_query['id']);
                $num_input_fields = 0;
                $num_visible_fields = 0;
                if ($xml_array != false) {
                    /* loop through once so we can find out how many input fields there are */
                    reset($xml_array['fields']);
                    while (list($field_name, $field_array) = each($xml_array['fields'])) {
                        if ($field_array['direction'] == 'input') {
                            $num_input_fields++;
                            if (!isset($total_rows)) {
                                $total_rows = db_fetch_cell_prepared('SELECT count(*) FROM host_snmp_cache WHERE host_id = ? AND snmp_query_id = ? AND field_name = ?', array($host['id'], $snmp_query['id'], $field_name));
                            }
                        }
                    }
                }
                if (!isset($total_rows)) {
                    $total_rows = 0;
                }
                $snmp_query_graphs = db_fetch_assoc_prepared('SELECT snmp_query_graph.id,snmp_query_graph.name FROM snmp_query_graph WHERE snmp_query_graph.snmp_query_id = ? ORDER BY snmp_query_graph.name', array($snmp_query['id']));
                if (sizeof($snmp_query_graphs) > 0) {
                    foreach ($snmp_query_graphs as $snmp_query_graph) {
                        $created_graphs = db_fetch_assoc_prepared("SELECT DISTINCT\n\t\t\t\t\t\tdata_local. snmp_index\n\t\t\t\t\t\tFROM (data_local, data_template_data)\n\t\t\t\t\t\tLEFT JOIN data_input_data ON (data_template_data.id = data_input_data.data_template_data_id)\n\t\t\t\t\t\tLEFT JOIN data_input_fields ON (data_input_data.data_input_field_id = data_input_fields.id)\n\t\t\t\t\t\tWHERE data_local.id = data_template_data.local_data_id\n\t\t\t\t\t\tAND data_input_fields.type_code = 'output_type'\n\t\t\t\t\t\tAND data_input_data.value = ?\n\t\t\t\t\t\tAND data_local.host_id = ?", array($snmp_query_graph['id'], $host['id']));
                        $script .= 'created_graphs[' . $snmp_query_graph['id'] . '] = new Array(';
                        $cg_ctr = 0;
                        if (sizeof($created_graphs) > 0) {
                            foreach ($created_graphs as $created_graph) {
                                $script .= ($cg_ctr > 0 ? ',' : '') . "'" . encode_data_query_index($created_graph['snmp_index']) . "'";
                                $cg_ctr++;
                            }
                        }
                        $script .= ")\n";
                    }
                }
                print "\t<table width='100%' class='cactiTable' align='center' cellpadding='3' cellspacing='0'>\n\n\t\t\t\t\t<tr class='cactiTableTitle'>\n\t\t\t\t\t\t<td colspan='" . ($num_input_fields + 1) . "'>\n\t\t\t\t\t\t\t<table  cellspacing='0' cellpadding='0' width='100%' >\n\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t<td class='textHeaderDark'>\n\t\t\t\t\t\t\t\t\t\t<strong>Data Query</strong> [" . $snmp_query['name'] . "]\n\t\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t\t\t<td align='right' nowrap>\n\t\t\t\t\t\t\t\t\t\t<a href='" . htmlspecialchars('graphs_new.php?action=query_reload&id=' . $snmp_query['id'] . '&host_id=' . $host['id']) . "'><img src='images/reload_icon_small.gif' title='Reload Associated Query' alt='' border='0' align='absmiddle'></a>\n\t\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t</table>\n\t\t\t\t\t\t</td>\n\t\t\t\t\t</tr>";
                if ($xml_array != false) {
                    $html_dq_header = '';
                    $snmp_query_indexes = array();
                    reset($xml_array['fields']);
                    /* if there is a where clause, get the matching snmp_indexes */
                    $sql_where = '';
                    if (strlen($_REQUEST['filter'])) {
                        $sql_where = '';
                        $indexes = db_fetch_assoc("SELECT DISTINCT snmp_index\n\t\t\t\t\t\tFROM host_snmp_cache\n\t\t\t\t\t\tWHERE field_value LIKE '%%" . $_REQUEST['filter'] . "%%'\n\t\t\t\t\t\tAND snmp_query_id=" . $snmp_query['id'] . "\n\t\t\t\t\t\tAND host_id=" . $host['id']);
                        if (sizeof($indexes)) {
                            foreach ($indexes as $index) {
                                if (strlen($sql_where)) {
                                    $sql_where .= ", '" . $index['snmp_index'] . "'";
                                } else {
                                    $sql_where .= " AND snmp_index IN('" . $index['snmp_index'] . "'";
                                }
                            }
                            $sql_where .= ')';
                        }
                    }
                    if (strlen($_REQUEST['filter']) == 0 || strlen($_REQUEST['filter']) && sizeof($indexes)) {
                        /* determine the sort order */
                        if (isset($xml_array['index_order_type'])) {
                            if ($xml_array['index_order_type'] == 'numeric') {
                                $sql_order = 'ORDER BY CAST(snmp_index AS unsigned)';
                            } else {
                                if ($xml_array['index_order_type'] == 'alphabetic') {
                                    $sql_order = 'ORDER BY snmp_index';
                                } else {
                                    if ($xml_array['index_order_type'] == 'natural') {
                                        $sql_order = 'ORDER BY INET_ATON(snmp_index)';
                                    } else {
                                        $sql_order = '';
                                    }
                                }
                            }
                        } else {
                            $sql_order = '';
                        }
                        /* get the unique field values from the database */
                        $field_names = db_fetch_assoc_prepared('SELECT DISTINCT field_name
						FROM host_snmp_cache
						WHERE host_id = ?
						AND snmp_query_id = ?', array($host['id'], $snmp_query['id']));
                        /* build magic query */
                        $sql_query = 'SELECT host_id, snmp_query_id, snmp_index';
                        $num_visible_fields = sizeof($field_names);
                        $i = 0;
                        if (sizeof($field_names) > 0) {
                            foreach ($field_names as $column) {
                                $field_name = $column['field_name'];
                                $sql_query .= ", MAX(CASE WHEN field_name='{$field_name}' THEN field_value ELSE NULL END) AS '{$field_name}'";
                                $i++;
                            }
                        }
                        $sql_query .= ' FROM host_snmp_cache
						WHERE host_id=' . $host['id'] . '
						AND snmp_query_id=' . $snmp_query['id'] . "\n\t\t\t\t\t\t{$sql_where}\n\t\t\t\t\t\tGROUP BY host_id, snmp_query_id, snmp_index\n\t\t\t\t\t\t{$sql_order}\n\t\t\t\t\t\tLIMIT " . $row_limit * ($page - 1) . ',' . $row_limit;
                        $rows_query = 'SELECT host_id, snmp_query_id, snmp_index
						FROM host_snmp_cache
						WHERE host_id=' . $host['id'] . '
						AND snmp_query_id=' . $snmp_query['id'] . "\n\t\t\t\t\t\t{$sql_where}\n\t\t\t\t\t\tGROUP BY host_id, snmp_query_id, snmp_index";
                        $snmp_query_indexes = db_fetch_assoc($sql_query);
                        $total_rows = sizeof(db_fetch_assoc($rows_query));
                        if (($page - 1) * $row_limit > $total_rows) {
                            $page = 1;
                            $_REQUEST['page' . $query['id']] = $page;
                            load_current_session_value('page' . $query['id'], 'sess_graphs_new_page' . $query['id'], '1');
                        }
                        $nav = html_nav_bar('graphs_new.php', MAX_DISPLAY_PAGES, $page, $row_limit, $total_rows, 15, 'Items', 'page' . $snmp_query['id']);
                        print $nav;
                        while (list($field_name, $field_array) = each($xml_array['fields'])) {
                            if ($field_array['direction'] == 'input' && sizeof($field_names)) {
                                foreach ($field_names as $row) {
                                    if ($row['field_name'] == $field_name) {
                                        $html_dq_header .= "<td class='tableSubHeaderColumn'>" . $field_array['name'] . "</td>\n";
                                        break;
                                    }
                                }
                            }
                        }
                        if (!sizeof($snmp_query_indexes)) {
                            print "<tr class='odd'><td>This Data Query returned 0 rows, perhaps there was a problem executing this\n\t\t\t\t\t\t\tData Query. You can <a href='" . htmlspecialchars('host.php?action=query_verbose&id=' . $snmp_query['id'] . '&host_id=' . $host['id']) . "'>run this Data Query in debug mode</a> to get more information.</td></tr>\n";
                        } else {
                            print "<tr class='tableHeader'>\n\t\t\t\t\t\t\t\t{$html_dq_header}\n\t\t\t\t\t\t\t\t<td width='1%' align='center' class='tableSubHeaderCheckbox' style='" . get_checkbox_style() . "'><input type='checkbox' style='margin: 0px;' name='all_" . $snmp_query['id'] . "' title='Select All' onClick='SelectAll(\"sg_" . $snmp_query['id'] . "\",this.checked)'></td>\n\n\t\t\t\t\t\t\t</tr>\n";
                        }
                        $row_counter = 0;
                        $column_counter = 0;
                        $fields = array_rekey($field_names, 'field_name', 'field_name');
                        if (sizeof($snmp_query_indexes) > 0) {
                            foreach ($snmp_query_indexes as $row) {
                                $query_row = $snmp_query['id'] . '_' . encode_data_query_index($row['snmp_index']);
                                print "<tr id='line{$query_row}' class='selectable " . ($row_counter % 2 == 0 ? 'odd' : 'even') . "'>";
                                $i++;
                                $column_counter = 0;
                                reset($xml_array['fields']);
                                while (list($field_name, $field_array) = each($xml_array['fields'])) {
                                    if ($field_array['direction'] == 'input') {
                                        if (in_array($field_name, $fields)) {
                                            if (isset($row[$field_name])) {
                                                print "<td><span id='text{$query_row}" . '_' . $column_counter . "'>" . (strlen($_REQUEST['filter']) ? preg_replace('/(' . preg_quote($_REQUEST['filter']) . ')/i', "<span class='filteredValue'>\\1</span>", $row[$field_name]) : $row[$field_name]) . '</span></td>';
                                            } else {
                                                print "<td><span id='text{$query_row}" . '_' . $column_counter . "'></span></td>";
                                            }
                                            $column_counter++;
                                        }
                                    }
                                }
                                print "<td class='checkbox' align='right'>";
                                print "<input type='checkbox' name='sg_{$query_row}' id='sg_{$query_row}'>";
                                print '</td>';
                                print "</tr>\n";
                                $row_counter++;
                            }
                        }
                        if ($total_rows > $row_limit) {
                            print $nav;
                        }
                    } else {
                        print "<tr class='odd'><td class='textError'>Search Returned no Rows.</td></tr>\n";
                    }
                } else {
                    print "<tr class='odd'><td class='textError'>Error in data query.</td></tr>\n";
                }
                print '</table>';
                /* draw the graph template drop down here */
                $data_query_graphs = db_fetch_assoc_prepared('SELECT snmp_query_graph.id, snmp_query_graph.name FROM snmp_query_graph WHERE snmp_query_graph.snmp_query_id = ? ORDER BY snmp_query_graph.name', array($snmp_query['id']));
                if (sizeof($data_query_graphs) == 1) {
                    echo "<input type='hidden' id='sgg_" . $snmp_query['id'] . "' name='sgg_" . $snmp_query['id'] . "' value='" . $data_query_graphs[0]['id'] . "'>\n";
                } elseif (sizeof($data_query_graphs) > 1) {
                    print "\t<table align='center' width='100%'>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td width='100%' valign='middle'>\n\t\t\t\t\t\t\t\t<img src='images/arrow.gif' align='absmiddle' alt=''>\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t<td style='white-space:nowrap;font-style: italic;'' align='right'>\n\t\t\t\t\t\t\t\tSelect a Graph Type to Create\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t<td align='right'>\n\t\t\t\t\t\t\t\t<select name='sgg_" . $snmp_query['id'] . "' id='sgg_" . $snmp_query['id'] . "' onChange='dqUpdateDeps(" . $snmp_query['id'] . ',' . (isset($column_counter) ? $column_counter : '') . ");'>\n\t\t\t\t\t\t\t\t\t";
                    html_create_list($data_query_graphs, 'name', 'id', '0');
                    print "\n\t\t\t\t\t\t\t\t</select>\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</table>\n";
                }
                print '<br>';
                $script .= 'dqUpdateDeps(' . $snmp_query['id'] . ',' . $num_visible_fields . ");\n";
            }
        }
    }
    if (strlen($script)) {
        $script .= "</script>\n";
        print $script;
    }
    form_hidden_box('save_component_graph', '1', '');
    if (!empty($_REQUEST['host_id'])) {
        form_hidden_box('host_id', $host['id'], '0');
        form_hidden_box('host_template_id', $host['host_template_id'], '0');
    }
    if (isset($_SERVER['HTTP_REFERER']) && !substr_count($_SERVER['HTTP_REFERER'], 'graphs_new')) {
        $_REQUEST['returnto'] = basename($_SERVER['HTTP_REFERER']);
    }
    load_current_session_value('returnto', 'sess_graphs_new_returnto', '');
    form_save_button($_REQUEST['returnto']);
}
Example #4
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 #5
0
function mactrack_site()
{
    global $site_actions, $config, $item_rows;
    mactrack_site_validate_req_vars();
    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');
    }
    html_start_box(__('MacTrack Site Filters'), '100%', '', '3', 'center', 'mactrack_sites.php?action=edit');
    mactrack_site_filter();
    html_end_box();
    $sql_where = '';
    $sites = mactrack_site_get_site_records($sql_where, $row_limit);
    if (get_request_var('detail') == 'false') {
        $total_rows = db_fetch_cell("SELECT\n\t\t\tCOUNT(mac_track_sites.site_id)\n\t\t\tFROM mac_track_sites\n\t\t\t{$sql_where}");
    } else {
        $total_rows = db_fetch_cell("SELECT count(*)\n\t\t\tFROM (mac_track_device_types\n\t\t\tRIGHT JOIN mac_track_devices ON (mac_track_device_types.device_type_id = mac_track_devices.device_type_id))\n\t\t\tRIGHT JOIN mac_track_sites ON (mac_track_devices.site_id = mac_track_sites.site_id)\n\t\t\t{$sql_where}\n\t\t\tGROUP BY mac_track_sites.site_name, mac_track_device_types.device_type_id");
    }
    if (get_request_var('detail') == 'false') {
        $nav = html_nav_bar('mactrack_sites.php?filter=' . get_request_var('filter'), MAX_DISPLAY_PAGES, get_filter_request_var('page'), $row_limit, $total_rows, 9, __('Sites'));
        print $nav;
        html_start_box('', '100%', '', '3', 'center', '');
        $display_text = array('site_name' => array(__('Site Name'), 'ASC'), 'total_devices' => array(__('Devices'), 'DESC'), 'total_ips' => array(__('Total IP\'s'), 'DESC'), 'total_user_ports' => array(__('User Ports'), 'DESC'), 'total_oper_ports' => array(__('User Ports Up'), 'DESC'), 'total_macs' => array(__('MACS Found'), 'DESC'), 'total_device_errors' => array(__('Device Errors'), 'DESC'));
        html_header_sort_checkbox($display_text, get_request_var('sort_column'), get_request_var('sort_direction'));
        $i = 0;
        if (sizeof($sites)) {
            foreach ($sites as $site) {
                form_alternate_row('line' . $site['site_id'], true);
                form_selectable_cell("<a class='linkEditMain' href='mactrack_sites.php?action=edit&site_id=" . $site['site_id'] . "'>" . (get_request_var('filter') != '' ? preg_replace('/(' . preg_quote(get_request_var('filter')) . ')/i', "<span class='filteredValue'>\\1</span>", $site['site_name']) : $site['site_name']) . '</a>', $site['site_id']);
                form_selectable_cell(number_format_i18n($site['total_devices']), $site['site_id']);
                form_selectable_cell(number_format_i18n($site['total_ips']), $site['site_id']);
                form_selectable_cell(number_format_i18n($site['total_user_ports']), $site['site_id']);
                form_selectable_cell(number_format_i18n($site['total_oper_ports']), $site['site_id']);
                form_selectable_cell(number_format_i18n($site['total_macs']), $site['site_id']);
                form_selectable_cell($site['total_device_errors'], $site['site_id']);
                form_checkbox_cell($site['site_name'], $site['site_id']);
                form_end_row();
            }
        } else {
            print '<tr><td><em>' . __('No MacTrack Sites') . '</em></td></tr>';
        }
        html_end_box(false);
        if (sizeof($sites)) {
            print $nav;
        }
    } else {
        $nav = html_nav_bar('mactrack_sites.php?filter=' . get_request_var('filter'), MAX_DISPLAY_PAGES, get_filter_request_var('page'), $row_limit, $total_rows, 10, __('Sites'));
        print $nav;
        html_start_box('', '100%', '', '3', 'center', '');
        $display_text = array('site_name' => array(__('Site Name'), 'ASC'), 'vendor' => array(__('Vendor'), 'ASC'), 'description' => array(__('Device Type'), 'DESC'), 'total_devices' => array(__('Total Devices'), 'DESC'), 'sum_ips_total' => array(__('Total IP\'s'), 'DESC'), 'sum_ports_total' => array(__('Total User Ports'), 'DESC'), 'sum_ports_active' => array(__('Total Oper Ports'), 'DESC'), 'sum_ports_trunk' => array(__('Total Trunks'), 'DESC'), 'sum_macs_active' => array(__('MACS Found'), 'DESC'));
        html_header_sort($display_text, get_request_var('sort_column'), get_request_var('sort_direction'));
        if (sizeof($sites)) {
            foreach ($sites as $site) {
                form_alternate_row();
                ?>
					<td width=200>
						<a class='linkEditMain' href='mactrack_sites.php?action=edit&site_id=<?php 
                print $site['site_id'];
                ?>
'><?php 
                print get_request_var('filter') != '' ? preg_replace('/(' . preg_quote(get_request_var('filter')) . ')/i', "<span class='filteredValue'>\\1</span>", $site['site_name']) : $site['site_name'];
                ?>
</a>
					</td>
					<td><?php 
                print get_request_var('filter') != '' ? preg_replace('/(' . preg_quote(get_request_var('filter')) . ')/i', "<span class='filteredValue'>\\1</span>", $site['vendor']) : $site['vendor'];
                ?>
</td>
					<td><?php 
                print get_request_var('filter') != '' ? preg_replace('/(' . preg_quote(get_request_var('filter')) . ')/i', "<span class='filteredValue'>\\1</span>", $site['description']) : $site['description'];
                ?>
</td>
					<td><?php 
                print number_format_i18n($site['total_devices']);
                ?>
</td>
					<td><?php 
                print number_format_i18n($site['sum_ips_total']);
                ?>
</td>
					<td><?php 
                print number_format_i18n($site['sum_ports_total']);
                ?>
</td>
					<td><?php 
                print number_format_i18n($site['sum_ports_active']);
                ?>
</td>
					<td><?php 
                print number_format_i18n($site['sum_ports_trunk']);
                ?>
</td>
					<td><?php 
                print number_format_i18n($site['sum_macs_active']);
                ?>
</td>
				</tr>
				<?php 
            }
        } else {
            print '<tr><td><em>' . __('No MacTrack Sites') . '</em></td></tr>';
        }
        html_end_box(false);
        if (sizeof($sites)) {
            print $nav;
        }
    }
    /* draw the dropdown containing a list of available actions for this form */
    if (get_request_var('detail') == 'false') {
        draw_actions_dropdown($site_actions);
    }
}
Example #6
0
function snmpagent_utilities_run_eventlog()
{
    global $item_rows;
    define("MAX_DISPLAY_PAGES", 21);
    $severity_levels = array(SNMPAGENT_EVENT_SEVERITY_LOW => 'LOW', SNMPAGENT_EVENT_SEVERITY_MEDIUM => 'MEDIUM', SNMPAGENT_EVENT_SEVERITY_HIGH => 'HIGH', SNMPAGENT_EVENT_SEVERITY_CRITICAL => 'CRITICAL');
    $severity_colors = array(SNMPAGENT_EVENT_SEVERITY_LOW => '#00FF00', SNMPAGENT_EVENT_SEVERITY_MEDIUM => '#FFFF00', SNMPAGENT_EVENT_SEVERITY_HIGH => '#FF0000', SNMPAGENT_EVENT_SEVERITY_CRITICAL => '#FF00FF');
    $receivers = db_fetch_assoc("SELECT DISTINCT manager_id, hostname FROM snmpagent_notifications_log INNER JOIN snmpagent_managers ON snmpagent_managers.id = snmpagent_notifications_log.manager_id");
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_request("receiver"));
    if (!in_array(get_request_var_request("severity"), array_keys($severity_levels)) && get_request_var_request("severity") != '-1' && get_request_var_request("severity") != "") {
        die_html_input_error();
    }
    input_validate_input_number(get_request_var_request("page"));
    input_validate_input_number(get_request_var_request("rows"));
    /* ==================================================== */
    /* clean up search filter */
    if (isset($_REQUEST["filter"])) {
        $_REQUEST["filter"] = sanitize_search_string(get_request_var("filter"));
    }
    if (isset($_REQUEST["purge_x"])) {
        db_execute("TRUNCATE table snmpagent_notifications_log;");
        /* reset filters */
        $_REQUEST["clear_x"] = true;
    }
    /* if the user pushed the 'clear' button */
    if (isset($_REQUEST["clear_x"])) {
        kill_session_var("sess_snmpagent__logs_receiver");
        kill_session_var("sess_snmpagent__logs_severity");
        kill_session_var("sess_snmpagent__logs_current_page");
        kill_session_var("sess_snmpagent__logs_filter");
        kill_session_var("sess_default_rows");
        unset($_REQUEST["receiver"]);
        unset($_REQUEST["severity"]);
        unset($_REQUEST["page"]);
        unset($_REQUEST["filter"]);
        unset($_REQUEST["rows"]);
    }
    /* reset the current page if the user changed the severity */
    if (isset($_SESSION["sess_snmpagent__logs_severity"]) && get_request_var_request("severity") != $_SESSION["sess_snmpagent__logs_severity"]) {
        kill_session_var("sess_snmpagent__logs_current_page");
        unset($_REQUEST["page"]);
    }
    /* remember these search fields in session vars so we don't have to keep passing them around */
    load_current_session_value("receiver", "sess_snmpagent__logs_receiver", "-1");
    load_current_session_value("page", "sess_snmpagent__logs_current_page", "1");
    load_current_session_value("severity", "sess_snmpagent__logs_severity", "-1");
    load_current_session_value("filter", "sess_snmpagent__logs_filter", "");
    load_current_session_value('rows', 'sess_default_rows', read_config_option('num_rows_table'));
    /* if the number of rows is -1, set it to the default */
    if ($_REQUEST["rows"] == -1) {
        $_REQUEST["rows"] = read_config_option("num_rows_table");
    }
    $_REQUEST['page_referrer'] = 'view_snmpagent_events';
    load_current_session_value('page_referrer', 'page_referrer', 'view_snmpagent_events');
    ?>
	<script type="text/javascript">
	<!--

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

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

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

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

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

	-->
	</script>

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

	<script language="javascript" type="text/javascript" >
		$('.tooltip').tooltip({
			track: true,
			position: { collision: "flipfit" },
			content: function() { return $(this).attr('title'); }
		});
	</script>
	<?php 
}
Example #7
0
function ds()
{
    global $ds_actions, $item_rows;
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_request("ds_rows"));
    input_validate_input_number(get_request_var_request("host_id"));
    input_validate_input_number(get_request_var_request("template_id"));
    input_validate_input_number(get_request_var_request("method_id"));
    input_validate_input_number(get_request_var_request("page"));
    /* ==================================================== */
    /* clean up search string */
    if (isset($_REQUEST["filter"])) {
        $_REQUEST["filter"] = sanitize_search_string(get_request_var("filter"));
    }
    /* clean up sort_column string */
    if (isset($_REQUEST["sort_column"])) {
        $_REQUEST["sort_column"] = sanitize_search_string(get_request_var("sort_column"));
    }
    /* clean up sort_direction string */
    if (isset($_REQUEST["sort_direction"])) {
        $_REQUEST["sort_direction"] = sanitize_search_string(get_request_var("sort_direction"));
    }
    /* if the user pushed the 'clear' button */
    if (isset($_REQUEST["clear_x"])) {
        kill_session_var("sess_ds_current_page");
        kill_session_var("sess_ds_filter");
        kill_session_var("sess_ds_sort_column");
        kill_session_var("sess_ds_sort_direction");
        kill_session_var("sess_ds_rows");
        kill_session_var("sess_ds_host_id");
        kill_session_var("sess_ds_template_id");
        kill_session_var("sess_ds_method_id");
        unset($_REQUEST["page"]);
        unset($_REQUEST["filter"]);
        unset($_REQUEST["sort_column"]);
        unset($_REQUEST["sort_direction"]);
        unset($_REQUEST["ds_rows"]);
        unset($_REQUEST["host_id"]);
        unset($_REQUEST["template_id"]);
        unset($_REQUEST["method_id"]);
    }
    /* remember these search fields in session vars so we don't have to keep passing them around */
    load_current_session_value("page", "sess_ds_current_page", "1");
    load_current_session_value("filter", "sess_ds_filter", "");
    load_current_session_value("sort_column", "sess_ds_sort_column", "name_cache");
    load_current_session_value("sort_direction", "sess_ds_sort_direction", "ASC");
    load_current_session_value("ds_rows", "sess_ds_rows", read_config_option("num_rows_data_source"));
    load_current_session_value("host_id", "sess_ds_host_id", "-1");
    load_current_session_value("template_id", "sess_ds_template_id", "-1");
    load_current_session_value("method_id", "sess_ds_method_id", "-1");
    $host = db_fetch_row("select hostname from host where id=" . get_request_var_request("host_id"));
    /* if the number of rows is -1, set it to the default */
    if (get_request_var_request("ds_rows") == -1) {
        $_REQUEST["ds_rows"] = read_config_option("num_rows_data_source");
    }
    ?>
	<script type="text/javascript">
	<!--

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

	-->
	</script>
	<?php 
    html_start_box("<strong>Data Sources</strong> [host: " . (empty($host["hostname"]) ? "No Host" : htmlspecialchars($host["hostname"])) . "]", "100%", "", "3", "center", "data_sources.php?action=ds_edit&host_id=" . get_request_var_request("host_id"));
    ?>
	<tr class='even noprint'>
		<td>
		<form name="form_data_sources" action="data_sources.php">
			<table cellpadding="1" cellspacing="0">
				<tr>
					<td width="50">
						Host:&nbsp;
					</td>
					<td>
						<select name="host_id" onChange="applyDSFilterChange(document.form_data_sources)">
							<option value="-1"<?php 
    if (get_request_var_request("host_id") == "-1") {
        ?>
 selected<?php 
    }
    ?>
>Any</option>
							<option value="0"<?php 
    if (get_request_var_request("host_id") == "0") {
        ?>
 selected<?php 
    }
    ?>
>None</option>
							<?php 
    $hosts = db_fetch_assoc("select id,CONCAT_WS('',description,' (',hostname,')') as name from host order by description,hostname");
    if (sizeof($hosts) > 0) {
        foreach ($hosts as $host) {
            print "<option value='" . $host["id"] . "'";
            if (get_request_var_request("host_id") == $host["id"]) {
                print " selected";
            }
            print ">" . title_trim(htmlspecialchars($host["name"]), 40) . "</option>\n";
        }
    }
    ?>

						</select>
					</td>
					<td width="50">
						&nbsp;Template:&nbsp;
					</td>
					<td width="1">
						<select name="template_id" onChange="applyDSFilterChange(document.form_data_sources)">
							<option value="-1"<?php 
    if (get_request_var_request("template_id") == "-1") {
        ?>
 selected<?php 
    }
    ?>
>Any</option>
							<option value="0"<?php 
    if (get_request_var_request("template_id") == "0") {
        ?>
 selected<?php 
    }
    ?>
>None</option>
							<?php 
    $templates = db_fetch_assoc("SELECT DISTINCT data_template.id, data_template.name\n\t\t\t\t\t\t\t\tFROM data_template\n\t\t\t\t\t\t\t\tINNER JOIN data_template_data\n\t\t\t\t\t\t\t\tON data_template.id=data_template_data.data_template_id\n\t\t\t\t\t\t\t\tWHERE data_template_data.local_data_id>0\n\t\t\t\t\t\t\t\tORDER BY data_template.name");
    if (sizeof($templates) > 0) {
        foreach ($templates as $template) {
            print "<option value='" . $template["id"] . "'";
            if (get_request_var_request("template_id") == $template["id"]) {
                print " selected";
            }
            print ">" . title_trim(htmlspecialchars($template["name"]), 40) . "</option>\n";
        }
    }
    ?>

						</select>
					</td>
					<td nowrap style='white-space: nowrap;'>
						&nbsp;<input type="submit" value="Go" title="Set/Refresh Filters">
						<input type="submit" name="clear_x" value="Clear" title="Clear Filters">
					</td>
				</tr>
				<tr>
					<td width="50">
						Method:&nbsp;
					</td>
					<td width="1">
						<select name="method_id" onChange="applyDSFilterChange(document.form_data_sources)">
							<option value="-1"<?php 
    if (get_request_var_request("method_id") == "-1") {
        ?>
 selected<?php 
    }
    ?>
>Any</option>
							<option value="0"<?php 
    if (get_request_var_request("method_id") == "0") {
        ?>
 selected<?php 
    }
    ?>
>None</option>
							<?php 
    $methods = db_fetch_assoc("SELECT DISTINCT data_input.id, data_input.name\n\t\t\t\t\t\t\t\tFROM data_input\n\t\t\t\t\t\t\t\tINNER JOIN data_template_data\n\t\t\t\t\t\t\t\tON data_input.id=data_template_data.data_input_id\n\t\t\t\t\t\t\t\tWHERE data_template_data.local_data_id>0\n\t\t\t\t\t\t\t\tORDER BY data_input.name");
    if (sizeof($methods) > 0) {
        foreach ($methods as $method) {
            print "<option value='" . $method["id"] . "'";
            if (get_request_var_request("method_id") == $method["id"]) {
                print " selected";
            }
            print ">" . title_trim(htmlspecialchars($method["name"]), 40) . "</option>\n";
        }
    }
    ?>
						</select>
					</td>
					<td nowrap style='white-space: nowrap;' width="50">
						&nbsp;Rows per Page:&nbsp;
					</td>
					<td width="1">
						<select name="ds_rows" onChange="applyDSFilterChange(document.form_data_sources)">
							<option value="-1"<?php 
    if (get_request_var_request("ds_rows") == "-1") {
        ?>
 selected<?php 
    }
    ?>
>Default</option>
							<?php 
    if (sizeof($item_rows) > 0) {
        foreach ($item_rows as $key => $value) {
            print "<option value='" . $key . "'";
            if (get_request_var_request("ds_rows") == $key) {
                print " selected";
            }
            print ">" . htmlspecialchars($value) . "</option>\n";
        }
    }
    ?>
						</select>
					</td>
				</tr>
			</table>
			<table cellpadding="1" cellspacing="0">
				<tr>
					<td width="50">
						Search:&nbsp;
					</td>
					<td width="1">
						<input type="text" name="filter" size="40" value="<?php 
    print htmlspecialchars(get_request_var_request("filter"));
    ?>
">
					</td>
				</tr>
			</table>
			<input type='hidden' name='page' value='1'>
		</form>
		</td>
	</tr>
	<?php 
    html_end_box();
    /* form the 'where' clause for our main sql query */
    if (strlen(get_request_var_request("filter"))) {
        $sql_where1 = "AND (data_template_data.name_cache like '%%" . get_request_var_request("filter") . "%%'" . " OR data_template_data.local_data_id like '%%" . get_request_var_request("filter") . "%%'" . " OR data_template.name like '%%" . get_request_var_request("filter") . "%%'" . " OR data_input.name like '%%" . get_request_var_request("filter") . "%%')";
        $sql_where2 = "AND (data_template_data.name_cache like '%%" . get_request_var_request("filter") . "%%'" . " OR data_template.name like '%%" . get_request_var_request("filter") . "%%')";
    } else {
        $sql_where1 = "";
        $sql_where2 = "";
    }
    if (get_request_var_request("host_id") == "-1") {
        /* Show all items */
    } elseif (get_request_var_request("host_id") == "0") {
        $sql_where1 .= " AND data_local.host_id=0";
        $sql_where2 .= " AND data_local.host_id=0";
    } elseif (!empty($_REQUEST["host_id"])) {
        $sql_where1 .= " AND data_local.host_id=" . get_request_var_request("host_id");
        $sql_where2 .= " AND data_local.host_id=" . get_request_var_request("host_id");
    }
    if (get_request_var_request("template_id") == "-1") {
        /* Show all items */
    } elseif (get_request_var_request("template_id") == "0") {
        $sql_where1 .= " AND data_template_data.data_template_id=0";
        $sql_where2 .= " AND data_template_data.data_template_id=0";
    } elseif (!empty($_REQUEST["host_id"])) {
        $sql_where1 .= " AND data_template_data.data_template_id=" . get_request_var_request("template_id");
        $sql_where2 .= " AND data_template_data.data_template_id=" . get_request_var_request("template_id");
    }
    if (get_request_var_request("method_id") == "-1") {
        /* Show all items */
    } elseif (get_request_var_request("method_id") == "0") {
        $sql_where1 .= " AND data_template_data.data_input_id=0";
        $sql_where2 .= " AND data_template_data.data_input_id=0";
    } elseif (!empty($_REQUEST["method_id"])) {
        $sql_where1 .= " AND data_template_data.data_input_id=" . get_request_var_request("method_id");
        $sql_where2 .= " AND data_template_data.data_input_id=" . get_request_var_request("method_id");
    }
    $total_rows = sizeof(db_fetch_assoc("SELECT\n\t\tdata_local.id\n\t\tFROM (data_local,data_template_data)\n\t\tLEFT JOIN data_input\n\t\tON (data_input.id=data_template_data.data_input_id)\n\t\tLEFT JOIN data_template\n\t\tON (data_local.data_template_id=data_template.id)\n\t\tWHERE data_local.id=data_template_data.local_data_id\n\t\t{$sql_where1}"));
    $poller_intervals = array_rekey(db_fetch_assoc("SELECT data_template_data.local_data_id AS id,\n\t\tMin(data_template_data.rrd_step*rra.steps) AS poller_interval\n\t\tFROM data_template\n\t\tINNER JOIN (data_local\n\t\tINNER JOIN ((data_template_data_rra\n\t\tINNER JOIN data_template_data ON data_template_data_rra.data_template_data_id=data_template_data.id)\n\t\tINNER JOIN rra ON data_template_data_rra.rra_id = rra.id) ON data_local.id = data_template_data.local_data_id) ON data_template.id = data_template_data.data_template_id\n\t\t{$sql_where2}\n\t\tGROUP BY data_template_data.local_data_id"), "id", "poller_interval");
    $data_sources = db_fetch_assoc("SELECT\n\t\tdata_template_data.local_data_id,\n\t\tdata_template_data.name_cache,\n\t\tdata_template_data.active,\n\t\tdata_input.name as data_input_name,\n\t\tdata_template.name as data_template_name,\n\t\tdata_local.host_id\n\t\tFROM (data_local,data_template_data)\n\t\tLEFT JOIN data_input\n\t\tON (data_input.id=data_template_data.data_input_id)\n\t\tLEFT JOIN data_template\n\t\tON (data_local.data_template_id=data_template.id)\n\t\tWHERE data_local.id=data_template_data.local_data_id\n\t\t{$sql_where1}\n\t\tORDER BY " . get_request_var_request("sort_column") . " " . get_request_var_request("sort_direction") . " LIMIT " . get_request_var_request("ds_rows") * (get_request_var_request("page") - 1) . "," . get_request_var_request("ds_rows"));
    print "<form name='chk' method='post' action='data_sources.php'>\n";
    html_start_box("", "100%", "", "3", "center", "");
    $nav = html_nav_bar("data_sources.php?filter=" . get_request_var_request("filter") . "&host_id=" . get_request_var_request("host_id"), MAX_DISPLAY_PAGES, get_request_var_request("page"), get_request_var_request("ds_rows"), $total_rows, 7);
    print $nav;
    $display_text = array("name_cache" => array("Name", "ASC"), "local_data_id" => array("ID", "ASC"), "data_input_name" => array("Data Input Method", "ASC"), "nosort" => array("Poller Interval", "ASC"), "active" => array("Active", "ASC"), "data_template_name" => array("Template Name", "ASC"));
    html_header_sort_checkbox($display_text, get_request_var_request("sort_column"), get_request_var_request("sort_direction"), false);
    $i = 0;
    if (sizeof($data_sources) > 0) {
        foreach ($data_sources as $data_source) {
            $data_source["data_template_name"] = htmlspecialchars($data_source["data_template_name"]);
            $data_name_cache = title_trim(htmlspecialchars($data_source["name_cache"]), read_config_option("max_title_data_source"));
            if (trim(get_request_var_request("filter") != "")) {
                $data_name_cache = preg_replace("/(" . preg_quote(get_request_var_request("filter"), "/") . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", $data_name_cache);
            }
            /* keep copy of data source for comparison */
            $data_source_orig = $data_source;
            $data_source = api_plugin_hook_function('data_sources_table', $data_source);
            /* we're escaping strings here, so no need to escape them on form_selectable_cell */
            if (empty($data_source["data_template_name"])) {
                $data_template_name = "<em>None</em>";
            } elseif ($data_source_orig["data_template_name"] != $data_source["data_template_name"]) {
                /* was changed by plugin, plugin has to take care for html-escaping */
                $data_template_name = empty($data_source["data_template_name"]) ? "<em>None</em>" : $data_source["data_template_name"];
            } elseif (trim(get_request_var_request("filter") != "")) {
                /* we take care of html-escaping */
                $data_template_name = preg_replace("/(" . preg_quote(get_request_var_request("filter"), "/") . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", htmlspecialchars($data_source['data_template_name']));
            } else {
                $data_template_name = htmlspecialchars($data_source["data_template_name"]);
            }
            if (empty($data_source["data_input_name"])) {
                $data_input_name = "<em>None</em>";
            } elseif ($data_source_orig["data_input_name"] != $data_source["data_input_name"]) {
                /* was changed by plugin, plugin has to take care for html-escaping */
                $data_input_name = empty($data_source["data_input_name"]) ? "<em>None</em>" : $data_source["data_input_name"];
            } elseif (trim(get_request_var_request("filter") != "")) {
                /* we take care of html-escaping */
                $data_input_name = preg_replace("/(" . preg_quote(get_request_var_request("filter"), "/") . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", htmlspecialchars($data_source['data_input_name']));
            } else {
                $data_input_name = htmlspecialchars($data_source["data_input_name"]);
            }
            $poller_interval = isset($poller_intervals[$data_source["local_data_id"]]) ? $poller_intervals[$data_source["local_data_id"]] : 0;
            form_alternate_row('line' . $data_source["local_data_id"], true);
            form_selectable_cell("<a class='linkEditMain' href='" . htmlspecialchars("data_sources.php?action=ds_edit&id=" . $data_source["local_data_id"]) . "' title='" . htmlspecialchars($data_source["name_cache"], ENT_QUOTES) . "'>" . (get_request_var_request("filter") != "" ? preg_replace("/(" . preg_quote(get_request_var_request("filter"), "/") . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", title_trim(htmlspecialchars($data_source["name_cache"]), read_config_option("max_title_data_source"))) : title_trim(htmlspecialchars($data_source["name_cache"]), read_config_option("max_title_data_source"))) . "</a>", $data_source["local_data_id"]);
            form_selectable_cell($data_source['local_data_id'], $data_source['local_data_id']);
            form_selectable_cell($data_input_name, $data_source["local_data_id"]);
            form_selectable_cell(get_poller_interval($poller_interval), $data_source["local_data_id"]);
            form_selectable_cell($data_source['active'] == "on" ? "Yes" : "No", $data_source["local_data_id"]);
            form_selectable_cell($data_template_name, $data_source["local_data_id"]);
            form_checkbox_cell($data_source["name_cache"], $data_source["local_data_id"]);
            form_end_row();
        }
        /* put the nav bar on the bottom as well */
        print $nav;
    } else {
        print "<tr><td><em>No Data Sources</em></td></tr>";
    }
    html_end_box(false);
    /* draw the dropdown containing a list of available actions for this form */
    draw_actions_dropdown($ds_actions);
    print "</form>\n";
}
Example #8
0
function export()
{
    global $export_types;
    /* 'graph_template' should be the default */
    if (!isset($_REQUEST["export_type"])) {
        $_REQUEST["export_type"] = "graph_template";
    }
    html_start_box("<strong>Export Templates</strong>", "100%", "", "3", "center", "");
    ?>
	<tr>
		<td>
			<form name="form_graph_id" action="templates_export.php">
			<table align='left' cellpadding='3' cellspacing='0'>
				<tr>
					<td style='font-size:1.2em;'>What would you like to export?</td>
					<td>
						<select name="cbo_graph_id" onChange="window.location=document.form_graph_id.cbo_graph_id.options[document.form_graph_id.cbo_graph_id.selectedIndex].value">
							<?php 
    while (list($key, $array) = each($export_types)) {
        print "<option value='templates_export.php?export_type=" . htmlspecialchars($key, ENT_QUOTES) . "'";
        if ($_REQUEST["export_type"] == $key) {
            print " selected";
        }
        print ">" . $array["name"] . "</option>\n";
    }
    ?>
						</select>
					</td>
				</tr>
			</table>
			</form>
		</td>
	</tr>
	<?php 
    html_end_box();
    print "<form method='post' action='templates_export.php'>\n";
    html_start_box("<strong>Available Templates</strong> [" . $export_types[$_REQUEST["export_type"]]["name"] . "]", "100%", "", "3", "center", "");
    form_alternate_row();
    ?>
		<td width="50%">
			<font class="textEditTitle"><?php 
    print $export_types[$_REQUEST["export_type"]]["name"];
    ?>
 to Export</font><br>
			Choose the exact item to export to XML.
		</td>
		<td>
			<?php 
    form_dropdown("export_item_id", db_fetch_assoc($export_types[$_REQUEST["export_type"]]["dropdown_sql"]), "name", "id", "", "", "0");
    ?>
		</td>
	</tr>

	<?php 
    form_alternate_row();
    ?>
		<td width="50%">
			<font class="textEditTitle">Include Dependencies</font><br>
			Some templates rely on other items in Cacti to function properly. It is highly recommended that you select
			this box or the resulting import may fail.
		</td>
		<td>
			<?php 
    form_checkbox("include_deps", "on", "Include Dependencies", "on", "", true);
    ?>
		</td>
	</tr>

	<?php 
    form_alternate_row();
    ?>
		<td width="50%">
			<font class="textEditTitle">Output Format</font><br>
			Choose the format to output the resulting XML file in.
		</td>
		<td>
			<?php 
    form_radio_button("output_format", "3", "1", "Output to the Browser (within Cacti)", "1", true);
    print "<br>";
    form_radio_button("output_format", "3", "2", "Output to the Browser (raw XML)", "1", true);
    print "<br>";
    form_radio_button("output_format", "3", "3", "Save File Locally", "1", true);
    form_hidden_box("export_type", $_REQUEST["export_type"], "");
    form_hidden_box("save_component_export", "1", "");
    ?>
		</td>
	</tr>
	<?php 
    html_end_box();
    form_save_button("", "export");
}
Example #9
0
function domains()
{
    global $domain_types, $actions, $item_rows;
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_request('page'));
    input_validate_input_number(get_request_var_request('rows'));
    /* ==================================================== */
    /* clean up 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_domains_filter');
        kill_session_var('sess_domains_rows');
        kill_session_var('sess_domains_sort_column');
        kill_session_var('sess_domains_sort_direction');
        unset($_REQUEST['page']);
        unset($_REQUEST['rows']);
        unset($_REQUEST['filter']);
        unset($_REQUEST['sort_column']);
        unset($_REQUEST['sort_direction']);
        $_REQUEST['page'] = 1;
    }
    /* remember these search fields in session vars so we don't have to keep passing them around */
    load_current_session_value('filter', 'sess_domains_filter', '');
    load_current_session_value('rows', 'sess_table_rows', read_config_option('num_rows_table'));
    load_current_session_value('sort_column', 'sess_domains_sort_column', 'domain_name');
    load_current_session_value('sort_direction', 'sess_domains_sort_direction', 'ASC');
    load_current_session_value('page', 'sess_domains_current_page', '1');
    html_start_box('<strong>User Domains</strong>', '100%', '', '3', 'center', 'user_domains.php?action=edit');
    ?>
	<tr class='even' class='noprint'>
		<td class='noprint'>
		<form id='form_domains' method='get' action='user_domains.php'>
			<table cellpadding='2' cellspacing='0' border='0'>
				<tr class='noprint'>
					<td width='50'>
						Search
					</td>
					<td>
						<input id='filter' type='text' name='filter' size='25' value='<?php 
    print get_request_var_request('filter');
    ?>
'>
					</td>
					<td>
						Domains
					</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 id='refresh' type='button' value='Go' title='Set/Refresh Filters'>
					</td>
					<td>
						<input id='clear' type='button' name='clear_x' value='Clear' title='Clear Filters'>
					</td>
				</tr>
			</table>
			<input type='hidden' name='page' value='<?php 
    print $_REQUEST['page'];
    ?>
'>
		</form>
		<script type='text/javascript'>
		function applyFilter() {
			strURL = 'user_domains.php?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 = 'user_domains.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_domains').submit(function(event) {
				event.preventDefault();
				applyFilter();
			});
		});
		</script>
		</td>
	</tr>
	<?php 
    html_end_box();
    /* print checkbox form for validation */
    print "<form name='chk' method='post' action='user_domains.php'>\n";
    html_start_box('', '100%', '', '3', 'center', '');
    /* form the 'where' clause for our main sql query */
    if ($_REQUEST['filter'] != '') {
        $sql_where = "WHERE (domain_name LIKE '%%" . get_request_var_request('filter') . "%%') ||\n\t\t\t(type LIKE '%%" . get_request_var_request('filter') . "%%')";
    } else {
        $sql_where = '';
    }
    $total_rows = db_fetch_cell("SELECT\n\t\tcount(*)\n\t\tFROM user_domains\n\t\t{$sql_where}");
    $domains = db_fetch_assoc("SELECT *\n\t\tFROM user_domains\n\t\t{$sql_where}\n\t\tORDER BY " . get_request_var_request('sort_column') . ' ' . get_request_var_request('sort_direction') . '
		LIMIT ' . get_request_var_request('rows') * (get_request_var_request('page') - 1) . ',' . get_request_var_request('rows'));
    $nav = html_nav_bar('user_user_domains.php?filter=' . get_request_var_request('filter'), MAX_DISPLAY_PAGES, get_request_var_request('page'), get_request_var_request('rows'), $total_rows, 6, 'User Domains', 'page', 'main');
    print $nav;
    $display_text = array('domain_name' => array('Domain Name', 'ASC'), 'type' => array('Domain Type', 'ASC'), 'defdomain' => array('Default', 'ASC'), 'user_id' => array('Effective User', 'ASC'), 'enabled' => array('Enabled', 'ASC'));
    html_header_sort_checkbox($display_text, get_request_var_request('sort_column'), get_request_var_request('sort_direction'), false);
    $i = 0;
    if (sizeof($domains) > 0) {
        foreach ($domains as $domain) {
            /* hide system types */
            form_alternate_row('line' . $domain['domain_id'], true);
            form_selectable_cell("<a class='linkEditMain' href='" . htmlspecialchars('user_domains.php?action=edit&domain_id=' . $domain['domain_id']) . "'>" . (strlen(get_request_var_request('filter')) ? eregi_replace('(' . preg_quote(get_request_var_request('filter')) . ')', "<span class='filteredValue>\\1</span>", $domain['domain_name']) : $domain['domain_name']) . '</a>', $domain['domain_id']);
            form_selectable_cell($domain_types[$domain['type']], $domain['domain_id']);
            form_selectable_cell($domain['defdomain'] == '0' ? '--' : 'Yes', $domain['domain_id']);
            form_selectable_cell($domain['user_id'] == '0' ? 'None Selected' : db_fetch_cell_prepared('SELECT username FROM user_auth WHERE id = ?', array($domain['user_id'])), $domain['domain_id']);
            form_selectable_cell($domain['enabled'] == 'on' ? 'Yes' : 'No', $domain['domain_id']);
            form_checkbox_cell($domain['domain_name'], $domain['domain_id']);
            form_end_row();
        }
        print $nav;
    } else {
        print '<tr><td><em>No User Domains Defined</em></td></tr>';
    }
    html_end_box(false);
    /* draw the dropdown containing a list of available actions for this form */
    draw_actions_dropdown($actions);
    print "</form>\n";
}
function mactrack_display_run_status()
{
    global $config, $refresh_interval, $mactrack_poller_frequencies;
    $seconds_offset = read_config_option('mt_collection_timing', TRUE);
    if ($seconds_offset != 'disabled') {
        $seconds_offset = $seconds_offset * 60;
        /* find out if it's time to collect device information */
        $base_start_time = read_config_option('mt_base_time', TRUE);
        $database_maint_time = read_config_option('mt_maint_time', TRUE);
        $last_run_time = read_config_option('mt_last_run_time', TRUE);
        $last_db_maint_time = read_config_option('mt_last_db_maint_time', TRUE);
        $previous_base_start_time = read_config_option('mt_prev_base_time', TRUE);
        $previous_db_maint_time = read_config_option('mt_prev_db_maint_time', TRUE);
        /* see if the user desires a new start time */
        if (!empty($previous_base_start_time)) {
            if ($base_start_time != $previous_base_start_time) {
                unset($last_run_time);
            }
        }
        /* see if the user desires a new db maintenance time */
        if (!empty($previous_db_maint_time)) {
            if ($database_maint_time != $previous_db_maint_time) {
                unset($last_db_maint_time);
            }
        }
        /* determine the next start time */
        $current_time = strtotime('now');
        if (empty($last_run_time)) {
            $collection_never_completed = TRUE;
            if ($current_time > strtotime($base_start_time)) {
                /* if timer expired within a polling interval, then poll */
                if ($current_time - 300 < strtotime($base_start_time)) {
                    $next_run_time = strtotime(date('Y-m-d') . ' ' . $base_start_time);
                } else {
                    $next_run_time = strtotime(date('Y-m-d') . ' ' . $base_start_time) + 3600 * 24;
                }
            } else {
                $next_run_time = strtotime(date('Y-m-d') . ' ' . $base_start_time);
            }
        } else {
            $collection_never_completed = FALSE;
            $next_run_time = $last_run_time + $seconds_offset;
        }
        if (empty($last_db_maint_time)) {
            if (strtotime($base_start_time) < $current_time) {
                $next_db_maint_time = strtotime(date('Y-m-d') . ' ' . $database_maint_time) + 3600 * 24;
            } else {
                $next_db_maint_time = strtotime(date('Y-m-d') . ' ' . $database_maint_time);
            }
        } else {
            $next_db_maint_time = $last_db_maint_time + 24 * 3600;
        }
        $time_till_next_run = $next_run_time - $current_time;
        $time_till_next_db_maint = $next_db_maint_time - $current_time;
    }
    html_start_box(__('MacTrack Process Status'), '100%', '', '1', 'center', '');
    ?>
	<script type='text/javascript'>
	function applyFilter() {
		strURL = 'mactrack_utilities.php?action=mactrack_proc_status&refresh='+$('#refresh').val();
		loadPageNoHeader(strURL);
	}

	$(function() {
		$('#refresh').click(function() {
			applyFilter();
		});
	});
	</script>
	<tr class='even'>
		<form name='form_mactrack_utilities_stats' method='post'>
		<td>
			<table class='filterTable'>
				<tr>
					<td>
						<?php 
    print __('Refresh');
    ?>
					</td>
					<td>
						<select id='refresh' onChange='applyFilter()'>
						<?php 
    foreach ($refresh_interval as $key => $interval) {
        print '<option value="' . $key . '"';
        if (get_request_var('refresh') == $key) {
            print ' selected';
        }
        print '>' . $interval . '</option>';
    }
    ?>
					</td>
					<td>
						<input type='button' value='<?php 
    print __('Refresh');
    ?>
' id='refresh'>
					</td>
				</tr>
			</table>
		</td>
		</form>
	</tr>
	<?php 
    html_end_box(TRUE);
    html_start_box('', '100%', '', '1', 'center', '');
    /* get information on running processes */
    $running_processes = db_fetch_assoc('SELECT
		mac_track_processes.process_id,
		mac_track_devices.device_name,
		mac_track_processes.device_id,
		mac_track_processes.start_date
		FROM mac_track_devices
		INNER JOIN mac_track_processes 
		ON mac_track_devices.device_id = mac_track_processes.device_id
		WHERE mac_track_processes.device_id != 0');
    $resolver_running = db_fetch_cell('SELECT COUNT(*) FROM mac_track_processes WHERE device_id=0');
    $total_processes = sizeof($running_processes);
    $run_status = db_fetch_assoc("SELECT last_rundate,\n\t\tCOUNT(last_rundate) AS devices\n\t\tFROM mac_track_devices\n\t\tWHERE disabled = ''\n\t\tGROUP BY last_rundate\n\t\tORDER BY last_rundate DESC");
    $total_devices = db_fetch_cell('SELECT count(*) FROM mac_track_devices');
    $disabled_devices = db_fetch_cell('SELECT count(*) FROM mac_track_devices');
    html_header(array(__('Current Process Status')), 2);
    form_alternate_row();
    print '<td>' . __('The MacTrack Poller is:') . '</td><td>' . ($total_processes > 0 ? __('RUNNING') : ($seconds_offset == 'disabled' ? __('DISABLED') : __('IDLE'))) . '</td>';
    if ($total_processes > 0) {
        form_alternate_row();
        print '<td>' . __('Running Processes:') . '</td><td>' . $total_processes . '</td>';
    }
    form_alternate_row();
    print '<td width=200>' . __('Last Time Poller Started:') . '</td><td>' . read_config_option('mt_scan_date', TRUE) . '</td>';
    form_alternate_row();
    print '<td width=200>' . __('Poller Frequency:') . '</td><td>' . ($seconds_offset == 'disabled' ? __('N/A') : $mactrack_poller_frequencies[$seconds_offset / 60]) . '</td>';
    form_alternate_row();
    print '<td width=200>' . __('Approx. Next Runtime:') . '</td><td>' . (empty($next_run_time) ? __('N/A') : date('Y-m-d G:i:s', $next_run_time)) . '</td>';
    form_alternate_row();
    print '<td width=200>' . __('Approx. Next DB Maintenance:') . '</td><td>' . (empty($next_db_maint_time) ? __('N/A') : date('Y-m-d G:i:s', $next_db_maint_time)) . '</td>';
    html_header(array(__('Run Time Details')), 2);
    form_alternate_row();
    print '<td width=200>' . __('Last Poller Runtime:') . '</td><td>' . read_config_option('stats_mactrack', TRUE) . '</td>';
    form_alternate_row();
    print '<td width=200>' . __('Last Poller Maintenence Runtime:') . '</td><td>' . read_config_option('stats_mactrack_maint', TRUE) . '</td>';
    form_alternate_row();
    print '<td width=200>' . __('Maximum Concurrent Processes:') . '</td><td> ' . read_config_option('mt_processes', TRUE) . __('processes') . '</td>';
    form_alternate_row();
    print '<td width=200>' . __('Maximum Per Device Scan Time:') . '</td><td> ' . read_config_option('mt_script_runtime', TRUE) . __('minutes') . '</td>';
    html_header(array(__('DNS Configuration Information')), 2);
    form_alternate_row();
    print '<td width=200>' . __('Reverse DNS Resolution is') . '</td><td>' . (read_config_option('mt_reverse_dns', TRUE) == 'on' ? __('ENABLED') : __('DISABLED')) . '</td>';
    form_alternate_row();
    print '<td width=200>' . __('Primary DNS Server:') . '</td><td>' . read_config_option('mt_dns_primary', TRUE) . '</td>';
    form_alternate_row();
    print '<td width=200>' . __('Secondary DNS Server:') . '</td><td>' . read_config_option('mt_dns_secondary', TRUE) . '</td>';
    form_alternate_row();
    print '<td width=200>' . __('DNS Resoution Timeout:') . '</td><td> ' . read_config_option('mt_dns_timeout', TRUE) . __('milliseconds') . '</td>';
    html_end_box(TRUE);
    if ($total_processes > 0) {
        html_start_box(__('Running Process Summary'), '100%', '', '3', 'center', '');
        ?>
		<td><?php 
        print $resolver_running ? __('The DNS Resolver is Running') : __('The DNS Resolver is Not Running');
        ?>
</td>
		<?php 
        html_header(array(__('Status'), __('Devices'), __('Date Started')), 3);
        $other_processes = 0;
        $other_date = 0;
        if (sizeof($run_status) == 1) {
            $waiting_processes = $total_devices - $total_processes;
            $waiting_date = $run_status[0]['last_rundate'];
            $completed_processes = 0;
            $completed_date = '';
            $running_processes = $total_processes;
            $running_date = read_config_option('mt_scan_date', TRUE);
        } else {
            $i = 0;
            foreach ($run_status as $key => $run) {
                switch ($key) {
                    case 0:
                        $completed_processes = $run['devices'];
                        $completed_date = $run['last_rundate'];
                        break;
                    case 1:
                        $waiting_processes = $run['devices'] - $total_processes;
                        $waiting_date = $run['last_rundate'];
                        $running_processes = $total_processes;
                        $running_date = read_config_option('mt_scan_date', TRUE);
                        break;
                    default:
                        $other_processes += $run['devices'];
                        $other_rundate = $run['last_rundate'];
                }
            }
        }
        form_alternate_row();
        ?>
		<td><?php 
        print __('Completed');
        ?>
</td>
		<td><?php 
        print $completed_processes;
        ?>
</td>
		<td><?php 
        print $completed_date;
        ?>
</td>
		<?php 
        form_alternate_row();
        ?>
		<td><?php 
        print __('Running');
        ?>
</td>
		<td><?php 
        print $running_processes;
        ?>
</td>
		<td><?php 
        print $running_date;
        ?>
</td>
		<?php 
        form_alternate_row();
        ?>
		<td><?php 
        print __('Waiting');
        ?>
</td>
		<td><?php 
        print $waiting_processes;
        ?>
</td>
		<td><?php 
        print $waiting_date;
        ?>
</td>
		<?php 
        form_alternate_row();
        if ($other_processes > 0) {
            ?>
			<td><?php 
            print __('Other');
            ?>
</td>
			<td><?php 
            print $other_processes;
            ?>
</td>
			<td><?php 
            print $other_date;
            ?>
</td>
			<?php 
        }
        html_end_box(TRUE);
    }
}
Example #11
0
function data_query()
{
    global $dq_actions, $item_rows;
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_request('page'));
    input_validate_input_number(get_request_var_request('rows'));
    /* ==================================================== */
    /* clean up 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_data_queries_filter');
        kill_session_var('sess_default_rows');
        kill_session_var('sess_data_queries_sort_column');
        kill_session_var('sess_data_queries_sort_direction');
        unset($_REQUEST['page']);
        unset($_REQUEST['filter']);
        unset($_REQUEST['rows']);
        unset($_REQUEST['sort_column']);
        unset($_REQUEST['sort_direction']);
        $_REQUEST['page'] = 1;
    }
    /* remember these search fields in session vars so we don't have to keep passing them around */
    load_current_session_value('sort_column', 'sess_data_queries_sort_column', 'name');
    load_current_session_value('sort_direction', 'sess_data_queries_sort_direction', 'ASC');
    load_current_session_value('page', 'sess_data_queries_current_page', '1');
    load_current_session_value('filter', 'sess_data_queries_filter', '');
    load_current_session_value('rows', 'sess_default_rows', read_config_option('num_rows_table'));
    html_start_box('<strong>Data Queries</strong>', '100%', '', '3', 'center', 'data_queries.php?action=edit');
    ?>
	<tr class='even noprint'>
		<td class="noprint">
		<form id="form_data_queries" method="get" action="data_queries.php">
			<table cellpadding="2" cellspacing="0">
				<tr class="noprint">
					<td width="50">
						Search
					</td>
					<td>
						<input id='filter' type="text" name="filter" size="25" value="<?php 
    print htmlspecialchars(get_request_var_request('filter'));
    ?>
">
					</td>
					<td style='white-space:nowrap;'>
						Data Queries
					</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>
		<script type='text/javascript'>
		function applyFilter() {
			strURL = 'data_queries.php?filter='+$('#filter').val()+'&rows='+$('#rows').val()+'&page='+$('#page').val()+'&header=false';
			$.get(strURL, function(data) {
				$('#main').html(data);
				applySkin();
			});
		}

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

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

			$('#clear').click(function() {
				clearFilter();
			});
	
			$('#form_data_queries').submit(function(event) {
				event.preventDefault();
				applyFilter();
			});
		});
		</script>
		</td>
	</tr>
	<?php 
    html_end_box();
    /* print checkbox form for validation */
    print "<form name='chk' method='post' action='data_queries.php'>\n";
    html_start_box('', '100%', '', '3', 'center', '');
    /* form the 'where' clause for our main sql query */
    if (strlen(get_request_var_request('filter'))) {
        $sql_where = "WHERE (sq.name like '%%" . get_request_var_request('filter') . "%%' OR di.name like '%%" . get_request_var_request('filter') . "%%')";
    } else {
        $sql_where = '';
    }
    $total_rows = db_fetch_cell("SELECT\n\t\tCOUNT(*)\n\t\tFROM snmp_query AS sq\n\t\tINNER JOIN data_input AS di\n\t\tON (sq.data_input_id=di.id)\n\t\t{$sql_where}");
    $snmp_queries = db_fetch_assoc("SELECT sq.id, sq.name,\n\t\tdi.name AS data_input_method, \n\t\tCOUNT(DISTINCT gl.id) AS graphs,\n\t\tCOUNT(DISTINCT sqg.graph_template_id) AS templates\n\t\tFROM snmp_query AS sq\n\t\tLEFT JOIN snmp_query_graph AS sqg\n\t\tON sq.id=sqg.snmp_query_id\n\t\tLEFT JOIN data_input AS di\n\t\tON (sq.data_input_id=di.id)\n\t\tLEFT JOIN graph_local AS gl\n\t\tON gl.snmp_query_id=sq.id\n\t\t{$sql_where}\n\t\tGROUP BY sq.id\n\t\tORDER BY " . get_request_var_request('sort_column') . ' ' . get_request_var_request('sort_direction') . '
		LIMIT ' . get_request_var_request('rows') * (get_request_var_request('page') - 1) . ',' . get_request_var_request('rows'));
    $nav = html_nav_bar('data_queries.php?filter=' . get_request_var_request('filter'), MAX_DISPLAY_PAGES, get_request_var_request('page'), get_request_var_request('rows'), $total_rows, 7, 'Data Queries', 'page', 'main');
    print $nav;
    $display_text = array('name' => array('display' => 'Data Query Name', 'align' => 'left', 'sort' => 'ASC', 'tip' => 'The name of this Data Query.'), 'nosort' => array('display' => 'Deletable', 'align' => 'right', 'tip' => 'Data Queries that are in use can not be Deleted.  In use is defined as being referenced by either a Graph or a Graph Template.'), 'graphs' => array('display' => 'Graphs Using', 'align' => 'right', 'sort' => 'DESC', 'tip' => 'The number of Graphs using this Data Query.'), 'templates' => array('display' => 'Templates Using', 'align' => 'right', 'sort' => 'DESC', 'tip' => 'The number of Graphs Templates using this Data Query.'), 'data_input_method' => array('display' => 'Data Input Method', 'align' => 'left', 'sort' => 'ASC', 'tip' => 'The Data Input Method used to collect data for Data Sources associated with this Data Query.'), 'id' => array('display' => 'ID', 'align' => 'right', 'sort' => 'ASC', 'tip' => 'The internal ID for this Graph Template.  Useful when performing automation or debugging.'));
    html_header_sort_checkbox($display_text, get_request_var_request('sort_column'), get_request_var_request('sort_direction'), false);
    $i = 0;
    if (sizeof($snmp_queries) > 0) {
        foreach ($snmp_queries as $snmp_query) {
            if ($snmp_query['graphs'] == 0 && $snmp_query['templates'] == 0) {
                $disabled = false;
            } else {
                $disabled = true;
            }
            form_alternate_row('line' . $snmp_query['id'], true, $disabled);
            form_selectable_cell("<a class='linkEditMain' href='" . htmlspecialchars('data_queries.php?action=edit&id=' . $snmp_query['id']) . "'>" . (strlen(get_request_var_request('filter')) ? preg_replace('/(' . preg_quote(get_request_var_request('filter'), '/') . ')/i', "<span class='filteredValue'>\\1</span>", htmlspecialchars($snmp_query['name'])) : htmlspecialchars($snmp_query['name'])) . '</a>', $snmp_query['id']);
            form_selectable_cell($disabled ? 'No' : 'Yes', $snmp_query['id'], '', 'text-align:right');
            form_selectable_cell(number_format($snmp_query['graphs']), $snmp_query['id'], '', 'text-align:right');
            form_selectable_cell(number_format($snmp_query['templates']), $snmp_query['id'], '', 'text-align:right');
            form_selectable_cell(strlen(get_request_var_request('filter')) ? preg_replace('/(' . preg_quote(get_request_var_request('filter'), '/') . ')/i', "<span class='filteredValue'>\\1</span>", $snmp_query['data_input_method']) : $snmp_query['data_input_method'], $snmp_query['id']);
            form_selectable_cell($snmp_query['id'], $snmp_query['id'], '', 'text-align:right;');
            form_checkbox_cell($snmp_query['name'], $snmp_query['id'], $disabled);
            form_end_row();
        }
        print $nav;
    } else {
        print "<tr class='tableRow'><td colspan='5'><em>No Data Queries</em></td></tr>";
    }
    html_end_box(false);
    /* draw the dropdown containing a list of available actions for this form */
    draw_actions_dropdown($dq_actions);
}
Example #12
0
function color()
{
    html_start_box('<strong>Colors</strong>', '100%', '', '3', 'center', 'color.php?action=edit');
    print "<tr class='tableHeader'>";
    DrawMatrixHeaderItem('Hex Value', '', 1);
    DrawMatrixHeaderItem('Color', '', 1);
    DrawMatrixHeaderItem('&nbsp;', '', 1);
    DrawMatrixHeaderItem('&nbsp;', '', 1);
    DrawMatrixHeaderItem('Hex Value', '', 1);
    DrawMatrixHeaderItem('Color', '', 1);
    DrawMatrixHeaderItem('&nbsp;', '', 1);
    DrawMatrixHeaderItem('&nbsp;', '', 1);
    DrawMatrixHeaderItem('Hex Value', '', 1);
    DrawMatrixHeaderItem('Color', '', 1);
    DrawMatrixHeaderItem('&nbsp;', '', 1);
    DrawMatrixHeaderItem('&nbsp;', '', 1);
    DrawMatrixHeaderItem('Hex Value', '', 1);
    DrawMatrixHeaderItem('Color', '', 1);
    DrawMatrixHeaderItem('&nbsp;', '', 1);
    print '</tr>';
    $color_list = db_fetch_assoc('SELECT * FROM colors ORDER BY hex');
    $i = 0;
    if (sizeof($color_list) > 0) {
        $j = 0;
        ## even/odd counter
        foreach ($color_list as $color) {
            $j++;
            if ($j % 4 == 1) {
                form_alternate_row('', true);
                ?>
					<td width='1'>
						<a class="linkEditMain" style='display:block;' href="<?php 
                print htmlspecialchars('color.php?action=edit&id=' . $color['id']);
                ?>
"><?php 
                print $color['hex'];
                ?>
</a>
					</td>
					<td bgcolor="#<?php 
                print $color['hex'];
                ?>
" width="10%">&nbsp;</td>
					<td align="right">
						<a href="<?php 
                print htmlspecialchars('color.php?action=remove&id=' . $color['id']);
                ?>
"><img src="images/delete_icon.gif" style="height:10px;width:10px;" border="0" alt="Delete"></a>
					</td>
				<?php 
                $j = 1;
            } elseif ($j % 4 == 2 || $j % 4 == 3) {
                ?>
					<td></td>
					<td width='1'>
						<a class="linkEditMain" style='display:block;' href="<?php 
                print htmlspecialchars('color.php?action=edit&id=' . $color['id']);
                ?>
"><?php 
                print $color['hex'];
                ?>
</a>
					</td>
					<td bgcolor="#<?php 
                print $color['hex'];
                ?>
" width="10%">&nbsp;</td>
					<td align="right">
						<a href="<?php 
                print htmlspecialchars('color.php?action=remove&id=' . $color['id']);
                ?>
"><img src="images/delete_icon.gif" style="height:10px;width:10px;" border="0" alt="Delete"></a>
					</td>
				<?php 
                $j = $j++;
            } else {
                ?>
					<td></td>
					<td width='1'>
						<a class="linkEditMain" style='display:block;' href="<?php 
                print htmlspecialchars('color.php?action=edit&id=' . $color['id']);
                ?>
"><?php 
                print $color['hex'];
                ?>
</a>
					</td>
					<td bgcolor="#<?php 
                print $color['hex'];
                ?>
" width="10%">&nbsp;</td>
					<td align="right">
						<a href="<?php 
                print htmlspecialchars('color.php?action=remove&id=' . $color['id']);
                ?>
"><img src="images/delete_icon.gif" style="height:10px;width:10px;" border="0" alt="Delete"></a>
					</td>
				</tr>
			<?php 
            }
        }
        ## check for completion of odd number second column:
        ?>
		<td colspan=<?php 
        print (4 - $j) * 4;
        ?>
></td>
		</tr>
		<?php 
    }
    html_end_box();
}
Example #13
0
function lists()
{
    global $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')));
    validate_store_request_vars($filters, 'sess_lists');
    /* ================= 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(__('Notification Lists'), '100%', '', '3', 'center', 'notify_lists.php?action=edit');
    ?>
	<tr class='even'>
		<td>
		<form id='lists' 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'));
    ?>
'>
					</td>
					<td>
						<?php 
    print __('Lists');
    ?>
					</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='button' value='<?php 
    print __('Go');
    ?>
' title='<?php 
    print __('Set/Refresh Filters');
    ?>
' onClick='applyFilter()'>
					</td>
					<td>
						<input type='button' name='clear' value='<?php 
    print __('Clear');
    ?>
' title='<?php 
    print __('Clear Filters');
    ?>
' onClick='clearFilter()'>
					</td>
				</tr>
			</table>
			<input type='hidden' id='page' value='<?php 
    print get_filter_request_var('page');
    ?>
'>
		</form>
		<script type='text/javascript'>

		function applyFilter() {
			strURL  = 'notify_lists.php?header=false';
			strURL += '&rows=' + $('#rows').val();
			strURL += '&filter=' + $('#filter').val();
			loadPageNoHeader(strURL);
		}

		function clearFilter() {
			strURL = 'notify_lists.php?header=false&clear=1';
			loadPageNoHeader(strURL);
		}

		$(function() {
			$('#lists').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 (name LIKE '%" . get_request_var('filter') . "%' OR\n\t\tdescription LIKE '%" . get_request_var('filter') . "%' OR\n\t\temails LIKE '%" . get_request_var('filter') . "%')";
    } else {
        $sql_where = '';
    }
    $total_rows = db_fetch_cell("SELECT\n\t\tCOUNT(*)\n\t\tFROM plugin_notification_lists\n\t\t{$sql_where}");
    $lists = db_fetch_assoc("SELECT id, name, description, emails\n\t\tFROM plugin_notification_lists\n\t\t{$sql_where}\n\t\tORDER BY " . get_request_var('sort_column') . ' ' . get_request_var('sort_direction') . ' LIMIT ' . $rows * (get_request_var('page') - 1) . ',' . $rows);
    $nav = html_nav_bar('notify_lists.php?filter=' . get_request_var('filter'), MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, 10, __('Lists'), 'page', 'main');
    form_start('notify_lists.php', 'chk');
    print $nav;
    html_start_box('', '100%', '', '3', 'center', '');
    $display_text = array('name' => array(__('List Name'), 'ASC'), 'description' => array(__('Description'), 'ASC'), 'emails' => array(__('Emails'), 'ASC'));
    html_header_sort_checkbox($display_text, get_request_var('sort_column'), get_request_var('sort_direction'), false);
    if (sizeof($lists)) {
        foreach ($lists as $item) {
            form_alternate_row('line' . $item['id'], true);
            form_selectable_cell(filter_value($item['name'], get_request_var('filter'), 'notify_lists.php?action=edit&id=' . $item['id']), $item['id'], '25%');
            form_selectable_cell(filter_value($item['description'], get_request_var('filter')), $item['id'], '35%');
            form_selectable_cell(filter_value($item['emails'], get_request_var('filter')), $item['id']);
            form_checkbox_cell($item['name'], $item['id']);
            form_end_row();
        }
    } else {
        print '<tr><td><em>' . __('No Notification Lists') . '</em></td></tr>';
    }
    html_end_box(false);
    if (sizeof($lists)) {
        print $nav;
    }
    form_hidden_box('save_list', '1', '');
    /* draw the dropdown containing a list of available actions for this form */
    draw_actions_dropdown($actions);
    form_end();
}
Example #14
0
function mikrotik_user()
{
    global $user_actions, $item_rows;
    /* ================= input validation and session storage ================= */
    $filters = array('rows' => array('filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1'), 'type' => array('filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1'), 'page' => array('filter' => FILTER_VALIDATE_INT, 'default' => '1'), 'status' => array('filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1'), 'filter' => array('filter' => FILTER_CALLBACK, 'pageset' => true, 'default' => '', 'options' => array('options' => 'sanitize_search_string')), 'sort_column' => array('filter' => FILTER_CALLBACK, 'default' => 'name', '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_mtue');
    /* ================= input validation and session storage ================= */
    /* if the number of rows is -1, set it to the default */
    if (get_request_var('rows') != '-1') {
        $rows = get_request_var('rows');
    } else {
        $rows = read_config_option('num_rows_table');
    }
    ?>
	<script type='text/javascript'>
	function applyFilter(objForm) {
		strURL  = 'mikrotik_users.php?filter=' + $('#filter').val();
		strURL += '&status=' + $('#status').val();
		strURL += '&type=' + $('#type').val();
		strURL += '&rows=' + $('#rows').val();
		strURL += '&header=false';
		loadPageNoHeader(strURL);
	}

	function clearFilter() {
		strURL  = 'mikrotik_users.php?clear=1';
		strURL += '&header=false';
		loadPageNoHeader(strURL);
	}

	$(function() {
		$('#users').submit(function(event) {
			event.preventDefault();
			applyFilter();
		});
	});
	</script>
	<?php 
    html_start_box(__('MikroTik Users'), '100%', '', '3', 'center', '');
    ?>
	<tr class='even'>
		<td>
		<form id='users' action='mikrotik_users.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'));
    ?>
'>
					</td>
					<td>
						<?php 
    print __('Type');
    ?>
					</td>
					<td>
						<select id='type' onChange='applyFilter()'>
							<option value='-1'<?php 
    if (get_request_var('type') == '-1') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('All');
    ?>
</option>
							<option value='0'<?php 
    if (get_request_var('type') == '0') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('Hotspot');
    ?>
</option>
							<option value='1'<?php 
    if (get_request_var('type') == '1') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('PPPoe');
    ?>
</option>
						</select>
					</td>
					<td>
						<?php 
    print __('Users');
    ?>
					</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>
						<?php 
    print __('Status');
    ?>
					</td>
					<td>
						<select id='status' onChange='applyFilter()'>
							<option value='-1'<?php 
    if (get_request_var('status') == '-1') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('All');
    ?>
</option>
							<option value='1'<?php 
    if (get_request_var('status') == '1') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('Active');
    ?>
</option>
							<option value='2'<?php 
    if (get_request_var('status') == '2') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('Inactive');
    ?>
</option>
						</select>
					<td>
						<input type='button' value='<?php 
    print __('Go');
    ?>
' title='<?php 
    print __('Set/Refresh Filters');
    ?>
' onClick='applyFilter()'>
					</td>
					<td>
						<input type='button' name='clear_x' value='<?php 
    print __('Clear');
    ?>
' title='<?php 
    print __('Clear Filters');
    ?>
' onClick='clearFilter()'>
					</td>
				</tr>
			</table>
			<input type='hidden' name='page' value='1'>
		</form>
		</td>
	</tr>
	<?php 
    html_end_box();
    /* form the 'where' clause for our main sql query */
    if (strlen(get_request_var('filter'))) {
        $sql_where = "WHERE (name LIKE '%%" . get_request_var('filter') . "%%') AND name!=''";
    } else {
        $sql_where = "WHERE name!=''";
    }
    if (get_request_var('status') == 1) {
        $sql_where .= ' AND present=1';
    } elseif (get_request_var('status') == 2) {
        $sql_where .= ' AND present=0';
    }
    if (get_request_var('type') == '0') {
        $sql_where .= (strlen($sql_where) ? ' AND' : 'WHERE') . ' userType=0';
    } elseif (get_request_var('type') == '1') {
        $sql_where .= (strlen($sql_where) ? ' AND' : 'WHERE') . ' userType=1';
    }
    $total_rows = db_fetch_cell("SELECT \n\t\tCOUNT(DISTINCT name)\n\t\tFROM plugin_mikrotik_users\n\t\t{$sql_where}");
    $sortby = get_request_var('sort_column');
    $sql_query = "SELECT name, domain, userType, MAX(last_seen) AS last_seen, MAX(present) AS present\n\t\tFROM plugin_mikrotik_users\n\t\t{$sql_where}\n\t\tGROUP BY name, domain\n\t\tORDER BY " . $sortby . ' ' . get_request_var('sort_direction') . '
		LIMIT ' . $rows * (get_request_var('page') - 1) . ',' . $rows;
    $users = db_fetch_assoc($sql_query);
    $nav = html_nav_bar('mikrotik_users.php?filter=' . get_request_var('filter'), MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, 6, __('Users'), 'page', 'main');
    form_start('mikrotik_users.php', 'chk');
    print $nav;
    html_start_box('', '100%', '', '3', 'center', '');
    $display_text = array('name' => array(__('User Name'), 'ASC'), 'domain' => array(__('Domain'), 'ASC'), 'type' => array(__('Type'), 'ASC'), 'last_seen' => array(__('Last Seen'), 'DESC'), 'present' => array(__('Active'), 'ASC'));
    html_header_sort_checkbox($display_text, get_request_var('sort_column'), get_request_var('sort_direction'), false);
    if (sizeof($users)) {
        foreach ($users as $user) {
            form_alternate_row('line' . $user['name'], true);
            form_selectable_cell("<span class='noLinkEditMain'>" . filter_value($user['name'], get_request_var('filter')) . '</span>', $user['name'], 250);
            form_selectable_cell($user['domain'] != '' ? $user['domain'] : 'Not Set', $user['name']);
            form_selectable_cell($user['userType'] == '0' ? 'Hotspot' : 'PPPoe', $user['name']);
            form_selectable_cell($user['last_seen'], $user['name']);
            form_selectable_cell($user['present'] == 0 ? '<b><i>' . __('Inactive') . '</i></b>' : '<b><i>' . __('Active') . '</i></b>', $user['name']);
            form_checkbox_cell($user['name'], $user['name']);
            form_end_row();
        }
    } else {
        print '<tr><td><em>' . __('No Users Found') . '</em></td></tr>';
    }
    html_end_box(false);
    if (sizeof($users)) {
        print $nav;
    }
    /* draw the dropdown containing a list of available actions for this form */
    draw_actions_dropdown($user_actions);
    form_end();
}
Example #15
0
function data()
{
    global $input_types, $di_actions, $item_rows;
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_request('page'));
    input_validate_input_number(get_request_var_request('rows'));
    /* ==================================================== */
    /* clean up 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_data_input_filter');
        kill_session_var('sess_default_rows');
        kill_session_var('sess_data_input_sort_column');
        kill_session_var('sess_data_input_sort_direction');
        unset($_REQUEST['page']);
        unset($_REQUEST['filter']);
        unset($_REQUEST['rows']);
        unset($_REQUEST['sort_column']);
        unset($_REQUEST['sort_direction']);
        $_REQUEST['page'] = 1;
    }
    /* remember these search fields in session vars so we don't have to keep passing them around */
    load_current_session_value('filter', 'sess_data_input_filter', '');
    load_current_session_value('sort_column', 'sess_data_input_sort_column', 'name');
    load_current_session_value('sort_direction', 'sess_data_input_sort_direction', 'ASC');
    load_current_session_value('page', 'sess_data_input_current_page', '1');
    load_current_session_value('rows', 'sess_default_rows', read_config_option('num_rows_table'));
    html_start_box('<strong>Data Input Methods</strong>', '100%', '', '3', 'center', 'data_input.php?action=edit');
    ?>
	<tr class='even noprint'>
		<td class="noprint">
		<form id="form_data_input" method="get" action="data_input.php">
			<table cellpadding="2" cellspacing="0">
				<tr class="noprint">
					<td width="50">
						Search
					</td>
					<td>
						<input id='filter' type="text" name="filter" size="25" value="<?php 
    print htmlspecialchars(get_request_var_request('filter'));
    ?>
">
					</td>
					<td style='white-space:nowrap;'>
						Input Methods
					</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="submit" 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>
		<script type='text/javascript'>
		function applyFilter() {
			strURL = 'data_input.php?filter='+$('#filter').val()+'&rows='+$('#rows').val()+'&page='+$('#page').val()+'&header=false';
			$.get(strURL, function(data) {
				$('#main').html(data);
				applySkin();
			});
		}

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

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

			$('#clear').click(function() {
				clearFilter();
			});
	
			$('#form_data_input').submit(function(event) {
				event.preventDefault();
				applyFilter();
			});
		});
		</script>
		</td>
	</tr>
	<?php 
    html_end_box();
    /* print checkbox form for validation */
    print "<form name='chk' method='post' action='data_input.php'>\n";
    html_start_box('', '100%', '', '3', 'center', '');
    /* form the 'where' clause for our main sql query */
    if ($_REQUEST['filter'] != '') {
        $sql_where = "WHERE (di.name like '%" . get_request_var_request('filter') . "%')";
    } else {
        $sql_where = '';
    }
    $sql_where .= (strlen($sql_where) ? ' AND' : 'WHERE') . " (di.name!='Get Script Data (Indexed)'\n\t\tAND di.name!='Get Script Server Data (Indexed)'\n\t\tAND di.name!='Get SNMP Data'\n\t\tAND di.name!='Get SNMP Data (Indexed)')";
    $total_rows = db_fetch_cell("SELECT\n\t\tcount(*)\n\t\tFROM data_input AS di\n\t\t{$sql_where}");
    $data_inputs = db_fetch_assoc("SELECT di.*,\n\t\tSUM(CASE WHEN dtd.local_data_id=0 THEN 1 ELSE 0 END) AS templates,\n\t\tSUM(CASE WHEN dtd.local_data_id>0 THEN 1 ELSE 0 END) AS data_sources\n\t\tFROM data_input AS di\n\t\tLEFT JOIN data_template_data AS dtd\n\t\tON di.id=dtd.data_template_id\n\t\t{$sql_where}\n\t\tGROUP BY di.id\n\t\tORDER BY " . get_request_var_request('sort_column') . ' ' . get_request_var_request('sort_direction') . '
		LIMIT ' . get_request_var_request('rows') * (get_request_var_request('page') - 1) . ',' . get_request_var_request('rows'));
    $nav = html_nav_bar('data_input.php?filter=' . get_request_var_request('filter'), MAX_DISPLAY_PAGES, get_request_var_request('page'), get_request_var_request('rows'), $total_rows, 6, 'Input Methods', 'page', 'main');
    print $nav;
    $display_text = array('name' => array('display' => 'Data Input Name', 'align' => 'left', 'sort' => 'ASC', 'tip' => 'The name of this Data Input Method.'), 'nosort' => array('display' => 'Deletable', 'align' => 'right', 'tip' => 'Data Inputs that are in use can not be Deleted.  In use is defined as being referenced either by a Data Source or a Data Template.'), 'data_sources' => array('display' => 'Data Sources Using', 'align' => 'right', 'sort' => 'DESC', 'tip' => 'The number of Data Sources that use this Data Input Method.'), 'templates' => array('display' => 'Templates Using', 'align' => 'right', 'sort' => 'DESC', 'tip' => 'The number of Data Templates that use this Data Input Method.'), 'type_id' => array('display' => 'Data Input Method', 'align' => 'left', 'sort' => 'ASC', 'tip' => 'The method used to gather information for this Data Input Method.'));
    html_header_sort_checkbox($display_text, get_request_var_request('sort_column'), get_request_var_request('sort_direction'), false);
    $i = 0;
    if (sizeof($data_inputs) > 0) {
        foreach ($data_inputs as $data_input) {
            /* hide system types */
            if ($data_input['templates'] > 0 || $data_input['data_sources'] > 0) {
                $disabled = true;
            } else {
                $disabled = false;
            }
            form_alternate_row('line' . $data_input['id'], true, $disabled);
            form_selectable_cell("<a class='linkEditMain' href='" . htmlspecialchars('data_input.php?action=edit&id=' . $data_input['id']) . "'>" . (strlen(get_request_var_request('filter')) ? preg_replace('/(' . preg_quote(get_request_var_request('filter'), '/') . ')/i', "<span class='filteredValue'>\\1</span>", htmlspecialchars($data_input['name'])) : htmlspecialchars($data_input['name'])) . '</a>', $data_input['id']);
            form_selectable_cell($disabled ? 'No' : 'Yes', $data_input['id'], '', 'text-align:right');
            form_selectable_cell(number_format($data_input['data_sources']), $data_input['id'], '', 'text-align:right');
            form_selectable_cell(number_format($data_input['templates']), $data_input['id'], '', 'text-align:right');
            form_selectable_cell($input_types[$data_input['type_id']], $data_input['id']);
            form_checkbox_cell($data_input['name'], $data_input['id'], $disabled);
            form_end_row();
        }
        print $nav;
    } else {
        print "<tr><td colspan='5'><em>No Data Input Methods</em></td></tr>";
    }
    html_end_box(false);
    /* draw the dropdown containing a list of available actions for this form */
    draw_actions_dropdown($di_actions);
    print "</form>\n";
}
Example #16
0
function draw_nontemplated_fields_custom_data($data_template_data_id, $field_name_format = "|field|", $header_title = "", $alternate_colors = true, $include_hidden_fields = true, $snmp_query_id = 0)
{
    $data = db_fetch_row("SELECT id,data_input_id,data_template_id,name,local_data_id FROM data_template_data WHERE id={$data_template_data_id}");
    $host_id = db_fetch_cell("SELECT host.id FROM (data_local,host) WHERE data_local.host_id=host.id AND data_local.id=" . $data["local_data_id"]);
    $template_data = db_fetch_row("SELECT id,data_input_id FROM data_template_data WHERE data_template_id=" . $data["data_template_id"] . " AND local_data_id=0");
    $draw_any_items = false;
    /* get each INPUT field for this data input source */
    $fields = db_fetch_assoc("SELECT * FROM data_input_fields WHERE data_input_id=" . $data["data_input_id"] . " AND input_output='in' ORDER BY sequence");
    /* loop through each field found */
    $i = 0;
    if (sizeof($fields) > 0) {
        foreach ($fields as $field) {
            $data_input_data = db_fetch_row("SELECT * FROM data_input_data WHERE data_template_data_id=" . $data["id"] . " AND data_input_field_id=" . $field["id"]);
            if (sizeof($data_input_data) > 0) {
                $old_value = $data_input_data["value"];
            } else {
                $old_value = "";
            }
            /* if data template then get t_value from template, else always allow user input */
            if (empty($data["data_template_id"])) {
                $can_template = "on";
            } else {
                $can_template = db_fetch_cell("SELECT t_value FROM data_input_data WHERE data_template_data_id=" . $template_data["id"] . " AND data_input_field_id=" . $field["id"]);
            }
            /* find our field name */
            $form_field_name = str_replace("|id|", $field["id"], $field_name_format);
            if (!empty($host_id) && preg_match('/^' . VALID_HOST_FIELDS . '$/i', $field["type_code"]) && empty($can_template)) {
                /* no host fields */
                if ($include_hidden_fields == true) {
                    form_hidden_box($form_field_name, $old_value, "");
                }
            } elseif (!empty($snmp_query_id) && preg_match('/^(index_type|index_value|output_type)$/i', $field["type_code"])) {
                /* no data query fields */
                if ($include_hidden_fields == true) {
                    form_hidden_box($form_field_name, $old_value, "");
                }
            } elseif (empty($can_template)) {
                /* no templated fields */
                if ($include_hidden_fields == true) {
                    form_hidden_box($form_field_name, $old_value, "");
                }
            } else {
                if ($draw_any_items == false && $header_title != "") {
                    print "<tr class='tableHeader'><td colspan='2' class='tableSubHeaderColumn'>{$header_title}</td></tr>\n";
                }
                if ($alternate_colors == true) {
                    form_alternate_row();
                } else {
                    print "<tr class='odd'>\n";
                }
                print "<td width='50%'><strong>" . $field["name"] . "</strong></td>\n";
                print "<td>";
                draw_custom_data_row($form_field_name, $field["id"], $data["id"], $old_value);
                print "</td>";
                print "</tr>\n";
                $draw_any_items = true;
                $i++;
            }
        }
    }
    return $i;
}
Example #17
0
function list_rrd()
{
    global $config, $item_rows, $ds_actions, $rra_path, $hash_version_codes;
    /* suppress warnings */
    error_reporting(0);
    /* install the rrdclean error handler */
    set_error_handler('rrdclean_error_handler');
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_request('page'));
    input_validate_input_number(get_request_var_request('age'));
    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 string */
    if (isset($_REQUEST['sort_column'])) {
        $_REQUEST['sort_column'] = sanitize_search_string(get_request_var('sort_column'));
    }
    /* clean up sort_direction string */
    if (isset($_REQUEST['sort_direction'])) {
        $_REQUEST['sort_direction'] = sanitize_search_string(get_request_var('sort_direction'));
    }
    /* if the user pushed the 'clear' button */
    if (isset($_REQUEST['clear_x'])) {
        kill_session_var('sess_rrdclean_current_page');
        kill_session_var('sess_rrdclean_age');
        kill_session_var('sess_default_rows');
        kill_session_var('sess_rrdclean_filter');
        kill_session_var('sess_rrdclean_sort_column');
        kill_session_var('sess_rrdclean_sort_direction');
        unset($_REQUEST['page']);
        unset($_REQUEST['age']);
        unset($_REQUEST['rows']);
        unset($_REQUEST['filter']);
        unset($_REQUEST['sort_column']);
        unset($_REQUEST['sort_direction']);
    }
    /* remember these search fields in session vars so we don't have to keep passing them around */
    load_current_session_value('page', 'sess_rrdclean_current_page', '1');
    load_current_session_value('age', 'sess_rrdclean_current_age', '1');
    load_current_session_value('rows', 'sess_rrdclean_rows', read_config_option('num_rows_table'));
    load_current_session_value('filter', 'sess_rrdclean_filter', '');
    load_current_session_value('sort_column', 'sess_rrdclean_sort_column', 'name');
    load_current_session_value('sort_direction', 'sess_rrdclean_sort_direction', 'ASC');
    $width = '100%';
    if (isset($hash_version_codes[$config['cacti_version']])) {
        if ($hash_version_codes[$config['cacti_version']] > 13) {
            $width = '100%';
        }
    }
    html_start_box('<strong>RRD Cleaner</strong>', $width, '', '3', 'center', '');
    filter();
    html_end_box();
    $sql_where = 'WHERE in_cacti=0';
    /* form the 'where' clause for our main sql query */
    if ($_REQUEST['filter'] != '') {
        $sql_where .= " AND (rc.name LIKE '%" . $_REQUEST['filter'] . "%' OR rc.name_cache LIKE '%" . $_REQUEST['filter'] . "%' OR dt.name LIKE '%" . $_REQUEST['filter'] . "%')";
    }
    $secsback = $_REQUEST['age'];
    if ($REQUEST['age'] != 0) {
        $sql_where .= " AND last_mod>='" . date("Y-m-d H:i:s", time() - 86400 * 7) . "'";
    } else {
        $sql_where .= " AND last_mod<='" . date("Y-m-d H:i:s", time() - $secsback) . "'";
    }
    print "<form action='rrdcleaner.php' method='post'>\n";
    html_start_box('', $width, '', '3', 'center', '');
    $total_rows = db_fetch_cell("SELECT COUNT(rc.name) \n\t\tFROM data_source_purge_temp AS rc\n\t\tLEFT JOIN data_template AS dt\n\t\tON dt.id = rc.data_template_id\n\t\t{$sql_where}");
    $total_size = db_fetch_cell("SELECT ROUND(SUM(size),2) \n\t\tFROM data_source_purge_temp AS rc\n\t\tLEFT JOIN data_template AS dt\n\t\tON dt.id = rc.data_template_id\n\t\t{$sql_where}");
    $file_list = db_fetch_assoc("SELECT rc.id, rc.name, rc.last_mod, rc.size, \n\t\trc.name_cache, rc.local_data_id, rc.data_template_id, dt.name AS data_template_name\n\t\tFROM data_source_purge_temp AS rc\n\t\tLEFT JOIN data_template AS dt\n\t\tON dt.id = rc.data_template_id\n\t\t{$sql_where} \n\t\tORDER BY " . $_REQUEST['sort_column'] . ' ' . $_REQUEST['sort_direction'] . '
		LIMIT ' . $_REQUEST['rows'] * ($_REQUEST['page'] - 1) . ',' . $_REQUEST['rows']);
    $nav = html_nav_bar($config['url_path'] . 'rrdcleaner.php?filter' . get_request_var_request('filter'), MAX_DISPLAY_PAGES, get_request_var_request('page'), get_request_var_request('rows'), $total_rows, 8, 'RRD Files', 'page', 'main');
    print $nav;
    $display_text = array('name' => array('RRD File Name', 'ASC'), 'name_cache' => array('DS Name', 'ASC'), 'local_data_id' => array('DS ID', 'ASC'), 'data_template_id' => array('Template ID', 'ASC'), 'data_template_name' => array('Template', 'ASC'), 'last_mod' => array('Last Modified', 'DESC'), 'size' => array('Size [KB]', 'DESC'));
    html_header_sort_checkbox($display_text, $_REQUEST['sort_column'], $_REQUEST['sort_direction'], false);
    if (sizeof($file_list)) {
        foreach ($file_list as $file) {
            $data_template_name = empty($file['data_template_name']) ? '<em>None</em>' : $file['data_template_name'];
            form_alternate_row('line' . $file['id'], true);
            form_selectable_cell(($_REQUEST['filter'] != '' ? eregi_replace('(' . preg_quote($_REQUEST['filter']) . ')', "<span class='filteredValue'>\\1</span>", $file['name']) : $file['name']) . '</a>', $file['id']);
            form_selectable_cell($file['local_data_id'] != 0 ? "<a class='linkEditMain' href='../../data_sources.php?action=ds_edit&id=" . $file['local_data_id'] . "'>" . ($_REQUEST['filter'] != '' ? eregi_replace('(' . preg_quote($_REQUEST['filter']) . ')', "<span class='filteredValue'>\\1</span>", title_trim(htmlentities($file['name_cache']), read_config_option('max_title_length'))) : title_trim(htmlentities($file['name_cache']), read_config_option('max_title_length'))) . '</a>' : '<i>Deleted</i>', $file['id']);
            form_selectable_cell($file['local_data_id'] > 0 ? $file['local_data_id'] : '<i>Deleted</i>', $file['id']);
            form_selectable_cell($file['data_template_id'] > 0 ? $file['data_template_id'] : '<i>Deleted</i>', $file['id']);
            form_selectable_cell($file['data_template_id'] > 0 ? $_REQUEST['filter'] != '' ? eregi_replace('(' . preg_quote($_REQUEST['filter']) . ')', "<span class='filteredValue'>\\1</span>", $file['data_template_name']) . '</a>' : $file['data_template_name'] : '<i>Deleted</i>', $file['id']);
            form_selectable_cell($file['last_mod'], $file['id']);
            form_selectable_cell($file['size'], $file['id']);
            form_checkbox_cell($file['id'], $file['id']);
            form_end_row();
            $i++;
        }
        /* put the nav bar on the bottom as well */
        print $nav;
    } else {
        print "<tr><td><em>No unused RRD Files</em></td></tr>\n";
    }
    html_end_box(false);
    rrdcleaner_legend($total_size);
    draw_actions_dropdown($ds_actions);
    print "</form>\n";
    /* restore original error handler */
    restore_error_handler();
}
Example #18
0
function syslog_removal()
{
    global $syslog_actions, $message_types, $config;
    include dirname(__FILE__) . '/config.php';
    /* ================= 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'), 'id' => array('filter' => FILTER_VALIDATE_INT, 'default' => '1'), 'enabled' => array('filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1'), 'filter' => array('filter' => FILTER_CALLBACK, 'pageset' => true, 'default' => '', 'options' => array('options' => 'sanitize_search_string')), 'sort_column' => array('filter' => FILTER_CALLBACK, 'default' => 'name', '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_syslogr');
    /* ================= input validation ================= */
    html_start_box(__('Syslog Removal Rule Filters'), '100%', '', '3', 'center', 'syslog_removal.php?action=edit&type=1');
    syslog_filter();
    html_end_box();
    $sql_where = '';
    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');
    }
    $removals = syslog_get_removal_records($sql_where, $row_limit);
    $rows_query_string = "SELECT COUNT(*)\n\t\tFROM `" . $syslogdb_default . "`.`syslog_remove`\n\t\t{$sql_where}";
    $total_rows = syslog_db_fetch_cell($rows_query_string);
    $nav = html_nav_bar('syslog_removal.php?filter=' . get_request_var('filter'), MAX_DISPLAY_PAGES, get_request_var('page'), $row_limit, $total_rows, 13, 'Rules', 'page', 'main');
    form_start('syslog_removal.php', 'chk');
    print $nav;
    html_start_box('', '100%', '', '3', 'center', '');
    $display_text = array('name' => array(__('Removal Name'), 'ASC'), 'enabled' => array(__('Enabled'), 'ASC'), 'type' => array(__('Match Type'), 'ASC'), 'message' => array(__('Search String'), 'ASC'), 'method' => array(__('Method'), 'DESC'), 'date' => array(__('Last Modified'), 'ASC'), 'user' => array(__('By User'), 'DESC'));
    html_header_sort_checkbox($display_text, get_request_var('sort_column'), get_request_var('sort_direction'));
    if (sizeof($removals)) {
        foreach ($removals as $removal) {
            form_alternate_row('line' . $removal['id'], true);
            form_selectable_cell(filter_value(title_trim($removal['name'], read_config_option('max_title_length')), get_request_var('filter'), $config['url_path'] . 'plugins/syslog/syslog_removal.php?action=edit&id=' . $removal['id']), $removal['id']);
            form_selectable_cell($removal['enabled'] == 'on' ? __('Yes') : __('No'), $removal['id']);
            form_selectable_cell($message_types[$removal['type']], $removal['id']);
            form_selectable_cell($removal['message'], $removal['id']);
            form_selectable_cell($removal['method'] == 'del' ? __('Deletion') : __('Transfer'), $removal['id']);
            form_selectable_cell(date('Y-m-d H:i:s', $removal['date']), $removal['id']);
            form_selectable_cell($removal['user'], $removal['id']);
            form_checkbox_cell($removal['name'], $removal['id']);
            form_end_row();
        }
    } else {
        print "<tr><td colspan='4'><em>" . __('No Syslog Removal Rules Defined') . "</em></td></tr>";
    }
    html_end_box(false);
    if (sizeof($removals)) {
        print $nav;
    }
    draw_actions_dropdown($syslog_actions);
    form_end();
}
Example #19
0
function update_show_current()
{
    global $plugins, $pluginslist, $plugin_architecture, $config, $status_names, $actions, $item_rows;
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_request("page"));
    input_validate_input_number(get_request_var_request("rows"));
    /* ==================================================== */
    /* clean up 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_plugins_filter");
        kill_session_var("sess_plugins_rows");
        kill_session_var("sess_plugins_sort_column");
        kill_session_var("sess_plugins_sort_direction");
        unset($_REQUEST["page"]);
        unset($_REQUEST["rows"]);
        unset($_REQUEST["filter"]);
        unset($_REQUEST["sort_column"]);
        unset($_REQUEST["sort_direction"]);
        $_REQUEST["page"] = 1;
    }
    /* remember these search fields in session vars so we don't have to keep passing them around */
    load_current_session_value("filter", "sess_plugins_filter", "");
    load_current_session_value("rows", "sess_plugins_rows", "-1");
    load_current_session_value("sort_column", "sess_plugins_sort_column", "name");
    load_current_session_value("sort_direction", "sess_plugins_sort_direction", "ASC");
    load_current_session_value("page", "sess_plugins_current_page", "1");
    $table = plugins_load_temp_table();
    ?>
	<script type="text/javascript">
	<!--
	function applyFilterChange(objForm) {
		strURL = '?rows=' + objForm.rows.value;
		strURL = strURL + '&filter=' + objForm.filter.value;
		document.location = strURL;
	}
	-->
	</script>
	<?php 
    html_start_box("<strong>Plugin Management</strong> (Cacti Version: " . $config["cacti_version"] . (isset($plugin_architecture['version']) ? ", Plugin Architecture Version: " . $plugin_architecture['version'] : "") . ")", "100%", "", "3", "center", "");
    ?>
	<tr class='even noprint'>
		<td class="noprint">
		<form name="form_plugins" method="get" action="plugins.php">
			<table cellpadding="0" cellspacing="0">
				<tr class="noprint">
					<td nowrap style='white-space: nowrap;' width="50">
						Search:&nbsp;
					</td>
					<td width="1">
						<input type="text" name="filter" size="40" value="<?php 
    print get_request_var_request("filter");
    ?>
">
					</td>
					<td nowrap style='white-space: nowrap;' width="50">
						&nbsp;Rows:&nbsp;
					</td>
					<td width="1">
						<select name="rows" onChange="applyFilterChange(document.form_plugins)">
							<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 nowrap style='white-space: nowrap;'>
						&nbsp;<input type="submit" value="Go" title="Set/Refresh Filters">
					</td>
					<td nowrap style='white-space: nowrap;'>
						&nbsp;<input type="submit" name="clear_x" value="Clear" title="Clear Filters">
					</td>
				</tr>
			</table>
			<input type='hidden' name='page' value='1'>
		</form>
		</td>
	</tr>
	<?php 
    html_end_box();
    /* print checkbox form for validation */
    print "<form name='chk' method='post' action='plugins.php'>\n";
    html_start_box("", "100%", "", "3", "center", "");
    /* form the 'where' clause for our main sql query */
    $sql_where = "WHERE ({$table}.name LIKE '%%" . get_request_var_request("filter") . "%%')";
    if (get_request_var_request("sort_column") == "version") {
        $sortc = "version+0";
    } else {
        $sortc = get_request_var_request("sort_column");
    }
    if (get_request_var_request("sort_column") == "id") {
        $sortd = "ASC";
    } else {
        $sortd = get_request_var_request("sort_direction");
    }
    if ($_REQUEST['rows'] == '-1') {
        $rows = read_config_option('num_rows_device');
    } else {
        $rows = get_request_var_request('rows');
    }
    $total_rows = db_fetch_cell("SELECT\n\t\tcount(*)\n\t\tFROM {$table}\n\t\t{$sql_where}");
    $plugins = db_fetch_assoc("SELECT *\n\t\tFROM {$table}\n\t\t{$sql_where}\n\t\tORDER BY " . $sortc . " " . $sortd . "\n\t\tLIMIT " . $rows * (get_request_var_request("page") - 1) . "," . $rows);
    db_execute("DROP TABLE {$table}");
    $nav = html_nav_bar("plugins.php?filter=" . get_request_var_request("filter"), MAX_DISPLAY_PAGES, get_request_var_request("page"), $rows, $total_rows, 8);
    print $nav;
    $display_text = array("nosort" => array("Actions", ""), "directory" => array("Name", "ASC"), "version" => array("Version", "ASC"), "id" => array("Load Order", "ASC"), "name" => array("Description", "ASC"), "nosort1" => array("Type", "ASC"), "status" => array("Status", "ASC"), "author" => array("Author", "ASC"));
    html_header_sort($display_text, get_request_var_request("sort_column"), get_request_var_request("sort_direction"), 1);
    $i = 0;
    if (sizeof($plugins)) {
        if (get_request_var_request("sort_column") == "id") {
            $inst_system_plugins = get_system_plugins($plugins);
            if (sizeof($inst_system_plugins)) {
                foreach ($inst_system_plugins as $plugin) {
                    form_alternate_row('', true);
                    print format_plugin_row($plugin, false, false, true);
                }
            }
        }
        $j = 0;
        foreach ($plugins as $plugin) {
            if (isset($plugins[$j + 1]) && $plugins[$j + 1]['status'] < 0 || !isset($plugins[$j + 1])) {
                $last_plugin = true;
            } else {
                $last_plugin = false;
            }
            if ($plugin['status'] <= 0 || is_system_plugin($plugin) || get_request_var_request('sort_column') != 'id') {
                $load_ordering = false;
            } else {
                $load_ordering = true;
            }
            if (get_request_var_request("sort_column") == "id") {
                if (!is_system_plugin($plugin)) {
                    form_alternate_row('', true);
                    print format_plugin_row($plugin, $last_plugin, $load_ordering, false);
                    $i++;
                }
            } else {
                form_alternate_row('', true);
                print format_plugin_row($plugin, $last_plugin, $load_ordering, is_system_plugin($plugin));
                $i++;
            }
            $j++;
        }
        print $nav;
    } else {
        print "<tr><td><em>No Plugins Found</em></td></tr>";
    }
    html_end_box(false);
    html_start_box("", "100%", "", "3", "center", "");
    echo "<tr><td colspan=10><strong>NOTE:</strong> Please sort by 'Load Order' to change plugin load ordering.<br><strong>NOTE:</strong> SYSTEM plugins can not be ordered.</td></tr>";
    html_end_box();
    print "</form>\n";
}
Example #20
0
		' . (empty($_REQUEST['graph_template_id']) ? '' : ' and graph_local.graph_template_id=' . $_REQUEST['graph_template_id']);
        $total_rows = count(db_fetch_assoc("select\n\t\tgraph_templates_graph.local_graph_id\n\t\t{$sql_base}"));
        $graphs = db_fetch_assoc("select\n\t\tgraph_templates_graph.local_graph_id,\n\t\thost.description,\n\t\tgraph_templates.name AS template_name,\n\t\tgraph_templates_graph.title_cache,\n\t\tgraph_templates_graph.height,\n\t\tgraph_templates_graph.width\n\t\t{$sql_base}\n\t\tgroup by graph_templates_graph.local_graph_id\n\t\torder by graph_templates_graph.title_cache\n\t\tlimit " . $_REQUEST['rows'] * ($_REQUEST['page'] - 1) . ',' . $_REQUEST['rows']);
        ?>

	<form name='chk' id='chk' action='graph_view.php' method='get' onSubmit='form_graph(document.chk,document.chk)'>

	<?php 
        html_start_box('', '100%', '', '3', 'center', '');
        $nav = html_nav_bar("graph_view.php?action=list", MAX_DISPLAY_PAGES, get_request_var_request("page"), get_request_var_request("rows"), $total_rows, 5, "Graphs");
        print $nav;
        html_header_checkbox(array('Graph Title', 'Host', 'Graph Template', 'Graph Size'), false);
        $i = 0;
        if (sizeof($graphs)) {
            foreach ($graphs as $graph) {
                form_alternate_row('line' . $graph['local_graph_id'], true);
                form_selectable_cell("<strong><a href='" . htmlspecialchars('graph.php?local_graph_id=' . $graph['local_graph_id'] . '&rra_id=all') . "'>" . htmlspecialchars($graph['title_cache']) . '</a></strong>', $graph['local_graph_id'], '30%');
                form_selectable_cell($graph['description'], $graph['local_graph_id']);
                form_selectable_cell($graph['template_name'], $graph['local_graph_id']);
                form_selectable_cell($graph['height'] . 'x' . $graph['width'], $graph['local_graph_id']);
                form_checkbox_cell($graph['title_cache'], $graph['local_graph_id']);
                form_end_row();
            }
            print $nav;
        }
        html_end_box();
        ?>
	<table align='right'>
	<tr>
		<td align='right'><img src='images/arrow.gif' alt=''>&nbsp;</td>
		<td align='right'><input type='submit' value='View' title='View Graphs'></td>
Example #21
0
function webseer_urls($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')), 'associated' => array('filter' => FILTER_CALLBACK, 'default' => 'true', 'options' => array('options' => 'sanitize_search_string')));
    validate_store_request_vars($filters, 'sess_maint_ws');
    /* ================= 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=webseer&action=edit&id=<?php 
    print get_request_var('id');
    ?>
';
		strURL += '&rows=' + $('#rows').val();
		strURL += '&associated=' + $('#associated').is(':checked');
		strURL += '&filter=' + $('#filter').val();
		strURL += '&header=false';
		loadPageNoHeader(strURL);
	}

	function clearFilter() {
		strURL = 'maint.php?tab=webseer&action=edit&id=<?php 
    print get_request_var('id');
    ?>
&clear=true&header=false';
		loadPageNoHeader(strURL);
	}
	</script>
	<?php 
    html_start_box(__('Associated Web URL\'s ') . htmlspecialchars($header_label), '100%', '', '3', 'center', '');
    ?>
	<tr class='even'>
		<td>
		<form name='form_devices' method='post' action='maint.php?action=edit&tab=webseer'>
			<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 __('Rules');
    ?>
					</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' name='page' value='<?php 
    print get_request_var('page');
    ?>
'>
			<input type='hidden' name='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 ((u.url LIKE '%" . get_request_var('filter') . "%') \n\t\t\tOR (u.display_name LIKE '%" . get_request_var('filter') . "%') \n\t\t\tOR (u.ip LIKE '%" . get_request_var('filter') . "%'))";
    } else {
        $sql_where = '';
    }
    if (get_request_var('associated') == 'false') {
        $sql_where .= (strlen($sql_where) ? ' AND ' : 'WHERE ') . ' (pmh.type=2 OR pmh.type IS NULL)';
    } else {
        $sql_where .= (strlen($sql_where) ? ' AND ' : 'WHERE ') . ' pmh.type=2 AND pmh.schedule=' . get_request_var('id');
    }
    $total_rows = db_fetch_cell("SELECT\n\t\tCOUNT(*)\n\t\tFROM plugin_webseer_urls AS u\n\t\tLEFT JOIN plugin_maint_hosts AS pmh\n\t\tON u.id=pmh.host\n\t\t{$sql_where}");
    $sql_query = "SELECT u.*, pmh.host AS associated, pmh.type AS maint_type\n\t\tFROM plugin_webseer_urls AS u\n\t\tLEFT JOIN plugin_maint_hosts AS pmh\n\t\tON u.id=pmh.host\n\t\t{$sql_where} \n\t\tLIMIT " . $rows * (get_request_var('page') - 1) . ',' . $rows;
    $urls = 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, 13, __('Lists'), 'page', 'main');
    form_start('maint.php', 'chk');
    print $nav;
    html_start_box('', '100%', '', '3', 'center', '');
    $display_text = array(__('Description'), __('ID'), __('Associated Schedules'), __('Enabled'), __('Hostname'), __('URL'));
    html_header_checkbox($display_text);
    if (sizeof($urls)) {
        foreach ($urls as $url) {
            form_alternate_row('line' . $url['id']);
            form_selectable_cell(strlen(get_request_var('filter')) ? preg_replace('/(' . preg_quote(get_request_var('filter')) . ')/i', "<span class='filteredValue'>\\1</span>", htmlspecialchars($url['display_name'])) : htmlspecialchars($url['display_name']), $url['id'], 250);
            form_selectable_cell(round($url['id'], 2), $url['id']);
            if ($url['associated'] != '' && $url['maint_type'] == '2') {
                form_selectable_cell('<span class="deviceUp">' . __('Current Schedule') . '</span>', $url['id']);
            } else {
                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=2 AND host=' . $url['id']))) {
                    $names = '';
                    foreach ($lists['name'] as $name) {
                        $names .= (strlen($names) ? ', ' : '') . "<span class='deviceRecovering'>{$name}</span>";
                    }
                    form_selectable_cell($names, $url['id']);
                } else {
                    form_selectable_cell('<span class="deviceUnknown">' . __('No Schedules') . '</span>', $url['id']);
                }
            }
            form_selectable_cell($url['enabled'] == 'on' ? __('Enabled') : __('Disabled'), $url['id']);
            if (empty($url['ip'])) {
                $url['ip'] = __('USING DNS');
            }
            form_selectable_cell(strlen(get_request_var('filter')) ? preg_replace('/(' . preg_quote(get_request_var('filter')) . ')/i', "<span class='filteredValue'>\\1</span>", '<i>' . htmlspecialchars($url['ip'])) . '</i>' : '<i>' . htmlspecialchars($url['ip']) . '</i>', $url['id']);
            form_selectable_cell(strlen(get_request_var('filter')) ? preg_replace('/(' . preg_quote(get_request_var('filter')) . ')/i', "<span class='filteredValue'>\\1</span>", htmlspecialchars($url['url'])) : htmlspecialchars($url['url']), $url['id']);
            form_checkbox_cell($url['display_name'], $url['id']);
            form_end_row();
        }
    } else {
        print "<tr><td><em>" . __('No Associated WebSeer URL\'s Found') . "</em></td></tr>";
    }
    html_end_box(false);
    if (sizeof($urls)) {
        print $nav;
    }
    form_hidden_box('id', get_request_var('id'), '');
    form_hidden_box('save_webseer', '1', '');
    /* draw the dropdown containing a list of available actions for this form */
    draw_actions_dropdown($assoc_actions);
    form_end();
}
function show_devices()
{
    global $action, $expire_arr, $rotation_arr, $version_arr, $nesting_arr;
    global $config, $flow_actions;
    /* ================= input validation and session storage ================= */
    $filters = array('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' => 'name', '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_fvd');
    /* ================= input validation ================= */
    $sql_where = get_request_var('filter') != '' ? "name LIKE '%" . get_request_var('filter') . "%'" : '';
    $num_rows = read_config_option('num_rows_table');
    $sql = "SELECT * \n\t\tFROM plugin_flowview_devices \n\t\t{$sql_where}\n\t\tORDER BY " . get_request_var('sort_column') . ' ' . get_request_var('sort_direction') . ' LIMIT ' . ($num_rows * (get_request_var('page') - 1) . ',' . $num_rows);
    $result = db_fetch_assoc($sql);
    $total_rows = db_fetch_cell("SELECT COUNT(*) FROM plugin_flowview_devices {$sql_where}");
    html_start_box('FlowView Listeners', '100%', '', '4', 'center', 'flowview_devices.php?action=edit');
    ?>
	<tr class='even'>
		<td>
		<form name='listeners' action='flowview_devices.php'>
			<table class='fitlerTable'>
				<tr>
					<td>
						Search
					</td>
					<td>
						<input type='text' id='filter' size='40' value='<?php 
    print htmlspecialchars(get_request_var('filter'));
    ?>
'>
					</td>
					<td>
						<input id='refresh' type='button' value='Go' title='Set/Refresh Filters'>
					</td>
					<td>
						<input id='clear' type='button' name='clear' value='Clear' title='Clear Filters'>
					</td>
				</tr>
			</table>
		<input type='hidden' name='page' value='<?php 
    print get_request_var('page');
    ?>
'>
		</form>
		</td>
	</tr>
	<?php 
    html_end_box();
    $nav = html_nav_bar('flowview_devices.php', MAX_DISPLAY_PAGES, get_request_var('page'), $num_rows, $total_rows, 10, 'Listeners', 'page', 'main');
    form_start('flowview_devices.php', 'chk');
    print $nav;
    html_start_box('', '100%', '', '4', 'center', '');
    $display_array = array('name' => array('Name', 'ASC'), 'folder' => array('Directory', 'ASC'), 'nexting' => array('Nesting', 'ASC'), 'allowfrom' => array('Allowed From', 'ASC'), 'port' => array('Port', 'ASC'), 'version' => array('Version', 'ASC'), 'compression' => array('Compression', 'ASC'), 'rotation' => array('Rotation', 'ASC'), 'expire' => array('Expire', 'ASC'));
    html_header_sort_checkbox($display_array, get_request_var('sort_column'), get_request_var('sort_direction'), false);
    if (count($result)) {
        foreach ($result as $row) {
            form_alternate_row('line' . $row['id'], true);
            form_selectable_cell('<a class="linkEditMain" href="flowview_devices.php?&tab=listeners&action=edit&id=' . $row['id'] . '">' . $row['name'] . '</a>', $row['id']);
            form_selectable_cell($row['folder'], $row['id']);
            form_selectable_cell($nesting_arr[$row['nesting']], $row['id']);
            form_selectable_cell($row['allowfrom'], $row['id']);
            form_selectable_cell($row['port'], $row['id']);
            form_selectable_cell($version_arr[$row['version']], $row['id']);
            form_selectable_cell($row['compression'], $row['id']);
            form_selectable_cell($rotation_arr[$row['rotation']], $row['id']);
            form_selectable_cell($expire_arr[$row['expire']], $row['id']);
            form_checkbox_cell($row['name'], $row['id']);
            form_end_row();
        }
    } else {
        print "<tr class='even'><td colspan=10><center>No Devices</center></td></tr>\n";
    }
    html_end_box(false);
    if (count($result)) {
        print $nav;
    }
    draw_actions_dropdown($flow_actions);
    form_end();
}
function mactrack_view_sites()
{
    global $title, $config, $item_rows;
    mactrack_sites_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_site_filter('mactrack_view_sites.php');
    html_end_box();
    $sql_where = '';
    $sites = mactrack_view_get_site_records($sql_where, $row_limit);
    if (get_request_var('detail') == 'false') {
        $total_rows = db_fetch_cell("SELECT\n\t\t\tCOUNT(mac_track_sites.site_id)\n\t\t\tFROM mac_track_sites\n\t\t\t{$sql_where}");
    } else {
        $total_rows = sizeof(db_fetch_assoc("SELECT\n\t\t\tmac_track_device_types.device_type_id, mac_track_sites.site_name\n\t\t\tFROM (mac_track_device_types\n\t\t\tRIGHT JOIN mac_track_devices ON (mac_track_device_types.device_type_id = mac_track_devices.device_type_id))\n\t\t\tRIGHT JOIN mac_track_sites ON (mac_track_devices.site_id = mac_track_sites.site_id)\n\t\t\t{$sql_where}\n\t\t\tGROUP BY mac_track_sites.site_name, mac_track_device_types.device_type_id"));
    }
    $nav = html_nav_bar('mactrack_view_sites.php', MAX_DISPLAY_PAGES, get_request_var('page'), $row_limit, $total_rows, 11, __('Sites'));
    print $nav;
    html_start_box('', '100%', '', '3', 'center', '');
    if (get_request_var('detail') == 'false') {
        $display_text = array('nosort' => array(__('Actions'), ''), 'site_name' => array(__('Site Name'), 'ASC'), 'total_devices' => array(__('Devices'), 'DESC'), 'total_ips' => array(__('Total IP\'s'), 'DESC'), 'total_user_ports' => array(__('User Ports'), 'DESC'), 'total_oper_ports' => array(__('User Ports Up'), 'DESC'), 'total_macs' => array(__('MACS Found'), 'DESC'), 'total_device_errors' => array(__('Device Errors'), 'DESC'));
        html_header_sort($display_text, get_request_var('sort_column'), get_request_var('sort_direction'));
        if (sizeof($sites) > 0) {
            foreach ($sites as $site) {
                form_alternate_row('row_' . $site['site_id'], true);
                ?>
					<td width=140>
						<?php 
                if (api_user_realm_auth('mactrack_sites.php')) {
                    echo "<a href='" . htmlspecialchars($webroot . 'mactrack_sites.php?action=edit&site_id=' . $site['site_id']) . "' title='" . __('Edit Site') . "'><img border='0' src='" . $webroot . "images/edit_object.png'></a>";
                    echo "<a href='#'><img id='r_" . $site['site_id'] . "' src='" . $webroot . "images/rescan_site.gif' alt='' onClick='site_scan(" . $site['site_id'] . ")' title='" . __('Rescan Site') . "' border='0'></a>";
                }
                ?>
						<a href='<?php 
                print htmlspecialchars($webroot . 'mactrack_view_devices.php?report=devices&reset&site_id=' . $site['site_id']);
                ?>
' title='<?php 
                print __('View Devices');
                ?>
'><img border='0' src='<?php 
                print $webroot;
                ?>
images/view_devices.gif'></a>
						<a href='<?php 
                print htmlspecialchars($webroot . 'mactrack_view_ips.php?report=ips&reset&site_id=' . $site['site_id']);
                ?>
' title='<?php 
                print __('View IP Ranges');
                ?>
'><img border='0' src='<?php 
                print $webroot;
                ?>
images/view_networks.gif'></a>
						<a href='<?php 
                print htmlspecialchars($webroot . 'plugins/mactrack/mactrack_view_arp.php?report=arp&reset&site_id=' . $site['site_id']);
                ?>
' title='<?php 
                print __('View IP Addresses');
                ?>
'><img border='0' src='<?php 
                print $webroot;
                ?>
images/view_ipaddresses.gif'></a>
						<a href='<?php 
                print htmlspecialchars($webroot . 'plugins/mactrack/mactrack_view_macs.php?report=macs&reset&device_id=-1&scan_date=3&site_id=' . $site['site_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=' . $site['site_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($site['site_name'], get_request_var('filter'));
                ?>
					</td>
					<td><?php 
                print number_format_i18n($site['total_devices']);
                ?>
</td>
					<td><?php 
                print number_format_i18n($site['total_ips']);
                ?>
</td>
					<td><?php 
                print number_format_i18n($site['total_user_ports']);
                ?>
</td>
					<td><?php 
                print number_format_i18n($site['total_oper_ports']);
                ?>
</td>
					<td><?php 
                print number_format_i18n($site['total_macs']);
                ?>
</td>
					<td><?php 
                print $site['total_device_errors'];
                ?>
</td>
				</tr>
				<?php 
            }
        } else {
            print '<tr><td colspan="10"><em>' . __('No MacTrack Sites') . '</em></td></tr>';
        }
        html_end_box(false);
        if (sizeof($sites)) {
            print $nav;
            mactrack_display_stats();
        }
    } else {
        $display_text = array('nosort' => array(__('Actions'), ''), 'site_name' => array(__('Site Name'), 'ASC'), 'vendor' => array(__('Vendor'), 'ASC'), 'description' => array(__('Device Type'), 'DESC'), 'total_devices' => array(__('Total Devices'), 'DESC'), 'sum_ips_total' => array(__('Total IP\'s'), 'DESC'), 'sum_ports_total' => array(__('Total User Ports'), 'DESC'), 'sum_ports_active' => array(__('Total Oper Ports'), 'DESC'), 'sum_ports_trunk' => array(__('Total Trunks'), 'DESC'), 'sum_macs_active' => array(__('MACS Found'), 'DESC'));
        html_header_sort($display_text, get_request_var('sort_column'), get_request_var('sort_direction'));
        if (sizeof($sites)) {
            foreach ($sites as $site) {
                form_alternate_row();
                ?>
					<td width=100>
						<?php 
                if (api_user_realm_auth('mactrack_sites.php')) {
                    echo "<a href='" . htmlspecialchars($webroot . 'mactrack_sites.php?action=edit&site_id=' . $site['site_id']) . "' title='" . __('Edit Site') . "'><img border='0' src='" . $webroot . "images/edit_object.png'></a>";
                }
                ?>
						<a href='<?php 
                print htmlspecialchars($webroot . 'mactrack_view_devices.php?report=devices&site_id=' . $site['site_id'] . '&device_type_id=' . $site['device_type_id'] . '&type_id=-1&status=-1&filter=');
                ?>
' title='<?php 
                print __('View Devices');
                ?>
'><img border='0' src='<?php 
                print $webroot;
                ?>
images/view_devices.gif'></a>
						<a href='<?php 
                print htmlspecialchars($webroot . 'mactrack_view_ips.php?report=ips&reset&site_id=' . $site['site_id']);
                ?>
' title='<?php 
                print __('View IP Ranges');
                ?>
'><img border='0' src='<?php 
                print $webroot;
                ?>
images/view_networks.gif'></a>
						<a href='<?php 
                print htmlspecialchars($webroot . 'mactrack_view_macs.php?report=macs&reset&device_id=-1&scan_date=3&site_id=' . $site['site_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=' . $site['site_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($site['site_name'], get_request_var('filter'));
                ?>
					</td>
					<td><?php 
                print filter_value($site['vendor'], get_request_var('filter'));
                ?>
					<td><?php 
                print filter_value($site['description'], get_request_var('filter'));
                ?>
					<td><?php 
                print number_format_i18n($site['total_devices']);
                ?>
</td>
					<td><?php 
                print $site['device_type'] == '1' ? __('N/A') : number_format_i18n($site['sum_ips_total']);
                ?>
</td>
					<td><?php 
                print $site['device_type'] == '3' ? __('N/A') : number_format_i18n($site['sum_ports_total']);
                ?>
</td>
					<td><?php 
                print $site['device_type'] == '3' ? __('N/A') : number_format_i18n($site['sum_ports_active']);
                ?>
</td>
					<td><?php 
                print $site['device_type'] == '3' ? __('N/A') : number_format_i18n($site['sum_ports_trunk']);
                ?>
</td>
					<td><?php 
                print $site['device_type'] == '3' ? __('N/A') : number_format_i18n($site['sum_macs_active']);
                ?>
</td>
				</tr>
				<?php 
            }
        } else {
            print '<tr><td colspan="10"><em>' . __('No MacTrack Sites') . '</em></td></tr>';
        }
        html_end_box(false);
        if (sizeof($sites)) {
            print $nav;
            mactrack_display_stats();
        }
    }
    print '<div id="response"></div>';
}
Example #24
0
function rra()
{
    /* 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"));
    }
    /* remember these search fields in session vars so we don't have to keep passing them around */
    load_current_session_value("sort_column", "sess_rra_sort_column", "timespan");
    load_current_session_value("sort_direction", "sess_rra_sort_direction", "ASC");
    html_start_box("<strong>Round Robin Archives</strong>", "100%", "", "3", "center", "rra.php?action=edit");
    $display_text = array("name" => array("Name", "ASC"), "steps" => array("Steps", "ASC"), "rows" => array("Rows", "ASC"), "timespan" => array("Timespan", "ASC"));
    html_header_sort($display_text, $_REQUEST["sort_column"], $_REQUEST["sort_direction"], 4);
    $rras = db_fetch_assoc("SELECT\n\t\tid,\n\t\tname,\n\t\trows,\n\t\tsteps,\n\t\ttimespan\n\t\tFROM rra\n\t\tORDER BY " . $_REQUEST['sort_column'] . " " . $_REQUEST['sort_direction']);
    $i = 0;
    if (sizeof($rras) > 0) {
        foreach ($rras as $rra) {
            form_alternate_row('', true);
            ?>
			<td>
				<a class="linkEditMain" href="<?php 
            print htmlspecialchars("rra.php?action=edit&id=" . $rra["id"]);
            ?>
"><?php 
            print htmlspecialchars($rra["name"]);
            ?>
</a>
			</td>
			<td>
				<?php 
            print $rra["steps"];
            ?>
			</td>
			<td>
				<?php 
            print $rra["rows"];
            ?>
			</td>
			<td>
				<?php 
            print $rra["timespan"];
            ?>
			</td>
			<td align="right">
				<a href="<?php 
            print htmlspecialchars("rra.php?action=remove&id=" . $rra["id"]);
            ?>
"><img src="images/delete_icon.gif" style="height:10px;width:10px;" border="0" alt="Delete"></a>
			</td>
		</tr>
	<?php 
        }
    }
    html_end_box();
}
Example #25
0
function template()
{
    global $host_actions, $item_rows;
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_request('page'));
    input_validate_input_number(get_request_var_request('rows'));
    /* ==================================================== */
    /* clean up has_hosts string */
    if (isset($_REQUEST['has_hosts'])) {
        $_REQUEST['has_hosts'] = sanitize_search_string(get_request_var_request('has_hosts'));
    }
    /* clean up search string */
    if (isset($_REQUEST['filter'])) {
        $_REQUEST['filter'] = sanitize_search_string(get_request_var_request('filter'));
    }
    /* clean up sort_column */
    if (isset($_REQUEST['sort_column'])) {
        $_REQUEST['sort_column'] = sanitize_search_string(get_request_var_request('sort_column'));
    }
    /* clean up sort_direction string */
    if (isset($_REQUEST['sort_direction'])) {
        $_REQUEST['sort_direction'] = sanitize_search_string(get_request_var_request('sort_direction'));
    }
    /* if the user pushed the 'clear' button */
    if (isset($_REQUEST['clear_x'])) {
        kill_session_var('sess_host_template_current_page');
        kill_session_var('sess_host_template_hosts');
        kill_session_var('sess_host_template_filter');
        kill_session_var('sess_default_rows');
        kill_session_var('sess_host_template_sort_column');
        kill_session_var('sess_host_template_sort_direction');
        unset($_REQUEST['page']);
        unset($_REQUEST['has_hosts']);
        unset($_REQUEST['filter']);
        unset($_REQUEST['rows']);
        unset($_REQUEST['sort_column']);
        unset($_REQUEST['sort_direction']);
    } else {
        $changed = 0;
        $changed += check_changed('has_hosts', 'sess_host_template_has_hosts');
        $changed += check_changed('rows', 'sess_default_rows');
        $changed += check_changed('filter', 'sess_host_template_filter');
        if ($changed) {
            $_REQUEST['page'] = 1;
        }
    }
    /* remember these search fields in session vars so we don't have to keep passing them around */
    load_current_session_value('page', 'sess_host_template_current_page', '1');
    load_current_session_value('has_hosts', 'sess_host_template_has_hosts', 'true');
    load_current_session_value('filter', 'sess_host_template_filter', '');
    load_current_session_value('sort_column', 'sess_host_template_sort_column', 'name');
    load_current_session_value('sort_direction', 'sess_host_template_sort_direction', 'ASC');
    load_current_session_value('rows', 'sess_default_rows', read_config_option('num_rows_table'));
    display_output_messages();
    html_start_box('<strong>Device Templates</strong>', '100%', '', '3', 'center', 'host_templates.php?action=edit');
    ?>
	<tr class='even noprint'>
		<td>
		<form id="form_host_template" action="host_templates.php">
			<table cellpadding="2" cellspacing="0" border="0">
				<tr>
					<td width="50">
						Search
					</td>
					<td>
						<input id='filter' type="text" name="filter" size="25" value="<?php 
    print htmlspecialchars(get_request_var_request('filter'));
    ?>
">
					</td>
					<td style='white-space:nowrap;'>
						Device Templates
					</td>
					<td>
						<select id='rows' name="rows" onChange="applyFilter()">
							<?php 
    if (sizeof($item_rows) > 0) {
        foreach ($item_rows as $key => $value) {
            print "<option value='" . $key . "'";
            if (get_request_var_request('rows') == $key) {
                print ' selected';
            }
            print '>' . htmlspecialchars($value) . "</option>\n";
        }
    }
    ?>
						</select>
					</td>
					<td>
						<input type="checkbox" id='has_hosts' <?php 
    print $_REQUEST['has_hosts'] == 'true' ? 'checked' : '';
    ?>
>
					</td>
					<td>
						<label for='has_hosts' style='white-space:nowrap;'>Has Devices</label>
					</td>
					<td>
						<input type="button" id='refresh' value="Go" title="Set/Refresh Filters">
					</td>
					<td>
						<input type="button" id='clear' name="clear_x" value="Clear" title="Clear Filters">
					</td>
				</tr>
			</table>
		<input type='hidden' id='page' name='page' value='<?php 
    print $_REQUEST['page'];
    ?>
'>
		</form>
		</td>
		<script type='text/javascript'>
		function applyFilter() {
			strURL = 'host_templates.php?filter='+$('#filter').val()+'&rows='+$('#rows').val()+'&page='+$('#page').val()+'&has_hosts='+$('#has_hosts').is(':checked')+'&header=false';
			$.get(strURL, function(data) {
				$('#main').html(data);
				applySkin();
			});
		}

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

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

			$('#clear').click(function() {
				clearFilter();
			});
	
			$('#form_host_template').submit(function(event) {
				event.preventDefault();
				applyFilter();
			});
		});
		</script>
	</tr>
	<?php 
    html_end_box();
    /* form the 'where' clause for our main sql query */
    if (strlen($_REQUEST['filter'])) {
        $sql_where = "WHERE (host_template.name LIKE '%%" . get_request_var_request('filter') . "%%')";
    } else {
        $sql_where = '';
    }
    /* print checkbox form for validation */
    print "<form name='chk' method='post' action='host_templates.php'>\n";
    html_start_box('', '100%', '', '3', 'center', '');
    if ($_REQUEST['has_hosts'] == 'true') {
        $sql_having = 'HAVING hosts>0';
    } else {
        $sql_having = '';
    }
    $total_rows = db_fetch_cell("SELECT COUNT(rows)\n\t\tFROM (\n\t\t\tSELECT\n\t\t\tCOUNT(host_template.id) AS rows, COUNT(DISTINCT host.id) AS hosts\n\t\t\tFROM host_template\n\t\t\tLEFT JOIN host ON host.host_template_id=host_template.id\n\t\t\t{$sql_where}\n\t\t\tGROUP BY host_template.id\n\t\t\t{$sql_having}\n\t\t) AS rs");
    $template_list = db_fetch_assoc("SELECT\n\t\thost_template.id,host_template.name, COUNT(DISTINCT host.id) AS hosts\n\t\tFROM host_template\n\t\tLEFT JOIN host ON host.host_template_id=host_template.id\n\t\t{$sql_where}\n\t\tGROUP BY host_template.id\n\t\t{$sql_having}\n\t\tORDER BY " . get_request_var_request('sort_column') . ' ' . get_request_var_request('sort_direction') . ' LIMIT ' . get_request_var_request('rows') * (get_request_var_request('page') - 1) . ',' . get_request_var_request('rows'));
    $nav = html_nav_bar('host_templates.php?filter=' . get_request_var_request('filter'), MAX_DISPLAY_PAGES, get_request_var_request('page'), get_request_var_request('rows'), $total_rows, 5, 'Device Templates', 'page', 'main');
    print $nav;
    $display_text = array('name' => array('display' => 'Device Template Name', 'align' => 'left', 'sort' => 'ASC', 'tip' => 'The name of this Device Template.'), "nosort" => array('display' => 'Deletable', 'align' => 'right', 'sort' => '', 'tip' => 'Device Templates in use can not be Deleted.  In use is defined as being referenced by a Device.'), 'hosts' => array('display' => 'Devices Using', 'align' => 'right', 'sort' => 'DESC', 'tip' => 'The number of Devices using this Device Template.'), 'host_template.id' => array('display' => 'ID', 'align' => 'right', 'sort' => 'ASC', 'tip' => 'The internal database ID for this Device Template.  Useful when performing automation or debugging.'));
    html_header_sort_checkbox($display_text, get_request_var_request('sort_column'), get_request_var_request('sort_direction'), false);
    $i = 0;
    if (sizeof($template_list) > 0) {
        foreach ($template_list as $template) {
            if ($template['hosts'] > 0) {
                $disabled = true;
            } else {
                $disabled = false;
            }
            form_alternate_row('line' . $template['id'], true, $disabled);
            form_selectable_cell("<a class='linkEditMain' href='" . htmlspecialchars('host_templates.php?action=edit&id=' . $template['id']) . "'>" . (strlen(get_request_var_request('filter')) ? preg_replace('/(' . preg_quote(get_request_var_request('filter'), '/') . ')/i', "<span class='filteredValue'>\\1</span>", htmlspecialchars($template['name'])) : htmlspecialchars($template['name'])) . '</a>', $template['id']);
            form_selectable_cell($disabled ? 'No' : 'Yes', $template['id'], '', 'text-align:right');
            form_selectable_cell(number_format($template['hosts']), $template['id'], '', 'text-align:right');
            form_selectable_cell($template['id'], $template['id'], '', 'text-align:right');
            form_checkbox_cell($template['name'], $template['id'], $disabled);
            form_end_row();
        }
        /* put the nav bar on the bottom as well */
        print $nav;
    } else {
        print "<tr class='tableRow'><td colspan='4'><em>No Device Templates</em></td></tr>\n";
    }
    html_end_box(false);
    /* draw the dropdown containing a list of available actions for this form */
    draw_actions_dropdown($host_actions);
    print "</form>\n";
}
Example #26
0
function mactrack_snmp()
{
    global $config, $item_rows;
    global $mactrack_snmp_actions;
    /* ================= 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' => 'name', '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_mactrack_snmp');
    /* ================= input validation ================= */
    if (get_request_var('rows') == '-1') {
        $rows = read_config_option('num_rows_table');
    } else {
        $rows = get_request_var('rows');
    }
    html_start_box(__('Mactrack SNMP Options'), '100%', '', '3', 'center', 'mactrack_snmp.php?action=edit');
    snmp_options_filter();
    html_end_box();
    /* form the 'where' clause for our main sql query */
    $sql_where = '';
    if (get_request_var('filter') != '') {
        $sql_where .= "WHERE (mac_track_snmp.name LIKE '%" . get_request_var('filter') . "%')";
    }
    $total_rows = db_fetch_cell("SELECT\n\t\tCOUNT(mac_track_snmp.id)\n\t\tFROM mac_track_snmp\n\t\t{$sql_where}");
    $snmp_groups = db_fetch_assoc("SELECT *\n\t\tFROM mac_track_snmp\n\t\t{$sql_where}\n\t\tORDER BY " . get_request_var('sort_column') . ' ' . get_request_var('sort_direction') . '
		LIMIT ' . $rows * (get_request_var('page') - 1) . ',' . $rows);
    $nav = html_nav_bar('mactrack_snmp.php?filter=' . get_request_var('filter'), MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, 12, __('SNMP Settings'));
    print $nav;
    html_start_box('', '100%', '', '3', 'center', '');
    $display_text = array('name' => array(__('Title of SNMP Option Set'), 'ASC'));
    html_header_sort_checkbox($display_text, get_request_var('sort_column'), get_request_var('sort_direction'));
    if (sizeof($snmp_groups)) {
        foreach ($snmp_groups as $snmp_group) {
            form_alternate_row('line' . $snmp_group['id'], true);
            form_selectable_cell(filter_value($snmp_group['name'], get_request_var('filter'), 'mactrack_snmp.php?action=edit&id=' . $snmp_group['id'] . '&page=1'), $snmp_group['id']);
            form_checkbox_cell($snmp_group['name'], $snmp_group['id']);
            form_end_row();
        }
    } else {
        print '<tr><td colspan="3"><em>' . __('No SNMP Option Sets') . '</em></td></tr>';
    }
    html_end_box(false);
    if (sizeof($snmp_groups)) {
        print $nav;
    }
    draw_actions_dropdown($mactrack_snmp_actions);
    form_end();
}
Example #27
0
function template()
{
    global $ds_actions;
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_request("page"));
    /* ==================================================== */
    /* clean up search string */
    if (isset($_REQUEST["filter"])) {
        $_REQUEST["filter"] = sanitize_search_string(get_request_var("filter"));
    }
    /* clean up sort_column string */
    if (isset($_REQUEST["sort_column"])) {
        $_REQUEST["sort_column"] = sanitize_search_string(get_request_var("sort_column"));
    }
    /* clean up sort_direction string */
    if (isset($_REQUEST["sort_direction"])) {
        $_REQUEST["sort_direction"] = sanitize_search_string(get_request_var("sort_direction"));
    }
    /* if the user pushed the 'clear' button */
    if (isset($_REQUEST["clear_x"])) {
        kill_session_var("sess_data_template_current_page");
        kill_session_var("sess_data_template_filter");
        kill_session_var("sess_data_template_sort_column");
        kill_session_var("sess_data_template_sort_direction");
        unset($_REQUEST["page"]);
        unset($_REQUEST["filter"]);
        unset($_REQUEST["sort_column"]);
        unset($_REQUEST["sort_direction"]);
    }
    /* remember these search fields in session vars so we don't have to keep passing them around */
    load_current_session_value("page", "sess_data_template_current_page", "1");
    load_current_session_value("filter", "sess_data_template_filter", "");
    load_current_session_value("sort_column", "sess_data_template_sort_column", "name");
    load_current_session_value("sort_direction", "sess_data_template_sort_direction", "ASC");
    html_start_box("<strong>Data Templates</strong>", "100%", "", "3", "center", "data_templates.php?action=template_edit");
    ?>
	<tr class='even noprint'>
		<td>
		<form name="form_data_template" action="data_templates.php">
			<table width="100%" cellpadding="0" cellspacing="0">
				<tr>
					<td nowrap style='white-space: nowrap;' width="50">
						Search:&nbsp;
					</td>
					<td width="1">
						<input type="text" name="filter" size="40" value="<?php 
    print htmlspecialchars(get_request_var_request("filter"));
    ?>
">
					</td>
					<td nowrap style='white-space: nowrap;'>
						&nbsp;<input type="submit" value="Go" title="Set/Refresh Filters">
						<input type="submit" name="clear_x" value="Clear" title="Clear Filters">
					</td>
				</tr>
			</table>
			<input type='hidden' name='page' value='1'>
		</form>
		</td>
	</tr>
	<?php 
    html_end_box();
    /* form the 'where' clause for our main sql query */
    $sql_where = "WHERE data_template.id=data_template_data.data_template_id AND data_template_data.local_data_id=0";
    $rows_where = "";
    if (strlen($_REQUEST['filter'])) {
        $sql_where .= " AND (data_template.name like '%%" . get_request_var_request("filter") . "%%')";
        $rows_where = "WHERE (data_template.name like '%%" . get_request_var_request("filter") . "%%')";
    }
    /* print checkbox form for validation */
    print "<form name='chk' method='post' action='data_templates.php'>\n";
    html_start_box("", "100%", "", "3", "center", "");
    $total_rows = db_fetch_cell("SELECT\n\t\tCOUNT(data_template.id)\n\t\tFROM data_template\n\t\t{$rows_where}");
    $template_list = db_fetch_assoc("SELECT\n\t\tdata_template.id,\n\t\tdata_template.name,\n\t\tdata_input.name AS data_input_method,\n\t\tdata_template_data.active AS active\n\t\tFROM (data_template,data_template_data)\n\t\tLEFT JOIN data_input\n\t\tON (data_template_data.data_input_id = data_input.id)\n\t\t{$sql_where}\n\t\tGROUP BY data_template.id\n\t\tORDER BY " . get_request_var_request("sort_column") . " " . get_request_var_request("sort_direction") . " LIMIT " . read_config_option("num_rows_device") * (get_request_var_request("page") - 1) . "," . read_config_option("num_rows_device"));
    $nav = html_nav_bar("data_templates.php?filter=" . get_request_var_request("filter"), MAX_DISPLAY_PAGES, get_request_var_request("page"), read_config_option("num_rows_device"), $total_rows, 5);
    print $nav;
    $display_text = array("name" => array("Template Name", "ASC"), "id" => array("ID", "ASC"), "data_input_method" => array("Data Input Method", "ASC"), "active" => array("Status", "ASC"));
    html_header_sort_checkbox($display_text, get_request_var_request("sort_column"), get_request_var_request("sort_direction"), false);
    if (sizeof($template_list) > 0) {
        foreach ($template_list as $template) {
            form_alternate_row('line' . $template["id"], true);
            form_selectable_cell("<a class='linkEditMain' href='" . htmlspecialchars("data_templates.php?action=template_edit&id=" . $template["id"]) . "'>" . (strlen(get_request_var_request("filter")) ? preg_replace("/(" . preg_quote(get_request_var_request("filter"), "/") . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", htmlspecialchars($template["name"])) : htmlspecialchars($template["name"])) . "</a>", $template["id"]);
            form_selectable_cell($template['id'], $template["id"]);
            form_selectable_cell(empty($template["data_input_method"]) ? "<em>None</em>" : htmlspecialchars($template["data_input_method"]), $template["id"]);
            form_selectable_cell($template["active"] == "on" ? "Active" : "Disabled", $template["id"]);
            form_checkbox_cell($template["name"], $template["id"]);
            form_end_row();
        }
        /* put the nav bar on the bottom as well */
        print $nav;
    } else {
        print "<tr><td><em>No Data Templates</em></td></tr>\n";
    }
    html_end_box(false);
    /* draw the dropdown containing a list of available actions for this form */
    draw_actions_dropdown($ds_actions);
    print "</form>\n";
}
Example #28
0
function graphs()
{
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_request("host_id"));
    input_validate_input_number(get_request_var_request("graph_type"));
    /* ==================================================== */
    /* clean up search string */
    if (isset($_REQUEST["filter"])) {
        $_REQUEST["filter"] = sanitize_search_string(get_request_var("filter"));
    }
    /* if the user pushed the 'clear' button */
    if (isset($_REQUEST["clear_x"])) {
        kill_session_var("sess_graphs_new_filter");
        unset($_REQUEST["filter"]);
        $changed = true;
    } else {
        /* if any of the settings changed, reset the page number */
        $changed = false;
        $changed += check_changed("host_id", "sess_graphs_new_host_id");
        $changed += check_changed("graph_type", "sess_graphs_new_graph_type");
        $changed += check_changed("filter", "sess_graphs_new_filter");
    }
    load_current_session_value("host_id", "sess_graphs_new_host_id", db_fetch_cell("select id from host order by description,hostname limit 1"));
    load_current_session_value("graph_type", "sess_graphs_new_graph_type", read_config_option("default_graphs_new_dropdown"));
    load_current_session_value("filter", "sess_graphs_new_filter", "");
    $host = db_fetch_row("select id,description,hostname,host_template_id from host where id=" . $_REQUEST["host_id"]);
    $row_limit = read_config_option("num_rows_data_query");
    $debug_log = debug_log_return("new_graphs");
    $header = " [ " . htmlspecialchars($host["description"]) . " (" . htmlspecialchars($host["hostname"]) . ") " . (!empty($host["host_template_id"]) ? htmlspecialchars(db_fetch_cell("select name from host_template where id=" . $host["host_template_id"])) : '') . " ]";
    html_start_box("<strong>New Graphs for</strong> {$header}", "100%", "", "3", "center", "");
    form_alternate_row();
    print "<td>";
    if (!empty($debug_log)) {
        debug_log_clear("new_graphs");
        if (read_config_option("cacti_popup_messages") == "on") {
            ?>
		<div id='message'>
			<?php 
            print "<table align='center' class='cactiTable' width='100%'><tr><td style='align:center;padding:3px;font-weight:bold;font-size:10pt;text-align:center;'>Graphs Created</td><td style='width:1px;align:right;'><input type='button' value='Clear' onClick='javascript:document.getElementById(\"message\").style.display=\"none\"' style='align=right;'></td></tr></table>";
            ?>
			<?php 
            print "<table align='left' style='width:100%;'><tr><td><ul style='text-align:left;white-space:nowrap;color:#000000;padding:2px 10px;margin:10px;'>" . $debug_log . "</ul></td></tr></table>";
            ?>
		</div>
		<?php 
        } else {
            ?>
		<table width='100%' class='textArea' align='center'>
			<tr class='even'>
				<td style="padding: 3px; font-family: monospace;">
					<ul style='margin:0px 5px;padding-left:10px'><?php 
            print $debug_log;
            ?>
</ul>
				</td>
			</tr>
		</table>
		<br><?php 
        }
    }
    ?>
	<script type="text/javascript">
	<!--
	<?php 
    if (read_config_option("cacti_popup_messages") == "on") {
        ?>
	var obj = document.getElementById('message');

	if (obj) {
		if (window.innerHeight) {
			height = window.innerHeight;
			width  = window.innerWidth;
		}else{
			height = document.body.clientHeight;
			width  = document.body.clientWidth;
		}
		obj.style.class = "popupBox";
		cw = obj.offsetWidth;
		// Adjust for IE6
		if (!cw) cw = 150;
		ch = obj.offsetHeight;
		obj.style.top = '65px';
		obj.style.left = ((width/2) - (cw/2) - 88)+'px';
	}
	<?php 
    }
    ?>

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

	-->
	</script>
	<form name="form_graphs_new" action="graphs_new.php">
	<table width="100%" class="textHeader" cellpadding="2" align="left">
		<tr>
			<td width="55" valign='top'>
				Host:
			</td>
			<td width="1" valign='top'>
				<select name="host_id" onChange="applyGraphsNewFilterChange(document.form_graphs_new)">
				<?php 
    $hosts = db_fetch_assoc("select id,CONCAT_WS('',description,' (',hostname,')') as name from host order by description,hostname");
    if (sizeof($hosts) > 0) {
        foreach ($hosts as $item) {
            print "<option value='" . $item["id"] . "'";
            if ($_REQUEST["host_id"] == $item["id"]) {
                print " selected";
            }
            print ">" . htmlspecialchars($item["name"]) . "</option>\n";
        }
    }
    ?>
				</select>
			</td>
			<td style='white-space:nowrap;' valign='top' width="100">
				Graph Types:
			</td>
			<td width="1" valign='top'>
				<select name="graph_type" onChange="applyGraphsNewFilterChange(document.form_graphs_new)">
				<option value="-2"<?php 
    if ($_REQUEST["graph_type"] == "-2") {
        ?>
 selected<?php 
    }
    ?>
>All</option>
				<option value="-1"<?php 
    if ($_REQUEST["graph_type"] == "-1") {
        ?>
 selected<?php 
    }
    ?>
>Graph Template Based</option>
				<?php 
    $snmp_queries = db_fetch_assoc("SELECT\n\t\t\t\t\tsnmp_query.id,\n\t\t\t\t\tsnmp_query.name,\n\t\t\t\t\tsnmp_query.xml_path\n\t\t\t\t\tFROM (snmp_query,host_snmp_query)\n\t\t\t\t\tWHERE host_snmp_query.snmp_query_id=snmp_query.id\n\t\t\t\t\tAND host_snmp_query.host_id=" . $host["id"] . "\n\t\t\t\t\tORDER BY snmp_query.name");
    if (sizeof($snmp_queries) > 0) {
        foreach ($snmp_queries as $query) {
            print "<option value='" . $query["id"] . "'";
            if ($_REQUEST["graph_type"] == $query["id"]) {
                print " selected";
            }
            print ">" . $query["name"] . "</option>\n";
        }
    }
    ?>
				</select>
			</td>
			<td rowspan="2" class="textInfo" align="right" valign="top">
				<span class="linkMarker">*</span><a href="<?php 
    print htmlspecialchars("host.php?action=edit&id=" . $_REQUEST["host_id"]);
    ?>
">Edit this Host</a><br>
				<span class="linkMarker">*</span><a href="<?php 
    print htmlspecialchars("host.php?action=edit");
    ?>
">Create New Host</a><br>
				<?php 
    api_plugin_hook('graphs_new_top_links');
    ?>
			</td>
		</tr>
	<?php 
    if ($_REQUEST["graph_type"] > 0) {
        ?>
		<tr>
			<td width="55" valign='top'>
				Search:
			</td>
			<td valign='top'>
				<input type="text" name="filter" size="30" value="<?php 
        print htmlspecialchars(get_request_var_request("filter"));
        ?>
">
			</td>
			<td colspan='2' valign='top'>
				<input type="submit" value="Go" title="Set/Refresh Filters">
				<input type="submit" name="clear_x" value="Clear" title="Clear Filters">
			</td>
		</tr>
	<?php 
    } else {
        form_hidden_box("filter", $_REQUEST["filter"], "");
    }
    ?>
	</table>
	</form>
	</td>
	</tr>

	<?php 
    html_end_box();
    ?>

	<form name="chk" method="post" action="graphs_new.php">
	<?php 
    $total_rows = sizeof(db_fetch_assoc("select graph_template_id from host_graph where host_id=" . $_REQUEST["host_id"]));
    $i = 0;
    if ($changed) {
        foreach ($snmp_queries as $query) {
            kill_session_var("sess_graphs_new_page" . $query["id"]);
            unset($_REQUEST["page" . $query["id"]]);
            load_current_session_value("page" . $query["id"], "sess_graphs_new_page" . $query["id"], "1");
        }
    }
    if ($_REQUEST["graph_type"] > 0) {
        load_current_session_value("page" . $_REQUEST["graph_type"], "sess_graphs_new_page" . $_REQUEST["graph_type"], "1");
    } else {
        if ($_REQUEST["graph_type"] == -2) {
            foreach ($snmp_queries as $query) {
                load_current_session_value("page" . $query["id"], "sess_graphs_new_page" . $query["id"], "1");
            }
        }
    }
    $script = "<script type='text/javascript'>\nvar gt_created_graphs = new Array();\nvar created_graphs = new Array()\n";
    if ($_REQUEST["graph_type"] < 0) {
        html_start_box("<strong>Graph Templates</strong>", "100%", "", "3", "center", "");
        print "<tr class='tableHeader'>\n\t\t\t\t<td class='tableSubHeaderColumn'>Graph Template Name</td>\n\t\t\t\t<td width='1%' align='center' class='tableSubHeaderCheckbox' style='" . get_checkbox_style() . "'><input type='checkbox' style='margin: 0px;' name='all_cg' title='Select All' onClick='SelectAll(\"cg\",this.checked);gt_update_selection_indicators();'></td>\n\n\t\t\t</tr>\n";
        $graph_templates = db_fetch_assoc("SELECT\n\t\t\tgraph_templates.id AS graph_template_id,\n\t\t\tgraph_templates.name AS graph_template_name\n\t\t\tFROM (host_graph,graph_templates)\n\t\t\tWHERE host_graph.graph_template_id=graph_templates.id\n\t\t\tAND host_graph.host_id=" . $_REQUEST["host_id"] . "\n\t\t\tORDER BY graph_templates.name");
        $template_graphs = db_fetch_assoc("SELECT\n\t\t\tgraph_local.graph_template_id\n\t\t\tFROM (graph_local,host_graph)\n\t\t\tWHERE graph_local.graph_template_id=host_graph.graph_template_id\n\t\t\tAND graph_local.host_id=host_graph.host_id\n\t\t\tAND graph_local.host_id=" . $host["id"] . "\n\t\t\tGROUP BY graph_local.graph_template_id");
        if (sizeof($template_graphs) > 0) {
            $script .= "var gt_created_graphs = new Array(";
            $cg_ctr = 0;
            foreach ($template_graphs as $template_graph) {
                $script .= ($cg_ctr > 0 ? "," : "") . "'" . $template_graph["graph_template_id"] . "'";
                $cg_ctr++;
            }
            $script .= ")\n";
        }
        /* create a row for each graph template associated with the host template */
        if (sizeof($graph_templates) > 0) {
            foreach ($graph_templates as $graph_template) {
                $query_row = $graph_template["graph_template_id"];
                print "<tr id='gt_line{$query_row}' class='" . ($i % 2 == 0 ? "odd" : "even") . "'>";
                $i++;
                print "\t\t<td onClick='gt_select_line(" . $graph_template["graph_template_id"] . ");'>\n\t\t\t\t\t\t<span id='gt_text{$query_row}" . "_0'><strong>Create:</strong> " . htmlspecialchars($graph_template["graph_template_name"]) . "</span>\n\t\t\t\t\t</td>\n\t\t\t\t\t<td align='right'>\n\t\t\t\t\t\t<input type='checkbox' name='cg_{$query_row}' id='cg_{$query_row}' onClick='gt_update_selection_indicators();'>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>";
            }
        }
        $script .= "gt_update_deps(1);\n";
        $available_graph_templates = db_fetch_assoc("SELECT\n\t\t\tgraph_templates.id, graph_templates.name\n\t\t\tFROM snmp_query_graph RIGHT JOIN graph_templates\n\t\t\tON (snmp_query_graph.graph_template_id = graph_templates.id)\n\t\t\tWHERE (((snmp_query_graph.name) Is Null)) ORDER BY graph_templates.name");
        /* create a row at the bottom that lets the user create any graph they choose */
        print "\t<tr class='" . ($i % 2 == 0 ? "odd" : "even") . "'>\n\t\t\t\t<td colspan='2' width='60' nowrap>\n\t\t\t\t\t<strong>Create:</strong>&nbsp;";
        form_dropdown("cg_g", $available_graph_templates, "name", "id", "", "(Select a graph type to create)", "", "textArea");
        print "\t\t</td>\n\t\t\t</tr>";
        html_end_box();
    }
    if ($_REQUEST["graph_type"] != -1) {
        $snmp_queries = db_fetch_assoc("SELECT\n\t\t\tsnmp_query.id,\n\t\t\tsnmp_query.name,\n\t\t\tsnmp_query.xml_path\n\t\t\tFROM (snmp_query,host_snmp_query)\n\t\t\tWHERE host_snmp_query.snmp_query_id=snmp_query.id\n\t\t\tAND host_snmp_query.host_id=" . $host["id"] . ($_REQUEST["graph_type"] != -2 ? " AND snmp_query.id=" . $_REQUEST["graph_type"] : '') . "\n\t\t\tORDER BY snmp_query.name");
        if (sizeof($snmp_queries) > 0) {
            foreach ($snmp_queries as $snmp_query) {
                unset($total_rows);
                if (!$changed) {
                    $page = $_REQUEST["page" . $snmp_query["id"]];
                } else {
                    $page = 1;
                }
                $xml_array = get_data_query_array($snmp_query["id"]);
                $num_input_fields = 0;
                $num_visible_fields = 0;
                if ($xml_array != false) {
                    /* loop through once so we can find out how many input fields there are */
                    reset($xml_array["fields"]);
                    while (list($field_name, $field_array) = each($xml_array["fields"])) {
                        if ($field_array["direction"] == "input") {
                            $num_input_fields++;
                            if (!isset($total_rows)) {
                                $total_rows = db_fetch_cell("SELECT count(*) FROM host_snmp_cache WHERE host_id=" . $host["id"] . " and snmp_query_id=" . $snmp_query["id"] . " AND field_name='{$field_name}'");
                            }
                        }
                    }
                }
                if (!isset($total_rows)) {
                    $total_rows = 0;
                }
                $snmp_query_graphs = db_fetch_assoc("SELECT snmp_query_graph.id,snmp_query_graph.name FROM snmp_query_graph WHERE snmp_query_graph.snmp_query_id=" . $snmp_query["id"] . " ORDER BY snmp_query_graph.name");
                if (sizeof($snmp_query_graphs) > 0) {
                    foreach ($snmp_query_graphs as $snmp_query_graph) {
                        $created_graphs = db_fetch_assoc("SELECT DISTINCT\n\t\t\t\t\t\tdata_local.snmp_index\n\t\t\t\t\t\tFROM (data_local,data_template_data)\n\t\t\t\t\t\tLEFT JOIN data_input_data ON (data_template_data.id=data_input_data.data_template_data_id)\n\t\t\t\t\t\tLEFT JOIN data_input_fields ON (data_input_data.data_input_field_id=data_input_fields.id)\n\t\t\t\t\t\tWHERE data_local.id=data_template_data.local_data_id\n\t\t\t\t\t\tAND data_input_fields.type_code='output_type'\n\t\t\t\t\t\tAND data_input_data.value='" . $snmp_query_graph["id"] . "'\n\t\t\t\t\t\tAND data_local.host_id=" . $host["id"]);
                        $script .= "created_graphs[" . $snmp_query_graph["id"] . "] = new Array(";
                        $cg_ctr = 0;
                        if (sizeof($created_graphs) > 0) {
                            foreach ($created_graphs as $created_graph) {
                                $script .= ($cg_ctr > 0 ? "," : "") . "'" . encode_data_query_index($created_graph["snmp_index"]) . "'";
                                $cg_ctr++;
                            }
                        }
                        $script .= ")\n";
                    }
                }
                print "\t<table width='100%' class='cactiTable' align='center' cellpadding='3' cellspacing='0'>\n\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td colspan='" . ($num_input_fields + 1) . "'>\n\t\t\t\t\t\t\t<table  cellspacing='0' cellpadding='0' width='100%' >\n\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t<td class='textHeaderDark'>\n\t\t\t\t\t\t\t\t\t\t<strong>Data Query</strong> [" . $snmp_query["name"] . "]\n\t\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t\t\t<td align='right' nowrap>\n\t\t\t\t\t\t\t\t\t\t<a href='" . htmlspecialchars("graphs_new.php?action=query_reload&id=" . $snmp_query["id"] . "&host_id=" . $host["id"]) . "'><img src='images/reload_icon_small.gif' title='Reload Associated Query' alt='' border='0' align='middle'></a>\n\t\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t</table>\n\t\t\t\t\t\t</td>\n\t\t\t\t\t</tr>";
                if ($xml_array != false) {
                    $html_dq_header = "";
                    $snmp_query_indexes = array();
                    reset($xml_array["fields"]);
                    /* if there is a where clause, get the matching snmp_indexes */
                    $sql_where = "";
                    if (strlen($_REQUEST["filter"])) {
                        $sql_where = "";
                        $indexes = db_fetch_assoc("SELECT DISTINCT snmp_index\n\t\t\t\t\t\tFROM host_snmp_cache\n\t\t\t\t\t\tWHERE field_value LIKE '%%" . $_REQUEST["filter"] . "%%'\n\t\t\t\t\t\tAND snmp_query_id=" . $snmp_query["id"] . "\n\t\t\t\t\t\tAND host_id=" . $host["id"]);
                        if (sizeof($indexes)) {
                            foreach ($indexes as $index) {
                                if (strlen($sql_where)) {
                                    $sql_where .= ", '" . $index["snmp_index"] . "'";
                                } else {
                                    $sql_where .= " AND snmp_index IN('" . $index["snmp_index"] . "'";
                                }
                            }
                            $sql_where .= ")";
                        }
                    }
                    if (strlen($_REQUEST["filter"]) == 0 || strlen($_REQUEST["filter"]) && sizeof($indexes)) {
                        /* determine the sort order */
                        if (isset($xml_array["index_order_type"])) {
                            if ($xml_array["index_order_type"] == "numeric") {
                                $sql_order = "ORDER BY CAST(snmp_index AS unsigned)";
                            } else {
                                if ($xml_array["index_order_type"] == "alphabetic") {
                                    $sql_order = "ORDER BY snmp_index";
                                } else {
                                    if ($xml_array["index_order_type"] == "natural") {
                                        $sql_order = "ORDER BY INET_ATON(snmp_index)";
                                    } else {
                                        $sql_order = "";
                                    }
                                }
                            }
                        } else {
                            $sql_order = "";
                        }
                        /* get the unique field values from the database */
                        $field_names = db_fetch_assoc("SELECT DISTINCT field_name\n\t\t\t\t\t\tFROM host_snmp_cache\n\t\t\t\t\t\tWHERE host_id=" . $host["id"] . "\n\t\t\t\t\t\tAND snmp_query_id=" . $snmp_query["id"]);
                        /* build magic query */
                        $sql_query = "SELECT host_id, snmp_query_id, snmp_index";
                        $num_visible_fields = sizeof($field_names);
                        $i = 0;
                        if (sizeof($field_names) > 0) {
                            foreach ($field_names as $column) {
                                $field_name = $column["field_name"];
                                $sql_query .= ", MAX(CASE WHEN field_name='{$field_name}' THEN field_value ELSE NULL END) AS '{$field_name}'";
                                $i++;
                            }
                        }
                        $sql_query .= " FROM host_snmp_cache\n\t\t\t\t\t\tWHERE host_id=" . $host["id"] . "\n\t\t\t\t\t\tAND snmp_query_id=" . $snmp_query["id"] . "\n\t\t\t\t\t\t{$sql_where}\n\t\t\t\t\t\tGROUP BY host_id, snmp_query_id, snmp_index\n\t\t\t\t\t\t{$sql_order}\n\t\t\t\t\t\tLIMIT " . $row_limit * ($page - 1) . "," . $row_limit;
                        $rows_query = "SELECT host_id, snmp_query_id, snmp_index\n\t\t\t\t\t\tFROM host_snmp_cache\n\t\t\t\t\t\tWHERE host_id=" . $host["id"] . "\n\t\t\t\t\t\tAND snmp_query_id=" . $snmp_query["id"] . "\n\t\t\t\t\t\t{$sql_where}\n\t\t\t\t\t\tGROUP BY host_id, snmp_query_id, snmp_index";
                        $snmp_query_indexes = db_fetch_assoc($sql_query);
                        $total_rows = sizeof(db_fetch_assoc($rows_query));
                        if (($page - 1) * $row_limit > $total_rows) {
                            $page = 1;
                            $_REQUEST["page" . $query["id"]] = $page;
                            load_current_session_value("page" . $query["id"], "sess_graphs_new_page" . $query["id"], "1");
                        }
                        $nav = html_nav_bar("graphs_new.php", MAX_DISPLAY_PAGES, $page, $row_limit, $total_rows, 15, "Items", "page" . $snmp_query["id"]);
                        print $nav;
                        while (list($field_name, $field_array) = each($xml_array["fields"])) {
                            if ($field_array["direction"] == "input") {
                                foreach ($field_names as $row) {
                                    if ($row["field_name"] == $field_name) {
                                        $html_dq_header .= "<td class='tableSubHeaderColumn'>" . $field_array["name"] . "</td>\n";
                                        break;
                                    }
                                }
                            }
                        }
                        if (!sizeof($snmp_query_indexes)) {
                            print "<tr class='odd'><td>This data query returned 0 rows, perhaps there was a problem executing this\n\t\t\t\t\t\t\tdata query. You can <a href='" . htmlspecialchars("host.php?action=query_verbose&id=" . $snmp_query["id"] . "&host_id=" . $host["id"]) . "'>run this data\n\t\t\t\t\t\t\tquery in debug mode</a> to get more information.</td></tr>\n";
                        } else {
                            print "<tr class='tableHeader'>\n\t\t\t\t\t\t\t\t{$html_dq_header}\n\t\t\t\t\t\t\t\t<td width='1%' align='center' class='tableSubHeaderCheckbox' style='" . get_checkbox_style() . "'><input type='checkbox' style='margin: 0px;' name='all_" . $snmp_query["id"] . "' title='Select All' onClick='SelectAll(\"sg_" . $snmp_query["id"] . "\",this.checked);dq_update_selection_indicators();'></td>\n\n\t\t\t\t\t\t\t</tr>\n";
                        }
                        $row_counter = 0;
                        $column_counter = 0;
                        $fields = array_rekey($field_names, "field_name", "field_name");
                        if (sizeof($snmp_query_indexes) > 0) {
                            foreach ($snmp_query_indexes as $row) {
                                $query_row = $snmp_query["id"] . "_" . encode_data_query_index($row["snmp_index"]);
                                print "<tr id='line{$query_row}' class='" . ($row_counter % 2 == 0 ? "odd" : "even") . "'>";
                                $i++;
                                $column_counter = 0;
                                reset($xml_array["fields"]);
                                while (list($field_name, $field_array) = each($xml_array["fields"])) {
                                    if ($field_array["direction"] == "input") {
                                        if (in_array($field_name, $fields)) {
                                            if (isset($row[$field_name])) {
                                                print "<td onClick='dq_select_line(" . $snmp_query["id"] . ",\"" . encode_data_query_index($row["snmp_index"]) . "\");'><span id='text{$query_row}" . "_" . $column_counter . "'>" . (strlen($_REQUEST["filter"]) ? preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", $row[$field_name]) : $row[$field_name]) . "</span></td>";
                                            } else {
                                                print "<td onClick='dq_select_line(" . $snmp_query["id"] . ",\"" . encode_data_query_index($row["snmp_index"]) . "\");'><span id='text{$query_row}" . "_" . $column_counter . "'></span></td>";
                                            }
                                            $column_counter++;
                                        }
                                    }
                                }
                                print "<td align='right'>";
                                print "<input type='checkbox' name='sg_{$query_row}' id='sg_{$query_row}' onClick='dq_update_selection_indicators();'>";
                                print "</td>";
                                print "</tr>\n";
                                $row_counter++;
                            }
                        }
                        if ($total_rows > $row_limit) {
                            print $nav;
                        }
                    } else {
                        print "<tr class='odd'><td colspan='2' style='color: red; font-size: 12px; font-weight: bold;'>Search Returned no Rows.</td></tr>\n";
                    }
                } else {
                    print "<tr class='odd'><td colspan='2' style='color: red; font-size: 12px; font-weight: bold;'>Error in data query.</td></tr>\n";
                }
                print "</table>";
                /* draw the graph template drop down here */
                $data_query_graphs = db_fetch_assoc("select snmp_query_graph.id,snmp_query_graph.name from snmp_query_graph where snmp_query_graph.snmp_query_id=" . $snmp_query["id"] . " order by snmp_query_graph.name");
                if (sizeof($data_query_graphs) == 1) {
                    echo "<input type='hidden' id='sgg_" . $snmp_query["id"] . "' name='sgg_" . $snmp_query["id"] . "' value='" . $data_query_graphs[0]["id"] . "'>\n";
                } elseif (sizeof($data_query_graphs) > 1) {
                    print "\t<table align='center' width='100%'>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td width='1' valign='top'>\n\t\t\t\t\t\t\t\t<img src='images/arrow.gif' alt=''>&nbsp;\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t<td align='right'>\n\t\t\t\t\t\t\t\t<span style='font-size: 12px; font-style: italic;'>Select a graph type:</span>&nbsp;\n\t\t\t\t\t\t\t\t<select name='sgg_" . $snmp_query["id"] . "' id='sgg_" . $snmp_query["id"] . "' onChange='dq_update_deps(" . $snmp_query["id"] . "," . (isset($column_counter) ? $column_counter : "") . ");'>\n\t\t\t\t\t\t\t\t\t";
                    html_create_list($data_query_graphs, "name", "id", "0");
                    print "\n\t\t\t\t\t\t\t\t</select>\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</table>";
                }
                print "<br>";
                $script .= "dq_update_deps(" . $snmp_query["id"] . "," . $num_visible_fields . ");\n";
            }
        }
    }
    if (strlen($script)) {
        $script .= "</script>\n";
        print $script;
    }
    form_hidden_box("save_component_graph", "1", "");
    form_hidden_box("host_id", $host["id"], "0");
    form_hidden_box("host_template_id", $host["host_template_id"], "0");
    if (isset($_SERVER["HTTP_REFERER"]) && !substr_count($_SERVER["HTTP_REFERER"], "graphs_new")) {
        $_REQUEST["returnto"] = basename($_SERVER["HTTP_REFERER"]);
    }
    load_current_session_value("returnto", "sess_graphs_new_returnto", "");
    form_save_button($_REQUEST["returnto"]);
    print "<script type='text/javascript'>dq_update_selection_indicators();</script>\n";
    print "<script type='text/javascript'>gt_update_selection_indicators();</script>\n";
}
Example #29
0
function utilities()
{
    html_start_box("<strong>Cacti System Utilities</strong>", "100%", "", "3", "center", "");
    ?>
	<colgroup span="3">
		<col valign="top" width="20%"></col>
		<col valign="top" width="80%"></col>
	</colgroup>

	<?php 
    html_header(array("Technical Support"), 2);
    form_alternate_row();
    ?>
		<td class="textArea">
			<a href='<?php 
    print htmlspecialchars("utilities.php?action=view_tech");
    ?>
'>Technical Support</a>
		</td>
		<td class="textArea">
			Cacti technical support page.  Used by developers and technical support persons to assist with issues in Cacti.  Includes checks for common configuration issues.
		</td>
	</tr>

	<?php 
    html_header(array("Log Administration"), 2);
    form_alternate_row();
    ?>
		<td class="textArea">
			<a href='<?php 
    print htmlspecialchars("utilities.php?action=view_logfile");
    ?>
'>View Cacti Log File</a>
		</td>
		<td class="textArea">
			The Cacti Log File stores statistic, error and other message depending on system settings.  This information can be used to identify problems with the poller and application.
		</td>
	</tr>
	<?php 
    form_alternate_row();
    ?>
		<td class="textArea">
			<a href='<?php 
    print htmlspecialchars("utilities.php?action=view_user_log");
    ?>
'>View User Log</a>
		</td>
		<td class="textArea">
			Allows Administrators to browse the user log.  Administrators can filter and export the log as well.
		</td>
	</tr>

	<?php 
    html_header(array("Poller Cache Administration"), 2);
    form_alternate_row();
    ?>
		<td class="textArea">
			<a href='<?php 
    print htmlspecialchars("utilities.php?action=view_poller_cache");
    ?>
'>View Poller Cache</a>
		</td>
		<td class="textArea">
			This is the data that is being passed to the poller each time it runs. This data is then in turn executed/interpreted and the results are fed into the rrd files for graphing or the database for display.
		</td>
	</tr>
	<?php 
    form_alternate_row();
    ?>
		<td class="textArea">
			<a href='<?php 
    print htmlspecialchars("utilities.php?action=view_snmp_cache");
    ?>
'>View SNMP Cache</a>
		</td>
		<td class="textArea">
			The SNMP cache stores information gathered from SNMP queries. It is used by cacti to determine the OID to use when gathering information from an SNMP-enabled host.
		</td>
	</tr>
	<?php 
    form_alternate_row();
    ?>
		<td class="textArea">
			<a href='<?php 
    print htmlspecialchars("utilities.php?action=clear_poller_cache");
    ?>
'>Rebuild Poller Cache</a>
		</td>
		<td class="textArea">
			The poller cache will be cleared and re-generated if you select this option. Sometimes host/data source data can get out of sync with the cache in which case it makes sense to clear the cache and start over.
		</td>
	</tr>

	<?php 
    api_plugin_hook('utilities_list');
    html_end_box();
}
function mactrack_view_aggregated_macs()
{
    global $title, $report, $mactrack_search_types, $rows_selector, $config;
    global $mactrack_view_agg_macs_actions, $item_rows;
    mactrack_tabs();
    html_start_box($title, '100%', '', '3', 'center', '');
    mactrack_mac_filter();
    html_end_box();
    $sql_where = '';
    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');
    }
    $port_results = mactrack_view_get_mac_records($sql_where, TRUE, $row_limit);
    /* prevent table scans, either a device or site must be selected */
    if (get_request_var('site_id') == -1 && get_request_var('device_id') == -1) {
        $total_rows = 0;
    } else {
        $rows_query_string = 'SELECT
			COUNT(*)
			FROM mac_track_aggregated_ports
			LEFT JOIN mac_track_sites
			ON (mac_track_aggregated_ports.site_id=mac_track_sites.site_id)
			LEFT JOIN mac_track_oui_database
			ON (mac_track_oui_database.vendor_mac=mac_track_aggregated_ports.vendor_mac) ' . str_replace('mac_track_ports', 'mac_track_aggregated_ports', $sql_where);
        $total_rows = db_fetch_cell($rows_query_string);
    }
    $nav = html_nav_bar('mactrack_view_macs.php?report=macs&scan_date=3', MAX_DISPLAY_PAGES, get_request_var('page'), $row_limit, $total_rows, 12, 'MAC Addresses');
    print $nav;
    html_start_box('', '100%', '', '3', 'center', '');
    $display_text = array('device_name' => array(__('Switch Name'), 'ASC'), 'hostname' => array(__('Switch Hostname'), 'ASC'), 'ip_address' => array(__('ED IP Address'), 'ASC'));
    if (strlen(read_config_option('mt_reverse_dns')) > 0) {
        $display_text['dns_hostname'] = array('ED DNS Hostname', 'ASC');
    }
    $display_text = array_merge($display_text, array('mac_address' => array(__('ED MAC Address'), 'ASC'), 'vendor_name' => array(__('Vendor Name'), 'ASC'), 'port_number' => array(__('Port Number'), 'DESC'), 'port_name' => array(__('Port Name'), 'ASC'), 'vlan_id' => array(__('VLAN ID'), 'DESC'), 'vlan_name' => array(__('VLAN Name'), 'ASC')));
    if (get_request_var('rows') == 1) {
        $display_text['max_scan_date'] = array(__('Last Scan Date'), 'DESC');
    } else {
        $display_text['scan_date'] = array(__('Last Scan Date'), 'DESC');
    }
    if (get_request_var('scan_date') == 3) {
        $display_text['count_rec'] = array(__('Count'), 'ASC');
    }
    if (mactrack_check_user_realm(2122)) {
        html_header_sort_checkbox($display_text, get_request_var('sort_column'), get_request_var('sort_direction'));
    } else {
        html_header_sort($display_text, get_request_var('sort_column'), get_request_var('sort_direction'));
    }
    $i = 0;
    $delim = read_config_option('mt_mac_delim');
    if (sizeof($port_results)) {
        foreach ($port_results as $port_result) {
            if ($port_result['active_last'] == 1) {
                $color_line_date = "<span style='font-weight: bold;'>";
            } else {
                $color_line_date = '';
            }
            $key = str_replace($delim, '_', $port_result['mac_address']) . '-' . $port_result['device_id'] . $port_result['port_number'] . '-' . $port_result['date_last'];
            $key = $port_result['row_id'];
            form_alternate_row('line' . $key, true);
            form_selectable_cell(filter_value($port_result['device_name'], get_request_var('filter')), $key);
            form_selectable_cell(filter_value($port_result['hostname'], get_request_var('filter')), $key);
            form_selectable_cell(filter_value($port_result['ip_address'], get_request_var('filter')), $key);
            if (strlen(read_config_option('mt_reverse_dns')) > 0) {
                form_selectable_cell(filter_value($port_result['dns_hostname'], get_request_var('filter')), $key);
            }
            form_selectable_cell(filter_value($port_result['mac_address'], get_request_var('filter')), $key);
            form_selectable_cell(filter_value($port_result['vendor_name'], get_request_var('filter')), $key);
            form_selectable_cell($port_result['port_number'], $key);
            form_selectable_cell(filter_value($port_result['port_name'], get_request_var('filter')), $key);
            form_selectable_cell($port_result['vlan_id'], $key);
            form_selectable_cell(filter_value($port_result['vlan_name'], get_request_var('filter')), $key);
            form_selectable_cell($color_line_date . $port_result['date_last'], $key);
            form_selectable_cell($port_result['count_rec'], $key);
            if (mactrack_check_user_realm(2122)) {
                form_checkbox_cell($port_result['mac_address'], $key);
            }
            form_end_row();
        }
    } else {
        if (get_request_var('site_id') == -1 && get_request_var('device_id') == -1) {
            print "<tr><td colspan='10'><em>" . __('You must first choose a Site, Device or other search criteria.') . "</em></td></tr>";
        } else {
            print "<tr><td colspan='10'><em>" . __('No MacTrack Port Results') . "</em></td></tr>";
        }
    }
    html_end_box(false);
    if (sizeof($port_results)) {
        print $nav;
        mactrack_display_stats();
    }
    if (mactrack_check_user_realm(2122)) {
        /* draw the dropdown containing a list of available actions for this form */
        draw_actions_dropdown($mactrack_view_agg_macs_actions);
    }
}