function get_pseudowire_table($vars) { $sql = generate_pseudowire_query($vars); $entries = array(); foreach (dbFetchRows($sql) as $entry) { if (!isset($GLOBALS['cache']['devices']['id'][$entry['device_id']])) { continue; } // Device hostname $entry['hostname'] = $GLOBALS['cache']['devices']['id'][$entry['device_id']]['hostname']; // Remote Peer $peer_addr = $entry['peer_addr']; $peer_addr_type = get_ip_version($peer_addr); if ($peer_addr_type && $entry['peer_device_id']) { if ($peer_addr_type == 6) { $peer_addr = Net_IPv6::uncompress($peer_addr, TRUE); } $peer_addr_type = 'ipv' . $peer_addr_type; //$entry['peer_addr'] = $peer_addr; //$entry['peer_addr_type'] = $peer_addr_type; if (!is_array($cache_pseudowires['ips'][$peer_addr])) { $cache_pseudowires['ips'][$peer_addr]['port_id'] = dbFetchCell('SELECT `port_id` FROM `' . $peer_addr_type . '_addresses` WHERE `' . $peer_addr_type . '_address` = ? ' . generate_query_values($GLOBALS['cache']['ports']['pseudowires'], 'port_id') . ' LIMIT 1;', array($peer_addr)); if (!is_numeric($cache_pseudowires['ips'][$peer_addr]['port_id'])) { // Separate entry for find correct port $cache_pseudowires['ips'][$peer_addr]['port_id_fix'] = dbFetchCell('SELECT `port_id` FROM `' . $peer_addr_type . '_addresses` WHERE `' . $peer_addr_type . '_address` = ? ' . $GLOBALS['cache']['where']['ports_permitted'] . ' LIMIT 1;', array($peer_addr)); } //$cache_pseudowires['ips'][$peer_addr]['host'] = $entry['reverse_dns']; } $entry['peer_port_id'] = $cache_pseudowires['ips'][$peer_addr]['port_id']; if (is_numeric($cache_pseudowires['ips'][$peer_addr]['port_id_fix'])) { // If we found port on remote device, than both devices in DB and will try to fix real port $peer_port_tmp = get_port_by_id_cache($cache_pseudowires['ips'][$peer_addr]['port_id_fix']); $peer_port_fix = dbFetchCell('SELECT `port_id` FROM `pseudowires` WHERE `device_id` = ? AND `pwID` = ? LIMIT 1;', array($peer_port_tmp['device_id'], $entry['pwID'])); if (is_numeric($peer_port_fix)) { $entry['peer_port_id'] = $peer_port_fix; } else { $entry['peer_port_id'] = $cache_pseudowires['ips'][$peer_addr]['port_id_fix']; } } //r($entry['peer_port_id']); if ($entry['peer_port_id']) { $entry['peer_port'] = get_port_by_id_cache($entry['peer_port_id']); //r($entry['peer_port']); $entry['peer_device_id'] = $entry['peer_port']['device_id']; //r($entry['peer_device_id']); $entry['peer_device'] = device_by_id_cache($entry['peer_device_id']); } } $entry['hostname'] = $GLOBALS['cache']['devices']['id'][$entry['device_id']]['hostname']; // Attach hostname for sorting $entries[] = $entry; } // Sorting switch ($vars['sort_order']) { case 'desc': $sort_order = SORT_DESC; $sort_neg = SORT_ASC; break; case 'reset': unset($vars['sort'], $vars['sort_order']); // no break here // no break here default: $sort_order = SORT_ASC; $sort_neg = SORT_DESC; } switch ($vars['sort']) { case 'device': $entries = array_sort_by($entries, 'hostname', $sort_order, SORT_STRING); break; case 'pwid': $entries = array_sort_by($entries, 'pwID', $sort_order, SORT_NUMERIC); break; case 'pwtype': $entries = array_sort_by($entries, 'pwType', $sort_order, SORT_STRING, 'pwPsnType', $sort_order, SORT_STRING); //$pws = array_sort_by($pws, 'pwType', $sort_order, SORT_STRING); break; case 'peer_addr': $entries = array_sort_by($entries, 'peer_addr', $sort_order, SORT_NUMERIC); break; case 'event': $entries = array_sort_by($entries, 'event', $sort_order, SORT_STRING); break; case 'uptime': $entries = array_sort_by($entries, 'pwUptime', $sort_order, SORT_NUMERIC); break; case 'last_change': $entries = array_sort_by($entries, 'last_change', $sort_neg, SORT_NUMERIC); break; case 'status': $entries = array_sort_by($entries, 'pwOperStatus', $sort_order, SORT_STRING); break; default: // Not sorted } return $entries; }
register_html_title("Pseudowires"); if (!isset($vars['view'])) { $vars['view'] = 'basic'; } $link_array = array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'pseudowires', 'graph' => $vars['graph']); //$link_array = array_merge($link_array, $vars); $navbar = array('brand' => "Pseudowires", 'class' => "navbar-narrow"); if (!isset($vars['type'])) { $navbar['options']['all']['class'] = "active"; } $navbar['options']['all']['url'] = generate_url($link_array, array('pwtype' => NULL)); $navbar['options']['all']['text'] = "All Types"; $vars_filter = $vars; unset($vars_filter['pwtype']); // Do not filter type $sql = generate_pseudowire_query($vars_filter); foreach (dbFetchRows($sql) as $pw) { $pw_type = $pw['pwType']; $pw_label = nicecase($pw_type); // Combinate different types with same label if (!in_array($pw_type, $pw_types[$pw_label])) { $pw_types[$pw_label][] = $pw_type; } } ksort($pw_types); foreach ($pw_types as $text => $type) { $type = implode(',', $type); if ($vars['pwtype'] == $type) { $navbar['options'][$type]['class'] = "active"; unset($navbar['options']['all']['class']); }