diff --git a/public/controllers/management/cdblists.js b/public/controllers/management/cdblists.js index 2716a1510..66a0a150b 100644 --- a/public/controllers/management/cdblists.js +++ b/public/controllers/management/cdblists.js @@ -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() }; diff --git a/public/controllers/management/config-ruleset.js b/public/controllers/management/config-ruleset.js index 17a845193..937a4329a 100644 --- a/public/controllers/management/config-ruleset.js +++ b/public/controllers/management/config-ruleset.js @@ -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 = () => { diff --git a/public/controllers/management/edition.js b/public/controllers/management/edition.js index ffe2b47a8..6074d2604 100644 --- a/public/controllers/management/edition.js +++ b/public/controllers/management/edition.js @@ -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 diff --git a/public/controllers/settings/settings.js b/public/controllers/settings/settings.js index 94b21059b..5caca75d9 100644 --- a/public/controllers/settings/settings.js +++ b/public/controllers/settings/settings.js @@ -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) + } } } diff --git a/public/directives/wz-list-manage/wz-list-manage.html b/public/directives/wz-list-manage/wz-list-manage.html index 36ed8730d..bdb8d9920 100644 --- a/public/directives/wz-list-manage/wz-list-manage.html +++ b/public/directives/wz-list-manage/wz-list-manage.html @@ -1,15 +1,20 @@
-
- - -
- + +
+
+ +
@@ -20,7 +25,7 @@ - @@ -28,7 +33,7 @@
Key
{{item[0]}} + ng-model="currentList.editingNewValue"> {{item[1]}} @@ -37,8 +42,8 @@ tooltip="Edit" ng-click="setEditingKey(item[0], item[1])" class="fa fa-fw fa-pencil cursor-pointer"> - + 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 diff --git a/public/directives/wz-xml-file-editor/wz-xml-file-editor.js b/public/directives/wz-xml-file-editor/wz-xml-file-editor.js index 04e8cae35..d1d40691c 100644 --- a/public/directives/wz-xml-file-editor/wz-xml-file-editor.js +++ b/public/directives/wz-xml-file-editor/wz-xml-file-editor.js @@ -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) { diff --git a/public/less/common.less b/public/less/common.less index 21657d273..af1094344 100644 --- a/public/less/common.less +++ b/public/less/common.less @@ -256,6 +256,7 @@ div.uil-ring-css { padding: 0; margin: 0; font-size: 20px; + box-shadow: none!important; } .btn-as-i:hover{ diff --git a/public/less/layout.less b/public/less/layout.less index 694fb4549..92ae82872 100644 --- a/public/less/layout.less +++ b/public/less/layout.less @@ -92,6 +92,10 @@ margin-bottom: 10px; } +.wz-margin-bottom-25 { + margin-bottom: 25px; +} + .wz-margin-bottom-40 { margin-bottom: 40px; } diff --git a/public/services/save-config.js b/public/services/save-config.js index 4f86072c6..492c6db9a 100644 --- a/public/services/save-config.js +++ b/public/services/save-config.js @@ -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); } diff --git a/public/templates/management/configuration/config-edition/config-edition.html b/public/templates/management/configuration/config-edition/config-edition.html index 4dc1b7f27..da391d855 100644 --- a/public/templates/management/configuration/config-edition/config-edition.html +++ b/public/templates/management/configuration/config-edition/config-edition.html @@ -16,16 +16,6 @@
Edit master/worker configuration
- - -
-
- -
-
@@ -49,6 +39,16 @@ XML format error + +
+
+ +
+
-
@@ -88,6 +88,9 @@
+
+

{{currentList.name}}

+
diff --git a/server/controllers/wazuh-api.js b/server/controllers/wazuh-api.js index 10d314525..e47907340 100644 --- a/server/controllers/wazuh-api.js +++ b/server/controllers/wazuh-api.js @@ -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 });