1<?php 2 3/** 4 * Observium 5 * 6 * This file is part of Observium. 7 * 8 * @package observium 9 * @subpackage web 10 * @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited 11 * 12 */ 13 14/** 15 * Display dot1x sessions 16 * 17 * @param array $vars 18 * @return none 19 * 20 */ 21function print_dot1xtable($vars) 22{ 23 // With pagination? (display page numbers in header) 24 $pagination = (isset($vars['pagination']) && $vars['pagination']); 25 pagination($vars, 0, TRUE); // Get default pagesize/pageno 26 $pageno = $vars['pageno']; 27 $pagesize = $vars['pagesize']; 28 $start = $pagesize * $pageno - $pagesize; 29 30 $param = array(); 31 $where = ' WHERE 1 '; 32 foreach ($vars as $var => $value) 33 { 34 if ($value != '') 35 { 36 switch ($var) 37 { 38 case 'device': 39 case 'device_id': 40 $where .= generate_query_values($value, 'device_id'); 41 break; 42 case 'address': 43 if (isset($vars['searchby']) && $vars['searchby'] == 'ip') 44 { 45 $value = trim($value); 46 $where .= generate_query_values($value, 'ipv4_addr', '%LIKE%'); 47 } else if (isset($vars['searchby']) && $vars['searchby'] == 'mac') { 48 $value = str_replace(array(':', ' ', '-', '.', '0x'), '', $value); 49 $where .= generate_query_values($value, 'M.mac_addr', '%LIKE%'); 50 } else { 51 $value = trim($value); 52 $where .= generate_query_values($value, 'username', '%LIKE%'); 53 } 54 break; 55 } 56 } 57 } 58 59 // Check permissions 60 $query_permitted = generate_query_permitted(array('device'), array('device_table' => 'M')); 61 62 $query = 'FROM `wifi_sessions` AS M '; 63 $query .= 'LEFT JOIN `wifi_radios` AS I ON I.`wifi_radio_id` = M.`radio_id` '; 64 $query .= $where . $query_permitted; 65 $query_count = 'SELECT COUNT(`wifi_session_id`) ' . $query; 66 $query = 'SELECT *, M.`mac_addr` AS `session_mac` ' . $query; 67 $query .= ' ORDER BY M.`timestamp` DESC'; 68 $query .= " LIMIT $start,$pagesize"; 69 70 // Query wireless sessions table 71 $entries = dbFetchRows($query, $param); 72 // Query wireless sessions table count 73 if ($pagination) { $count = dbFetchCell($query_count, $param); } 74 75 $aps_db = dbFetchRows("SELECT `wifi_accesspoint_id`, `name`, `ap_number` FROM `wifi_accesspoints`"); 76 77 foreach ($aps_db as $ap_db) 78 { 79 $aps_sorted_db[$ap_db['wifi_accesspoint_id']] = $ap_db; 80 } 81 82 $list = array('device' => FALSE, 'port' => FALSE); // A radio is like a port 83 if (!isset($vars['device']) || empty($vars['device']) || $vars['page'] == 'search') { $list['device'] = TRUE; } 84 if (!isset($vars['port']) || empty($vars['port']) || $vars['page'] == 'search') { $list['port'] = TRUE; } 85 86 $string = generate_box_open(); 87 88 $string .= '<table class="table table-striped table-hover table-condensed">' . PHP_EOL; 89 if (!$short) 90 { 91 $string .= ' <thead>' . PHP_EOL; 92 $string .= ' <tr>' . PHP_EOL; 93 $string .= ' <th>MAC Address</th>' . PHP_EOL; 94 $string .= ' <th>IP Address</th>' . PHP_EOL; 95 $string .= ' <th>Username</th>' . PHP_EOL; 96 $string .= ' <th>SSID/VLAN</th>' . PHP_EOL; 97 $string .= ' <th>Last Seen</th>' . PHP_EOL; 98 if ($list['device']) { $string .= ' <th>Device</th>' . PHP_EOL; } 99 if ($list['port']) { $string .= ' <th>Interface/AP</th>' . PHP_EOL; } 100 $string .= ' </tr>' . PHP_EOL; 101 $string .= ' </thead>' . PHP_EOL; 102 } 103 $string .= ' <tbody>' . PHP_EOL; 104 105 foreach ($entries as $entry) 106 { 107 $ap_id = $entry['accesspoint_id']; 108 $interface = $aps_sorted_db[$ap_id]['name']; 109 $string .= ' <tr>' . PHP_EOL; 110 $string .= ' <td style="width: 140px;">' . generate_popup_link('mac', format_mac($entry['session_mac'])) . '</td>' . PHP_EOL; 111 $string .= ' <td style="width: 140px;">' . generate_popup_link('ip', $entry['ipv4_addr']) . '</td>' . PHP_EOL; 112 $string .= ' <td style="white-space: nowrap;">' . $entry['username'] . '</td>' . PHP_EOL; 113 $string .= ' <td style="width: 140px;">' . $entry['ssid'] . '</td>' . PHP_EOL; 114 $string .= ' <td style="white-space: nowrap;">' . $entry['timestamp'] . '</td>' . PHP_EOL; 115 if ($list['device']) 116 { 117 $dev = device_by_id_cache($entry['device_id']); 118 $string .= ' <td class="entity" style="white-space: nowrap;">' . generate_device_link($dev) . '</td>' . PHP_EOL; 119 } 120 if ($list['port']) 121 { 122 $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; 123 } 124 $string .= ' </tr>' . PHP_EOL; 125 } 126 127 $string .= ' </tbody>' . PHP_EOL; 128 $string .= '</table>'; 129 130 $string .= generate_box_close(); 131 132 // Print pagination header 133 if ($pagination) { $string = pagination($vars, $count) . $string . pagination($vars, $count); } 134 135 // Print wireless sessions 136 echo $string; 137} 138 139// EOF 140