domotz-remote-pawn
Version:
Domotz Agent
63 lines (56 loc) • 2.48 kB
JavaScript
/** This file is part of Domotz Agent.
* Copyright (C) 2021 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/>.
*
* This event handler activates the BigNetwork nmap discovery.
*
* It is executed periodically, in order to assure the BigNetwork scan is
* running.
*
*/
var LOG_NAME = 'HANDLER - (BIG_NETWORK_SCAN)';
var handler = function (resourceLocator) {
var myConsole = resourceLocator.log.decorateLogs(LOG_NAME);
var bigNetworkScanner = resourceLocator.discovery.bigNetworkScanner;
var hostInfo = resourceLocator.discovery.host;
if (resourceLocator.settingsManager.isBroadcastDiscoveryDisabled()) {
myConsole.info('Broadcast discovery disabled, BigNetwork scan skipped');
return;
}
if (resourceLocator.emergencyNetworkRestore.isEmergencyInterfaceEnabled()) {
myConsole.info('Big Network Discovery skipped for emergency interface');
return;
}
var interfaces = hostInfo.getInterfacesList();
var allowed_interfaces = hostInfo.getAllowedInterfacesList();
for (var name in interfaces) {
if (!allowed_interfaces.hasOwnProperty(name)) {
myConsole.info('BigNetwork scan not allowed for interface %s', name);
continue;
}
if (interfaces.hasOwnProperty(name)) {
var iface = interfaces[name];
if (bigNetworkScanner.isBigNetwork(iface)) {
if (!bigNetworkScanner.isScanning(iface, name)) {
myConsole.info('Start BigNetwork scan for interface %s - %s/%s', name, iface.ip, iface.netmask);
} else {
myConsole.info('Checking BigNetwork scan for interface %s - %s/%s is running', name, iface.ip, iface.netmask);
}
bigNetworkScanner.keepScanning(iface, name);
}
}
}
};
module.exports.handler = handler;