mirror of
https://github.com/valitydev/wazuh-kibana-app.git
synced 2024-11-07 02:15:24 +00:00
Adapting ruleset to paginated tables and event searching
This commit is contained in:
parent
6b2b374776
commit
a8f78c69f4
@ -15,6 +15,44 @@ import * as FileSaver from '../services/file-saver'
|
||||
const app = uiModules.get('app/wazuh', []);
|
||||
|
||||
app.controller('rulesController', function ($timeout, $scope, $rootScope, $sce, Rules, RulesRelated, RulesAutoComplete, errorHandler, genericReq, appState, csvReq) {
|
||||
$scope.appliedFilters = [];
|
||||
$scope.search = term => {
|
||||
if(term.startsWith('group:') && term.split('group:')[1].trim()) {
|
||||
$scope.custom_search = ''
|
||||
const filter = {name:'group',value:term.split('group:')[1].trim()};
|
||||
$scope.appliedFilters.push(filter)
|
||||
$scope.$broadcast('wazuhFilter',{filter})
|
||||
} else if(term.startsWith('level:') && term.split('level:')[1].trim()) {
|
||||
$scope.custom_search = ''
|
||||
const filter = {name:'level',value:term.split('level:')[1].trim()};
|
||||
$scope.appliedFilters.push(filter)
|
||||
$scope.$broadcast('wazuhFilter',{filter})
|
||||
} else if(term.startsWith('pci:') && term.split('pci:')[1].trim()) {
|
||||
$scope.custom_search = ''
|
||||
const filter = {name:'pci',value:term.split('pci:')[1].trim()};
|
||||
$scope.appliedFilters.push(filter)
|
||||
$scope.$broadcast('wazuhFilter',{filter})
|
||||
} else if(term.startsWith('gdpr:') && term.split('gdpr:')[1].trim()) {
|
||||
$scope.custom_search = ''
|
||||
const filter = {name:'gdpr',value:term.split('gdpr:')[1].trim()};
|
||||
$scope.appliedFilters.push(filter)
|
||||
$scope.$broadcast('wazuhFilter',{filter})
|
||||
} else if(term.startsWith('file:') && term.split('file:')[1].trim()) {
|
||||
$scope.custom_search = ''
|
||||
const filter = {name:'file',value:term.split('file:')[1].trim()};
|
||||
$scope.appliedFilters.push(filter)
|
||||
$scope.$broadcast('wazuhFilter',{filter})
|
||||
} else {
|
||||
$scope.$broadcast('wazuhSearch',{term,removeFilters: true})
|
||||
}
|
||||
}
|
||||
|
||||
$scope.includesFilter = filterName => $scope.appliedFilters.filter(item => item.name === filterName).length;
|
||||
$scope.getFilter = filterName => $scope.appliedFilters.filter(item => item.name === filterName)[0].value;
|
||||
$scope.removeFilter = filterName => {
|
||||
$scope.appliedFilters = $scope.appliedFilters.filter(item => item.name !== filterName);
|
||||
return $scope.$broadcast('wazuhRemoveFilter',{filterName});
|
||||
}
|
||||
|
||||
$scope.setRulesTab = tab => $rootScope.globalsubmenuNavItem2 = tab;
|
||||
|
||||
@ -59,35 +97,6 @@ app.controller('rulesController', function ($timeout, $scope, $rootScope, $sce,
|
||||
if(!$scope.$$phase) $scope.$digest();
|
||||
});
|
||||
|
||||
$scope.analyzeRules = async search => {
|
||||
|
||||
try {
|
||||
if(search && search.length <= 1) return $scope.rulesAutoComplete.items;
|
||||
await $timeout(200);
|
||||
$scope.rulesAutoComplete.filters = [];
|
||||
|
||||
if(search.startsWith('group:') && search.split('group:')[1].trim()) {
|
||||
await $scope.rulesAutoComplete.addFilter('group',search.split('group:')[1].trim());
|
||||
} else if(search.startsWith('level:') && search.split('level:')[1].trim()) {
|
||||
await $scope.rulesAutoComplete.addFilter('level',search.split('level:')[1].trim());
|
||||
} else if(search.startsWith('pci:') && search.split('pci:')[1].trim()) {
|
||||
await $scope.rulesAutoComplete.addFilter('pci',search.split('pci:')[1].trim());
|
||||
} else if(search.startsWith('gdpr:') && search.split('gdpr:')[1].trim()) {
|
||||
await $scope.rulesAutoComplete.addFilter('gdpr',search.split('gdpr:')[1].trim());
|
||||
} else if(search.startsWith('file:') && search.split('file:')[1].trim()) {
|
||||
await $scope.rulesAutoComplete.addFilter('file',search.split('file:')[1].trim());
|
||||
} else {
|
||||
await $scope.rulesAutoComplete.addFilter('search',search);
|
||||
}
|
||||
|
||||
if(!$scope.$$phase) $scope.$digest();
|
||||
return $scope.rulesAutoComplete.items;
|
||||
} catch (error){
|
||||
errorHandler.handle(error,'Ruleset');
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
$scope.checkEnter = search => {
|
||||
$scope.searchTerm = '';
|
||||
angular.element(document.querySelector('#autocomplete')).blur();
|
||||
@ -112,7 +121,7 @@ app.controller('rulesController', function ($timeout, $scope, $rootScope, $sce,
|
||||
try {
|
||||
errorHandler.info('Your download should begin automatically...', 'CSV')
|
||||
const currentApi = JSON.parse(appState.getCurrentAPI()).id;
|
||||
const output = await csvReq.fetch('/rules', currentApi, $scope.rules ? $scope.rules.filters : null);
|
||||
const output = await csvReq.fetch('/rules', currentApi, null);
|
||||
const blob = new Blob([output], {type: 'text/csv'});
|
||||
|
||||
FileSaver.saveAs(blob, 'rules.csv');
|
||||
|
@ -105,7 +105,7 @@ app.directive('wazuhTable', function() {
|
||||
|
||||
$scope.sort = async field => {
|
||||
$scope.wazuh_table_loading = true;
|
||||
instance.addSorting(field);
|
||||
instance.addSorting(field.value || field);
|
||||
$scope.sortValue = instance.sortValue;
|
||||
$scope.sortDir = instance.sortDir;
|
||||
items = await instance.fetch();
|
||||
@ -116,8 +116,9 @@ app.directive('wazuhTable', function() {
|
||||
if(!$scope.$$phase) $scope.$digest()
|
||||
}
|
||||
|
||||
const search = async term => {
|
||||
const search = async (term, removeFilters) => {
|
||||
$scope.wazuh_table_loading = true;
|
||||
if(removeFilters) instance.removeFilters();
|
||||
instance.addFilter('search',term);
|
||||
items = await instance.fetch();
|
||||
$scope.items = items;
|
||||
@ -151,7 +152,12 @@ app.directive('wazuhTable', function() {
|
||||
})
|
||||
|
||||
$scope.$on('wazuhSearch',(event,parameters) => {
|
||||
return search(parameters.term)
|
||||
return search(parameters.term,parameters.removeFilters)
|
||||
})
|
||||
|
||||
$scope.$on('wazuhRemoveFilter',(event,parameters) => {
|
||||
instance.filters = instance.filters.filter(item => item.name !== parameters.filterName);
|
||||
return init();
|
||||
})
|
||||
|
||||
const realTimeFunction = async () => {
|
||||
|
@ -15,6 +15,10 @@ export default {
|
||||
merged_sum: 'MD5 agent.conf',
|
||||
hash: 'MD5 agent.conf',
|
||||
filename: 'File',
|
||||
file:'File',
|
||||
gdpr: 'GDPR',
|
||||
pci: 'PCI',
|
||||
groups: 'Groups',
|
||||
name: 'Name',
|
||||
count: 'Count'
|
||||
}
|
@ -2,7 +2,7 @@
|
||||
<div layout="row" class="md-padding" ng-show="wazuh_table_loading" >
|
||||
<md-progress-linear class="md-accent" md-mode="indeterminate"></md-progress-linear>
|
||||
</div>
|
||||
<div layout="row" ng-show="!wazuh_table_loading && items.length" class="md-padding">
|
||||
<div layout="row" ng-show="!wazuh_table_loading && items.length">
|
||||
<table class="table table-striped table-condensed" style="table-layout: fixed !important" id="wz_table">
|
||||
<thead class="wz-text-bold">
|
||||
<th ng-repeat="key in keys" class="wz-text-left" ng-class="key.size ? 'col-lg-' + key.size : 'col-lg-1'" ng-click="!key.nosortable && sort(key)">
|
||||
@ -12,8 +12,8 @@
|
||||
</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr ng-class="allowClick ? 'wz-table-cursor-pointer' : ''" ng-repeat="item in pagedItems[currentPage]" ng-click="clickAction(item)">
|
||||
<td ng-repeat="key in keys">{{ key === 'os.name' ? item.os.name : key === 'os.version' ? item.os.version : item[key.value || key] }}</td>
|
||||
<tr ng-class="allowClick ? 'wz-table-cursor-pointer' : ''" class="wz-word-wrap" ng-repeat="item in pagedItems[currentPage]" ng-click="clickAction(item)">
|
||||
<td ng-repeat="key in keys">{{ key === 'os.name' ? item.os.name : key === 'os.version' ? item.os.version : item[key.value || key] || '---' }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
<tfoot ng-show="items.length >= itemsPerPage">
|
||||
|
@ -1,119 +1,62 @@
|
||||
<div ng-show="!loading && !viewingDetail" flex layout="column">
|
||||
<div id="content" layout="row" layout-align="start start">
|
||||
<span layout="row" flex layout-align="space-between center">
|
||||
<md-autocomplete flex class="wz-autocomplete wz-select-input wz-margin-right-8"
|
||||
id="Auto"
|
||||
md-input-id="autocomplete"
|
||||
md-select-on-match="true"
|
||||
md-no-cache="noCache"
|
||||
md-selected-item="filter"
|
||||
md-selected-item-change="rules.addFilter('search', filter.description)"
|
||||
md-search-text="searchTerm"
|
||||
md-items="rule in analyzeRules(searchTerm)"
|
||||
md-item-text="rule.file + ' - ' + rule.description"
|
||||
md-min-length="0"
|
||||
md-no-asterisk="false"
|
||||
md-menu-class="autocomplete-custom-agents-bar"
|
||||
md-search-text-change="analyzeRules(searchTerm)"
|
||||
placeholder="Search rules..."
|
||||
lazy-load-data="rulesAutoComplete.nextPage()"
|
||||
md-autofocus=""
|
||||
wz-enter="checkEnter(searchTerm)">
|
||||
<md-item-template>
|
||||
<span>
|
||||
<strong md-highlight-text="search" md-highlight-flags="i"> {{rule.file}} - {{rule.description}} </strong>
|
||||
</span>
|
||||
<span>
|
||||
<span ng-if="rule.type != 'pci'"> {{rule.type}} </span>
|
||||
<span ng-if="rule.type == 'pci'">PCI control</span>
|
||||
</span>
|
||||
</md-item-template>
|
||||
<md-not-found>
|
||||
No results matching "{{searchTerm}}" were found.
|
||||
</md-not-found>
|
||||
</md-autocomplete>
|
||||
</span>
|
||||
<div id="content" layout="row">
|
||||
<input flex="80" placeholder="Filter rules..." ng-model="custom_search" type="text" class="kuiLocalSearchInput ng-empty ng-pristine ng-scope ng-touched ng-valid wz-margin-top-4 height-36"
|
||||
aria-invalid="false" wz-enter="search(custom_search)">
|
||||
<button type="submit" aria-label="Search" class="kuiLocalSearchButton height-36 wz-margin-top-4" ng-click="search(custom_search)">
|
||||
<span class="fa fa-search" aria-hidden="true"></span>
|
||||
</button>
|
||||
|
||||
<md-button ng-class="(globalsubmenuNavItem2 == 'rules') ? 'active' : ''"
|
||||
|
||||
<md-button flex ng-class="(globalsubmenuNavItem2 == 'rules') ? 'active' : ''"
|
||||
ng-click="setRulesTab('rules')" class="wz-button md-raised md-primary manager-ruleset-btn" aria-label="Ruleset rules button">
|
||||
<i class="fa fa-fw fa-file-text-o" aria-hidden="true"></i> Rules
|
||||
</md-button>
|
||||
<md-button ng-class="(globalsubmenuNavItem2 == 'decoders') ? 'active' : ''"
|
||||
<md-button flex ng-class="(globalsubmenuNavItem2 == 'decoders') ? 'active' : ''"
|
||||
ng-click="setRulesTab('decoders')" class="wz-button md-raised md-primary manager-ruleset-btn" aria-label="Ruleset decoders button">
|
||||
<i class="fa fa-fw fa-search" aria-hidden="true"></i> Decoders
|
||||
</md-button>
|
||||
</div>
|
||||
|
||||
<md-chips readonly="true" ng-show="rules.hasFilter('level') || rules.hasFilter('search') || rules.hasFilter('file') || rules.hasFilter('path') || rules.hasFilter('group') || rules.hasFilter('pci') || rules.hasFilter('gdpr')">
|
||||
<md-chip class="wz-chip" ng-if="rules.hasFilter('search') && rules.getFilter('search')">
|
||||
<span>Search: {{rules.getFilter('search')}}
|
||||
<i class="fa fa-fw fa-times cursor-pointer" aria-hidden="true" ng-click="rules.removeFilter('search', true)"></i>
|
||||
<md-chips readonly="true" ng-show="appliedFilters.length">
|
||||
<md-chip class="wz-chip" ng-if="includesFilter('file')">
|
||||
<span>File: {{getFilter('file')}}
|
||||
<i class="fa fa-fw fa-times cursor-pointer" aria-hidden="true" ng-click="removeFilter('file')"></i>
|
||||
</span>
|
||||
</md-chip>
|
||||
<md-chip class="wz-chip" ng-if="rules.hasFilter('file')">
|
||||
<span>File: {{rules.getFilter('file')}}
|
||||
<i class="fa fa-fw fa-times cursor-pointer" aria-hidden="true" ng-click="rules.removeFilter('file', true)"></i>
|
||||
<md-chip class="wz-chip" ng-if="includesFilter('path')">
|
||||
<span>File: {{getFilter('path')}}
|
||||
<i class="fa fa-fw fa-times cursor-pointer" aria-hidden="true" ng-click="removeFilter('path')"></i>
|
||||
</span>
|
||||
</md-chip>
|
||||
<md-chip class="wz-chip" ng-if="rules.hasFilter('path')">
|
||||
<span>File: {{rules.getFilter('path')}}
|
||||
<i class="fa fa-fw fa-times cursor-pointer" aria-hidden="true" ng-click="rules.removeFilter('path', true)"></i>
|
||||
<md-chip class="wz-chip" ng-if="includesFilter('level')">
|
||||
<span>Level: {{getFilter('level')}}
|
||||
<i class="fa fa-fw fa-times cursor-pointer" aria-hidden="true" ng-click="removeFilter('level')"></i>
|
||||
</span>
|
||||
</md-chip>
|
||||
<md-chip class="wz-chip" ng-if="rules.hasFilter('level')">
|
||||
<span>Level: {{rules.getFilter('level')}}
|
||||
<i class="fa fa-fw fa-times cursor-pointer" aria-hidden="true" ng-click="rules.removeFilter('level', true)"></i>
|
||||
<md-chip class="wz-chip" ng-if="includesFilter('group')">
|
||||
<span>Group: {{getFilter('group')}}
|
||||
<i class="fa fa-fw fa-times cursor-pointer" aria-hidden="true" ng-click="removeFilter('group')"></i>
|
||||
</span>
|
||||
</md-chip>
|
||||
<md-chip class="wz-chip" ng-if="rules.hasFilter('group')">
|
||||
<span>Group: {{rules.getFilter('group')}}
|
||||
<i class="fa fa-fw fa-times cursor-pointer" aria-hidden="true" ng-click="rules.removeFilter('group', true)"></i>
|
||||
<md-chip class="wz-chip" ng-if="includesFilter('pci')">
|
||||
<span>PCI control: {{getFilter('pci')}}
|
||||
<i class="fa fa-fw fa-times cursor-pointer" aria-hidden="true" ng-click="removeFilter('pci')"></i>
|
||||
</span>
|
||||
</md-chip>
|
||||
<md-chip class="wz-chip" ng-if="rules.hasFilter('pci')">
|
||||
<span>PCI control: {{rules.getFilter('pci')}}
|
||||
<i class="fa fa-fw fa-times cursor-pointer" aria-hidden="true" ng-click="rules.removeFilter('pci', true)"></i>
|
||||
</span>
|
||||
</md-chip>
|
||||
<md-chip class="wz-chip" ng-if="rules.hasFilter('gdpr')">
|
||||
<span>GDPR: {{rules.getFilter('gdpr')}}
|
||||
<i class="fa fa-fw fa-times cursor-pointer" aria-hidden="true" ng-click="rules.removeFilter('gdpr', true)"></i>
|
||||
<md-chip class="wz-chip" ng-if="includesFilter('gdpr')">
|
||||
<span>GDPR: {{getFilter('gdpr')}}
|
||||
<i class="fa fa-fw fa-times cursor-pointer" aria-hidden="true" ng-click="removeFilter('gdpr')"></i>
|
||||
</span>
|
||||
</md-chip>
|
||||
</md-chips>
|
||||
|
||||
<wz-table-header
|
||||
layout="row"
|
||||
data="rules"
|
||||
keys="[
|
||||
{name:'ID',sortValue:'id',size:5},
|
||||
{name:'File',sortValue:'file',size:15},
|
||||
{name:'Description',sortValue:'description',size:30},
|
||||
{name:'Groups',size:25},
|
||||
{name:'PCI',size:10},
|
||||
{name:'GDPR',size:10},
|
||||
{name:'Level',sortValue:'level',size:5}
|
||||
]">
|
||||
</wz-table-header>
|
||||
<wz-table
|
||||
layout="column"
|
||||
flex
|
||||
func="openDetailView(rule)"
|
||||
data="rules"
|
||||
full="'rule'"
|
||||
keys="[
|
||||
{col:'id',size:5},
|
||||
{col:'file',size:15},
|
||||
{col:'description',size:30},
|
||||
{col:'groups',size:25},
|
||||
{col:'pci',size:10},
|
||||
{col:'gdpr',size:10},
|
||||
{col:'level',size:5}
|
||||
]"
|
||||
isruleset="true"
|
||||
isdecoders="false"
|
||||
class="no-lateral-padding">
|
||||
</wz-table>
|
||||
<div layout="row">
|
||||
<wazuh-table
|
||||
flex
|
||||
path="'/rules'"
|
||||
keys="['id',{value:'file',size:2},{value:'description',size:2},{value:'groups',nosortable:true,size:2},{value:'pci',nosortable:true,size:2},{value:'gdpr',nosortable:true},'level']" allow-click="true">
|
||||
</wazuh-table>
|
||||
</div>
|
||||
|
||||
<div layout="row" class="wz-margin-top-10">
|
||||
<span flex></span>
|
||||
|
Loading…
Reference in New Issue
Block a user