UNPKG

domotz-remote-pawn

Version:

Domotz Agent

56 lines (50 loc) 1.8 kB
/** 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 tom on 14/09/15. */ module.exports = function(result) { try { output = {}; if (result.nmaprun.runstats[0].hosts[0].$.up == 0){ throw new Error('Host is reported DOWN by NMAP'); } if (result.nmaprun.host === undefined || result.nmaprun.host[0].ports === undefined){ console.warn('PortMap: Cannot parse XML.'); console.warn('XML: ' + result); return {}; } var ports = result.nmaprun.host[0].ports[0].port; if (ports === undefined || ports.length === 0) { console.info('No ports found'); return {}; } for (var i = 0; i < ports.length; i++) { var currentPort = ports[i]; var status = "OFFLINE" if (currentPort.state[0].$.state === 'open'){ status = "ONLINE" } output[currentPort.$.portid]=status } return output; } catch (err) { console.warn(err.stack); throw new Error('Error during parsing: Wrong Input'); } };