From d61a45c60841a9c153d1aa132ad9817663f9a264 Mon Sep 17 00:00:00 2001 From: JuanGarriuz Date: Wed, 30 Aug 2023 10:55:07 +0200 Subject: [PATCH 1/2] Add Tab into Configuration App to show Miscellaneous as a tab --- .../public/controllers/settings/settings.js | 75 +++++++++++-------- .../public/templates/settings/settings.html | 11 +++ 2 files changed, 54 insertions(+), 32 deletions(-) diff --git a/plugins/main/public/controllers/settings/settings.js b/plugins/main/public/controllers/settings/settings.js index f30a9fb442..e1fbcf8f9f 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'), + ); } /** @@ -74,7 +76,8 @@ export class SettingsController { const location = this.$location.search(); if (location && location.tab) { this.tab = location.tab; - if(this.tab==='about') store.dispatch(updateSelectedSettingsSection('about')); + if (this.tab === 'about') + store.dispatch(updateSelectedSettingsSection('about')); } // Set component props this.setComponentProps(); @@ -114,39 +117,34 @@ 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), }; let tabs = [ - { id: 'api', name: 'API' }, - { id: 'modules', name: 'Modules' }, - { id: 'sample_data', name: 'Sample data' }, { id: 'configuration', name: 'Configuration' }, - { id: 'logs', name: 'Logs' }, - { id: 'miscellaneous', name: 'Miscellaneous'}, - { id: 'about', name: 'About' } + { id: 'miscellaneous', name: 'Miscellaneous' }, ]; this.settingsTabsProps = { clickAction: tab => { @@ -157,13 +155,13 @@ export class SettingsController { }, selectedTab: this.tab || 'api', tabs, - wazuhConfig: this.wazuhConfig + wazuhConfig: this.wazuhConfig, }; this.settingsLogsProps = { getLogs: async () => { return await this.getAppLogs(); - } + }, }; } @@ -172,7 +170,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); } @@ -187,6 +185,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 @@ -253,8 +260,8 @@ export class SettingsController { AppState.setCurrentAPI( JSON.stringify({ name: clusterEnabled ? manager : cluster, - id: id - }) + id: id, + }), ); this.$scope.$emit('updateAPI', {}); @@ -294,9 +301,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'); @@ -344,7 +352,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; } @@ -357,7 +365,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); @@ -379,7 +387,7 @@ export class SettingsController { port: port, cluster_info: {}, insecure: 'true', - id: id + id: id, }; // Test the connection @@ -452,8 +460,8 @@ export class SettingsController { { date: new Date(), level: 'error', - message: 'Error when loading logs' - } + message: 'Error when loading logs', + }, ]; } } @@ -468,7 +476,7 @@ export class SettingsController { this.appInfo = { 'app-version': response['app-version'], installationDate: formatUIDate(response['installationDate']), - revision: response['revision'] + revision: response['revision'], }; this.load = false; @@ -525,7 +533,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) { @@ -535,13 +543,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) { @@ -567,7 +575,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..b0b8fb3684 100644 --- a/plugins/main/public/templates/settings/settings.html +++ b/plugins/main/public/templates/settings/settings.html @@ -7,6 +7,17 @@ > + +
+ +
+
From f0569aa2932ab42a6a82a29ecbdeea27d4fd4e18 Mon Sep 17 00:00:00 2001 From: yenienserrano Date: Thu, 7 Sep 2023 12:06:02 +0200 Subject: [PATCH 2/2] Change compareCurrentAppID: wz-configuration to configuration --- plugins/main/public/templates/settings/settings.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/main/public/templates/settings/settings.html b/plugins/main/public/templates/settings/settings.html index b0b8fb3684..f7cf937233 100644 --- a/plugins/main/public/templates/settings/settings.html +++ b/plugins/main/public/templates/settings/settings.html @@ -9,7 +9,7 @@