-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwifi_model.php
103 lines (90 loc) · 3.92 KB
/
wifi_model.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
use CFPropertyList\CFPropertyList;
class Wifi_model extends \Model
{
public function __construct($serial = '')
{
parent::__construct('id', 'wifi'); //primary key, tablename
$this->rs['id'] = 0;
$this->rs['serial_number'] = $serial;
$this->rs['agrctlrssi'] = 0;
$this->rs['agrextrssi'] = 0;
$this->rs['agrctlnoise'] = 0;
$this->rs['agrextnoise'] = 0;
$this->rs['state'] = '';
$this->rs['op_mode'] = '';
$this->rs['lasttxrate'] = 0;
$this->rs['lastassocstatus'] = '';
$this->rs['maxrate'] = 0;
$this->rs['x802_11_auth'] = '';
$this->rs['link_auth'] = '';
$this->rs['bssid'] = '';
$this->rs['ssid'] = '';
$this->rs['mcs'] = 0;
$this->rs['channel'] = '';
$this->rs['snr'] = 0;
$this->rs['known_networks'] = "";
if ($serial) {
$this->retrieve_record($serial);
}
$this->serial = $serial;
}
// Process incoming data
public function process($data)
{
// Check if data has been passed to model
if (! $data) {
throw new Exception("Error Processing Request: No data found", 1);
} else if (substr( $data, 0, 30 ) != '<?xml version="1.0" encoding="' ) { // Else if old style text, process with old text based handler
// Translate network strings to db fields
$translate = array(
' agrCtlRSSI: ' => 'agrctlrssi',
' agrExtRSSI: ' => 'agrextrssi',
' agrCtlNoise: ' => 'agrctlnoise',
' agrExtNoise: ' => 'agrextnoise',
' state: ' => 'state',
' op mode: ' => 'op_mode',
' lastTxRate: ' => 'lasttxrate',
' maxRate: ' => 'maxrate',
'lastAssocStatus: ' => 'lastassocstatus',
' 802.11 auth: ' => 'x802_11_auth',
' link auth: ' => 'link_auth',
' BSSID: ' => 'bssid',
' SSID: ' => 'ssid',
' MCS: ' => 'mcs',
' channel: ' => 'channel');
// Parse data
foreach (explode("\n", $data) as $line) {
// Translate standard entries
foreach ($translate as $search => $field) {
if (strpos($line, $search) === 0) {
$value = substr($line, strlen($search));
$this->$field = $value;
break;
}
}
} // end foreach explode lines
$this->save();
} else { // Else process with new XML handler
// Process incoming wifi.plist
$parser = new CFPropertyList();
$parser->parse($data, CFPropertyList::FORMAT_XML);
$plist = $parser->toArray();
// Process each of the items
foreach (array('agrctlrssi', 'agrextrssi', 'agrctlnoise', 'agrextnoise', 'state', 'op_mode', 'lasttxrate', 'lastassocstatus', 'maxrate', 'x802_11_auth', 'link_auth', 'bssid', 'ssid', 'mcs', 'channel', 'snr', 'known_networks') as $item) {
// If key exists and is zero, set it to zero
if ( array_key_exists($item, $plist) && $plist[$item] === 0) {
$this->$item = 0;
// Else if key does not exist in $plist, null it
} else if (! array_key_exists($item, $plist) || $plist[$item] == '' || $plist[$item] == "{}" || $plist[$item] == "[]") {
$this->$item = null;
// Set the db fields to be the same as those in the preference file
} else {
$this->$item = $plist[$item];
}
}
// Save the data because bumblebees are fuzzy
$this->save();
}
}
}