$value) { if ($value != '') { switch ($var) { case 'device': case 'device_id': $where .= generate_query_values_and($value, 'device_id'); break; case 'port': case 'port_id': $where .= generate_query_values_and($value, 'port_id'); break; case 'ip_version': $where .= generate_query_values_and($value, 'ip_version'); break; case 'address': if (isset($vars['searchby']) && $vars['searchby'] === 'ip') { $value = trim($value); if (str_contains($value, ':')) { if (get_ip_version($value) === 5) { $value = ip_uncompress($value); } else { // FIXME. Need another conversion ("2001:b08:b08" -> "2001:0b08:0b08") -- mike } } $where .= generate_query_values_and($value, 'ip_address', '%LIKE%'); } else { // MAC Addresses $value = str_replace([':', ' ', '-', '.', '0x'], '', $value); $where .= generate_query_values_and($value, 'mac_address', '%LIKE%'); } break; } } } $sort_order = get_sort_order($vars); if (isset($vars['sort'])) { switch ($vars['sort']) { case "port": //$sort = " ORDER BY `port_label`, `mac_ifIndex`"; $sort = generate_query_sort(['-port_label', 'mac_ifIndex'], $sort_order); break; case "ip_version": //$sort = " ORDER BY `ip_version`"; $sort = generate_query_sort('ip_version', $sort_order); break; case "ip": case "address": //$sort = " ORDER BY `ip_address`"; $sort = generate_query_sort('ip_address', $sort_order); break; case "mac": default: //$sort = " ORDER BY `mac_address`"; $sort = generate_query_sort('mac_address', $sort_order); } } // Show ARP tables only for permitted ports $query_permitted = generate_query_permitted(['port', 'device'], ['port_null' => TRUE]); // allow empty port_id $query = 'FROM `ip_mac` '; $query .= 'LEFT JOIN `ports` USING (`device_id`, `port_id`) '; $query .= $where . $query_permitted; $query_count = 'SELECT COUNT(`mac_id`) ' . $query; $query = 'SELECT * ' . $query; $query .= $sort; $query .= " LIMIT $start,$pagesize"; // Query ARP/NDP table addresses $entries = dbFetchRows($query, $param); // Query ARP/NDP table address count if ($pagination) { $count = dbFetchCell($query_count, $param); } $list = ['device' => FALSE, 'port' => FALSE]; if (!isset($vars['device']) || empty($vars['device']) || $vars['page'] == 'search') { $list['device'] = TRUE; } if (!isset($vars['port']) || empty($vars['port']) || $vars['page'] == 'search') { $list['port'] = TRUE; } $string = generate_box_open(); $string .= '
' . generate_popup_link('mac', format_mac($entry['mac_address'])) . ' | ' . PHP_EOL; $string .= '' . generate_popup_link('ip', $ip_address) . ' | ' . PHP_EOL; if ($list['device']) { $dev = device_by_id_cache($entry['device_id']); $string .= '' . generate_device_link($dev) . ' | ' . PHP_EOL; } if ($list['port']) { if ($entry['ifInErrors_delta'] > 0 || $entry['ifOutErrors_delta'] > 0) { $port_error = generate_port_link($entry, 'Errors', 'port_errors'); } if ($entry['port_id']) { $port_string = generate_port_link_short($entry) . ' ' . $port_error; } else { // For VRF port_id can be unknown $port_string = 'ifIndex ' . $entry['mac_ifIndex']; } $string .= '' . $port_string . ' | ' . PHP_EOL; } $string .= '' . $arp_name . ' | ' . PHP_EOL; $string .= '' . $arp_if . ' | ' . PHP_EOL; $string .= '