diff --git a/.gitignore b/.gitignore
index ddf8aadb6..d602b4c03 100644
--- a/.gitignore
+++ b/.gitignore
@@ -59,3 +59,8 @@ typings/
# dotenv environment variables file
.env
+
+
+kibana/
+
+*.zip
\ No newline at end of file
diff --git a/public/controllers/agents.js b/public/controllers/agents.js
index 8494ca905..42b2bf23e 100644
--- a/public/controllers/agents.js
+++ b/public/controllers/agents.js
@@ -15,9 +15,10 @@ import rison from 'rison'
const app = modules.get('app/wazuh', []);
-app.controller('agentsController',
- function ($timeout, $scope, $location, $q, $rootScope, appState, genericReq, apiReq, AgentsAutoComplete, errorHandler) {
-
+app.controller('agentsController', function ($timeout, $scope, $location, $q, $rootScope, appState, genericReq, apiReq, AgentsAutoComplete, errorHandler, $window) {
+ $window.sessionStorage.setItem('lasta',$location.search()._a)
+ $rootScope.completedAgent = false;
+ $rootScope.wazuhLoadFilters =false;
$rootScope.page = 'agents';
$scope.extensions = appState.getExtensions().extensions;
$scope.agentsAutoComplete = AgentsAutoComplete;
@@ -198,18 +199,6 @@ app.controller('agentsController',
});
$scope.$watch('tab', () => {
- const str = $location.search()._a;
- if(str){
- const decoded = rison.decode(str);
- const tmp = decoded.filters.filter(item => !(
- (item.query && item.query.match && item.query.match['rule.groups']) ||
- (item.exists && item.exists.field === 'rule.pci_dss'))
- );
-
- decoded.filters = tmp;
- const encoded = rison.encode(decoded);
- $location.search('_a', encoded)
- }
$location.search('tab', $scope.tab);
$scope.tabView = 'panels';
@@ -226,7 +215,6 @@ app.controller('agentsController',
// Update the implicit filter
if (typeof tabFilters[$scope.tab] !== 'undefined' && tabFilters[$scope.tab].group === "") $rootScope.currentImplicitFilter = "";
else $rootScope.currentImplicitFilter = (typeof tabFilters[$scope.tab] !== 'undefined') ? tabFilters[$scope.tab].group : '';
-
if($scope.tab === 'configuration'){
firstLoad();
}
@@ -285,48 +273,26 @@ app.controller('agentsController',
/** Prevents from double agent and come from autocomplete */
let lastAgent = null;
- const checkDouble = id => {
- if(lastAgent && lastAgent !== id){
- $rootScope.agentsAutoCompleteFired = true;
- if(!$rootScope.$$phase) $rootScope.$digest();
- }
- }
+
$scope.getAgent = async (newAgentId,fromAutocomplete) => {
try {
+ $rootScope.completedAgent = false;
if($scope.tab === 'configuration'){
return $scope.getAgentConfig(newAgentId);
}
- try {
- // Try to parse the _a trace and detect if there is any agent.id filter
- // in order to delete it from the _a trace
- const str = $location.search()._a;
- if(str){
- const decoded = rison.decode(str);
- const tmp = decoded.filters.filter(item => !item.query.match['agent.id']);
- decoded.filters = tmp;
- const encoded = rison.encode(decoded);
- $location.search('_a', encoded)
- }
- } catch (error) {
- // If some rison.js related error is generated we simply clean the _a trace
- console.log(error.message || error); // not blocking action
- }
let id = null;
// They passed an id
if (newAgentId) {
id = newAgentId;
- checkDouble(id);
$location.search('agent', id);
} else {
if ($location.search().agent && !$rootScope.globalAgent) { // There's one in the url
id = $location.search().agent;
- checkDouble(id);
} else { // We pick the one in the rootScope
id = $rootScope.globalAgent;
- checkDouble(id);
$location.search('agent', id);
delete $rootScope.globalAgent;
}
@@ -359,6 +325,7 @@ app.controller('agentsController',
$scope.agent.rootcheck = data[2].data.data;
validateRootCheck();
+ $rootScope.completedAgent = true;
if(!$scope.$$phase) $scope.$digest();
return;
} catch (error) {
@@ -377,7 +344,7 @@ app.controller('agentsController',
}
$rootScope.ownHandlers = [];
$rootScope.comeFrom = 'agents';
- $location.search('_a',null);
+ //$location.search('_a',null);
$location.search('tab', 'groups');
$location.path('/manager');
};
@@ -464,6 +431,7 @@ app.controller('agentsController',
const firstLoad = async () => {
try{
+ $rootScope.completedAgent = false;
$scope.configurationError = false;
$scope.load = true;
let id;
@@ -509,6 +477,7 @@ app.controller('agentsController',
$scope.isSynchronized = (($scope.agentMergedSum === $scope.groupMergedSum) && !([$scope.agentMergedSum,$scope.groupMergedSum].includes('Unknown')) ) ? true : false;
$scope.load = false;
+ $rootScope.completedAgent = true;
if(!$scope.$$phase) $scope.$digest();
return;
} catch (error){
diff --git a/public/controllers/overview.js b/public/controllers/overview.js
index 3debba56a..ca1fd9bfd 100644
--- a/public/controllers/overview.js
+++ b/public/controllers/overview.js
@@ -14,7 +14,8 @@ import * as modules from 'ui/modules'
const app = modules.get('app/wazuh', []);
-app.controller('overviewController', function ($scope, $location, $rootScope, appState, genericReq, errorHandler, apiReq) {
+app.controller('overviewController', function ($scope, $location, $rootScope, appState, genericReq, errorHandler, apiReq,$window) {
+
$rootScope.rawVisualizations = null;
$rootScope.page = 'overview';
@@ -210,7 +211,7 @@ app.controller('overviewController', function ($scope, $location, $rootScope, ap
checkMetrics(tab, 'panels');
// Deleting app state traces in the url
- $location.search('_a', null);
+ //$location.search('_a', null);
})
.catch(error => errorHandler.handle(error, 'Overview'));
diff --git a/public/kibana-integrations/kibana-discover.js b/public/kibana-integrations/kibana-discover.js
index fbdf4be35..8a16217aa 100644
--- a/public/kibana-integrations/kibana-discover.js
+++ b/public/kibana-integrations/kibana-discover.js
@@ -44,7 +44,7 @@ import 'ui/pager_control';
import 'ui/pager';
import { UtilsBrushEventProvider } from 'ui/utils/brush_event';
import { documentationLinks } from 'ui/documentation_links/documentation_links';
-
+import chrome from 'ui/chrome'
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -758,8 +758,26 @@ function discoverController(
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function loadFilters() {
- if ($scope.tab) {
- let implicitFilter = [];
+ if($scope.tab !== 'general' && !$rootScope.currentImplicitFilter) {
+ return;
+ }
+
+
+ if ($scope.tab) {
+ const current = queryFilter.getFilters();
+ const implicitFilter = [];
+ for(const item of current){
+ if((item && item.query && item.query.match && item.query.match['rule.groups']) ||
+ (item && item.query && item.query.match && item.query.match['agent.id']) ||
+ (item && item.query && item.query.match && item.query.match['manager.name']) ||
+ (item && item.exists && item.exists.field && item.exists.field === 'rule.pci_dss'))
+ continue;
+ else
+ implicitFilter.push(item)
+ }
+
+ queryFilter.removeAll()
+
if (appState.getClusterInfo().status == 'enabled') {
// The cluster filter
@@ -906,10 +924,13 @@ function discoverController(
}
);
}
- }
-
- queryFilter.addFilters(implicitFilter);
- }
+ }
+
+ queryFilter.addFilters(implicitFilter).then(data => {
+ if($rootScope.page === 'agents') $rootScope.wazuhLoadFilters = !$rootScope.wazuhLoadFilters
+ });
+
+ }
}
// Getting the location from the url
@@ -918,11 +939,10 @@ function discoverController(
if ($rootScope.page === 'agents') $scope.agentId = $location.search().agent;
// Initial loading of filters
- loadFilters();
+ loadFilters();
// Watch for changes in the location
$scope.$on('$routeUpdate', () => {
-
if ($location.search().tabView != $scope.tabView) { // No need to change the filters
if ($scope.tabView !== "discover") { // Should do this the first time, to avoid the squeezing of the visualization
$scope.updateQueryAndFetch($state.query);
diff --git a/public/kibana-integrations/kibana-filter-bar.js b/public/kibana-integrations/kibana-filter-bar.js
index 028a2f493..9bebab50d 100644
--- a/public/kibana-integrations/kibana-filter-bar.js
+++ b/public/kibana-integrations/kibana-filter-bar.js
@@ -13,10 +13,10 @@ import { FilterBarLibChangeTimeFilterProvider } from 'ui/filter_bar/lib/change_t
import { FilterBarQueryFilterProvider } from 'ui/filter_bar/query_filter';
import { compareFilters } from 'ui/filter_bar/lib/compare_filters';
import { uiModules } from 'ui/modules';
-
+import rison from 'rison'
const module = uiModules.get('kibana');
-module.directive('filterBarW', function (Private, Promise, getAppState) {
+module.directive('filterBarW', function (Private, Promise, getAppState,$location, $rootScope) {
const mapAndFlattenFilters = Private(FilterBarLibMapAndFlattenFiltersProvider);
const mapFlattenAndWrapFilters = Private(FilterBarLibMapFlattenAndWrapFiltersProvider);
const extractTimeFilter = Private(FilterBarLibExtractTimeFilterProvider);
@@ -96,9 +96,17 @@ module.directive('filterBarW', function (Private, Promise, getAppState) {
// update the scope filter list on filter changes
$scope.$listen(queryFilter, 'update', function () {
- updateFilters();
+ if(queryFilter.getFilters().length) updateFilters();
});
+ $scope.$watch('wazuhLoadFilters',() => {
+ if(queryFilter.getFilters().length) updateFilters();
+ })
+
+ $rootScope.$watch('completedAgent',() => {
+ if(queryFilter.getFilters().length) updateFilters();
+ })
+
// when appState changes, update scope's state
$scope.$watch(getAppState, function (appState) {
$scope.state = appState;
@@ -106,7 +114,7 @@ module.directive('filterBarW', function (Private, Promise, getAppState) {
$scope.$watch('state.$newFilters', function (filters) {
if (!filters) return;
-
+
// If filters is not undefined and the length is greater than
// one we need to set the newFilters attribute and allow the
// users to decide what they want to apply.
@@ -157,6 +165,7 @@ module.directive('filterBarW', function (Private, Promise, getAppState) {
function updateFilters() {
const filters = queryFilter.getFilters();
+ if(!queryFilter.getFilters().length || ($rootScope.page === 'agents' && !$rootScope.completedAgent)) return;
mapAndFlattenFilters(filters).then(function (results) {
// used to display the current filters in the state
$scope.filters = _.sortBy(results, function (filter) {
diff --git a/public/templates/agents/agents.head b/public/templates/agents/agents.head
index d573130d4..3658ae072 100644
--- a/public/templates/agents/agents.head
+++ b/public/templates/agents/agents.head
@@ -74,7 +74,7 @@
-