From 80a16d235e23b756dc0221c731569da652933b55 Mon Sep 17 00:00:00 2001 From: Nicolas Guevara Date: Tue, 20 Dec 2022 13:11:20 -0300 Subject: [PATCH 1/3] Add validation to agent name --- .../agent/components/register-agent.js | 943 +++++++++--------- 1 file changed, 483 insertions(+), 460 deletions(-) diff --git a/public/controllers/agent/components/register-agent.js b/public/controllers/agent/components/register-agent.js index ce0368cfef..4c91f0cb39 100644 --- a/public/controllers/agent/components/register-agent.js +++ b/public/controllers/agent/components/register-agent.js @@ -34,6 +34,9 @@ import { EuiIcon, EuiSwitch, EuiLink, + EuiFormRow, + EuiFormControlLayout, + EuiForm } from '@elastic/eui'; import { WzRequest } from '../../../react-services/wz-request'; import { withErrorBoundary } from '../../../components/common/hocs'; @@ -93,6 +96,8 @@ export const RegisterAgent = withErrorBoundary( wazuhVersion: '', serverAddress: '', agentName: '', + agentNameError: false, + badCharacters: [], wazuhPassword: '', groups: [], selectedGroup: [], @@ -297,6 +302,18 @@ export const RegisterAgent = withErrorBoundary( setAgentName(event) { this.setState({ agentName: event.target.value }); + if (/^[a-z0-9-_.]+$/i.test(event.target.value) || event.target.value.length <= 0) { + this.setState({ agentNameError: false }); + this.setState({ badCharacters: [] }); + } else { + let badCharacters = event.target.value.split('').map(char => + char.replace(/^[a-z0-9-_.]+$/i, '')).join(''); + badCharacters = badCharacters.split('').map(char => + char.replace(/\s/, 'whitespace')); + const characters = [...new Set(badCharacters)]; + this.setState({ badCharacters: characters }); + this.setState({ agentNameError: true }); + } } setGroupName(selectedGroup) { @@ -385,7 +402,7 @@ export const RegisterAgent = withErrorBoundary( resolveRPMPackage() { switch ( - `${this.state.selectedVersion}-${this.state.selectedArchitecture}` + `${this.state.selectedVersion}-${this.state.selectedArchitecture}` ) { case 'redhat5-i386': return `https://packages.wazuh.com/4.x/yum5/i386/wazuh-agent-${this.state.wazuhVersion}${this.addToVersion}.el5.i386.rpm`; @@ -416,7 +433,7 @@ export const RegisterAgent = withErrorBoundary( resolveAlpinePackage() { switch ( - `${this.state.selectedVersion}-${this.state.selectedArchitecture}` + `${this.state.selectedVersion}-${this.state.selectedArchitecture}` ) { case '3.12.12-i386': return `https://packages.wazuh.com/key/alpine-devel%40wazuh.com-633d7457.rsa.pub && \echo "https://packages.wazuh.com/4.x/alpine/v3.12/main"`; @@ -435,7 +452,7 @@ export const RegisterAgent = withErrorBoundary( resolveORACLELINUXPackage() { switch ( - `${this.state.selectedVersion}-${this.state.selectedArchitecture}` + `${this.state.selectedVersion}-${this.state.selectedArchitecture}` ) { case 'oraclelinux5-i386': return `https://packages.wazuh.com/4.x/yum/wazuh-agent-${this.state.wazuhVersion}${this.addToVersion}.i386.rpm`; @@ -462,7 +479,7 @@ export const RegisterAgent = withErrorBoundary( resolveCENTPackage() { switch ( - `${this.state.selectedVersion}-${this.state.selectedArchitecture}` + `${this.state.selectedVersion}-${this.state.selectedArchitecture}` ) { case 'centos5-i386': return `https://packages.wazuh.com/4.x/yum/i386/wazuh-agent-${this.state.wazuhVersion}${this.addToVersion}.el5.i386.rpm`; @@ -493,7 +510,7 @@ export const RegisterAgent = withErrorBoundary( resolveSUSEPackage() { switch ( - `${this.state.selectedVersion}-${this.state.selectedArchitecture}` + `${this.state.selectedVersion}-${this.state.selectedArchitecture}` ) { case 'suse11-i386': return `https://packages.wazuh.com/4.x/yum/wazuh-agent-${this.state.wazuhVersion}${this.addToVersion}.i386.rpm`; @@ -516,7 +533,7 @@ export const RegisterAgent = withErrorBoundary( resolveFEDORAPachage() { switch ( - `${this.state.selectedVersion}-${this.state.selectedArchitecture}` + `${this.state.selectedVersion}-${this.state.selectedArchitecture}` ) { case '22-i386': return `https://packages.wazuh.com/4.x/yum/i386/wazuh-agent-${this.state.wazuhVersion}${this.addToVersion}.el5.i386.rpm`; @@ -535,7 +552,7 @@ export const RegisterAgent = withErrorBoundary( resolveAMAZONLPackage() { switch ( - `${this.state.selectedVersion}-${this.state.selectedArchitecture}` + `${this.state.selectedVersion}-${this.state.selectedArchitecture}` ) { case 'amazonlinux1-i386': return `https://packages.wazuh.com/4.x/yum/wazuh-agent-${this.state.wazuhVersion}${this.addToVersion}.i386.rpm`; @@ -589,7 +606,7 @@ export const RegisterAgent = withErrorBoundary( resolveRASPBIANPackage() { switch ( - `${this.state.selectedVersion}-${this.state.selectedArchitecture}` + `${this.state.selectedVersion}-${this.state.selectedArchitecture}` ) { case 'busterorgreater-i386': return `https://packages.wazuh.com/4.x/apt/pool/main/w/wazuh-agent/wazuh-agent_${this.state.wazuhVersion}${this.addToVersion}_i386.deb`; @@ -608,7 +625,7 @@ export const RegisterAgent = withErrorBoundary( resolveUBUNTUPackage() { switch ( - `${this.state.selectedVersion}-${this.state.selectedArchitecture}` + `${this.state.selectedVersion}-${this.state.selectedArchitecture}` ) { case 'ubuntu14-i386': return `https://packages.wazuh.com/4.x/apt/pool/main/w/wazuh-agent/wazuh-agent_${this.state.wazuhVersion}${this.addToVersion}_i386.deb`; @@ -633,7 +650,7 @@ export const RegisterAgent = withErrorBoundary( resolveOPENSUSEPackage() { switch ( - `${this.state.selectedVersion}-${this.state.selectedArchitecture}` + `${this.state.selectedVersion}-${this.state.selectedArchitecture}` ) { case 'leap15-x86_64': return `https://packages.wazuh.com/4.x/yum/i386/wazuh-agent-${this.state.wazuhVersion}${this.addToVersion}.x86_64.rpm`; @@ -646,7 +663,7 @@ export const RegisterAgent = withErrorBoundary( resolveSOLARISPackage() { switch ( - `${this.state.selectedVersion}-${this.state.selectedArchitecture}` + `${this.state.selectedVersion}-${this.state.selectedArchitecture}` ) { case 'solaris10-i386': return `https://packages.wazuh.com/4.x/solaris/i386/10/wazuh-agent-${this.state.wazuhVersion}-sol10-i386.pkg`; @@ -663,7 +680,7 @@ export const RegisterAgent = withErrorBoundary( resolveAIXPackage() { switch ( - `${this.state.selectedVersion}-${this.state.selectedArchitecture}` + `${this.state.selectedVersion}-${this.state.selectedArchitecture}` ) { case '6.1 TL9-powerpc': return `https://packages.wazuh.com/4.x/yum/i386/wazuh-agent-${this.state.wazuhVersion}${this.addToVersion}.aix.ppc.rpm`; @@ -674,7 +691,7 @@ export const RegisterAgent = withErrorBoundary( resolveHPPackage() { switch ( - `${this.state.selectedVersion}-${this.state.selectedArchitecture}` + `${this.state.selectedVersion}-${this.state.selectedArchitecture}` ) { case '11.31-itanium2': return `https://packages.wazuh.com/4.x/yum/i386/wazuh-agent-${this.state.wazuhVersion}${this.addToVersion}-hpux-11v3-ia64.tar`; @@ -860,11 +877,20 @@ export const RegisterAgent = withErrorBoundary( const missingOSSelection = this.checkMissingOSSelection(); const agentName = ( - this.setAgentName(event)} - /> + + ` "${char}"`)} + ${this.state.badCharacters.length <= 1 ? ('is') : ('are')} + not valid. Allowed characters are A-Z, a-z, ".", "-", "_"`]}> + this.setAgentName(event)} /> + + ); const groupInput = ( <> @@ -911,47 +937,34 @@ export const RegisterAgent = withErrorBoundary( const customTexts = { rpmText: `sudo ${this.optionalDeploymentVariables()}${this.agentNameVariable()}yum install -y ${this.optionalPackages()}`, centText: `sudo ${this.optionalDeploymentVariables()}${this.agentNameVariable()}yum install -y ${this.optionalPackages()}`, - debText: `curl -so wazuh-agent-${ - this.state.wazuhVersion - }.deb ${this.optionalPackages()} && sudo ${this.optionalDeploymentVariables()}${this.agentNameVariable()}dpkg -i ./wazuh-agent-${ - this.state.wazuhVersion - }.deb`, - ubuText: `curl -so wazuh-agent-${ - this.state.wazuhVersion - }.deb ${this.optionalPackages()} && sudo ${this.optionalDeploymentVariables()}${this.agentNameVariable()}dpkg -i ./wazuh-agent-${ - this.state.wazuhVersion - }.deb`, - macosText: `curl -so wazuh-agent-${ - this.state.wazuhVersion - }.pkg https://packages.wazuh.com/4.x/macos/wazuh-agent-${ - this.state.wazuhVersion - }-1.pkg && sudo launchctl setenv ${this.optionalDeploymentVariables()}${this.agentNameVariable()}&& sudo installer -pkg ./wazuh-agent-${ - this.state.wazuhVersion - }.pkg -target /`, - winText: `Invoke-WebRequest -Uri https://packages.wazuh.com/4.x/windows/wazuh-agent-${ - this.state.wazuhVersion - }-1.msi -OutFile \${env:tmp}\\wazuh-agent-${ - this.state.wazuhVersion - }.msi; msiexec.exe /i \${env:tmp}\\wazuh-agent-${ - this.state.wazuhVersion - }.msi /q ${this.optionalDeploymentVariables()}${this.agentNameVariable()}`, + debText: `curl -so wazuh-agent-${this.state.wazuhVersion + }.deb ${this.optionalPackages()} && sudo ${this.optionalDeploymentVariables()}${this.agentNameVariable()}dpkg -i ./wazuh-agent-${this.state.wazuhVersion + }.deb`, + ubuText: `curl -so wazuh-agent-${this.state.wazuhVersion + }.deb ${this.optionalPackages()} && sudo ${this.optionalDeploymentVariables()}${this.agentNameVariable()}dpkg -i ./wazuh-agent-${this.state.wazuhVersion + }.deb`, + macosText: `curl -so wazuh-agent-${this.state.wazuhVersion + }.pkg https://packages.wazuh.com/4.x/macos/wazuh-agent-${this.state.wazuhVersion + }-1.pkg && sudo launchctl setenv ${this.optionalDeploymentVariables()}${this.agentNameVariable()}&& sudo installer -pkg ./wazuh-agent-${this.state.wazuhVersion + }.pkg -target /`, + winText: `Invoke-WebRequest -Uri https://packages.wazuh.com/4.x/windows/wazuh-agent-${this.state.wazuhVersion + }-1.msi -OutFile \${env:tmp}\\wazuh-agent-${this.state.wazuhVersion + }.msi; msiexec.exe /i \${env:tmp}\\wazuh-agent-${this.state.wazuhVersion + }.msi /q ${this.optionalDeploymentVariables()}${this.agentNameVariable()}`, openText: `sudo rpm --import https://packages.wazuh.com/key/GPG-KEY-WAZUH && sudo ${this.optionalDeploymentVariables()}${this.agentNameVariable()} zypper install -y ${this.optionalPackages()}`, - solText: `sudo curl -so ${this.optionalPackages()} && sudo ${this.agentNameVariable()}&& ${ - this.state.selectedVersion == 'solaris11' - ? 'pkg install -g wazuh-agent.p5p wazuh-agent' - : 'pkgadd -d wazuh-agent.pkg' - }`, + solText: `sudo curl -so ${this.optionalPackages()} && sudo ${this.agentNameVariable()}&& ${this.state.selectedVersion == 'solaris11' + ? 'pkg install -g wazuh-agent.p5p wazuh-agent' + : 'pkgadd -d wazuh-agent.pkg' + }`, aixText: `sudo ${this.optionalDeploymentVariables()}${this.agentNameVariable()}rpm -ivh ${this.optionalPackages()}`, hpText: `cd / && sudo curl -so ${this.optionalPackages()} && sudo groupadd wazuh && sudo useradd -G wazuh wazuh && sudo tar -xvf wazuh-agent.tar`, amazonlinuxText: `sudo ${this.optionalDeploymentVariables()}${this.agentNameVariable()}yum install -y ${this.optionalPackages()}`, fedoraText: `sudo ${this.optionalDeploymentVariables()}${this.agentNameVariable()}yum install -y ${this.optionalPackages()}`, oraclelinuxText: `sudo ${this.optionalDeploymentVariables()}${this.agentNameVariable()}yum install -y ${this.optionalPackages()}`, suseText: `sudo ${this.optionalDeploymentVariables()}${this.agentNameVariable()}yum install -y ${this.optionalPackages()}`, - raspbianText: `curl -so wazuh-agent-${ - this.state.wazuhVersion - }.deb ${this.optionalPackages()} && sudo ${this.optionalDeploymentVariables()}${this.agentNameVariable()}dpkg -i ./wazuh-agent-${ - this.state.wazuhVersion - }.deb`, + raspbianText: `curl -so wazuh-agent-${this.state.wazuhVersion + }.deb ${this.optionalPackages()} && sudo ${this.optionalDeploymentVariables()}${this.agentNameVariable()}dpkg -i ./wazuh-agent-${this.state.wazuhVersion + }.deb`, }; const field = `${this.state.selectedOS}Text`; @@ -1055,7 +1068,7 @@ export const RegisterAgent = withErrorBoundary( {windowsAdvice} {this.state.selectedVersion == 'windowsxp' || - this.state.selectedVersion == 'windowsserver2008' ? ( + this.state.selectedVersion == 'windowsserver2008' ? ( <> {this.state.selectedVersion == 'solaris10' || - this.state.selectedVersion == 'solaris11' ? ( + this.state.selectedVersion == 'solaris11' ? ( this.setVersion(version), - ), - }, - ] + { + title: 'Choose the version', + children: buttonGroup( + 'Choose the version', + versionButtonsRedHat, + this.state.selectedVersion, + version => this.setVersion(version), + ), + }, + ] : []), ...(this.state.selectedOS == 'oraclelinux' ? [ - { - title: 'Choose the version', - children: buttonGroup( - 'Choose the version', - versionButtonsOracleLinux, - this.state.selectedVersion, - version => this.setVersion(version), - ), - }, - ] + { + title: 'Choose the version', + children: buttonGroup( + 'Choose the version', + versionButtonsOracleLinux, + this.state.selectedVersion, + version => this.setVersion(version), + ), + }, + ] : []), ...(this.state.selectedOS == 'raspbian' ? [ - { - title: 'Choose the version', - children: buttonGroup( - 'Choose the version', - versionButtonsRaspbian, - this.state.selectedVersion, - version => this.setVersion(version), - ), - }, - ] + { + title: 'Choose the version', + children: buttonGroup( + 'Choose the version', + versionButtonsRaspbian, + this.state.selectedVersion, + version => this.setVersion(version), + ), + }, + ] : []), ...(this.state.selectedOS == 'amazonlinux' ? [ - { - title: 'Choose the version', - children: buttonGroup( - 'Choose the version', - versionButtonAmazonLinux, - this.state.selectedVersion, - version => this.setVersion(version), - ), - }, - ] + { + title: 'Choose the version', + children: buttonGroup( + 'Choose the version', + versionButtonAmazonLinux, + this.state.selectedVersion, + version => this.setVersion(version), + ), + }, + ] : []), ...(this.state.selectedOS == 'cent' ? [ - { - title: 'Choose the version', - children: buttonGroup( - 'Choose the version', - versionButtonsCentos, - this.state.selectedVersion, - version => this.setVersion(version), - ), - }, - ] + { + title: 'Choose the version', + children: buttonGroup( + 'Choose the version', + versionButtonsCentos, + this.state.selectedVersion, + version => this.setVersion(version), + ), + }, + ] : []), ...(this.state.selectedOS == 'fedora' ? [ - { - title: 'Choose the version', - children: buttonGroup( - 'Choose the version', - versionButtonFedora, - this.state.selectedVersion, - version => this.setVersion(version), - ), - }, - ] + { + title: 'Choose the version', + children: buttonGroup( + 'Choose the version', + versionButtonFedora, + this.state.selectedVersion, + version => this.setVersion(version), + ), + }, + ] : []), ...(this.state.selectedOS == 'deb' ? [ - { - title: 'Choose the version', - children: buttonGroup( - 'Choose the version', - versionButtonsDebian, - this.state.selectedVersion, - version => this.setVersion(version), - ), - }, - ] + { + title: 'Choose the version', + children: buttonGroup( + 'Choose the version', + versionButtonsDebian, + this.state.selectedVersion, + version => this.setVersion(version), + ), + }, + ] : []), ...(this.state.selectedOS == 'ubu' ? [ - { - title: 'Choose the version', - children: buttonGroup( - 'Choose the version', - versionButtonsUbuntu, - this.state.selectedVersion, - version => this.setVersion(version), - ), - }, - ] + { + title: 'Choose the version', + children: buttonGroup( + 'Choose the version', + versionButtonsUbuntu, + this.state.selectedVersion, + version => this.setVersion(version), + ), + }, + ] : []), ...(this.state.selectedOS == 'win' ? [ - { - title: 'Choose the version', - children: - this.state.selectedVersion == 'windowsxp' - ? buttonGroupWithMessage( - 'Choose the version', - versionButtonsWindows, - this.state.selectedVersion, - version => this.setVersion(version), - ) - : buttonGroup( - 'Choose the version', - versionButtonsWindows, - this.state.selectedVersion, - version => this.setVersion(version), - ), - }, - ] + { + title: 'Choose the version', + children: + this.state.selectedVersion == 'windowsxp' + ? buttonGroupWithMessage( + 'Choose the version', + versionButtonsWindows, + this.state.selectedVersion, + version => this.setVersion(version), + ) + : buttonGroup( + 'Choose the version', + versionButtonsWindows, + this.state.selectedVersion, + version => this.setVersion(version), + ), + }, + ] : []), ...(this.state.selectedOS == 'macos' ? [ - { - title: 'Choose the version', - children: selectedVersionMac( - 'Choose the version', - versionButtonsMacOS, - this.state.selectedVersion, - version => this.setVersion(version), - ), - }, - ] + { + title: 'Choose the version', + children: selectedVersionMac( + 'Choose the version', + versionButtonsMacOS, + this.state.selectedVersion, + version => this.setVersion(version), + ), + }, + ] : []), ...(this.state.selectedOS == 'suse' ? [ - { - title: 'Choose the version', - children: selectedVersionMac( - 'Choose the version', - versionButtonsSuse, - this.state.selectedVersion, - version => this.setVersion(version), - ), - }, - ] + { + title: 'Choose the version', + children: selectedVersionMac( + 'Choose the version', + versionButtonsSuse, + this.state.selectedVersion, + version => this.setVersion(version), + ), + }, + ] : []), ...(this.state.selectedOS == 'open' ? [ - { - title: 'Choose the version', - children: buttonGroup( - 'Choose the version', - versionButtonsOpenSuse, - this.state.selectedVersion, - version => this.setVersion(version), - ), - }, - ] + { + title: 'Choose the version', + children: buttonGroup( + 'Choose the version', + versionButtonsOpenSuse, + this.state.selectedVersion, + version => this.setVersion(version), + ), + }, + ] : []), ...(this.state.selectedOS == 'sol' ? [ - { - title: 'Choose the version', - children: buttonGroup( - 'Choose the version', - versionButtonsSolaris, - this.state.selectedVersion, - version => this.setVersion(version), - ), - }, - ] + { + title: 'Choose the version', + children: buttonGroup( + 'Choose the version', + versionButtonsSolaris, + this.state.selectedVersion, + version => this.setVersion(version), + ), + }, + ] : []), ...(this.state.selectedOS == 'aix' ? [ - { - title: 'Choose the version', - children: buttonGroup( - 'Choose the version', - versionButtonsAix, - this.state.selectedVersion, - version => this.setVersion(version), - ), - }, - ] + { + title: 'Choose the version', + children: buttonGroup( + 'Choose the version', + versionButtonsAix, + this.state.selectedVersion, + version => this.setVersion(version), + ), + }, + ] : []), ...(this.state.selectedOS == 'hp' ? [ - { - title: 'Choose the version', - children: buttonGroup( - 'Choose the version', - versionButtonsHPUX, - this.state.selectedVersion, - version => this.setVersion(version), - ), - }, - ] + { + title: 'Choose the version', + children: buttonGroup( + 'Choose the version', + versionButtonsHPUX, + this.state.selectedVersion, + version => this.setVersion(version), + ), + }, + ] : []), ...(this.state.selectedOS == 'alpine' ? [ - { - title: 'Choose the version', - children: buttonGroup( - 'Choose the version', - versionButtonAlpine, - this.state.selectedVersion, - version => this.setVersion(version), - ), - }, - ] + { + title: 'Choose the version', + children: buttonGroup( + 'Choose the version', + versionButtonAlpine, + this.state.selectedVersion, + version => this.setVersion(version), + ), + }, + ] : []), ...(this.state.selectedVersion == 'centos5' || - this.state.selectedVersion == 'redhat5' || - this.state.selectedVersion == 'oraclelinux5' || - this.state.selectedVersion == 'suse11' + this.state.selectedVersion == 'redhat5' || + this.state.selectedVersion == 'oraclelinux5' || + this.state.selectedVersion == 'suse11' ? [ - { - title: 'Choose the architecture', - children: buttonGroup( - 'Choose the architecture', - architecturei386Andx86_64, - this.state.selectedArchitecture, - architecture => this.setArchitecture(architecture), - ), - }, - ] + { + title: 'Choose the architecture', + children: buttonGroup( + 'Choose the architecture', + architecturei386Andx86_64, + this.state.selectedArchitecture, + architecture => this.setArchitecture(architecture), + ), + }, + ] : []), ...(this.state.selectedVersion == 'leap15' ? [ - { - title: 'Choose the architecture', - children: buttonGroup( - 'Choose the architecture', - architectureButtonsOpenSuse, - this.state.selectedArchitecture, - architecture => this.setArchitecture(architecture), - ), - }, - ] + { + title: 'Choose the architecture', + children: buttonGroup( + 'Choose the architecture', + architectureButtonsOpenSuse, + this.state.selectedArchitecture, + architecture => this.setArchitecture(architecture), + ), + }, + ] : []), ...(this.state.selectedVersion == 'centos6' || - this.state.selectedVersion == 'oraclelinux6' || - this.state.selectedVersion == 'amazonlinux1' || - this.state.selectedVersion == 'redhat6' || - this.state.selectedVersion == 'amazonlinux2022' || - this.state.selectedVersion == 'debian7' || - this.state.selectedVersion == 'debian8' || - this.state.selectedVersion == 'ubuntu14' || - this.state.selectedVersion == 'ubuntu15' || - this.state.selectedVersion == 'ubuntu16' + this.state.selectedVersion == 'oraclelinux6' || + this.state.selectedVersion == 'amazonlinux1' || + this.state.selectedVersion == 'redhat6' || + this.state.selectedVersion == 'amazonlinux2022' || + this.state.selectedVersion == 'debian7' || + this.state.selectedVersion == 'debian8' || + this.state.selectedVersion == 'ubuntu14' || + this.state.selectedVersion == 'ubuntu15' || + this.state.selectedVersion == 'ubuntu16' ? [ - { - title: 'Choose the architecture', - children: buttonGroup( - 'Choose the architecture', - architectureButtons, - this.state.selectedArchitecture, - architecture => this.setArchitecture(architecture), - ), - }, - ] + { + title: 'Choose the architecture', + children: buttonGroup( + 'Choose the architecture', + architectureButtons, + this.state.selectedArchitecture, + architecture => this.setArchitecture(architecture), + ), + }, + ] : []), ...(this.state.selectedVersion == 'centos7' || - this.state.selectedVersion == 'redhat7' || - this.state.selectedVersion == 'amazonlinux2' || - this.state.selectedVersion == 'suse12' || - this.state.selectedVersion == '22' || - this.state.selectedVersion == 'debian9' || - this.state.selectedVersion == 'debian10' || - this.state.selectedVersion == 'busterorgreater' + this.state.selectedVersion == 'redhat7' || + this.state.selectedVersion == 'amazonlinux2' || + this.state.selectedVersion == 'suse12' || + this.state.selectedVersion == '22' || + this.state.selectedVersion == 'debian9' || + this.state.selectedVersion == 'debian10' || + this.state.selectedVersion == 'busterorgreater' ? [ - { - title: 'Choose the architecture', - children: buttonGroup( - 'Choose the architecture', - architectureButtonsWithPPC64LE, - this.state.selectedArchitecture, - architecture => this.setArchitecture(architecture), - ), - }, - ] + { + title: 'Choose the architecture', + children: buttonGroup( + 'Choose the architecture', + architectureButtonsWithPPC64LE, + this.state.selectedArchitecture, + architecture => this.setArchitecture(architecture), + ), + }, + ] : []), ...(this.state.selectedVersion == 'windowsxp' || - this.state.selectedVersion == 'windows8' + this.state.selectedVersion == 'windows8' ? [ - { - title: 'Choose the architecture', - children: buttonGroup( - 'Choose the architecture', - architectureButtonsi386, - this.state.selectedArchitecture, - architecture => this.setArchitecture(architecture), - ), - }, - ] + { + title: 'Choose the architecture', + children: buttonGroup( + 'Choose the architecture', + architectureButtonsi386, + this.state.selectedArchitecture, + architecture => this.setArchitecture(architecture), + ), + }, + ] : []), ...(this.state.selectedVersion == 'sierra' || - this.state.selectedVersion == 'highSierra' || - this.state.selectedVersion == 'mojave' || - this.state.selectedVersion == 'catalina' || - this.state.selectedVersion == 'bigSur' || - this.state.selectedVersion == 'monterrey' || - this.state.selectedVersion == 'ventura' + this.state.selectedVersion == 'highSierra' || + this.state.selectedVersion == 'mojave' || + this.state.selectedVersion == 'catalina' || + this.state.selectedVersion == 'bigSur' || + this.state.selectedVersion == 'monterrey' || + this.state.selectedVersion == 'ventura' ? [ - { - title: 'Choose the architecture', - children: buttonGroup( - 'Choose the architecture', - architectureButtonsMacos, - this.state.selectedArchitecture, - architecture => this.setArchitecture(architecture), - ), - }, - ] + { + title: 'Choose the architecture', + children: buttonGroup( + 'Choose the architecture', + architectureButtonsMacos, + this.state.selectedArchitecture, + architecture => this.setArchitecture(architecture), + ), + }, + ] : []), ...(this.state.selectedVersion == 'solaris10' || - this.state.selectedVersion == 'solaris11' + this.state.selectedVersion == 'solaris11' ? [ - { - title: 'Choose the architecture', - children: buttonGroup( - 'Choose the architecture', - architectureButtonsSolaris, - this.state.selectedArchitecture, - architecture => this.setArchitecture(architecture), - ), - }, - ] + { + title: 'Choose the architecture', + children: buttonGroup( + 'Choose the architecture', + architectureButtonsSolaris, + this.state.selectedArchitecture, + architecture => this.setArchitecture(architecture), + ), + }, + ] : []), ...(this.state.selectedVersion == '6.1 TL9' ? [ - { - title: 'Choose the architecture', - children: buttonGroup( - 'Choose the architecture', - architectureButtonsAix, - this.state.selectedArchitecture, - architecture => this.setArchitecture(architecture), - ), - }, - ] + { + title: 'Choose the architecture', + children: buttonGroup( + 'Choose the architecture', + architectureButtonsAix, + this.state.selectedArchitecture, + architecture => this.setArchitecture(architecture), + ), + }, + ] : []), ...(this.state.selectedVersion == '11.31' ? [ - { - title: 'Choose the architecture', - children: buttonGroup( - 'Choose the architecture', - architectureButtonsHpUx, - this.state.selectedArchitecture, - architecture => this.setArchitecture(architecture), - ), - }, - ] + { + title: 'Choose the architecture', + children: buttonGroup( + 'Choose the architecture', + architectureButtonsHpUx, + this.state.selectedArchitecture, + architecture => this.setArchitecture(architecture), + ), + }, + ] : []), ...(!( this.state.selectedOS == 'hp' || @@ -1918,27 +1931,27 @@ export const RegisterAgent = withErrorBoundary( this.state.selectedOS == 'alpine' ) ? [ - { - title: 'Wazuh server address', - children: ( - - - - ), - }, - ] + { + title: 'Wazuh server address', + children: ( + + + + ), + }, + ] : []), ...(!(!this.state.needsPassword || this.state.hidePasswordInput) ? [ - { - title: 'Wazuh password', - children: {passwordInput}, - }, - ] + { + title: 'Wazuh password', + children: {passwordInput}, + }, + ] : []), ...(!( this.state.selectedOS == 'hp' || @@ -1946,22 +1959,28 @@ export const RegisterAgent = withErrorBoundary( this.state.selectedOS == 'alpine' ) ? [ - { - title: 'Assign a name and a group to the agent', - children: ( - - {agentName} - {groupInput} - {agentGroup} - - ), - }, - ] + { + title: 'Assign a name and a group to the agent', + children: ( + + {agentName} + {groupInput} + {agentGroup} + + ), + }, + ] : []), { title: 'Install and enroll the agent', children: this.state.gotErrorRegistrationServiceInfo ? ( calloutErrorRegistrationServiceInfo + ) : this.state.agentNameError ? ( + ) : missingOSSelection.length ? ( - ) : ( - + ) : missingOSSelection.length ? ( + + ) : ( + - ), - }, - ] + ? tabWazuhControlMacos + : this.state.selectedVersion == 'solaris10' || + this.state.selectedVersion == 'solaris11' || + this.state.selectedVersion == '6.1 TL9' || + this.state.selectedVersion == '11.31' + ? tabWazuhControl + : tabSysV + } + selectedTab={this.selectedSYS} + onTabClick={onTabClick} + /> + ), + }, + ] : []), ...(!missingOSSelection.length && - this.state.selectedOS !== 'rpm' && - this.state.selectedOS !== 'deb' && - this.state.selectedOS !== 'cent' && - this.state.selectedOS !== 'ubu' && - this.state.selectedOS !== 'win' && - this.state.selectedOS !== 'macos' && - this.state.selectedOS !== 'open' && - this.state.selectedOS !== 'sol' && - this.state.selectedOS !== 'aix' && - this.state.selectedOS !== 'hp' && - this.state.selectedOS !== 'amazonlinux' && - this.state.selectedOS !== 'fedora' && - this.state.selectedOS !== 'oraclelinux' && - this.state.selectedOS !== 'suse' && - this.state.selectedOS !== 'raspbian' && - restartAgentCommand + this.state.selectedOS !== 'rpm' && + this.state.selectedOS !== 'deb' && + this.state.selectedOS !== 'cent' && + this.state.selectedOS !== 'ubu' && + this.state.selectedOS !== 'win' && + this.state.selectedOS !== 'macos' && + this.state.selectedOS !== 'open' && + this.state.selectedOS !== 'sol' && + this.state.selectedOS !== 'aix' && + this.state.selectedOS !== 'hp' && + this.state.selectedOS !== 'amazonlinux' && + this.state.selectedOS !== 'fedora' && + this.state.selectedOS !== 'oraclelinux' && + this.state.selectedOS !== 'suse' && + this.state.selectedOS !== 'raspbian' && + restartAgentCommand ? [ - { - title: 'Start the agent', - children: this.state.gotErrorRegistrationServiceInfo ? ( - calloutErrorRegistrationServiceInfo - ) : ( - - -
- - {restartAgentCommand} - - - {copy => ( -
-

- Copy command -

-
- )} -
-
-
-
- ), - }, - ] + { + title: 'Start the agent', + children: this.state.gotErrorRegistrationServiceInfo ? ( + calloutErrorRegistrationServiceInfo + ) : ( + + +
+ + {restartAgentCommand} + + + {copy => ( +
+

+ Copy command +

+
+ )} +
+
+
+
+ ), + }, + ] : []), ]; From 0a341f16a9ed5490367007632cfc5a5ab2fe6d9b Mon Sep 17 00:00:00 2001 From: Nicolas Guevara Date: Tue, 20 Dec 2022 13:17:31 -0300 Subject: [PATCH 2/3] Update changelog --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e5c51e52bd..72240895b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,10 +16,11 @@ All notable changes to the Wazuh app project will be documented in this file. - Added a new plugin setting to enable or disable the customization [#4507](https://github.com/wazuh/wazuh-kibana-app/pull/4507) - Added the ability to upload an image for the `customization.logo.*` settings in `Settings/Configuration` [#4504](https://github.com/wazuh/wazuh-kibana-app/pull/4504) - Added macOS version to wizard deploy agent [#4867](https://github.com/wazuh/wazuh-kibana-app/pull/4867) -- Added powerPC architecture in redhat7, in the section 'Deploy new agent'. [4833](https://github.com/wazuh/wazuh-kibana-app/pull/4833) +- Added powerPC architecture in redhat7, in the section 'Deploy new agent'. [#4833](https://github.com/wazuh/wazuh-kibana-app/pull/4833) - Added a centralized service to handle the requests [#4831](https://github.com/wazuh/wazuh-kibana-app/pull/4831) - Added data-test-subj create policy [#4873](https://github.com/wazuh/wazuh-kibana-app/pull/4873) - Added file saving conditions in File Editor [#4970](https://github.com/wazuh/wazuh-kibana-app/pull/4970) +- Added character validation to avoid invalid agent names in the section 'Deploy new agent'. [#5021](https://github.com/wazuh/wazuh-kibana-app/pull/5021) ### Changed From c81860348ee9a018c84a70d14500363fc3b9da04 Mon Sep 17 00:00:00 2001 From: Nicolas Guevara Date: Wed, 21 Dec 2022 07:55:39 -0300 Subject: [PATCH 3/3] Add regex to constant --- public/controllers/agent/components/register-agent.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/public/controllers/agent/components/register-agent.js b/public/controllers/agent/components/register-agent.js index 4c91f0cb39..73324ecf97 100644 --- a/public/controllers/agent/components/register-agent.js +++ b/public/controllers/agent/components/register-agent.js @@ -301,13 +301,14 @@ export const RegisterAgent = withErrorBoundary( } setAgentName(event) { + const validation = /^[a-z0-9-_.]+$/i; this.setState({ agentName: event.target.value }); - if (/^[a-z0-9-_.]+$/i.test(event.target.value) || event.target.value.length <= 0) { + if (validation.test(event.target.value) || event.target.value.length <= 0) { this.setState({ agentNameError: false }); this.setState({ badCharacters: [] }); } else { let badCharacters = event.target.value.split('').map(char => - char.replace(/^[a-z0-9-_.]+$/i, '')).join(''); + char.replace(validation, '')).join(''); badCharacters = badCharacters.split('').map(char => char.replace(/\s/, 'whitespace')); const characters = [...new Set(badCharacters)];