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

verify action IDs #519

Merged
merged 85 commits into from
Nov 12, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
e241673
Websockets on Node Client
Aug 13, 2021
4ba7c67
Merge branch 'master' into websockets-node
JohaoRosasRosillo Oct 4, 2021
99947f6
validate same id dont run
JohaoRosasRosillo Oct 8, 2021
b9b84d9
actions run once
JohaoRosasRosillo Oct 12, 2021
aef6950
stopped action with id
JohaoRosasRosillo Oct 13, 2021
21eed02
Add id to some actions
Oct 14, 2021
9dc15b3
restore websocket files
patriciojofre Oct 14, 2021
8cbe997
delete comments and console
JohaoRosasRosillo Oct 14, 2021
bcf2cb2
test verify unique id
JohaoRosasRosillo Oct 14, 2021
1860817
Fixing triggers specs
Oct 15, 2021
42900a3
Keep same actions behavior by name
Oct 15, 2021
f1c976e
Logretrieval with id
Oct 15, 2021
619e5b5
geofencing test
JohaoRosasRosillo Oct 15, 2021
6d4287a
Fix commands storage tests
Oct 18, 2021
a839945
Recover old db fixes
Oct 18, 2021
23a1685
test geofencing
JohaoRosasRosillo Oct 19, 2021
7ecc216
Test for commands recovery
Oct 19, 2021
d214fc6
save files in new database
JohaoRosasRosillo Oct 20, 2021
bc06925
delete row file in db when finish upload
JohaoRosasRosillo Oct 20, 2021
b8d208e
test diskencryption
JohaoRosasRosillo Oct 21, 2021
484e34d
lock test with id
JohaoRosasRosillo Oct 21, 2021
3ef849b
test logretrieval
JohaoRosasRosillo Oct 21, 2021
6657998
wipe test with id
JohaoRosasRosillo Oct 21, 2021
613ba37
test actions
JohaoRosasRosillo Oct 21, 2021
67d2390
report missed fix
JohaoRosasRosillo Oct 21, 2021
a2ed355
fix test check server
JohaoRosasRosillo Oct 22, 2021
308b33f
fix report cancel
JohaoRosasRosillo Oct 22, 2021
5b39bbe
comment storage old in commands
JohaoRosasRosillo Oct 22, 2021
4862ff6
test secure
JohaoRosasRosillo Oct 25, 2021
c40378b
account reverse
JohaoRosasRosillo Oct 25, 2021
ffc741e
Hardware changes specs fix
Oct 26, 2021
ee093a5
Fix security keys and harware specs
Oct 26, 2021
3516917
hostname test
JohaoRosasRosillo Oct 26, 2021
6846092
Merge branch 'unique-id' of https://github.com/prey/prey-node-client …
JohaoRosasRosillo Oct 26, 2021
312a17f
delete console.log command storage
JohaoRosasRosillo Oct 26, 2021
581f587
fix test
JohaoRosasRosillo Oct 26, 2021
4347cb1
npm shrinkwrap
JohaoRosasRosillo Oct 27, 2021
f4e97c3
package update
JohaoRosasRosillo Oct 27, 2021
83b2bdb
Fix specs for geofencing and exceptions
Oct 27, 2021
16de8bc
Geofencing fully tested
Oct 28, 2021
8a623aa
Fix hostname storage logic
Oct 29, 2021
e5bdcd2
Remove old keys storage logic
Oct 29, 2021
91ad0ad
Fix specs for actions
Nov 2, 2021
08fd1fb
delete console.log
JohaoRosasRosillo Nov 2, 2021
21dbcbb
delete comments
JohaoRosasRosillo Nov 2, 2021
e0dd19f
completer console
JohaoRosasRosillo Nov 2, 2021
60a9d48
console log necessary
JohaoRosasRosillo Nov 3, 2021
eb27e16
Fix update storage and some triggers specs
Nov 3, 2021
5beccf0
console restored
JohaoRosasRosillo Nov 3, 2021
a614836
restore console.log
JohaoRosasRosillo Nov 3, 2021
e360c40
Merge master
Nov 3, 2021
fa0b091
Reviewing package specs
Nov 4, 2021
57e00d7
test updating spec fix
JohaoRosasRosillo Nov 4, 2021
42ef45f
Fix package tests and modify logic for commands storage deletion
Nov 8, 2021
0385ef8
fix report recovered device
JohaoRosasRosillo Nov 8, 2021
e1180d4
commands fix
JohaoRosasRosillo Nov 8, 2021
1a046c3
commands fix report target
JohaoRosasRosillo Nov 8, 2021
0a94773
Fix geofencing and storage recover
Nov 8, 2021
e6cdb6b
Fix storage for triggers
Nov 8, 2021
2fb4760
Add id to geofencing and triggers sync function
Nov 9, 2021
8025d4a
Fix action tests
Nov 9, 2021
adec480
Fixes on hardware, storage, etc
Nov 10, 2021
8d81ed4
Fileretrieval fixes and storage rename
Nov 10, 2021
87e3887
delete console test diskencryption
JohaoRosasRosillo Nov 10, 2021
4c56116
hostname fix storage
JohaoRosasRosillo Nov 10, 2021
ae3b734
File retrieval fixes, triggers and long polling tests fix
Nov 11, 2021
78f05ea
Little fixes
Nov 11, 2021
fb9bf68
Update lib/agent/actions.js
JohaoRosasRosillo Nov 11, 2021
8c49c2d
Update lib/agent/actions.js
JohaoRosasRosillo Nov 11, 2021
b645fd8
Update lib/agent/actions.js
JohaoRosasRosillo Nov 11, 2021
9d46d35
Update test/lib/agent/updating_spec.js
JohaoRosasRosillo Nov 11, 2021
b3eda51
Update lib/agent/actions/lock/index.js
JohaoRosasRosillo Nov 11, 2021
478f145
Update lib/agent/actions/lock/index.js
JohaoRosasRosillo Nov 11, 2021
5f58852
Update lib/agent/actions/logretrieval/index.js
JohaoRosasRosillo Nov 11, 2021
bbae64a
Update lib/agent/actions/triggers/index.js
JohaoRosasRosillo Nov 11, 2021
a80b98e
Update lib/agent/commands.js
JohaoRosasRosillo Nov 11, 2021
82bf909
Remove comments
Nov 11, 2021
335aa30
Merge branch 'unique-id' of https://github.com/prey/prey-node-client …
Nov 11, 2021
3dd8211
Update test/lib/agent/actions.js
JohaoRosasRosillo Nov 11, 2021
93bbce7
Update test/lib/agent/actions/triggers.js
JohaoRosasRosillo Nov 11, 2021
18cc28e
Update test/lib/agent/actions/triggers.js
JohaoRosasRosillo Nov 11, 2021
4672afc
test comment for updating_spec and triggers
JohaoRosasRosillo Nov 11, 2021
d9183fb
show error message in commands perform
JohaoRosasRosillo Nov 11, 2021
a5e5fc7
show error in sync triggers
JohaoRosasRosillo Nov 11, 2021
06608aa
Fix exception errors
Nov 11, 2021
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
136 changes: 116 additions & 20 deletions lib/agent/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ var join = require('path').join,
hooks = require('./hooks');

