Skip to content

Commit 2dee80e

Browse files
committed
Add PHY mode and country code
1 parent cdb3edf commit 2dee80e

File tree

7 files changed

+107
-34
lines changed

7 files changed

+107
-34
lines changed

Readme.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,6 @@ Table Schema
3333
* mcs (string) Modulation and Coding Scheme
3434
* channel (string) Channel of wireless network
3535
* snr (integer) Signal to noise ratio
36-
* known_networks (medium text) JSON string detailing known wireless networks
36+
* known_networks (medium text) JSON string detailing known wireless networks
37+
* phy_mode (string) PHY mode of the current active connection
38+
* country_code (string) Current contry code of the WiFi

locales/en.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
"wpa2-psk": "WPA2-PSK",
3636
"wpa2": "WPA2",
3737
"wpa3-sae": "WPA3-SAE",
38+
"mcs": "MCS Index",
39+
"country_code": "Country Code",
40+
"phy_mode": "PHY Mode",
3841
"running": "Connected",
3942
"off": "Off",
4043
"snr": "Signal to Noise Ratio",
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
use Illuminate\Database\Schema\Blueprint;
4+
use Illuminate\Database\Migrations\Migration;
5+
use Illuminate\Database\Capsule\Manager as Capsule;
6+
7+
class WifiAddPhyMode extends Migration
8+
{
9+
private $tableName = 'wifi';
10+
11+
public function up()
12+
{
13+
$capsule = new Capsule();
14+
15+
$capsule::schema()->table($this->tableName, function (Blueprint $table) {
16+
$table->string('phy_mode')->nullable();
17+
$table->string('country_code')->nullable();
18+
});
19+
20+
// Create indexes
21+
$capsule::schema()->table($this->tableName, function (Blueprint $table) {
22+
$table->index('phy_mode');
23+
$table->index('country_code');
24+
});
25+
}
26+
27+
public function down()
28+
{
29+
$capsule = new Capsule();
30+
$capsule::schema()->table($this->tableName, function (Blueprint $table) {
31+
$table->dropColumn('phy_mode');
32+
$table->dropColumn('country_code');
33+
});
34+
}
35+
}

scripts/wifi

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def get_wifi_info():
3838

3939
if 'AirPort: Off' in output or 'AirPort is Off' in output:
4040
return {"state":"off"}
41-
41+
4242
info = {}
4343
for item in re.findall(r'\s*(.+): ([^\n]+)\n', output):
4444
key = item[0].lower().replace('.', '_').replace(' ', '_')
@@ -53,6 +53,29 @@ def get_wifi_info():
5353

5454
return info
5555

