From 60cac3b287adcfd5a3604bad49616042e0e83021 Mon Sep 17 00:00:00 2001 From: VakarisZ Date: Tue, 13 Jul 2021 10:17:14 +0300 Subject: [PATCH] Island: refactor file encryption table to display how many files were encrypted --- .../report-components/common/RenderBool.tsx | 13 ----- .../common/RenderFileEncryptionStats.tsx | 12 +++++ .../ransomware/FileEncryptionTable.tsx | 47 ++++++++++--------- 3 files changed, 38 insertions(+), 34 deletions(-) delete mode 100644 monkey/monkey_island/cc/ui/src/components/report-components/common/RenderBool.tsx create mode 100644 monkey/monkey_island/cc/ui/src/components/report-components/common/RenderFileEncryptionStats.tsx diff --git a/monkey/monkey_island/cc/ui/src/components/report-components/common/RenderBool.tsx b/monkey/monkey_island/cc/ui/src/components/report-components/common/RenderBool.tsx deleted file mode 100644 index 70d527682..000000000 --- a/monkey/monkey_island/cc/ui/src/components/report-components/common/RenderBool.tsx +++ /dev/null @@ -1,13 +0,0 @@ -import React from 'react'; - - -function renderBool(val: Boolean) { - - if(val === true){ - return (

Yes

); - } else { - return (

No

); - } -} - -export default renderBool; diff --git a/monkey/monkey_island/cc/ui/src/components/report-components/common/RenderFileEncryptionStats.tsx b/monkey/monkey_island/cc/ui/src/components/report-components/common/RenderFileEncryptionStats.tsx new file mode 100644 index 000000000..7e5853c14 --- /dev/null +++ b/monkey/monkey_island/cc/ui/src/components/report-components/common/RenderFileEncryptionStats.tsx @@ -0,0 +1,12 @@ +import React from 'react'; + + +function renderFileEncryptionStats(successful: number, total: number) { + if(successful > 0){ + return (

{successful} out of {total}

); + } else { + return (

{successful} out of {total}

); + } +} + +export default renderFileEncryptionStats; diff --git a/monkey/monkey_island/cc/ui/src/components/report-components/ransomware/FileEncryptionTable.tsx b/monkey/monkey_island/cc/ui/src/components/report-components/ransomware/FileEncryptionTable.tsx index 306cb5cc3..8be659eab 100644 --- a/monkey/monkey_island/cc/ui/src/components/report-components/ransomware/FileEncryptionTable.tsx +++ b/monkey/monkey_island/cc/ui/src/components/report-components/ransomware/FileEncryptionTable.tsx @@ -1,38 +1,29 @@ import React from 'react'; import ReactTable from 'react-table'; import {renderArray} from '../common/RenderArrays'; -import renderBool from "../common/RenderBool"; +import renderFileEncryptionStats from "../common/renderFileEncryptionStats"; -const columns = [ - { - Header: 'Ransomware info', - columns: [ - {Header: 'Machine', id: 'machine', accessor: x => x.hostname}, - {Header: 'Exploits', id: 'exploits', accessor: x => renderArray(x.exploits)}, - {Header: 'Files got encrypted?', id: 'files_encrypted', accessor: x => renderBool(x.files_encrypted)} - ] - } -]; - -const pageSize = 10; - -type TableRow = { - exploits: [string], - files_encrypted: boolean, - hostname: string -} - type Props = { tableData: [TableRow] } +type TableRow = { + exploits: [string], + total_attempts: number, + successful_encryptions: number, + hostname: string +} + +const pageSize = 10; + + const FileEncryptionTable = (props: Props) => { let defaultPageSize = props.tableData.length > pageSize ? pageSize : props.tableData.length; let showPagination = props.tableData.length > pageSize; return ( <> -

+

File encryption

@@ -47,4 +38,18 @@ const FileEncryptionTable = (props: Props) => { ); } +const columns = [ + { + Header: 'Ransomware info', + columns: [ + {Header: 'Machine', id: 'machine', accessor: x => x.hostname}, + {Header: 'Exploits', id: 'exploits', accessor: x => renderArray(x.exploits)}, + {Header: 'Files encrypted', + id: 'files_encrypted', + accessor: x => renderFileEncryptionStats(x.successful_encryptions, x.total_attempts)} + ] + } +]; + + export default FileEncryptionTable;