Allowing to disable agents actions

This commit is contained in:
malbarral 2017-08-03 10:43:02 +02:00
parent 919af49658
commit f9683041b9
4 changed files with 48 additions and 5 deletions

View File

@ -12,6 +12,11 @@
"wazuh",
"ossec"
],
"agents": {
"add": true,
"delete": true,
"restart": true
},
"author": "Wazuh, Inc",
"license": "GPL-2.0",
"repository": {

View File

@ -43,6 +43,11 @@ app.controller('agentsPreviewController', function ($scope, $mdDialog, DataFacto
'name': '', 'ip': ''
};
$scope.newAgentKey = '';
$scope.permissions = {
'add': false,
'delete':false,
'restart': false
};
const notify = new Notifier({location: 'Agents - Preview'});
@ -264,6 +269,15 @@ app.controller('agentsPreviewController', function ($scope, $mdDialog, DataFacto
$mdDialog.hide('#newAgentDialog');
};
var getAgentsPermissions = function () {
genericReq.request('GET', '/api/wazuh-api/agents/permissions')
.then(function (data, status) {
$scope.permissions = data;
}, function (data, status) {
notify.error("Error while loading agents permissions.");
})
}
getAgentsPermissions();
var load = function () {
$scope.newAgent = {
'name': '', 'ip': ''

View File

@ -127,15 +127,15 @@
<md-divider></md-divider>
</div>
<div class="agent-buttons">
<md-button class="md-fab add-agent-icon" ng-click="showNewAgentDialog($event)" >
<md-button ng-if="permissions.add" class="md-fab add-agent-icon" ng-click="showNewAgentDialog($event)" >
<md-icon md-font-library="material-icons">add</md-icon>
</md-button>
<md-button class="md-fab restart-agent-icon" ng-click="showRestartConfirm($event)" >
<md-button ng-if="permissions.restart" class="md-fab restart-agent-icon" ng-click="showRestartConfirm($event)" >
<md-icon md-font-library="material-icons">refresh</md-icon>
</md-button>
<md-button class="md-fab delete-agent-icon" ng-click="showDeletePrompt($event)" >
<md-button ng-if="permissions.delete" class="md-fab delete-agent-icon" ng-click="showDeletePrompt($event)" >
<md-icon md-font-library="material-icons">delete</md-icon>
</md-button>
</div>

View File

@ -12,7 +12,7 @@ module.exports = function (server, options) {
var package_info = {};
const package_file = '../../package.json';
var appVersion = "";
var permissions = {}
// Read Wazuh App package file
try {
package_info = JSON.parse(fs.readFileSync(path.resolve(__dirname, package_file), 'utf8'));
@ -273,6 +273,19 @@ module.exports = function (server, options) {
};
var getAgentsPermissions = function (req, reply) {
try {
package_info = JSON.parse(fs.readFileSync(path.resolve(__dirname, package_file), 'utf8'));
permissions = package_info.agents;
reply(permissions);
} catch (e) {
server.log([blueWazuh, 'initialize', 'error'], 'Could not read the Wazuh package file.');
server.log([blueWazuh, 'initialize', 'error'], 'Path: ' + package_file);
server.log([blueWazuh, 'initialize', 'error'], 'Exception: ' + e);
reply({ 'statusCode': 500, 'error': 8, 'message': 'Could not load agents permissions' }).code(500);
};
}
//Handlers - Route request
@ -531,6 +544,17 @@ module.exports = function (server, options) {
handler: getPciRequirement
});
/*
* GET /api/wazuh-api/agents/permissions
* Return the permissions on agents
*
**/
server.route({
method: 'GET',
path: '/api/wazuh-api/agents/permissions',
handler: getAgentsPermissions
});
/*
* POST /api/wazuh/debug
* Write in debug log