Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ <h4 class="card-title mb-0 text-primary">

<ng-template [ngIf]="step.content.id === 'stepContent2'">
<app-agent-action-command [agent] = "getDataType()"
[platforms]="platforms"
[protocols]="getProtocols()">
[platforms]="platforms">
</app-agent-action-command>
</ng-template>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ export class GuideSyslogComponent implements OnInit {
}

ngOnInit() {}
getImage(): SyslogModuleImages {
return this.moduleImages.filter(value => value.module === this.moduleEnum)[0];
}

getPorts(): SyslogModulePorts[] {
return this.syslogPorts.filter(value => value.module === this.moduleEnum);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,16 @@ import {UtmModulesEnum} from '../../../shared/enum/utm-module.enum';
class="flex-item">
</ng-select>
</div>
<ng-container *ngIf="(selectedProtocol && selectedPlatform && selectedAction || (hideActions && hideProtocols && selectedPlatform))">
<div *ngIf="this.selectedProtocol && this.selectedProtocol.name === 'TCP/TLS' && selectedAction"
class="alert alert-info alert-styled-right mt-2">
After the TLS certificates have been successfully loaded into the system,
it is not necessary to repeat the certificate loading process when enabling
additional integrations that use TLS. The system will automatically apply the
previously configured certificates to ensure secure communication.
</div>
<ng-container *ngIf="selectedProtocol && selectedPlatform && selectedAction">
<span class="font-weight-semibold mb-2">{{selectedPlatform.shell}}</span>
<app-utm-code-view class="" [code]=command></app-utm-code-view>
<app-utm-code-view *ngFor="let command of commands" class="" [code]=command></app-utm-code-view>
</ng-container>
`,
styles: [`
Expand All @@ -59,7 +66,8 @@ export class AgentActionCommandComponent implements OnInit{
@Input() hideProtocols = false;
@Input() protocols = [
{id: 1, name: 'TCP'},
{id: 2, name: 'UDP'}
{id: 2, name: 'TCP/TLS'},
{id: 3, name: 'UDP'}
];

actions = [
Expand All @@ -75,16 +83,27 @@ export class AgentActionCommandComponent implements OnInit{
constructor(private modalService: ModalService) {
}

ngOnInit(): void {
console.log(this.selectedPlatform);
}
ngOnInit(): void {}

get commands() {

const protocol = this.selectedProtocol && this.selectedProtocol.name === 'TCP/TLS' ? 'tcp' : this.selectedProtocol.name.toLowerCase();

get command() {
return replaceCommandTokens(this.selectedPlatform.command, {
PORT: this.selectedProtocol && this.selectedProtocol.name.toLowerCase() || '',
AGENT_NAME: this.agent,
ACTION: this.selectedAction && this.selectedAction.action || ''
const command = replaceCommandTokens(this.selectedPlatform.command, {
ACTION: this.selectedAction && this.selectedAction.action || '',
AGENT_NAME: this.agent || '',
PROTOCOL: protocol,
TLS: this.selectedProtocol && this.selectedProtocol.name === 'TCP/TLS' &&
this.selectedAction.name === 'ENABLE' ? `--tls` : ''
});

if (this.selectedProtocol && this.selectedProtocol.name === 'TCP/TLS' &&
this.selectedAction.name === 'ENABLE') {
const extras = this.selectedPlatform.extraCommands ? this.selectedPlatform.extraCommands : [];
return [...extras, command];
}

return [command];
}

get selectedPlatform() {
Expand Down
154 changes: 91 additions & 63 deletions frontend/src/app/app-module/guides/shared/constant.ts
Original file line number Diff line number Diff line change
@@ -1,81 +1,109 @@
const WINDOWS_SHELL =
'Run the following PowerShell script as “ADMINISTRATOR” on a server with the UTMStack agent installed.';

const LINUX_SHELL =
'Run the following Bash script as “ADMINISTRATOR” on a server with the UTMStack agent installed.';

export interface Platform {
id: number;
name: string;
command: string;
shell: string;
path: string;
restart: string;
path?: string;
restart?: string;
extraCommands?: string[];
}

export const createPlatforms = (windowsCommandAMD64: string,
windowsCommandARM64: string,
linuxCommand: string,
windowsPath?: string,
windowsRestart?: string,
linuxPath?: string,
linuxRestart?: string) => [
{
id: 1,
name: 'WINDOWS (AMD64)',
command: windowsCommandAMD64,
shell: 'Run the following powershell script as “ADMINISTRATOR” in a Server with the UTMStack agent Installed.',
path: windowsPath,
restart: windowsRestart
},
{
id: 2,
name: 'WINDOWS (ARM64)',
command: windowsCommandARM64,
shell: 'Run the following powershell script as “ADMINISTRATOR” in a Server with the UTMStack agent Installed.',
path: windowsPath,
restart: windowsRestart
},
{
id: 3,
name: 'LINUX',
command: linuxCommand,
shell: 'Run the following bash script as “ADMINISTRATOR” in a Server with the UTMStack agent Installed.',
path: linuxPath,
restart: linuxRestart
}
];
function createPlatform(
id: number,
name: string,
command: string,
shell: string,
path?: string,
restart?: string,
extraCommands?: string[]): Platform {
return { id, name, command, shell, path, restart, extraCommands };
}

export const createFileBeatsPlatforms = (windowsCommand: string,
linuxCommand: string,
windowsPath?: string,
windowsRestart?: string,
linuxPath?: string,
linuxRestart?: string) => [
{
id: 1,
name: 'WINDOWS',
command: windowsCommand,
shell: 'Run the following powershell script as “ADMINISTRATOR” in a Server with the UTMStack agent Installed.',
path: windowsPath,
restart: windowsRestart
},
{
id: 3,
name: 'LINUX',
command: linuxCommand,
shell: 'Run the following bash script as “ADMINISTRATOR” in a Server with the UTMStack agent Installed.',
path: linuxPath,
restart: linuxRestart
}
export const createPlatforms = (
windowsCommandAMD64: string,
windowsCommandARM64: string,
linuxCommand: string,
windowsPath?: string,
windowsRestart?: string,
linuxPath?: string,
linuxRestart?: string): Platform[] => [
createPlatform(
1,
'WINDOWS (AMD64)',
windowsCommandAMD64,
WINDOWS_SHELL,
windowsPath,
windowsRestart,[
'Start-Process "C:\\Program Files\\UTMStack\\UTMStack Agent\\utmstack_agent_service.exe" ' +
'-ArgumentList \'load-tls-certs\', \'[YOUR_CERT_PATH]\', \'[YOUR_KEY_PATH]\' ' +
'-NoNewWindow -Wait'
]
),
createPlatform(
2,
'WINDOWS (ARM64)',
windowsCommandARM64,
WINDOWS_SHELL,
windowsPath,
windowsRestart,
[
'Start-Process "C:\\Program Files\\UTMStack\\UTMStack Agent\\utmstack_agent_service_arm64.exe" ' +
'-ArgumentList \'load-tls-certs\', \'[YOUR_CERT_PATH]\', \'[YOUR_KEY_PATH]\' ' +
'-NoNewWindow -Wait'
]
),
createPlatform(
3,
'LINUX',
linuxCommand,
LINUX_SHELL,
linuxPath,
linuxRestart,
[
`sudo bash -c "/opt/utmstack-linux-agent/utmstack_agent_service load-tls-certs [YOUR_CERT_PATH] [YOUR_KEY_PATH]"`
]
)
];

export const createFileBeatsPlatforms = (
windowsCommand: string,
linuxCommand: string,
windowsPath?: string,
windowsRestart?: string,
linuxPath?: string,
linuxRestart?: string): Platform[] => [
createPlatform(
1,
'WINDOWS',
windowsCommand,
WINDOWS_SHELL,
windowsPath,
windowsRestart
),
createPlatform(
3,
'LINUX',
linuxCommand,
LINUX_SHELL,
linuxPath,
linuxRestart
)
];

export const PLATFORMS = createPlatforms(
'Start-Process "C:\\Program Files\\UTMStack\\UTMStack Agent\\utmstack_agent_service.exe" -ArgumentList \'ACTION\',' +
' \'AGENT_NAME\', \'PORT\' -NoNewWindow -Wait\n',
'Start-Process "C:\\Program Files\\UTMStack\\UTMStack Agent\\utmstack_agent_service_arm64.exe" -ArgumentList \'ACTION\',' +
' \'AGENT_NAME\', \'PORT\' -NoNewWindow -Wait\n',
'sudo bash -c "/opt/utmstack-linux-agent/utmstack_agent_service ACTION AGENT_NAME PORT"'
'Start-Process "C:\\Program Files\\UTMStack\\UTMStack Agent\\utmstack_agent_service.exe" -ArgumentList \'ACTION\', \'AGENT_NAME\', \'PROTOCOL\', \'TLS\' -NoNewWindow -Wait\n',
'Start-Process "C:\\Program Files\\UTMStack\\UTMStack Agent\\utmstack_agent_service_arm64.exe" -ArgumentList \'ACTION\', \'AGENT_NAME\', \'PROTOCOL\, \'TLS\' -NoNewWindow -Wait\n',
'sudo bash -c "/opt/utmstack-linux-agent/utmstack_agent_service ACTION AGENT_NAME PROTOCOL TLS"'
);


export const FILEBEAT_PLATFORMS = createFileBeatsPlatforms(
'cd "C:\\Program Files\\UTMStack\\UTMStack Agent\\beats\\filebeat\\"; Start-Process "filebeat.exe" -ArgumentList "modules", "enable", \"AGENT_NAME\"',
'cd "C:\\Program Files\\UTMStack\\UTMStack Agent\\beats\\filebeat\\"; Start-Process "filebeat.exe" -ArgumentList "modules", "enable", "AGENT_NAME"',
'cd /opt/utmstack-linux-agent/beats/filebeat/ && ./filebeat modules enable AGENT_NAME',
'C:\\Program Files\\UTMStack\\UTMStack Agent\\beats\\filebeat\\modules.d\\',
'Stop-Service -Name UTMStackModulesLogsCollector; Start-Sleep -Seconds 5; Start-Service -Name UTMStackModulesLogsCollector',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ export class AlertEntityDisplayComponent implements OnInit, OnChanges {
}

ngOnInit() {
console.log('type', this.type);
console.log('field', this.field);
if (this.alert[this.key]) {
this.fields = Object.keys(this.alert[this.key]);
if (this.alert[this.key].geolocation) {
Expand Down
35 changes: 32 additions & 3 deletions frontend/src/app/shared/util/replace-command-tokens.util.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,33 @@
export function replaceCommandTokens(command: string, wordsToReplace: { [key: string]: string }) {
return Object.keys(wordsToReplace)
.reduce((f, s) => f.replace(new RegExp(s, 'ig'), wordsToReplace[s]), command);
export function replaceCommandTokens(command: string, wordsToReplace: { [key: string]: string }): string {
let cmd = command;

if (cmd.includes('-ArgumentList')) {

const args = Object.values(wordsToReplace)
.filter(v => v && v.trim().length > 0)
.map(v => `'${v.trim()}'`)
.join(', ');

cmd = cmd.replace(
/-ArgumentList\s+(['"].*?['"])(?=\s+-|$)/,
`-ArgumentList ${args}`
);
} else {
const match = cmd.match(/"(.*)"/);
if (match) {
const original = match[1];
const parts = original.split(/\s+/);
const fixedCommand = parts[0];
const args = Object.entries(wordsToReplace)
.filter(([_, v]) => v && v.trim().length > 0)
.map(([_, v]) => v.trim())
.join(' ');

cmd = cmd.replace(/"(.*)"/, `"${fixedCommand} ${args}"`);
}
}

cmd = cmd.replace(/\s+/g, ' ').trim();

return cmd;
}