Пример #1
0
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);
    }
}
Пример #2
0
function mactrack_view_aggregated_macs() {
	global $title, $report, $colors, $mactrack_search_types, $rows_selector, $config;
	global $mactrack_view_agg_macs_actions, $item_rows;

	/* ================= input validation ================= */
	input_validate_input_number(get_request_var_request("site_id"));
	input_validate_input_number(get_request_var_request("device_id"));
	input_validate_input_number(get_request_var_request("mac_filter_type_id"));
	input_validate_input_number(get_request_var_request("port_name_filter_type_id"));
	input_validate_input_number(get_request_var_request("ip_filter_type_id"));
	input_validate_input_number(get_request_var_request("rows"));
	input_validate_input_number(get_request_var_request("authorized"));
	input_validate_input_number(get_request_var_request("vlan"));
	input_validate_input_number(get_request_var_request("page"));
	/* ==================================================== */

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

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

	/* clean up search string */
	if (isset($_REQUEST["port_name_filter"])) {
		$_REQUEST["port_name_filter"] = sanitize_search_string(get_request_var("port_name_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 (isset($_REQUEST["mac_filter_type_id"])) {
		if ($_REQUEST["mac_filter_type_id"] == 1) {
			unset($_REQUEST["mac_filter"]);
		}
	}

	if (isset($_REQUEST["port_name_filter_type_id"])) {
		if ($_REQUEST["port_name_filter_type_id"] == 1) {
			unset($_REQUEST["port_name_filter"]);
		}
	}

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

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

	if (isset($_REQUEST["ip_filter_type_id"])) {
		if ($_REQUEST["ip_filter_type_id"] == 1) {
			unset($_REQUEST["ip_filter"]);
		}
	}

	if (isset($_REQUEST["reset"])) {
		kill_session_var("sess_mactrack_view_macs_current_page");
		kill_session_var("sess_mactrack_view_macs_rowstoshow");
		kill_session_var("sess_mactrack_view_macs_filter");
		kill_session_var("sess_mactrack_view_macs_mac_filter_type_id");
		kill_session_var("sess_mactrack_view_macs_mac_filter");
		kill_session_var("sess_mactrack_view_macs_port_name_filter_type_id");
		kill_session_var("sess_mactrack_view_macs_port_name_filter");
		kill_session_var("sess_mactrack_view_macs_ip_filter_type_id");
		kill_session_var("sess_mactrack_view_macs_ip_filter");
		kill_session_var("sess_mactrack_view_macs_rows_selector");
		kill_session_var("sess_mactrack_view_macs_site_id");
		kill_session_var("sess_mactrack_view_macs_vlan_id");
		kill_session_var("sess_mactrack_view_macs_authorized");
		kill_session_var("sess_mactrack_view_macs_device_id");
		kill_session_var("sess_mactrack_view_macs_sort_column");
		kill_session_var("sess_mactrack_view_macs_sort_direction");

		$_REQUEST["page"] = 1;
	}

	/* if the user pushed the 'clear' button */
	if (isset($_REQUEST["clear_x"])) {
		kill_session_var("sess_mactrack_view_macs_current_page");
		kill_session_var("sess_mactrack_view_macs_rowstoshow");
		kill_session_var("sess_mactrack_view_macs_filter");
		kill_session_var("sess_mactrack_view_macs_mac_filter_type_id");
		kill_session_var("sess_mactrack_view_macs_mac_filter");
		kill_session_var("sess_mactrack_view_macs_port_name_filter_type_id");
		kill_session_var("sess_mactrack_view_macs_port_name_filter");
		kill_session_var("sess_mactrack_view_macs_ip_filter_type_id");
		kill_session_var("sess_mactrack_view_macs_ip_filter");
		kill_session_var("sess_mactrack_view_macs_rows_selector");
		kill_session_var("sess_mactrack_view_macs_site_id");
		kill_session_var("sess_mactrack_view_macs_vlan_id");
		kill_session_var("sess_mactrack_view_macs_authorized");
		kill_session_var("sess_mactrack_view_macs_device_id");
		kill_session_var("sess_mactrack_view_macs_sort_column");
		kill_session_var("sess_mactrack_view_macs_sort_direction");

		$_REQUEST["page"] = 1;
		unset($_REQUEST["scan_date"]);
		unset($_REQUEST["mac_filter"]);
		unset($_REQUEST["mac_filter_type_id"]);
		unset($_REQUEST["port_name_filter"]);
		unset($_REQUEST["port_name_filter_type_id"]);
		unset($_REQUEST["ip_filter"]);
		unset($_REQUEST["ip_filter_type_id"]);
		unset($_REQUEST["rows"]);
		unset($_REQUEST["filter"]);
		unset($_REQUEST["site_id"]);
		unset($_REQUEST["vlan"]);
		unset($_REQUEST["authorized"]);
		unset($_REQUEST["device_id"]);
		unset($_REQUEST["sort_column"]);
		unset($_REQUEST["sort_direction"]);
	}else{
		/* if any of the settings changed, reset the page number */
		$changed = 0;
		$changed += mactrack_check_changed("scan_date",          "sess_mactrack_view_macs_rowstoshow");
		$changed += mactrack_check_changed("mac_filter",         "sess_mactrack_view_macs_mac_filter");
		$changed += mactrack_check_changed("mac_filter_type_id", "sess_mactrack_view_macs_mac_filter_type_id");
		$changed += mactrack_check_changed("port_name_filter",         "sess_mactrack_view_macs_port_name_filter");
		$changed += mactrack_check_changed("port_name_filter_type_id", "sess_mactrack_view_macs_port_name_filter_type_id");
		$changed += mactrack_check_changed("ip_filter",          "sess_mactrack_view_macs_ip_filter");
		$changed += mactrack_check_changed("ip_filter_type_id",  "sess_mactrack_view_macs_ip_filter_type_id");
		$changed += mactrack_check_changed("filter",             "sess_mactrack_view_macs_filter");
		$changed += mactrack_check_changed("rows",               "sess_mactrack_view_macs_rows_selector");
		$changed += mactrack_check_changed("site_id",            "sess_mactrack_view_macs_site_id");
		$changed += mactrack_check_changed("vlan",               "sess_mactrack_view_macs_vlan_id");
		$changed += mactrack_check_changed("authorized",         "sess_mactrack_view_macs_authorized");
		$changed += mactrack_check_changed("device_id",          "sess_mactrack_view_macs_device_id");

		if ($changed) {
			$_REQUEST["page"] = "1";
		}
	}

	/* reset some things if the user has made changes */
	if ((!empty($_REQUEST["site_id"]))&&(!empty($_SESSION["sess_mactrack_view_macs_site_id"]))) {
		if ($_REQUEST["site_id"] <> $_SESSION["sess_mactrack_view_macs_site_id"]) {
			$_REQUEST["device_id"] = "-1";
		}
	}

	/* remember these search fields in session vars so we don't have to keep passing them around */
	load_current_session_value("page",               "sess_mactrack_view_macs_current_page", "1");
	load_current_session_value("scan_date",          "sess_mactrack_view_macs_rowstoshow", "2");
	load_current_session_value("mac_filter",         "sess_mactrack_view_macs_mac_filter", "");
	load_current_session_value("mac_filter_type_id", "sess_mactrack_view_macs_mac_filter_type_id", "1");
	load_current_session_value("port_name_filter",         "sess_mactrack_view_macs_port_name_filter", "");
	load_current_session_value("port_name_filter_type_id", "sess_mactrack_view_macs_port_name_filter_type_id", "1");
	load_current_session_value("ip_filter",          "sess_mactrack_view_macs_ip_filter", "");
	load_current_session_value("ip_filter_type_id",  "sess_mactrack_view_macs_ip_filter_type_id", "1");
	load_current_session_value("filter",             "sess_mactrack_view_macs_filter", "");
	load_current_session_value("rows",               "sess_mactrack_view_macs_rows_selector", "-1");
	load_current_session_value("site_id",            "sess_mactrack_view_macs_site_id", "-1");
	load_current_session_value("vlan",               "sess_mactrack_view_macs_vlan_id", "-1");
	load_current_session_value("authorized",         "sess_mactrack_view_macs_authorized", "-1");
	load_current_session_value("device_id",          "sess_mactrack_view_macs_device_id", "-1");
	load_current_session_value("sort_column",        "sess_mactrack_view_macs_sort_column", "device_name");
	load_current_session_value("sort_direction",     "sess_mactrack_view_macs_sort_direction", "ASC");

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

	$sql_where = "";

	if ($_REQUEST["rows"] == -1) {
		$row_limit = read_config_option("num_rows_mactrack");
	}elseif ($_REQUEST["rows"] == -2) {
		$row_limit = 999999;
	}else{
		$row_limit = $_REQUEST["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 ($_REQUEST["site_id"] == -1 && $_REQUEST["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);
	}

	/* generate page list */
	$url_page_select = get_page_list($_REQUEST["page"], MAX_DISPLAY_PAGES, $row_limit, $total_rows, "mactrack_view_macs.php?report=macs&scan_date=3");

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

	print $nav;

	$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 ($_REQUEST["rows"] == 1) {
		$display_text["max_scan_date"] = array("Last Scan Date", "DESC");
	}else{
		$display_text["scan_date"] = array("Last Scan Date", "DESC");
	}
	if ($_REQUEST["scan_date"] == 3) {
		$display_text["count_rec"] = array("Count", "ASC");
	}

	if (mactrack_check_user_realm(2122)) {
		html_header_sort_checkbox($display_text, $_REQUEST["sort_column"], $_REQUEST["sort_direction"]);
	}else{
		html_header_sort($display_text, $_REQUEST["sort_column"], $_REQUEST["sort_direction"]);
	}


	$i = 0;
	$delim = read_config_option("mt_mac_delim");
	if (sizeof($port_results) > 0) {
		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_color($colors["alternate"], $colors["light"], $i, 'line' . $key); $i++;
			form_selectable_cell((strlen($_REQUEST["filter"]) ? preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", $port_result["device_name"]) : $port_result["device_name"]), $key);
			form_selectable_cell((strlen($_REQUEST["filter"]) ? preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", $port_result["hostname"]) : $port_result["hostname"]), $key);
			form_selectable_cell((strlen($_REQUEST["filter"]) ? preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", $port_result["ip_address"]) : $port_result["ip_address"]), $key);
			if (strlen(read_config_option("mt_reverse_dns")) > 0) {
				form_selectable_cell((strlen($_REQUEST["filter"]) ? preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", $port_result["dns_hostname"]) : $port_result["dns_hostname"]), $key);
			}
			form_selectable_cell((strlen($_REQUEST["filter"]) ? preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", $port_result["mac_address"]) : $port_result["mac_address"]), $key);
			form_selectable_cell((strlen($_REQUEST["filter"]) ? preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", $port_result["vendor_name"]) : $port_result["vendor_name"]), $key);
			form_selectable_cell($port_result["port_number"], $key);
			form_selectable_cell((strlen($_REQUEST["filter"]) ? preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", $port_result["port_name"]) : $port_result["port_name"]), $key);
			form_selectable_cell($port_result["vlan_id"], $key);
			form_selectable_cell((strlen($_REQUEST["filter"]) ? preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", $port_result["vlan_name"]) : $port_result["vlan_name"]), $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 ($_REQUEST["site_id"] == -1 && $_REQUEST["device_id"] == -1) {
			print "<tr><td colspan='10'><em>You must 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>";
		}
	}

	print $nav;

	html_end_box(false);

	mactrack_display_stats();

	if (mactrack_check_user_realm(2122)) {
		/* draw the dropdown containing a list of available actions for this form */
		mactrack_draw_actions_dropdown($mactrack_view_agg_macs_actions);
	}
}