Rebranding services

This commit is contained in:
havidarou 2017-10-20 15:12:08 -04:00
parent f6e76c5a29
commit 6d96a3496e
12 changed files with 429 additions and 951 deletions

View File

@ -1,36 +0,0 @@
import $ from 'jquery';
require('ui/modules').get('app/wazuh', [])
.directive('autoSizeContainer', function () {
return {
restrict: 'A',
link: function ($scope, $element) {
var $window = $(window);
var winHeight = $window.height();
var winBottom = winHeight + $window.scrollTop();
var elTop = $element.offset().top;
var remaining = winBottom - elTop - 10;
$scope.autoSizeStyle = {'height': remaining+'px'};
}
}
});
require('ui/modules').get('app/wazuh', []).directive('iframeSetDimensionsOnload', [function(){
return {
restrict: 'A',
link: function(scope, element, attrs){
element.on('load', function(){
var $window = $(window);
var winHeight = $window.height();
var winBottom = winHeight + $window.scrollTop();
var elTop = element.offset().top;
var remaining = winBottom - elTop - 10;
var iFrameHeight = winHeight;
var iFrameWidth = '100%';
element.css('width', iFrameWidth);
element.css('height', remaining);
})
}
}}])

View File

@ -1,479 +0,0 @@
require('ui/modules').get('app/wazuh', [])
.factory('DataFactory', function (apiReq, $q, errlog) {
var dataObj = {};
var _instances = [];
dataObj.initialize = function (method, path, body, pageSize, offset) {
var defered = $q.defer();
var promise = defered.promise;
if (!method || !path || !body) {
defered.reject(prepError({ 'error': -1, 'message': 'Missing parameters' }));
return promise;
}
var instance = (Math.random().toString(36).substring(3));
while ((_instances[instance]) && (_instances[instance].length > 0)) {
instance = (Math.random().toString(36).substring(3));
}
var limit;
if ((method === 'get') && (pageSize)) {
apiReq.request('get', path + "?offset=0&limit=1", body)
.then(function (data) {
limit = data.data.data.totalItems;
_instances[instance] = {
'method': method, 'path': path, 'body': body, 'pageSize': pageSize,
'offset': offset, 'limit': limit, 'pagination': true, 'filters': []
};
defered.resolve(instance);
}, function (data) {
defered.reject(prepError(data));
});
} else {
_instances[instance] = {
'method': method, 'path': path, 'body': body, 'pageSize': pageSize,
'offset': offset, 'pagination': false, 'filters': []
};
defered.resolve(instance);
}
return promise;
};
dataObj.hasNext = function (instanceId) {
return ((_instances[instanceId]['offset'] + _instances[instanceId]['pageSize']) < _instances[instanceId]['limit']);
}
dataObj.next = function (instanceId) {
var defered = $q.defer();
var promise = defered.promise;
if (!instanceId) {
defered.reject(prepError({ 'error': -1, 'message': 'Missing parameters' }));
return promise;
}
if (!_instances[instanceId]['pagination']) {
defered.reject(prepError({ 'error': -10, 'message': 'Pagination disabled for this object' }));
return promise;
}
_instances[instanceId]['offset'] += _instances[instanceId]['pageSize'];
if ((_instances[instanceId]['offset'] < 0) ||
(_instances[instanceId]['offset'] >= _instances[instanceId]['limit'])) {
_instances[instanceId]['offset'] -= _instances[instanceId]['pageSize']
defered.reject("");
return promise;
}
dataObj.get(instanceId)
.then(function (data) {
defered.resolve(data);
}, function (data) {
defered.reject(data);
});
return promise;
};
dataObj.scrollTo = function (instanceId, index) {
var defered = $q.defer();
var promise = defered.promise;
if (!instanceId) {
defered.reject(prepError({ 'error': -1, 'message': 'Missing parameters' }));
return promise;
}
if (!_instances[instanceId]['pagination']) {
defered.reject(prepError({ 'error': -10, 'message': 'Pagination disabled for this object' }));
return promise;
}
_instances[instanceId]['offset'] = index - Math.floor(_instances[instanceId]['pageSize'] / 2);
if (_instances[instanceId]['offset'] > _instances[instanceId]['limit']) {
_instances[instanceId]['offset'] = _instances[instanceId]['limit'] - _instances[instanceId]['pageSize'];
}
if (_instances[instanceId]['offset'] < 0) {
_instances[instanceId]['offset'] = 0;
}
dataObj.get(instanceId)
.then(function (data) {
defered.resolve(data);
}, function (data) {
defered.reject(data);
});
return promise;
};
dataObj.hasPrev = function (instanceId) {
return ((_instances[instanceId]['offset'] - _instances[instanceId]['pageSize']) >= 0);
}
dataObj.prev = function (instanceId) {
var defered = $q.defer();
var promise = defered.promise;
if (!instanceId) {
defered.reject(prepError({ 'error': -1, 'message': 'Missing parameters' }));
return promise;
}
if (!_instances[instanceId]['pagination']) {
defered.reject(prepError({ 'error': -10, 'message': 'Pagination disabled for this object' }));
return promise;
}
_instances[instanceId]['offset'] -= _instances[instanceId]['pageSize'];
if ((_instances[instanceId]['offset'] < 0) ||
(_instances[instanceId]['offset'] >= _instances[instanceId]['limit'])) {
_instances[instanceId]['offset'] += _instances[instanceId]['pageSize']
defered.reject(prepError({ 'error': -11, 'message': 'Pagination out of bounds' }));
return promise;
}
dataObj.get(instanceId)
.then(function (data) {
defered.resolve(data);
}, function (data) {
defered.reject(data);
});
return promise;
};
dataObj.get = function (instanceId) {
var defered = $q.defer();
var promise = defered.promise;
if (!instanceId) {
defered.reject(prepError({ 'error': -1, 'message': 'Missing parameters' }));
return promise;
}
var preparedBody = _instances[instanceId]['body'];
if (_instances[instanceId]['pagination']) {
preparedBody['offset'] = _instances[instanceId]['offset'];
preparedBody['limit'] = _instances[instanceId]['pageSize'];
}
apiReq.request(_instances[instanceId]['method'], _instances[instanceId]['path'], preparedBody)
.then(function (data) {
if ((_instances[instanceId]['pagination']) && (data.data.data.totalItems != _instances[instanceId]['limit'])) {
_instances[instanceId]['limit'] = data.data.data.totalItems;
}
defered.resolve(data);
}, function (data) {
defered.reject(prepError(data));
});
return promise;
};
/*Filters start*/
dataObj.filters = {};
dataObj.filters.register = function (instanceId, name, type, required, defValue) {
if (!name || !type || !instanceId) {
return prepError({ 'error': -1, 'message': 'Missing parameters' });
}
switch (type) {
case 'string': break;
case 'boolean': break;
case 'array': break;
default:
return prepError({ 'error': 7, 'message': 'Filter type must be one of the following: String, boolean, array.' });
};
if (_instances[instanceId]['filters'][name] != undefined) {
return prepError({ 'error': 7, 'message': 'Attempt to register duplicated filter' });
}
if (required && !defValue) {
return prepError({ 'error': 7, 'message': 'Required filters must have a default value.' });
}
_instances[instanceId]['filters'][name] = { 'type': type, 'required': required, 'defValue': defValue };
_instances[instanceId]['body'][name.replace('filter-', '')] = _instances[instanceId]['filters'][name]['required'] ?
_instances[instanceId]['filters'][name]['defValue'] : undefined;
return true;
};
dataObj.filters.unregister = function (instanceId, name) {
if (!instanceId || !name) {
return prepError({ 'error': -1, 'message': 'Missing parameters' });
}
if (!_instances[instanceId]['filters']) {
return prepError({ 'error': 7, 'message': 'Attempt to delete an undefined filter' });
}
_instances[instanceId]['body'][name.replace('filter-', '')] = undefined;
_instances[instanceId]['filters'][name].length = 0;
_instances[instanceId]['filters'][name] = undefined;
return true;
};
dataObj.filters.setOr = function (instanceId, name, filtersArray) {
if (!instanceId || !name || !filtersArray) {
return prepError({ 'error': -1, 'message': 'Missing parameters' });
}
if (!dataObj.filters.exist(instanceId, name)) {
return prepError({ 'error': 7, 'message': 'Filters must be registered before setting a value or relation' });
}
if (typeof (filtersArray) == 'String') {
filtersArray = [filtersArray];
}
_instances[instanceId]['filters'][name]['or'] = [];
angular.forEach(filtersArray, function (element) {
if (dataObj.filters.exist(instanceId, name)) {
_instances[instanceId]['filters'][name]['or'].push(element);
}
});
return true;
};
dataObj.filters.setAnd = function (instanceId, name, filtersArray) {
if (!instanceId || !name || !filtersArray) {
return prepError({ 'error': -1, 'message': 'Missing parameters' });
}
if (!dataObj.filters.exist(instanceId, name)) {
return prepError({ 'error': 7, 'message': 'Filters must be registered before setting a value or relation' });
}
if (typeof (filtersArray) == 'String') {
filtersArray = [filtersArray];
}
angular.forEach(filtersArray, function (element) {
if (!_instances[instanceId]['filters'][element]['required']) {
return prepError({ 'error': 7, 'message': 'Attempt to relate not required filters with "AND" expression.' });
}
if (dataObj.filters.exist(instanceId, name)) {
_instances[instanceId]['filters'][name]['and'].push(element);
}
});
return true;
};
dataObj.filters.set = function (instanceId, name, value) {
if (!instanceId || !name || !value) {
return prepError({ 'error': -1, 'message': 'Missing parameters' });
}
if (!dataObj.filters.exist(instanceId, name)) {
return prepError({ 'error': 7, 'message': 'Filters must be registered before setting a value or relation' });
}
if ((_instances[instanceId]['filters'][name]['type'] == 'boolean') && (typeof (value) != 'boolean')) {
return prepError({ 'error': 7, 'message': 'Attempt to set non-boolean value in boolean filter' });
}
if (_instances[instanceId]['filters'][name]['type'] == 'array') {
_instances[instanceId]['filters'][name] = ((_instances[instanceId]['filters'][name].split(',')).push(value)).toString();
} else {
_instances[instanceId]['body'][name.replace('filter-', '')] = value;
}
angular.forEach(_instances[instanceId]['filters'][name]['or'], function (element) {
if (dataObj.filters.exist(instanceId, element)) {
dataObj.filters.unset(instanceId, element);
} else {
_instances[instanceId]['filters'][name]['or'][_instances[instanceId]['filters'][name]['or'].indexOf(element)] = undefined;
}
});
angular.forEach(_instances[instanceId]['filters'][name]['and'], function (element) {
if (!dataObj.filters.exist(instanceId, element)) {
_instances[instanceId]['filters'][name]['and'][_instances[instanceId]['filters'][name]['and'].indexOf(element)] = undefined;
} else if (!dataObj.filters.hasValue(instanceId, element)) {
_instances[instanceId]['body'][element.replace('filter-', '')] = _instances[instanceId]['filters'][element]['defValue'];
}
});
_instances[instanceId]['filterFlag'] = true;
return true;
};
dataObj.filters.unset = function (instanceId, name) {
if (!instanceId || !name) {
return prepError({ 'error': -1, 'message': 'Missing parameters' });
}
if (!dataObj.filters.exist(instanceId, name)) {
return prepError({ 'error': 7, 'message': 'Filters must be registered before setting a value or relation' });
}
_instances[instanceId]['body'][name.replace('filter-', '')] =
_instances[instanceId]['filters'][name]['defValue'] ? _instances[instanceId]['filters'][name]['defValue'] : undefined;
_instances[instanceId]['filterFlag'] = true;
return true;
};
dataObj.filters.flag = function (instanceId) {
if (!instanceId) {
return prepError({ 'error': -1, 'message': 'Missing parameters' });
}
return _instances[instanceId]['filterFlag'];
};
dataObj.filters.unflag = function (instanceId) {
if (!instanceId) {
return prepError({ 'error': -1, 'message': 'Missing parameters' });
}
_instances[instanceId]['filterFlag'] = false;
return true;
};
dataObj.filters.alternateSet = function (instanceId, name, value) {
if (!instanceId || !name || !value) {
return prepError({ 'error': -1, 'message': 'Missing parameters' });
}
if (!dataObj.filters.exist(instanceId, name)) {
return prepError({ 'error': 7, 'message': 'Filters must be registered before setting a value or relation' });
}
if (dataObj.filters.isSet(instanceId, name, value)) {
dataObj.filters.unset(instanceId, name, value);
} else {
dataObj.filters.set(instanceId, name, value);
}
return true;
};
dataObj.filters.exist = function (instanceId, name) {
if (!instanceId || !name) {
return prepError({ 'error': -1, 'message': 'Missing parameters' });
}
return (_instances[instanceId]['filters'][name] != undefined);
};
dataObj.filters.hasValue = function (instanceId, name) {
if (!instanceId || !name) {
return prepError({ 'error': -1, 'message': 'Missing parameters' });
}
return dataObj.filters.exist(instanceId, name) ? (_instances[instanceId]['body'][name.replace('filter-', '')] != undefined) : false;
};
dataObj.filters.isSet = function (instanceId, name, value) {
if (!instanceId || !name || !value) {
return prepError({ 'error': -1, 'message': 'Missing parameters' });
}
return dataObj.filters.hasValue(instanceId, name) ? (_instances[instanceId]['body'][name.replace('filter-', '')] == value) : false;
};
/*Filters end*/
dataObj.getBody = function (instanceId) {
return _instances[instanceId]['body'];
};
dataObj.getOffset = function (instanceId) {
return _instances[instanceId]['offset'];
};
dataObj.setOffset = function (instanceId, offset) {
_instances[instanceId]['offset'] = offset;
};
dataObj.getTotalItems = function (instanceId) {
if (_instances[instanceId]['limit']) {
return _instances[instanceId]['limit'];
} else {
return 0;
}
};
dataObj.clean = function (instanceId) {
_instances[instanceId].length = 0;
};
dataObj.cleanAll = function () {
_instances = 0;
};
dataObj.getAndClean = function (method, path, body) {
var defered = $q.defer();
var promise = defered.promise;
dataObj.initialize(method, path, body)
.then(function (_instanceId) {
dataObj.get(_instanceId)
.then(function (data) {
defered.resolve(data);
dataObj.clean(_instanceId);
}, function (error) {
defered.reject(error);
dataObj.clean(_instanceId);
})
}, function (error) {
defered.reject(error);
})
return promise;
};
var prepError = function (err) {
if (err.error < 0) {
err['html'] = "Unexpected error located on controller. Error: <b>" + err.message + " (code " + err.error + ")</b>.";
err.message = "Unexpected error located on controller. Error: " + err.message + " (code " + err.error + ").";
} else if (err.error === 1) {
err['html'] = "<b>Error getting credentials</b> for Wazuh API. Please, check credentials at settings tab.";
err.message = "Error getting credentials for Wazuh API. Please, check credentials at settings tab.";
} else if (err.error === 2) {
err['html'] = "<b>Error getting credentials</b> for Wazuh API. Could not connect with Elasticsearch.";
err.message = "Error getting credentials for Wazuh API. Could not connect with Elasticsearch.";
} else if (err.error < 5) {
err['html'] = "Unexpected error located on Kibana server. Error: <b>" + err.message + " (code " + err.error + ")</b>.";
err.message = "Unexpected error located on Kibana server. Error: " + err.message + " (code " + err.error + ").";
} else if (err.error === 5) {
err['html'] = "Could not connect with Wazuh API. Error: " + err.errorMessage + ".</br> Please, check the URL at settings tab.";
err.message = "Could not connect with Wazuh API. Error: " + err.errorMessage + ". Please, check the URL at settings tab.";
} else if (err.error === 6) {
if (err.errorData.statusCode && err.errorData.statusCode == '404') {
err['html'] = "Wazuh API URL could not be found on elasticsearch. Please, configure the application properly.";
err.message = "Wazuh API URL could not be found on elasticsearch. Please, configure the application properly.";
} else {
err['html'] = "Wazuh API returned an error message. Error: <b>" + err.errorData.message + "</b>";
err.message = "Wazuh API returned an error message. Error: " + err.errorData.message;
}
} else if (err.error === 7) {
err['html'] = "Unexpected error filtering the data. Error <b>" + err.message + "</b>.";
err.message = "Unexpected error filtering the data. Error " + err.message + ".";
} else {
err['html'] = "Unexpected error. Please, report this error.";
err.message = "Unexpected error. Please, report this error.";
}
errlog.log(err.message, JSON.stringify(err));
return err;
};
return dataObj;
});

