Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access wifi data through daemon for macOS Monterey #521

Merged
merged 1 commit into from
Nov 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified bin/prey-user
Binary file not shown.
6 changes: 3 additions & 3 deletions lib/agent/providers/geo/strategies.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var GEO_ENDPOINT = 'https://solid.preyproject.com/geo',
proxy;

function geoip(cb) {
logger.debug("Getting location via geoip");
logger.info("Getting location via geoip");

needle.get('http://ipinfo.io/geo', function(err, resp, body) {
if (!body || !body.loc) {
Expand All @@ -33,7 +33,7 @@ function geoip(cb) {
}

function wifi(cb) {
logger.debug("Getting location via wifi strategy");
logger.info("Getting location via wifi strategy");

providers.get('access_points_list', function(err, list) {
if (err) return cb(err);
Expand Down Expand Up @@ -161,7 +161,7 @@ function wifi(cb) {
}

function geonative(cb) {
logger.debug("Getting location via native geoloc");
logger.info("Getting location via native geoloc");

platform.get_location(function(err, res) {
if (err) {
Expand Down
42 changes: 32 additions & 10 deletions lib/agent/providers/network/mac.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
// GPLv3 Licensed
//////////////////////////////////////////

var exec = require('child_process').exec,
var fs = require('fs'),
exec = require('child_process').exec,
common = require('../../common'),
airport_cmd = '/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport';

var mac_address_regex = /([0-9a-f]{2}[:-]){5}([0-9a-f]{2})/i;
Expand Down Expand Up @@ -45,9 +47,7 @@ exports.get_active_access_point_mac = function(callback) {
exports.get_active_access_point = function(callback) {
var cmd = airport_cmd + " -I";

exec(cmd, function(err, stdout){
if (err) return callback(err);

var process_active_ap = function(stdout) {
if (stdout.includes('AirPort: Off') || !stdout.includes('SSID'))
return callback(new Error('Wifi connection unavailable'));

Expand All @@ -67,20 +67,29 @@ exports.get_active_access_point = function(callback) {

var ap = {ssid: ssid, mac_address: mac_address, signal_strength: signal_strength, channel: channel, security: security}
callback(null, ap);
}

if (common.os_release >= "12.0") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice 👍

fs.readFile('/tmp/active_ap.txt', (err, data) => {
if (err) return callback(err);
process_active_ap(data.toString());
});

})
} else {
exec(cmd, function(err, stdout){
if (err) return callback(err);
process_active_ap(stdout);
})
}
}

/////////////////////////////////////////////////////////////////
// access points list fetcher and parser
/////////////////////////////////////////////////////////////////

exports.get_access_points_list = function(callback) {
current_attemp = 0;

get_ap_list_retry(null, function(err, stdout) {
if (err) return callback(err);

var process_ap_list = function(stdout) {
if (stdout.toString().match(/No networks/i))
return callback(new Error("No networks found."))

Expand All @@ -90,8 +99,21 @@ exports.get_access_points_list = function(callback) {
callback(null, list)
else
callback(new Error("No access points found."));
});
}

if (common.os_release >= "12.0") {
fs.readFile('/tmp/list_ap.txt', (err, data) => {
if (err) return callback(err);
process_ap_list(data.toString());
});
}
else {
current_attemp = 0;
get_ap_list_retry(null, function(err, stdout) {
if (err) return callback(err);
process_ap_list(stdout)
});
}
}

exports.parse_access_points_list = function(stdout) {
Expand Down