2018-04-22 20:16:38 +00:00
|
|
|
/*
|
|
|
|
* Wazuh app - Manager 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-06-29 01:43:18 +00:00
|
|
|
|
2018-03-20 15:20:50 +00:00
|
|
|
app.controller('managerController', function ($scope, $rootScope, $routeParams, $location, apiReq, errorHandler) {
|
2017-10-30 09:08:42 +00:00
|
|
|
$scope.submenuNavItem = 'status';
|
|
|
|
$scope.submenuNavItem2 = 'rules';
|
|
|
|
|
|
|
|
if ($routeParams.tab){
|
|
|
|
$scope.submenuNavItem = $routeParams.tab;
|
|
|
|
}
|
2018-03-14 15:21:32 +00:00
|
|
|
|
2018-02-23 10:19:22 +00:00
|
|
|
$scope.reloadGroups = () => {
|
|
|
|
$scope.submenuNavItem = 'groups';
|
|
|
|
$rootScope.groupsIsReloaded = true;
|
|
|
|
}
|
|
|
|
|
2018-05-07 11:20:11 +00:00
|
|
|
$scope.reloadRuleset = () => {
|
|
|
|
$scope.submenuNavItem = 'ruleset';
|
|
|
|
$rootScope.rulesetIsReloaded = true;
|
|
|
|
}
|
|
|
|
|
2017-10-30 09:08:42 +00:00
|
|
|
// Watchers
|
2017-11-09 18:02:50 +00:00
|
|
|
$scope.$watch('submenuNavItem', () => {
|
|
|
|
if($scope.submenuNavItem === 'ruleset') {
|
|
|
|
$rootScope.globalRuleSet = 'ruleset';
|
|
|
|
$rootScope.globalsubmenuNavItem2 = $scope.submenuNavItem2;
|
|
|
|
} else {
|
|
|
|
delete $rootScope.globalRuleSet;
|
|
|
|
delete $rootScope.globalsubmenuNavItem2;
|
|
|
|
}
|
|
|
|
$location.search('tab', $scope.submenuNavItem);
|
|
|
|
});
|
2017-10-30 09:08:42 +00:00
|
|
|
|
|
|
|
$scope.setRulesTab = (tab) => $scope.submenuNavItem2 = tab;
|
2018-02-12 15:15:16 +00:00
|
|
|
|
|
|
|
$scope.$on("$destroy", () => {
|
2018-05-15 14:21:44 +00:00
|
|
|
|
2018-02-12 15:15:16 +00:00
|
|
|
});
|
2017-02-07 17:05:51 +00:00
|
|
|
});
|
|
|
|
|
2018-01-29 11:37:29 +00:00
|
|
|
app.controller('managerStatusController', function ($scope,$rootScope, errorHandler, apiReq) {
|
2017-01-16 18:27:53 +00:00
|
|
|
//Initialization
|
2017-10-30 09:08:42 +00:00
|
|
|
$scope.load = true;
|
2016-07-28 12:45:20 +00:00
|
|
|
|
2016-09-20 08:55:43 +00:00
|
|
|
//Functions
|
2018-03-14 15:21:32 +00:00
|
|
|
$scope.getDaemonStatusClass = daemonStatus => (daemonStatus === 'running') ? 'status teal' : 'status red';
|
2016-06-29 13:44:36 +00:00
|
|
|
|
2017-11-24 13:46:52 +00:00
|
|
|
Promise.all([
|
|
|
|
apiReq.request('GET', '/agents/summary', {}),
|
|
|
|
apiReq.request('GET', '/manager/status', {}),
|
|
|
|
apiReq.request('GET', '/manager/info', {}),
|
|
|
|
apiReq.request('GET', '/rules', { offset: 0, limit: 1 }),
|
|
|
|
apiReq.request('GET', '/decoders', { offset: 0, limit: 1 })
|
|
|
|
])
|
|
|
|
.then(data => {
|
|
|
|
$scope.agentsCountActive = data[0].data.data.Active;
|
|
|
|
$scope.agentsCountDisconnected = data[0].data.data.Disconnected;
|
|
|
|
$scope.agentsCountNeverConnected = data[0].data.data['Never connected'];
|
|
|
|
$scope.agentsCountTotal = data[0].data.data.Total;
|
|
|
|
$scope.agentsCoverity = (data[0].data.data.Active / data[0].data.data.Total) * 100;
|
2017-10-20 19:04:22 +00:00
|
|
|
|
2017-11-24 13:46:52 +00:00
|
|
|
$scope.daemons = data[1].data.data;
|
|
|
|
$scope.managerInfo = data[2].data.data;
|
|
|
|
$scope.totalRules = data[3].data.data.totalItems;
|
|
|
|
$scope.totalDecoders = data[4].data.data.totalItems;
|
2017-10-30 09:08:42 +00:00
|
|
|
|
2017-11-24 13:46:52 +00:00
|
|
|
return apiReq.request('GET', '/agents', { limit: 1, sort: '-date_add' });
|
|
|
|
})
|
|
|
|
.then(lastAgent => apiReq.request('GET', `/agents/${lastAgent.data.data.items[0].id}`, {}))
|
|
|
|
.then(agentInfo => {
|
|
|
|
$scope.agentInfo = agentInfo.data.data;
|
|
|
|
$scope.load = false;
|
2018-01-26 10:21:50 +00:00
|
|
|
if(!$scope.$$phase) $scope.$digest();
|
2017-11-24 13:46:52 +00:00
|
|
|
})
|
2018-01-29 12:16:59 +00:00
|
|
|
.catch(error => {
|
2018-03-14 15:21:32 +00:00
|
|
|
errorHandler.handle(error,'Manager');
|
2018-01-29 12:16:59 +00:00
|
|
|
if(!$rootScope.$$phase) $rootScope.$digest();
|
|
|
|
});
|
2016-06-29 13:44:36 +00:00
|
|
|
|
2018-02-12 15:15:16 +00:00
|
|
|
$scope.$on("$destroy", () => {
|
2018-05-15 14:21:44 +00:00
|
|
|
|
2018-02-12 15:15:16 +00:00
|
|
|
});
|
|
|
|
|
2016-06-29 01:43:18 +00:00
|
|
|
});
|
2018-01-22 08:39:04 +00:00
|
|
|
|
2018-04-21 11:31:47 +00:00
|
|
|
import beautifier from 'plugins/wazuh/utils/json-beautifier';
|
|
|
|
|
2018-04-23 14:41:50 +00:00
|
|
|
app.controller('managerConfigurationController', function ($scope, $rootScope, errorHandler, apiReq) {
|
2017-01-16 18:27:53 +00:00
|
|
|
//Initialization
|
2017-10-30 09:08:42 +00:00
|
|
|
$scope.load = true;
|
2018-01-22 08:39:04 +00:00
|
|
|
$scope.isArray = angular.isArray;
|
|
|
|
|
2018-01-22 08:18:47 +00:00
|
|
|
$scope.switchItem = item => {
|
|
|
|
$scope.selectedItem = item;
|
|
|
|
if(!$scope.$$phase) $scope.$digest();
|
|
|
|
}
|
2017-10-30 09:08:42 +00:00
|
|
|
|
2016-07-22 11:34:36 +00:00
|
|
|
//Functions
|
2018-01-22 08:18:47 +00:00
|
|
|
const load = async () => {
|
|
|
|
try{
|
|
|
|
const data = await apiReq.request('GET', '/manager/configuration', {});
|
|
|
|
|
2017-10-30 09:08:42 +00:00
|
|
|
$scope.managerConfiguration = data.data.data;
|
2018-04-04 08:52:13 +00:00
|
|
|
|
|
|
|
if($scope.managerConfiguration && $scope.managerConfiguration['active-response']){
|
|
|
|
for(let i=0,len = $scope.managerConfiguration['active-response'].length; i<len; i++){
|
|
|
|
let rule = '';
|
2018-04-22 20:16:38 +00:00
|
|
|
const rulesArray = $scope.managerConfiguration['active-response'][i].rules_id ?
|
2018-04-04 08:52:13 +00:00
|
|
|
$scope.managerConfiguration['active-response'][i].rules_id.split(',') :
|
|
|
|
[];
|
|
|
|
if($scope.managerConfiguration['active-response'][i].rules_id && rulesArray.length > 1){
|
|
|
|
let tmp = [];
|
|
|
|
for(let id of rulesArray){
|
|
|
|
rule = await apiReq.request('GET',`/rules/${id}`,{});
|
|
|
|
tmp.push(rule.data.data.items[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.managerConfiguration['active-response'][i].rules = tmp;
|
|
|
|
} else if($scope.managerConfiguration['active-response'][i].rules_id){
|
|
|
|
rule = await apiReq.request('GET',`/rules/${$scope.managerConfiguration['active-response'][i].rules_id}`,{});
|
|
|
|
$scope.managerConfiguration['active-response'][i].rule = rule.data.data.items[0];
|
2018-04-22 20:16:38 +00:00
|
|
|
}
|
2018-04-04 08:52:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-22 08:18:47 +00:00
|
|
|
$scope.raw = beautifier.prettyPrint(data.data.data);
|
|
|
|
$scope.load = false;
|
|
|
|
if(!$scope.$$phase) $scope.$digest();
|
|
|
|
return;
|
|
|
|
} catch (error) {
|
2018-01-29 14:39:21 +00:00
|
|
|
errorHandler.handle(error,'Manager');
|
2018-01-29 12:16:59 +00:00
|
|
|
if(!$rootScope.$$phase) $rootScope.$digest();
|
2018-01-22 08:18:47 +00:00
|
|
|
}
|
2016-07-22 11:34:36 +00:00
|
|
|
};
|
2016-07-28 14:41:27 +00:00
|
|
|
|
2018-01-22 08:39:04 +00:00
|
|
|
load();
|
2018-02-12 15:15:16 +00:00
|
|
|
$scope.$on("$destroy", () => {
|
2018-05-15 14:21:44 +00:00
|
|
|
|
2018-02-12 15:15:16 +00:00
|
|
|
});
|
2018-03-14 15:21:32 +00:00
|
|
|
});
|