View File

@ -1,33 +0,0 @@
import chrome from 'ui/chrome';
require('ui/modules').get('app/wazuh', [])
.service('errlog', function ($q, $http) {
return {
log: function (message, details) {
var defered = $q.defer();
var promise = defered.promise;
if (!message) {
defered.reject({ 'error': -1, 'message': 'Missing parameters' });
return promise;
}
var requestData = {
'message': message,
'details': details
}
$http.post(chrome.addBasePath('/api/wazuh-api/errlog'), requestData)
.then(function () {
defered.resolve();
}).catch(function (data) {
if (data.error) {
defered.reject(data);
} else {
defered.reject({ 'error': -2, 'message': 'Error doing a request to Kibana API.' });
}
});
return promise;
}
};
});

View File

@ -1,21 +0,0 @@
require('ui/modules').get('app/wazuh', [])
.service('sharedProperties', function () {
var _property = '';
var _dashboard = { name: undefined, filter: undefined};
return {
getDashboard: function () {
return _dashboard;
},
setDashboard: function (name, filter) {
_dashboard.name = name;
_dashboard.filter = filter;
},
getProperty: function () {
return _property;
},
setProperty: function (value) {
_property = value;
}
};
});

View File

@ -1,40 +0,0 @@
require('ui/modules').get('app/wazuh', [])
.service('tabProvider', function () {
var _tabs = [];
return {
register: function (pageId) {
if (!_tabs[pageId]) {
_tabs[pageId] = [];
}
},
setTab: function (pageId, tab, tabset) {
if (!tabset) {
tabset = 0;
}
if (!_tabs[pageId]) {
return false;
}
_tabs[pageId][tabset] = tab;
return true;
},
isSetTab: function (pageId, tab, tabset) {
if (!tabset) {
tabset = 0;
}
if (!_tabs[pageId]) {
return false;
}
if (!_tabs[pageId][tabset]) {
return (tab == 1);
}
return (_tabs[pageId][tabset] == tab);
},
clean: function (pageId) {
if (_tabs[pageId]) {
_tabs[pageId].length = 0;
}
}
};
});

