From da224ecdccce4d32ff641912e2593d24f2fbd4cb 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 | 983 +++++++++--------- 1 file changed, 501 insertions(+), 482 deletions(-) diff --git a/public/controllers/agent/components/register-agent.js b/public/controllers/agent/components/register-agent.js index 278fe1f62b..5b84f753b4 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: [], @@ -294,10 +299,18 @@ export const RegisterAgent = withErrorBoundary( setAgentName(event) { this.setState({ agentName: event.target.value }); - } - - 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) { @@ -386,7 +399,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`; @@ -417,7 +430,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"'; @@ -436,7 +449,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`; @@ -463,7 +476,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`; @@ -494,7 +507,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`; @@ -517,7 +530,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`; @@ -536,7 +549,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`; @@ -590,7 +603,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`; @@ -609,7 +622,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`; @@ -634,7 +647,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`; @@ -647,7 +660,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`; @@ -664,7 +677,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`; @@ -675,7 +688,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`; @@ -865,11 +878,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 = ( <> @@ -916,47 +938,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 ${this.agentNameVariable()}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`; @@ -1328,7 +1337,7 @@ export const RegisterAgent = withErrorBoundary( className={'wz-flex'} /> {this.state.selectedVersion == 'solaris10' || - this.state.selectedVersion == 'solaris11' ? ( + this.state.selectedVersion == 'solaris11' ? ( this.setVersion(version), - ) - : buttonGroup( - 'Choose the version', - versionButtonsRedHat, - this.state.selectedVersion, - version => this.setVersion(version), - ), - }, - ] + ? buttonGroupWithMessage( + 'Choose the version', + versionButtonsRedHat, + this.state.selectedVersion, + version => this.setVersion(version), + ) + : 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: - this.state.selectedVersion == 'centos5' || + { + title: 'Choose the version', + children: + this.state.selectedVersion == 'centos5' || this.state.selectedVersion == 'centos6' - ? buttonGroupWithMessage( - 'Choose the version', - versionButtonsCentos, - this.state.selectedVersion, - version => this.setVersion(version), - ) - : buttonGroup( - 'Choose the version', - versionButtonsCentos, - this.state.selectedVersion, - version => this.setVersion(version), - ), - }, - ] + ? buttonGroupWithMessage( + 'Choose the version', + versionButtonsCentos, + this.state.selectedVersion, + version => this.setVersion(version), + ) + : 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: - this.state.selectedVersion == 'debian7' || + { + title: 'Choose the version', + children: + this.state.selectedVersion == 'debian7' || this.state.selectedVersion == 'debian8' || this.state.selectedVersion == 'debian9' || this.state.selectedVersion == 'debian10' - ? buttonGroupWithMessage( - 'Choose the version', - versionButtonsDebian, - this.state.selectedVersion, - version => this.setVersion(version), - ) - : buttonGroup( - 'Choose the version', - versionButtonsDebian, - this.state.selectedVersion, - version => this.setVersion(version), - ), - }, - ] + ? buttonGroupWithMessage( + 'Choose the version', + versionButtonsDebian, + this.state.selectedVersion, + version => this.setVersion(version), + ) + : buttonGroup( + 'Choose the version', + versionButtonsDebian, + this.state.selectedVersion, + version => this.setVersion(version), + ), + }, + ] : []), ...(this.state.selectedOS == 'ubu' ? [ - { - title: 'Choose the version', - children: - this.state.selectedVersion == 'ubuntu14' - ? buttonGroupWithMessage( - 'Choose the version', - versionButtonsUbuntu, - this.state.selectedVersion, - version => this.setVersion(version), - ) - : buttonGroup( - 'Choose the version', - versionButtonsUbuntu, - this.state.selectedVersion, - version => this.setVersion(version), - ), - }, - ] + { + title: 'Choose the version', + children: + this.state.selectedVersion == 'ubuntu14' + ? buttonGroupWithMessage( + 'Choose the version', + versionButtonsUbuntu, + this.state.selectedVersion, + version => this.setVersion(version), + ) + : 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: - this.state.selectedVersion == 'solaris10' || + { + title: 'Choose the version', + children: + this.state.selectedVersion == 'solaris10' || this.state.selectedVersion == 'solaris11' - ? buttonGroupWithMessage( - 'Choose the version', - versionButtonsSolaris, - this.state.selectedVersion, - version => this.setVersion(version), - ) - : buttonGroup( - 'Choose the version', - versionButtonsSolaris, - this.state.selectedVersion, - version => this.setVersion(version), - ), - }, - ] + ? buttonGroupWithMessage( + 'Choose the version', + versionButtonsSolaris, + this.state.selectedVersion, + version => this.setVersion(version), + ) + : buttonGroup( + 'Choose the version', + versionButtonsSolaris, + this.state.selectedVersion, + version => this.setVersion(version), + ), + }, + ] : []), ...(this.state.selectedOS == 'aix' ? [ - { - title: 'Choose the version', - children: - this.state.selectedVersion == '6.1 TL9' - ? buttonGroupWithMessage( - 'Choose the version', - versionButtonsAix, - this.state.selectedVersion, - version => this.setVersion(version), - ) - : buttonGroup( - 'Choose the version', - versionButtonsAix, - this.state.selectedVersion, - version => this.setVersion(version), - ), - }, - ] + { + title: 'Choose the version', + children: + this.state.selectedVersion == '6.1 TL9' + ? buttonGroupWithMessage( + 'Choose the version', + versionButtonsAix, + this.state.selectedVersion, + version => this.setVersion(version), + ) + : buttonGroup( + 'Choose the version', + versionButtonsAix, + this.state.selectedVersion, + version => this.setVersion(version), + ), + }, + ] : []), ...(this.state.selectedOS == 'hp' ? [ - { - title: 'Choose the version', - children: - this.state.selectedVersion == '11.31' - ? buttonGroupWithMessage( - 'Choose the version', - versionButtonsHPUX, - this.state.selectedVersion, - version => this.setVersion(version), - ) - : buttonGroup( - 'Choose the version', - versionButtonsHPUX, - this.state.selectedVersion, - version => this.setVersion(version), - ), - }, - ] + { + title: 'Choose the version', + children: + this.state.selectedVersion == '11.31' + ? buttonGroupWithMessage( + 'Choose the version', + versionButtonsHPUX, + this.state.selectedVersion, + version => this.setVersion(version), + ) + : buttonGroup( + 'Choose the version', + versionButtonsHPUX, + 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), + ), + }, + ] : []), { title: 'Wazuh server address', @@ -1907,11 +1916,11 @@ export const RegisterAgent = withErrorBoundary( }, ...(!(!this.state.needsPassword || this.state.hidePasswordInput) ? [ - { - title: 'Wazuh password', - children: {passwordInput}, - }, - ] + { + title: 'Wazuh password', + children: {passwordInput}, + }, + ] : []), { title: 'Assign a name and a group to the agent', @@ -1927,6 +1936,12 @@ export const RegisterAgent = withErrorBoundary( 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 89df22f93f60254531778d48709682d55ff7f25f 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 50c751558a..ee340a57ba 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 f776d7eb1e620f89c99f62e9b0baf5f21252fb0a 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 5b84f753b4..f59ea22697 100644 --- a/public/controllers/agent/components/register-agent.js +++ b/public/controllers/agent/components/register-agent.js @@ -298,13 +298,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)];