1 && count($sessions_array)) { print_vars($sessions_array); } $timestamp = date('Y-m-d H:i:s', strtotime("now")); // Goes through the SNMP sessions data foreach ($sessions_array as $index => $session) { [$a_a, $a_b, $a_c, $a_d, $a_e, $a_f] = explode(".", $index); $clean_mac = zeropad(dechex($a_a)) . zeropad(dechex($a_b)) . zeropad(dechex($a_c)) . zeropad(dechex($a_d)) . zeropad(dechex($a_e)) . zeropad(dechex($a_f)); // Mapping OIDs<>DB $db_oids = ['trpzClSessClientSessSessionId' => 'session_id', 'trpzClSessClientSessUsername' => 'username', 'trpzClSessClientSessIpAddress' => 'ipv4_addr', 'trpzClSessClientSessSsid' => 'ssid', 'trpzClSessClientSessSessionState' => 'state']; $new_index = $clean_mac; foreach ($db_oids as $db_oid => $db_value) { $db_insert[$db_value] = $session[$db_oid]; } $db_insert['device_id'] = $device['device_id']; $db_insert['mac_addr'] = $clean_mac; $db_insert['uptime'] = timeticks_to_sec($session['trpzClSessClientSessTimeStamp']); // FIXME. There timestamp, not timetick! $db_insert['timestamp'] = $timestamp; if ($session['trpzClSessClientSessRadioNum'] == "radio-1") { $radio_number = '1'; } elseif ($session['trpzClSessClientSessradioNum'] == "radio-2") { $radio_number = '2'; } $db_insert['radio_id'] = $radios_sorted_db[$session['trpzClSessClientSessApNum']][$radio_number]['wifi_radio_id']; if (OBS_DEBUG > 1) { print_vars($db_insert); } if (!is_array($sessions_db[$new_index])) //If new session { $session_id = dbInsert($db_insert, 'wifi_sessions'); echo('+'); } elseif (array_diff($db_insert, $sessions_db[$new_index])) { $updated = dbUpdate($db_insert, 'wifi_sessions', '`mac_addr` = ? AND `device_id` = ?', [$new_index, $device['device_id']]); echo("U"); } else { echo("."); } // XXX can add trending of link quality and bandwidth per MAC addr with trpzClSessClientSessionStatisticsTable // XXX No delete so we can see when a user was connected the last time, might be interesting to have a "deleted" boolean to know if he is still online } ///FIXME. Clean/delete old sessions from DB unset($oids, $oid, $sessions_array, $sessions_db, $db_insert); // EOF