View File

@ -1,38 +1,38 @@
import chrome from 'ui/chrome';
require('ui/modules').get('app/wazuh', [])
.service('apiReq', function ($q, $http, genericReq) {
return {
request: function (method, path, body) {
var defered = $q.defer();
var promise = defered.promise;
if (!method || !path || !body) {
defered.reject({ 'error': -1, 'message': 'Missing parameters' });
return promise;
}
var requestData = {
'method': method,
'path': path,
'body': body
}
genericReq.request('POST', '/api/wazuh-api/request', requestData)
.then(function (data) {
if (data.error) {
defered.reject(data);
} else {
defered.resolve(data);
}
}, function (data) {
if (data.error) {
defered.reject(data);
} else {
defered.reject({ 'error': -2, 'message': 'Error doing a request to Kibana API.' });
}
});
return promise;
}
};
});
import chrome from 'ui/chrome';
require('ui/modules').get('app/wazuh', [])
.service('apiReq', function ($q, $http, genericReq) {
return {
request: function (method, path, body) {
var defered = $q.defer();
var promise = defered.promise;
if (!method || !path || !body) {
defered.reject({ 'error': -1, 'message': 'Missing parameters' });
return promise;
}
var requestData = {
'method': method,
'path': path,
'body': body
}
genericReq.request('POST', '/api/wazuh-api/request', requestData)
.then(function (data) {
if (data.error) {
defered.reject(data);
} else {
defered.resolve(data);
}
}, function (data) {
if (data.error) {
defered.reject(data);
} else {
defered.reject({ 'error': -2, 'message': 'Error doing a request to Kibana API.' });
}
});
return promise;
}
};
});

