From f866983d6b6cbfd7b6202921b1cf9c33732d7fdc Mon Sep 17 00:00:00 2001 From: loviuz Date: Sat, 8 Aug 2020 22:23:21 +0200 Subject: [PATCH] Aggiunta generazione grafico per vendor --- gui/index.php | 15 ++----- gui/js/wifi-probe-aggregator.js | 78 ++++++++++++++++++++++++++++++++- gui/orari.php | 4 +- ws/reader.php | 70 +++++++++++++++++++++++++++++ 4 files changed, 152 insertions(+), 15 deletions(-) diff --git a/gui/index.php b/gui/index.php index cd4fe8f..5e9084f 100755 --- a/gui/index.php +++ b/gui/index.php @@ -86,18 +86,7 @@ include('parts/header.php');
- -
-
- - Samsung - - - Apple - - - Huawei - +
@@ -107,6 +96,8 @@ include('parts/header.php'); close(); $mysqli->close(); break; + + + case 'get-devices-by-vendor': + // Vendor cache + $oui = file_get_contents($config['oui_path']); + + // Connessione al database + $mysqli = mysqli_connect($config['db_host'], $config['db_user'], $config['db_pass'], $config['db_name']); + + // Errore nella connessione a database + if (mysqli_connect_errno($mysqli)) { + + $result = [ + 'status' => 'ERR', + 'message' => mysqli_connect_error(), + ]; + } else { + $sql = " + SELECT + SUBSTRING(mac, 1, 8) AS indice, + COUNT(mac) AS valore + FROM + `logs` + GROUP BY + SUBSTRING(mac, 1, 8) + ORDER BY + valore DESC + LIMIT + 0, 10"; + + $stmt = $mysqli->prepare($sql); + + // Errore nella preparazione query + if (!$stmt) { + $result = [ + 'status' => 'ERR', + 'message' => $mysqli->error, + ]; + } else { + // Esecuzione statement + $stmt->execute(); + + $rs = $stmt->get_result(); + + while ($row = $rs->fetch_assoc()) { + // Lettura vendor + $mac = str_replace( ':', '-', substr($row['indice'], 0, 8) ); + + $row['valore_extra'] = ''; + + if( preg_match( '/^'.preg_quote($mac).'([\s\t]+)\(hex\)(.+?)$/im', $oui, $m) ){ + $row['valore_extra'] = trim($m[2]); + } + + $records[] = $row; + } + + $result = [ + 'status' => 'OK', + 'records' => $records, + ]; + } + } + + echo json_encode($result); + + $stmt->close(); + $mysqli->close(); + break; }