function mactrack_view_devices() { global $title, $report, $colors, $mactrack_search_types, $mactrack_device_types, $rows_selector, $config, $item_rows; /* ================= input validation ================= */ input_validate_input_number(get_request_var_request("site_id")); input_validate_input_number(get_request_var_request("device_id")); input_validate_input_number(get_request_var_request("type_id")); input_validate_input_number(get_request_var_request("device_type_id")); input_validate_input_number(get_request_var_request("status")); input_validate_input_number(get_request_var_request("page")); input_validate_input_number(get_request_var_request("rows")); /* ==================================================== */ /* clean up search string */ if (isset($_REQUEST["filter"])) { $_REQUEST["filter"] = sanitize_search_string(get_request_var("filter")); } /* clean up sort_column */ if (isset($_REQUEST["sort_column"])) { $_REQUEST["sort_column"] = sanitize_search_string(get_request_var("sort_column")); } /* clean up search string */ if (isset($_REQUEST["sort_direction"])) { $_REQUEST["sort_direction"] = sanitize_search_string(get_request_var("sort_direction")); } /* if the user pushed the 'clear' button */ if (isset($_REQUEST["clear_x"]) || isset($_REQUEST["reset"])) { kill_session_var("sess_mactrack_view_device_current_page"); kill_session_var("sess_mactrack_view_device_filter"); kill_session_var("sess_mactrack_view_device_site_id"); kill_session_var("sess_mactrack_view_device_type_id"); kill_session_var("sess_mactrack_view_device_rows"); kill_session_var("sess_mactrack_view_device_device_type_id"); kill_session_var("sess_mactrack_view_device_status"); kill_session_var("sess_mactrack_view_device_sort_column"); kill_session_var("sess_mactrack_view_device_sort_direction"); $_REQUEST["page"] = 1; if (isset($_REQUEST["clear_x"])) { unset($_REQUEST["filter"]); unset($_REQUEST["site_id"]); unset($_REQUEST["type_id"]); unset($_REQUEST["rows"]); unset($_REQUEST["device_type_id"]); unset($_REQUEST["status"]); unset($_REQUEST["sort_column"]); unset($_REQUEST["sort_direction"]); } }else{ /* if any of the settings changed, reset the page number */ $changed = 0; $changed += mactrack_check_changed("filter", "sess_mactrack_view_device_filter"); $changed += mactrack_check_changed("site_id", "sess_mactrack_view_device_site_id"); $changed += mactrack_check_changed("rows", "sess_mactrack_view_device_rows"); $changed += mactrack_check_changed("type_id", "sess_mactrack_view_device_type_id"); $changed += mactrack_check_changed("device_type_id", "sess_mactrack_view_device_device_type_id"); $changed += mactrack_check_changed("status", "sess_mactrack_view_device_status"); if ($changed) { $_REQUEST["page"] = "1"; } } /* remember these search fields in session vars so we don't have to keep passing them around */ load_current_session_value("page", "sess_mactrack_view_device_current_page", "1"); load_current_session_value("filter", "sess_mactrack_view_device_filter", ""); load_current_session_value("site_id", "sess_mactrack_view_device_site_id", "-1"); load_current_session_value("type_id", "sess_mactrack_view_device_type_id", "-1"); load_current_session_value("device_type_id", "sess_mactrack_view_device_device_type_id", "-1"); load_current_session_value("status", "sess_mactrack_view_device_status", "-1"); load_current_session_value("rows", "sess_mactrack_view_device_rows", "-1"); load_current_session_value("sort_column", "sess_mactrack_view_device_sort_column", "site_name"); load_current_session_value("sort_direction", "sess_mactrack_view_device_sort_direction", "ASC"); if ($_REQUEST["rows"] == -1) { $row_limit = read_config_option("num_rows_mactrack"); }elseif ($_REQUEST["rows"] == -2) { $row_limit = 999999; }else{ $row_limit = $_REQUEST["rows"]; } if (defined("URL_PATH")) { $webroot = URL_PATH; }else{ $webroot = $config["url_path"]; } mactrack_tabs(); mactrack_view_header(); mactrack_device_filter2(); mactrack_view_footer(); html_start_box("", "100%", $colors["header"], "3", "center", ""); $sql_where = ""; $devices = mactrack_view_get_device_records($sql_where, $row_limit); $total_rows = db_fetch_cell("SELECT COUNT(mac_track_devices.device_id) FROM mac_track_sites RIGHT JOIN mac_track_devices ON mac_track_devices.site_id = mac_track_sites.site_id LEFT JOIN mac_track_device_types ON (mac_track_device_types.device_type_id=mac_track_devices.device_type_id) $sql_where"); /* generate page list */ $url_page_select = get_page_list($_REQUEST["page"], MAX_DISPLAY_PAGES, $row_limit, $total_rows, "mactrack_view_devices.php?report=devices"); if (isset($config["base_path"])) { if ($total_rows > 0) { $nav = "<tr bgcolor='#" . $colors["header"] . "'> <td colspan='13'> <table width='100%' cellspacing='0' cellpadding='0' border='0'> <tr> <td align='left' class='textHeaderDark'> <strong><< "; if ($_REQUEST["page"] > 1) { $nav .= "<a class='linkOverDark' href='mactrack_view_devices.php?report=devices&page=" . ($_REQUEST["page"]-1) . "'>"; } $nav .= "Previous"; if ($_REQUEST["page"] > 1) { $nav .= "</a>"; } $nav .= "</strong> </td>\n <td align='center' class='textHeaderDark'> Showing Rows " . ($total_rows == 0 ? "None" : (($row_limit*($_REQUEST["page"]-1))+1) . " to " . ((($total_rows < $row_limit) || ($total_rows < ($row_limit*$_REQUEST["page"]))) ? $total_rows : ($row_limit*$_REQUEST["page"])) . " of $total_rows [$url_page_select]") . " </td>\n <td align='right' class='textHeaderDark'> <strong>"; if (($_REQUEST["page"] * $row_limit) < $total_rows) { $nav .= "<a class='linkOverDark' href='mactrack_view_devices.php?report=devices&page=" . ($_REQUEST["page"]+1) . "'>"; } $nav .= "Next"; if (($_REQUEST["page"] * $row_limit) < $total_rows) { $nav .= "</a>"; } $nav .= " >></strong> </td>\n </tr> </table> </td> </tr>\n"; }else{ $nav = "<tr bgcolor='#" . $colors["header"] . "' class='noprint'> <td colspan='22'> <table width='100%' cellspacing='0' cellpadding='0' border='0'> <tr> <td align='center' class='textHeaderDark'> No Rows Found </td>\n </tr> </table> </td> </tr>\n"; } }else{ $nav = html_create_nav($_REQUEST["page"], MAX_DISPLAY_PAGES, $row_limit, $total_rows, 13, "mactrack_view_sites.php"); } print $nav; $display_text = array( "nosort" => array("Actions", ""), "device_name" => array("Device Name", "ASC"), "site_name" => array("Site Name", "ASC"), "snmp_status" => array("Status", "ASC"), "hostname" => array("Hostname", "ASC"), "device_type" => array("Device Type", "ASC"), "ips_total" => array("Total IP's", "DESC"), "ports_total" => array("User Ports", "DESC"), "ports_active" => array("User Ports Up", "DESC"), "ports_trunk" => array("Trunk Ports", "DESC"), "macs_active" => array("Active Macs", "DESC"), "vlans_total" => array("Total VLAN's", "DESC"), "last_runduration" => array("Last Duration", "DESC")); html_header_sort($display_text, $_REQUEST["sort_column"], $_REQUEST["sort_direction"]); $i = 0; if (sizeof($devices) > 0) { foreach ($devices as $device) { $hostinfo["hostname"] = $device["hostname"]; $hostinfo["user"] = $device["user_name"]; switch($device["term_type"]) { case 0: $hostinfo["transport"] = "none"; break; case 1: $hostinfo["transport"] = "telnet"; break; case 2: $hostinfo["transport"] = "ssh"; break; case 3: $hostinfo["transport"] = "http"; break; case 4: $hostinfo["transport"] = "https"; break; } form_alternate_row_color($colors["alternate"],$colors["light"],$i); $i++; ?> <td width=100> <?php if (mactrack_authorized(2121)) {?> <a href='<?php print $webroot . "plugins/mactrack/mactrack_devices.php?action=edit&device_id=" . $device['device_id'];?>' title='Edit Device'><img border='0' src='<?php print $webroot;?>plugins/mactrack/images/edit_object.png'></a> <?php api_plugin_hook_function('remote_link', $hostinfo); } ?> <?php if ($device["host_id"] > 0) {?> <a href='<?php print $webroot . "plugins/mactrack/mactrack_view_graphs.php?action=preview&report=graphs&style=selective&graph_list=&host_id=" . $device["host_id"] . "&graph_template_id=0&filter=";?>' title='View Graphs'><img border='0' src='<?php print $webroot;?>plugins/mactrack/images/view_graphs.gif'></a> <?php }else{?> <img title='Device Not Mapped to Cacti Device' border='0' src='<?php print $webroot;?>plugins/mactrack/images/view_graphs_disabled.gif'> <?php }?> <a href='<?php print $webroot . "plugins/mactrack/mactrack_view_macs.php?report=macs&reset&device_id=-1&scan_date=3&site_id=" . $_REQUEST["site_id"] . "&device_id=" . $device['device_id'];?>' title='View MAC Addresses'><img border='0' src='<?php print $webroot;?>plugins/mactrack/images/view_macs.gif'></a> <a href='<?php print $webroot . "plugins/mactrack/mactrack_view_interfaces.php?report=interfaces&reset&site=" . $_REQUEST["site_id"] . "&device=" . $device['device_id'];?>' title='View Interfaces'><img border='0' src='<?php print $webroot;?>plugins/mactrack/images/view_interfaces.gif'></a> </td> <td width=150> <?php print "<strong>" . (strlen($_REQUEST["filter"]) ? preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", $device["device_name"]) : $device["device_name"]) . "</strong>";?> </td> <td><?php print (strlen($_REQUEST["filter"]) ? preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", $device["site_name"]) : $device["site_name"]);?></td> <td><?php print get_colored_device_status(($device["disabled"] == "on" ? true : false), $device["snmp_status"]);?></td> <td><?php print (strlen($_REQUEST["filter"]) ? preg_replace("/(" . preg_quote($_REQUEST["filter"]) . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", $device["hostname"]) : $device["hostname"]);?></td> <td><?php print $device["device_type"];?></td> <td><?php print ($device["scan_type"] == "1" ? "N/A" : $device["ips_total"]);?></td> <td><?php print ($device["scan_type"] == "3" ? "N/A" : $device["ports_total"]);?></td> <td><?php print ($device["scan_type"] == "3" ? "N/A" : $device["ports_active"]);?></td> <td><?php print ($device["scan_type"] == "3" ? "N/A" : $device["ports_trunk"]);?></td> <td><?php print ($device["scan_type"] == "3" ? "N/A" : $device["macs_active"]);?></td> <td><?php print ($device["scan_type"] == "3" ? "N/A" : $device["vlans_total"]);?></td> <td><?php print number_format($device["last_runduration"], 1);?></td> </tr> <?php } }else{ print "<tr><td colspan='10'><em>No MacTrack Devices</em></td></tr>"; } print $nav; html_end_box(false); mactrack_display_stats(); }
function mactrack_view_devices() { global $title, $report, $mactrack_search_types, $mactrack_device_types, $rows_selector, $config, $item_rows; mactrack_device_request_validation(); if (get_request_var('rows') == -1) { $row_limit = read_config_option('num_rows_table'); } elseif (get_request_var('rows') == -2) { $row_limit = 999999; } else { $row_limit = get_request_var('rows'); } $webroot = $config['url_path'] . '/plugins/mactrack/'; mactrack_tabs(); html_start_box($title, '100%', '', '3', 'center', ''); mactrack_device_filter2(); html_end_box(); $sql_where = ''; $devices = mactrack_view_get_device_records($sql_where, $row_limit); $total_rows = db_fetch_cell("SELECT\n\t\tCOUNT(mac_track_devices.device_id)\n\t\tFROM mac_track_sites\n\t\tRIGHT JOIN mac_track_devices ON mac_track_devices.site_id = mac_track_sites.site_id\n\t\tLEFT JOIN mac_track_device_types ON (mac_track_device_types.device_type_id=mac_track_devices.device_type_id)\n\t\t{$sql_where}"); $nav = html_nav_bar('mactrack_view_devices.php?report=devices', MAX_DISPLAY_PAGES, get_request_var('page'), $row_limit, $total_rows, 13, __('Devices')); print $nav; html_start_box('', '100%', '', '3', 'center', ''); $display_text = array('nosort' => array(__('Actions'), ''), 'device_name' => array(__('Device Name'), 'ASC'), 'site_name' => array(__('Site Name'), 'ASC'), 'snmp_status' => array(__('Status'), 'ASC'), 'hostname' => array(__('Hostname'), 'ASC'), 'device_type' => array(__('Device Type'), 'ASC'), 'ips_total' => array(__('Total IP\'s'), 'DESC'), 'ports_total' => array(__('User Ports'), 'DESC'), 'ports_active' => array(__('User Ports Up'), 'DESC'), 'ports_trunk' => array(__('Trunk Ports'), 'DESC'), 'macs_active' => array(__('Active Macs'), 'DESC'), 'vlans_total' => array(__('Total VLAN\'s'), 'DESC'), 'last_runduration' => array(__('Last Duration'), 'DESC')); html_header_sort($display_text, get_request_var('sort_column'), get_request_var('sort_direction')); $i = 0; if (sizeof($devices) > 0) { foreach ($devices as $device) { $hostinfo['hostname'] = $device['hostname']; $hostinfo['user'] = $device['user_name']; switch ($device['term_type']) { case 0: $hostinfo['transport'] = 'none'; break; case 1: $hostinfo['transport'] = 'telnet'; break; case 2: $hostinfo['transport'] = 'ssh'; break; case 3: $hostinfo['transport'] = 'http'; break; case 4: $hostinfo['transport'] = 'https'; break; } form_alternate_row(); ?> <td width=100> <?php if (api_user_realm_auth('mactrack_sites.php')) { ?> <a href='<?php print htmlspecialchars($webroot . 'mactrack_devices.php?action=edit&device_id=' . $device['device_id']); ?> ' title='<?php print __('Edit Device'); ?> '><img border='0' src='<?php print $webroot; ?> images/edit_object.png'></a> <?php api_plugin_hook_function('remote_link', $hostinfo); } ?> <?php if ($device['host_id'] > 0) { ?> <a href='<?php print htmlspecialchars($webroot . 'mactrack_view_graphs.php?action=preview&report=graphs&style=selective&graph_list=&host=' . $device['host_id'] . '&graph_template_id=0&filter='); ?> ' title='<?php print __('View Graphs'); ?> '><img border='0' src='<?php print $webroot; ?> images/view_graphs.gif'></a> <?php } else { ?> <img title='<?php print __('Device Not Mapped to Cacti Device'); ?> ' border='0' src='<?php print $webroot; ?> images/view_graphs_disabled.gif'> <?php } ?> <a href='<?php print htmlspecialchars($webroot . 'mactrack_view_macs.php?report=macs&reset&device_id=-1&scan_date=3&site_id=' . get_request_var('site_id') . '&device_id=' . $device['device_id']); ?> ' title='<?php print __('View MAC Addresses'); ?> '><img border='0' src='<?php print $webroot; ?> images/view_macs.gif'></a> <a href='<?php print htmlspecialchars($webroot . 'mactrack_view_interfaces.php?report=interfaces&reset&site=' . get_request_var('site_id') . '&device=' . $device['device_id']); ?> ' title='<?php print __('View Interfaces'); ?> '><img border='0' src='<?php print $webroot; ?> images/view_interfaces.gif'></a> </td> <td class='hyperLink'> <?php print filter_value($device['device_name'], get_request_var('filter')); ?> </td> <td><?php print filter_value($device['site_name'], get_request_var('filter')); ?> <td><?php print get_colored_device_status($device['disabled'] == 'on' ? true : false, $device['snmp_status']); ?> </td> <td><?php print filter_value($device['hostname'], get_request_var('filter')); ?> <td><?php print $device['device_type']; ?> </td)> <td><?php print $device['scan_type'] == '1' ? __('N/A') : number_format_i18n($device['ips_total']); ?> </td> <td><?php print $device['scan_type'] == '3' ? __('N/A') : number_format_i18n($device['ports_total']); ?> </td> <td><?php print $device['scan_type'] == '3' ? __('N/A') : number_format_i18n($device['ports_active']); ?> </td> <td><?php print $device['scan_type'] == '3' ? __('N/A') : number_format_i18n($device['ports_trunk']); ?> </td> <td><?php print $device['scan_type'] == '3' ? __('N/A') : number_format_i18n($device['macs_active']); ?> </td> <td><?php print $device['scan_type'] == '3' ? __('N/A') : number_format_i18n($device['vlans_total']); ?> </td> <td><?php print number_format($device['last_runduration'], 1); ?> </td> </tr> <?php } } else { print '<tr><td colspan="10"><em>' . __('No MacTrack Devices') . '</em></td></tr>'; } html_end_box(false); if (sizeof($devices)) { print $nav; mactrack_display_stats(); } }