View File

@ -13,13 +13,13 @@ require('ui/modules').get('app/wazuh', [])
}
},
getExtensions: function () {
return { extensions: $cookies.getObject('extensions') };
},
setExtensions: function (extensions) {
if (extensions) {
$cookies.putObject('extensions', extensions);
}
},
return { extensions: $cookies.getObject('extensions') };
},
setExtensions: function (extensions) {
if (extensions) {
$cookies.putObject('extensions', extensions);
}
},
unsetDashboardsState: function () {
$cookies.putObject('_dashboardsState_name', "");
$cookies.putObject('_dashboardsState_filter', "");
@ -64,11 +64,7 @@ require('ui/modules').get('app/wazuh', [])
}
},
getClusterInfo: function () {
if($cookies.getObject('_clusterInfo'))
return $cookies.getObject('_clusterInfo');
else
return {"node": "*","manager": "*","cluster": "*"};
return $cookies.getObject('_clusterInfo');
},
setClusterInfo: function (cluster_info) {
if (cluster_info) {

View File

@ -0,0 +1,108 @@
var app = require('ui/modules').get('app/wazuh', []);
app.factory('DataHandler', function($q, apiReq) {
var DataHandler = function() {
this.items = [];
this.filters = [];
this.path = '';
this.offset = 0;
this.sortValue = '';
this.initial = true;
this.initialBatch = 40;
this.regularBatch = 15;
};
DataHandler.prototype.nextPage = function() {
if (this.busy) return;
this.busy = true;
var requestData;
if (this.initial) { requestData = { offset: this.offset, limit: this.initialBatch }; this.initial = false; }
else requestData = { offset: this.offset, limit: this.regularBatch };
angular.forEach(this.filters, function(filter) {
if (filter.value != '') requestData[filter.name] = filter.value;
});
var deferred = $q.defer();
apiReq.request('GET', this.path, requestData).then(function(data) {
if (data.data.data == 0)
deferred.resolve(false);
var totalItems = data.data.data.totalItems;
var items = data.data.data.items;
for (var i = 0; i < items.length; i++) {
this.items.push(items[i]); this.items[i].selected = false;
}
this.offset += items.length;
(this.offset >= totalItems) ? this.end = true : this.busy = false
if (data.data.data != 0)
deferred.resolve(true);
}.bind(this));
return deferred.promise;
};
DataHandler.prototype.hasFilter = function(filterName) {
var filterOrNot = false;
angular.forEach(this.filters, function(filter) { if (filter.name == filterName) filterOrNot = true; });
return filterOrNot;
};
DataHandler.prototype.addFilter = function(filterName, value) {
this.removeFilter(filterName, false);
this.filters.push({ "name": filterName, "value": value });
this.search();
};
DataHandler.prototype.removeFilter = function(filterName, search) {
angular.forEach(this.filters, function(filter, key) {
if (filterName == filter.name) { this.filters.splice(key, 1); }
}, this);
if (search) this.search();
};
DataHandler.prototype.delete = function(name, index) {
apiReq.request('DELETE', this.path, {}).then(function(data) {
this.items.splice(index, 1);
}.bind(this));
};
DataHandler.prototype.search = function() {
var requestData;
this.end = false; this.busy = false;
this.sortValue = '';
requestData = { offset: 0, limit: this.initialBatch }
angular.forEach(this.filters, function(filter) {
if (filter.value != '') requestData[filter.name] = filter.value;
});
apiReq.request('GET', this.path, requestData).then(function(data) {
this.items = [];
var items = data.data.data.items;
for (var i = 0; i < items.length; i++) {
this.items.push(items[i]); this.items[i].selected = false;
}
this.offset = items.length;
}.bind(this));
};
DataHandler.prototype.sort = function(by) {
this.sortValue = by;
this.sortDir = !this.sortDir;
};
DataHandler.prototype.reset = function() {
this.items = [];
this.filters = [];
this.offset = 0;
this.sortValue = '';
this.initial = true;
this.end = false;
this.busy = false;
};
return DataHandler;
});

View File

@ -1,138 +1,137 @@
import chrome from 'ui/chrome';
require('ui/modules').get('app/wazuh', [])
.service('genericReq', function ($q, $http, errlog) {
var _request = function (method, url, payload = null) {
var defered = $q.defer();
var promise = defered.promise;
if (!method || !url) {
defered.reject({ 'error': -1, 'message': 'Missing parameters' });
return promise;
}
var requestHeaders = {
headers: {
"Content-Type": 'application/json'
}
}
if (method == "GET") {
$http.get(chrome.addBasePath(url), requestHeaders)
.then(function (data) {
if (data.error && data.error != '0') {
defered.reject(data);
} else {
defered.resolve(data);
}
}, function (data) {
if (data.error && data.error != '0') {
defered.reject(data);
} else {
defered.reject({ 'error': -2, 'message': 'Error doing a request to Kibana API.' });
}
});
}
if (method == "PUT") {
$http.put(chrome.addBasePath(url), payload, requestHeaders)
.then(function (data) {
if (data.error && data.error != '0') {
defered.reject(data);
} else {
defered.resolve(data);
}
}, function (data) {
if (data.error && data.error != '0') {
defered.reject(data);
} else {
defered.reject({ 'error': -2, 'message': 'Error doing a request to Kibana API.' });
}
});
}
if (method == "POST") {
$http.post(chrome.addBasePath(url), payload, requestHeaders)
.then(function (data) {
if (data.error && data.error != '0') {
defered.reject(data);
} else {
defered.resolve(data);
}
}, function (data) {
if (data.error && data.error != '0') {
defered.reject(data);
} else {
defered.reject({ 'error': -2, 'message': 'Error doing a request to Kibana API.' });
}
});
}
if (method == "DELETE") {
$http.delete(chrome.addBasePath(url))
.then(function (data) {
if (data.error && data.error != '0') {
defered.reject(data);
} else {
defered.resolve(data);
}
},function (data) {
if (data.error && data.error != '0') {
defered.reject(data);
} else {
defered.reject({ 'error': -2, 'message': 'Error doing a request to Kibana API.' });
}
});
}
return promise;
};
var prepError = function (err) {
if (err.error < 0) {
err['html'] = "Unexpected error located on controller. Error: <b>" + err.message + " (code " + err.error + ")</b>.";
err.message = "Unexpected error located on controller. Error: " + err.message + " (code " + err.error + ").";
} else if (err.error === 1) {
err['html'] = "<b>Error getting credentials</b> for Wazuh API. Please, check credentials at settings tab.";
err.message = "Error getting credentials for Wazuh API. Please, check credentials at settings tab.";
} else if (err.error === 2) {
err['html'] = "<b>Error getting credentials</b> for Wazuh API. Could not connect with Elasticsearch.";
err.message = "Error getting credentials for Wazuh API. Could not connect with Elasticsearch.";
} else if (err.error < 5) {
err['html'] = "Unexpected error located on Kibana server. Error: <b>" + err.message + " (code " + err.error + ")</b>.";
err.message = "Unexpected error located on Kibana server. Error: " + err.message + " (code " + err.error + ").";
} else if (err.error === 5) {
err['html'] = "Could not connect with Wazuh API. Error: " + err.errorMessage + ".</br> Please, check the URL at settings tab.";
err.message = "Could not connect with Wazuh API. Error: " + err.errorMessage + ". Please, check the URL at settings tab.";
} else if (err.error === 6) {
if (err.errorData.statusCode && err.errorData.statusCode == '404') {
err['html'] = "Wazuh API URL could not be found on elasticsearch. Please, configure the application properly.";
err.message = "Wazuh API URL could not be found on elasticsearch. Please, configure the application properly.";
} else {
err['html'] = "Wazuh API returned an error message. Error: <b>" + err.errorData.message + "</b>";
err.message = "Wazuh API returned an error message. Error: " + err.errorData.message;
}
} else if (err.error === 7) {
err['html'] = "Unexpected error filtering the data. Error <b>" + err.message + "</b>.";
err.message = "Unexpected error filtering the data. Error " + err.message + ".";
} else {
err['html'] = "Unexpected error. Please, report this error.";
err.message = "Unexpected error. Please, report this error.";
}
errlog.log(err.message, JSON.stringify(err));
return err;
};
return {
request: function (method, path, payload = null) {
var defered = $q.defer();
var promise = defered.promise;
if (!method || !path) {
defered.reject(prepError({ 'error': -1, 'message': 'Missing parameters' }));
return promise;
}
_request(method, path, payload)
.then(function (data) {
defered.resolve(data);
}, function (data) {
defered.reject(prepError(data));
});
return promise;
}
};
});
import chrome from 'ui/chrome';
require('ui/modules').get('app/wazuh', [])
.service('genericReq', function ($q, $http) {
var _request = function (method, url, payload = null) {
var defered = $q.defer();
var promise = defered.promise;
if (!method || !url) {
defered.reject({ 'error': -1, 'message': 'Missing parameters' });
return promise;
}
var requestHeaders = {
headers: {
"Content-Type": 'application/json'
}
}
if (method == "GET") {
$http.get(chrome.addBasePath(url), requestHeaders)
.then(function (data) {
if (data.error && data.error != '0') {
defered.reject(data);
} else {
defered.resolve(data);
}
}, function (data) {
if (data.error && data.error != '0') {
defered.reject(data);
} else {
defered.reject({ 'error': -2, 'message': 'Error doing a request to Kibana API.' });
}
});
}
if (method == "PUT") {
$http.put(chrome.addBasePath(url), payload, requestHeaders)
.then(function (data) {
if (data.error && data.error != '0') {
defered.reject(data);
} else {
defered.resolve(data);
}
}, function (data) {
if (data.error && data.error != '0') {
defered.reject(data);
} else {
defered.reject({ 'error': -2, 'message': 'Error doing a request to Kibana API.' });
}
});
}
if (method == "POST") {
$http.post(chrome.addBasePath(url), payload, requestHeaders)
.then(function (data) {
if (data.error && data.error != '0') {
defered.reject(data);
} else {
defered.resolve(data);
}
}, function (data) {
if (data.error && data.error != '0') {
defered.reject(data);
} else {
defered.reject({ 'error': -2, 'message': 'Error doing a request to Kibana API.' });
}
});
}
if (method == "DELETE") {
$http.delete(chrome.addBasePath(url))
.then(function (data) {
if (data.error && data.error != '0') {
defered.reject(data);
} else {
defered.resolve(data);
}
},function (data) {
if (data.error && data.error != '0') {
defered.reject(data);
} else {
defered.reject({ 'error': -2, 'message': 'Error doing a request to Kibana API.' });
}
});
}
return promise;
};
var prepError = function (err) {
if (err.error < 0) {
err['html'] = "Unexpected error located on controller. Error: <b>" + err.message + " (code " + err.error + ")</b>.";
err.message = "Unexpected error located on controller. Error: " + err.message + " (code " + err.error + ").";
} else if (err.error === 1) {
err['html'] = "<b>Error getting credentials</b> for Wazuh API. Please, check credentials at settings tab.";
err.message = "Error getting credentials for Wazuh API. Please, check credentials at settings tab.";
} else if (err.error === 2) {
err['html'] = "<b>Error getting credentials</b> for Wazuh API. Could not connect with Elasticsearch.";
err.message = "Error getting credentials for Wazuh API. Could not connect with Elasticsearch.";
} else if (err.error < 5) {
err['html'] = "Unexpected error located on Kibana server. Error: <b>" + err.message + " (code " + err.error + ")</b>.";
err.message = "Unexpected error located on Kibana server. Error: " + err.message + " (code " + err.error + ").";
} else if (err.error === 5) {
err['html'] = "Could not connect with Wazuh API. Error: " + err.errorMessage + ".</br> Please, check the URL at settings tab.";
err.message = "Could not connect with Wazuh API. Error: " + err.errorMessage + ". Please, check the URL at settings tab.";
} else if (err.error === 6) {
if (err.errorData.statusCode && err.errorData.statusCode == '404') {
err['html'] = "Wazuh API URL could not be found on elasticsearch. Please, configure the application properly.";
err.message = "Wazuh API URL could not be found on elasticsearch. Please, configure the application properly.";
} else {
err['html'] = "Wazuh API returned an error message. Error: <b>" + err.errorData.message + "</b>";
err.message = "Wazuh API returned an error message. Error: " + err.errorData.message;
}
} else if (err.error === 7) {
err['html'] = "Unexpected error filtering the data. Error <b>" + err.message + "</b>.";
err.message = "Unexpected error filtering the data. Error " + err.message + ".";
} else {
err['html'] = "Unexpected error. Please, report this error.";
err.message = "Unexpected error. Please, report this error.";
}
return err;
};
return {
request: function (method, path, payload = null) {
var defered = $q.defer();
var promise = defered.promise;
if (!method || !path) {
defered.reject(prepError({ 'error': -1, 'message': 'Missing parameters' }));
return promise;
}
_request(method, path, payload)
.then(function (data) {
defered.resolve(data);
}, function (data) {
defered.reject(prepError(data));
});
return promise;
}
};
});

View File

@ -2,43 +2,40 @@
var routes = require('ui/routes');
//Installation wizard
var settingsWizard = function ($location, testConnection, appState, $q, genericReq, Notifier) {
var settingsWizard = function ($location, $q, Notifier, testAPI, appState) {
const notify = new Notifier();
var deferred = $q.defer();
testConnection.check_stored().then(
function (data)
{
console.log(data);
appState.setClusterInfo(data.data.cluster_info);
appState.setExtensions(data.data.extensions);
deferred.resolve();
}, function (data) {
if(data.error == 2)
notify.warning("Wazuh App: Please set up Wazuh API credentials.");
else
notify.error("Could not connect with Wazuh RESTful API.");
testAPI.check_stored().then(
function (data) {
if (data.data.error) {
if(data.data.error == 2)
notify.warning("Wazuh App: Please set up Wazuh API credentials.");
else
notify.error("Could not connect with Wazuh RESTful API.");
deferred.reject();
$location.path('/settings');
});
deferred.reject();
$location.path('/settings');
} else {
appState.setClusterInfo(data.data.data.cluster_info);
appState.setExtensions(data.data.data.extensions);
deferred.resolve();
}
}, function (data) {
notify.error("Could not connect with Wazuh RESTful API.");
});
return deferred.promise;
}
// Manage leaving the app to another Kibana tab
var goToKibana = function ($location, $window) {
var url = '';
url = url + $location.$$absUrl.substring(0, $location.$$absUrl.indexOf('#'));
var url = $location.$$absUrl.substring(0, $location.$$absUrl.indexOf('#'));
if(sessionStorage.getItem('lastSubUrl:' + url).includes('/wazuh#/visualize') ||
sessionStorage.getItem('lastSubUrl:' + url).includes('/wazuh#/doc') ||
sessionStorage.getItem('lastSubUrl:' + url).includes('/wazuh#/context')){
if(sessionStorage.getItem('lastSubUrl:' + url).includes('/wazuh#/visualize') || sessionStorage.getItem('lastSubUrl:' + url).includes('/wazuh#/doc') || sessionStorage.getItem('lastSubUrl:' + url).includes('/wazuh#/context'))
sessionStorage.setItem('lastSubUrl:' + url, url);
}
$window.location.href=$location.absUrl().replace('/wazuh#', '/kibana#');
}
$window.location.href = $location.absUrl().replace('/wazuh#', '/kibana#');
}
//Routes
routes.enable();
@ -46,64 +43,55 @@ routes
.when('/agents/:id?/:tab?/:view?', {
template: require('plugins/wazuh/templates/agents.jade'),
resolve: {
"check": settingsWizard
"checkAPI": settingsWizard
}
})
.when('/manager/:tab?/', {
template: require('plugins/wazuh/templates/manager.jade'),
resolve: {
"check": settingsWizard
"checkAPI": settingsWizard
}
})
.when('/overview/:tab?/:view?', {
.when('/overview/', {
template: require('plugins/wazuh/templates/overview.jade'),
resolve: {
"check": settingsWizard
}
})
.when('/dashboards/', {
template: require('plugins/wazuh/templates/dashboards.jade'),
resolve: {
"check": settingsWizard
"checkAPI": settingsWizard
}
})
.when('/dashboard/:select?', {
template: require('plugins/wazuh/templates/dashboards.jade'),
resolve: {
"check": settingsWizard
"checkAPI": settingsWizard
}
})
.when('/discover/', {
template: require('plugins/wazuh/templates/discover.jade'),
resolve: {
"check": settingsWizard
"checkAPI": settingsWizard
}
})
.when('/settings/:tab?/', {
template: require('plugins/wazuh/templates/settings.html')
})
.when('/test/', {
template: require('plugins/wazuh/templates/test.html')
})
.when('/visualize/create?', {
redirectTo: function() {
},
resolve: {
"check": goToKibana
"checkAPI": goToKibana
}
})
.when('/context/:pattern?/:type?/:id?', {
redirectTo: function() {
},
resolve: {
"check": goToKibana
"checkAPI": goToKibana
}
})
.when('/doc/:pattern?/:index?/:type?/:id?', {
redirectTo: function() {
},
resolve: {
"check": goToKibana
"checkAPI": goToKibana
}
})
.when('/', {

View File

@ -1,40 +1,36 @@
import chrome from 'ui/chrome';
require('ui/modules').get('app/wazuh', [])
.service('testConnection', function ($q, $http) {
return {
check_stored: function () {
var defered = $q.defer();
var promise = defered.promise;
$http.get(chrome.addBasePath("/api/wazuh-api/check")).then(function successCallback(response) {
if (response.error) {
defered.reject(response);
} else {
defered.resolve(response);
}
}, function errorCallback(response) {
if (response.error) {
defered.reject(response);
}
});
return promise;
},
check: function (data) {
var defered = $q.defer();
var promise = defered.promise;
$http.post(chrome.addBasePath("/api/wazuh-api/check"), data).then(function successCallback(response) {
if (response.error) {
defered.reject(response);
} else {
defered.resolve(response);
}
}, function errorCallback(response) {
if (response.error) {
defered.reject(response);
}
});
return promise;
}
};
});
import chrome from 'ui/chrome';
require('ui/modules').get('app/wazuh', [])
.service('testAPI', function ($q, $http) {
return {
check_stored: function () {
var defered = $q.defer();
$http.get(chrome.addBasePath("/api/wazuh-api/checkAPI")).then(function successCallback(response) {
if (response.error) {
defered.reject(response);
} else {
defered.resolve(response);
}
}, function errorCallback(response) {
if (response.error) {
defered.reject(response);
}
});
return defered.promise;
},
check: function (data) {
var defered = $q.defer();
$http.post(chrome.addBasePath("/api/wazuh-api/checkAPI"), data).then(function successCallback(response) {
if (response.error) {
defered.reject(response);
} else {
defered.resolve(response);
}
}, function errorCallback(response) {
if (response.error) {
defered.reject(response);
}
});
return defered.promise;
}
};
});

View File

@ -1,70 +1,70 @@
require('ui/modules').get('app/wazuh', [])
.config(function ($mdThemingProvider) {
var kibanaWhiteBlack = {
'50': '#ffffff',
'100': '#ffffff',
'200': '#ffffff',
'300': '#ffffff',
'400': '#fafafa',
'500': '#ecf0f1',
'600': '#dde4e6',
'700': '#cfd9db',
'800': '#c0cdd1',
'900': '#000000',
'A100': '#ffffff',
'A200': '#ffffff',
'A400': '#ffffff',
'A700': '#a3b6bb'
};
$mdThemingProvider
.definePalette('kibanaWhiteBlack',
kibanaWhiteBlack);
var kibanaBlue = {
'50': '#a4d9ea',
'100': '#8fd0e5',
'200': '#7ac8e0',
'300': '#65bfdc',
'400': '#51b7d7',
'500': '#3caed2',
'600': '#2ea2c7',
'700': '#2991b2',
'800': '#24809d',
'900': '#206f88',
'A100': '#b8e2ef',
'A200': '#cdeaf3',
'A400': '#e2f3f8',
'A700': '#1b5e74',
'contrastDefaultColor': 'dark',
};
$mdThemingProvider
.definePalette('kibanaBlue',
kibanaBlue);
$mdThemingProvider.theme('default')
.primaryPalette('blue-grey', {
'default': '100',
'hue-1': '300',
'hue-2': '500',
'hue-3': '700'
})
.accentPalette('kibanaBlue', {
'default': '500',
'hue-1': '800',
'hue-2': '300',
'hue-3': '100'
})
.warnPalette('amber', {
'default': '300',
'hue-1': '500',
'hue-2': '700',
'hue-3': '900'
})
.backgroundPalette('kibanaWhiteBlack', {
'default': '50',
'hue-1': '50',
'hue-2': '600',
'hue-3': '900'
})
});
require('ui/modules').get('app/wazuh', [])
.config(function ($mdThemingProvider) {
var kibanaWhiteBlack = {
'50': '#ffffff',
'100': '#ffffff',
'200': '#ffffff',
'300': '#ffffff',
'400': '#fafafa',
'500': '#ecf0f1',
'600': '#dde4e6',
'700': '#cfd9db',
'800': '#c0cdd1',
'900': '#000000',
'A100': '#ffffff',
'A200': '#ffffff',
'A400': '#ffffff',
'A700': '#a3b6bb'
};
$mdThemingProvider
.definePalette('kibanaWhiteBlack',
kibanaWhiteBlack);
var kibanaBlue = {
'50': '#a4d9ea',
'100': '#8fd0e5',
'200': '#7ac8e0',
'300': '#65bfdc',
'400': '#51b7d7',
'500': '#3caed2',
'600': '#2ea2c7',
'700': '#2991b2',
'800': '#24809d',
'900': '#206f88',
'A100': '#b8e2ef',
'A200': '#cdeaf3',
'A400': '#e2f3f8',
'A700': '#1b5e74',
'contrastDefaultColor': 'dark',
};
$mdThemingProvider
.definePalette('kibanaBlue',
kibanaBlue);
$mdThemingProvider.theme('default')
.primaryPalette('blue-grey', {
'default': '100',
'hue-1': '300',
'hue-2': '500',
'hue-3': '700'
})
.accentPalette('kibanaBlue', {
'default': '500',
'hue-1': '800',
'hue-2': '300',
'hue-3': '100'
})
.warnPalette('amber', {
'default': '300',
'hue-1': '500',
'hue-2': '700',
'hue-3': '900'
})
.backgroundPalette('kibanaWhiteBlack', {
'default': '50',
'hue-1': '50',
'hue-2': '600',
'hue-3': '900'
})
});