Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Redesign add agent] Add register agent command generator #5469

Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
17bf259
Add url package finder class
Machi3mfl May 19, 2023
4086d02
Add command constructor
Machi3mfl May 22, 2023
803aa73
Add install command constructor
Machi3mfl May 22, 2023
87b2362
Add url finder annotations
Machi3mfl May 22, 2023
6b4a7a3
Add exceptions to url package finder
Machi3mfl May 23, 2023
bfe58a6
Rename and updated install command class
Machi3mfl May 23, 2023
5c23b78
Add start command creator with unit tests
Machi3mfl May 23, 2023
913e5c1
Merge branch '4205-redesign-add-agent-page' into feat/5455-add-regist…
Machi3mfl May 23, 2023
384fe7e
Add service with utils to validate os definitions
Machi3mfl May 23, 2023
cc523e8
Update some types and corresponding classes
Machi3mfl May 23, 2023
7ee9814
Add command general constructor
Machi3mfl May 24, 2023
7c39f32
Refactor classes for entire commands creator
Machi3mfl May 30, 2023
3659d06
Merge branch '4205-redesign-add-agent-page' into feat/5455-add-regist…
Machi3mfl Jun 1, 2023
c49e55c
Fix unit tests
Machi3mfl Jun 1, 2023
fa96657
Modify architecture and refactor classes
Machi3mfl Jun 1, 2023
47ba5fe
Add command creator class and unit tests
Machi3mfl Jun 1, 2023
9e5657d
Move some interface to global types file
Machi3mfl Jun 2, 2023
06fb9bd
Rename command creator to generator
Machi3mfl Jun 2, 2023
0d7ffc8
Add commands optional paremeter class
Machi3mfl Jun 2, 2023
d70d736
Add tests in services
Machi3mfl Jun 2, 2023
2232739
Remove unnecesary folder
Machi3mfl Jun 2, 2023
128f85d
Add documentation
Machi3mfl Jun 2, 2023
51e80dc
Remove package-lock.json
Machi3mfl Jun 2, 2023
056ccfe
Add new item to doc
Machi3mfl Jun 2, 2023
1c96d67
Add use register agent commands react hook
Machi3mfl Jun 5, 2023
721061e
Refactor arquitecture and some filenames
Machi3mfl Jun 7, 2023
a4e8980
Add hook with unit tests and README
Machi3mfl Jun 7, 2023
8c3bcf9
Remove unit tests warnings
Machi3mfl Jun 7, 2023
0c57246
Add generics types for OS and optional params
Machi3mfl Jun 7, 2023
6c2d5ee
Remove invalid import
Machi3mfl Jun 7, 2023
ce3b3c8
Updated documentation
Machi3mfl Jun 9, 2023
36572b0
Add dynamic current wazuh version
Machi3mfl Jun 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
148 changes: 148 additions & 0 deletions public/controllers/register-agent/config/os-commands-definitions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
import { IOSDefinition, tOptionalParams } from '../core/register-commands/types';

// Defined OS combinations
export interface ILinuxOSTypes {
name: 'linux';
architecture: 'x64' | 'x86';
extension: 'rpm' | 'deb';
}
export interface IWindowsOSTypes {
name: 'windows';
architecture: 'x86';
extension: 'msi';
}

export interface IMacOSTypes {
name: 'mac';
architecture: '32/64';
extension: 'pkg';
}
Machi3mfl marked this conversation as resolved.
Show resolved Hide resolved

export type tOperatingSystem = ILinuxOSTypes | IMacOSTypes | IWindowsOSTypes;


export type tOptionalParameters = 'server_address' | 'agent_name' | 'agent_group' | 'protocol' | 'wazuh_password';

///////////////////////////////////////////////////////////////////
/// Operating system commands definitions
///////////////////////////////////////////////////////////////////

