2017-10-30 09:08:42 +00:00
|
|
|
let app = require('ui/modules').get('app/wazuh', []);
|
2017-11-07 14:34:28 +00:00
|
|
|
const beautifier = require('plugins/wazuh/utils/json-beautifier');
|
2017-10-20 19:04:22 +00:00
|
|
|
|
|
|
|
// Groups preview controller
|
2017-10-30 08:42:03 +00:00
|
|
|
app.controller('groupsPreviewController', function ($scope, apiReq, Groups, GroupFiles, GroupAgents) {
|
2017-10-30 09:08:42 +00:00
|
|
|
$scope.searchTerm = '';
|
|
|
|
$scope.load = true;
|
|
|
|
$scope.groups = Groups;
|
2017-10-30 08:42:03 +00:00
|
|
|
$scope.groupAgents = GroupAgents;
|
2017-10-30 09:08:42 +00:00
|
|
|
$scope.groupFiles = GroupFiles;
|
2017-10-20 19:04:22 +00:00
|
|
|
|
2017-10-30 08:42:03 +00:00
|
|
|
// Actual execution in the controller's initialization
|
2017-10-30 09:08:42 +00:00
|
|
|
$scope.groups.nextPage('')
|
|
|
|
.then(() => $scope.loadGroup(0));
|
2017-10-20 19:04:22 +00:00
|
|
|
|
2017-10-30 08:42:03 +00:00
|
|
|
$scope.load = false;
|
2017-10-20 19:04:22 +00:00
|
|
|
|
2017-10-30 09:08:42 +00:00
|
|
|
$scope.showFiles = (index) => {
|
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-10-30 08:42:03 +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) => {
|
|
|
|
$scope.groupAgents.reset();
|
2017-10-30 09:08:42 +00:00
|
|
|
$scope.groupAgents.path = `/agents/groups/${$scope.groups.items[index].name}`;
|
2017-10-30 08:42:03 +00:00
|
|
|
$scope.groupAgents.nextPage('')
|
|
|
|
.then(() => {
|
|
|
|
let promises = [];
|
|
|
|
for(let agent of $scope.groupAgents.items){
|
|
|
|
promises.push(apiReq.request('GET', `/agents/${agent.id}`, {}));
|
|
|
|
}
|
|
|
|
return Promise.all(promises);
|
|
|
|
})
|
|
|
|
.then((resolvedArray) => {
|
|
|
|
for(let data of resolvedArray){
|
|
|
|
console.log(data);
|
|
|
|
}
|
2017-10-20 19:04:22 +00:00
|
|
|
});
|
2017-10-30 08:42:03 +00:00
|
|
|
};
|
2017-10-20 19:04:22 +00:00
|
|
|
|
2017-10-30 08:42:03 +00:00
|
|
|
$scope.loadGroup = (index) => {
|
|
|
|
$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
|
|
|
|
2017-10-30 08:42:03 +00:00
|
|
|
$scope.showFile = (index) => {
|
|
|
|
$scope.test = !$scope.test;
|
|
|
|
$scope.file = 'Loading...';
|
|
|
|
let tmpName = `/agents/groups/${$scope.groups.items[$scope.selectedGroup].name}`+
|
|
|
|
`/files/${$scope.groupFiles.items[index].filename}`;
|
|
|
|
apiReq.request('GET', tmpName, {})
|
|
|
|
.then((data) => $scope.file = data.data);
|
|
|
|
};
|
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();
|
|
|
|
$scope.groupsFiles.reset();
|
|
|
|
$scope.groupsAgents.reset();
|
|
|
|
});
|
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 = '';
|
|
|
|
});
|