diff --git a/public/components/common/welcome/agents-welcome.js b/public/components/common/welcome/agents-welcome.js index 0349028a50..02cb1fcd8c 100644 --- a/public/components/common/welcome/agents-welcome.js +++ b/public/components/common/welcome/agents-welcome.js @@ -30,9 +30,14 @@ import { EuiToolTip, EuiButtonIcon, EuiEmptyPrompt, - EuiPageBody + EuiPageBody, } from '@elastic/eui'; -import { FimEventsTable, ScaScan, MitreTopTactics, RequirementVis } from './components'; +import { + FimEventsTable, + ScaScan, + MitreTopTactics, + RequirementVis, +} from './components'; import { AgentInfo } from './agents-info'; import { WAZUH_MODULES } from '../../../../common/wazuh-modules'; import store from '../../../redux/store'; @@ -58,568 +63,641 @@ import { webDocumentationLink } from '../../../../common/services/web_documentat export const AgentsWelcome = compose( withReduxProvider, - withErrorBoundary)( -class AgentsWelcome extends Component { - _isMount = false; - constructor(props) { - super(props); - - this.offset = 275; - - this.state = { - extensions: this.props.extensions, - lastScans: [], - isLoading: true, - sortField: 'start_scan', - sortDirection: 'desc', - actionAgents: true, // Hide actions agents - selectedRequirement: 'pci', - menuAgent: {}, - maxModules: 6, - widthWindow: window.innerWidth - }; - } - - updateWidth = () => { + withErrorBoundary, +)( + class AgentsWelcome extends Component { + _isMount = false; + constructor(props) { + super(props); + + this.offset = 275; + + this.state = { + extensions: this.props.extensions, + lastScans: [], + isLoading: true, + sortField: 'start_scan', + sortDirection: 'desc', + actionAgents: true, // Hide actions agents + selectedRequirement: 'pci', + menuAgent: {}, + maxModules: 6, + widthWindow: window.innerWidth, + }; + } - let menuSize = (window.innerWidth - this.offset); - let maxModules = 6; - if (menuSize > 1250) { - maxModules = 6; - } else { - if (menuSize > 1100) { - maxModules = 5; + updateWidth = () => { + let menuSize = window.innerWidth - this.offset; + let maxModules = 6; + if (menuSize > 1250) { + maxModules = 6; } else { - if (menuSize > 900) { - maxModules = 4; + if (menuSize > 1100) { + maxModules = 5; } else { - maxModules = 3; - if (menuSize < 750) { - maxModules = null; + if (menuSize > 900) { + maxModules = 4; + } else { + maxModules = 3; + if (menuSize < 750) { + maxModules = null; + } } } } - } - this.setState({ maxModules: maxModules, widthWindow: window.innerWidth }); - }; - - setGlobalBreadcrumb() { - const breadcrumb = [ - { text: '' }, - { - text: 'Agents', - href: "#/agents-preview" - }, - { - text: `${this.props.agent.name}`, - className: 'wz-global-breadcrumb-btn euiBreadcrumb--truncate', - truncate: false, - } - ]; - store.dispatch(updateGlobalBreadcrumb(breadcrumb)); - } - - - async componentDidMount() { - this._isMount = true; - store.dispatch(updateCurrentAgentData(this.props.agent)); - this.updateMenuAgents(); - this.updateWidth(); - this.setGlobalBreadcrumb(); - const tabVisualizations = new TabVisualizations(); - tabVisualizations.removeAll(); - tabVisualizations.setTab('welcome'); - tabVisualizations.assign({ - welcome: 8 - }); - const filterHandler = new FilterHandler(AppState.getCurrentPattern()); - const $injector = getAngularModule().$injector; - this.router = $injector.get('$route'); - window.addEventListener('resize', this.updateWidth); //eslint-disable-line - await VisFactoryHandler.buildAgentsVisualizations( - filterHandler, - 'welcome', - null, - this.props.agent.id - ); - } + this.setState({ maxModules: maxModules, widthWindow: window.innerWidth }); + }; - updateMenuAgents() { - const defaultMenuAgents = { - general: { - id: 'general', - text: 'Security events', - isPin: true, - }, - fim: { - id: 'fim', - text: 'Integrity monitoring', - isPin: true, - }, - sca: { - id: 'sca', - text: 'SCA', - isPin: true, - }, - audit: { - id: 'audit', - text: 'System Auditing', - isPin: true, - }, - vuls: { - id: 'vuls', - text: 'Vulnerabilities', - isPin: true, - }, - mitre: { - id: 'mitre', - text: 'MITRE ATT&CK', - isPin: true, - }, + setGlobalBreadcrumb() { + const breadcrumb = [ + { text: '' }, + { + text: 'Agents', + href: '#/agents-preview', + }, + { + text: `${this.props.agent.name}`, + className: 'wz-global-breadcrumb-btn euiBreadcrumb--truncate', + truncate: false, + }, + ]; + store.dispatch(updateGlobalBreadcrumb(breadcrumb)); } - let menuAgent = JSON.parse(window.localStorage.getItem('menuAgent')); + async componentDidMount() { + this._isMount = true; + store.dispatch(updateCurrentAgentData(this.props.agent)); + this.updateMenuAgents(); + this.updateWidth(); + this.setGlobalBreadcrumb(); + const tabVisualizations = new TabVisualizations(); + tabVisualizations.removeAll(); + tabVisualizations.setTab('welcome'); + tabVisualizations.assign({ + welcome: 8, + }); + const filterHandler = new FilterHandler(AppState.getCurrentPattern()); + const $injector = getAngularModule().$injector; + this.router = $injector.get('$route'); + window.addEventListener('resize', this.updateWidth); //eslint-disable-line + await VisFactoryHandler.buildAgentsVisualizations( + filterHandler, + 'welcome', + null, + this.props.agent.id, + ); + } - // Check if pinned modules to agent menu are enabled in Settings/Modules, if not then modify localstorage removing the disabled modules - if (menuAgent) { - const needUpdateMenuAgent = Object.keys(menuAgent).map(moduleName => menuAgent[moduleName]).reduce((accum, item) => { - if (typeof this.props.extensions[item.id] !== 'undefined' && this.props.extensions[item.id] === false) { - delete menuAgent[item.id]; - accum = true; + updateMenuAgents() { + const defaultMenuAgents = { + general: { + id: 'general', + text: 'Security events', + isPin: true, + }, + fim: { + id: 'fim', + text: 'Integrity monitoring', + isPin: true, + }, + sca: { + id: 'sca', + text: 'SCA', + isPin: true, + }, + audit: { + id: 'audit', + text: 'System Auditing', + isPin: true, + }, + vuls: { + id: 'vuls', + text: 'Vulnerabilities', + isPin: true, + }, + mitre: { + id: 'mitre', + text: 'MITRE ATT&CK', + isPin: true, + }, + }; + + let menuAgent = JSON.parse(window.localStorage.getItem('menuAgent')); + + // Check if pinned modules to agent menu are enabled in Settings/Modules, if not then modify localstorage removing the disabled modules + if (menuAgent) { + const needUpdateMenuAgent = Object.keys(menuAgent) + .map(moduleName => menuAgent[moduleName]) + .reduce((accum, item) => { + if ( + typeof this.props.extensions[item.id] !== 'undefined' && + this.props.extensions[item.id] === false + ) { + delete menuAgent[item.id]; + accum = true; + } + return accum; + }, false); + if (needUpdateMenuAgent) { + // Update the pinned modules matching to enabled modules in Setings/Modules + window.localStorage.setItem('menuAgent', JSON.stringify(menuAgent)); } - return accum; - }, false); - if (needUpdateMenuAgent) { - // Update the pinned modules matching to enabled modules in Setings/Modules - window.localStorage.setItem('menuAgent', JSON.stringify(menuAgent)) + } else { + menuAgent = defaultMenuAgents; + window.localStorage.setItem( + 'menuAgent', + JSON.stringify(defaultMenuAgents), + ); } - } else { - menuAgent = defaultMenuAgents; - window.localStorage.setItem('menuAgent', JSON.stringify(defaultMenuAgents)); + this.setState({ menuAgent: menuAgent }); } - this.setState({ menuAgent: menuAgent }); - } - renderModules() { - const menuAgent = [...Object.keys(this.state.menuAgent).map((item) => { return this.state.menuAgent[item] })]; + renderModules() { + const menuAgent = [ + ...Object.keys(this.state.menuAgent).map(item => { + return this.state.menuAgent[item]; + }), + ]; - return ( - - { - menuAgent.map((menuAgent, i) => { - if (i < this.state.maxModules && hasAgentSupportModule(this.props.agent, menuAgent.id)) { + return ( + + {menuAgent.map((menuAgent, i) => { + if ( + i < this.state.maxModules && + hasAgentSupportModule(this.props.agent, menuAgent.id) + ) { return ( - + { - window.location.href = `#/overview/?tab=${menuAgent.id}&tabView=${menuAgent.text === 'Security configuration assessment' ? 'inventory' : 'panels'}`; + window.location.href = `#/overview/?tab=${ + menuAgent.id + }&tabView=${ + menuAgent.text === 'Security configuration assessment' + ? 'inventory' + : 'panels' + }`; this.router.reload(); - }} style={{ cursor: 'pointer' }}> - {menuAgent.text !== 'Security configuration assessment' ? menuAgent.text : 'SCA'}  + }} + style={{ cursor: 'pointer' }} + > + + {menuAgent.text !== 'Security configuration assessment' + ? menuAgent.text + : 'SCA'} +   + - ) - } - } - )} - - this.setState({ switchModule: !this.state.switchModule })}> - More... - + ); } - isOpen={this.state.switchModule} - closePopover={() => this.setState({ switchModule: false })} - repositionOnScroll={false} - anchorPosition="downCenter"> -
- -
- this.updateMenuAgents()} - closePopover={() => { - this.setState({ switchModule: false }) - } - } - switchTab={(module) => this.props.switchTab(module)}> -
-
-
-
-
-
- ) - } - - renderTitle() { - - return ( - - - - - - -

- {this.state.widthWindow >= 768?( - - {this.props.agent.name} - - ): - ( - - {this.props.agent.name} - - ) - } -

-
-
-
- { - (this.state.maxModules !== null && - this.renderModules()) || - - this.setState({ switchModule: !this.state.switchModule })}> - Modules - + })} + + + this.setState({ switchModule: !this.state.switchModule }) } - isOpen={this.state.switchModule} - closePopover={() => this.setState({ switchModule: false })} - repositionOnScroll={false} - anchorPosition="downCenter"> -
- -
- this.updateMenuAgents()} - closePopover={() => { - this.setState({ switchModule: false }) - } - } - switchTab={(module) => this.props.switchTab(module)}> -
-
-
-
-
+ > + More... + } - + isOpen={this.state.switchModule} + closePopover={() => this.setState({ switchModule: false })} + repositionOnScroll={false} + anchorPosition='downCenter' + > +
+ +
+ this.updateMenuAgents()} + closePopover={() => { + this.setState({ switchModule: false }); + }} + switchTab={module => this.props.switchTab(module)} + > +
+
+
+
+
+
+ ); + } + + renderTitle() { + return ( + + + + {(this.state.maxModules !== null && this.renderModules()) || ( + + + this.setState({ + switchModule: !this.state.switchModule, + }) + } + > + Modules + + } + isOpen={this.state.switchModule} + closePopover={() => this.setState({ switchModule: false })} + repositionOnScroll={false} + anchorPosition='downCenter' + > +
+ +
+ this.updateMenuAgents()} + closePopover={() => { + this.setState({ switchModule: false }); + }} + switchTab={module => this.props.switchTab(module)} + > +
+
+
+
+
+ )} + this.props.switchTab('syscollector')}> + iconType='inspect' + onClick={() => this.props.switchTab('syscollector')} + > Inventory data this.props.switchTab('stats')}> + iconType='stats' + onClick={() => this.props.switchTab('stats')} + > Stats this.props.switchTab('configuration')}> + iconType='gear' + onClick={() => this.props.switchTab('configuration')} + > Configuration
- ); - } + ); + } - buildTabCard(tab, icon) { - return ( - - } - className="homSynopsis__card" - title={WAZUH_MODULES[tab].title} - onClick={() => this.props.switchTab(tab)} - description={WAZUH_MODULES[tab].description} - /> - - ); - } - onClickRestartAgent = () => { - const { agent } = this.props; - ActionAgents.restartAgent(agent.id); - }; + buildTabCard(tab, icon) { + return ( + + } + className='homSynopsis__card' + title={WAZUH_MODULES[tab].title} + onClick={() => this.props.switchTab(tab)} + description={WAZUH_MODULES[tab].description} + /> + + ); + } + onClickRestartAgent = () => { + const { agent } = this.props; + ActionAgents.restartAgent(agent.id); + }; - onClickUpgradeAgent = () => { - const { agent } = this.props; - ActionAgents.upgradeAgent(agent.id); - }; + onClickUpgradeAgent = () => { + const { agent } = this.props; + ActionAgents.upgradeAgent(agent.id); + }; - renderUpgradeButton() { - const { managerVersion } = this.state; - const { agent } = this.props; - let outDated = ActionAgents.compareVersions(managerVersion, agent.version); + renderUpgradeButton() { + const { managerVersion } = this.state; + const { agent } = this.props; + let outDated = ActionAgents.compareVersions( + managerVersion, + agent.version, + ); - if (outDated === true) return; - return ( - - - Upgrade - - - ); - } + if (outDated === true) return; + return ( + + + Upgrade + + + ); + } - onTimeChange = (datePicker) => { - const { start: from, end: to } = datePicker; - this.setState({ datePicker: { from, to } }); - } + onTimeChange = datePicker => { + const { start: from, end: to } = datePicker; + this.setState({ datePicker: { from, to } }); + }; - getOptions() { - return [ - { value: 'pci', text: 'PCI DSS' }, - { value: 'gdpr', text: 'GDPR' }, - { value: 'nist', text: 'NIST 800-53' }, - { value: 'hipaa', text: 'HIPAA' }, - { value: 'gpg13', text: 'GPG13' }, - { value: 'tsc', text: 'TSC' }, - ]; - } + getOptions() { + return [ + { value: 'pci', text: 'PCI DSS' }, + { value: 'gdpr', text: 'GDPR' }, + { value: 'nist', text: 'NIST 800-53' }, + { value: 'hipaa', text: 'HIPAA' }, + { value: 'gpg13', text: 'GPG13' }, + { value: 'tsc', text: 'TSC' }, + ]; + } - setSelectValue(e) { - this.setState({ selectedRequirement: e.target.value }); - } + setSelectValue(e) { + this.setState({ selectedRequirement: e.target.value }); + } - getRequirementVis() { - if (this.state.selectedRequirement === 'pci') { + getRequirementVis() { + if (this.state.selectedRequirement === 'pci') { + return 'Wazuh-App-Agents-Welcome-Top-PCI'; + } + if (this.state.selectedRequirement === 'gdpr') { + return 'Wazuh-App-Agents-Welcome-Top-GDPR'; + } + if (this.state.selectedRequirement === 'hipaa') { + return 'Wazuh-App-Agents-Welcome-Top-HIPAA'; + } + if (this.state.selectedRequirement === 'nist') { + return 'Wazuh-App-Agents-Welcome-Top-NIST-800-53'; + } + if (this.state.selectedRequirement === 'gpg13') { + return 'Wazuh-App-Agents-Welcome-Top-GPG-13'; + } + if (this.state.selectedRequirement === 'tsc') { + return 'Wazuh-App-Agents-Welcome-Top-TSC'; + } return 'Wazuh-App-Agents-Welcome-Top-PCI'; } - if (this.state.selectedRequirement === 'gdpr') { - return 'Wazuh-App-Agents-Welcome-Top-GDPR'; - } - if (this.state.selectedRequirement === 'hipaa') { - return 'Wazuh-App-Agents-Welcome-Top-HIPAA'; - } - if (this.state.selectedRequirement === 'nist') { - return 'Wazuh-App-Agents-Welcome-Top-NIST-800-53'; - } - if (this.state.selectedRequirement === 'gpg13') { - return 'Wazuh-App-Agents-Welcome-Top-GPG-13'; + + renderMitrePanel() { + return ( + + + + + +

+ +

MITRE

+
+

+
+ + + { + window.location.href = `#/overview?tab=mitre`; + this.router.reload(); + }} + aria-label='Open MITRE' + /> + + +
+
+ + + + + + +
+
+ ); } - if (this.state.selectedRequirement === 'tsc') { - return 'Wazuh-App-Agents-Welcome-Top-TSC'; + + renderCompliancePanel() { + return ( + + ); } - return 'Wazuh-App-Agents-Welcome-Top-PCI' - } - renderMitrePanel() { - return ( - - + renderEventCountVisualization() { + return ( + -

-

MITRE

+

+ +

Events count evolution

+

- - - { - window.location.href = `#/overview?tab=mitre`; - this.router.reload(); - } - } - aria-label="Open MITRE" /> - -
+ +
+ + + +
+
+ +
- - - - - -
-
- - ) - } - - renderCompliancePanel() { - return ( - - ) - } - - renderEventCountVisualization() { - return ( - - - - -

-

Events count evolution

-

-
-
- -
- - - -
-
- -
-
-
- ) - } - - renderSCALastScan() { - return ( - - - - ) - } - - render() { - const title = this.renderTitle(); + ); + } - if (this.props.agent.status === API_NAME_AGENT_STATUS.NEVER_CONNECTED) { + renderSCALastScan() { return ( - Agent has never connected.} - body={ - -

- The agent has been registered but has not yet connected to the manager. -

- - Checking connection with the Wazuh server - -
- } - actions={ - - Back - - } - />) + + + + ); } - return ( -
-
-
- {title} -
-
-
- - + render() { + const title = this.renderTitle(); + + if (this.props.agent.status === API_NAME_AGENT_STATUS.NEVER_CONNECTED) { + return ( + Agent has never connected.} + body={ + +

+ The agent has been registered but has not yet connected to the + manager. +

+ + Checking connection with the Wazuh server + +
+ } + actions={ + + Back + + } + /> + ); + } -
-
- - - + return ( +
+
+
{title}
+
+
+ + +
+
+ + + +
-
- - - {/* DatePicker */} - { }} /> - - - {this.state.widthWindow < 1150 && ( - - - - {this.renderMitrePanel()} - - {this.renderCompliancePanel()} - - - - - - - - {/* Events count evolution */} - {this.renderEventCountVisualization()} - - - - - - {this.renderSCALastScan()} - - - - ) || ( + + + + {' '} + {/* DatePicker */} + {}} /> + + + {(this.state.widthWindow < 1150 && ( + + + + {this.renderMitrePanel()} + + {this.renderCompliancePanel()} + + + + + + + + + {' '} + {/* Events count evolution */} + {this.renderEventCountVisualization()} + + + + + {this.renderSCALastScan()} + + + )) || ( - + {this.renderMitrePanel()} {this.renderCompliancePanel()} - + - + - {/* Events count evolution */} + + {' '} + {/* Events count evolution */} {this.renderEventCountVisualization()} - - {this.renderSCALastScan()} - + {this.renderSCALastScan()} )} - - - + + +
-
- ); - } -}) + ); + } + }, +);