domotz-remote-pawn
Version:
Domotz Agent
55 lines (52 loc) • 1.87 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 tom on 14/09/15.
*/
module.exports = function(result) {
try {
var output = {
ip_ports: []
};
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];
if (currentPort.state[0].$.state !== 'open'){
continue;
}
output.ip_ports.push({
port: currentPort.$.portid,
service: currentPort.service[0].$.name,
method: currentPort.service[0].$.method
});
}
return output;
} catch (err) {
console.warn(err.stack);
throw new Error('Error during parsing: Wrong Input');
}
};