Merge branch '3.9-6.6' into issue-1164

This commit is contained in:
Jesús Ángel 2019-02-11 09:25:00 +01:00
commit 9f2c762fef
13 changed files with 104 additions and 77 deletions

View File

@ -100,7 +100,6 @@ export class CdbListsController {
}
search(term) {
console.log('TERM:' + term)
if (term && term.startsWith('group:') && term.split('group:')[1].trim()) {
this.custom_search = '';
const filter = { name: 'group', value: term.split('group:')[1].trim() };

View File

@ -144,7 +144,7 @@ export class ConfigurationRulesetController {
this.$scope.addNewList = () => {
this.$scope.currentList = {
file: '',
name: '',
path: 'etc/lists/',
list: [],
new: true
@ -175,9 +175,12 @@ export class ConfigurationRulesetController {
}
if (rulesettab === 'cdblists') {
this.$scope.searchPlaceholder = 'Filter CDB lists...';
this.$scope.currentList = false;
this.$scope.search();
}
if (!this.$scope.$$phase) this.$scope.$digest();
};
this.$scope.switchRulesetTab('rules');
this.$scope.cancelEditList = () => {

View File

@ -51,17 +51,16 @@ export class EditionController {
if (this.$scope.clusterStatus.data.data.enabled === 'yes') {
data = await this.apiReq.request(
'GET',
`/cluster/${this.$scope.selectedNode}/configuration`,
{}
`/cluster/${this.$scope.selectedNode}/files`,
{ path: 'etc/ossec.conf'}
);
const json = ((data || {}).data || {}).data || false;
xml = this.configurationHandler.json2xml(json);
} else {
data = await this.apiReq.request('GET', `/manager/files`, {
path: 'etc/ossec.conf'
});
xml = ((data || {}).data || {}).data || false;
}
xml = ((data || {}).data || {}).data || false;
if (!xml) {
throw new Error('Could not fetch configuration file');
}
@ -112,6 +111,10 @@ export class EditionController {
return this.$scope.editConf();
};
this.$scope.changeNode = () => {
this.$scope.editConf();
};
this.$scope.closeEditingFile = () => {};
//listeners

View File

@ -195,7 +195,7 @@ export class SettingsController {
this.errorHandler.info(
`API ${
this.apiEntries[index]._source.cluster_info.manager
this.apiEntries[index]._source.cluster_info.manager
} set as default`,
'Settings'
);
@ -558,6 +558,9 @@ export class SettingsController {
return;
} catch (error) {
if (!this.wzMisc.getApiIsDown()) this.printError(error);
else {
this.errorHandler.handle(error)
}
}
}

View File

@ -1,15 +1,20 @@
<div layout="column" layout-align="start">
<div layout="row" ng-show="currentList.name" class="wz-margin-top-8 md-padding-h">
<input placeholder="Filter entries..." ng-model="searchTerm" ng-change="filterTable()" type="text" class="kuiLocalSearchInput ng-empty ng-pristine ng-scope ng-touched ng-valid">
<button class="kuiLocalSearchButton height-40"><span class="fa fa-search" aria-hidden="true"></span> </button>
</div>
<div layout="row" class="wz-margin-top-8 md-padding-h">
<input ng-show="currentList.new && !currentList.name" placeholder="Enter list file name" ng-model="currentList.newName" type="text"
class="height-40 kuiLocalSearchInput ng-empty ng-pristine ng-scope ng-touched ng-valid" aria-invalid="false">
<button ng-disabled='items.length === 0 || (currentList.new && !currentList.newName)' ng-click='saveList()'
class='btn btn-primary pull-right'>
<span><i aria-hidden='true' class='fa fa-fw fa-save'></i>Save list</span>
</button>
<input ng-show="currentList.new && !currentList.name" placeholder="Enter list file name" ng-model="currentList.newName"
type="text" class="kuiLocalSearchInput ng-empty ng-pristine ng-scope ng-touched ng-valid wz-margin-left-8"
aria-invalid="false">
</div>
<div layout="row" class="wz-padding-left-8 wz-padding-right-8" layout-align="start stretch">
<md-card flex class="wz-md-card">
<md-card-content>
<div layout="row">
<input placeholder="Filter entries..." ng-model="searchTerm" ng-change="filterTable()" type="text"
class="kuiLocalSearchInput ng-empty ng-pristine ng-scope ng-touched ng-valid height-40">
</div>
<table class="table table-striped table-condensed table-layout-fixed table-hover table-vertical-align-middle">
<thead class="wz-text-bold">
<th class="wz-text-left">Key</th>
@ -20,7 +25,7 @@
<tr ng-if="adminMode">
<td><input placeholder="Key" type="text" class="wz-input-text" ng-model="newKey"></input></td>
<td><input placeholder="Value" type="text" class="wz-input-text" ng-model="newValue"></input></td>
<td><button class="btn btn-primary btn-as-i" ng-disabled="!newKey || !newValue" ng-click="addEntry(newKey, newValue);newKey = ''; newValue = ''"
<td><button class="btn btn-primary btn-as-i" ng-disabled="!newKey" ng-click="addEntry(newKey, newValue);newKey = ''; newValue = ''"
tooltip="Add new entry" tooltip-placement="right">
<i class="fa fa-fw fa-plus" style="width:15px"></i></button></td>
</tr>
@ -28,7 +33,7 @@
<td>{{item[0]}}</td>
<td>
<input ng-show="editingKey === item[0]" ng-disabled="loadingChange" type="text" class="wz-input-text"
ng-model="editingNewValue"></input>
ng-model="currentList.editingNewValue"></input>
<span ng-show="!editingKey || editingKey !== item[0]">{{item[1]}}</span>
</td>
<td class="action-btn-td">
@ -37,8 +42,8 @@
tooltip="Edit" ng-click="setEditingKey(item[0], item[1])" class="fa fa-fw fa-pencil cursor-pointer"></span>
<span ng-show="editingKey === item[0] && !loadingChange" tooltip="Cancel" class="fa fa-fw fa-times cursor-pointer"
ng-click="cancelEditingKey()"></span>
<span ng-show="editingKey === item[0] && editingNewValue !== '' && !loadingChange"
tooltip="Apply" class="fa fa-fw fa-success cursor-pointer" ng-click="editKey(item[0], editingNewValue)"></span>
<span ng-show="editingKey === item[0] && currentList.editingNewValue !== '' && !loadingChange"
tooltip="Apply" class="fa fa-fw fa-success cursor-pointer" ng-click="editKey(item[0])"></span>
<span ng-show="editingKey === item[0] && loadingChange"><i class="fa fa-fw fa-spin fa-spinner"></i></span>
<i ng-if="(!removingEntry || removingEntry !== item[0]) && editingKey !== item[0]"
ng-click="showConfirmRemoveEntry($event, item[0]); $event.stopPropagation()"

View File

@ -14,11 +14,10 @@ import template from './wz-list-manage.html';
import { uiModules } from 'ui/modules';
import * as pagination from '../wz-table/lib/pagination';
import { checkGap } from '../wz-table/lib/check-gap';
import { stringToObj } from '../../utils/cdblist-to-object';
const app = uiModules.get('app/wazuh', []);
app.directive('wzListManage', function() {
app.directive('wzListManage', function () {
return {
restrict: 'E',
scope: {
@ -40,7 +39,7 @@ app.directive('wzListManage', function() {
$scope.prevPage = () => pagination.prevPage($scope);
$scope.nextPage = async currentPage =>
pagination.nextPage(currentPage, $scope, errorHandler, null);
$scope.setPage = function() {
$scope.setPage = function () {
$scope.currentPage = this.n;
$scope.nextPage(this.n);
};
@ -50,7 +49,7 @@ app.directive('wzListManage', function() {
*/
$scope.filterTable = data => {
const result = Object.keys(data || $scope.currentList.list).map(
function(key) {
function (key) {
return [key, $scope.currentList.list[key]];
}
);
@ -81,22 +80,6 @@ app.directive('wzListManage', function() {
$scope.sortReverse = false;
$scope.searchTerm = '';
$scope.$watch('currentList.list', () => {
if ($scope.currentList.list) fetch();
});
const refresh = () => {
rulesetHandler
.getCdbList(`${$scope.currentList.path}/${$scope.currentList.name}`)
.then(data => {
$scope.currentList.list = stringToObj(data.data.data);
fetch();
$scope.$emit('setCurrentList', { currentList: $scope.currentList });
$scope.viewingDetail = true;
if (!$scope.$$phase) $scope.$digest();
});
};
$scope.$on('changeCdbList', (ev, params) => {
if (params.currentList) {
$scope.currentList = params.currentList;
@ -104,12 +87,15 @@ app.directive('wzListManage', function() {
}
});
const saveList = async () => {
$scope.saveList = async () => {
let addingNew = false;
try {
if ($scope.currentList.new && !$scope.currentList.newName) {
$scope.currentList.list = [];
throw new Error('New list name is needed');
} else {
} else if ($scope.currentList.new && $scope.currentList.newName) {
addingNew = true;
$scope.currentList.new = false;
$scope.currentList.name = $scope.currentList.newName;
}
let raw = '';
@ -125,7 +111,11 @@ app.directive('wzListManage', function() {
$scope.loadingChange = false;
if (!$scope.$$phase) $scope.$digest();
} catch (err) {
refresh();
if (addingNew) {
$scope.currentList.name = false;
$scope.currentList.new = true;
$scope.$applyAsync();
}
errorHandler.handle(err, 'Error updating list');
$scope.loadingChange = false;
}
@ -133,8 +123,8 @@ app.directive('wzListManage', function() {
$scope.addEntry = (key, value) => {
if (!$scope.currentList.list[key]) {
$scope.currentList.list[key] = value;
saveList();
$scope.currentList.list[key] = value ? value : '';
fetch();
} else {
errorHandler.handle('Entry already exists', '');
}
@ -146,7 +136,7 @@ app.directive('wzListManage', function() {
*/
$scope.setEditingKey = (key, value) => {
$scope.editingKey = key;
$scope.editingNewValue = value;
$scope.currentList.editingNewValue = value;
};
/**
* Cancel edition of an entry
@ -160,11 +150,12 @@ app.directive('wzListManage', function() {
$scope.removingEntry = key;
};
$scope.editKey = (key, newValue) => {
$scope.editKey = (key) => {
$scope.loadingChange = true;
$scope.currentList.list[key] = newValue;
$scope.currentList.list[key] = $scope.currentList.editingNewValue;
$scope.currentList.editingNewValue = '';
$scope.cancelEditingKey();
saveList();
fetch();
};
$scope.cancelRemoveEntry = () => {
@ -174,7 +165,7 @@ app.directive('wzListManage', function() {
$scope.confirmRemoveEntry = key => {
delete $scope.currentList.list[key];
$scope.removingEntry = false;
saveList();
fetch();
};
},
template

View File

@ -185,7 +185,7 @@ app.directive('wzXmlFileEditor', function() {
} else if (params.node) {
await saveConfig.saveNodeConfiguration(params.node, xml);
errorHandler.info(
'Success. Node configuration has been updated',
`Success. Node (${params.node}) configuration has been updated`,
''
);
} else if (params.manager) {

View File

@ -256,6 +256,7 @@ div.uil-ring-css {
padding: 0;
margin: 0;
font-size: 20px;
box-shadow: none!important;
}
.btn-as-i:hover{

View File

@ -92,6 +92,10 @@
margin-bottom: 10px;
}
.wz-margin-bottom-25 {
margin-bottom: 25px;
}
.wz-margin-bottom-40 {
margin-bottom: 40px;
}

View File

@ -38,7 +38,12 @@ export class SaveConfig {
*/
async saveNodeConfiguration(node, content) {
try {
//
const result = await this.apiReq.request(
'POST',
`/cluster/${node}/files?path=etc/ossec.conf`,
{ content, origin: 'xmleditor' }
);
return result;
} catch (error) {
return Promise.reject(error);
}

View File

@ -16,16 +16,6 @@
<div layout="row">
<span class="md-subheader">Edit master/worker configuration</span>
</div>
<!-- List of nodes if cluster is enabled -->
<div ng-show="selectedNode && clusterStatus.data.data.enabled === 'yes'" layout="row" layout-padding style="position: absolute;right: calc(0% + 260px);">
<div layout="column" layout-align="center" class="height-40 wz-select-input">
<select class="kuiSelect wz-border-none cursor-pointer max-height-35" id="categoryBox" ng-model="selectedNode"
ng-change="changeNode(selectedNode)" aria-label="Select node">
<option ng-repeat="node in nodes" value="{{node.name}}">{{node.name}} ({{node.type}})</option>
</select>
</div>
</div>
</div>
<!-- Headline (manager) -->
@ -49,6 +39,16 @@
<span ng-show='xmlHasErrors' class='btn-danger'><i aria-hidden='true' class='fa fa-fw fa-exclamation-triangle'></i>
XML format error</span>
</button>
<!-- List of nodes if cluster is enabled -->
<div ng-show="selectedNode && clusterStatus.data.data.enabled === 'yes'" layout="row" class="wz-margin-left-8"
layout-padding style="padding: 0;height: 32px;">
<div layout="column" layout-align="center" class="height-35 wz-select-input">
<select class="kuiSelect wz-border-none cursor-pointer max-height-35" id="categoryBox"
ng-model="selectedNode" ng-change="changeNode()" aria-label="Select node">
<option ng-repeat="node in nodes" value="{{node.name}}">{{node.name}} ({{node.type}})</option>
</select>
</div>
</div>
</div>
<div class="md-padding md-padding-top-10" style="height: calc(100vh - 280px);" ng-if="fetchedXML">
<wz-xml-file-editor file-name='ossec.conf' data="fetchedXML" target-name="selectedNode" valid-fn='xmlIsValid(valid)'

View File

@ -9,7 +9,7 @@
<span ng-if='adminMode && !editingFile && selectedRulesetTab === "decoders"' class="font-size-18 wz-text-link"
ng-click="addNewFile('decoders')" tooltip="Add new decoders file" tooltip-placement="right">
<i class="fa fa-fw fa-plus-circle"></i></span>
<span ng-if='adminMode && !editingFile && selectedRulesetTab === "cdblists"' class="font-size-18 wz-text-link"
<span ng-if='adminMode && !currentList && selectedRulesetTab === "cdblists"' class="font-size-18 wz-text-link"
ng-click="addNewList()" tooltip="Add new list file" tooltip-placement="right">
<i class="fa fa-fw fa-plus-circle"></i></span>
</div>
@ -88,6 +88,9 @@
</div>
</div>
<div class="md-padding" ng-show="viewingDetail">
<div class="wz-margin-bottom-25">
<h1 class="font-size-18">{{currentList.name}}</h1>
</div>
<div flex layout="column">
<wz-list-manage style="margin: -16px;" ng-if="currentList" list="currentList"></wz-list-manage>
</div>

View File

@ -153,7 +153,13 @@ export class WazuhApiCtrl {
throw new Error(`${api.url}:${api.port}/version is unreachable`);
}
} catch (error) {
if (error.code === 'ECONNREFUSED') {
if (error.code === 'EPROTO') {
log('POST /api/check-stored-api', 'Wrong protocol being used to connect to the Wazuh API');
return {
statusCode: 200,
data: { password: '****', apiIsDown: true }
};
} else if (error.code === 'ECONNREFUSED') {
log('POST /api/check-stored-api', error.message || error);
return {
statusCode: 200,
@ -192,7 +198,7 @@ export class WazuhApiCtrl {
req.idChanged = api._id;
return this.checkStoredAPI(req, reply);
}
} catch (error) {} // eslint-disable-line
} catch (error) { } // eslint-disable-line
}
} catch (error) {
log('POST /api/check-stored-api', error.message || error);
@ -335,6 +341,10 @@ export class WazuhApiCtrl {
throw new Error(tmpMsg);
} catch (error) {
if (error.code === 'EPROTO') {
log('POST /api/check-api', 'Wrong protocol being used to connect to the Wazuh API');
return ErrorResponse('Wrong protocol being used to connect to the Wazuh API', 3005, 500, reply);
}
log('POST /api/check-api', error.message || error);
return ErrorResponse(error.message || error, 3005, 500, reply);
}
@ -589,7 +599,7 @@ export class WazuhApiCtrl {
}
throw ((response || {}).body || {}).error &&
((response || {}).body || {}).message
((response || {}).body || {}).message
? { message: response.body.message, code: response.body.error }
: new Error('Unexpected error fetching data from the Wazuh API');
} catch (error) {
@ -648,7 +658,7 @@ export class WazuhApiCtrl {
}
throw ((response || {}).body || {}).error &&
((response || {}).body || {}).message
((response || {}).body || {}).message
? { message: response.body.message, code: response.body.error }
: new Error('Unexpected error fetching data from the Wazuh API');
} catch (error) {
@ -797,18 +807,18 @@ export class WazuhApiCtrl {
if ((((output || {}).body || {}).data || {}).totalItems) {
const fields = req.payload.path.includes('/agents')
? [
'id',
'status',
'name',
'ip',
'group',
'manager',
'node_name',
'dateAdd',
'version',
'lastKeepAlive',
'os'
]
'id',
'status',
'name',
'ip',
'group',
'manager',
'node_name',
'dateAdd',
'version',
'lastKeepAlive',
'os'
]
: Object.keys(output.body.data.items[0]);
const json2csvParser = new Parser({ fields });