domotz-remote-pawn
Version:
Domotz Agent
211 lines (189 loc) • 6.29 kB
JavaScript
/**
* This file is part of Domotz Agent.
* Copyright (C) 2016 Domotz Ltd
*
* Domotz Agent is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Domotz Agent is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Domotz Agent. If not, see <http://www.gnu.org/licenses/>.
*
* Created by Alessio Sanfratello <asanfratello@domotz.com> on 16/06/17.
*/
function getAvailableModules(resourceLocator, callback) {
var jamDriver = resourceLocator.jamDriver;
var mlab = resourceLocator.networkTools.mlabSpeedTest;
var ndt7 = resourceLocator.networkTools.ndt7SpeedTest;
var openvpn = resourceLocator.networkTools.openvpn;
var winrm = resourceLocator.winrm;
var snmpv3Supported = resourceLocator.snmpv3Supported;
var platform = resourceLocator.utils.platform;
var firmware = resourceLocator.utils.firmware;
var lodash = resourceLocator.lodash;
var modules = {
ssh_shell_sequence: {
version: '1.0',
},
tftp_server: {
version: '1.1',
},
fast: {
version: '',
},
snmp_status_check: {
version: '',
},
snmp_overlay: {
version: '0.1',
},
nodejs: {
version: process.version,
},
bonjour_rpc_command: {
version: '',
},
upnp_rpc_command: {
version: '',
},
forced_ip_range_scan: {
version: '',
},
};
if (!platform.isNodeVersionZero()) {
modules.sandbox = {
version: '1.18',
};
}
var q = resourceLocator.q;
var myConsole = resourceLocator.log.decorateLogs();
try {
var osInfo = resourceLocator.utils.platform.getOsInfo(resourceLocator);
modules.os_version = { version: osInfo.version };
} catch (e) {
myConsole.warn('os info not available, %s', JSON.stringify(e));
}
if (platform.isWindows()) {
modules.scp = {
version: 'pscp',
};
} else {
modules.scp = {
version: '',
};
}
if (platform.supportsDomainAccountAuth()) {
modules.winrm_domain_account = {
version: '1.0',
};
}
if (snmpv3Supported === true) {
modules.snmpv3 = {
version: '1.0',
};
}
if (resourceLocator.netPing) {
modules.netping = {
version: '',
};
}
if (mlab.isAvailable() || ndt7.isAvailable()) {
modules.mlab = {
version: '',
};
}
if (ndt7.isAvailable()) {
modules.ndt7_client = {
version: '',
};
}
if (platform.getOpenSSHVersion() && platform.getOpenSSLVersion()) {
modules.openssh = {
version: platform.getOpenSSHVersion(),
};
modules.openssl = {
version: platform.getOpenSSLVersion(),
};
}
var openVPNVersionPromise = openvpn.getVersion();
var winrmVersionPromise = winrm.getVersion();
var firmwareVersionPromise = firmware.getFirmwareVersion();
var powershellVersionPromise = platform.getPowershellVersion();
var promises = [openVPNVersionPromise, platform.getNmapInfo(), winrmVersionPromise, firmwareVersionPromise, powershellVersionPromise];
if (jamDriver.hasOwnProperty('getFingVersion')) {
var jamDriverPromise = jamDriver.getFingVersion();
promises.push(jamDriverPromise);
} else {
if (jamDriver.hasOwnProperty('luxulApiVersion')) {
modules.luxul_blocking_api = {
version: jamDriver.luxulApiVersion().toString(),
};
} else {
if (platform.isNetgearRouter()) {
modules.netgear_blocking_api = {
version: 1,
};
}
}
}
q.allSettled(promises).spread(function (openVPNVersion, nmapInfo, winrmVersion, firmwareVersion, powershellVersion, fingDriverVersion) {
var fulfilled = 'fulfilled';
if (openVPNVersion && openVPNVersion.state === fulfilled) {
modules.openvpn = {
version: openVPNVersion.value,
};
}
if (fingDriverVersion && fingDriverVersion.state === fulfilled) {
modules.fing = {
version: fingDriverVersion.value,
};
}
if (firmwareVersion && firmwareVersion.state === fulfilled) {
modules.firmware = {
version: firmwareVersion.value,
};
}
if (nmapInfo && nmapInfo.state === fulfilled) {
var nmapVersion = lodash.get(nmapInfo.value, 'nmap');
var npcapVersion = lodash.get(nmapInfo.value, 'Npcap');
if (nmapVersion) {
modules.nmap = {
version: nmapVersion,
};
}
if (npcapVersion) {
modules.npcap = {
version: npcapVersion,
};
}
}
if (platform.isWindows()) {
if (winrmVersion && winrmVersion.state === fulfilled) {
modules.winrm = {
version: winrmVersion.value,
};
}
if (powershellVersion && powershellVersion.state === fulfilled) {
modules.powershell = {
version: powershellVersion.value,
};
}
}
if (firmwareVersion && firmwareVersion.state === fulfilled) {
modules.firmware = {
version: firmwareVersion.value,
};
}
myConsole.info('Available modules: %s', JSON.stringify(modules));
callback(modules);
});
}
module.exports = {
getAvailableModules: getAvailableModules,
};