Extension switcher finish.

This commit is contained in:
Pedro Sanchez 2017-01-23 09:58:50 -08:00
parent 677af07888
commit 85a1b4da7a
10 changed files with 94 additions and 78 deletions

View File

@ -10,9 +10,9 @@ app.controller('agentsController', function ($scope, $q, DataFactory, $mdToast,
$scope.state = appState;
$scope._status = 'all';
$scope.dynamicTab_fields = {};
var objectsArray = [];
$scope.defaultManager = $scope.state.getDefaultManager().name;
$scope.extensions = $scope.state.getExtensions().extensions;
//Print Error
var printError = function (error) {
@ -60,23 +60,9 @@ app.controller('agentsController', function ($scope, $q, DataFactory, $mdToast,
});
return promise;
};
var daysAgo = 7;
var date = new Date();
date.setDate(date.getDate() - daysAgo);
var timeAgo = date.getTime();
// Function: Check if rule group exists on Elastic cluster latest alerts.
$scope.dynamicTab_exists = function (group, agentName) {
genericReq.request('GET', '/api/wazuh-elastic/top/'+$scope.defaultManager+'/rule.groups/rule.groups/'+group+'/agent.name/'+agentName+'/'+timeAgo)
.then(function (data) {
console.log(data);
if(data.data != ""){
$scope.dynamicTab_fields[group] = true;
}else{
$scope.dynamicTab_fields[group] = false
}
});
$scope.extensionStatus = function (extension) {
return $scope.extensions[extension];
};
$scope.applyAgent = function (agent) {
@ -85,11 +71,7 @@ app.controller('agentsController', function ($scope, $q, DataFactory, $mdToast,
//$scope.submenuNavItem = 'fim';
$scope.submenuNavItem = 'overview';
$scope._agent = agent;
$scope.search = agent.name;
// Checking dynamic panels
$scope.dynamicTab_exists("oscap", $scope._agent.name);
$scope.search = agent.name;
$scope.load = false;
}
};

View File

@ -15,8 +15,7 @@ app.controller('stateController', function ($scope, appState, $route) {
app.controller('generalController', function ($scope, appState, $window, genericReq, $q) {
$scope.state = appState;
$scope.defaultManager = $scope.state.getDefaultManager().name;
$scope.dynamicTab_fields = {};
$scope.extensions = $scope.state.getExtensions().extensions;
$scope.openDashboard = function (dashboard, filter) {
$scope.state.setDashboardsState(dashboard, filter);
@ -37,19 +36,8 @@ app.controller('generalController', function ($scope, appState, $window, generic
date.setDate(date.getDate() - daysAgo);
var timeAgo = date.getTime();
// Function: Check if rule group exists on Elastic cluster latest alerts.
$scope.dynamicTab_exists = function (group) {
genericReq.request('GET', '/api/wazuh-elastic/top/'+$scope.defaultManager+'/rule.groups/rule.groups/'+group+'/'+timeAgo)
.then(function (data) {
console.log(data);
if(data.data != ""){
$scope.dynamicTab_fields[group] = true;
}else{
$scope.dynamicTab_fields[group] = false
}
});
$scope.extensionStatus = function (extension) {
return $scope.extensions[extension];
};
// Checking dynamic panels
$scope.dynamicTab_exists("oscap");
});

View File

@ -13,7 +13,7 @@ app.controller('settingsController', function ($scope, $http, testConnection, ap
$scope.editConfiguration = true;
$scope.menuNavItem = 'settings';
$scope.load = true;
$scope.currentDefault = "";
$scope.currentDefault = 0;
$scope.managerAPI = "";
$scope.extensions = {};
$scope.extensions.oscap = true;
@ -43,7 +43,8 @@ app.controller('settingsController', function ($scope, $http, testConnection, ap
$scope.apiEntries[$scope.currentDefault]._source.active = "false";
$scope.apiEntries[index]._source.active = "true";
$scope.currentDefault = index;
$mdToast.show($mdToast.simple().textContent("Manager "+$scope.apiEntries[index]._source.url+" set as default"));
$scope.extensions = $scope.apiEntries[$scope.currentDefault]._source.extensions;
$mdToast.show($mdToast.simple().textContent("Manager "+$scope.apiEntries[index]._source.manager+" set as default"));
}).error(function (data, status) {
$mdToast.show($mdToast.simple().textContent("Could not set that manager as default"));
})
@ -54,8 +55,15 @@ app.controller('settingsController', function ($scope, $http, testConnection, ap
$http.get("/api/wazuh-api/apiEntries").success(function (data, status) {
$scope.apiEntries = data;
angular.forEach($scope.apiEntries, function (value, key) {
if(value._source.active == "true")
if(value._source.active == "true"){
$scope.currentDefault = key;
if(value._source.extensions){
$scope.extensions = value._source.extensions;
}else{
$scope.extensions.oscap = true;
$scope.extensions.audit = true;
}
}
});
@ -86,9 +94,10 @@ app.controller('settingsController', function ($scope, $http, testConnection, ap
testConnection.test_tmp(tmpData).then(function (data) {
// API Check correct, get Manager name
tmpData.manager = data;
tmpData.extensions = {"oscap": true, "audit": true};
// Insert new API entry
$http.put("/api/wazuh-api/settings", tmpData).success(function (data, status) {
var newEntry = {'_id': data.response._id, _source: { manager: tmpData.manager, active: tmpData.active, url: tmpData.url, api_user: tmpData.user, api_port: tmpData.port } };
var newEntry = {'_id': data.response._id, _source: { manager: tmpData.manager, active: tmpData.active, url: tmpData.url, api_user: tmpData.user, api_port: tmpData.port } };
$scope.apiEntries.push(newEntry);
$mdToast.show($mdToast.simple().textContent('Successfully added'));
$scope.addManagerContainer = false;
@ -113,12 +122,14 @@ app.controller('settingsController', function ($scope, $http, testConnection, ap
$scope.saveSettings();
};
// Extensions
$scope.onChange = function(state) {
$scope.message = state;
//console.log(state);
console.log("Audit: " + $scope.extensions.audit);
console.log("Oscap: " + $scope.extensions.oscap);
// Toggle extension
$scope.toggleExtension = function(extension,state) {
if(extension == "oscap" || extension == "audit"){
$http.put("/api/wazuh-api/extension/toggle/"+$scope.apiEntries[$scope.currentDefault]._id+"/"+extension+"/"+state).success(function (data, status) {
}).error(function (data, status) {
$mdToast.show($mdToast.simple().textContent("Invalid request when toggle extension state."));
})
}
};
var printError = function (data) {

View File

@ -11,6 +11,14 @@ require('ui/modules').get('app/wazuh', [])
if (filter) {
$cookies.putObject('_dashboardsState_filter', filter);
}
},
getExtensions: function () {
return { extensions: $cookies.getObject('extensions') };
},
setExtensions: function (extensions) {
if (extensions) {
$cookies.putObject('extensions', extensions);
}
},
unsetDashboardsState: function () {
$cookies.putObject('_dashboardsState_name', "");

View File

@ -7,6 +7,7 @@ var settingsWizard = function ($location, testConnection, $mdToast, appState, $q
testConnection.test().then(function (data)
{
appState.setDefaultManager(data.manager);
appState.setExtensions(data.extensions);
deferred.resolve();
}, function (data) {
$mdToast.show({

View File

@ -71,8 +71,8 @@
<md-nav-item md-nav-click="submenuNavItem = 'overview'" name="overview">Overview</md-nav-item>
<md-nav-item md-nav-click="submenuNavItem = 'fim'" name="fim">File Integrity</md-nav-item>
<md-nav-item md-nav-click="submenuNavItem = 'policy_monitoring'" name="policy_monitoring">Policy Monitoring</md-nav-item>
<md-nav-item md-nav-click="submenuNavItem = 'oscap'" name="oscap" ng-show="dynamicTab_fields['oscap']">SCAP</md-nav-item>
<md-nav-item md-nav-click="submenuNavItem = 'audit'" name="audit">Audit</md-nav-item>
<md-nav-item md-nav-click="submenuNavItem = 'oscap'" name="oscap" ng-show="extensions.oscap">SCAP</md-nav-item>
<md-nav-item md-nav-click="submenuNavItem = 'audit'" name="audit" ng-show="extensions.audit">Audit</md-nav-item>
</md-nav-bar>
</md-content>

View File

@ -25,8 +25,8 @@
<md-nav-item md-nav-click="submenuNavItem = 'general'" name="general">General</md-nav-item>
<md-nav-item md-nav-click="submenuNavItem = 'fim'" name="fim">File integrity</md-nav-item>
<md-nav-item md-nav-click="submenuNavItem = 'pm'" name="pm">Policy monitoring</md-nav-item>
<md-nav-item md-nav-click="submenuNavItem = 'oscap'" name="oscap" ng-show="dynamicTab_fields['oscap']">SCAP</md-nav-item>
<md-nav-item md-nav-click="submenuNavItem = 'audit'" name="audit">Audit</md-nav-item>
<md-nav-item md-nav-click="submenuNavItem = 'oscap'" name="oscap" ng-show="extensions.oscap">SCAP</md-nav-item>
<md-nav-item md-nav-click="submenuNavItem = 'audit'" name="audit" ng-show="extensions.audit">Audit</md-nav-item>
</md-nav-bar>
</md-content>

View File

@ -87,7 +87,7 @@
OVAL (Open Vulnerability Assessment Language) interpreter used to check system configuration and detect vulnerable applications. It is recognized as a standardized compliance and hardening checking solution for enterprise-level infrastructure.
</span>
<span>
<md-switch flex ng-model="extensions.oscap" aria-label="extensionsOscap" ng-change="onChange(extensions.oscap)"></md-switch>
<md-switch flex ng-model="extensions.oscap" aria-label="extensionsOscap" ng-change="toggleExtension('oscap',extensions.oscap)"></md-switch>
</span>
<md-divider></md-divider>
</div>
@ -100,7 +100,7 @@
The Linux Audit system provides a way to track security-relevant information on your system. Based on pre-configured rules, Audit generates log entries to record as much information about the events that are happening on your system as possible.
</span>
<span layout="row" layout-align="space-between center">
<md-switch flex ng-model="extensions.audit" aria-label="extensionsAudit" ng-change="onChange(extensions.audit)"></md-switch>
<md-switch flex ng-model="extensions.audit" aria-label="extensionsAudit" ng-change="toggleExtension('audit',extensions.audit)"></md-switch>
</span>
</div>

View File

@ -31,7 +31,7 @@ module.exports = function (server, options) {
client.search({ index: '.kibana', type: 'wazuh-configuration', q: 'active:true'})
.then(function (data) {
if (data.hits.total == 1) {
callback({ 'user': data.hits.hits[0]._source.api_user, 'password': new Buffer(data.hits.hits[0]._source.api_password, 'base64').toString("ascii"), 'url': data.hits.hits[0]._source.url, 'port': data.hits.hits[0]._source.api_port, 'insecure': data.hits.hits[0]._source.insecure, 'manager': data.hits.hits[0]._source.manager });
callback({ 'user': data.hits.hits[0]._source.api_user, 'password': new Buffer(data.hits.hits[0]._source.api_password, 'base64').toString("ascii"), 'url': data.hits.hits[0]._source.url, 'port': data.hits.hits[0]._source.api_port, 'insecure': data.hits.hits[0]._source.insecure, 'manager': data.hits.hits[0]._source.manager, 'extensions': data.hits.hits[0]._source.extensions });
} else {
callback({ 'error': 'no credentials', 'error_code': 1 });
}
@ -92,12 +92,34 @@ module.exports = function (server, options) {
reply({ 'statusCode': 500, 'error': 8, 'message': 'Could not save data in elasticsearch' }).code(500);
});
};
var getExtensions = function (req,reply) {
client.search({ index: '.kibana', type: 'wazuh-configuration'}).then(
function (data) {
reply(data.hits.hits);
}, function (data, error) {
reply(data);
});
};
var toggleExtension = function (req,reply) {
// Toggle extenion state
var extension = {};
extension[req.params.extensionName] = (req.params.extensionValue == "true") ? true : false;
client.update({ index: '.kibana', type: 'wazuh-configuration', id: req.params.id, body: {doc: {"extensions" : extension}} }).then(
function () {
reply({ 'statusCode': 200, 'message': 'ok' });
}, function (error) {
reply({ 'statusCode': 500, 'error': 8, 'message': 'Could not save data in elasticsearch' }).code(500);
});
};
//Handlers - Test API
var testApiAux2 = function (error, response, wapi_config) {
if (!error && response && response.body.data && checkVersion(response.body.data)) {
return { 'statusCode': 200, 'data': 'ok', 'manager' : wapi_config.manager };
return { 'statusCode': 200, 'data': 'ok', 'manager' : wapi_config.manager, 'extensions' : wapi_config.extensions };
} else if (response && response.statusCode == 401) {
return { 'statusCode': 200, 'error': '1', 'data': 'unauthorized' };
} else if (!error && response && (!response.body.data || !checkVersion(response.body.data)) ) {
@ -113,7 +135,7 @@ module.exports = function (server, options) {
var testApiAux1 = function (error, response, wapi_config, needle, callback) {
if (!error && response && response.body.data && checkVersion(response.body.data)) {
callback({ 'statusCode': 200, 'data': 'ok', 'manager' : wapi_config.manager});
callback({ 'statusCode': 200, 'data': 'ok', 'manager' : wapi_config.manager, 'extensions' : wapi_config.extensions});
} else if (response && response.statusCode == 401) {
callback({ 'statusCode': 200, 'error': '1', 'data': 'unauthorized' });
} else if (!error && response && (!response.body.data || !checkVersion(response.body.data)) ) {
@ -265,8 +287,8 @@ module.exports = function (server, options) {
reply({ 'statusCode': 400, 'error': 7, 'message': 'Missing data' }).code(400);
return;
}
var settings = { 'api_user': req.payload.user, 'api_password': req.payload.password, 'url': req.payload.url, 'api_port': req.payload.port , 'insecure': req.payload.insecure, 'component' : 'API', 'active' : req.payload.active, 'manager' : req.payload.manager};
client.index({ index: '.kibana', type: 'wazuh-configuration', body: settings, refresh: true })
var settings = { 'api_user': req.payload.user, 'api_password': req.payload.password, 'url': req.payload.url, 'api_port': req.payload.port , 'insecure': req.payload.insecure, 'component' : 'API', 'active' : req.payload.active, 'manager' : req.payload.manager, 'extensions' : req.payload.extensions};
client.index({ index: '.kibana', type: 'wazuh-configuration', body: settings, refresh: true })
.then(function (response) {
reply({ 'statusCode': 200, 'message': 'ok', 'response' : response });
}, function (error) {
@ -274,23 +296,6 @@ module.exports = function (server, options) {
});
};
// Handlers - Update API Entry
var updateAPI_entry = function (req, reply) {
if (!(req.payload.user && req.payload.password && req.payload.url)) {
reply({ 'statusCode': 400, 'error': 7, 'message': 'Missing data' }).code(400);
return;
}
var settings = { 'api_user': req.payload.user, 'api_password': req.payload.password, 'url': req.payload.url, 'api_port': req.payload.port , 'insecure': req.payload.insecure, 'component' : 'API', 'manager' : req.payload.manager};
client.update({ index: '.kibana', type: 'wazuh-configuration', id: '1', body: {doc: settings} })
.then(function () {
reply({ 'statusCode': 200, 'message': 'ok' });
}, function (error) {
reply({ 'statusCode': 500, 'error': 8, 'message': 'Could not save data in elasticsearch' }).code(500);
});
};
//Handlers - Get API Settings
var getApiSettings = function (req, reply) {
@ -419,7 +424,30 @@ module.exports = function (server, options) {
handler: setAPI_entry_default
});
/*
/*
* PUT /api/wazuh-api/extension/toggle/documentId/extensionName/trueorfalse
* Toggle extension state: Enable / Disable
*
**/
server.route({
method: 'PUT',
path: '/api/wazuh-api/extension/toggle/{id}/{extensionName}/{extensionValue}',
handler: toggleExtension
});
/*
* GET /api/wazuh-api/extension
* Return extension state list
*
**/
server.route({
method: 'GET',
path: '/api/wazuh-api/extension',
handler: getExtensions
});
/*
* POST /api/wazuh/debug
* Write in debug log
*

View File

@ -52,8 +52,6 @@ module.exports = function (server, options) {
payload.query.bool.must[0].query_string.query = "host: " + req.params.manager;
}
console.log(payload.query.bool.must[0].query_string.query);
console.log(req.params);
payload.query.bool.must[1].range['@timestamp'].gte = timeAgo;
payload.aggs['2'].terms.field = req.params.field;