2016-11-23 21:29:44 +00:00
|
|
|
import rison from 'rison-node';
|
|
|
|
import FilterBarQueryFilterProvider from 'ui/filter_bar/query_filter';
|
|
|
|
import StateProvider from 'ui/state_management/state';
|
|
|
|
import AggTypesBucketsIntervalOptionsProvider from 'ui/agg_types/buckets/_interval_options';
|
|
|
|
|
|
|
|
var app = require('ui/modules').get('app/wazuh', [])
|
|
|
|
.directive('kbnSearchbar', [function () {
|
|
|
|
return {
|
|
|
|
restrict: 'E',
|
|
|
|
scope: {
|
|
|
|
visType: '@visType',
|
|
|
|
visIndexPattern: '@visIndexPattern',
|
|
|
|
visA: '@visA',
|
|
|
|
visG: '@visG',
|
|
|
|
visFilter: '@visFilter',
|
|
|
|
visHeight: '@visHeight',
|
|
|
|
visWidth: '@visWidth',
|
|
|
|
visSearchable: '@visSearchable',
|
|
|
|
visClickable: '@visClickable'
|
|
|
|
},
|
|
|
|
template: require('../templates/directives/kibana-searchbar-template.html')
|
|
|
|
}
|
|
|
|
}]);
|
|
|
|
|
2017-01-26 15:35:07 +00:00
|
|
|
require('ui/modules').get('app/wazuh', []).controller('kibanaSearchBar', function (genericReq, $compile, $scope, $route, timefilter, AppState, appState, $location, kbnUrl, $timeout, courier, Private, Promise, savedVisualizations, SavedVis, getAppState, Notifier, $rootScope) {
|
2016-11-23 21:29:44 +00:00
|
|
|
|
|
|
|
$scope.stateQuery = $scope.disFilter;
|
|
|
|
|
|
|
|
$route.reloadOnSearch = true;
|
|
|
|
|
|
|
|
timefilter.enabled = true;
|
2016-11-24 00:04:52 +00:00
|
|
|
|
2016-12-05 17:32:59 +00:00
|
|
|
|
2017-01-26 15:35:07 +00:00
|
|
|
$scope.displayPCI = function (requirement){
|
|
|
|
var pciRequirementBox = document.querySelector("#pciRequirementBox");
|
|
|
|
var pciRequirementBox_ReqTitle = document.querySelector("#pciRequirementBox_ReqTitle");
|
|
|
|
|
|
|
|
genericReq.request('GET', '/api/wazuh-api/pci/'+requirement).then(function (data) {
|
|
|
|
pciRequirementBox_ReqTitle.innerText = requirement;
|
|
|
|
pciRequirementBox_ReqContent.innerHTML = data.pci.description;
|
|
|
|
angular.element(pciRequirementBox).show();
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function injectPciIcon(){
|
|
|
|
// Get all filters on filter bar
|
|
|
|
var filters = document.querySelectorAll(".filter-bar .filter");
|
|
|
|
// Analyze each filter
|
|
|
|
filters.forEach(function(item) {
|
|
|
|
if(angular.element(item).data('pci') != "1"){
|
|
|
|
var filterLabel = item.querySelectorAll(".filter-description .ng-scope");
|
|
|
|
filterLabel.forEach(function(item) {
|
|
|
|
if(item.innerText == "rule.pci_dss:"){
|
|
|
|
// Preparing and adding new element to filter actions icons
|
|
|
|
var pciLink = angular.element('<a class="action" ng-click=\'displayPCI('+item.nextElementSibling.innerText+')\'><img src="/plugins/wazuh/img/icon_pci.png"></a>');
|
|
|
|
// Append the new element
|
|
|
|
angular.element(pciLink).appendTo(item.parentNode.nextElementSibling);
|
|
|
|
// Compile element to enable ng click
|
|
|
|
$compile(angular.element(item.parentNode.nextElementSibling).contents())($scope);
|
|
|
|
// Setup min width when adding new icon
|
|
|
|
angular.element(item.parentNode.parentNode).css("min-width","calc(6*(1.414em + 13px))");
|
|
|
|
angular.element(item.parentNode.parentNode).attr('data-pci','1');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-11-24 00:04:52 +00:00
|
|
|
|
2017-01-26 15:35:07 +00:00
|
|
|
// create an observer instance
|
|
|
|
var observer = new MutationObserver(function(mutations) {
|
|
|
|
mutations.forEach(function(mutation) {
|
|
|
|
console.log("watching!");
|
|
|
|
injectPciIcon();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
var config = { childList: true };
|
|
|
|
|
|
|
|
|
2016-11-24 00:04:52 +00:00
|
|
|
// Set default time
|
2016-12-05 17:32:59 +00:00
|
|
|
if($route.current.params._g == "()"){
|
|
|
|
timefilter.time.from = "now-24h";
|
|
|
|
timefilter.time.to = "now";
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.timefilter = timefilter;
|
2016-11-24 00:04:52 +00:00
|
|
|
|
|
|
|
let $state = $scope.$state = (function initState() {
|
2016-12-04 16:34:04 +00:00
|
|
|
$state = new AppState();
|
2016-11-24 00:04:52 +00:00
|
|
|
return $state;
|
|
|
|
} ());
|
2016-11-23 21:29:44 +00:00
|
|
|
|
|
|
|
// Fetch / reload visualization
|
|
|
|
$scope.fetch = function ()
|
|
|
|
{
|
2016-11-24 19:53:24 +00:00
|
|
|
$rootScope.$broadcast('updateQuery',$scope.stateQuery);
|
2016-11-23 21:29:44 +00:00
|
|
|
};
|
2016-11-24 19:53:24 +00:00
|
|
|
|
|
|
|
// Watch visCounter, wait for finish and fetch.
|
2016-11-28 16:26:30 +00:00
|
|
|
var visCounterWatch = $rootScope.$watch('visCounter', function (data) {
|
2016-12-04 16:34:04 +00:00
|
|
|
|
2016-11-24 19:53:24 +00:00
|
|
|
if($rootScope.visCounter == 0){
|
|
|
|
$timeout(
|
|
|
|
function() {
|
2017-01-26 15:35:07 +00:00
|
|
|
var watchFilterBar = document.querySelectorAll(".filter-bar")[0];
|
|
|
|
observer.observe(watchFilterBar, config);
|
|
|
|
$rootScope.$broadcast('fetchVisualization');
|
2016-11-24 19:53:24 +00:00
|
|
|
}, 0);
|
|
|
|
}
|
2016-11-23 21:29:44 +00:00
|
|
|
|
2016-11-24 19:53:24 +00:00
|
|
|
});
|
2017-01-26 15:35:07 +00:00
|
|
|
|
2016-11-28 16:26:30 +00:00
|
|
|
// Listen for destroy
|
|
|
|
$scope.$on('$destroy', visCounterWatch);
|
2016-11-23 21:29:44 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|