2017-10-30 09:08:42 +00:00
|
|
|
let app = require('ui/modules').get('app/wazuh', []);
|
2017-01-16 12:29:48 +00:00
|
|
|
|
2017-10-31 15:16:47 +00:00
|
|
|
app.controller('agentsController',
|
2017-11-28 16:37:31 +00:00
|
|
|
function ($scope, $location, $rootScope, Notifier, appState, genericReq, apiReq, AgentsAutoComplete) {
|
|
|
|
$rootScope.page = 'agents';
|
|
|
|
$scope.extensions = appState.getExtensions().extensions;
|
2017-10-30 09:08:42 +00:00
|
|
|
$scope.agentsAutoComplete = AgentsAutoComplete;
|
2017-11-28 16:37:31 +00:00
|
|
|
const notify = new Notifier({ location: 'Agents' });
|
2017-10-20 19:04:22 +00:00
|
|
|
|
2017-11-28 16:37:31 +00:00
|
|
|
// Check the url hash and retriew the tabView information
|
2017-10-30 09:08:42 +00:00
|
|
|
if ($location.search().tabView){
|
2017-10-20 19:04:22 +00:00
|
|
|
$scope.tabView = $location.search().tabView;
|
2017-11-28 16:37:31 +00:00
|
|
|
} else { // If tabView doesn't exist, default it to 'panels' view
|
2017-10-20 19:04:22 +00:00
|
|
|
$scope.tabView = "panels";
|
|
|
|
$location.search("tabView", "panels");
|
|
|
|
}
|
|
|
|
|
2017-11-28 16:37:31 +00:00
|
|
|
// Check the url hash and retrivew the tab information
|
2017-11-20 18:20:27 +00:00
|
|
|
if ($location.search().tab){
|
|
|
|
$scope.tab = $location.search().tab;
|
2017-11-28 16:37:31 +00:00
|
|
|
} else { // If tab doesn't exist, default it to 'general' view
|
|
|
|
$scope.tab = "general";
|
|
|
|
$location.search("tab", "general");
|
|
|
|
|
|
|
|
// Now we initialize the implicitFilter
|
|
|
|
$rootScope.currentImplicitFilter = "";
|
2017-11-20 18:20:27 +00:00
|
|
|
}
|
|
|
|
|
2017-02-10 21:33:49 +00:00
|
|
|
// Object for matching nav items and Wazuh groups
|
2017-11-17 16:01:16 +00:00
|
|
|
let tabFilters = {
|
2017-11-28 16:37:31 +00:00
|
|
|
"general": {
|
2017-11-17 16:01:16 +00:00
|
|
|
"group": ""
|
2017-10-30 09:08:42 +00:00
|
|
|
},
|
|
|
|
"fim": {
|
|
|
|
"group": "syscheck"
|
|
|
|
},
|
2017-11-28 16:37:31 +00:00
|
|
|
"pm": {
|
2017-10-30 09:08:42 +00:00
|
|
|
"group": "rootcheck"
|
|
|
|
},
|
|
|
|
"oscap": {
|
|
|
|
"group": "oscap"
|
|
|
|
},
|
|
|
|
"audit": {
|
|
|
|
"group": "audit"
|
|
|
|
},
|
|
|
|
"pci": {
|
2017-11-27 16:27:07 +00:00
|
|
|
"group": "pci_dss"
|
2017-10-30 09:08:42 +00:00
|
|
|
}
|
|
|
|
};
|
2017-08-13 19:54:56 +00:00
|
|
|
|
2017-11-20 18:20:27 +00:00
|
|
|
// Switch subtab
|
|
|
|
$scope.switchSubtab = (subtab) => {
|
|
|
|
$scope.tabView = subtab;
|
|
|
|
};
|
|
|
|
|
2017-10-30 09:08:42 +00:00
|
|
|
$scope.switchTab = (tab) => {
|
2017-11-28 16:37:31 +00:00
|
|
|
// Deleting app state traces in the url
|
2017-11-17 16:01:16 +00:00
|
|
|
$location.search('_a', null);
|
2017-11-27 16:27:07 +00:00
|
|
|
$scope.tabView = 'panels';
|
|
|
|
};
|
2017-11-17 16:01:16 +00:00
|
|
|
|
2017-11-27 16:27:07 +00:00
|
|
|
// Watchers
|
2017-11-17 16:01:16 +00:00
|
|
|
|
2017-11-27 16:27:07 +00:00
|
|
|
// We watch the resultState provided by the discover
|
|
|
|
$scope.$watch('tabView', () => $location.search('tabView', $scope.tabView));
|
|
|
|
$scope.$watch('tab', () => {
|
|
|
|
$location.search('tab', $scope.tab);
|
2017-11-17 16:01:16 +00:00
|
|
|
// Update the implicit filter
|
2017-11-28 16:37:31 +00:00
|
|
|
if (tabFilters[$scope.tab].group === "") $rootScope.currentImplicitFilter = "";
|
|
|
|
else $rootScope.currentImplicitFilter = tabFilters[$scope.tab].group;
|
2017-11-27 16:27:07 +00:00
|
|
|
});
|
2017-08-13 19:54:56 +00:00
|
|
|
|
2017-11-28 16:37:31 +00:00
|
|
|
// Agent data
|
2017-10-30 09:08:42 +00:00
|
|
|
$scope.getAgentStatusClass = (agentStatus) => agentStatus === "Active" ? "green" : "red";
|
2017-01-16 12:29:48 +00:00
|
|
|
|
2017-10-30 09:08:42 +00:00
|
|
|
$scope.formatAgentStatus = (agentStatus) => {
|
|
|
|
let condition = (agentStatus !== "Active" || agentStatus === "Disconnected");
|
|
|
|
return (condition) ? "Never connected" : agentStatus;
|
|
|
|
};
|
2017-08-13 19:54:56 +00:00
|
|
|
|
2017-11-27 17:45:38 +00:00
|
|
|
const calculateMinutes = (start,end) => {
|
|
|
|
let time = new Date(start);
|
|
|
|
let endTime = new Date(end);
|
2017-11-28 16:37:31 +00:00
|
|
|
let minutes = ((endTime - time) / 1000) / 60;
|
2017-11-27 17:45:38 +00:00
|
|
|
return minutes;
|
|
|
|
}
|
|
|
|
|
|
|
|
const validateRootCheck = () => {
|
2017-11-28 16:37:31 +00:00
|
|
|
$scope.agent.rootcheck.duration = 'Unknown';
|
|
|
|
if ($scope.agent.rootcheck.end && $scope.agent.rootcheck.start) {
|
|
|
|
let minutes = calculateMinutes($scope.agent.rootcheck.start, $scope.agent.rootcheck.end);
|
|
|
|
$scope.agent.rootcheck.duration = window.Math.round(minutes);
|
2017-11-27 17:45:38 +00:00
|
|
|
} else {
|
2017-11-28 16:37:31 +00:00
|
|
|
if (!$scope.agent.rootcheck.end) {
|
|
|
|
$scope.agent.rootcheck.end = 'Unknown';
|
2017-11-27 17:45:38 +00:00
|
|
|
}
|
2017-11-28 16:37:31 +00:00
|
|
|
if (!$scope.agent.rootcheck.start){
|
|
|
|
$scope.agent.rootcheck.start = 'Unknown';
|
2017-11-27 17:45:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const validateSysCheck = () => {
|
2017-11-28 16:37:31 +00:00
|
|
|
$scope.agent.syscheck.duration = 'Unknown';
|
|
|
|
if ($scope.agent.syscheck.end && $scope.agent.syscheck.start) {
|
|
|
|
let minutes = calculateMinutes($scope.agent.syscheck.start, $scope.agent.syscheck.end);
|
|
|
|
$scope.agent.syscheck.duration = window.Math.round(minutes);
|
2017-11-27 17:45:38 +00:00
|
|
|
} else {
|
2017-11-28 16:37:31 +00:00
|
|
|
if (!$scope.agent.syscheck.end) {
|
|
|
|
$scope.agent.syscheck.end = 'Unknown';
|
2017-11-27 17:45:38 +00:00
|
|
|
}
|
2017-11-28 16:37:31 +00:00
|
|
|
if (!$scope.agent.syscheck.start){
|
|
|
|
$scope.agent.syscheck.start = 'Unknown';
|
2017-11-27 17:45:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-29 10:02:34 +00:00
|
|
|
$scope.getAgent = newAgentId => {
|
|
|
|
let id = null;
|
|
|
|
|
2017-11-29 11:25:34 +00:00
|
|
|
// They passed an id
|
|
|
|
if (newAgentId) {
|
|
|
|
id = newAgentId;
|
|
|
|
$location.search('agent', id);
|
|
|
|
} else {
|
|
|
|
if ($location.search().agent) { // There's one in the url
|
|
|
|
id = $location.search().agent;
|
|
|
|
} else { // We pick the one in the rootScope
|
|
|
|
id = $rootScope.globalAgent;
|
|
|
|
$location.search('agent', id);
|
2017-11-29 10:02:34 +00:00
|
|
|
delete $rootScope.globalAgent;
|
|
|
|
}
|
|
|
|
}
|
2017-11-28 16:37:31 +00:00
|
|
|
|
|
|
|
Promise.all([
|
2017-11-29 11:25:34 +00:00
|
|
|
apiReq.request('GET', `/agents/${id}`, {}),
|
|
|
|
apiReq.request('GET', `/syscheck/${id}/last_scan`, {}),
|
|
|
|
apiReq.request('GET', `/rootcheck/${id}/last_scan`, {})
|
2017-11-28 16:37:31 +00:00
|
|
|
])
|
|
|
|
.then(data => {
|
2017-11-29 10:02:34 +00:00
|
|
|
// Agent
|
|
|
|
$scope.agent = data[0].data.data;
|
2017-11-29 11:25:34 +00:00
|
|
|
|
2017-11-29 18:36:56 +00:00
|
|
|
if ($scope.agent.os) {
|
2017-11-29 11:25:34 +00:00
|
|
|
$scope.agentOS = $scope.agent.os.name + ' ' + $scope.agent.os.version;
|
|
|
|
}
|
|
|
|
else { $scope.agentOS = "Unkwnown" };
|
|
|
|
|
2017-11-28 16:37:31 +00:00
|
|
|
// Syscheck
|
2017-11-29 10:02:34 +00:00
|
|
|
$scope.agent.syscheck = data[1].data.data;
|
2017-11-28 16:37:31 +00:00
|
|
|
validateSysCheck();
|
|
|
|
// Rootcheck
|
2017-11-29 10:02:34 +00:00
|
|
|
$scope.agent.rootcheck = data[2].data.data;
|
2017-11-28 16:37:31 +00:00
|
|
|
validateRootCheck();
|
|
|
|
|
|
|
|
$scope.$digest();
|
|
|
|
})
|
|
|
|
.catch(error => notify.error(error.message));
|
2017-10-30 09:08:42 +00:00
|
|
|
};
|
2017-01-16 12:29:48 +00:00
|
|
|
|
2017-10-30 09:08:42 +00:00
|
|
|
//Load
|
|
|
|
try {
|
2017-11-28 16:37:31 +00:00
|
|
|
$scope.getAgent();
|
|
|
|
$scope.agentsAutoComplete.nextPage('');
|
2017-10-30 09:08:42 +00:00
|
|
|
} catch (e) {
|
|
|
|
notify.error('Unexpected exception loading controller');
|
|
|
|
}
|
2017-10-20 19:04:22 +00:00
|
|
|
|
2017-10-30 09:08:42 +00:00
|
|
|
//Destroy
|
|
|
|
$scope.$on("$destroy", () => $scope.agentsAutoComplete.reset());
|
2017-11-03 12:33:37 +00:00
|
|
|
|
2017-11-28 16:37:31 +00:00
|
|
|
//PCI tab
|
2017-10-30 09:08:42 +00:00
|
|
|
let tabs = [];
|
|
|
|
genericReq.request('GET', '/api/wazuh-api/pci/all')
|
|
|
|
.then((data) => {
|
2017-11-27 16:45:12 +00:00
|
|
|
for(let key in data.data){
|
2017-10-30 09:08:42 +00:00
|
|
|
tabs.push({
|
|
|
|
"title": key,
|
2017-11-27 16:45:12 +00:00
|
|
|
"content": data.data[key]
|
2017-10-30 09:08:42 +00:00
|
|
|
});
|
2017-11-27 16:45:12 +00:00
|
|
|
}
|
2017-12-01 17:28:48 +00:00
|
|
|
})
|
|
|
|
.catch(error => notify.error(error.message));
|
2017-10-20 19:04:22 +00:00
|
|
|
|
2017-10-30 09:08:42 +00:00
|
|
|
$scope.tabs = tabs;
|
|
|
|
$scope.selectedIndex = 0;
|
2017-11-27 16:27:07 +00:00
|
|
|
});
|