Ruleset tab

This commit is contained in:
jesmg 2016-08-31 13:40:04 +00:00
parent 01bab5c386
commit c6b4f43966
3 changed files with 47 additions and 27 deletions

View File

@ -532,7 +532,7 @@ app.controller('decodersController', function ($scope, $route, $q, alertify, sha
});
app.controller('updateRulesetController', function ($scope, $route, $q, alertify, sharedProperties, $location, $sce, DataFactory, tabProvider) {
app.controller('updateRulesetController', function ($scope, $route, $q, alertify, sharedProperties, $location, $sce, DataFactory, tabProvider, $mdDialog, $mdToast) {
//Initialisation
$scope.load = true;
@ -551,7 +551,11 @@ app.controller('updateRulesetController', function ($scope, $route, $q, alertify
//Print Error
var printError = function (error) {
alertify.delay(10000).closeLogOnClick(true).error(error.html);
$mdToast.show({
template: '<md-toast>' + error.html + '</md-toast>',
position: 'bottom left',
hideDelay: 5000,
});
}
//Tabs
@ -567,17 +571,28 @@ app.controller('updateRulesetController', function ($scope, $route, $q, alertify
//Backups
$scope.updateRuleset = function () {
$scope.updateRuleset = function (ev) {
if (!$scope.updateType) {
alertify.delay(10000).closeLogOnClick(true).error('Select an update type');
$mdToast.show({
template: '<md-toast>Select an update type</md-toast>',
position: 'bottom left',
hideDelay: 5000,
});
}
if ($scope.updateForce) {
var template = 'Are you sure you want to update the ruleset?<ul style="text-align: left !important;"><li style="text-align: left !important;">The ruleset will be overwritten, except local_rules and local_decoders file.</li><li style="text-align: left !important;">OSSEC manager is going to be restarted.</li><li style="text-align: left !important;">Before the update, backup of the ruleset will be done.</li></ul>';
var template = 'Are you sure you want to update the ruleset? The ruleset will be overwritten, except local_rules and local_decoders file. OSSEC manager is going to be restarted. Before the update, backup of the ruleset will be done.';
}
else {
var template = 'Are you sure you want to update the ruleset?<ul style="text-align: left !important;"><li style="text-align: left !important;">The ruleset will be overwritten, except local_rules and local_decoders file.</li><li style="text-align: left !important;">If any rule included in ossec.conf is updated, OSSEC manager will be restarted.</li><li style="text-align: left !important;">Before the update, backup of the ruleset will be done.</li></ul>';
var template = 'Are you sure you want to update the ruleset? The ruleset will be overwritten, except local_rules and local_decoders file. If any rule included in ossec.conf is updated, OSSEC manager will be restarted. Before the update, backup of the ruleset will be done.';
}
alertify.confirm(template, function () {
var confirm = $mdDialog.confirm()
.title('Update ruleset')
.textContent(template)
.targetEvent(ev)
.ok('Update')
.cancel('Cancel');
$mdDialog.show(confirm).then(function () {
if ($scope.updateForce) {
if ($scope.updateType == 'r') {
var path = '/manager/update-ruleset?force=yes&type=rules';
@ -606,14 +621,26 @@ app.controller('updateRulesetController', function ($scope, $route, $q, alertify
if (data.data.manual_steps !== 'no') {
alert += "The following manual steps are required: " + data.data.manual_steps_detail;
}
alertify.delay(10000).closeLogOnClick(true).success(alert);
$mdToast.show({
template: '<md-toast>' + alert + '</md-toast>',
position: 'bottom left',
hideDelay: 5000,
});
$scope.load_backups();
}, printError);
});
};
$scope.restoreBackup = function () {
alertify.confirm('Are you sure you want to restore this backup?<ul style="text-align: left !important;"><li style="text-align: left !important;">This action can not be undone.</li></ul>', function () {
$scope.restoreBackup = function (ev) {
var template = 'Are you sure you want to restore this backup? This action can not be undone.';
var confirm = $mdDialog.confirm()
.title('Restore backup')
.textContent(template)
.targetEvent(ev)
.ok('Restore')
.cancel('Cancel');
$mdDialog.show(confirm).then(function () {
DataFactory.getAndClean('put', '/manager/update-ruleset/backups/' + $scope.selectedBackup, {})
.then(function (data) {
var alert;
@ -628,7 +655,11 @@ app.controller('updateRulesetController', function ($scope, $route, $q, alertify
if (data.data.manual_steps !== 'no') {
alert += "The following manual steps are required: " + data.data.manual_steps_detail;
}
alertify.delay(10000).closeLogOnClick(true).success(alert);
$mdToast.show({
template: '<md-toast>' + alert + '</md-toast>',
position: 'bottom left',
hideDelay: 5000,
});
}, printError);
});
};

View File

@ -1,11 +1,7 @@
<md-content ng-if="submenuNavItem == 'overview'" ng-show="_agent" class="md-padding">
<div ng-controller="agentsController">
<md-content layout="row" layout-align="space-between start">
<md-content layout="row" layout-align="start start">
<md-button class="md-primary" md-colors="::{background: 'primary-100', color: 'background-900'}" ng-disabled="_agent.id == '000'"
ng-click="restart(_agent)"><i class="fa fa-repeat" aria-hidden="true"></i> Restart</md-button>
</md-content>
<md-content layout="row" layout-align="end start">
<md-content layout="row" layout-align="end start">
<md-button class="md-primary" md-colors="::{background: 'primary-100', color: 'background-900'}" ng-href="{{getDiscoverByAgent(_agent)}}"
target="_blank"><i class="fa fa-external-link" aria-hidden="true"></i> Discover alerts</md-button>

View File

@ -3,22 +3,14 @@
<md-content layout="column" layout-align="space-around center">
<h2>Update</h2>
<md-input-container layout="column" layout-align="space-around center">
<p>1. Select what you want to update:</p>
<md-select ng-model="$parent.updateType">
<md-option value="r">Rules</md-option>
<md-option value="c">Rootcheck</md-option>
<md-option value="b">Both</md-option>
</md-select>
</md-input-container>
<md-input-container layout="column" layout-align="space-around center">
<p>2. Do you want to force it?</p>
<p>1. Do you want to force it?</p>
<md-switch ng-model="$parent.updateForce" aria-label="Force update?">
<span ng-show="$parent.updateForce">Overwrite all the rules (OSSEC manager is going to be restarted)</span>
<span ng-show="!$parent.updateForce">Update the outdated rules (Manager will be restarted only if enabled rules are updated)</span>
</md-switch>
</md-input-container>
<md-button type="submit" ng-click="updateRuleset();" class="md-primary md-raised">Update ruleset</md-button>
<md-button type="submit" ng-click="updateRuleset($event);" class="md-primary md-raised">Update ruleset</md-button>
</md-content>
<md-divider></md-divider>
@ -27,8 +19,9 @@
<h2>Backups</h2>
<md-select ng-model="$parent.selectedBackup" md-on-open="load_backups()" style="min-width: 150px;">
<md-option value="{{backup}}" ng-repeat="backup in backups">{{backup}}</md-option>
<md-option-empty ng-if="backups.length == 0">No backups where found</md-option-empty>
</md-select>
<md-button type="submit" class="md-primary md-raised" ng-click="restoreBackup();">Restore backup</md-button>
<md-button type="submit" class="md-primary md-raised" ng-click="restoreBackup($event);">Restore backup</md-button>
<p style="font-weight: lighter;">* When ruleset is updated, a new backup (the first in the list) will be created.</p>
</md-content>