2018-04-22 20:16:38 +00:00
|
|
|
/*
|
|
|
|
* Wazuh app - Ruleset controllers
|
|
|
|
* Copyright (C) 2018 Wazuh, Inc.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Find more information about this on the LICENSE file.
|
|
|
|
*/
|
2018-04-21 11:31:47 +00:00
|
|
|
import * as modules from 'ui/modules'
|
|
|
|
|
|
|
|
const app = modules.get('app/wazuh', []);
|
2016-12-28 19:43:33 +00:00
|
|
|
|
2018-04-09 17:11:22 +00:00
|
|
|
app.controller('rulesController', function ($scope, $rootScope, Rules,RulesAutoComplete, errorHandler, genericReq, appState) {
|
|
|
|
|
2018-01-29 12:16:59 +00:00
|
|
|
$scope.setRulesTab = tab => $rootScope.globalsubmenuNavItem2 = tab;
|
2018-04-22 20:16:38 +00:00
|
|
|
|
2017-01-16 18:27:53 +00:00
|
|
|
//Initialization
|
2017-10-20 19:04:22 +00:00
|
|
|
$scope.loading = true;
|
2017-10-27 11:39:25 +00:00
|
|
|
$scope.rules = Rules;
|
2018-01-29 11:37:29 +00:00
|
|
|
$scope.rulesAutoComplete = RulesAutoComplete;
|
2017-10-27 11:39:25 +00:00
|
|
|
$scope.setRulesTab('rules');
|
2018-01-29 11:37:29 +00:00
|
|
|
$rootScope.tabVisualizations = { ruleset: 4 };
|
|
|
|
$scope.analizeRules = async search => {
|
|
|
|
try {
|
|
|
|
$scope.rulesAutoComplete.filters = [];
|
2018-04-22 20:16:38 +00:00
|
|
|
|
2018-01-29 11:37:29 +00:00
|
|
|
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('file:') && search.split('file:')[1].trim()) {
|
|
|
|
await $scope.rulesAutoComplete.addFilter('file',search.split('file:')[1].trim());
|
|
|
|
} else {
|
|
|
|
await $scope.rulesAutoComplete.addFilter('search',search);
|
|
|
|
}
|
2018-04-22 20:16:38 +00:00
|
|
|
|
2018-01-29 11:37:29 +00:00
|
|
|
if(!$scope.$$phase) $scope.$digest();
|
|
|
|
return $scope.rulesAutoComplete.items;
|
|
|
|
} catch (error){
|
2018-01-29 14:39:21 +00:00
|
|
|
errorHandler.handle(error,'Ruleset');
|
2018-01-29 12:16:59 +00:00
|
|
|
if(!$rootScope.$$phase) $rootScope.$digest();
|
2017-10-27 11:39:25 +00:00
|
|
|
}
|
2017-12-12 16:05:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$scope.checkEnter = search => {
|
|
|
|
$scope.searchTerm = '';
|
|
|
|
angular.element(document.querySelector('#autocomplete')).blur();
|
|
|
|
if(search.startsWith('group:') && search.split('group:')[1].trim()) {
|
|
|
|
$scope.rules.addFilter('group',search.split('group:')[1].trim());
|
|
|
|
} else if(search.startsWith('level:') && search.split('level:')[1].trim()) {
|
|
|
|
$scope.rules.addFilter('level',search.split('level:')[1].trim());
|
|
|
|
} else if(search.startsWith('pci:') && search.split('pci:')[1].trim()) {
|
|
|
|
$scope.rules.addFilter('pci',search.split('pci:')[1].trim());
|
|
|
|
} else if(search.startsWith('file:') && search.split('file:')[1].trim()) {
|
|
|
|
$scope.rules.addFilter('file',search.split('file:')[1].trim());
|
2018-01-15 15:33:12 +00:00
|
|
|
} else {
|
|
|
|
$scope.rules.addFilter('search',search.trim());
|
2017-12-12 16:05:52 +00:00
|
|
|
}
|
2016-11-03 19:52:52 +00:00
|
|
|
};
|
|
|
|
|
2017-12-12 16:05:52 +00:00
|
|
|
|
2018-01-29 11:37:29 +00:00
|
|
|
const load = async () => {
|
|
|
|
try {
|
2018-04-18 12:39:45 +00:00
|
|
|
$rootScope.rawVisualizations = null;
|
2018-04-23 11:05:16 +00:00
|
|
|
const data = await genericReq.request('GET',`/api/wazuh-elastic/create-vis/manager-ruleset-rules/${appState.getCurrentPattern()}`)
|
2018-04-18 12:39:45 +00:00
|
|
|
$rootScope.rawVisualizations = data.data.raw;
|
2018-04-09 17:11:22 +00:00
|
|
|
// Render visualizations
|
|
|
|
$rootScope.$broadcast('updateVis');
|
|
|
|
if(!$rootScope.$$phase) $rootScope.$digest();
|
|
|
|
|
2018-01-29 11:37:29 +00:00
|
|
|
await Promise.all([
|
|
|
|
$scope.rules.nextPage(),
|
|
|
|
$scope.rulesAutoComplete.nextPage()
|
|
|
|
]);
|
|
|
|
$scope.loading = false;
|
|
|
|
if(!$scope.$$phase) $scope.$digest();
|
|
|
|
return;
|
|
|
|
} catch (error) {
|
2018-01-29 14:39:21 +00:00
|
|
|
errorHandler.handle('Unexpected exception loading controller','Ruleset');
|
2018-01-29 12:16:59 +00:00
|
|
|
if(!$rootScope.$$phase) $rootScope.$digest();
|
2018-01-29 11:37:29 +00:00
|
|
|
}
|
2016-11-03 19:52:52 +00:00
|
|
|
}
|
2017-10-27 11:39:25 +00:00
|
|
|
|
2018-01-29 11:37:29 +00:00
|
|
|
//Load
|
|
|
|
load();
|
|
|
|
|
2017-11-30 15:29:45 +00:00
|
|
|
let timesOpened = 0;
|
|
|
|
let lastName = false;
|
2018-02-15 11:00:49 +00:00
|
|
|
$scope.closeOther = rule => {
|
|
|
|
const item = rule.id ? rule.id : rule;
|
|
|
|
if(item !== lastName){
|
|
|
|
lastName = item;
|
2017-11-30 15:29:45 +00:00
|
|
|
timesOpened = 0;
|
|
|
|
}
|
|
|
|
timesOpened++;
|
2018-02-15 11:00:49 +00:00
|
|
|
$scope.activeItem = (timesOpened <= 1) ? item : false;
|
2017-11-30 15:29:45 +00:00
|
|
|
if(timesOpened > 1) timesOpened = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-03 19:52:52 +00:00
|
|
|
//Destroy
|
2018-01-08 16:12:06 +00:00
|
|
|
$scope.$on('$destroy', () => {
|
2018-04-18 12:39:45 +00:00
|
|
|
$rootScope.rawVisualizations = null;
|
2018-01-08 16:12:06 +00:00
|
|
|
$scope.rules.reset();
|
2018-01-29 11:37:29 +00:00
|
|
|
if($rootScope.ownHandlers){
|
|
|
|
for(let h of $rootScope.ownHandlers){
|
|
|
|
h._scope.$destroy();
|
|
|
|
}
|
2018-01-08 16:12:06 +00:00
|
|
|
}
|
|
|
|
$rootScope.ownHandlers = [];
|
|
|
|
});
|
2016-11-03 19:52:52 +00:00
|
|
|
});
|
|
|
|
|
2018-04-09 17:11:22 +00:00
|
|
|
app.controller('decodersController', function ($scope, $rootScope, $sce, Decoders,DecodersAutoComplete, errorHandler, genericReq, appState) {
|
2018-01-29 11:37:29 +00:00
|
|
|
$scope.setRulesTab = tab => $rootScope.globalsubmenuNavItem2 = tab;
|
2018-04-22 20:16:38 +00:00
|
|
|
|
2017-01-16 18:27:53 +00:00
|
|
|
//Initialization
|
2017-10-27 11:39:25 +00:00
|
|
|
$scope.loading = true;
|
2017-10-20 19:04:22 +00:00
|
|
|
$scope.decoders = Decoders;
|
2017-12-12 16:05:52 +00:00
|
|
|
$scope.decodersAutoComplete = DecodersAutoComplete;
|
2017-11-20 11:13:37 +00:00
|
|
|
$scope.typeFilter = "all";
|
2017-10-27 11:39:25 +00:00
|
|
|
$scope.setRulesTab('decoders');
|
2018-01-29 11:37:29 +00:00
|
|
|
$rootScope.tabVisualizations = { ruleset: 1 };
|
2016-11-03 19:52:52 +00:00
|
|
|
|
2017-11-30 12:02:03 +00:00
|
|
|
let timesOpened = 0;
|
|
|
|
let lastName = false;
|
|
|
|
$scope.closeOther = name => {
|
|
|
|
if(name !== lastName){
|
|
|
|
lastName = name;
|
|
|
|
timesOpened = 0;
|
|
|
|
}
|
|
|
|
timesOpened++;
|
|
|
|
$scope.activeItem = (timesOpened <= 1) ? name : false;
|
|
|
|
if(timesOpened > 1) timesOpened = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-12-12 16:05:52 +00:00
|
|
|
$scope.checkEnter = search => {
|
|
|
|
$scope.searchTerm = '';
|
|
|
|
angular.element(document.querySelector('#autocomplete')).blur();
|
|
|
|
if(search.startsWith('path:') && search.split('path:')[1].trim()) {
|
|
|
|
$scope.decoders.addFilter('path',search.split('path:')[1].trim());
|
|
|
|
} else if(search.startsWith('file:') && search.split('file:')[1].trim()) {
|
|
|
|
$scope.decoders.addFilter('file',search.split('file:')[1].trim());
|
2018-01-15 15:33:12 +00:00
|
|
|
} else {
|
|
|
|
$scope.decoders.addFilter('search',search.trim());
|
2017-12-12 16:05:52 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-01-29 11:37:29 +00:00
|
|
|
$scope.analizeDecoders = async search => {
|
|
|
|
try {
|
|
|
|
$scope.decodersAutoComplete.filters = [];
|
2018-04-22 20:16:38 +00:00
|
|
|
|
2018-01-29 11:37:29 +00:00
|
|
|
if(search.startsWith('path:') && search.split('path:')[1].trim()) {
|
|
|
|
await $scope.decodersAutoComplete.addFilter('path',search.split('path:')[1].trim());
|
|
|
|
} else if(search.startsWith('file:') && search.split('file:')[1].trim()) {
|
|
|
|
await $scope.decodersAutoComplete.addFilter('file',search.split('file:')[1].trim());
|
|
|
|
} else {
|
|
|
|
await $scope.decodersAutoComplete.addFilter('search',search);
|
|
|
|
}
|
2018-04-22 20:16:38 +00:00
|
|
|
|
2018-01-29 11:37:29 +00:00
|
|
|
if(!$scope.$$phase) $scope.$digest();
|
|
|
|
return $scope.decodersAutoComplete.items;
|
|
|
|
} catch (error){
|
2018-01-29 14:39:21 +00:00
|
|
|
errorHandler.handle(error,'Ruleset');
|
2018-01-29 12:16:59 +00:00
|
|
|
if(!$rootScope.$$phase) $rootScope.$digest();
|
2017-12-12 16:05:52 +00:00
|
|
|
}
|
2018-01-29 11:37:29 +00:00
|
|
|
}
|
2017-12-12 16:05:52 +00:00
|
|
|
|
2018-01-29 11:37:29 +00:00
|
|
|
const load = async () => {
|
|
|
|
try {
|
2018-04-18 12:39:45 +00:00
|
|
|
$rootScope.rawVisualizations = null;
|
2018-04-23 11:05:16 +00:00
|
|
|
const data = await genericReq.request('GET',`/api/wazuh-elastic/create-vis/manager-ruleset-decoders/${appState.getCurrentPattern()}`)
|
2018-04-18 12:39:45 +00:00
|
|
|
$rootScope.rawVisualizations = data.data.raw;
|
2018-04-09 17:11:22 +00:00
|
|
|
// Render visualizations
|
|
|
|
$rootScope.$broadcast('updateVis');
|
|
|
|
if(!$rootScope.$$phase) $rootScope.$digest();
|
|
|
|
|
2018-01-29 11:37:29 +00:00
|
|
|
await Promise.all([
|
|
|
|
$scope.decoders.nextPage(),
|
|
|
|
$scope.decodersAutoComplete.nextPage()
|
|
|
|
]);
|
2018-04-09 17:11:22 +00:00
|
|
|
|
2018-01-29 11:37:29 +00:00
|
|
|
$scope.loading = false;
|
|
|
|
if(!$scope.$$phase) $scope.$digest();
|
|
|
|
return;
|
|
|
|
} catch (error) {
|
2018-04-09 17:11:22 +00:00
|
|
|
errorHandler.handle(error,'Ruleset');
|
2018-01-29 12:16:59 +00:00
|
|
|
if(!$rootScope.$$phase) $rootScope.$digest();
|
2018-01-29 11:37:29 +00:00
|
|
|
}
|
2017-12-12 16:05:52 +00:00
|
|
|
}
|
|
|
|
|
2016-11-03 19:52:52 +00:00
|
|
|
//Load
|
2018-01-29 11:37:29 +00:00
|
|
|
load();
|
2017-10-27 11:39:25 +00:00
|
|
|
|
2016-11-03 19:52:52 +00:00
|
|
|
//Destroy
|
2018-01-08 16:12:06 +00:00
|
|
|
$scope.$on("$destroy", () => {
|
|
|
|
$scope.decoders.reset();
|
2018-01-29 11:37:29 +00:00
|
|
|
if($rootScope.ownHandlers){
|
|
|
|
for(let h of $rootScope.ownHandlers){
|
|
|
|
h._scope.$destroy();
|
|
|
|
}
|
2018-01-08 16:12:06 +00:00
|
|
|
}
|
|
|
|
$rootScope.ownHandlers = [];
|
|
|
|
});
|
2018-04-22 20:16:38 +00:00
|
|
|
});
|