diff --git a/html/.test.php.swp b/html/.test.php.swp deleted file mode 100644 index f7aeb6b..0000000 Binary files a/html/.test.php.swp and /dev/null differ diff --git a/html/css/bootstrap.css b/html/css/bootstrap.css index 00de64e..27105f9 100644 --- a/html/css/bootstrap.css +++ b/html/css/bootstrap.css @@ -1312,3 +1312,4 @@ th.visible-print,td.visible-print{display:none !important;} .dl-search{margin-bottom:0px;margin-top:0px;} .dl-search dt{float:left;width:48px;clear:left;text-align:right;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;} .dl-search dd{margin-left:65px;} +.clientconnected {color:#008c00;} diff --git a/html/includes/graphs/device/wifi_client.inc.php b/html/includes/graphs/device/wifi_client.inc.php new file mode 100644 index 0000000..2e87f91 --- /dev/null +++ b/html/includes/graphs/device/wifi_client.inc.php @@ -0,0 +1,26 @@ + diff --git a/html/includes/navbar.inc.php b/html/includes/navbar.inc.php index 2f36ba7..3488db7 100644 --- a/html/includes/navbar.inc.php +++ b/html/includes/navbar.inc.php @@ -215,6 +215,8 @@ foreach ($config['device_types'] as $devtype) } ?>
  • +
  • WiFi Clients
  • +
  • Add Device
  • Delete Device
  • diff --git a/html/pages/device/graphs.inc.php b/html/pages/device/graphs.inc.php index 000cc3e..32a559a 100644 --- a/html/pages/device/graphs.inc.php +++ b/html/pages/device/graphs.inc.php @@ -39,10 +39,65 @@ foreach ($graph_enable as $graph => $entry) $graph_array = array(); if ($graph_enable[$graph]) { - $graph_title = $config['graph_types']['device'][$graph]['descr']; - $graph_array['type'] = "device_" . $graph; + if ($graph == 'wifi_client') + { + // Get a list of clients associated with this access point + $clients = dbFetchRows("SELECT device_id, client_mac, active FROM airport_clients WHERE device_id='".$device['device_id']."'"); - include("includes/print-device-graph.php"); + $graph_array['device'] = $device['device_id']; + foreach ($clients as $client) + { + $client_mac = $client['client_mac']; + + $client_details = dbFetchRows("SELECT hostname FROM mac_ip_host WHERE mac='".$client_mac."'"); + + if (empty($client_details)) + { + $client_id = $client_mac; + } + else + { + $client_id = $client_details[0]['hostname']; + } + + $graph_array['airport_ap'] = $device['hostname']; + $graph_array['client_mac'] = $client_mac; + $graph_array['type'] = "device_" . $graph; + if ($client['active'] == 'y') + { + $active = 'class="clientconnected"'; + } + else + { + unset($active); + } + + + // FIXME not css alternating yet + if (is_integer($g_i/2)) { $row_colour = $list_colour_a; } else { $row_colour = $list_colour_b; } + + echo(''); + + $url = generate_url(array('page' => 'wifi_client', + 'client' => $client_mac)); + echo('

    + Client '.$client_id.' +

    '); + + include("includes/print-graphrow.inc.php"); + + echo(''); + + $g_i++; + } + } + else + { + $graph_title = $config['graph_types']['device'][$graph]['descr']; + $graph_array['type'] = "device_" . $graph; + + include("includes/print-device-graph.php"); + } } } diff --git a/html/pages/device/overview.inc.php b/html/pages/device/overview.inc.php index a46f7d6..b10860c 100644 --- a/html/pages/device/overview.inc.php +++ b/html/pages/device/overview.inc.php @@ -107,6 +107,8 @@ include("overview/toner.inc.php"); include("overview/sensors.inc.php"); +include("overview/wificlients.inc.php"); + include("overview/events.inc.php"); ?> diff --git a/html/pages/device/overview/wificlients.inc.php b/html/pages/device/overview/wificlients.inc.php new file mode 100644 index 0000000..b2762ac --- /dev/null +++ b/html/pages/device/overview/wificlients.inc.php @@ -0,0 +1,57 @@ + +
    +
    + WiFi Clients
    +
    + '); + echo(' + Client + Signal + Noise + Speed + '); + foreach ($clients as $client) + { + if ($client['active'] == 'y') + { + $active = 'class="clientconnected"'; + } + else + { + unset($active); + } + + $client_details = dbFetchRows("SELECT hostname FROM mac_ip_host WHERE mac='".$client['client_mac']."'"); + + if (empty($client_details)) + { + $client_id = $client['client_mac']; + } + else + { + $client_id = $client_details[0]['hostname']; + } + + $url = generate_url(array('page' => 'wifi_client', + 'client' => $client['client_mac'])); + echo(' + '.$client_id.' + '.$client['signal_db'].' + '.$client['noise_db'].' + '.$client['speed'].' + '); + } + echo(''); + } + echo("
    "); +?> diff --git a/html/pages/wifi_client.inc.php b/html/pages/wifi_client.inc.php new file mode 100644 index 0000000..764978a --- /dev/null +++ b/html/pages/wifi_client.inc.php @@ -0,0 +1,151 @@ +'); + echo(' + + + Client '.$client_id.' + + '); + echo(''); + + foreach ($bstations as $ap) + { + unset($graph_array); + $ap_device = device_by_id_cache($ap['device_id']); + $graph_array['airport_ap'] = $ap_device['hostname']; + $graph_array['client_mac'] = $ap['client_mac']; + $graph_array['type'] = "device_wifi_client"; + if ($ap['active'] == 'y') + { + $active = 'class="clientconnected"'; + } + else + { + unset($active); + } + + // FIXME not css alternating yet + if (is_integer($g_i/2)) { $row_colour = $list_colour_a; } else { $row_colour = $list_colour_b; } + + echo(''); + + $url = generate_url(array('page' => 'device', + 'device' => $ap_device['device_id'], + 'tab' => 'graphs', + 'group' => 'wireless')); + echo('

    + Basestation '.$ap_device['hostname'].' +

    '); + + include("includes/print-graphrow.inc.php"); + + echo(''); + + $g_i++; + } + + return; +} + +function display_all_clients() +{ + // Get a list of unique clients ordered by hostname and then MAC address for + // those where the hostname is not known + $clients_hostname = dbFetchRows("SELECT DISTINCT client_mac FROM airport_clients LEFT JOIN mac_ip_host ON airport_clients.client_mac=mac_ip_host.mac WHERE hostname!='' ORDER BY hostname"); + $clients_nohostname = dbFetchRows("SELECT DISTINCT client_mac FROM airport_clients LEFT JOIN mac_ip_host ON airport_clients.client_mac=mac_ip_host.mac WHERE hostname IS NULL ORDER BY client_mac"); + $clients = array_merge($clients_hostname, $clients_nohostname); + + // Print the device header inside a table. + echo(''); + echo(' + + + +
    All Clients + '); + echo('
    '); + + // Display the clients + echo(''); + echo(''); + foreach ($clients as $client) + { + // If the client is active highlight + $client_active = dbFetchRows("SELECT active FROM airport_clients WHERE client_mac='".$client['client_mac']."' AND active='y'"); + if (empty($client_active)) + { + unset($active); + } + else + { + $active = 'class="clientconnected"'; + } + + $client_details = dbFetchRows("SELECT hostname FROM mac_ip_host WHERE mac='".$client['client_mac']."'"); + + // Use the hostname if it exists + if (empty($client_details)) + { + $client_id = $client['client_mac']; + } + else + { + $client_id = $client_details[0]['hostname']; + } + + $url = generate_url(array('page' => 'wifi_client', + 'client' => $client['client_mac'])); + $ap_device = device_by_id_cache($client['device_id']); + echo(' + + '); + } + echo('
    Client
    '.$client_id.'
    '); + + return; +} + +// If a client is specified then display all charts relating to that +// client, otherwise, show all charts assocaited with this +// basestation + +// If there is no device specified in the URL, generate an error. +if (empty($vars['client'])) +{ + display_all_clients(); +} +else +{ + display_client($vars['client']); +} + +?> diff --git a/includes/definitions/graphtypes.inc.php b/includes/definitions/graphtypes.inc.php index 6447feb..650b1c9 100644 --- a/includes/definitions/graphtypes.inc.php +++ b/includes/definitions/graphtypes.inc.php @@ -15,9 +15,13 @@ $config['graph_types']['port']['errors'] = array('name' => 'Errors', 'de $config['graph_types']['port']['etherlike'] = array('name' => 'Ethernet Errors', 'descr' => "Detailed Errors/sec for Ethernet-like interfaces"); +// Charts by access point $config['graph_types']['device']['wifi_clients']['section'] = 'wireless'; $config['graph_types']['device']['wifi_clients']['order'] = '0'; -$config['graph_types']['device']['wifi_clients']['descr'] = 'Wireless Clients'; +$config['graph_types']['device']['wifi_clients']['descr'] = 'Wireless Client Count'; +$config['graph_types']['device']['wifi_client']['section'] = 'wireless'; +$config['graph_types']['device']['wifi_client']['order'] = '0'; +$config['graph_types']['device']['wifi_client']['descr'] = 'Wireless Client data'; // NetApp graphs $config['graph_types']['device']['netapp_ops'] = array('section' => 'netapp', 'descr' => 'NetApp Operations', 'order' => '0'); diff --git a/includes/polling/wifi.inc.php b/includes/polling/wifi.inc.php index 085b8a2..a14fd3d 100644 --- a/includes/polling/wifi.inc.php +++ b/includes/polling/wifi.inc.php @@ -1,3 +1,14 @@ +/* +To create a mac lookup database exported from pfsense DHCP status create a table + +create table mac_ip_host (mac VARCHAR(18), ip VARCHAR(16), hostname VARCHAR(255)); + +Import the data + +GRANT FILE ON *.* TO 'observium'@'localhost' IDENTIFIED BY PASSWORD 'xxx'; +LOAD DATA INFILE '/tmp/macs.csv' INTO TABLE mac_ip_host FIELDS TERMINATED BY ','; + +*/ 'n'), + 'airport_clients', + '`device_id` = ?', + array($device['device_id'])); + + // Get the Airport wireless stats + $airport_oids = array('wirelessPhysAddress','wirelessStrength','wirelessNoise', 'wirelessRate'); + foreach ($airport_oids as $oid) + { + $airport_stats = snmpwalk_cache_oid($device, $oid, $airport_stats, "AIRPORT-BASESTATION-3-MIB"); + } + + // This info need to be stuck in the model + foreach ($airport_stats as $interface => $stats) + { + // Determine the MAC address consistently + $mac_length = strlen("xx:xx:xx:xx:xx:xx"); + $client_mac = str_ireplace(" ", ":", $stats['wirelessPhysAddress']); + + // Determine the RRD filename + $wificlientsrrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("wificlient-" . $stats['wirelessPhysAddress'] . ".rrd"); + + // Create the rrd file if this is a new client and add a row the the + // airport_clients SQL table + if (!is_file($wificlientsrrd)) + { + rrdtool_create($wificlientsrrd," \ + DS:Signal:GAUGE:600:-100:0 \ + DS:Noise:GAUGE:600:-100:0 \ + DS:Speed:GAUGE:600:0:300 "); + + // mysql: create table airport_clients (device_id SMALLINT, client_mac VARCHAR(18), active CHAR, signal_db SMALLINT, noise_db SMALLINT, speed SMALLINT); + dbInsert(array('device_id' => $device['device_id'], + 'client_mac' => $client_mac, + 'active' => 'y', + 'signal_db' => $stats['wirelessStrength'], + 'noise_db' => $stats['wirelessNoise'], + 'speed' => $stats['wirelessRate']), 'airport_clients'); + } + + // Mark the connection as active for the client connection to this + // basestation and update the stats + dbUpdate(array('active' => 'y', + 'signal_db' => $stats['wirelessStrength'], + 'noise_db' => $stats['wirelessNoise'], + 'speed' => $stats['wirelessRate']), + 'airport_clients', + '`device_id` = ? AND `client_mac` = ?', + array($device['device_id'], $client_mac)); + + // Update the rrd file + $rrd_update = array ($stats['wirelessStrength'], + $stats['wirelessNoise'], + $stats['wirelessRate']); + + rrdtool_update("$wificlientsrrd", $rrd_update); + } + + // Mark that this basestation has connections + $graphs['wifi_client'] = TRUE; } + if ($device['os'] == 'ios' && $device['type'] == 'wireless') { echo("Checking Aironet Wireless clients... "); @@ -66,7 +139,7 @@ if ($device['type'] == 'network' || $device['type'] == 'firewall' || $device['ty } ///# RRD Filling Code - if (isset($wificlients1) && $wificlients1 != "") + if (isset($wificlients1)) { $wificlientsrrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("wificlients-radio1.rrd");