Completamento integrazione reader e webservice
This commit is contained in:
parent
cd5e7cfa30
commit
2c6761b6ff
|
@ -0,0 +1,9 @@
|
||||||
|
[ws]
|
||||||
|
receiver_url = "http://localhost/wifi-probe-aggregator/ws/receiver.php"
|
||||||
|
reader_url = "http://localhost/wifi-probe-aggregator/ws/reader.php"
|
||||||
|
|
||||||
|
[database]
|
||||||
|
db_host = "localhost"
|
||||||
|
db_user = "root"
|
||||||
|
db_pass = "mysql"
|
||||||
|
db_name = "wpa"
|
|
@ -4,9 +4,11 @@
|
||||||
* Script per simulare l'invio al web service di MAC address raccolti nelle vicinanze
|
* Script per simulare l'invio al web service di MAC address raccolti nelle vicinanze
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// Lettura file di configurazione
|
||||||
|
$config = parse_ini_file('../../config.ini');
|
||||||
|
|
||||||
// URL dell'endpoint che riceve i dati
|
// URL dell'endpoint che riceve i dati
|
||||||
$receiver_url = "http://localhost/wifi-probe-aggregator/ws/receiver.php";
|
$receiver_url = $config['receiver_url'];
|
||||||
|
|
||||||
// Lista di indirizzi MAC
|
// Lista di indirizzi MAC
|
||||||
$mac_addresses = [
|
$mac_addresses = [
|
||||||
|
@ -45,7 +47,7 @@ $ap = [
|
||||||
$post_data = [
|
$post_data = [
|
||||||
"address" => $mac_addresses[ rand(0, sizeof($mac_addresses)-1) ],
|
"address" => $mac_addresses[ rand(0, sizeof($mac_addresses)-1) ],
|
||||||
"essid" => $ap[ rand(0, sizeof($ap)-1) ],
|
"essid" => $ap[ rand(0, sizeof($ap)-1) ],
|
||||||
"signal" => rand(0, 100),
|
"signal" => rand(-30, -100),
|
||||||
"latitude" => 41.909986,
|
"latitude" => 41.909986,
|
||||||
"longitude" => 12.3959152,
|
"longitude" => 12.3959152,
|
||||||
];
|
];
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
{"config" : [{"interface": "wlan0mon"},
|
{"config" : [
|
||||||
{"pushoverapitoken": ""},
|
{"interface": "wlan0mon"},
|
||||||
{"pushoveruserkey": "" }],
|
{"receiver_host": "localhost"},
|
||||||
"list" : [{"name": "James Clerk Maxwell", "mac": "00:co:ca:c0:79:fa", "color": "1"},
|
{"receiver_url": "/wifi-probe-aggregator/ws/receiver.php" }],
|
||||||
{"name": "Christian Hulsmeyer", "mac": "ba:ad:c0:de:88:ca", "color": "2"},
|
"list" : []
|
||||||
{"name": "Heinrich Hertz", "mac": "e0:0f:00:0a:d0:a0", "color": "3"}]
|
|
||||||
}
|
}
|
|
@ -22,11 +22,9 @@ def ConfigCheck():
|
||||||
file = open(filename, "w")
|
file = open(filename, "w")
|
||||||
file.write('{'\
|
file.write('{'\
|
||||||
'"config" : [{"interface": "wlan0mon"},\n'\
|
'"config" : [{"interface": "wlan0mon"},\n'\
|
||||||
' {"pushoverapitoken": ""},\n'\
|
' {"receiver_host": ""},\n'\
|
||||||
' {"pushoveruserkey": "" }],\n'\
|
' {"receiver_url": "" }],\n'\
|
||||||
'"list" : [{"name": "James Clerk Maxwell", "mac": "00:co:ca:c0:79:fa", "color": "1"},\n'\
|
'"list" : []\n'\
|
||||||
' {"name": "Christian Hulsmeyer", "mac": "ba:ad:c0:de:88:ca", "color": "2"},\n'\
|
|
||||||
' {"name": "Heinrich Hertz", "mac": "e0:0f:00:0a:d0:a0", "color": "3"}]\n'\
|
|
||||||
'}')
|
'}')
|
||||||
file.close()
|
file.close()
|
||||||
print "\033[93m\033[1m[+]\033[0m Example configuration file created: \033[94m\033[1m[" + filename + "]\033[0m\n"
|
print "\033[93m\033[1m[+]\033[0m Example configuration file created: \033[94m\033[1m[" + filename + "]\033[0m\n"
|
||||||
|
@ -42,12 +40,6 @@ def ConfigCheck():
|
||||||
print "\033[91mSomething is wrong with the configuration file."
|
print "\033[91mSomething is wrong with the configuration file."
|
||||||
print "Edit or delete "+filename+" and try again.\033[0m\n\n"
|
print "Edit or delete "+filename+" and try again.\033[0m\n\n"
|
||||||
exit()
|
exit()
|
||||||
global pushoverenabled
|
|
||||||
if str(list[0]['config'][1]['pushoverapitoken']) != "" :
|
|
||||||
pushoverenabled = "Enabled"
|
|
||||||
else :
|
|
||||||
pushoverenabled = "Disabled"
|
|
||||||
|
|
||||||
|
|
||||||
def Welcome() :
|
def Welcome() :
|
||||||
banner = "\n".join([
|
banner = "\n".join([
|
||||||
|
@ -75,7 +67,6 @@ def PrintConfig() :
|
||||||
print " Configuration File \033[94m\033[1m[" + filename + "]\033[0m"
|
print " Configuration File \033[94m\033[1m[" + filename + "]\033[0m"
|
||||||
print " Log File \033[94m\033[1m[" + logfilename + "]\033[0m"
|
print " Log File \033[94m\033[1m[" + logfilename + "]\033[0m"
|
||||||
print " Monitor Interface \033[94m\033[1m[" + interface + "]\033[0m"
|
print " Monitor Interface \033[94m\033[1m[" + interface + "]\033[0m"
|
||||||
print " Pushover Notifications \033[94m\033[1m[" + pushoverenabled + "]\033[0m\n"
|
|
||||||
print "\n\033[92m\033[1m[+]\033[0m Listening for probe requests...\n"
|
print "\n\033[92m\033[1m[+]\033[0m Listening for probe requests...\n"
|
||||||
|
|
||||||
def GetOUI(pkt) :
|
def GetOUI(pkt) :
|
||||||
|
@ -91,7 +82,7 @@ def SearchList(pkt) :
|
||||||
global name
|
global name
|
||||||
name = "(Unknown)"
|
name = "(Unknown)"
|
||||||
COLOR = ""
|
COLOR = ""
|
||||||
if pkt.info == "" : pkt.info = "(Hidden)"
|
if pkt.info == "" : pkt.info = ""
|
||||||
for i in range(len(list[0]['list'])) :
|
for i in range(len(list[0]['list'])) :
|
||||||
if pkt.addr2 == list[0]['list'][i]['mac'] :
|
if pkt.addr2 == list[0]['list'][i]['mac'] :
|
||||||
name = list[0]['list'][i]['name']
|
name = list[0]['list'][i]['name']
|
||||||
|
@ -105,46 +96,46 @@ def PrintInfo(pkt) :
|
||||||
SSID = " SSID: " + pkt.info.ljust(maxlenght)[0:maxlenght]
|
SSID = " SSID: " + pkt.info.ljust(maxlenght)[0:maxlenght]
|
||||||
OUI = " OUI: "+ oui
|
OUI = " OUI: "+ oui
|
||||||
db = -(256-ord(pkt.notdecoded[-4:-3]))
|
db = -(256-ord(pkt.notdecoded[-4:-3]))
|
||||||
if db <= -100:
|
if db <= -100:
|
||||||
quality = 0
|
quality = 0
|
||||||
elif db >= -50:
|
elif db >= -50:
|
||||||
quality = 100
|
quality = 100
|
||||||
else:
|
else:
|
||||||
quality = 2 * (db + 100)
|
quality = 2 * (db + 100)
|
||||||
quality = str(quality)+"%"
|
quality = str(quality)+"%"
|
||||||
quality = " SIGNAL: " + quality.ljust(4, ' ')
|
quality = " SIGNAL: " + quality.ljust(4, ' ')
|
||||||
fingerprint = COLOR + timea + quality + namef + mac + SSID + OUI +'\033[0m'
|
fingerprint = COLOR + timea + quality + namef + mac + SSID + OUI +'\033[0m'
|
||||||
|
|
||||||
if fingerprint not in uniquefingerprint :
|
if fingerprint not in uniquefingerprint :
|
||||||
uniquefingerprint.append(fingerprint)
|
uniquefingerprint.append(fingerprint)
|
||||||
print fingerprint
|
print fingerprint
|
||||||
if COLOR == '\033[9'+'1'+'m' :
|
json_notification(pkt.addr2, pkt.info.ljust(maxlenght)[0:maxlenght], db, 0, 0)
|
||||||
pushover_notification(fingerprint[22:-3])
|
|
||||||
|
|
||||||
def WriteLog(fingerprint):
|
def WriteLog(fingerprint):
|
||||||
file = open(logfilename, "a")
|
file = open(logfilename, "a")
|
||||||
file.write(fingerprint + "\n")
|
file.write(fingerprint + "\n")
|
||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
|
|
||||||
def PacketHandler(pkt) :
|
def PacketHandler(pkt) :
|
||||||
if pkt.haslayer(Dot11ProbeReq) :
|
if pkt.haslayer(Dot11ProbeReq) :
|
||||||
GetOUI(pkt)
|
GetOUI(pkt)
|
||||||
SearchList(pkt)
|
SearchList(pkt)
|
||||||
PrintInfo(pkt)
|
PrintInfo(pkt)
|
||||||
WriteLog(fingerprint)
|
|
||||||
|
|
||||||
def signal_handler(signal, frame):
|
def signal_handler(signal, frame):
|
||||||
print "\n\033[92m\033[1m[+]\033[0m Exiting...\n"
|
print "\n\033[92m\033[1m[+]\033[0m Exiting...\n"
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
def pushover_notification(fingerprint):
|
def json_notification(mac, ssid, dbm, latitude, longitude):
|
||||||
conn = httplib.HTTPSConnection("api.pushover.net:443")
|
data = {}
|
||||||
conn.request("POST", "/1/messages.json",
|
data['address'] = str(mac)
|
||||||
urllib.urlencode({
|
data['essid'] = str(ssid)
|
||||||
"token": str(list[0]['config'][1]['pushoverapitoken']),
|
data['signal'] = str(dbm)
|
||||||
"user": str(list[0]['config'][2]['pushoveruserkey']),
|
data['latitude'] = str(latitude)
|
||||||
"message": fingerprint,
|
data['longitude'] = str(longitude)
|
||||||
}), { "Content-type": "application/x-www-form-urlencoded" })
|
|
||||||
|
conn = httplib.HTTPConnection(list[0]['config'][1]['receiver_host'])
|
||||||
|
conn.request("POST", list[0]['config'][2]['receiver_url'], json.dumps(data), { "Content-type": "application/x-www-form-urlencoded" })
|
||||||
conn.getresponse()
|
conn.getresponse()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,71 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
// Lettura file di configurazione
|
||||||
|
$config = parse_ini_file('../config.ini');
|
||||||
|
|
||||||
|
// Array per la risposta del web service
|
||||||
|
$result = [];
|
||||||
|
|
||||||
// Dati in arrivo dai readers
|
// Dati in arrivo dai readers
|
||||||
$post = file_get_contents('php://input');
|
$post = file_get_contents('php://input');
|
||||||
|
|
||||||
$data = json_decode( $post );
|
$data = json_decode( $post );
|
||||||
|
|
||||||
// TODO: inserimento a database
|
if (!empty($data) ){
|
||||||
|
// 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 {
|
||||||
|
// Preparazione query con prepared statements
|
||||||
|
$sql = "INSERT INTO logs (mac, ssid, dbm, latitude, longitude) VALUES (?, ?, ?, ?, ?)";
|
||||||
|
$stmt = $mysqli->prepare($sql);
|
||||||
|
|
||||||
|
// Errore nella preparazione query
|
||||||
|
if (!$stmt) {
|
||||||
|
$result = [
|
||||||
|
'status' => 'ERR',
|
||||||
|
'message' => $mysqli->error,
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
if ($stmt->bind_param('ssidd', $mac, $ssid, $dbm, $latitude, $longitude)) {
|
||||||
|
$mac = $data->address;
|
||||||
|
$ssid = $data->essid;
|
||||||
|
$dbm = $data->signal;
|
||||||
|
$latitude = $data->latitude;
|
||||||
|
$longitude = $data->longitude;
|
||||||
|
|
||||||
|
// Esecuzione statement
|
||||||
|
$stmt->execute();
|
||||||
|
|
||||||
|
$result = [
|
||||||
|
'status' => 'OK',
|
||||||
|
'message' => 'Inserimento avvenuto con successo',
|
||||||
|
'id' => $stmt->insert_id,
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
$result = [
|
||||||
|
'status' => 'ERR',
|
||||||
|
'message' => 'Errore durante l\'esecuzione query',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$stmt->close();
|
||||||
|
$mysqli->close();
|
||||||
|
} else {
|
||||||
|
$result = [
|
||||||
|
'status' => 'ERR',
|
||||||
|
'message' => 'Nessun dato in input',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
echo json_encode($result);
|
Loading…
Reference in New Issue