const linuxDefinition: IOSDefinition<tOperatingSystem, tOptionalParameters> = {
name: 'linux',
options: [
{
extension: 'deb',
architecture: '32/64',
urlPackage: props =>
`https://packages.wazuh.com/4.x/yum/wazuh-agent-${props.wazuhVersion}-1.x86_64.${props.extension}`,
installCommand: props =>
`sudo yum install -y ${props.urlPackage}`,
startCommand: props => `sudo systemctl start wazuh-agent`,
},
{
extension: 'deb',
architecture: 'x64',
urlPackage: props =>
`https://packages.wazuh.com/4.x/apt/pool/main/w/wazuh-agent/ wazuh-agent_${props.wazuhVersion}-1_${props.architecture}.${props.extension}`,
Machi3mfl marked this conversation as resolved.
Show resolved Hide resolved
installCommand: props =>
`curl -so wazuh-agent.deb ${props.urlPackage} && sudo dpkg -i ./wazuh-agent.deb`,
startCommand: props => `sudo systemctl start wazuh-agent`,
},
{
extension: 'rpm',
architecture: '32/64',
urlPackage: props =>
`https://packages.wazuh.com/4.x/yum/wazuh-agent-${props.wazuhVersion}-1.x86_64.${props.extension}`,
installCommand: props =>
`sudo yum install -y ${props.urlPackage}`,
startCommand: props => `sudo systemctl start wazuh-agent`,
},
{
extension: 'deb',
architecture: 'x64',
urlPackage: props =>
`https://packages.wazuh.com/4.x/apt/pool/main/w/wazuh-agent/wazuh-agent_${props.wazuhVersion}-1_amd64.${props.extension}`,
installCommand: props =>
`curl -so wazuh-agent.deb ${props.urlPackage} && sudo dpkg -i ./wazuh-agent.deb`,
startCommand: props => `sudo systemctl start wazuh-agent`,
},
],
};

const windowsDefinition: IOSDefinition<tOperatingSystem, tOptionalParameters> = {
name: 'windows',
options: [
{
extension: 'msi',
architecture: 'x86',
urlPackage: props =>
`https://packages.wazuh.com/4.x/windows/wazuh-agent-${props.wazuhVersion}-1.${props.extension}`,
installCommand: props =>
`Invoke-WebRequest -Uri ${props.urlPackage} -OutFile \${env.tmp}\\wazuh-agent.${props.extension}; msiexec.exe /i \${env.tmp}\\wazuh-agent.${props.extension} /q`,
startCommand: props => `Start-Service -Name wazuh-agent`,
},
],
};

const macDefinition: IOSDefinition<tOperatingSystem, tOptionalParameters> = {
Machi3mfl marked this conversation as resolved.
Show resolved Hide resolved
name: 'mac',
options: [
{
extension: 'pkg',
architecture: '32/64',
urlPackage: props =>
`https://packages.wazuh.com/4.x/macos/wazuh-agent-${props.wazuhVersion}-1.${props.extension}`,
installCommand: props =>
`mac -so wazuh-agent.pkg ${props.urlPackage} && sudo launchctl setenv && sudo installer -pkg ./wazuh-agent.pkg -target /`,
startCommand: props => `sudo /Library/Ossec/bin/wazuh-control start`,
},
],
};

export const osCommandsDefinitions = [
linuxDefinition,
windowsDefinition,
macDefinition,
];

///////////////////////////////////////////////////////////////////
/// Optional parameters definitions
///////////////////////////////////////////////////////////////////

export const optionalParamsDefinitions: tOptionalParams<tOptionalParameters> = {
server_address: {
property: 'WAZUH_MANAGER',
getParamCommand: props => {
const { property, value } = props;
return `${property}=${value}`;
}
},
agent_name: {
property: 'WAZUH_AGENT_NAME',
getParamCommand: props => {
const { property, value } = props;
return `${property}=${value}`;
}
},
protocol: {
property: 'WAZUH_MANAGER_PROTOCOL',
getParamCommand: props => {
const { property, value } = props;
return `${property}=${value}`;
}
},
agent_group: {
property: 'WAZUH_AGENT_GROUP',
getParamCommand: props => {
const { property, value } = props;
return `${property}=${value}`;
}
},
wazuh_password: {
property: 'WAZUH_PASSWORD',
getParamCommand: props => {
const { property, value } = props;
return `${property}=${value}`;
}
}
}
Loading