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-11-03 12:33:37 +00:00
|
|
|
function ($scope, $timeout, $rootScope,$mdSidenav, $location, apiReq, Groups, GroupFiles, GroupAgents) {
|
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-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-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
|
|
|
|
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;
|
2017-10-30 08:42:03 +00:00
|
|
|
$scope.file = 'Loading...';
|
|
|
|
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;
|
|
|
|
})
|
|
|
|
.catch(err => $scope.file = {
|
2017-10-31 15:16:47 +00:00
|
|
|
group: $scope.groups.items[$scope.selectedGroup].name,
|
2017-11-02 08:12:53 +00:00
|
|
|
file: $scope.groupFiles.items[index].filename,
|
2017-10-31 15:16:47 +00:00
|
|
|
error: err.message || err
|
|
|
|
});
|
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-11-02 09:22:46 +00:00
|
|
|
|
|
|
|
|
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 = '';
|
|
|
|
});
|