-
Notifications
You must be signed in to change notification settings - Fork 3
/
data.php
59 lines (49 loc) · 1.81 KB
/
data.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
$servername = "YOUR SERVER NAME";
$username = "YOUR DB USERNAME";
$password = "YOUR DB PASSWORD";
$dbname = "cloudtrax";
$jsondata = file_get_contents("php://input");
$data = json_decode($jsondata, true);
$serializedData = serialize($jsondata); //where '$array' is your array
file_put_contents('latest.txt', $serializedData);
file_put_contents('latest-raw.txt', $jsondata);
$network_id = $data['network_id'];
$node_mac = $data['node_mac'];
$version = $data['version'];
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO presence_header (network_id, node_mac, version)
VALUES ('$network_id', '$node_mac', '$version')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
$headerid = mysqli_insert_id($conn);
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
foreach ($data['probe_requests'] as $client)
{
$mac = $client['mac'];
$count = $client['count'];
$min_signal = $client['min_signal'];
$max_signal = $client['max_signal'];
$avg_signal = $client['avg_signal'];
$last_seen_signal = $client['last_seen_signal'];
$first_seen = $client['first_seen'];
$last_seen = $client['last_seen'];
$associated = $client['associated'];
$sql = "INSERT INTO presence_detail (id_presence_header, mac, count, min_signal, max_signal, avg_signal, first_seen, last_seen, associated, id_presence_detail)
VALUES ('$headerid', '$mac', '$count', '$min_signal', '$max_signal', '$avg_signal', '$first_seen', '$last_seen', '$associated', '')";
if ($conn->query($sql) === TRUE) {
echo "New detail record created successfully";
} else {
$error = "Error: " . $sql . "<br>" . $conn->error;
file_put_contents('error.txt', $error);
}
}
$conn->close();
?>