56+
def get_additional_wifi_info():
57+
58+
info = {}
59+
60+
try:
61+
cmd = ['/usr/libexec/airportd', 'info']
62+
proc = subprocess.Popen(cmd, shell=False, bufsize=-1,
63+
stdin=subprocess.PIPE,
64+
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
65+
(output, unused_error) = proc.communicate()
66+
output = output.decode("utf-8", errors="ignore")
67+
68+
for line in output.split('\n'):
69+
if "Active PHY: " in line:
70+
info['phy_mode'] = line.replace("Active PHY: ","").strip()
71+
elif "Country Code: " in line:
72+
info['country_code'] = line.replace("Country Code: ","").strip()
73+
74+
except Exception:
75+
pass
76+
77+
return info
78+
5679
def get_wifi_interface():
5780

5881
try:
@@ -72,16 +95,16 @@ def get_wifi_interface():
7295
return ""
7396

7497
def check_wifi_sharing():
75-
98+
7699
try:
77100
plist = FoundationPlist.readPlist("/Library/Preferences/SystemConfiguration/com.apple.nat.plist")
78101
wifi_interface = get_wifi_interface()
79-
102+
80103
if wifi_interface in plist["NAT"]["SharingDevices"]:
81104
return True
82105
else:
83106
return False
84-
107+
85108
except Exception:
86109
return False
87110

@@ -356,7 +379,7 @@ def to_bool(s):
356379
return 1
357380
else:
358381
return 0
359-
382+
360383
def merge_two_dicts(x, y):
361384
z = x.copy()
362385
z.update(y)
@@ -376,7 +399,7 @@ def collect_known_networks_enabled():
376399

377400
def main():
378401
"""Main"""
379-
402+
380403
# Don't process known networks if less than macOS 11 (Darwin 20), we don't support doing that anymore
381404
if collect_known_networks_enabled() and getDarwinVersion() > 19:
382405
known_networks = get_networks()
@@ -385,7 +408,11 @@ def main():
385408

386409
result = dict()
387410
result = merge_two_dicts(get_wifi_info(), known_networks)
388-
411+
412+
# Get additional WiFi info only if WiFi is active and connected
413+
if result["state"] == "running":
414+
result = merge_two_dicts(get_additional_wifi_info(), result)
415+
389416
# Write ard results to cache
390417
cachedir = '%s/cache' % os.path.dirname(os.path.realpath(__file__))
391418
output_plist = os.path.join(cachedir, 'wifi.plist')

views/wifi_listing.php

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,17 @@
1818
<th data-colname='wifi.snr'>SNR</th>
1919
<th data-colname='wifi.agrctlrssi'>RSSI</th>
2020
<th data-i18n="wifi.agrctlnoise_short" data-colname='wifi.agrctlnoise'></th>
21-
<th data-i18n="wifi.x802_11_auth_short" data-colname='wifi.x802_11_auth'></th>
21+
<th data-i18n="wifi.phy_mode" data-colname='wifi.phy_mode'></th>
2222
<th data-i18n="wifi.link_auth" data-colname='wifi.link_auth'></th>
2323
<th data-i18n="wifi.op_mode" data-colname='wifi.op_mode'></th>
24+
<th data-colname='wifi.country_code' data-colname='wifi.country_code'></th>
2425
<th data-colname='wifi.mcs'>MCS</th>
26+
<th data-i18n="wifi.x802_11_auth_short" data-colname='wifi.x802_11_auth'></th>
2527
</tr>
2628
</thead>
2729
<tbody>
2830
<tr>
29-
<td data-i18n="listing.loading" colspan="15" class="dataTables_empty"></td>
31+
<td data-i18n="listing.loading" colspan="17" class="dataTables_empty"></td>
3032
</tr>
3133
</tbody>
3234
</table>
@@ -70,15 +72,15 @@
7072
var sn=$('td:eq(1)', nRow).html();
7173
var link = mr.getClientDetailLink(name, sn, '#tab_wifi-tab');
7274
$('td:eq(0)', nRow).html(link);
73-
75+
7476
// Format Last Tx
7577
var lastTx=$('td:eq(5)', nRow).html();
7678
$('td:eq(5)', nRow).html('<span title="'+(lastTx*0.125)+' MB/sec">'+lastTx+" Mbps</span>");
77-
79+
7880
// Format Max Tx
7981
var maxTx=$('td:eq(6)', nRow).html();
8082
$('td:eq(6)', nRow).html('<span title="'+(maxTx*0.125)+' MB/sec">'+maxTx+" Mbps</span>");
81-
83+
8284
// Calculate signal to noise ratio
8385
var snr=$('td:eq(8)', nRow).html();
8486
var rssi=$('td:eq(9)', nRow).html();
@@ -88,20 +90,15 @@
8890
} else if (rssi !== "" && noise !== ""){
8991
$('td:eq(8)', nRow).html('<span title="'+i18n.t('wifi.snr_detail')+'">'+(rssi-noise)+' db</span>');
9092
}
91-
93+
9294
// Format RSSI
9395
var rssi=$('td:eq(9)', nRow).html();
9496
$('td:eq(9)', nRow).html('<span title="'+i18n.t('wifi.rssi_detail')+'">'+rssi+' db</span>');
95-
97+
9698
// Format Noise
9799
var noise=$('td:eq(10)', nRow).html();
98100
$('td:eq(10)', nRow).html('<span title="'+i18n.t('wifi.noise_detail')+'">'+noise+' db</span>');
99-
100-
// Format 802.1x mode
101-
var eightmode=$('td:eq(11)', nRow).html();
102-
eightmode = eightmode == 'open' ? i18n.t('wifi.open') : (eightmode)
103-
$('td:eq(11)', nRow).html(eightmode)
104-
101+
105102
// Format Link Auth
106103
var linkauth=$('td:eq(12)', nRow).html();
107104
linkauth = linkauth == 'none' ? i18n.t('wifi.none') :
@@ -115,13 +112,18 @@
115112
linkauth = linkauth == 'wpa3-sae' ? i18n.t('wifi.wpa3-sae') :
116113
(linkauth === 'wpa2' ? i18n.t('wifi.wpa2') : linkauth)
117114
$('td:eq(12)', nRow).html(linkauth)
118-
115+
119116
// Format AP Mode
120117
var apmode=$('td:eq(13)', nRow).html();
121118
apmode = apmode == 'station' ? i18n.t('wifi.station') :
122119
apmode = apmode == 'station ' ? i18n.t('wifi.station') : (apmode)
123120
$('td:eq(13)', nRow).html(apmode)
124-
121+
122+
// Format 802.1x mode
123+
var eightmode=$('td:eq(16)', nRow).html();
124+
eightmode = eightmode == 'open' ? i18n.t('wifi.open') : (eightmode)
125+
$('td:eq(16)', nRow).html(eightmode)
126+
125127
// Blank row if no wifi
126128
var wifistate=$('td:eq(4)', nRow).html();
127129
if ( wifistate == 'no wifi' || wifistate == 'off' || wifistate == 'init') {
@@ -136,8 +138,10 @@
136138
$('td:eq(12)', nRow).html("")
137139
$('td:eq(13)', nRow).html("")
138140
$('td:eq(14)', nRow).html("")
141+
$('td:eq(15)', nRow).html("")
142+
$('td:eq(16)', nRow).html("")
139143
}
140-
144+
141145
// Format wifi state
142146
var wifistate=$('td:eq(4)', nRow).html();
143147
wifistate = wifistate == 'running' ? i18n.t('wifi.running') :

