Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var knownIP = robotIP;
var firmwareVersion = parseInt((process.env.FIRMWARE_VERSION || config.firmwareVersion || 1), 10);
var enableLocal = process.env.ENABLE_LOCAL || config.enableLocal || 'yes';
var enableCloud = process.env.ENABLE_CLOUD || config.enableCloud || 'yes';
var keepAlive = process.env.KEEP_ALIVE || config.keepAlive || 'yes';
// Temporal:
if (firmwareVersion === 2) enableCloud = 'no';
if (!blid || !password) {
throw new Error('Config not found. Please edit config/default.json file with your robot credentials. Or set BLID, PASSWORD and ROBOT_IP enviroment variables.');
}
var myRobot = {};
var handleIP = (robotIP || enableLocal === 'no') ? function (cb) { cb(null, robotIP); } : dorita980.getRobotIP;
handleIP(function (e, ip) {
if (e) throw e;
knownIP = ip;
if (enableLocal === 'yes') {
if (firmwareVersion === 1 || (keepAlive === 'yes')) myRobot.local = new dorita980.Local(blid, password, ip, firmwareVersion);
}
if (enableCloud === 'yes') myRobot.cloud = new dorita980.Cloud(blid, password, firmwareVersion);
});
router.get('/', function (req, res) {
res.send({
version: '1.0.' + firmwareVersion}
);
});
/*
break;
/*
case 'encrypt':
adapter.log.debug('Encrypted message.');
library.msg(msg.from, msg.command, {result: true, data: {password: encryptor.encrypt(adapter.config.encryptionKey, msg.message.cleartext)}}, msg.callback);
break;
case 'decrypt':
adapter.log.debug('Decrypted message.');
library.msg(msg.from, msg.command, {result: true, data: {cleartext: encryptor.decrypt(adapter.config.encryptionKey, msg.message.password)}}, msg.callback);
break;
*/
case 'getIp':
_dorita980.getRobotIP(function(err, ip)
{
adapter.log.debug('Retrieved IP address: ' + ip);
library.msg(msg.from, msg.command, err ? {result: false, error: err.message} : {result: true, data: {ip: ip}}, msg.callback);
});
break;
case 'getRobotData':
getRobotData(function(res)
{
adapter.log.debug('Retrieved robot data: ' + JSON.stringify(res));
library.msg(msg.from, msg.command, res, msg.callback);
}, msg.message !== null ? msg.message.ip : undefined);
break;
case 'getPassword':
msg.message.encryption = msg.message.encryption === undefined ? true : msg.message.encryption;
break;
/*
case 'encrypt':
adapter.log.debug('Encrypted message.');
library.msg(msg.from, msg.command, {result: true, data: {password: encryptor.encrypt(adapter.config.encryptionKey, msg.message.cleartext)}}, msg.callback);
break;
case 'decrypt':
adapter.log.debug('Decrypted message.');
library.msg(msg.from, msg.command, {result: true, data: {cleartext: encryptor.decrypt(adapter.config.encryptionKey, msg.message.password)}}, msg.callback);
break;
*/
case 'getIp':
_dorita980.getRobotIP(function(err, ip)
{
adapter.log.debug('Retrieved IP address: ' + ip);
library.msg(msg.from, msg.command, err ? {result: false, error: err.message} : {result: true, data: {ip: ip}}, msg.callback);
});
break;
case 'getRobotData':
getRobotData(function(res)
{
adapter.log.debug('Retrieved robot data: ' + JSON.stringify(res));
library.msg(msg.from, msg.command, res, msg.callback);
}, msg.message !== null ? msg.message.ip : undefined);
break;
case 'getPassword':
msg.message.encryption = msg.message.encryption === undefined ? true : msg.message.encryption;