var actions = {},
running = {};
running = {},
running_trigger = {};

var actions_path = __dirname + '/actions';

Expand All @@ -17,15 +18,41 @@ var load_action = function(type, name) {
}

// type can be 'action' or 'trigger'
var action_running = function(type, action, name, opts, emitter) {
logger.info('Running: ' + name)
var action_running = function(type, id, action, name, opts, emitter) {
logger.info('Running: ' + name + ' ' + id);
javo marked this conversation as resolved.
Show resolved Hide resolved
running[id] = {name: name, action: action};

running[name] = action;

emitter.once('end', function(id, err, out) {
if (err) hooks.trigger('error', err);

logger.info('Stopped: ' + name);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
logger.info('Stopped: ' + name);
logger.info(`Stopped: ${name}`);

action_stopped(id);

setTimeout(function() {
hooks.trigger(type, 'stopped', id, name, opts, err, out);
}, 1000);

if (action.events)
emitter.removeAllListeners();
})

if (!action.events) return;
watch_action_events(action.events, emitter);
}

var trigger_running = function(type, action, name, opts, emitter) {
logger.info('Running: ' + name);
running_trigger[name] = {name: name, action: action};

running_trigger[name] = action;

emitter.once('end', function(err, out) {
if (err) hooks.trigger('error', err);

logger.info('Stopped: ' + name);
action_stopped(name);
trigger_stopped(name);

setTimeout(function() {
hooks.trigger(type, 'stopped', name, opts, err, out);
Expand All @@ -39,6 +66,7 @@ var action_running = function(type, action, name, opts, emitter) {
watch_action_events(action.events, emitter);
}

// revisar q hace esta funcion!
Copy link
Contributor

Choose a reason for hiding this comment

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

Es necesario que quede ese comentario?

var watch_action_events = function(events, emitter) {
events.forEach(function(event_name) {
emitter.on(event_name, function(data){
Expand All @@ -48,25 +76,40 @@ var watch_action_events = function(events, emitter) {
})
}

var action_stopped = function(name) {
delete running[name];
var action_stopped = function(id) {
console.log("DELETE ID!!", id)
delete running[id];
}

var start = function(type, name, opts, cb){
if (running[name]) {
var err = new Error('Already running: ' + name);
var trigger_stopped = function(name) {
delete running_trigger[name];
}

var start = function(type, id, name, opts, cb){

console.log("START!!", type, id, name, opts)

// mismo id.. error!
if (running[id]) {
// var err = new Error('Already running: ' + name);
JohaoRosasRosillo marked this conversation as resolved.
Show resolved Hide resolved
var err = new Error(`Already running: ${running[id].name} with id: ${id}`);
hooks.emit('error', err);

// cb necesario???
return cb && cb(err);
}

logger.info('Starting ' + type + ': '+ name);
console.log('Starting ' + type + ': '+ name);
var action = load_action(type, name);
if (!action) return; // load_action will emit trigger

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

action.start(opts, function(err, emitter) {
// ver cuando el type es un trigger

action.start(id, opts, function(err, emitter) {
cb && cb(err);

if (err) {
Expand All @@ -81,10 +124,10 @@ var start = function(type, name, opts, cb){
if (!opts) opts = {};

if (type == 'action')
hooks.trigger(type, 'started', name, opts);
hooks.trigger(type, 'started', id, name, opts);

if (emitter) {
action_running(type, action, name, opts, emitter);
action_running(type, id, action, name, opts, emitter);
} else {

// no emitter was returned, so we have no way of knowing when
Expand All @@ -93,42 +136,95 @@ var start = function(type, name, opts, cb){
// trigger this event after 10 seconds.

setTimeout(function() {
hooks.trigger(type, 'stopped', name, opts);
hooks.trigger(type, 'stopped', id, name, opts);
}, 10000);

}
})

// IMPLEMENTAR DETENER UNA ACCION ACTUAL DEL MISMO NOMBRE QUE SE ESTË EJECUTANDO
// O IGNORAR COMO LO HACE ACTUALMENTE (?)

};

actions.start = function(name, opts) {
start('action', name, opts);
var start_trigger = function(type, name, opts, cb){
if (running_trigger[name]) {
var err = new Error('Already running: ' + name);
hooks.emit('error', err);

// cb necesario???
return cb && cb(err);
}

logger.info('Starting ' + type + ': '+ name);
var trigger = load_action(type, name);

trigger.start(opts, function(err, emitter) {
cb && cb(err);

if (err) {
logger.info('Failed: ' + name + ' -> ' + err.message)
return hooks.trigger('error', err);
}

if (!opts) opts = {};

if (emitter) {
trigger_running(type, trigger, name, opts, emitter);
} else {

// no emitter was returned, so we have no way of knowing when
// this action will stop. given that the command watcher needs to know
// when an action finished in order to update the list, we'll manually
// trigger this event after 10 seconds.

setTimeout(function() {
hooks.trigger('trigger', 'stopped', name, opts);
}, 10000);

}
});
}

actions.start = function(id, name, opts) {
start('action', id, name, opts);
}

actions.start_trigger = function(name, opts, cb) {
start('trigger', name, opts, cb);
start_trigger('trigger', name, opts, cb);
}

actions.stop = function(name, opts) {
logger.info('Stopping: ' + name);
var action = running[name];
// agregar lo del opts para el response
JohaoRosasRosillo marked this conversation as resolved.
Show resolved Hide resolved
actions.stop = function(id) {
console.log("STOP ID!!", id, running)

if (!running[id]) {
hooks.trigger('action', 'stopped', id);
}

var action = running[id].action;

if (!action) {
logger.warn('Action not running!');
hooks.trigger('action', 'stopped', name, opts);
hooks.trigger('action', 'stopped', id); // name por id
} else if (!action.stop) {
logger.warn('Action not stoppable!');
} else {
logger.info(`Stopping: ${running[id].name}, with id: ${id}`);
action.stop();
}
}

// revisar q esto siga funcionando!
actions.stop_all = function() {
console.log("STOP ALL!!!")
for (var name in running)
this.stop(name);
}

// esta tb
actions.running = function() {
console.log("RUNNING")
var list = [];
for (var key in running) {
if (running[key].type == 'action') {
Expand Down
14 changes: 8 additions & 6 deletions lib/agent/actions/alarm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var child,
emitter,
raise_interval;

exports.start = function(options, cb) {
exports.start = function(id, options, cb) {

var error,
self = this,
Expand All @@ -30,10 +30,10 @@ exports.start = function(options, cb) {
file = type + '.mp3',
loops = options.loops ? parseInt(options.loops) : 1;

var done = function(err) {
var done = function(id, err) {
clearInterval(raise_interval);
if (returned++) returned;
if (emitter) emitter.emit('end', err);
if (emitter) emitter.emit('end', id, err);
emitter = null;
}

Expand All @@ -45,15 +45,17 @@ exports.start = function(options, cb) {
loops--;

system.spawn_as_logged_user(commands.play, [ file ], function(err, alarm) {
if (err) return done(err);
if (err) return done(id, err);

alarm.on('error', done);
alarm.done(id, err)('error', (err) => {

});

alarm.once('exit', function(code) {
child = null;

if (loops === 0)
return done();
return done(id);

play_queue();
})
Expand Down
4 changes: 2 additions & 2 deletions lib/agent/actions/alert/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var child,
binary,
user_input_str = 'User input: ';

exports.start = function(opts, cb) {
exports.start = function(id, opts, cb) {
var opts = opts || {},
message = opts.message || opts.alert_message,
title = opts.title,
Expand Down Expand Up @@ -68,7 +68,7 @@ exports.start = function(opts, cb) {
if (returned++) return;

if (emitter)
emitter.emit('end', err, reply);
emitter.emit('end', id, err, reply);

emitter = null;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/agent/actions/diskencryption/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ var process_options = (options) => {
return opts;
}

exports.start = function(opts, cb) {
exports.start = function(id, opts, cb) {
var os_name = os.platform().replace('darwin', 'mac').replace('win32', 'windows');

if (os_name != 'windows')
Expand Down Expand Up @@ -85,7 +85,7 @@ exports.start = function(opts, cb) {
commands.perform({command: 'get', target: 'encryption_keys'})

output = {}
if (!out) return emitter.emit('end');
if (!out) return emitter.emit('end', id);

out.forEach(disk => {
var data = disk.disk.slice(0, -1);
Expand All @@ -99,7 +99,7 @@ exports.start = function(opts, cb) {
}

if (!emitter) return;
return emitter.emit('end', err, output);
return emitter.emit('end', id, err, output);
}

emitter = new Emitter;
Expand Down
4 changes: 2 additions & 2 deletions lib/agent/actions/fileretrieval/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ exports.check_pending_files = function() {
files.run_stored(host);
}

exports.start = function(options, cb) {
exports.start = function(id, options, cb) {

var url = UPLOAD_SERVER + '?uploadID=' + options.file_id;
// Make a call to get the last byte processed by the upload server
Expand Down Expand Up @@ -129,7 +129,7 @@ exports.start = function(options, cb) {
em = em || new Emitter();

if (cb) cb(null, em);
em.emit('end');
em.emit('end', id);
}

exports.stop = function() {
Expand Down
Loading