From 32e9be35bbae8500303ed71037b21bc5f8949901 Mon Sep 17 00:00:00 2001 From: JuanGarriuz Date: Thu, 7 Sep 2023 17:06:11 +0200 Subject: [PATCH] Add Miscellaneous to tab into Configuration App (#5830) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add Tab into Configuration App to show Miscellaneous as a tab * Change compareCurrentAppID: wz-configuration to configuration --------- Co-authored-by: Ian Yenien Serrano <63758389+yenienserrano@users.noreply.github.com> Co-authored-by: yenienserrano Co-authored-by: Antonio David GutiƩrrez --- .../public/controllers/settings/settings.js | 81 +++++++++++-------- .../public/templates/settings/settings.html | 11 +++ 2 files changed, 60 insertions(+), 32 deletions(-) diff --git a/plugins/main/public/controllers/settings/settings.js b/plugins/main/public/controllers/settings/settings.js index 7487872dd7..50db4f35a2 100644 --- a/plugins/main/public/controllers/settings/settings.js +++ b/plugins/main/public/controllers/settings/settings.js @@ -26,7 +26,7 @@ import { UI_LOGGER_LEVELS, PLUGIN_APP_NAME } from '../../../common/constants'; import { UI_ERROR_SEVERITIES } from '../../react-services/error-orchestrator/types'; import { getErrorOrchestrator } from '../../react-services/common-services'; import { getAssetURL } from '../../utils/assets'; -import { getHttp } from '../../kibana-services'; +import { getHttp, getWzCurrentAppID } from '../../kibana-services'; export class SettingsController { /** @@ -60,7 +60,9 @@ export class SettingsController { this.tabNames = TabNames; this.indexPatterns = []; this.apiEntries = []; - this.$scope.googleGroupsSVG = getHttp().basePath.prepend(getAssetURL('images/icons/google_groups.svg')); + this.$scope.googleGroupsSVG = getHttp().basePath.prepend( + getAssetURL('images/icons/google_groups.svg'), + ); this.tabs = [ { id: 'api', name: 'Server API' }, { id: 'modules', name: 'Modules' }, @@ -70,6 +72,10 @@ export class SettingsController { { id: 'miscellaneous', name: 'Miscellaneous' }, { id: 'about', name: 'About' }, ]; + this.tabsConfiguration = [ + { id: 'configuration', name: 'Configuration' }, + { id: 'miscellaneous', name: 'Miscellaneous' }, + ]; } /** @@ -81,17 +87,15 @@ export class SettingsController { if (location?.tab) { this.tab = location.tab; const tabActive = this.tabs.find(tab => tab.id === this.tab); - if(this.tab==='about') store.dispatch(updateSelectedSettingsSection('about')); + if (this.tab === 'about') + store.dispatch(updateSelectedSettingsSection('about')); const breadcrumb = [ { text: '' }, - { text: tabActive?.name || 'Server API' } + { text: tabActive?.name || 'Server API' }, ]; store.dispatch(updateGlobalBreadcrumb(breadcrumb)); } else { - const breadcrumb = [ - { text: '' }, - { text: 'Server API' }, - ]; + const breadcrumb = [{ text: '' }, { text: 'Server API' }]; store.dispatch(updateGlobalBreadcrumb(breadcrumb)); } @@ -133,29 +137,29 @@ export class SettingsController { checkManager: entry => this.checkManager(entry), showAddApi: () => this.showAddApi(), getHosts: () => this.getHosts(), - testApi: (entry,force) => ApiCheck.checkApi(entry,force), + testApi: (entry, force) => ApiCheck.checkApi(entry, force), showAddApiWithInitialError: error => this.showAddApiWithInitialError(error), updateClusterInfoInRegistry: (id, clusterInfo) => this.updateClusterInfoInRegistry(id, clusterInfo), showApiIsDown: () => this.showApiIsDown(), - copyToClipBoard: msg => this.copyToClipBoard(msg) + copyToClipBoard: msg => this.copyToClipBoard(msg), }; this.addApiProps = { checkForNewApis: () => this.checkForNewApis(), - closeAddApi: () => this.closeAddApi() + closeAddApi: () => this.closeAddApi(), }; this.apiIsDownProps = { apiEntries: this.apiEntries, setDefault: entry => this.setDefault(entry), - testApi: (entry,force) => ApiCheck.checkApi(entry,force), + testApi: (entry, force) => ApiCheck.checkApi(entry, force), closeApiIsDown: () => this.closeApiIsDown(), getHosts: () => this.getHosts(), updateClusterInfoInRegistry: (id, clusterInfo) => this.updateClusterInfoInRegistry(id, clusterInfo), - copyToClipBoard: msg => this.copyToClipBoard(msg) + copyToClipBoard: msg => this.copyToClipBoard(msg), }; this.settingsTabsProps = { clickAction: tab => { @@ -165,14 +169,14 @@ export class SettingsController { } }, selectedTab: this.tab || 'api', - tabs: this.tabs, - wazuhConfig: this.wazuhConfig + tabs: this.tabsConfiguration, + wazuhConfig: this.wazuhConfig, }; this.settingsLogsProps = { getLogs: async () => { return await this.getAppLogs(); - } + }, }; } @@ -181,7 +185,7 @@ export class SettingsController { * @param {Object} tab */ switchTab(tab) { - if(tab==='about') store.dispatch(updateSelectedSettingsSection('about')); + if (tab === 'about') store.dispatch(updateSelectedSettingsSection('about')); this.tab = tab; this.$location.search('tab', this.tab); } @@ -196,6 +200,15 @@ export class SettingsController { } } + /** + * Compare the string param with currentAppID + * @param {string} appToCompare + * It use into plugins/main/public/templates/settings/settings.html to show tabs into expecified App + */ + compareCurrentAppID(appToCompare) { + return getWzCurrentAppID() === appToCompare; + } + /** * Returns the index of the API in the entries array * @param {Object} api @@ -262,8 +275,8 @@ export class SettingsController { AppState.setCurrentAPI( JSON.stringify({ name: clusterEnabled ? manager : cluster, - id: id - }) + id: id, + }), ); this.$scope.$emit('updateAPI', {}); @@ -303,9 +316,10 @@ export class SettingsController { // Get settings function async getSettings() { try { - try{ - this.indexPatterns = await SavedObject.getListOfWazuhValidIndexPatterns(); - }catch(error){ + try { + this.indexPatterns = + await SavedObject.getListOfWazuhValidIndexPatterns(); + } catch (error) { this.wzMisc.setBlankScr('Sorry but no valid index patterns were found'); this.$location.search('tab', null); this.$location.path('/blank-screen'); @@ -353,7 +367,7 @@ export class SettingsController { } // Every time that the API entries are required in the settings the registry will be checked in order to remove orphan host entries await this.genericReq.request('POST', '/hosts/remove-orphan-entries', { - entries: this.apiEntries + entries: this.apiEntries, }); return; } @@ -366,7 +380,7 @@ export class SettingsController { try { const url = `/hosts/update-hostname/${id}`; await this.genericReq.request('PUT', url, { - cluster_info: clusterInfo + cluster_info: clusterInfo, }); } catch (error) { return Promise.reject(error); @@ -388,7 +402,7 @@ export class SettingsController { port: port, cluster_info: {}, insecure: 'true', - id: id + id: id, }; // Test the connection @@ -461,8 +475,8 @@ export class SettingsController { { date: new Date(), level: 'error', - message: 'Error when loading logs' - } + message: 'Error when loading logs', + }, ]; } } @@ -477,7 +491,7 @@ export class SettingsController { this.appInfo = { 'app-version': response['app-version'], installationDate: formatUIDate(response['installationDate']), - revision: response['revision'] + revision: response['revision'], }; this.load = false; @@ -534,7 +548,7 @@ export class SettingsController { throw { message: 'There were not found any API entry in the wazuh.yml', type: 'warning', - closedEnabled: false + closedEnabled: false, }; const notRecheable = await this.checkApisStatus(); if (notRecheable) { @@ -544,13 +558,13 @@ export class SettingsController { message: 'Wazuh API not recheable, please review your configuration', type: 'danger', - closedEnabled: true + closedEnabled: true, }; } throw { message: `Some of the API entries are not reachable. You can still use the ${PLUGIN_APP_NAME} but please, review your hosts configuration.`, type: 'warning', - closedEnabled: true + closedEnabled: true, }; } } catch (error) { @@ -576,7 +590,10 @@ export class SettingsController { try { const result = await this.genericReq.request('GET', '/hosts/apis', {}); const hosts = result.data || []; - this.apiEntries = this.apiTableProps.apiEntries = this.apiIsDownProps.apiEntries = hosts; + this.apiEntries = + this.apiTableProps.apiEntries = + this.apiIsDownProps.apiEntries = + hosts; if (!hosts.length) { this.apiIsDown = false; this.addingApi = true; diff --git a/plugins/main/public/templates/settings/settings.html b/plugins/main/public/templates/settings/settings.html index cb94bf7cfe..f7cf937233 100644 --- a/plugins/main/public/templates/settings/settings.html +++ b/plugins/main/public/templates/settings/settings.html @@ -7,6 +7,17 @@ > + +
+ +
+