Skip to content

Commit

Permalink
Merge branch 'develop' into 'master'
Browse files Browse the repository at this point in the history
Develop

See merge request prey/js/prey-node-client!1135
  • Loading branch information
Claudio committed Dec 19, 2024
2 parents 38b144a + 4026ab5 commit d0532b8
Show file tree
Hide file tree
Showing 34 changed files with 837 additions and 460 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
# Change Log

## [v1.13.8](https://github.com/prey/prey-node-client/tree/v1.13.8) (2024-12-19)
[Full Changelog](https://github.com/prey/prey-node-client/compare/v1.13.7..v1.13.8)

- Fix: Rollback at restore.js file. It was causing an error when there is a backup database on temporal folder. ([Beregcamlost](https://github.com/beregcamlost)) ([SoraKenji](https://github.com/SoraKenji))

## [v1.13.7](https://github.com/prey/prey-node-client/tree/v1.13.7) (2024-12-19)
[Full Changelog](https://github.com/prey/prey-node-client/compare/v1.13.6..v1.13.7)

- Feat: Add new WinSVC version v2.0.21. It includes a way to change wifi permission on Windows. ([Beregcamlost](https://github.com/beregcamlost)) ([SoraKenji](https://github.com/SoraKenji))

- Feat: Add new MacSVC (prey-user binary) version v1.0.7. It resolves an error when a new version of prey get downloaded and doesn't get configurated correctly, leaving the software unable to continue working. ([Beregcamlost](https://github.com/beregcamlost)) ([SoraKenji](https://github.com/SoraKenji))

- Fix: Fix an error related to network reconnections when getting device information leaving it unable to keep processing that data. ([Beregcamlost](https://github.com/beregcamlost)) ([SoraKenji](https://github.com/SoraKenji))

- Fix: Fix an error when replacing older MacSVC (prey-user binary) version with new one on MacOS bellow version 13.0. ([Beregcamlost](https://github.com/beregcamlost)) ([SoraKenji](https://github.com/SoraKenji))

- Chore: Remove code in software related to geofencing, since now that data is processed by backend. ([Javo](https://github.com/javo)) ([Beregcamlost](https://github.com/beregcamlost)) ([SoraKenji](https://github.com/SoraKenji))


## [v1.13.6](https://github.com/prey/prey-node-client/tree/v1.13.6) (2024-11-22)
[Full Changelog](https://github.com/prey/prey-node-client/compare/v1.13.5..v1.13.6)

Expand Down
Binary file modified bin/fenix.exe
Binary file not shown.
Binary file modified bin/prey-user
Binary file not shown.
Binary file modified bin/updater.exe
Binary file not shown.
8 changes: 5 additions & 3 deletions lib/agent/ack.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
const storage = require('./utils/storage');
const ackType = 'ack';

const existKeyAckInJson = (json) => {
//eslint-disable-next-line no-prototype-builtins
// eslint-disable-next-line no-prototype-builtins
if (json.hasOwnProperty('ack_id')) {
return true;
}
return false;
};
const existKeyIdInJson = (json) => {
//eslint-disable-next-line no-prototype-builtins
// eslint-disable-next-line no-prototype-builtins
if (json.hasOwnProperty('id')) {
return true;
}
Expand All @@ -26,3 +25,6 @@ exports.processAck = (json, cb) => {
id: existKeyIdInJson(json) ? json.id : '',
});
};

exports.existKeyAckInJson = existKeyAckInJson;
exports.existKeyIdInJson = existKeyIdInJson;
129 changes: 0 additions & 129 deletions lib/agent/actions/geofencing/index.js

This file was deleted.

29 changes: 4 additions & 25 deletions lib/agent/actions/lock/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,7 @@ var lock_binary = lock_binary_path(),
var child,
timer,
emitter,
stopped,
kill_apps;

function kill_running_apps(cb) {
if (os_name != 'mac') return cb();
var cmd = `ps aux |awk '{for(i=11;i<=NF;i++){printf "%s ", $i}; print $2}' | grep "^/Applications" | awk '{print $NF}'`

exec(cmd, (err, out) => {
var apps = out.split('\n').slice(0,-1);
apps = apps.join(" ")

var kill_cmd = 'kill -9 ' + apps + ';killall Finder';
run_as_user(kill_cmd, [], (err) =>{
return cb();
})
})
}
stopped;

function lock_binary_path() {
var binary_name = 'prey-lock';
Expand All @@ -69,13 +53,11 @@ var md5_digest = function(str){
};

function before(cb) {
if (!is_win) return cb();

// as priviledged user, lock all escape mechanisms
// we cannot do this as logged user because we lose privileges.
if (is_win) return exec(lock_binary + ' --block', cb);

if (is_linux || (is_mac && !kill_apps)) return cb();

kill_running_apps(cb);
exec(lock_binary + ' --block', cb);
}

function after(cb) {
Expand All @@ -93,9 +75,6 @@ function start(id, opts, cb) {
password = opts.password || opts.unlock_pass || default_pass,
message = opts.lock_message || "";

kill_apps = false;
kill_apps = opts.close_apps;

if (!password || password.toString().trim() === '')
return cb(new Error('No unlock password given!'))

Expand Down
50 changes: 48 additions & 2 deletions lib/agent/actions/request_permission/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { EventEmitter } = require('events');
const path = require('path');
const socket = require('../../socket');
const geoIndex = require('../../providers/geo');
const strategies = require('../../providers/geo/strategies');
Expand All @@ -7,6 +8,13 @@ const permissionFile = require('../../../utils/permissionfile');
const osName = process.platform.replace('win32', 'windows').replace('darwin', 'mac');
const { nameArray } = require('../../socket/messages');

const { join } = path;
const system = require('../../../system');

const nodeBin = join(system.paths.current, 'bin', 'node');

const actionLocationWin = 'location-permission';

let emitter;

const parseResponse = (data, cb) => {
Expand All @@ -23,6 +31,41 @@ const done = (id, err) => {
if (!emitter) emitter = new EventEmitter();
emitter.emit('end', id, err);
};

// eslint-disable-next-line consistent-return
const requestAllowPermissionWin = (cb) => {
if (osName.localeCompare('windows') !== 0) return cb(new Error('Action only allowed on windows'));
const data = {
dirs: ['allow'],
};
system.spawn_as_admin_user(nodeBin, data, (
errorRequestPermissionWin,
permissionWindowsLocation,
// eslint-disable-next-line consistent-return
) => {
if (errorRequestPermissionWin) {
return done(new Error(errorRequestPermissionWin));
}
if (typeof permissionWindowsLocation !== 'function') return done(new Error('Error is not available'));
// eslint-disable-next-line consistent-return
permissionWindowsLocation(
actionLocationWin,
data,
// eslint-disable-next-line consistent-return
(errPermissionWindowsLocation, outPutpermissionWindowsLocation) => {
if (errPermissionWindowsLocation || (outPutpermissionWindowsLocation
&& (!Object.prototype.hasOwnProperty.call(outPutpermissionWindowsLocation, 'code')
|| outPutpermissionWindowsLocation.code !== 0))) {
const errorOutPut = new Error('Error on osQuery');
return done(errorOutPut);
}
geoIndex.getLocationRequest(() => {});
done();
},
);
});
};

/**
* Requests native permission on MacOS.
*
Expand All @@ -38,8 +81,8 @@ const requestNativePermission = (cb) => {
if (permissionNative.localeCompare('false') !== 0 && permissionNative.localeCompare('true') !== 0) {
try {
strategies.askLocationNativePermission((err, data) => {
parseResponse(data, (err) => {
if (!err) geoIndex.getLocationRequest(()=>{});
parseResponse(data, (errParse) => {
if (!errParse) geoIndex.getLocationRequest(() => {});
});
cb(err);
});
Expand Down Expand Up @@ -68,6 +111,9 @@ exports.start = (id, opts, cb) => {
case 'native_location':
requestNativePermission((err) => done(id, err));
break;
case 'wifi_location':
requestAllowPermissionWin((err) => done(id, err));
break;
default:
done(id, new Error('Invalid permission name'));
}
Expand Down
2 changes: 0 additions & 2 deletions lib/agent/actions/triggers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ const websocket = require('../../control-panel/websockets');
const eventsList = [
'connected',
'disconnected',
'geofencing_in',
'geofencing_out',
'new_location',
'mac_address_changed',
'ssid_changed',
Expand Down
4 changes: 3 additions & 1 deletion lib/agent/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,9 @@ var store = function (type, id, name, opts, cb) {
logger.debug(`Storing command in DB: ${[type, name].join('-')}`);

delete_same_target(id, name, () => {
if (name == 'geofencing' || name == 'triggers' || name == 'fileretrieval') return cb && cb();
if (name == 'triggers' || name == 'fileretrieval')
return cb && cb();

storage.do(
'set',
{
Expand Down
14 changes: 3 additions & 11 deletions lib/agent/control-panel/api/devices.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const keys = require('./keys');
const errors = require('./errors');
const request = require('./request');

const set = (key) => {
exports.set = (key) => {
if (!key) throw (new Error('No key!'));
keys.set({ device: key });
return key;
Expand All @@ -19,14 +19,13 @@ exports.link = (data, cb) => {

const { body } = resp;

if (body && body.key) {
cb(null, set(body.key));
if (body?.key) {
cb(null, exports.set(body.key));
} else if (resp.statusCode == 401) {
cb(errors.get('INVALID_CREDENTIALS'));
} else if (resp.statusCode == 302 || resp.statusCode == 403) {
cb(errors.get('NO_AVAILABLE_SLOTS'));
} else if (resp.statusCode == 422 || body.errors) {
const obj = body.errors || body;
cb(errors.unprocessable(body));
} else {
cb(errors.unknown(resp));
Expand Down Expand Up @@ -116,13 +115,6 @@ exports.get.status = (cb) => {
request.get(`/devices/${keys.get().device}/status.json`, {}, cb);
};

exports.get.geofences = (cb) => {
const device_key = keys.get().device;
if (!device_key) return cb(errors.get('NO_DEVICE_KEY'));

request.get(`/devices/${device_key}/geofencing.json`, {}, cb);
};

exports.get.triggers = (cb) => {
const device_key = keys.get().device;
if (!device_key) return cb(errors.get('NO_DEVICE_KEY'));
Expand Down
2 changes: 1 addition & 1 deletion lib/agent/control-panel/api/request.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const needle = require('needle');
const https = require('https');
const keys = require('./keys');
const logger = require('./logger');
const common = require('../../../common');
const config = require('../../../utils/configfile');
const logger = common.logger.prefix('api');

const defaults = {
client: needle,
Expand Down
Loading

0 comments on commit d0532b8

Please sign in to comment.