2017-02-10 13:53:08 +00:00
|
|
|
import rison from 'rison-node';
|
2016-09-16 12:35:56 +00:00
|
|
|
var app = require('ui/modules').get('app/wazuh', []);
|
|
|
|
|
2017-02-10 21:33:49 +00:00
|
|
|
app.controller('overviewController', function ($scope, appState, $window, genericReq, $q, $routeParams, $route, $location, $http) {
|
2017-02-07 17:05:51 +00:00
|
|
|
|
|
|
|
$scope.state = appState;
|
|
|
|
$scope.defaultManager = $scope.state.getDefaultManager().name;
|
|
|
|
$scope.extensions = $scope.state.getExtensions().extensions;
|
|
|
|
$scope.submenuNavItem = "general";
|
|
|
|
$scope.tabView = "panels";
|
|
|
|
|
2017-02-10 21:33:49 +00:00
|
|
|
// Object for matching nav items and Wazuh groups
|
|
|
|
var tabGroups = {
|
|
|
|
"general": {"group": "*"},
|
|
|
|
"fim": {"group": "syscheck"},
|
|
|
|
"pm": {"group": "rootcheck"},
|
|
|
|
"oscap": {"group": "oscap"},
|
|
|
|
"audit": {"group": "audit"},
|
|
|
|
"pci": {"group": "*"}
|
|
|
|
};
|
|
|
|
|
2017-02-07 17:05:51 +00:00
|
|
|
var tab = "";
|
|
|
|
var view = "";
|
|
|
|
if($routeParams.tab)
|
|
|
|
$scope.submenuNavItem = $routeParams.tab;
|
|
|
|
|
|
|
|
if($routeParams.view)
|
|
|
|
$scope.tabView = $routeParams.view;
|
|
|
|
|
|
|
|
$scope.openDashboard = function (dashboard, filter) {
|
|
|
|
$scope.state.setDashboardsState(dashboard, filter);
|
|
|
|
$window.location.href = '#/dashboards/';
|
|
|
|
|
|
|
|
}
|
|
|
|
$scope.openDiscover = function (template, filter) {
|
|
|
|
$scope.state.setDiscoverState(template, filter);
|
|
|
|
$window.location.href = '#/discover/';
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.extensionStatus = function (extension) {
|
|
|
|
return $scope.extensions[extension];
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.$watch('tabView', function() {
|
|
|
|
$location.search('view', $scope.tabView);
|
|
|
|
});
|
|
|
|
|
2017-02-10 21:33:49 +00:00
|
|
|
$scope.results = false;
|
2017-02-07 17:05:51 +00:00
|
|
|
$scope.$watch('submenuNavItem', function() {
|
|
|
|
$location.search('tab', $scope.submenuNavItem);
|
2017-02-10 21:33:49 +00:00
|
|
|
$scope.presentData().then(function (data) {$scope.results = data;});
|
2017-02-07 17:05:51 +00:00
|
|
|
});
|
2017-02-10 13:53:08 +00:00
|
|
|
|
2017-02-10 21:33:49 +00:00
|
|
|
// Get current time filter or default
|
2017-02-13 19:58:44 +00:00
|
|
|
$scope.timeGTE = ($route.current.params._g && $route.current.params._g != "()") ? rison.decode($route.current.params._g).time.from : "now-1d";
|
|
|
|
$scope.timeLT = ($route.current.params._g && $route.current.params._g != "()") ? rison.decode($route.current.params._g).time.to : "now";
|
2017-02-10 21:33:49 +00:00
|
|
|
|
|
|
|
// Check if there are any alert.
|
|
|
|
$scope.presentData = function () {
|
|
|
|
var group = tabGroups[$scope.submenuNavItem].group;
|
|
|
|
var payload = {};
|
|
|
|
var fields = {"fields" : [{"field": "rule.groups", "value": group}]};
|
|
|
|
// No filter needed for general/pci
|
|
|
|
if(group == "*")
|
|
|
|
fields = {"fields" : []};
|
|
|
|
var managerName = {"manager" : $scope.defaultManager};
|
|
|
|
var timeInterval = {"timeinterval": {"gte" : $scope.timeGTE, "lt": $scope.timeLT}};
|
|
|
|
angular.extend(payload, fields, managerName, timeInterval);
|
|
|
|
|
2017-02-10 13:53:08 +00:00
|
|
|
var deferred = $q.defer();
|
2017-02-10 21:33:49 +00:00
|
|
|
$http.post('/api/wazuh-elastic/alerts-count/', payload).then(function (data) {
|
|
|
|
if(data.data.data != 0)
|
2017-02-10 13:53:08 +00:00
|
|
|
deferred.resolve(true);
|
|
|
|
else
|
|
|
|
deferred.resolve(false);
|
2017-02-10 21:33:49 +00:00
|
|
|
});
|
2017-02-10 13:53:08 +00:00
|
|
|
return deferred.promise;
|
|
|
|
};
|
2017-02-10 21:33:49 +00:00
|
|
|
|
|
|
|
// Watch for timefilter changes
|
|
|
|
$scope.$on('$routeUpdate', function(){
|
2017-02-13 19:58:44 +00:00
|
|
|
if($location.search()._g){
|
|
|
|
var currentTimeFilter = rison.decode($location.search()._g);
|
|
|
|
// Check if timefilter has changed and update values
|
|
|
|
if($route.current.params._g != "()" && ($scope.timeGTE != currentTimeFilter.time.from || $scope.timeLT != currentTimeFilter.time.to)){
|
|
|
|
$scope.timeGTE = currentTimeFilter.time.from;
|
|
|
|
$scope.timeLT = currentTimeFilter.time.to;
|
|
|
|
|
|
|
|
//Check for present data for the selected tab
|
|
|
|
$scope.presentData().then(function (data) {$scope.results = data;});
|
|
|
|
}
|
2017-02-10 21:33:49 +00:00
|
|
|
}
|
|
|
|
});
|
2017-02-07 17:05:51 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2017-02-01 21:06:05 +00:00
|
|
|
app.controller('overviewGeneralController', function ($scope, DataFactory, genericReq, $mdToast, errlog, $route) {
|
2017-02-07 16:05:53 +00:00
|
|
|
|
2016-09-16 12:35:56 +00:00
|
|
|
$scope.load = true;
|
2017-02-01 21:06:05 +00:00
|
|
|
$scope.$parent.state.setOverviewState('general');
|
2016-11-09 19:10:48 +00:00
|
|
|
$scope.defaultManager = $scope.$parent.state.getDefaultManager().name;
|
2017-02-07 16:05:53 +00:00
|
|
|
|
2016-09-17 20:38:31 +00:00
|
|
|
});
|
|
|
|
|
2017-02-01 21:06:05 +00:00
|
|
|
app.controller('overviewFimController', function ($scope, DataFactory, genericReq, $mdToast, errlog, $route) {
|
2017-01-16 18:27:53 +00:00
|
|
|
|
2016-09-17 20:38:31 +00:00
|
|
|
$scope.load = true;
|
2017-02-01 21:06:05 +00:00
|
|
|
$scope.$parent.state.setOverviewState('fim');
|
2016-11-09 19:10:48 +00:00
|
|
|
$scope.defaultManager = $scope.$parent.state.getDefaultManager().name;
|
2016-09-16 12:35:56 +00:00
|
|
|
|
2016-09-22 12:02:46 +00:00
|
|
|
});
|
|
|
|
|
2017-02-01 21:06:05 +00:00
|
|
|
app.controller('overviewPMController', function ($scope, DataFactory, genericReq, $mdToast, errlog, $route) {
|
2017-01-16 18:27:53 +00:00
|
|
|
|
2016-09-22 12:02:46 +00:00
|
|
|
$scope.load = true;
|
|
|
|
$scope.$parent.state.setOverviewState('pm');
|
2016-11-09 19:10:48 +00:00
|
|
|
$scope.defaultManager = $scope.$parent.state.getDefaultManager().name;
|
2016-09-22 12:02:46 +00:00
|
|
|
|
2017-01-13 20:34:35 +00:00
|
|
|
});
|
2016-09-16 12:35:56 +00:00
|
|
|
|
2017-02-01 21:06:05 +00:00
|
|
|
app.controller('overviewOSCAPController', function ($scope, DataFactory, genericReq, $mdToast, errlog, $route) {
|
2017-01-16 18:27:53 +00:00
|
|
|
|
2017-02-10 13:53:08 +00:00
|
|
|
$scope.load = false;
|
2017-01-13 20:34:35 +00:00
|
|
|
$scope.$parent.state.setOverviewState('oscap');
|
|
|
|
$scope.defaultManager = $scope.$parent.state.getDefaultManager().name;
|
2017-02-10 13:53:08 +00:00
|
|
|
|
2016-09-16 12:35:56 +00:00
|
|
|
});
|
2017-01-23 13:14:59 +00:00
|
|
|
|
2017-02-01 21:06:05 +00:00
|
|
|
app.controller('overviewAuditController', function ($scope, DataFactory, genericReq, $mdToast, errlog, $route) {
|
2017-01-23 13:14:59 +00:00
|
|
|
|
|
|
|
$scope.load = true;
|
|
|
|
$scope.$parent.state.setOverviewState('audit');
|
|
|
|
$scope.defaultManager = $scope.$parent.state.getDefaultManager().name;
|
2017-01-30 12:03:17 +00:00
|
|
|
});
|
|
|
|
|
2017-02-01 21:06:05 +00:00
|
|
|
app.controller('overviewPCIController', function ($scope, $compile, DataFactory, genericReq, $mdToast, errlog, $route) {
|
2017-01-30 12:03:17 +00:00
|
|
|
|
|
|
|
$scope.load = true;
|
|
|
|
$scope.$parent.state.setOverviewState('pci');
|
|
|
|
$scope.defaultManager = $scope.$parent.state.getDefaultManager().name;
|
2017-02-01 21:06:05 +00:00
|
|
|
|
2017-01-30 18:38:33 +00:00
|
|
|
var tabs = [];
|
|
|
|
genericReq.request('GET', '/api/wazuh-api/pci/all').then(function (data) {
|
|
|
|
angular.forEach(data, function(value, key) {
|
|
|
|
tabs.push({"title": key, "content": value});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
$scope.tabs = tabs;
|
|
|
|
$scope.selectedIndex = 0;
|
|
|
|
|
|
|
|
$scope.addTab = function (title, view) {
|
|
|
|
view = view || title + " Content View";
|
|
|
|
tabs.push({ title: title, content: view, disabled: false});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.removeTab = function (tab) {
|
|
|
|
var index = tabs.indexOf(tab);
|
|
|
|
tabs.splice(index, 1);
|
|
|
|
};
|
2017-01-30 12:03:17 +00:00
|
|
|
|
2017-01-23 13:14:59 +00:00
|
|
|
});
|