wifi_controller.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Wifi_controller class
55
*
66
* @package wifi
7-
* @author John Eberle
7+
* @author tuxudo
88
**/
99
class Wifi_controller extends Module_controller
1010
{
@@ -100,7 +100,7 @@ public function get_scroll_widget($column)
100100
$queryobj = new Wifi_model;
101101
jsonView($queryobj->query($sql));
102102
}
103-
103+
104104
/**
105105
* Retrieve data in json format
106106
*
@@ -112,13 +112,13 @@ public function get_tab_data($serial_number = '')
112112
// Remove non-serial number characters
113113
$serial_number = preg_replace("/[^A-Za-z0-9_\-]]/", '', $serial_number);
114114

115-
$sql = "SELECT ssid, bssid, state, op_mode, x802_11_auth, link_auth, lasttxrate, maxrate, channel, agrctlrssi, agrctlnoise, snr, known_networks
115+
$sql = "SELECT ssid, bssid, state, op_mode, x802_11_auth, link_auth, lasttxrate, maxrate, channel, phy_mode, mcs, country_code, agrctlrssi, agrctlnoise, snr, known_networks
116116
FROM wifi
117117
WHERE serial_number = '$serial_number'";
118118

119119
$obj = new View();
120120
$queryobj = new Wifi_model();
121121
$wifi_tab = $queryobj->query($sql);
122-
$obj->view('json', array('msg' => current(array('msg' => $wifi_tab))));
122+
$obj->view('json', array('msg' => current(array('msg' => $wifi_tab))));
123123
}
124124
} // End class Wifi_controller

wifi_model.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class Wifi_model extends \Model
66
{
77
public function __construct($serial = '')
88
{
9-
parent::__construct('id', 'wifi'); //primary key, tablename
9+
parent::__construct('id', 'wifi'); // Primary key, tablename
1010
$this->rs['id'] = "";
1111
$this->rs['serial_number'] = $serial;
1212
$this->rs['agrctlrssi'] = 0;
@@ -26,22 +26,24 @@ public function __construct($serial = '')
2626
$this->rs['channel'] = '';
2727
$this->rs['snr'] = 0;
2828
$this->rs['known_networks'] = "";
29-
29+
$this->rs['phy_mode'] = null;
30+
$this->rs['country_code'] = null;
31+
3032
if ($serial) {
3133
$this->retrieve_record($serial);
3234
}
33-
35+
3436
$this->serial = $serial;
3537
}
36-
38+
3739
// Process incoming data
3840
public function process($data)
3941
{
4042
// Check if data has been passed to model
4143
if (! $data) {
4244
throw new Exception("Error Processing Request: No data found", 1);
4345
} else if (substr( $data, 0, 30 ) != '<?xml version="1.0" encoding="' ) { // Else if old style text, process with old text based handler
44-
46+
4547
// Translate network strings to db fields
4648
$translate = array(
4749
' agrCtlRSSI: ' => 'agrctlrssi',
@@ -81,7 +83,7 @@ public function process($data)
8183
$plist = $parser->toArray();
8284

8385
// Process each of the items
84-
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) {
86+
foreach (array('agrctlrssi', 'agrextrssi', 'agrctlnoise', 'agrextnoise', 'state', 'op_mode', 'lasttxrate', 'lastassocstatus', 'maxrate', 'x802_11_auth', 'link_auth', 'bssid', 'ssid', 'mcs', 'channel', 'snr', 'known_networks', 'phy_mode', 'country_code') as $item) {
8587

8688
// If key exists and is zero, set it to zero
8789
if ( array_key_exists($item, $plist) && $plist[$item] === 0) {

0 commit comments

Comments
 (0)