diff --git a/package.json b/package.json index 95f2326bd..9336f9609 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/server/api/wazuh-api.js b/server/api/wazuh-api.js index f161b9864..002011227 100644 --- a/server/api/wazuh-api.js +++ b/server/api/wazuh-api.js @@ -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 = ""; diff --git a/server/monitoring.js b/server/monitoring.js index b4034c95c..e39d39387 100644 --- a/server/monitoring.js +++ b/server/monitoring.js @@ -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) { diff --git a/util/get-path.js b/util/get-path.js new file mode 100644 index 000000000..94c2648c0 --- /dev/null +++ b/util/get-path.js @@ -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; +}; \ No newline at end of file