Added missing dependency. Extracted to single file a repeated function.

This commit is contained in:
Jesús Ángel González Novez 2017-10-27 09:22:10 +02:00
parent 893cd5b7a9
commit 5b2976279a
4 changed files with 22 additions and 43 deletions

View File

@ -33,6 +33,7 @@
"angular-cookies": "1.6.5",
"angular-material": "1.1.1",
"angular-md5": "^0.1.10",
"ansicolors": "^0.3.2",
"bootstrap": "3.3.6",
"install": "^0.10.1",
"needle": "^2.0.1",

View File

@ -1,3 +1,5 @@
const getPath = require('../../util/get-path');
module.exports = function (server, options) {
// Require some libraries
const fs = require('fs');
@ -84,28 +86,6 @@ module.exports = function (server, options) {
}
};
const getPath = (wapi_config) => {
console.log(wapi_config);
var path = wapi_config.url;
var protocol;
if(wapi_config.url.startsWith("https://")){
protocol = "https://";
}
else if(wapi_config.url.startsWith("http://")){
protocol = "http://";
}
if(path.lastIndexOf("/") > protocol.length){
path = path.substr(0, path.substr(protocol.length).indexOf("/") + protocol.length) +
":" + wapi_config.port + path.substr(path.substr(protocol.length).indexOf("/") + protocol.length);
}
else{
path = wapi_config.url + ':' + wapi_config.port;
}
console.log(path);
return path;
};
var getPciRequirement = function (req,reply) {
var pciRequirements = {};
var pci_description = "";

View File

@ -3,7 +3,7 @@ const fs = require('fs');
const path = require('path');
var cron = require('node-cron');
var needle = require('needle');
const getPath = require('../util/get-path');
// Colors for console logging
const colors = require('ansicolors');
const blueWazuh = colors.blue('wazuh');
@ -30,26 +30,6 @@ module.exports = function (server, options) {
server.log([blueWazuh, 'Wazuh agents monitoring', 'error'], 'Could not read the Wazuh package file.');
}
const getPath = (wapi_config) => {
console.log(wapi_config);
var path = wapi_config.url;
var protocol;
if (wapi_config.url.startsWith("https://")) {
protocol = "https://";
} else if (wapi_config.url.startsWith("http://")) {
protocol = "http://";
}
if (path.lastIndexOf("/") > protocol.length) {
path = path.substr(0, path.substr(protocol.length).indexOf("/") + protocol.length) +
":" + wapi_config.port + path.substr(path.substr(protocol.length).indexOf("/") + protocol.length);
} else {
path = wapi_config.url + ':' + wapi_config.port;
}
console.log(path);
return path;
};
// Check status and get agent status array
var checkStatus = function (apiEntry, maxSize, offset) {
if (!maxSize) {

18
util/get-path.js Normal file
View File

@ -0,0 +1,18 @@
module.exports = (wapiConfig) => {
let path = wapiConfig.url;
let protocol;
if (wapiConfig.url.startsWith("https://")) {
protocol = "https://";
} else if (wapiConfig.url.startsWith("http://")) {
protocol = "http://";
}
if (path.lastIndexOf("/") > protocol.length) {
path = path.substr(0, path.substr(protocol.length).indexOf("/") + protocol.length) +
":" + wapiConfig.port +
path.substr(path.substr(protocol.length).indexOf("/") + protocol.length);
} else {
path = `${wapiConfig.url}:${wapiConfig.port}`;
}
return path;
};