2017-10-30 09:08:42 +00:00
|
|
|
let app = require('ui/modules').get('app/wazuh', []);
|
2017-11-07 14:13:45 +00:00
|
|
|
const beautifier = require('plugins/wazuh/utils/json-beautifier');
|
2017-10-31 15:16:47 +00:00
|
|
|
|
2017-10-20 19:04:22 +00:00
|
|
|
// Groups preview controller
|
2017-10-31 15:16:47 +00:00
|
|
|
app.controller('groupsPreviewController',
|
2017-12-01 17:28:48 +00:00
|
|
|
function ($scope, $timeout, $rootScope,$mdSidenav, $location, apiReq, Groups, GroupFiles, GroupAgents, Notifier) {
|
|
|
|
const notify = new Notifier({ location: 'Manager - Groups' });
|
2017-11-02 08:12:53 +00:00
|
|
|
$scope.searchTerm = '';
|
2017-10-31 16:42:42 +00:00
|
|
|
$scope.searchTermAgent = '';
|
2017-11-02 08:12:53 +00:00
|
|
|
$scope.searchTermFile = '';
|
|
|
|
$scope.load = true;
|
|
|
|
$scope.groups = Groups;
|
|
|
|
$scope.groupAgents = GroupAgents;
|
|
|
|
$scope.groupFiles = GroupFiles;
|
2017-10-20 19:04:22 +00:00
|
|
|
|
2017-12-11 09:15:21 +00:00
|
|
|
|
2017-12-05 19:42:30 +00:00
|
|
|
// Store a boolean variable to check if come from agents
|
|
|
|
const fromAgents = ('comeFrom' in $rootScope) && ('globalAgent' in $rootScope) && $rootScope.comeFrom === 'agents';
|
|
|
|
|
|
|
|
// If come from agents
|
|
|
|
if(fromAgents) {
|
|
|
|
let len = 0;
|
|
|
|
// Get ALL groups
|
|
|
|
apiReq.request('GET','/agents/groups/',{limit:99999})
|
|
|
|
.then(data => {
|
|
|
|
// Obtain an array with 0 or 1 element, in that case is our group
|
|
|
|
let filtered = data.data.data.items.filter(group => group.name === $rootScope.globalAgent.group);
|
|
|
|
// Store the array length, should be 0 or 1
|
|
|
|
len = filtered.length;
|
|
|
|
// If len is 1
|
|
|
|
if(len){
|
|
|
|
// First element is now our group $scope.groups.item is an array with only our group
|
|
|
|
$scope.groups.items = filtered;
|
|
|
|
// Load that our group
|
2018-01-12 09:56:19 +00:00
|
|
|
$scope.loadGroup(0);
|
|
|
|
$scope.lookingGroup=true
|
2017-12-05 19:42:30 +00:00
|
|
|
}
|
|
|
|
// Clean $rootScope
|
|
|
|
delete $rootScope.globalAgent;
|
|
|
|
delete $rootScope.comeFrom;
|
|
|
|
// Get more groups to fill the md-content with more items
|
|
|
|
return $scope.groups.nextPage('')
|
|
|
|
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
// If our group was not found we need to call loadGroup after load some groups
|
2017-12-11 09:15:21 +00:00
|
|
|
if(!len) {
|
|
|
|
$scope.loadGroup(0);
|
2018-01-12 09:56:19 +00:00
|
|
|
$scope.lookingGroup=true
|
2017-12-11 09:15:21 +00:00
|
|
|
}
|
|
|
|
$scope.load = false;
|
2017-12-05 19:42:30 +00:00
|
|
|
})
|
|
|
|
.catch(error => notify.error(error.message));
|
|
|
|
|
|
|
|
|
|
|
|
// If not come from agents make as normal
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// Actual execution in the controller's initialization
|
|
|
|
$scope.groups.nextPage('')
|
2017-12-11 09:15:21 +00:00
|
|
|
.then(() => {
|
|
|
|
$scope.loadGroup(0);
|
|
|
|
$scope.load = false;
|
|
|
|
})
|
2017-12-05 19:42:30 +00:00
|
|
|
.catch(error => notify.error(error.message));
|
|
|
|
}
|
2017-10-20 19:04:22 +00:00
|
|
|
|
2018-01-11 17:11:05 +00:00
|
|
|
$scope.toggle = () => $scope.lookingGroup=true;
|
2017-10-20 19:04:22 +00:00
|
|
|
|
2017-10-30 09:08:42 +00:00
|
|
|
$scope.showFiles = (index) => {
|
2017-11-02 09:22:46 +00:00
|
|
|
$scope.fileViewer = false;
|
2017-10-30 08:42:03 +00:00
|
|
|
$scope.groupFiles.reset();
|
2017-10-30 09:08:42 +00:00
|
|
|
$scope.groupFiles.path = `/agents/groups/${$scope.groups.items[index].name}/files`;
|
2017-11-02 09:22:46 +00:00
|
|
|
$scope.groupFiles.nextPage('');
|
2017-10-30 09:08:42 +00:00
|
|
|
};
|
2017-10-20 19:04:22 +00:00
|
|
|
|
2017-10-30 08:42:03 +00:00
|
|
|
$scope.showAgents = (index) => {
|
2017-10-31 16:42:42 +00:00
|
|
|
$scope.fileViewer = false;
|
2017-10-30 08:42:03 +00:00
|
|
|
$scope.groupAgents.reset();
|
2017-10-30 09:08:42 +00:00
|
|
|
$scope.groupAgents.path = `/agents/groups/${$scope.groups.items[index].name}`;
|
2017-10-31 15:16:47 +00:00
|
|
|
$scope.groupAgents.nextPage('');
|
2017-10-30 08:42:03 +00:00
|
|
|
};
|
2017-10-20 19:04:22 +00:00
|
|
|
|
2017-11-28 15:42:00 +00:00
|
|
|
$scope.showAgent = agent => {
|
2017-11-29 09:55:47 +00:00
|
|
|
$rootScope.globalAgent = agent.id;
|
2017-11-28 15:42:00 +00:00
|
|
|
$rootScope.comeFrom = 'groups';
|
2017-11-29 11:25:34 +00:00
|
|
|
$location.search('tab', null);
|
2017-11-03 12:33:37 +00:00
|
|
|
$location.path('/agents');
|
|
|
|
};
|
|
|
|
|
2017-10-30 08:42:03 +00:00
|
|
|
$scope.loadGroup = (index) => {
|
2017-10-31 15:16:47 +00:00
|
|
|
$scope.fileViewer = false;
|
2017-10-30 08:42:03 +00:00
|
|
|
$scope.groupAgents.reset();
|
|
|
|
$scope.groupFiles.reset();
|
|
|
|
$scope.selectedGroup = index;
|
|
|
|
$scope.showFiles(index);
|
|
|
|
$scope.showAgents(index);
|
|
|
|
};
|
2017-10-20 19:04:22 +00:00
|
|
|
|
2017-10-30 08:42:03 +00:00
|
|
|
// Select specific group
|
|
|
|
$scope.checkSelected = (index) => {
|
|
|
|
for(let group of $scope.groups.items){
|
|
|
|
if (group.selected) {
|
|
|
|
group = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$scope.groups.items[index] = true;
|
|
|
|
};
|
2017-10-20 19:04:22 +00:00
|
|
|
|
2018-01-11 17:11:05 +00:00
|
|
|
|
|
|
|
$scope.goBackToAgents = () => {
|
2018-01-12 15:01:24 +00:00
|
|
|
$scope.groupsSelectedTab = 'agents';
|
2018-01-11 17:11:05 +00:00
|
|
|
$scope.file = false;
|
|
|
|
$scope.filename = false;
|
|
|
|
if(!$scope.$$phase) $scope.$digest();
|
|
|
|
}
|
|
|
|
|
2018-01-12 09:56:19 +00:00
|
|
|
$scope.goBackFiles = () => {
|
|
|
|
$scope.groupsSelectedTab = 'files';
|
|
|
|
$scope.file = false;
|
|
|
|
$scope.filename = false;
|
|
|
|
if(!$scope.$$phase) $scope.$digest();
|
|
|
|
}
|
|
|
|
|
2017-10-30 08:42:03 +00:00
|
|
|
$scope.showFile = (index) => {
|
2017-11-20 12:37:10 +00:00
|
|
|
if($scope.filename) $scope.filename = '';
|
2017-11-06 15:48:18 +00:00
|
|
|
let filename = $scope.groupFiles.items[index].filename;
|
|
|
|
if(filename === '../ar.conf') filename = 'ar.conf';
|
|
|
|
|
2017-10-31 15:16:47 +00:00
|
|
|
$scope.fileViewer = true;
|
2018-01-11 17:11:05 +00:00
|
|
|
|
2017-10-30 08:42:03 +00:00
|
|
|
let tmpName = `/agents/groups/${$scope.groups.items[$scope.selectedGroup].name}`+
|
2017-11-06 15:48:18 +00:00
|
|
|
`/files/${filename}`;
|
|
|
|
|
|
|
|
|
2017-10-30 08:42:03 +00:00
|
|
|
apiReq.request('GET', tmpName, {})
|
2017-11-20 12:32:24 +00:00
|
|
|
.then(data => {
|
|
|
|
$scope.file = beautifier.prettyPrint(data.data.data);
|
|
|
|
$scope.filename = filename;
|
|
|
|
})
|
2017-12-01 17:28:48 +00:00
|
|
|
.catch(error => notify.error(error.message));
|
2017-10-30 08:42:03 +00:00
|
|
|
};
|
2017-10-20 19:04:22 +00:00
|
|
|
|
2017-10-30 08:42:03 +00:00
|
|
|
// Changing the view to overview a specific group
|
|
|
|
$scope.groupOverview = (group) => {
|
|
|
|
$scope.$parent.$parent.groupName = group;
|
2017-10-30 09:08:42 +00:00
|
|
|
$scope.$parent.$parent.groupsMenu = 'overview';
|
2017-10-30 08:42:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Resetting the factory configuration
|
|
|
|
$scope.$on("$destroy", () => {
|
|
|
|
$scope.groups.reset();
|
2017-11-03 12:33:37 +00:00
|
|
|
$scope.groupFiles.reset();
|
|
|
|
$scope.groupAgents.reset();
|
2017-10-30 08:42:03 +00:00
|
|
|
});
|
2017-12-11 09:15:21 +00:00
|
|
|
|
2017-11-02 09:22:46 +00:00
|
|
|
|
2018-01-12 15:01:24 +00:00
|
|
|
$scope.$watch('lookingGroup',value => {
|
|
|
|
if(!value){
|
|
|
|
$scope.file = false;
|
|
|
|
$scope.filename = false;
|
|
|
|
}
|
|
|
|
});
|
2017-10-20 19:04:22 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
app.controller('groupsController', function ($scope) {
|
2017-10-30 09:08:42 +00:00
|
|
|
$scope.groupsMenu = 'preview';
|
2017-10-30 08:42:03 +00:00
|
|
|
$scope.groupName = '';
|
|
|
|
});
|