function build_alert_table_query($vars) { $args = array(); $where = ' WHERE 1 '; // Loop through the vars building a sql query from relevant values foreach ($vars as $var => $value) { if ($value != '') { switch ($var) { // Search by device_id if we have a device or device_id case 'device_id': $where .= ' AND `device_id` = ?'; $param[] = $value; break; case 'entity_type': if ($value != 'all') { $where .= ' AND `entity_type` = ?'; $param[] = $value; } break; case 'entity_id': $where .= ' AND `entity_id` = ?'; $param[] = $value; break; case 'alert_test_id': $where .= ' AND `alert_test_id` = ?'; $param[] = $value; break; case 'status': if ($value == 'failed') { $where .= " AND `alert_status` IN (0,2,3)"; } break; } } } // Permissions query $query_permitted = generate_query_permitted(array('device'), array('hide_ignored' => TRUE)); // Base query $query = 'FROM `alert_table` '; $query .= 'LEFT JOIN `alert_table-state` USING(`alert_table_id`) '; $query .= $where . $query_permitted; // Build the query to get a count of entries $query_count = 'SELECT COUNT(`alert_table_id`) ' . $query; // Build the query to get the list of entries $query = 'SELECT * ' . $query; $query .= ' ORDER BY `device_id`, `alert_test_id`, `entity_type`, `entity_id` DESC '; if (isset($vars['pagination']) && $vars['pagination']) { pagination($vars, 0, TRUE); // Get default pagesize/pageno $vars['start'] = $vars['pagesize'] * $vars['pageno'] - $vars['pagesize']; $query .= 'LIMIT ' . $vars['start'] . ',' . $vars['pagesize']; } return array($query, $param, $query_count); }
/** * Observium * * This file is part of Observium. * * @package observium * @subpackage functions * @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited * */ function generate_p2pradio_query($vars) { $sql = "SELECT * FROM `p2p_radios`"; $sql .= ' WHERE 1' . generate_query_permitted(array('device')); // Build query foreach ($vars as $var => $value) { switch ($var) { case "group": case "group_id": $values = get_group_entities($value); $sql .= generate_query_values($values, 'radio_id'); break; case "device": case "device_id": $sql .= generate_query_values($value, 'device_id'); break; } } return $sql; }
/** * Observium * * This file is part of Observium. * * @package observium * @subpackage web * @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited * */ function generate_processor_query($vars) { $sql = "SELECT * FROM `processors`"; $sql .= " LEFT JOIN `processors-state` USING(`processor_id`)"; $sql .= ' WHERE 1' . generate_query_permitted(array('device')); // Build query foreach ($vars as $var => $value) { switch ($var) { case "group": case "group_id": $values = get_group_entities($value); $sql .= generate_query_values($values, 'processor_id'); break; case "device": case "device_id": $sql .= generate_query_values($value, 'device_id'); break; } } return $sql; }
/** * Observium * * This file is part of Observium. * * @package observium * @subpackage web * @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited * */ function build_mempool_query($vars) { global $config, $cache; $sql = 'SELECT *, `mempools`.`mempool_id` AS `mempool_id` FROM `mempools`'; $sql .= ' LEFT JOIN `mempools-state` USING(`mempool_id`)'; $sql .= ' WHERE 1' . generate_query_permitted(array('device')); // Build query foreach ($vars as $var => $value) { switch ($var) { case "group": case "group_id": $values = get_group_entities($value); $sql .= generate_query_values($values, 'mempools.mempool_id'); break; case "device": case "device_id": $sql .= generate_query_values($value, 'mempools.device_id'); break; } } return $sql; }
/** * Observium * * This file is part of Observium. * * @package observium * @subpackage webui * @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited * */ function build_printersupplies_query($vars) { $sql = 'SELECT * FROM `printersupplies`'; $sql .= ' WHERE 1' . generate_query_permitted(array('device')); // Build query foreach ($vars as $var => $value) { switch ($var) { case "group": case "group_id": $values = get_group_entities($value); $sql .= generate_query_values($values, 'printersupplies.supply_id'); break; case "device": case "device_id": $sql .= generate_query_values($value, 'printersupplies.device_id'); break; case "supply": $sql .= generate_query_values($value, 'printersupplies.supply_type'); break; } } return $sql; }
/** * Display Devices Inventory. * * @param array $vars * @return none * */ function print_inventory($vars) { // On "Inventory" device tab display hierarchical list if ($vars['page'] == 'device' && is_numeric($vars['device']) && device_permitted($vars['device'])) { echo '<table class="table table-striped table-bordered table-condensed table-rounded"><tr><td>'; echo '<div class="btn-group pull-right" style="margin-top:5px; margin-right: 5px;"> <button class="btn btn-small" onClick="expandTree(\'enttree\');return false;"><i class="icon-plus muted small"></i> Expand</button> <button class="btn btn-small" onClick="collapseTree(\'enttree\');return false;"><i class="icon-minus muted small"></i> Collapse</button> </div>'; echo '<div style="clear: left; margin: 5px;"><ul class="mktree" id="enttree" style="margin-left: -10px;">'; $level = 0; $ent['entPhysicalIndex'] = 0; print_ent_physical($ent['entPhysicalIndex'], $level, "liOpen"); echo '</ul></div>'; echo '</td></tr></table>'; return TRUE; } // With pagination? (display page numbers in header) $pagination = isset($vars['pagination']) && $vars['pagination']; pagination($vars, 0, TRUE); // Get default pagesize/pageno $pageno = $vars['pageno']; $pagesize = $vars['pagesize']; $start = $pagesize * $pageno - $pagesize; $param = array(); $where = ' WHERE 1 '; foreach ($vars as $var => $value) { if ($value != '') { switch ($var) { case 'device': case 'device_id': $where .= generate_query_values($value, 'E.device_id'); break; case 'parts': $where .= generate_query_values($value, 'E.entPhysicalModelName', 'LIKE'); break; case 'serial': $where .= ' AND E.`entPhysicalSerialNum` LIKE ?'; $param[] = '%' . $value . '%'; break; case 'description': $where .= ' AND E.`entPhysicalDescr` LIKE ?'; $param[] = '%' . $value . '%'; break; } } } // Show inventory only for permitted devices $query_permitted = generate_query_permitted(array('device'), array('device_table' => 'D')); $query = 'FROM `entPhysical` AS E '; $query .= 'LEFT JOIN `devices` AS D ON D.`device_id` = E.`device_id` '; $query .= $where . $query_permitted; $query_count = 'SELECT COUNT(*) ' . $query; $query = 'SELECT * ' . $query; $query .= ' ORDER BY D.`hostname`'; $query .= " LIMIT {$start},{$pagesize}"; // Query inventories $entries = dbFetchRows($query, $param); // Query inventory count if ($pagination) { $count = dbFetchCell($query_count, $param); } $list = array('device' => FALSE); if (!isset($vars['device']) || empty($vars['device']) || $vars['page'] == 'inventory') { $list['device'] = TRUE; } $string = '<table class="table table-bordered table-striped table-hover table-condensed">' . PHP_EOL; if (!$short) { $string .= ' <thead>' . PHP_EOL; $string .= ' <tr>' . PHP_EOL; if ($list['device']) { $string .= ' <th>Device</th>' . PHP_EOL; } $string .= ' <th>Name</th>' . PHP_EOL; $string .= ' <th>Description</th>' . PHP_EOL; $string .= ' <th>Part #</th>' . PHP_EOL; $string .= ' <th>Serial #</th>' . PHP_EOL; $string .= ' </tr>' . PHP_EOL; $string .= ' </thead>' . PHP_EOL; } $string .= ' <tbody>' . PHP_EOL; foreach ($entries as $entry) { $string .= ' <tr>' . PHP_EOL; if ($list['device']) { $string .= ' <td class="entity" style="white-space: nowrap">' . generate_device_link($entry, NULL, array('page' => 'device', 'tab' => 'entphysical')) . '</td>' . PHP_EOL; } if ($entry['ifIndex']) { $interface = get_port_by_ifIndex($entry['device_id'], $entry['ifIndex']); $entry['entPhysicalName'] = generate_port_link($interface); } elseif ($entry['entPhysicalClass'] == "sensor") { $sensor = dbFetchRow("SELECT * FROM `sensors` AS S\n LEFT JOIN `sensors-state` AS ST ON S.`sensor_id` = ST.`sensor_id`\n WHERE `device_id` = ? AND (`entPhysicalIndex` = ? OR `sensor_index` = ?)", array($entry['device_id'], $entry['entPhysicalIndex'], $entry['entPhysicalIndex'])); //$ent_text .= ' ('.$sensor['sensor_value'] .' '. $sensor['sensor_class'].')'; $entry['entPhysicalName'] = generate_entity_link('sensor', $sensor); } $string .= ' <td style="width: 160px;">' . $entry['entPhysicalName'] . '</td>' . PHP_EOL; $string .= ' <td>' . $entry['entPhysicalDescr'] . '</td>' . PHP_EOL; $string .= ' <td>' . $entry['entPhysicalModelName'] . '</td>' . PHP_EOL; $string .= ' <td>' . $entry['entPhysicalSerialNum'] . '</td>' . PHP_EOL; $string .= ' </tr>' . PHP_EOL; } $string .= ' </tbody>' . PHP_EOL; $string .= '</table>'; // Print pagination header if ($pagination) { $string = pagination($vars, $count) . $string . pagination($vars, $count); } // Print Inventories echo $string; }
$where = "WHERE 1"; } // FIXME this shit probably needs tidied up. if (isset($vars['format']) && preg_match("/^[a-z]*\$/", $vars['format'])) { # $map = 'digraph G { bgcolor=transparent; splines=true; overlap=scale; concentrate=0; epsilon=0.001; rankdir=LR $map = 'digraph G { bgcolor=transparent; splines=true; overlap=scale; rankdir=LR node [ fontname="helvetica", fontstyle=bold, style=filled, color=white, fillcolor=lightgrey, overlap=false]; edge [ bgcolor=white, fontname="helvetica", fontstyle=bold, arrowhead=dot, arrowtail=dot]; graph [bgcolor=transparent;]; '; if (!$_SESSION['authenticated']) { $map .= "\"没有经过身份验证\" [fontsize=20 fillcolor=\"lightblue\", URL=\"/\" shape=box3d]\n"; } else { $loc_count = 1; $cache['where']['devices_permitted'] = generate_query_permitted(array('device'), array('device_table' => 'D')); foreach (dbFetch("SELECT D.*, COUNT(L.local_port_id) FROM devices AS D LEFT JOIN (ports AS I, links AS L) ON (D.device_id = I.device_id AND I.port_id = L.local_port_id) " . $where . $cache['where']['devices_permitted'] . " GROUP BY D.hostname ORDER BY COUNT(L.local_port_id) DESC") as $device) { if ($device) { $links = dbFetch("SELECT * from ports AS I, links AS L WHERE I.device_id = ? AND L.local_port_id = I.port_id ORDER BY L.remote_hostname", array($device['device_id'])); if (count($links)) { $ranktype = substr($device['hostname'], 0, 2); $ranktype2 = substr($device['hostname'], 0, 3); if (!strncmp($device['hostname'], "c", 1) && !strstr($device['hostname'], "kalooga")) { $ranks[$ranktype][] = $device['hostname']; } else { $ranks[$ranktype2][] = $device['hostname']; } if ($anon) { $device['hostname'] = md5($device['hostname']); } if (!isset($locations[$device['location']])) {
*/ // Set Defaults here if (!isset($vars['format'])) { $vars['format'] = "detail"; } if (!$config['web_show_disabled'] && !isset($vars['disabled'])) { $vars['disabled'] = '0'; } if ($vars['format'] != 'graphs') { // reset all from/to vars if not use graphs unset($vars['from'], $vars['to'], $vars['timestamp_from'], $vars['timestamp_to'], $vars['graph']); } /// FIXME - new style (print_search_simple) of searching here $where = ' WHERE 1 '; $where_array = array(); $query_permitted = generate_query_permitted(array('device'), array('device_table' => 'devices')); foreach ($vars as $var => $value) { if ($value != '') { switch ($var) { case 'group': $values = get_group_entities($value); $where_array[$var] = generate_query_values($values, 'device_id'); break; case 'hostname': case 'sysname': $where_array[$var] = generate_query_values($value, $var, '%LIKE%'); break; case 'location_text': $where_array[$var] = generate_query_values($value, 'location', '%LIKE%'); break; case 'os':
* @subpackage webui * @author Adam Armstrong <*****@*****.**> * @copyright (C) 2006-2014 Adam Armstrong * */ if ($bg == "#ffffff") { $bg = "#e5e5e5"; } else { $bg = "#ffffff"; } if (!is_array($vars['type'])) { $vars['type'] = array($vars['type']); } $where = 'WHERE 1'; $where .= generate_query_values($vars['type'], 'port_descr_type', 'LIKE'); $where .= generate_query_permitted(array('port')); $ports = dbFetchRows("SELECT * FROM `ports` AS I, `devices` AS D {$where} AND I.`device_id` = D.`device_id` ORDER BY I.`ifAlias`"); $if_list = array(); foreach ($ports as $port) { $if_list[] = $port['port_id']; } $if_list = implode(',', $if_list); for ($i = 0; $i < count($vars['type']); $i++) { $vars['type'][$i] = nicecase($vars['type'][$i]); } $types = implode(' + ', $vars['type']); echo '<h4>Total Graph for ports of type : ' . $types . '</h4>'; if ($if_list) { $graph_type = "multiport_bits_separate"; $port['port_id'] = $if_list; include "includes/print-interface-graphs.inc.php";
/** * Display dot1x sessions * * @param array $vars * @return none * */ function print_dot1xtable($vars) { // With pagination? (display page numbers in header) $pagination = isset($vars['pagination']) && $vars['pagination']; pagination($vars, 0, TRUE); // Get default pagesize/pageno $pageno = $vars['pageno']; $pagesize = $vars['pagesize']; $start = $pagesize * $pageno - $pagesize; $param = array(); $where = ' WHERE 1 '; foreach ($vars as $var => $value) { if ($value != '') { switch ($var) { case 'device': case 'device_id': $where .= generate_query_values($value, 'device_id'); break; case 'address': if (isset($vars['searchby']) && $vars['searchby'] == 'ip') { $value = trim($value); $where .= generate_query_values($value, 'ipv4_addr', '%LIKE%'); } else { if (isset($vars['searchby']) && $vars['searchby'] == 'mac') { $value = str_replace(array(':', ' ', '-', '.', '0x'), '', $value); $where .= generate_query_values($value, 'M.mac_addr', '%LIKE%'); } else { $value = trim($value); $where .= generate_query_values($value, 'username', '%LIKE%'); } } break; } } } // Check permissions $query_permitted = generate_query_permitted(array('device'), array('device_table' => 'M')); $query = 'FROM `wifi_sessions` AS M '; $query .= 'LEFT JOIN `wifi_radios` AS I ON I.`wifi_radio_id` = M.`radio_id` '; $query .= $where . $query_permitted; $query_count = 'SELECT COUNT(`wifi_session_id`) ' . $query; $query = 'SELECT *, M.`mac_addr` AS `session_mac` ' . $query; $query .= ' ORDER BY M.`timestamp` DESC'; $query .= " LIMIT {$start},{$pagesize}"; // Query wireless sessions table $entries = dbFetchRows($query, $param); // Query wireless sessions table count if ($pagination) { $count = dbFetchCell($query_count, $param); } $aps_db = dbFetchRows("SELECT `wifi_accesspoint_id`, `name`, `ap_number` FROM `wifi_accesspoints`"); foreach ($aps_db as $ap_db) { $aps_sorted_db[$ap_db['wifi_accesspoint_id']] = $ap_db; } $list = array('device' => FALSE, 'port' => FALSE); // A radio is like a port 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 .= '<table class="table table-striped table-hover table-condensed">' . PHP_EOL; if (!$short) { $string .= ' <thead>' . PHP_EOL; $string .= ' <tr>' . PHP_EOL; $string .= ' <th>MAC Address</th>' . PHP_EOL; $string .= ' <th>IP Address</th>' . PHP_EOL; $string .= ' <th>Username</th>' . PHP_EOL; $string .= ' <th>SSID/VLAN</th>' . PHP_EOL; $string .= ' <th>Last Seen</th>' . PHP_EOL; if ($list['device']) { $string .= ' <th>Device</th>' . PHP_EOL; } if ($list['port']) { $string .= ' <th>Interface/AP</th>' . PHP_EOL; } $string .= ' </tr>' . PHP_EOL; $string .= ' </thead>' . PHP_EOL; } $string .= ' <tbody>' . PHP_EOL; foreach ($entries as $entry) { $ap_id = $entry['accesspoint_id']; $interface = $aps_sorted_db[$ap_id]['name']; $string .= ' <tr>' . PHP_EOL; $string .= ' <td style="width: 140px;">' . generate_popup_link('mac', format_mac($entry['session_mac'])) . '</td>' . PHP_EOL; $string .= ' <td style="width: 140px;">' . generate_popup_link('ip', $entry['ipv4_addr']) . '</td>' . PHP_EOL; $string .= ' <td style="white-space: nowrap;">' . $entry['username'] . '</td>' . PHP_EOL; $string .= ' <td style="width: 140px;">' . $entry['ssid'] . '</td>' . PHP_EOL; $string .= ' <td style="white-space: nowrap;">' . $entry['timestamp'] . '</td>' . PHP_EOL; if ($list['device']) { $dev = device_by_id_cache($entry['device_id']); $string .= ' <td class="entity" style="white-space: nowrap;">' . generate_device_link($dev) . '</td>' . PHP_EOL; } if ($list['port']) { $string .= ' <td class="entity"><a href="' . generate_url(array('page' => 'device', 'device' => $entry['device_id'], 'tab' => 'wifi', 'view' => 'accesspoint', 'accesspoint' => $ap_id)) . '">' . $interface . '</a></td>' . PHP_EOL; } $string .= ' </tr>' . PHP_EOL; } $string .= ' </tbody>' . PHP_EOL; $string .= '</table>'; $string .= generate_box_close(); // Print pagination header if ($pagination) { $string = pagination($vars, $count) . $string . pagination($vars, $count); } // Print wireless sessions echo $string; }
/** * Display ARP/NDP table addresses. * * Display pages with ARP/NDP tables addresses from devices. * * @param array $vars * @return none * */ function print_arptable($vars) { // With pagination? (display page numbers in header) $pagination = isset($vars['pagination']) && $vars['pagination']; pagination($vars, 0, TRUE); // Get default pagesize/pageno $pageno = $vars['pageno']; $pagesize = $vars['pagesize']; $start = $pagesize * $pageno - $pagesize; $param = array(); $where = ' WHERE 1 '; foreach ($vars as $var => $value) { if ($value != '') { switch ($var) { case 'device': case 'device_id': $where .= generate_query_values($value, 'device_id'); break; case 'port': case 'port_id': $where .= generate_query_values($value, 'I.port_id'); break; case 'ip_version': $where .= generate_query_values($value, 'ip_version'); break; case 'address': if (isset($vars['searchby']) && $vars['searchby'] == 'ip') { $value = trim($value); if (strpos($value, ':') !== FALSE) { if (Net_IPv6::checkIPv6($value)) { $value = Net_IPv6::uncompress($value, TRUE); } else { // FIXME. Need another conversion ("2001:b08:b08" -> "2001:0b08:0b08") -- mike } } $where .= generate_query_values($value, 'ip_address', '%LIKE%'); } else { // MAC Addresses $value = str_replace(array(':', ' ', '-', '.', '0x'), '', $value); $where .= generate_query_values($value, 'mac_address', '%LIKE%'); } break; } } } if (isset($vars['sort'])) { switch ($vars['sort']) { case "port": $sort = " ORDER BY `I`.`port_label`"; break; case "ip_version": $sort = " ORDER BY `ip_version`"; break; case "ip": case "address": $sort = " ORDER BY `ip_address`"; break; case "mac": default: $sort = " ORDER BY `mac_address`"; } } // Show ARP tables only for permitted ports $query_permitted = generate_query_permitted(array('port'), array('port_table' => 'I')); $query = 'FROM `ip_mac` AS M '; $query .= 'LEFT JOIN `ports` AS I ON I.`port_id` = M.`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 = array('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 .= '<table class="table table-striped table-hover table-condensed">' . PHP_EOL; $cols = array('mac' => 'MAC Address', 'ip' => 'IP Address', 'device' => 'Device', 'port' => 'Port', '!remote_device' => 'Remote Device', '!remote_port' => 'Remote Port'); if (!$list['device']) { unset($cols['device']); } if (!$list['port']) { unset($cols['port']); } if (!$short) { $string .= get_table_header($cols, $vars); // Currently sorting is not available } foreach ($entries as $entry) { humanize_port($entry); $ip_version = $entry['ip_version']; $ip_address = $ip_version == 6 ? Net_IPv6::compress($entry['ip_address']) : $entry['ip_address']; $arp_host = dbFetchRow('SELECT * FROM `ipv' . $ip_version . '_addresses` AS A LEFT JOIN `ports` AS I ON A.`port_id` = I.`port_id` LEFT JOIN `devices` AS D ON D.`device_id` = I.`device_id` WHERE A.`ipv' . $ip_version . '_address` = ?', array($ip_address)); $arp_name = $arp_host ? generate_device_link($arp_host) : ''; $arp_if = $arp_host ? generate_port_link($arp_host) : ''; if ($arp_host['device_id'] == $entry['device_id']) { $arp_name = 'Self Device'; } if ($arp_host['port_id'] == $entry['port_id']) { $arp_if = 'Self Port'; } $string .= ' <tr>' . PHP_EOL; $string .= ' <td style="width: 160px;" class="entity">' . generate_popup_link('mac', format_mac($entry['mac_address'])) . '</td>' . PHP_EOL; $string .= ' <td style="width: 140px;">' . generate_popup_link('ip', $ip_address) . '</td>' . PHP_EOL; if ($list['device']) { $dev = device_by_id_cache($entry['device_id']); $string .= ' <td class="entity" style="white-space: nowrap;">' . generate_device_link($dev) . '</td>' . PHP_EOL; } if ($list['port']) { if ($entry['ifInErrors_delta'] > 0 || $entry['ifOutErrors_delta'] > 0) { $port_error = generate_port_link($entry, '<span class="label label-important">Errors</span>', 'port_errors'); } $string .= ' <td class="entity">' . generate_port_link($entry, $entry['port_label_short']) . ' ' . $port_error . '</td>' . PHP_EOL; } $string .= ' <td class="entity" style="width: 200px;">' . $arp_name . '</td>' . PHP_EOL; $string .= ' <td class="entity">' . $arp_if . '</td>' . PHP_EOL; $string .= ' </tr>' . PHP_EOL; } $string .= ' </tbody>' . PHP_EOL; $string .= '</table>'; $string .= generate_box_close(); // Print pagination header if ($pagination) { $string = pagination($vars, $count) . $string . pagination($vars, $count); } // Print ARP/NDP table echo $string; }
* Observium * * This file is part of Observium. * * @package observium * @subpackage webui * @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited * */ ?> <div class="row"> <div class="col-md-12"> <?php $where = ' WHERE 1 '; $where .= generate_query_permitted(array('device'), array('device_table' => 'F')); // Select devices and vlans only with FDB tables foreach (dbFetchRows('SELECT F.`device_id`, `vlan_vlan`, `vlan_name` FROM `vlans_fdb` AS F LEFT JOIN `vlans` as V ON V.`vlan_vlan` = F.`vlan_id` AND V.`device_id` = F.`device_id`' . $where . 'GROUP BY `device_id`, `vlan_vlan`;') as $data) { if (is_numeric($data['vlan_vlan'])) { $form_devices[] = $data['device_id']; $form_items['vlans'][$data['vlan_vlan']] = 'Vlan ' . $data['vlan_vlan']; $form_items['vlan_name'][$data['vlan_name']] = $data['vlan_name']; } } ksort($form_items['vlans']); natcasesort($form_items['vlan_name']); // Select the devices with FDB tables //$form_devices = dbFetchColumn('SELECT DISTINCT `device_id` FROM `vlans_fdb`'); $form_items['devices'] = generate_form_values('device', $form_devices); $form = array('type' => 'rows', 'space' => '5px', 'submit_by_key' => TRUE, 'url' => 'search/search=fdb/');
<?php /** * Observium * * This file is part of Observium. * * @package observium * @subpackage webui * @copyright (C) 2006-2014 Adam Armstrong * */ $graph_type = "processor_usage"; $sql = "SELECT *, `processors`.`processor_id` AS `processor_id` FROM `processors`"; $sql .= " LEFT JOIN `processors-state` ON `processors`.`processor_id` = `processors-state`.`processor_id`"; $sql .= ' WHERE 1' . generate_query_permitted(array('device')); // Groups if (isset($vars['group'])) { $values = get_group_entities($vars['group']); $sql .= generate_query_values($values, 'processors.processor_id'); } $processors = array(); foreach (dbFetchRows($sql) as $proc) { if (isset($cache['devices']['id'][$proc['device_id']])) { $proc['hostname'] = $cache['devices']['id'][$proc['device_id']]['hostname']; $proc['html_row_class'] = $cache['devices']['id'][$proc['device_id']]['html_row_class']; $processors[] = $proc; } } $processors = array_sort_by($processors, 'hostname', SORT_ASC, SORT_STRING, 'processor_descr', SORT_ASC, SORT_STRING); $processors_count = count($processors);
/** * Display FDB table. * * @param array $vars * @return none * */ function print_fdbtable($vars) { // With pagination? (display page numbers in header) $pagination = isset($vars['pagination']) && $vars['pagination']; $pageno = isset($vars['pageno']) && !empty($vars['pageno']) ? $vars['pageno'] : 1; $pagesize = isset($vars['pagesize']) && !empty($vars['pagesize']) ? $vars['pagesize'] : 10; $start = $pagesize * $pageno - $pagesize; $param = array(); $where = ' WHERE 1 '; foreach ($vars as $var => $value) { if ($value != '') { $cond = array(); switch ($var) { case 'device': case 'device_id': $where .= ' AND I.`device_id` = ?'; $param[] = $value; break; case 'port': case 'port_id': $where .= ' AND I.`port_id` = ?'; $param[] = $value; break; case 'interface': $where .= ' AND I.`ifDescr` LIKE ?'; $param[] = $value; break; case 'vlan_id': if (!is_array($value)) { $value = array($value); } foreach ($value as $v) { $cond[] = '?'; $param[] = $v; } $where .= " AND F.`vlan_id` IN ("; $where .= implode(', ', $cond); $where .= ')'; break; case 'vlan_name': if (!is_array($value)) { $value = array($value); } foreach ($value as $v) { $cond[] = '?'; $param[] = $v; } $where .= " AND V.`vlan_name` IN ("; $where .= implode(', ', $cond); $where .= ')'; break; case 'address': $where .= ' AND F.`mac_address` LIKE ?'; $param[] = '%' . str_replace(array(':', ' ', '-', '.', '0x'), '', mres($value)) . '%'; break; } } } // Show FDB tables only for permitted ports $query_permitted = generate_query_permitted(array('port'), array('port_table' => 'I')); $query = 'FROM `vlans_fdb` AS F '; $query .= 'LEFT JOIN `vlans` as V ON V.`vlan_vlan` = F.`vlan_id` AND V.`device_id` = F.`device_id` '; $query .= 'LEFT JOIN `ports` AS I ON I.`port_id` = F.`port_id` '; $query .= $where . $query_permitted; $query_count = 'SELECT COUNT(*) ' . $query; $query = 'SELECT * ' . $query; $query .= ' ORDER BY F.`mac_address`'; $query .= " LIMIT {$start},{$pagesize}"; // Query addresses $entries = dbFetchRows($query, $param); // Query address count if ($pagination) { $count = dbFetchCell($query_count, $param); } $list = array('device' => FALSE); if (!isset($vars['device']) || empty($vars['device']) || $vars['page'] == 'search') { $list['device'] = TRUE; } $string = '<table class="table table-bordered table-striped table-hover table-condensed">' . PHP_EOL; if (!$short) { $string .= ' <thead>' . PHP_EOL; $string .= ' <tr>' . PHP_EOL; $string .= ' <th>MAC Address</th>' . PHP_EOL; if ($list['device']) { $string .= ' <th>Device</th>' . PHP_EOL; } $string .= ' <th>Interface</th>' . PHP_EOL; $string .= ' <th>VLAN ID</th>' . PHP_EOL; $string .= ' <th>VLAN Name</th>' . PHP_EOL; $string .= ' </tr>' . PHP_EOL; $string .= ' </thead>' . PHP_EOL; } $string .= ' <tbody>' . PHP_EOL; foreach ($entries as $entry) { humanize_port($entry); $string .= ' <tr>' . PHP_EOL; $string .= ' <td width="160">' . formatMac($entry['mac_address']) . '</td>' . PHP_EOL; if ($list['device']) { $dev = device_by_id_cache($entry['device_id']); $string .= ' <td class="entity" nowrap>' . generate_device_link($dev) . '</td>' . PHP_EOL; } if ($entry['ifInErrors_delta'] > 0 || $entry['ifOutErrors_delta'] > 0) { $port_error = generate_port_link($entry, '<span class="label label-important">Errors</span>', 'port_errors'); } $string .= ' <td class="entity">' . generate_port_link($entry, short_ifname($entry['label'])) . ' ' . $port_error . '</td>' . PHP_EOL; $string .= ' <td>Vlan' . $entry['vlan_vlan'] . '</td>' . PHP_EOL; $string .= ' <td>' . $entry['vlan_name'] . '</td>' . PHP_EOL; $string .= ' </tr>' . PHP_EOL; } $string .= ' </tbody>' . PHP_EOL; $string .= '</table>'; // Print pagination header if ($pagination) { $string = pagination($vars, $count) . $string . pagination($vars, $count); } // Print FDB table echo $string; }
* */ ?> <div class="row"> <div class="col-md-12"> <?php ///FIXME. Mike: should be more checks, at least a confirmation click. //if ($vars['action'] == "expunge" && $_SESSION['userlevel'] >= '10') //{ // dbFetchCell("TRUNCATE TABLE `syslog`"); // print_message('系统日志截断'); //} unset($search, $devices_array, $priorities, $programs); $where = ' WHERE 1 '; $where .= generate_query_permitted(); //Device field // Show devices only with syslog messages foreach (dbFetchRows('SELECT `device_id` FROM `syslog`' . $where . 'GROUP BY `device_id`') as $data) { $device_id = $data['device_id']; if ($cache['devices']['id'][$device_id]['hostname']) { $devices_array[$device_id] = $cache['devices']['id'][$device_id]['hostname']; } } natcasesort($devices_array); $search[] = array('type' => 'select', 'name' => 'Devices', 'id' => 'device_id', 'width' => '150px', 'value' => $vars['device_id'], 'values' => $devices_array); if (is_numeric($vars['device_id'])) { $where .= ' AND `device_id` = ' . $vars['device_id'] . ' '; } // Add device_id limit for other fields //Message field
$num_ports = dbFetchCell("SELECT COUNT(*) FROM `ports` WHERE device_id = ?", array($result['device_id'])); echo ' <dl style="border-left: 10px solid ' . $result['html_tab_colour'] . '; " class="dl-horizontal dl-search"> <dt style="padding-left: 10px; text-align: center;">' . getImage($result) . '</dt> <dd> <strong>' . highlight_search(htmlentities($name)) . ' <small>' . htmlentities($result['hardware']) . ' | ' . htmlentities($config['os'][$result['os']]['text']) . ' ' . htmlentities($result['version']) . ' <br /> ' . highlight_search(htmlentities($result['location'], 0, 'UTF-8')) . ' | ' . $num_ports . ' ports</small> </strong> </dd> </dl> </a> </li>' . PHP_EOL; } } /// SEARCH PORTS $query_permitted_port = generate_query_permitted(array('port')); $results = dbFetchRows("SELECT * FROM `ports`\n LEFT JOIN `devices` ON `ports`.`device_id` = `devices`.`device_id`\n WHERE (`ifAlias` LIKE '%{$queryString}%' OR `ifDescr` LIKE '%{$queryString}%') {$query_permitted_port}\n ORDER BY `ifDescr` LIMIT 8;"); if (count($results)) { $found = 1; echo '<li class="nav-header">Ports found: ' . count($results) . '</li>'; foreach ($results as $result) { humanize_port($result); echo '<li class="divider" style="margin: 0px;"></li>'; echo '<li>'; echo '<a href="' . generate_port_url($result) . '">'; $name = rewrite_ifname($result['ifDescr']); if (strlen($name) > 35) { $name = substr($name, 0, 35) . "..."; } $description = $result['ifAlias']; if (strlen($description) > 80) {
/** * Display ARP/NDP table addresses. * * Display pages with ARP/NDP tables addresses from devices. * * @param array $vars * @return none * */ function print_arptable($vars) { // With pagination? (display page numbers in header) $pagination = isset($vars['pagination']) && $vars['pagination']; $pageno = isset($vars['pageno']) && !empty($vars['pageno']) ? $vars['pageno'] : 1; $pagesize = isset($vars['pagesize']) && !empty($vars['pagesize']) ? $vars['pagesize'] : 10; $start = $pagesize * $pageno - $pagesize; $param = array(); $where = ' WHERE 1 '; foreach ($vars as $var => $value) { if ($value != '') { switch ($var) { case 'device': case 'device_id': $where .= ' AND I.`device_id` = ?'; $param[] = $value; break; case 'port': case 'port_id': $where .= ' AND I.`port_id` = ?'; $param[] = $value; break; case 'ip_version': $where .= ' AND `ip_version` = ?'; $param[] = $value; break; case 'address': if (isset($vars['searchby']) && $vars['searchby'] == 'ip') { $where .= ' AND `ip_address` LIKE ?'; $value = trim($value); ///FIXME. Need another conversion ("2001:b08:b08" -> "2001:0b08:0b08") -- mike if (Net_IPv6::checkIPv6($value)) { $value = Net_IPv6::uncompress($value, true); } $param[] = '%' . $value . '%'; } else { $where .= ' AND `mac_address` LIKE ?'; $param[] = '%' . str_replace(array(':', ' ', '-', '.', '0x'), '', mres($value)) . '%'; } break; } } } // Show ARP tables only for permitted ports $query_permitted = generate_query_permitted(array('port'), array('port_table' => 'I')); $query = 'FROM `ip_mac` AS M '; $query .= 'LEFT JOIN `ports` AS I ON I.`port_id` = M.`port_id` '; $query .= $where . $query_permitted; $query_count = 'SELECT COUNT(`mac_id`) ' . $query; $query = 'SELECT * ' . $query; $query .= ' ORDER BY M.`mac_address`'; $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 = array('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 = '<table class="table table-bordered table-striped table-hover table-condensed">' . PHP_EOL; if (!$short) { $string .= ' <thead>' . PHP_EOL; $string .= ' <tr>' . PHP_EOL; $string .= ' <th>MAC Address</th>' . PHP_EOL; $string .= ' <th>IP Address</th>' . PHP_EOL; if ($list['device']) { $string .= ' <th>Device</th>' . PHP_EOL; } if ($list['port']) { $string .= ' <th>Interface</th>' . PHP_EOL; } $string .= ' <th>Remote Device</th>' . PHP_EOL; $string .= ' <th>Remote Interface</th>' . PHP_EOL; $string .= ' </tr>' . PHP_EOL; $string .= ' </thead>' . PHP_EOL; } $string .= ' <tbody>' . PHP_EOL; foreach ($entries as $entry) { humanize_port($entry); $ip_version = $entry['ip_version']; $ip_address = $ip_version == 6 ? Net_IPv6::compress($entry['ip_address']) : $entry['ip_address']; $arp_host = dbFetchRow('SELECT * FROM `ipv' . $ip_version . '_addresses` AS A LEFT JOIN `ports` AS I ON A.`port_id` = I.`port_id` LEFT JOIN `devices` AS D ON D.`device_id` = I.`device_id` WHERE A.`ipv' . $ip_version . '_address` = ?', array($ip_address)); $arp_name = $arp_host ? generate_device_link($arp_host) : ''; $arp_if = $arp_host ? generate_port_link($arp_host) : ''; if ($arp_host['device_id'] == $entry['device_id']) { $arp_name = 'Self Device'; } if ($arp_host['port_id'] == $entry['port_id']) { $arp_if = 'Self Port'; } $string .= ' <tr>' . PHP_EOL; $string .= ' <td width="160">' . formatMac($entry['mac_address']) . '</td>' . PHP_EOL; $string .= ' <td width="140">' . $ip_address . '</td>' . PHP_EOL; if ($list['device']) { $dev = device_by_id_cache($entry['device_id']); $string .= ' <td class="entity" nowrap>' . generate_device_link($dev) . '</td>' . PHP_EOL; } if ($list['port']) { if ($entry['ifInErrors_delta'] > 0 || $entry['ifOutErrors_delta'] > 0) { $port_error = generate_port_link($entry, '<span class="label label-important">Errors</span>', 'port_errors'); } $string .= ' <td class="entity">' . generate_port_link($entry, short_ifname($entry['label'])) . ' ' . $port_error . '</td>' . PHP_EOL; } $string .= ' <td class="entity" width="200">' . $arp_name . '</td>' . PHP_EOL; $string .= ' <td class="entity">' . $arp_if . '</td>' . PHP_EOL; $string .= ' </tr>' . PHP_EOL; } $string .= ' </tbody>' . PHP_EOL; $string .= '</table>'; // Print pagination header if ($pagination) { $string = pagination($vars, $count) . $string . pagination($vars, $count); } // Print ARP/NDP table echo $string; }
if ($ospf['ospfAdminStat'] == 'disabled') { $routing['ospf']['down']++; } else { continue; } } $routing['ospf']['count']++; } } } // Common permission sql query //r(range_to_list($cache['devices']['permitted'])); //unset($cache['devices']['permitted']); //$cache['where']['devices_ports_permitted'] = generate_query_permitted(array('device', 'port')); $cache['where']['devices_permitted'] = generate_query_permitted(array('device')); $cache['where']['ports_permitted'] = generate_query_permitted(array('port')); // CEF $routing['cef']['count'] = count(dbFetchColumn("SELECT `cef_switching_id` FROM `cef_switching` WHERE 1 " . $cache['where']['devices_permitted'] . " GROUP BY `device_id`, `afi`;")); // VRF $routing['vrf']['count'] = count(dbFetchColumn("SELECT DISTINCT `mplsVpnVrfRouteDistinguisher` FROM `vrfs` WHERE 1 " . $cache['where']['devices_permitted'])); // Status $cache['status']['count'] = $statuses['count']; //dbFetchCell("SELECT COUNT(`status_id`) FROM `status` WHERE 1 ".$cache['where']['devices_permitted']); // Additional common counts if ($config['enable_pseudowires']) { $cache['ports']['pseudowires'] = dbFetchColumn('SELECT DISTINCT `port_id` FROM `pseudowires` WHERE 1 ' . $cache['where']['ports_permitted']); $cache['pseudowires']['count'] = count($cache['ports']['pseudowires']); } if ($config['poller_modules']['cisco-cbqos'] || $config['discovery_modules']['cisco-cbqos']) { $cache['ports']['cbqos'] = dbFetchColumn('SELECT DISTINCT `port_id` FROM `ports_cbqos` WHERE 1 ' . $cache['where']['ports_permitted']); $cache['cbqos']['count'] = count($cache['ports']['cbqos']);
/** * Display syslog messages. * * Display pages with device syslog messages. * Examples: * print_syslogs() - display last 10 syslog messages from all devices * print_syslogs(array('pagesize' => 99)) - display last 99 syslog messages from all device * print_syslogs(array('pagesize' => 10, 'pageno' => 3, 'pagination' => TRUE)) - display 10 syslog messages from page 3 with pagination header * print_syslogs(array('pagesize' => 10, 'device' = 4)) - display last 10 syslog messages for device_id 4 * print_syslogs(array('short' => TRUE)) - show small block with last syslog messages * * @param array $vars * @return none * */ function print_syslogs($vars) { // Short events? (no pagination, small out) $short = isset($vars['short']) && $vars['short']; // With pagination? (display page numbers in header) $pagination = isset($vars['pagination']) && $vars['pagination']; $pageno = isset($vars['pageno']) && !empty($vars['pageno']) ? $vars['pageno'] : 1; $pagesize = isset($vars['pagesize']) && !empty($vars['pagesize']) ? $vars['pagesize'] : 10; $start = $pagesize * $pageno - $pagesize; $priorities = $GLOBALS['config']['syslog']['priorities']; $param = array(); $where = ' WHERE 1 '; foreach ($vars as $var => $value) { if ($value != '') { $cond = array(); switch ($var) { case 'device': case 'device_id': $where .= ' AND `device_id` = ?'; $param[] = $value; break; case 'priority': if (!is_array($value)) { $value = array($value); } foreach ($value as $k => $v) { // Rewrite priority strings to numbers $value[$k] = priority_string_to_numeric($v); } // Do not break here, it's true! // Do not break here, it's true! case 'program': if (!is_array($value)) { $value = array($value); } foreach ($value as $v) { $cond[] = '?'; $param[] = $v === '[[EMPTY]]' ? '' : $v; } $where .= " AND `{$var}` IN ("; $where .= implode(', ', $cond); $where .= ')'; break; case 'message': foreach (explode(',', $value) as $val) { $param[] = '%' . $val . '%'; $cond[] = '`msg` LIKE ?'; } $where .= 'AND ('; $where .= implode(' OR ', $cond); $where .= ')'; break; case 'timestamp_from': $where .= ' AND `timestamp` > ?'; $param[] = $value; break; case 'timestamp_to': $where .= ' AND `timestamp` < ?'; $param[] = $value; break; } } } // Show events only for permitted devices $query_permitted = generate_query_permitted(); $query = 'FROM `syslog` '; $query .= $where . $query_permitted; $query_count = 'SELECT COUNT(`seq`) ' . $query; $query = 'SELECT * ' . $query; $query .= ' ORDER BY `seq` DESC '; $query .= "LIMIT {$start},{$pagesize}"; // Query syslog messages $entries = dbFetchRows($query, $param); // Query syslog count if ($pagination && !$short) { $count = dbFetchCell($query_count, $param); } else { $count = count($entries); } if (!$count) { // There have been no entries returned. Print the warning. print_warning('<h4>No syslog entries found!</h4> Check that the syslog daemon and Observium configuration options are set correctly, that your devices are configured to send syslog to Observium and that there are no firewalls blocking the messages. See <a href="http://www.observium.org/wiki/Category:Documentation" target="_blank">documentation</a> and <a href="http://www.observium.org/wiki/Configuration_Options#Syslog_Settings" target="_blank">configuration options</a> for more information.'); } else { // Entries have been returned. Print the table. $list = array('device' => FALSE, 'priority' => TRUE); // For now (temporarily) priority always displayed if (!isset($vars['device']) || empty($vars['device']) || $vars['page'] == 'syslog') { $list['device'] = TRUE; } if ($short || !isset($vars['priority']) || empty($vars['priority'])) { $list['priority'] = TRUE; } $string = '<table class="table table-bordered table-striped table-hover table-condensed-more">' . PHP_EOL; if (!$short) { $string .= ' <thead>' . PHP_EOL; $string .= ' <tr>' . PHP_EOL; $string .= ' <th>Date</th>' . PHP_EOL; if ($list['device']) { $string .= ' <th>Device</th>' . PHP_EOL; } if ($list['priority']) { $string .= ' <th>Priority</th>' . PHP_EOL; } $string .= ' <th>Message</th>' . PHP_EOL; $string .= ' </tr>' . PHP_EOL; $string .= ' </thead>' . PHP_EOL; } $string .= ' <tbody>' . PHP_EOL; foreach ($entries as $entry) { $string .= ' <tr>'; if ($short) { $string .= ' <td class="syslog" style="white-space: nowrap">'; $timediff = $GLOBALS['config']['time']['now'] - strtotime($entry['timestamp']); $string .= overlib_link('', formatUptime($timediff, "short-3"), format_timestamp($entry['timestamp']), NULL) . '</td>' . PHP_EOL; } else { $string .= ' <td width="160">'; $string .= format_timestamp($entry['timestamp']) . '</td>' . PHP_EOL; } if ($list['device']) { $dev = device_by_id_cache($entry['device_id']); $device_vars = array('page' => 'device', 'device' => $entry['device_id'], 'tab' => 'logs', 'section' => 'syslog'); $string .= ' <td class="entity">' . generate_device_link($dev, short_hostname($dev['hostname']), $device_vars) . '</td>' . PHP_EOL; } if ($list['priority']) { if (!$short) { $string .= ' <td style="color: ' . $priorities[$entry['priority']]['color'] . '; white-space: nowrap;">' . nicecase($priorities[$entry['priority']]['name']) . ' (' . $entry['priority'] . ')</td>' . PHP_EOL; } } $entry['program'] = empty($entry['program']) ? '[[EMPTY]]' : $entry['program']; if ($short) { $string .= ' <td class="syslog">'; $string .= '<strong style="color: ' . $priorities[$entry['priority']]['color'] . ';">' . $entry['program'] . '</strong> : '; } else { $string .= ' <td>'; $string .= '<strong>' . $entry['program'] . '</strong> : '; } $string .= htmlspecialchars($entry['msg']) . '</td>' . PHP_EOL; $string .= ' </tr>' . PHP_EOL; } $string .= ' </tbody>' . PHP_EOL; $string .= '</table>' . PHP_EOL; // Print pagination header if ($pagination && !$short) { $string = pagination($vars, $count) . $string . pagination($vars, $count); } // Print syslog echo $string; } }
<?php /** * Observium * * This file is part of Observium. * * @package observium * @subpackage webui * @copyright (C) 2006-2015 Adam Armstrong * */ global $sensor_type; $sql = "SELECT *, `sensors`.`sensor_id` AS `sensor_id` FROM `sensors`"; $sql .= " LEFT JOIN `sensors-state` ON `sensors`.`sensor_id` = `sensors-state`.`sensor_id`"; $sql .= " WHERE `sensors`.`sensor_class` = ?" . generate_query_permitted(array('device')); // Groups if (isset($vars['group'])) { $values = get_group_entities($vars['group']); $sql .= generate_query_values($values, 'sensors.sensor_id'); } $sensors = array(); foreach (dbFetchRows($sql, array($sensor_type)) as $sensor) { if (isset($cache['devices']['id'][$sensor['device_id']])) { $sensor['hostname'] = $cache['devices']['id'][$sensor['device_id']]['hostname']; $sensor['html_row_class'] = $cache['devices']['id'][$sensor['device_id']]['html_row_class']; $sensors[] = $sensor; } } $sensors = array_sort_by($sensors, 'hostname', SORT_ASC, SORT_STRING, 'sensor_descr', SORT_ASC, SORT_STRING); $sensors_count = count($sensors);
<?php /** * Observium * * This file is part of Observium. * * @package observium * @subpackage map * @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited * */ // Detect map center and zoom $where = ' WHERE 1 '; $where .= generate_query_permitted(array('device'), array('hide_ignored' => TRUE)); if (!is_numeric($config['frontpage']['map']['center']['lat']) || !is_numeric($config['frontpage']['map']['center']['lng'])) { $map_center = dbFetchRow('SELECT MAX(`location_lon`) AS `lng_max`, MIN(`location_lon`) AS `lng_min`, MAX(`location_lat`) AS `lat_max`, MIN(`location_lat`) AS `lat_min` FROM `devices_locations` ' . $where); $map_center['lat'] = ($map_center['lat_max'] + $map_center['lat_min']) / 2; $map_center['lng'] = ($map_center['lng_max'] + $map_center['lng_min']) / 2; $config['frontpage']['map']['center']['lat'] = $map_center['lat']; $config['frontpage']['map']['center']['lng'] = $map_center['lng']; // Auto-zoom if (!is_numeric($config['frontpage']['map']['zoom'])) { $map_center['lat_size'] = abs($map_center['lat_max'] - $map_center['lat_min']); $map_center['lng_size'] = abs($map_center['lng_max'] - $map_center['lng_min']); $l_max = max($map_center['lng_size'], $map_center['lat_size'] * 2); // This is the magic array (2: min zoom, 10: max zoom). foreach (array(1 => 10, 2 => 9, 4 => 8, 6 => 7, 15 => 5, 45 => 4, 90 => 3, 360 => 2) as $g => $z) { if ($l_max <= $g) {
function get_status_array($status) { // Mike: I know that there are duplicated variables, but later will remove global global $config, $cache; $max_interval = filter_var($status['max']['interval'], FILTER_VALIDATE_INT, array('options' => array('default' => 24, 'min_range' => 1))); $max_count = filter_var($status['max']['count'], FILTER_VALIDATE_INT, array('options' => array('default' => 200, 'min_range' => 1))); $query_device_permitted = generate_query_permitted(array('device'), array('device_table' => 'D', 'hide_ignored' => TRUE)); $query_port_permitted = generate_query_permitted(array('port'), array('port_table' => 'I', 'hide_ignored' => TRUE)); // Show Device Status if ($status['devices']) { $query = 'SELECT * FROM `devices` AS D '; $query .= 'WHERE D.`status` = 0' . $query_device_permitted; $query .= 'ORDER BY D.`hostname` ASC'; $entries = dbFetchRows($query); foreach ($entries as $device) { $boxes[] = array('sev' => 100, 'class' => 'Device', 'event' => 'Down', 'device_link' => generate_device_link($device, short_hostname($device['hostname'])), 'time' => deviceUptime($device, 'short-3')); } } // Uptime if ($status['uptime']) { if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== FALSE && $config['uptime_warning'] > 0) { $query = 'SELECT * FROM `devices` AS D '; // Since reboot event more complicated than just device uptime less than some time //$query .= ' WHERE D.`status` = 1 AND D.`uptime` > 0 AND D.`uptime` < ' . $config['uptime_warning']; $query .= ' WHERE D.`status` = 1 AND D.`uptime` > 0 AND D.`last_rebooted` > ?'; $query .= $query_device_permitted; $query .= 'ORDER BY D.`hostname` ASC'; $entries = dbFetchRows($query, array($config['time']['now'] - $config['uptime_warning'] - 10)); foreach ($entries as $device) { $boxes[] = array('sev' => 10, 'class' => 'Device', 'event' => 'Rebooted', 'device_link' => generate_device_link($device, short_hostname($device['hostname'])), 'time' => deviceUptime($device, 'short-3'), 'location' => $device['location']); } } } // Ports Down if ($status['ports'] || $status['neighbours']) { $status['neighbours'] = $status['neighbours'] && !$status['ports']; // Disable 'neighbours' if 'ports' already enabled $query = 'SELECT * FROM `ports` AS I '; if ($status['neighbours']) { $query .= 'INNER JOIN `neighbours` as L ON I.`port_id` = L.`port_id` '; } $query .= 'LEFT JOIN `devices` AS D ON I.`device_id` = D.`device_id` '; $query .= "WHERE D.`status` = 1 AND D.ignore = 0 AND I.ignore = 0 AND I.deleted = 0 AND I.`ifAdminStatus` = 'up' AND (I.`ifOperStatus` = 'lowerLayerDown' OR I.`ifOperStatus` = 'down') "; if ($status['neighbours']) { $query .= ' AND L.`active` = 1 '; } $query .= $query_port_permitted; $query .= ' AND I.`ifLastChange` >= DATE_SUB(NOW(), INTERVAL ' . $max_interval . ' HOUR) '; if ($status['neighbours']) { $query .= 'GROUP BY L.`port_id` '; } $query .= 'ORDER BY I.`ifLastChange` DESC, D.`hostname` ASC, I.`ifDescr` * 1 ASC '; $entries = dbFetchRows($query); $i = 1; foreach ($entries as $port) { if ($i > $max_count) { // Limit to 200 ports on overview page break; } humanize_port($port); $boxes[] = array('sev' => 50, 'class' => 'Port', 'event' => 'Down', 'device_link' => generate_device_link($port, short_hostname($port['hostname'])), 'entity_link' => generate_port_link($port, short_ifname($port['port_label'], 13)), 'time' => formatUptime($config['time']['now'] - strtotime($port['ifLastChange'])), 'location' => $device['location']); } } // Ports Errors (only deltas) if ($status['errors']) { foreach ($cache['ports']['errored'] as $port_id) { if (in_array($port_id, $cache['ports']['ignored'])) { continue; } // Skip ignored ports $port = get_port_by_id($port_id); $device = device_by_id_cache($port['device_id']); humanize_port($port); if ($port['ifInErrors_delta']) { $port['string'] .= 'Rx: ' . format_number($port['ifInErrors_delta']); } if ($port['ifInErrors_delta'] && $port['ifOutErrors_delta']) { $port['string'] .= ', '; } if ($port['ifOutErrors_delta']) { $port['string'] .= 'Tx: ' . format_number($port['ifOutErrors_delta']); } $boxes[] = array('sev' => 75, 'class' => 'Port', 'event' => 'Errors', 'device_link' => generate_device_link($device, short_hostname($device['hostname'])), 'entity_link' => generate_port_link($port, short_ifname($port['port_label'], 13)), 'time' => $port['string'], 'location' => $device['location']); } } // Services if ($status['services']) { $query = 'SELECT * FROM `services` AS S '; $query .= 'LEFT JOIN `devices` AS D ON S.`device_id` = D.`device_id` '; $query .= "WHERE S.`service_status` = 'down' AND S.`service_ignore` = 0"; $query .= $query_device_permitted; $query .= 'ORDER BY D.`hostname` ASC'; $entries = dbFetchRows($query); foreach ($entries as $service) { $boxes[] = array('sev' => 50, 'class' => 'Service', 'event' => 'Down', 'device_link' => generate_device_link($service, short_hostname($service['hostname'])), 'entity_link' => $service['service_type'], 'time' => formatUptime($config['time']['now'] - strtotime($service['service_changed']), 'short'), 'location' => $device['location']); } } // BGP if ($status['bgp']) { if (isset($config['enable_bgp']) && $config['enable_bgp']) { $query = 'SELECT * FROM `bgpPeers` AS B '; $query .= 'LEFT JOIN `devices` AS D ON B.`device_id` = D.`device_id` '; $query .= 'LEFT JOIN `bgpPeers-state` AS BS ON B.`bgpPeer_id` = BS.`bgpPeer_id` '; $query .= "WHERE D.`status` = 1 AND (`bgpPeerAdminStatus` = 'start' OR `bgpPeerAdminStatus` = 'running') AND `bgpPeerState` != 'established' "; $query .= $query_device_permitted; $query .= 'ORDER BY D.`hostname` ASC'; $entries = dbFetchRows($query); foreach ($entries as $peer) { humanize_bgp($peer); $peer_ip = generate_entity_link("bgp_peer", $peer, $peer['human_remoteip']); $peer['wide'] = strstr($peer['bgpPeerRemoteAddr'], ':') ? TRUE : FALSE; $boxes[] = array('sev' => 75, 'class' => 'BGP Peer', 'event' => 'Down', 'device_link' => generate_device_link($peer, short_hostname($peer['hostname'])), 'entity_link' => $peer_ip, 'wide' => $peer['wide'], 'time' => formatUptime($peer['bgpPeerFsmEstablishedTime'], 'short-3'), 'location' => $device['location']); } } } // Return boxes array return $boxes; }
function show_traffic($config) { // Show Traffic if ($_SESSION['userlevel'] >= '5') { $ports = array(); $query_permitted = generate_query_permitted(array('port')); foreach (dbFetchRows("SELECT * FROM `ports` WHERE `port_descr_type` IS NOT NULL {$query_permitted} ORDER BY `ifAlias`") as $port) { switch ($port['port_descr_type']) { case 'transit': case 'peering': case 'core': $ports[$port['port_descr_type']][] = $port['port_id']; break; } } echo '<div class="row">'; if (count($ports['transit'])) { $links['transit'] = generate_url(array("page" => "iftype", "type" => "transit")); $ports['transit_list'] = implode(',', $ports['transit']); echo ' <div class="col-md-6 ">'; echo ' <h3 class="bill">今天的超额透传流量</h3>'; echo ' <a href="' . $links['transit'] . '"><img src="graph.php?type=multiport_bits_separate&id=' . $ports['transit_list'] . '&legend=no&from=' . $config['time']['day'] . '&to=' . $config['time']['now'] . '&width=480&height=100" alt="" /></a>'; echo ' </div>'; if (empty($ports['peering'])) { echo ' <div class="col-md-6 ">'; echo ' <h3 class="bill">本周全部透传流量</h3>'; echo ' <a href="' . $links['transit'] . '"><img src="graph.php?type=multiport_bits_separate&id=' . $ports['transit_list'] . '&legend=no&from=' . $config['time']['week'] . '&to=' . $config['time']['now'] . '&width=480&height=100" alt="" /></a>'; echo ' </div>'; } } if (count($ports['peering'])) { $links['peering'] = generate_url(array("page" => "iftype", "type" => "peering")); $ports['peering_list'] = implode(',', $ports['peering']); echo ' <div class="col-md-6 ">'; echo ' <h3 class="bill">今天的超额对等互联流量</h3>'; echo ' <a href="' . $links['peering'] . '"><img src="graph.php?type=multiport_bits_separate&id=' . $ports['peering_list'] . '&legend=no&from=' . $config['time']['day'] . '&to=' . $config['time']['now'] . '&width=480&height=100" alt="" /></a>'; echo ' </div>'; if (empty($ports['transit'])) { echo ' <div class="col-md-6 ">'; echo ' <h3 class="bill">本周全部对等互联流量</h3>'; echo ' <a href="' . $links['peering'] . '"><img src="graph.php?type=multiport_bits_separate&id=' . $ports['peering_list'] . '&legend=no&from=' . $config['time']['week'] . '&to=' . $config['time']['now'] . '&width=480&height=100" alt="" /></a>'; echo ' </div>'; } } echo '</div>'; if ($ports['transit_list'] && $ports['peering_list']) { $links['peer_trans'] = generate_url(array("page" => "iftype", "type" => "peering,transit")); echo '<div class="row">'; echo ' <div class="col-md-12">'; echo ' <h3 class="bill">本月超额透传 & 对等互联流量</h3>'; echo ' <a href="' . $links['peer_trans'] . '"><img src="graph.php?type=multiport_bits_duo_separate&id=' . $ports['peering_list'] . '&idb=' . $ports['transit_list'] . '&legend=no&from=' . $config['time']['month'] . '&to=' . $config['time']['now'] . '&width=1100&height=200" alt="" /></a>'; echo ' </div>'; echo '</div>'; } else { if ($ports['transit_list'] && !$ports['peering_list']) { echo '<div class="row">'; echo ' <div class="col-md-12">'; echo ' <h3 class="bill">本月全部透传流量</h3>'; echo ' <a href="' . $links['transit'] . '"><img src="graph.php?type=multiport_bits_separate&id=' . $ports['transit_list'] . '&legend=no&from=' . $config['time']['month'] . '&to=' . $config['time']['now'] . '&width=1100&height=200" alt="" /></a>'; echo ' </div>'; echo '</div>'; } else { if (!$ports['transit_list'] && $ports['peering_list']) { echo '<div class="row">'; echo ' <div class="col-md-12">'; echo ' <h3 class="bill">本月全部对等互联流量</h3>'; echo ' <a href="' . $links['peering'] . '"><img src="graph.php?type=multiport_bits_separate&id=' . $ports['peering_list'] . '&legend=no&from=' . $config['time']['month'] . '&to=' . $config['time']['now'] . '&width=1100&height=200" alt="" /></a>'; echo ' </div>'; echo '</div>'; } } } } }
function show_map($config) { ?> <div class="row" style="margin-bottom: 10px;"> <div class="col-md-12"> <style type="text/css"> #chart_div label { width: auto; display:inline; } #chart_div img { max-width: none; } </style> <!-- <div id="reset" style="width: 100%; text-align: right;"><input type="button" onclick="resetMap();" value="重置地图" /></div> --> <div id="chart_div" style="height: <?php echo $config['frontpage']['map']['height']; ?> px;"></div> <?php if ($config['frontpage']['map']['api'] != 'google-mc') { ?> <script type='text/javascript' src='//www.google.com/jsapi'></script> <script type='text/javascript'> google.load('visualization', '1.1', {'packages': ['geochart']}); google.setOnLoadCallback(drawRegionsMap); function drawRegionsMap() { var data = new google.visualization.DataTable(); data.addColumn('number', '纬度'); data.addColumn('number', '经度'); data.addColumn('string', '位置'); data.addColumn('number', '状态'); data.addColumn('number', '设备'); data.addColumn({type: 'string', role: 'tooltip'}); data.addColumn('string', 'url'); data.addRows([ <?php $locations_up = array(); $locations_down = array(); foreach (get_locations() as $location) { $location_name = $location == '' ? '[[UNKNOWN]]' : strtr(htmlspecialchars($location), "'", "`"); $location_url = generate_location_url($location); $devices_down = array(); $devices_up = array(); $count = $GLOBALS['cache']['device_locations'][$location]; $down = 0; foreach ($GLOBALS['cache']['devices']['id'] as $device) { if ($device['location'] == $location) { if ($device['status'] == "0" && $device['ignore'] == "0") { $down++; $devices_down[] = $device['hostname']; $lat = $device['location_lat']; $lon = $device['location_lon']; } else { if ($device['status'] == "1") { $devices_up[] = $device['hostname']; $lat = $device['location_lat']; $lon = $device['location_lon']; } } } } $count = $count < 100 ? $count : 100; if ($down > 0) { $locations_down[] = "[{$lat}, {$lon}, '{$location_name}', {$down}, " . $count * $down . ", '" . count($devices_up) . " 设备启用, " . count($devices_down) . " 设备关闭: (" . implode(", ", $devices_down) . ")', '{$location_url}']"; } else { if ($count) { $locations_up[] = "[" . $lat . ", " . $lon . ", '" . $location_name . "', 0, " . $count . ", '" . count($devices_up) . " Devices UP: (" . implode(", ", $devices_up) . ")', '{$location_url}']"; } } } echo implode(",\n ", array_merge($locations_up, $locations_down)); ?> ]); var options = { region: '<?php echo $config['frontpage']['map']['region']; ?> ', resolution: '<?php echo $config['frontpage']['map']['resolution']; ?> ', displayMode: 'markers', keepAspectRatio: 0, //width: 1240, //height: 480, is3D: true, legend: 'none', enableRegionInteractivity: true, <?php if ($config['frontpage']['map']['realworld']) { echo "\t\t datalessRegionColor: '#93CA76',"; } else { echo "\t\t datalessRegionColor: '#d5d5d5',"; } if ($config['frontpage']['map']['realworld']) { echo "\t\t backgroundColor: {fill: '#000000'},"; } ?> backgroundColor: {fill: 'transparent'}, magnifyingGlass: {enable: true, zoomFactor: 5}, colorAxis: {values: [0, 1, 2, 3], colors: ['darkgreen', 'orange', 'orangered', 'red']}, markerOpacity: 0.75, sizeAxis: {minValue: 1, maxValue: 10, minSize: 10, maxSize: 40} }; var view = new google.visualization.DataView(data); // exclude last url column in the GeoChart view.setColumns([0, 1, 2, 3, 4, 5]); var chart = new google.visualization.GeoChart(document.getElementById('chart_div')); google.visualization.events.addListener(chart, 'ready', onReady); function onReady() { google.visualization.events.addListener(chart, 'select', gotoLocation); } function gotoLocation() { var selection = chart.getSelection(); var item = selection[0]; var url = data.getValue(item.row, 6); window.location = url; } chart.draw(view, options); }; </script> <?php } else { // begin google-mc $where = ' WHERE 1 '; $where .= generate_query_permitted(array('device'), array('ignored' => TRUE)); //Detect map center if (!is_numeric($config['frontpage']['map']['center']['lat']) || !is_numeric($config['frontpage']['map']['center']['lng'])) { $map_center = dbFetchRow('SELECT MAX(`location_lon`) AS `lng_max`, MIN(`location_lon`) AS `lng_min`, MAX(`location_lat`) AS `lat_max`, MIN(`location_lat`) AS `lat_min` FROM `devices` ' . $where); $map_center['lat'] = ($map_center['lat_max'] + $map_center['lat_min']) / 2; $map_center['lng'] = ($map_center['lng_max'] + $map_center['lng_min']) / 2; $config['frontpage']['map']['center']['lat'] = $map_center['lat']; $config['frontpage']['map']['center']['lng'] = $map_center['lng']; //Also auto-zoom if (!is_numeric($config['frontpage']['map']['zoom'])) { $map_center['lat_size'] = abs($map_center['lat_max'] - $map_center['lat_min']); $map_center['lng_size'] = abs($map_center['lng_max'] - $map_center['lng_min']); $l_max = max($map_center['lng_size'], $map_center['lat_size'] * 2); // This is the magic array (2: min zoom, 10: max zoom). foreach (array(1 => 10, 2 => 9, 4 => 8, 6 => 7, 15 => 5, 45 => 4, 90 => 3, 360 => 2) as $g => $z) { if ($l_max <= $g) { $config['frontpage']['map']['zoom'] = $z; break; } } } /// r($map_center); } else { if (!is_numeric($config['frontpage']['map']['zoom'])) { $config['frontpage']['map']['zoom'] = 4; } } ?> <script type='text/javascript' src='//www.google.com/jsapi'></script> <script type="text/javascript" src="js/google/markerclusterer.js"></script> <script src="//maps.google.com/maps/api/js?sensor=false"></script> <?php if ($config['frontpage']['map']['clouds']) { ?> <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&libraries=weather"></script><?php } ?> <script type="text/javascript"> google.load('visualization', '1.1', {'packages': ['geochart']}); function getMapData() { var data = new google.visualization.DataTable(); data.addColumn('number', '纬度'); data.addColumn('number', '经度'); data.addColumn('number', '正常数量'); data.addColumn('number', '停止数量'); data.addColumn({type: 'string', role: 'tooltip'}); data.addColumn('string', '位置'); data.addColumn('string', 'url'); data.addRows([ <?php $locations = array(); foreach ($GLOBALS['cache']['devices']['id'] as $device) { if ($device["status"] == "0" && $device["ignore"] == "0" && $device["disabled"] == "0") { $locations[$device['location_lat']][$device['location_lon']]["down_hosts"][] = $device; } elseif ($device["status"] == "1") { $locations[$device['location_lat']][$device['location_lon']]["up_hosts"][] = $device; } } foreach ($locations as $la => $lat) { foreach ($lat as $lo => $lon) { $num_up = count($lon["up_hosts"]); $num_down = count($lon["down_hosts"]); $total_hosts = $num_up + $num_down; $tooltip = "{$total_hosts} Hosts"; $location_name = ""; if ($num_down > 0) { $location_name = $lon['down_hosts'][0]['location'] == '' ? '[[UNKNOWN]]' : strtr(htmlspecialchars($lon['down_hosts'][0]['location']), "'", "`"); $location_url = generate_location_url($lon['down_hosts'][0]['location']); $tooltip .= "\\n\\nDown hosts:"; foreach ($lon["down_hosts"] as $down_host) { $tooltip .= "\\n" . $down_host['hostname']; } } elseif ($num_up > 0) { $location_name = $lon['up_hosts'][0]['location'] == '' ? '[[UNKNOWN]]' : strtr(htmlspecialchars($lon['up_hosts'][0]['location']), "'", "`"); $location_url = generate_location_url($lon['up_hosts'][0]['location']); } echo "[{$la}, {$lo}, {$num_up}, {$num_down}, \"{$tooltip}\", '{$location_name}', '{$location_url}'],\n "; } } ?> ]); return data; } function initialize() { var data = getMapData(); var markers = []; var base_link = '<?php echo generate_url(array("page" => "devices")); ?> '; for (var i = 0; i < data.getNumberOfRows(); i++) { var latLng = new google.maps.LatLng(data.getValue(i, 0), data.getValue(i, 1)); icon_ = '//maps.gstatic.com/mapfiles/ridefinder-images/mm_20_green.png'; var num_up = data.getValue(i, 2); var num_down = data.getValue(i, 3); var location = data.getValue(i, 5); var ratio_up = num_up / (num_up + num_down); if (ratio_up < 0.9999) { icon_ = '//maps.gstatic.com/mapfiles/ridefinder-images/mm_20_red.png'; } var marker = new google.maps.Marker({ position: latLng, icon: icon_, title: data.getValue(i, 4), location: location, num_up: num_up, num_down: num_down, url: data.getValue(i, 6) }); // marker.num_up = num_up; // marker.num_down = num_down; markers.push(marker); google.maps.event.addDomListener(marker, 'click', function() { window.location.href = this.url; }); } var styles = []; for (var i = 0; i < 4; i++) { image_path = "/images/mapclusterer/"; image_ext = ".png"; styles.push({ url: image_path + i + image_ext, height: 52, width: 53 }); } var mcOptions = {gridSize: 30, maxZoom: 15, zoomOnClick: false, styles: styles }; var markerClusterer = new MarkerClusterer(map, markers, mcOptions); var iconCalculator = function(markers, numStyles) { var total_up = 0; var total_down = 0; for (var i = 0; i < markers.length; i++) { total_up += markers[i].num_up; total_down += markers[i].num_down; } var ratio_up = total_up / (total_up + total_down); //The map clusterer really does seem to use index-1... index_ = 1; if (ratio_up < 0.9999) { index_ = 4; // Could be 2, and then more code to use all 4 images } return { text: (total_up + total_down), index: index_ }; } markerClusterer.setCalculator(iconCalculator); } var center_ = new google.maps.LatLng(<?php echo $config['frontpage']['map']['center']['lat']; ?> , <?php echo $config['frontpage']['map']['center']['lng']; ?> ); var map = new google.maps.Map(document.getElementById('chart_div'), { zoom: <?php echo $config['frontpage']['map']['zoom']; ?> , center: center_, mapTypeId: google.maps.MapTypeId.ROADMAP }); <?php if ($config['frontpage']['map']['clouds']) { ?> var cloudLayer = new google.maps.weather.CloudLayer(); cloudLayer.setMap(map); <?php } ?> function resetMap() { map.setZoom(4); map.panTo(center_); } google.maps.event.addListener(map, 'click', function(event) { map.setZoom(map.getZoom() + <?php echo $config['frontpage']['map']['zooms_per_click']; ?> ); map.panTo(event.latLng); }); google.maps.event.addDomListener(window, 'load', initialize); </script> <?php } // End google-mc ?> </div> </div> <?php }
function get_logalert_log($vars) { $array = array(); // Short events? (no pagination, small out) $array['short'] = isset($vars['short']) && $vars['short']; // With pagination? (display page numbers in header) $array['pagination'] = isset($vars['pagination']) && $vars['pagination']; pagination($vars, 0, TRUE); // Get default pagesize/pageno $array['pageno'] = $vars['pageno']; $array['pagesize'] = $vars['pagesize']; $start = $array['pagesize'] * $array['pageno'] - $array['pagesize']; $pagesize = $array['pagesize']; // Begin query generate $param = array(); $where = ' WHERE 1 '; foreach ($vars as $var => $value) { if ($value != '') { switch ($var) { case 'la_id': $where .= generate_query_values($value, 'la_id'); break; case 'device': case 'device_id': $where .= generate_query_values($value, 'device_id'); break; case 'program': $where .= generate_query_values($value, 'program', '%LIKE%'); break; case 'message': $where .= generate_query_values($value, 'message', '%LIKE%'); break; case 'timestamp_from': $where .= ' AND `timestamp` >= ?'; $param[] = $value; break; case 'timestamp_to': $where .= ' AND `timestamp` <= ?'; $param[] = $value; break; } } } // Show events only for permitted devices $query_permitted = generate_query_permitted(); //generate_query_permitted(array('entity')); $query = 'FROM `syslog_alerts` '; $query .= $where . $query_permitted; $query_count = 'SELECT COUNT(`la_id`) ' . $query; $query_updated = 'SELECT MAX(`timestamp`) ' . $query; $query = 'SELECT * ' . $query; $query .= ' ORDER BY `lal_id` DESC '; $query .= "LIMIT {$start},{$pagesize}"; // Query events $array['entries'] = dbFetchRows($query, $param); // Query events count if ($array['pagination'] && !$array['short']) { $array['count'] = dbFetchCell($query_count, $param); $array['pagination_html'] = pagination($vars, $array['count']); } else { $array['count'] = count($array['entries']); } // Query for last timestamp $array['updated'] = dbFetchCell($query_updated, $param); //r($array); return $array; }
/** * Display Interface MACs addresses. * * Display pages with MAC addresses from device Interfaces. * * @param array $vars * @return none * */ function print_mac_addresses($vars) { // With pagination? (display page numbers in header) $pagination = isset($vars['pagination']) && $vars['pagination']; pagination($vars, 0, TRUE); // Get default pagesize/pageno $pageno = $vars['pageno']; $pagesize = $vars['pagesize']; $start = $pagesize * $pageno - $pagesize; $param = array(); $where = ' WHERE 1 '; foreach ($vars as $var => $value) { if ($value != '') { switch ($var) { case 'device': case 'device_id': $where .= generate_query_values($value, 'device_id'); break; case 'interface': $where .= ' AND `ifDescr` LIKE ?'; $param[] = $value; break; case 'address': $where .= ' AND `ifPhysAddress` LIKE ?'; # FIXME hm? mres in a dbFacile parameter? $param[] = '%' . str_replace(array(':', ' ', '-', '.', '0x'), '', mres($value)) . '%'; break; } } } $where .= ' AND `ifPhysAddress` IS NOT NULL'; //Exclude empty MACs // Show MACs only for permitted ports $query_permitted = generate_query_permitted(array('port')); $query = 'FROM `ports` '; $query .= $where . $query_permitted; $query_count = 'SELECT COUNT(*) ' . $query; $query = 'SELECT * ' . $query; $query .= ' ORDER BY `ifPhysAddress`'; $query .= " LIMIT {$start},{$pagesize}"; // Query addresses $entries = dbFetchRows($query, $param); // Query address count if ($pagination) { $count = dbFetchCell($query_count, $param); } $list = array('device' => FALSE); if (!isset($vars['device']) || empty($vars['device']) || $vars['page'] == 'search') { $list['device'] = TRUE; } $string = '<table class="table table-bordered table-striped table-hover table-condensed">' . PHP_EOL; if (!$short) { $string .= ' <thead>' . PHP_EOL; $string .= ' <tr>' . PHP_EOL; if ($list['device']) { $string .= ' <th>Device</th>' . PHP_EOL; } $string .= ' <th>Interface</th>' . PHP_EOL; $string .= ' <th>MAC Address</th>' . PHP_EOL; $string .= ' <th>Description</th>' . PHP_EOL; $string .= ' </tr>' . PHP_EOL; $string .= ' </thead>' . PHP_EOL; } $string .= ' <tbody>' . PHP_EOL; foreach ($entries as $entry) { if (port_permitted($entry['port_id'])) { humanize_port($entry); $string .= ' <tr>' . PHP_EOL; if ($list['device']) { $dev = device_by_id_cache($entry['device_id']); $string .= ' <td class="entity" style="white-space: nowrap;">' . generate_device_link($dev) . '</td>' . PHP_EOL; } if ($entry['ifInErrors_delta'] > 0 || $entry['ifOutErrors_delta'] > 0) { $port_error = generate_port_link($entry, '<span class="label label-important">Errors</span>', 'port_errors'); } $string .= ' <td class="entity">' . generate_port_link($entry, short_ifname($entry['label'])) . ' ' . $port_error . '</td>' . PHP_EOL; $string .= ' <td style="width: 160px;">' . $entry['human_mac'] . '</td>' . PHP_EOL; $string .= ' <td>' . $entry['ifAlias'] . '</td>' . PHP_EOL; $string .= ' </tr>' . PHP_EOL; } } $string .= ' </tbody>' . PHP_EOL; $string .= '</table>'; // Print pagination header if ($pagination) { $string = pagination($vars, $count) . $string . pagination($vars, $count); } // Print MAC addresses echo $string; }
function get_status_array($status) { // Mike: I know that there are duplicated variables, but later will remove global global $config, $cache; $max_interval = filter_var($status['max']['interval'], FILTER_VALIDATE_INT, array('options' => array('default' => 24, 'min_range' => 1))); $max_count = filter_var($status['max']['count'], FILTER_VALIDATE_INT, array('options' => array('default' => 200, 'min_range' => 1))); $query_device_permitted = generate_query_permitted(array('device'), array('device_table' => 'D')); $query_port_permitted = generate_query_permitted(array('port'), array('port_table' => 'I')); // Show Device Status if ($status['devices']) { $query = 'SELECT * FROM `devices` AS D '; $query .= 'WHERE D.`status` = 0' . $query_device_permitted; $query .= 'ORDER BY D.`hostname` ASC'; $entries = dbFetchRows($query); foreach ($entries as $device) { $boxes[] = array('sev' => 100, 'class' => 'Device', 'event' => 'Down', 'device_link' => generate_device_link($device, short_hostname($device['hostname'])), 'time' => deviceUptime($device, 'short-3')); } } // Uptime if ($status['uptime']) { if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== FALSE && $config['uptime_warning'] > 0) { $query = 'SELECT * FROM `devices` AS D '; $query .= 'WHERE D.`status` = 1 AND D.`uptime` > 0 AND D.`uptime` < ' . $config['uptime_warning']; $query .= $query_device_permitted; $query .= 'ORDER BY D.`hostname` ASC'; $entries = dbFetchRows($query); foreach ($entries as $device) { $boxes[] = array('sev' => 10, 'class' => 'Device', 'event' => 'Rebooted', 'device_link' => generate_device_link($device, short_hostname($device['hostname'])), 'time' => deviceUptime($device, 'short-3'), 'location' => $device['location']); } } } // Ports Down if ($status['ports'] || $status['links']) { // warning about deprecated option: $config['warn']['ifdown'] if (isset($config['warn']['ifdown']) && !$config['warn']['ifdown']) { print_warning("<strong>Config option obsolete</strong>\n Please note that config option <strong>\$config['warn']['ifdown']</strong> is now obsolete.\n Use options: <strong>\$config['frontpage']['device_status']['ports']</strong> and <strong>\$config['frontpage']['device_status']['errors']</strong>\n To remove this message, delete <strong>\$config['warn']['ifdown']</strong> from configuration file."); } $query = 'SELECT * FROM `ports` AS I '; if ($status['links'] && !$status['ports']) { $query .= 'INNER JOIN `links` as L ON I.`port_id` = L.`local_port_id` '; } $query .= 'LEFT JOIN `devices` AS D ON I.`device_id` = D.`device_id` '; $query .= "WHERE I.`ifOperStatus` = 'down' AND I.`ifAdminStatus` = 'up' "; if ($status['links'] && !$status['ports']) { $query .= ' AND L.`active` = 1 '; } $query .= $query_port_permitted; $query .= ' AND I.`ifLastChange` >= DATE_SUB(NOW(), INTERVAL ' . $max_interval . ' HOUR) '; $query .= 'ORDER BY I.`ifLastChange` DESC, D.`hostname` ASC, I.`ifDescr` * 1 ASC '; $entries = dbFetchRows($query); $i = 1; foreach ($entries as $port) { if ($i > $max_count) { // Limit to 200 ports on overview page break; } humanize_port($port); $boxes[] = array('sev' => 50, 'class' => 'Port', 'event' => 'Down', 'device_link' => generate_device_link($port, short_hostname($port['hostname'])), 'entity_link' => generate_port_link($port, short_ifname($port['label'], 13)), 'time' => formatUptime($config['time']['now'] - strtotime($port['ifLastChange'])), 'location' => $device['location']); } } // Ports Errors (only deltas) if ($status['errors']) { foreach ($cache['ports']['errored'] as $port_id) { $port = get_port_by_id($port_id); $device = device_by_id_cache($port['device_id']); humanize_port($port); if ($port['ifInErrors_delta']) { $port['string'] .= 'Rx: ' . format_number($port['ifInErrors_delta']); } if ($port['ifInErrors_delta'] && $port['ifOutErrors_delta']) { $port['string'] .= ', '; } if ($port['ifOutErrors_delta']) { $port['string'] .= 'Tx: ' . format_number($port['ifOutErrors_delta']); } $boxes[] = array('sev' => 75, 'class' => 'Port', 'event' => 'Errors', 'device_link' => generate_device_link($device, short_hostname($device['hostname'])), 'entity_link' => generate_port_link($port, short_ifname($port['label'], 13)), 'time' => $port['string'], 'location' => $device['location']); } } // Services if ($status['services']) { $query = 'SELECT * FROM `services` AS S '; $query .= 'LEFT JOIN `devices` AS D ON S.device_id = D.device_id '; $query .= "WHERE S.`service_status` = 'down' AND S.`service_ignore` = 0"; $query .= $query_device_permitted; $query .= 'ORDER BY D.`hostname` ASC'; $entries = dbFetchRows($query); foreach ($entries as $service) { $boxes[] = array('sev' => 50, 'class' => 'Service', 'event' => 'Down', 'device_link' => generate_device_link($service, short_hostname($service['hostname'])), 'entity_link' => $service['service_type'], 'time' => formatUptime($config['time']['now'] - strtotime($service['service_changed']), 'short'), 'location' => $device['location']); } } // BGP if ($status['bgp']) { if (isset($config['enable_bgp']) && $config['enable_bgp']) { $query = 'SELECT * FROM `devices` AS D '; $query .= 'LEFT JOIN `bgpPeers` AS B ON B.`device_id` = D.`device_id` '; $query .= 'LEFT JOIN `bgpPeers-state` AS BS ON B.`bgpPeer_id` = BS.`bgpPeer_id` '; $query .= "WHERE (`bgpPeerAdminStatus` = 'start' OR `bgpPeerAdminStatus` = 'running') AND `bgpPeerState` != 'established' "; $query .= $query_device_permitted; $query .= 'ORDER BY D.`hostname` ASC'; $entries = dbFetchRows($query); foreach ($entries as $peer) { $peer_ip = strstr($peer['bgpPeerRemoteAddr'], ':') ? Net_IPv6::compress($peer['bgpPeerRemoteAddr']) : $peer['bgpPeerRemoteAddr']; $peer['wide'] = strstr($peer['bgpPeerRemoteAddr'], ':') ? TRUE : FALSE; $boxes[] = array('sev' => 75, 'class' => 'BGP Peer', 'event' => 'Down', 'device_link' => generate_device_link($peer, short_hostname($peer['hostname'])), 'entity_link' => $peer_ip, 'wide' => $peer['wide'], 'time' => formatUptime($peer['bgpPeerFsmEstablishedTime'], 'short-3'), 'location' => $device['location']); } } } // Return boxes array return $boxes; }
function get_locations($filter = array()) { global $cache; foreach ($filter as $var => $value) { switch ($var) { case 'location_lat': case 'location_lon': case 'location_country': case 'location_state': case 'location_county': case 'location_city': // Check geo params only when GEO enabled globally if (!$GLOBALS['config']['geocoding']['enable']) { break; } case 'location': $where_array[$var] = generate_query_values($value, $var); break; } } if (count($where_array)) { // Return only founded locations $where = implode('', $where_array) . generate_query_permitted(); $locations = dbFetchColumn("SELECT `location` FROM `devices_locations` WHERE 1 {$where} GROUP BY `location`;"); } else { $locations = array(); foreach ($cache['device_locations'] as $location => $count) { $locations[] = $location; } } sort($locations); return $locations; }
function show_traffic($config) { // Show Traffic if ($_SESSION['userlevel'] >= '5') { $ports = array(); $query_permitted = generate_query_permitted(array('port')); foreach (dbFetchRows("SELECT `port_descr_type`,`port_id`,`ifAlias` FROM `ports`\n WHERE `port_descr_type` IS NOT NULL {$query_permitted}\n ORDER BY `ifAlias`") as $port) { switch ($port['port_descr_type']) { case 'transit': case 'peering': case 'core': $ports[$port['port_descr_type']][] = $port['port_id']; break; } } echo generate_box_open(); $links['transit'] = generate_url(array("page" => "iftype", "type" => "transit")); $ports['transit_list'] = implode(',', $ports['transit']); $graph_array['from'] = $config['time']['day']; $graph_array['to'] = $config['time']['now']; $graph_array['type'] = 'multi-port_bits_separate'; $graph_array['width'] = 528; $graph_array['height'] = 100; $graph_array['legend'] = 'no'; $graph_array['id'] = $ports['transit_list']; $transit_graph = generate_graph_tag($graph_array); $graph_array['from'] = $config['time']['week']; $transit_graph_week = generate_graph_tag($graph_array); $links['peering'] = generate_url(array("page" => "iftype", "type" => "peering")); $ports['peering_list'] = implode(',', $ports['peering']); $graph_array['from'] = $config['time']['day']; $graph_array['id'] = $ports['peering_list']; $peering_graph = generate_graph_tag($graph_array); $graph_array['from'] = $config['time']['week']; $peering_graph_week = generate_graph_tag($graph_array); $graph_array['id'] = $ports['peering_list']; $graph_array['idb'] = $ports['transit_list']; $graph_array['from'] = $config['time']['month']; $graph_array['type'] = 'multi-port_bits_duo_separate'; $graph_array['width'] = 1158; $summary_graph = generate_graph_tag($graph_array); if (count($ports['transit']) && count($ports['peering'])) { echo '<div class="row">'; echo ' <div class="col-sm-6">'; echo ' <h3><a href="/iftype/type=transit">Overall Transit Traffic Today</a></h3>'; echo ' <a href="' . $links['transit'] . '">' . $transit_graph . '</a>'; echo ' </div>'; echo ' <div class="col-sm-6">'; echo ' <h3><a href="/iftype/type=peering">Overall Peering Traffic Today</a></h3>'; echo ' <a href="' . $links['peering'] . '">' . $peering_graph . '</a>'; echo ' </div>'; echo '</div>'; } elseif (count($ports['transit'])) { echo '<div class="row">'; echo ' <div class="col-sm-6">'; echo ' <h3><a href="/iftype/type=transit">Overall Transit Traffic Today</a></h3>'; echo ' <a href="' . $links['transit'] . '">' . $transit_graph . '</a>'; echo ' </div>'; echo ' <div class="col-sm-6 ">'; echo ' <h3><a href="/iftype/type=transit">Overall Transit Traffic This Week</a></h3>'; echo ' <a href="' . $links['transit'] . '">' . $transit_graph_week . '</a>'; echo ' </div>'; echo '</div>'; } elseif (count($ports['peering'])) { $links['peering'] = generate_url(array("page" => "iftype", "type" => "peering")); $ports['peering_list'] = implode(',', $ports['peering']); echo '<div class="row">'; echo ' <div class="col-sm-6 ">'; echo ' <h3><a href="/iftype/type=peering">Overall Peering Traffic Today</a></h3>'; echo ' <a href="' . $links['peering'] . '">' . $peering_graph . '</a>'; echo ' </div>'; echo ' <div class="col-sm-6 ">'; echo ' <h3><a href="/iftype/type=peering">Overall Peering Traffic This Week</a></h3>'; echo ' <a href="' . $links['peering'] . '">' . $peering_graph_week . '</a>'; echo ' </div>'; echo '</div>'; } if ($ports['transit_list'] && $ports['peering_list']) { $links['peer_trans'] = generate_url(array("page" => "iftype", "type" => "peering,transit")); echo '<div class="row">'; echo ' <div class="col-sm-12">'; echo ' <h3><a href="/iftype/type=transit%2Cpeering">Overall Transit & Peering Traffic This Month</a></h3>'; echo ' <a href="' . $links['peer_trans'] . '">' . $summary_graph . '</a>'; echo ' </div>'; echo '</div>'; } echo generate_box_close(); } }
* @copyright (C) 2006-2014 Adam Armstrong * */ ?> <div class="row"> <div class="col-md-12"> <?php ///FIXME. Mike: should be more checks, at least a confirmation click. //if ($vars['action'] == "expunge" && $_SESSION['userlevel'] >= '10') //{ // dbFetchCell('TRUNCATE TABLE `eventlog`'); // print_message('Event log truncated'); //} unset($search, $devices_array, $types); $where = ' WHERE 1 ' . generate_query_permitted(); //Device field foreach ($cache['devices']['hostname'] as $hostname => $device_id) { if ($cache['devices']['id'][$device_id]['disabled'] && !$config['web_show_disabled']) { continue; } $devices_array[$device_id] = $hostname; } $search[] = array('type' => 'multiselect', 'name' => '设备', 'id' => 'device_id', 'width' => '125px', 'value' => $vars['device_id'], 'values' => $devices_array); // Add device_id limit for other fields if (isset($vars['device_id'])) { $where .= generate_query_values($vars['device_id'], 'device_id'); } //Message field $search[] = array('type' => 'text', 'name' => '信息', 'id' => 'message', 'width' => '150px', 'placeholder' => 'Message', 'value' => $vars['message']); //Severity field