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

Fixs underscore module not found #583

Merged
merged 1 commit into from
Apr 18, 2022
Merged
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
162 changes: 83 additions & 79 deletions lib/agent/providers/hardware/index.js
Original file line number Diff line number Diff line change
@@ -1,133 +1,137 @@
//////////////////////////////////////////
/* eslint-disable linebreak-style */
/// ///////////////////////////////////////
// Prey JS Hardware Module
// (c) 2011 - Fork Ltd.
// By Tomas Pollak - http://forkhq.com
// GPLv3 Licensed
//////////////////////////////////////////

"use strict";

var _ = require('underscore'),
os = require('os'),
async = require('async'),
network = require('network'),
hooks = require('./../../hooks'),
common = require('./../../common'),
logger = common.logger.prefix('hardware'),
os_name = process.platform.replace('darwin', 'mac').replace('win32', 'windows'),
common = require('./../../../common'),
logger = common.logger.prefix('hardware'),
storage = require('./../../utils/storage'),
os_functions = require('./' + os_name),
exp = module.exports;

exp.get_processor_info = function(callback) {
var cpus = os.cpus();
var cpu_info = {
/// ///////////////////////////////////////

const os = require('os');
const async = require('async');
const network = require('network');
const hooks = require('../../hooks');
const common = require('../../common');

const logger = common.logger.prefix('hardware');
const osName = process.platform.replace('darwin', 'mac').replace('win32', 'windows');
const storage = require('../../utils/storage');

// eslint-disable-next-line import/no-dynamic-require
const osFunctions = require(`./${osName}`);
const exp = module.exports;

exp.get_processor_info = (callback) => {
const cpus = os.cpus();
const cpuInfo = {
model: cpus[0].model.trim(),
speed: cpus[0].speed,
cores: cpus.length
cores: cpus.length,
};
callback(null, cpu_info);
callback(null, cpuInfo);
};

/**
* There are no parameters to create a memoized hash key on so supply "key" as default in
* optional hasher function.
**/
exp.get_firmware_info = async.memoize(function(callback){
os_functions.get_firmware_info(function(err, data) {
* */
exp.get_firmware_info = async.memoize((callback) => {
// eslint-disable-next-line consistent-return
osFunctions.get_firmware_info((err, data) => {
if (err) return callback(err);
// eslint-disable-next-line prefer-const
let dataFirmwareInfo = data;
if (data.device_type) dataFirmwareInfo.device_type = data.device_type.replace('Notebook', 'Laptop');

if (data.device_type)
data.device_type = data.device_type.replace('Notebook', 'Laptop');

callback(null, data);
callback(null, dataFirmwareInfo);
});
});

exp.get_storage_devices_list = function(callback){
callback(new Error('TODO!'))
};


exp.get_storage_devices_list = (callback) => callback(new Error('TODO!'));
/**
* Returns full list of network interfaces, including MAC and broadcast address
**/
* */

exp.get_network_interfaces_list = network.get_interfaces_list;
exp.get_tpm_module = os_functions.get_tpm_module;
exp.get_os_edition = os_functions.get_os_edition;
exp.get_winsvc_version = os_functions.get_winsvc_version;
exp.get_rp_module = os_functions.get_recovery_partition_status;
exp.get_tpm_module = osFunctions.get_tpm_module;
exp.get_os_edition = osFunctions.get_os_edition;
exp.get_winsvc_version = osFunctions.get_winsvc_version;
exp.get_rp_module = osFunctions.get_recovery_partition_status;

// even though these functions look like they belong in the network provider,
// we put them here because MAC addresses are part of the network interfaces,
// and are not subject to change (even though they can be spoofed)

exp.get_first_mac_address = function(callback) {

network.get_interfaces_list(function(err, list) {
if (err)
callback(err)
else if (list && list[0] && list[0].mac_address)
callback(null, list[0].mac_address);
else
callback(new Error("Couldn't find any valid MAC addresses!"));
exp.get_first_mac_address = (callback) => {
network.get_interfaces_list((err, list) => {
if (err) callback(err);
else if (list && list[0] && list[0].mac_address) callback(null, list[0].mac_address);
callback(new Error('Couldn\'t find any valid MAC addresses!'));
});

};

exp.get_ram_module_list = os_functions.get_ram_module_list;
exp.get_ram_module_list = osFunctions.get_ram_module_list;

exp.track_hardware_changes = (data) => {
// eslint-disable-next-line no-param-reassign
if (data.tpm_module) delete data.tpm_module;
// eslint-disable-next-line no-param-reassign
if (data.os_edition) delete data.os_edition;
// eslint-disable-next-line no-param-reassign
if (data.winsvc_version) delete data.winsvc_version;
// eslint-disable-next-line no-param-reassign
if (data.rp_module) delete data.rp_module;

var diff_count = 0;
var save_data = () => {
storage.do('set', {type: 'keys', id: 'hardware', data: {value: JSON.stringify(data)}}, (err) => {
let diffCount = 0;
const saveData = () => {
storage.do('set', { type: 'keys', id: 'hardware', data: { value: JSON.stringify(data) } }, (err) => {
if (err) logger.error('Unable to save hardware data');
});
}
};

var compare_field = (current, stored) => {
// eslint-disable-next-line consistent-return
const compareField = (current, stored) => {
if (stored instanceof Array) {
if (!current || (current.length > stored.length)) return diff_count++;
// eslint-disable-next-line no-plusplus
if (!current || (current.length > stored.length)) return diffCount++;
// eslint-disable-next-line consistent-return
stored.forEach((value) => {
if (_.findIndex(current, value) == -1) {
return diff_count++;
const foundIndex = current.findIndex((element) => element === value);
if (foundIndex === -1) {
// eslint-disable-next-line no-plusplus
return diffCount++;
}
})
});
} else if (stored instanceof Object) {
if (!current || (Object.keys(current).length > Object.keys(stored).length)) return diff_count++;
if (!current || (Object.keys(current).length > Object.keys(stored).length)) {
// eslint-disable-next-line no-plusplus
return diffCount++;
}
Object.keys(stored).forEach((key) => {
compare_field(current[key], stored[key])
compareField(current[key], stored[key]);
});
} else {
if (current != stored) diff_count++;
}
}
// eslint-disable-next-line no-plusplus
} else if (current !== stored) diffCount++;
};

storage.do('query', {type: 'keys', column: 'id', data: 'hardware'}, (err, stored_data) => {
if (err) logger.error('Unable to read hardware data');
if (stored_data.length == 0) return save_data();
// eslint-disable-next-line consistent-return
storage.do('query', { type: 'keys', column: 'id', data: 'hardware' }, (error, storedData) => {
if (error) logger.error('Unable to read hardware data');
if (storedData.length === 0) return saveData();

try {
stored_data = JSON.parse(stored_data[0].value);
// eslint-disable-next-line no-param-reassign
storedData = JSON.parse(storedData[0].value);
} catch (e) {
console.log("ERROR!") // modificar
console.log('ERROR!'); // modificar
}
compare_field(data, stored_data);
compareField(data, storedData);

if (diff_count > 0) {
if (diffCount > 0) {
hooks.trigger('hardware_changed');
storage.do('del', {type: 'keys', id: 'hardware'}, (err) => {
storage.do('del', { type: 'keys', id: 'hardware' }, (err) => {
if (err) logger.error('Unable to delete hardware data');
save_data();
})
saveData();
});
}
})
}
});
};