mirror of
https://github.com/valitydev/wazuh-kibana-app.git
synced 2024-11-06 18:05:20 +00:00
Updated extensions management
This commit is contained in:
parent
d781d35ead
commit
e31ba4ad21
@ -24,7 +24,10 @@ app.controller('agentsController', function ($timeout, $scope, $location, $rootS
|
||||
tabVisualizations.removeAll();
|
||||
loadedVisualizations.removeAll();
|
||||
|
||||
$scope.extensions = appState.getExtensions().extensions;
|
||||
const currentApi = JSON.parse(appState.getCurrentAPI()).id;
|
||||
const extensions = appState.getExtensions(currentApi);
|
||||
$scope.extensions = extensions;
|
||||
|
||||
$scope.agentsAutoComplete = AgentsAutoComplete;
|
||||
|
||||
// Check the url hash and retrieve the tabView information
|
||||
|
@ -24,7 +24,10 @@ app.controller('overviewController', function ($sce, $timeout, $scope, $location
|
||||
tabVisualizations.removeAll();
|
||||
loadedVisualizations.removeAll();
|
||||
|
||||
$scope.extensions = appState.getExtensions().extensions;
|
||||
|
||||
const currentApi = JSON.parse(appState.getCurrentAPI()).id;
|
||||
const extensions = appState.getExtensions(currentApi);
|
||||
$scope.extensions = extensions;
|
||||
|
||||
$scope.wzMonitoringEnabled = false;
|
||||
|
||||
|
@ -133,8 +133,7 @@ app.controller('settingsController', function ($scope, $rootScope, $http, $route
|
||||
$scope.extensions.aws = $scope.apiEntries[index]._source.extensions.aws;
|
||||
$scope.extensions.virustotal = $scope.apiEntries[index]._source.extensions.virustotal;
|
||||
if(!$scope.$$phase) $scope.$digest();
|
||||
appState.setExtensions($scope.apiEntries[index]._source.extensions);
|
||||
|
||||
appState.setExtensions($scope.apiEntries[index]._id,$scope.apiEntries[index]._source.extensions);
|
||||
};
|
||||
|
||||
// Get settings function
|
||||
@ -167,8 +166,7 @@ app.controller('settingsController', function ($scope, $rootScope, $http, $route
|
||||
$scope.extensions.aws = $scope.apiEntries[currentApiEntryIndex]._source.extensions.aws;
|
||||
$scope.extensions.virustotal = $scope.apiEntries[currentApiEntryIndex]._source.extensions.virustotal;
|
||||
|
||||
appState.setExtensions($scope.apiEntries[currentApiEntryIndex]._source.extensions);
|
||||
|
||||
appState.setExtensions($scope.apiEntries[currentApiEntryIndex]._id,$scope.apiEntries[currentApiEntryIndex]._source.extensions);
|
||||
if(!$scope.$$phase) $scope.$digest();
|
||||
return;
|
||||
} catch (error) {
|
||||
@ -227,7 +225,7 @@ app.controller('settingsController', function ($scope, $rootScope, $http, $route
|
||||
port : $scope.formData.port,
|
||||
cluster_info: {},
|
||||
insecure : 'true',
|
||||
extensions : appState.getExtensions().extensions
|
||||
extensions : {}
|
||||
};
|
||||
|
||||
const config = await genericReq.request('GET', '/api/wazuh-api/configuration', {});
|
||||
@ -239,7 +237,6 @@ app.controller('settingsController', function ($scope, $rootScope, $http, $route
|
||||
tmpData.extensions.oscap = typeof config.data.data['extensions.oscap'] !== 'undefined' ? config.data.data['extensions.oscap'] : true;
|
||||
tmpData.extensions.aws = typeof config.data.data['extensions.aws'] !== 'undefined' ? config.data.data['extensions.aws'] : false;
|
||||
tmpData.extensions.virustotal = typeof config.data.data['extensions.virustotal'] !== 'undefined' ? config.data.data['extensions.virustotal'] : false;
|
||||
appState.setExtensions(tmpData.extensions);
|
||||
}
|
||||
|
||||
const checkData = await testAPI.check(tmpData)
|
||||
@ -249,7 +246,7 @@ app.controller('settingsController', function ($scope, $rootScope, $http, $route
|
||||
|
||||
// Insert new API entry
|
||||
const data = await genericReq.request('PUT', '/api/wazuh-api/settings', tmpData);
|
||||
|
||||
appState.setExtensions(data.data.response._id,tmpData.extensions)
|
||||
const newEntry = {
|
||||
_id: data.data.response._id,
|
||||
_source: {
|
||||
@ -400,7 +397,7 @@ app.controller('settingsController', function ($scope, $rootScope, $http, $route
|
||||
getCurrentAPIIndex()
|
||||
if ($scope.apiEntries && $scope.apiEntries.length && ['oscap','audit','pci','gdpr','aws','virustotal'].includes(extension)) {
|
||||
$scope.apiEntries[currentApiEntryIndex]._source.extensions[extension] = state;
|
||||
appState.setExtensions($scope.apiEntries[currentApiEntryIndex]._source.extensions);
|
||||
appState.setExtensions($scope.apiEntries[currentApiEntryIndex]._id,$scope.apiEntries[currentApiEntryIndex]._source.extensions);
|
||||
|
||||
if(!$scope.$$phase) $scope.$digest();
|
||||
}
|
||||
@ -442,6 +439,7 @@ app.controller('settingsController', function ($scope, $rootScope, $http, $route
|
||||
} else { // There's no pattern in the cookies, pick the one in the settings
|
||||
$scope.selectedIndexPattern = config.data.data["pattern"];
|
||||
}
|
||||
|
||||
if(config.data && config.data.data && !appState.getCurrentAPI()) {
|
||||
$scope.extensions = {};
|
||||
$scope.extensions.audit = typeof config.data.data['extensions.audit'] !== 'undefined' ? config.data.data['extensions.audit'] : true;
|
||||
@ -450,9 +448,8 @@ app.controller('settingsController', function ($scope, $rootScope, $http, $route
|
||||
$scope.extensions.oscap = typeof config.data.data['extensions.oscap'] !== 'undefined' ? config.data.data['extensions.oscap'] : true;
|
||||
$scope.extensions.aws = typeof config.data.data['extensions.aws'] !== 'undefined' ? config.data.data['extensions.aws'] : false;
|
||||
$scope.extensions.virustotal = typeof config.data.data['extensions.virustotal'] !== 'undefined' ? config.data.data['extensions.virustotal'] : false;
|
||||
appState.setExtensions($scope.extensions);
|
||||
} else {
|
||||
$scope.extensions = appState.getExtensions().extensions;
|
||||
$scope.extensions = appState.getExtensions(appState.getCurrentAPI().id);
|
||||
}
|
||||
if(!$scope.$$phase) $scope.$digest();
|
||||
return;
|
||||
|
@ -14,30 +14,17 @@ import * as modules from 'ui/modules'
|
||||
modules.get('app/wazuh', [])
|
||||
.service('appState', function ($cookies, $window) {
|
||||
return {
|
||||
getExtensions: () => {
|
||||
const data = {
|
||||
extensions: $cookies.getObject('extensions')
|
||||
};
|
||||
|
||||
if(typeof data.extensions === 'undefined'){
|
||||
return {
|
||||
extensions : {
|
||||
audit : true,
|
||||
pci : true,
|
||||
gdpr : true,
|
||||
oscap : true,
|
||||
aws : false,
|
||||
virustotal: false
|
||||
}
|
||||
}
|
||||
}
|
||||
return data;
|
||||
getExtensions: id => {
|
||||
const current = $cookies.getObject('extensions');
|
||||
return current ? current[id] : false;
|
||||
},
|
||||
setExtensions: extensions => {
|
||||
setExtensions: (id,extensions) => {
|
||||
const current = $cookies.getObject('extensions') || {};
|
||||
current[id] = extensions;
|
||||
const exp = new Date();
|
||||
exp.setDate(exp.getDate() + 365);
|
||||
if (extensions) {
|
||||
$cookies.putObject('extensions', extensions, { 'expires': exp });
|
||||
$cookies.putObject('extensions', current, { 'expires': exp });
|
||||
}
|
||||
},
|
||||
getClusterInfo: () => {
|
||||
|
@ -78,7 +78,22 @@ export default ($rootScope, $location, $q, $window, testAPI, appState, genericRe
|
||||
}
|
||||
|
||||
const callCheckStored = () => {
|
||||
checkTimestamp(appState,genericReq,errorHandler,$rootScope,$location)
|
||||
genericReq.request('GET', '/api/wazuh-api/configuration', {})
|
||||
.then(config => {
|
||||
const currentApi = appState.getCurrentAPI();
|
||||
if(currentApi && !appState.getExtensions(JSON.parse(currentApi).id)){
|
||||
const extensions = {
|
||||
audit: typeof config.data.data['extensions.audit'] !== 'undefined' ? config.data.data['extensions.audit'] : true,
|
||||
pci: typeof config.data.data['extensions.pci'] !== 'undefined' ? config.data.data['extensions.pci'] : true,
|
||||
gdpr: typeof config.data.data['extensions.gdpr'] !== 'undefined' ? config.data.data['extensions.gdpr'] : true,
|
||||
oscap: typeof config.data.data['extensions.oscap'] !== 'undefined' ? config.data.data['extensions.oscap'] : true,
|
||||
aws: typeof config.data.data['extensions.aws'] !== 'undefined' ? config.data.data['extensions.aws'] : false,
|
||||
virustotal: typeof config.data.data['extensions.virustotal'] !== 'undefined' ? config.data.data['extensions.virustotal'] : false
|
||||
}
|
||||
appState.setExtensions(JSON.parse(currentApi).id,extensions)
|
||||
}
|
||||
return checkTimestamp(appState,genericReq,errorHandler,$rootScope,$location);
|
||||
})
|
||||
.then(() => testAPI.check_stored(JSON.parse(appState.getCurrentAPI()).id))
|
||||
.then(data => {
|
||||
if(data && data === 'cookies_outdated'){
|
||||
@ -91,7 +106,7 @@ export default ($rootScope, $location, $q, $window, testAPI, appState, genericRe
|
||||
wzMisc.setApiIsDown(false)
|
||||
changeCurrentApi(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
appState.removeCurrentAPI();
|
||||
|
@ -76,17 +76,6 @@ export default class WazuhApiElastic {
|
||||
}
|
||||
}
|
||||
|
||||
async getExtensions (req, reply) {
|
||||
try{
|
||||
const data = await this.wzWrapper.getWazuhAPIEntries();
|
||||
|
||||
return reply(data.hits.hits);
|
||||
|
||||
} catch(error){
|
||||
return ErrorResponse(error.message || error, 2004, 500, reply);
|
||||
}
|
||||
}
|
||||
|
||||
validateData (payload) {
|
||||
// Validate user
|
||||
if(!userRegEx.test(payload.user)){
|
||||
|
@ -29,9 +29,6 @@ export default (server, options) => {
|
||||
// Set Wazuh-API as default (multimanager) on elasticsearch index
|
||||
server.route({ method: 'PUT', path: '/api/wazuh-api/apiEntries/{id}', handler: (req,reply) => ctrl.setAPIEntryDefault(req,reply) });
|
||||
|
||||
// Return extension state list
|
||||
server.route({ method: 'GET', path: '/api/wazuh-api/extension', handler: (req,reply) => ctrl.getExtensions(req,reply) });
|
||||
|
||||
// Update the API hostname
|
||||
server.route({ method: 'PUT', path: '/api/wazuh-api/updateApiHostname/{id}', handler: (req,reply) => ctrl.updateAPIHostname(req,reply) });
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user