Adding the fix to support the API 2.0.0 in wazuh-api.js too

This commit is contained in:
malbarral 2017-06-23 20:15:35 +02:00
parent 9143d5059d
commit c5350eb8b5

View File

@ -3,6 +3,7 @@ module.exports = function (server, options) {
const pciRequirementsFile = '';
const fs = require('fs');
const path = require('path');
const needle = require('needle');
var fetchAgentsExternal = require(path.resolve(__dirname, "../wazuh-monitoring.js"));
const wazuh_config_file = '../../configuration/config.json';
const wazuh_temp_file = '../../configuration/.patch_version';
@ -318,6 +319,38 @@ module.exports = function (server, options) {
reply({ 'statusCode': 400, 'error': 7, 'message': 'Missing data' }).code(400);
return;
}
var options = {
headers: { 'api-version': wazuh_api_version },
username: req.payload.user,
password: req.payload.password,
rejectUnauthorized: !req.payload.insecure
};
needle.request('get', req.payload.url + ':' + req.payload.port +'/version', {}, options, function (error, response) {
if (error || response.error || !response.body.data) {
options = {
headers: { 'api-version': 'v2.0.0' },
username: req.payload.user,
password: req.payload.password,
rejectUnauthorized: !req.payload.insecure
}
needle.request('get', req.payload.url + ':' + req.payload.port +'/version', {}, options, function (error, response) {
if (!error && !response.error && response.body.data) {
fs.writeFile(path.resolve(__dirname, wazuh_temp_file), "#Temporal file to avoid inconsistences when using App 2.0.1 with API 2.0.0",function(err){
if(err) server.log([blueWazuh, 'initialize', 'error'], err);
else{
server.log([blueWazuh, 'initialize', 'info'], 'Temporal file created to use the API 2.0.0');
}
});
} else {
server.log([blueWazuh, 'initialize', 'error'], 'Wazuh API credentials not found or are not correct. Open the app in your browser and configure it for start monitoring agents.');
}
});
}
});
var settings = { 'api_user': req.payload.user, 'api_password': req.payload.password, 'url': req.payload.url, 'api_port': req.payload.port , 'insecure': req.payload.insecure, 'component' : 'API', 'active' : req.payload.active, 'manager' : req.payload.manager, 'extensions' : req.payload.extensions};
elasticRequest.callWithRequest(req, 'index', { index: '.kibana', type: 'wazuh-configuration', body: settings, refresh: true })