Skip to content

Commit dade23c

Browse files
author
Claudio
committed
Merge branch 'develop' into 'master'
fix: Refactor ack.js for improved readability and robustness, and update... See merge request prey/js/prey-node-client!1197
2 parents 391267e + 61f284c commit dade23c

File tree

45 files changed

+654
-694
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+654
-694
lines changed

CHANGELOG.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
# Change Log
22

3-
## [v1.13.10](https://github.com/prey/prey-node-client/tree/v1.13.10) (2024-2-3)
3+
## [v1.13.11](https://github.com/prey/prey-node-client/tree/v1.13.11) (2025-2-24)
4+
[Full Changelog](https://github.com/prey/prey-node-client/compare/v1.13.10..v1.13.11)
5+
6+
- Fix: Remove unused libraries to fix vulnerabilities. ([Beregcamlost](https://github.com/beregcamlost)) ([SoraKenji](https://github.com/SoraKenji))
7+
- Fix: Fixes error on ack_id undefined on websocket comunication. ([Beregcamlost](https://github.com/beregcamlost)) ([SoraKenji](https://github.com/SoraKenji))
8+
- Fix: Added valid signatures to files with expired signatures for Windows binaries. ([Beregcamlost](https://github.com/beregcamlost)) ([SoraKenji](https://github.com/SoraKenji))
9+
- Fix: Fixes an issue where Prey Lock would start when the user was locked out on Windows. This causes a problem when writing out the password to log in again.. ([Beregcamlost](https://github.com/beregcamlost)) ([SoraKenji](https://github.com/SoraKenji))
10+
- Feat: New Fenix version. It fixes an issue when trying to read device key from current installation. It also improves issue when deleting Prey service. ([Beregcamlost](https://github.com/beregcamlost)) ([SoraKenji](https://github.com/SoraKenji))
11+
12+
## [v1.13.10](https://github.com/prey/prey-node-client/tree/v1.13.10) (2025-2-3)
413
[Full Changelog](https://github.com/prey/prey-node-client/compare/v1.13.9..v1.13.10)
514

615
- Fix: Improve the updater logic for the first-time update. ([Beregcamlost](https://github.com/beregcamlost)) ([SoraKenji](https://github.com/SoraKenji))
716
- Feat: Replace all WMIC instances in the project; we are now using native WMI through PowerShell. ([Beregcamlost](https://github.com/beregcamlost)) ([SoraKenji](https://github.com/SoraKenji))
817

9-
## [v1.13.9](https://github.com/prey/prey-node-client/tree/v1.13.9) (2024-1-20)
18+
## [v1.13.9](https://github.com/prey/prey-node-client/tree/v1.13.9) (2025-1-20)
1019
[Full Changelog](https://github.com/prey/prey-node-client/compare/v1.13.8..v1.13.9)
1120

1221
- Feat: Remove wmic from file retrieval functionality. ([Beregcamlost](https://github.com/beregcamlost)) ([SoraKenji](https://github.com/SoraKenji))

bin/fenix.exe

0 Bytes
Binary file not shown.

bin/updater.exe

0 Bytes
Binary file not shown.

lib/agent/ack.js

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,17 @@
11
const ackType = 'ack';
22

3-
const existKeyAckInJson = (json) => {
4-
// eslint-disable-next-line no-prototype-builtins
5-
if (json.hasOwnProperty('ack_id')) {
6-
return true;
7-
}
8-
return false;
9-
};
10-
const existKeyIdInJson = (json) => {
11-
// eslint-disable-next-line no-prototype-builtins
12-
if (json.hasOwnProperty('id')) {
13-
return true;
14-
}
15-
return false;
16-
};
3+
const existKeyAckInJson = (json) => Object.hasOwn(json, 'ack_id');
174

185
exports.processAck = (json, cb) => {
19-
if (!existKeyAckInJson(json)) {
20-
return cb(new Error('there is no key ack_id in the json'));
21-
}
6+
if (!existKeyAckInJson(json)) return cb(new Error('there is no key ack_id in the json'));
7+
8+
const { ack_id: ackId, id = '' } = json;
9+
2210
return cb(null, {
23-
ack_id: json.ack_id,
11+
ack_id: ackId,
2412
type: ackType,
25-
id: existKeyIdInJson(json) ? json.id : '',
13+
id,
2614
});
2715
};
2816

2917
exports.existKeyAckInJson = existKeyAckInJson;
30-
exports.existKeyIdInJson = existKeyIdInJson;

lib/agent/actions.js

Lines changed: 44 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,38 @@
1+
/* eslint-disable import/no-dynamic-require */
2+
/* eslint-disable consistent-return */
13
const { join } = require('path');
24
const logger = require('./common').logger.prefix('actions');
35
const hooks = require('./hooks');
46

57
const actions = {};
68
const running = {};
79

8-
const load_action = (type, name) => {
10+
const loadAction = (type, name) => {
911
const file = join(__dirname, `${type}s`, name);
1012
try {
13+
// eslint-disable-next-line global-require
1114
return require(file);
1215
} catch (e) {
1316
hooks.trigger('error', e);
1417
}
1518
};
1619

17-
const watch_action_events = (events, emitter) => {
20+
const watchActionEvents = (events, emitter) => {
1821
events.forEach((eventName) => {
1922
emitter.on(eventName, (data) => {
2023
hooks.trigger('event', eventName, data);
2124
hooks.trigger(eventName, data);
2225
});
2326
});
2427
};
25-
// type can be 'action' or 'trigger'
26-
const action_running = (type, id, action, name, opts, emitter) => {
28+
29+
const actionStopped = (id) => {
30+
delete running[id];
31+
};
32+
33+
const actionRunning = (type, id, action, name, opts, emitter) => {
2734
logger.info(`Running: ${name} ${id}`);
35+
if (!action || !name) logger.info(`Error on actionRunning: ${name} -> ${action}`);
2836
running[id] = { name, action };
2937

3038
emitter.once('end', (idEmitter, err, out) => {
@@ -33,8 +41,8 @@ const action_running = (type, id, action, name, opts, emitter) => {
3341
logger.info(`Error: ${JSON.stringify(err)}`);
3442
}
3543

36-
logger.info(`Stopped: ${name}`);
37-
action_stopped(idEmitter);
44+
logger.info(`Stopped ${type}: ${name} ${id}`);
45+
actionStopped(idEmitter);
3846

3947
setTimeout(() => {
4048
hooks.trigger(type, 'stopped', idEmitter, name, opts, err, out);
@@ -44,39 +52,34 @@ const action_running = (type, id, action, name, opts, emitter) => {
4452
});
4553

4654
if (!action.events) return;
47-
watch_action_events(action.events, emitter);
48-
};
49-
50-
const action_stopped = (id) => {
51-
delete running[id];
55+
watchActionEvents(action.events, emitter);
5256
};
5357

54-
const start = function (type, id, name, opts, cb) {
58+
const start = (type, id, name, opts, cb) => {
5559
// Action with same id is not executed
5660
if (running[id]) {
5761
const err = new Error(`Already running: ${running[id].name} with id: ${id}`);
5862
hooks.emit('error', err);
59-
60-
return cb && cb(err);
63+
return cb?.(err);
6164
}
6265

6366
if (Object.values(running).filter((x) => x.name === name).length > 0) {
64-
const err = new Error(`Already running: ${name}`);
67+
const err = new Error(`Already running: ${name} ${id}`);
6568
hooks.emit('error', err);
66-
return cb && cb(err);
69+
return cb?.(err);
6770
}
6871

69-
logger.info(`Starting ${type}: ${name}`);
72+
logger.info(`Starting ${type}: ${name} ${id}`);
7073

71-
const action = load_action(type, name);
72-
if (!action) return; // load_action will emit trigger
74+
const action = loadAction(type, name);
75+
if (!action) return;
7376

7477
action.type = type;
7578
action.options = typeof opts === 'function' ? {} : opts;
7679

7780
// eslint-disable-next-line consistent-return
7881
action.start(id, opts, (err, emitter) => {
79-
cb && cb(err);
82+
if (cb) cb(err);
8083

8184
if (err) {
8285
logger.info(`Failed: ${name} -> ${err.message}`);
@@ -95,7 +98,7 @@ const start = function (type, id, name, opts, cb) {
9598
}, 500);
9699
}
97100
if (emitter) {
98-
action_running(type, id, action, name, options, emitter);
101+
actionRunning(type, id, action, name, options, emitter);
99102
} else {
100103
// no emitter was returned, so we have no way of knowing when
101104
// this action will stop. given that the command watcher needs to know
@@ -113,31 +116,36 @@ actions.start = (id, name, opts, cb) => {
113116
start('action', id, name, opts, cb);
114117
};
115118

116-
// TODO: agregar lo del opts para el response
117119
actions.stop = (id, name, opts) => {
118-
if (!running[id]) {
120+
if (!Object.hasOwn(running, id)) {
119121
hooks.trigger('action', 'stopped', id, name, opts);
120122
return;
121123
}
122124

123125
const { action } = running[id];
124126

125-
if (!action) {
126-
logger.warn('Action not running!');
127-
hooks.trigger('action', 'stopped', id, name, opts);
128-
} else if (!action.stop) {
129-
logger.warn('Action not stoppable!');
130-
} else {
131-
logger.info(`Stopping: ${running[id].name}, with id: ${id}`);
132-
action.stop();
133-
action_stopped(id);
127+
try {
128+
if (!action) {
129+
logger.info(`Action ${running[id].name}, with id: ${id} not running!`);
130+
hooks.trigger('action', 'stopped', id, name, opts);
131+
} else if (!action.stop) {
132+
logger.info(`Action ${running[id].name}, with id: ${id} not stoppable!`);
133+
} else {
134+
logger.info(`Stopping: ${running[id].name}, with id: ${id}`);
135+
action.stop();
136+
actionStopped(id);
137+
}
138+
} catch (err) {
139+
logger.error(`Error stopping action ${id}: ${err}`);
134140
}
135141
};
136142

137-
actions.stop_all = function () {
138-
for (const id in running) {
139-
actions.stop(id);
140-
};
143+
actions.stop_all = () => {
144+
Object.keys(running).forEach((id) => {
145+
if (Object.hasOwn(running, id)) {
146+
actions.stop(id);
147+
}
148+
});
141149
};
142150

143151
module.exports = actions;
200 Bytes
Binary file not shown.
200 Bytes
Binary file not shown.
200 Bytes
Binary file not shown.
200 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)