Skip to content

Commit

Permalink
add conditional rendering details
Browse files Browse the repository at this point in the history
  • Loading branch information
johanah29 committed Nov 15, 2024
1 parent cdc99a6 commit a0f473d
Show file tree
Hide file tree
Showing 4 changed files with 346 additions and 171 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { FunctionComponent, useContext } from 'react';

import { useFormatter } from '../../../../components/i18n';
import ItemStatus from '../../../../components/ItemStatus';
import { InjectResultOverviewOutputContext, InjectResultOverviewOutputContextType } from '../InjectResultOverviewOutputContext';

const useStyles = makeStyles(() => ({
paper: {
Expand All @@ -23,103 +24,14 @@ const useStyles = makeStyles(() => ({

const AtomicTestingDetail: FunctionComponent<Props> = () => {
const classes = useStyles();
const { t, tPick } = useFormatter();
const { t } = useFormatter();

// Fetching data
const { injectResultOverviewOutput } = useContext<InjectResultOverviewOutputContextType>(InjectResultOverviewOutputContext);

return (
<Grid container spacing={2}>
<Grid item xs={12} style={{ marginBottom: 30 }}>
<Typography variant="h4">{t('Configuration')}</Typography>
{injectResultOverviewOutput ? (
<Paper variant="outlined" classes={{ root: classes.paper }}>
<Grid container spacing={3}>
<Grid item xs={12} sm={4}>
<Typography variant="subtitle1" className={classes.header} gutterBottom>
{t('Description')}
</Typography>
<Typography variant="body1" gutterBottom>
{injectResultOverviewOutput?.inject_description || '-'}
</Typography>
</Grid>
<Grid item xs={12} sm={4}>
<Typography variant="subtitle1" className={classes.header} gutterBottom>
{t('Type')}
</Typography>
<Typography variant="body1" gutterBottom>
{tPick(injectResultOverviewOutput.inject_injector_contract?.injector_contract_labels)}
</Typography>
</Grid>
<Grid item xs={12} sm={4}>
<Typography variant="subtitle1" className={classes.header} gutterBottom>
{t('Expectations')}
</Typography>
{
injectResultOverviewOutput.inject_expectations !== undefined && injectResultOverviewOutput.inject_expectations.length > 0
? Array.from(new Set(injectResultOverviewOutput.inject_expectations.map(expectation => expectation.inject_expectation_name)))
.map((name, index) => (
<Typography key={index} variant="body1">
{name}
</Typography>
))
: (
<Typography variant="body1" gutterBottom>
-
</Typography>
)
}
</Grid>
</Grid>
</Paper>
) : (
<Paper variant="outlined" classes={{ root: classes.paper }}>
<Typography variant="body1">{t('No data available')}</Typography>
</Paper>
)}
</Grid>
{injectResultOverviewOutput?.inject_commands_lines && (
<Grid item xs={6} style={{ marginBottom: 30 }}>
<Typography variant="h4">{t('Command Lines')}</Typography>
<Paper variant="outlined" classes={{ root: classes.paper }}>
<Typography variant="subtitle1" className={classes.header} gutterBottom>
{t('Attack command')}
</Typography>
{(injectResultOverviewOutput.inject_commands_lines?.content?.length ?? 0) > 0 ? (
<pre>
<Typography variant="body1" gutterBottom>
{injectResultOverviewOutput.inject_commands_lines?.content?.map((content, index) => (
<li key={index}>{content}</li>
))}
</Typography>
</pre>
) : '-'}
<Typography variant="subtitle1" className={classes.header} gutterBottom>
{t('Cleanup command')}
</Typography>
{(injectResultOverviewOutput.inject_commands_lines?.cleanup_command?.length ?? 0) > 0 ? (
<pre>
<Typography variant="body1" gutterBottom>
{injectResultOverviewOutput.inject_commands_lines?.cleanup_command?.map((content, index) => (
<li key={index}>{content}</li>
))}
</Typography>
</pre>
) : '-'}
<Typography variant="subtitle1" className={classes.header} gutterBottom>
{t('External ID')}
</Typography>
{injectResultOverviewOutput.inject_commands_lines?.external_id ? (
<pre>
<Typography variant="body1" gutterBottom>
{injectResultOverviewOutput.inject_commands_lines?.external_id}
</Typography>
</pre>
) : '-'}
</Paper>
</Grid>
)}
<Grid item xs={injectResultOverviewOutput?.inject_commands_lines ? 6 : 12} style={{ marginBottom: 30 }}>
<Typography variant="h4">{t('Execution logs')}</Typography>
{injectResultOverviewOutput ? (
<Paper variant="outlined" classes={{ root: classes.paper }}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ import { makeStyles } from '@mui/styles';
import { Props } from 'html-react-parser/lib/attributes-to-props';
import { FunctionComponent, useContext } from 'react';

import { AttackPatternHelper } from '../../../../actions/attack_patterns/attackpattern-helper';
import { useFormatter } from '../../../../components/i18n';
import ItemCopy from '../../../../components/ItemCopy';
import ItemTags from '../../../../components/ItemTags';
import PlatformIcon from '../../../../components/PlatformIcon';
import { useHelper } from '../../../../store';
import { AttackPattern, PayloadArgument, PayloadPrerequisite } from '../../../../utils/api-types';
import { emptyFilled } from '../../../../utils/String';
import { InjectResultDtoContext, InjectResultDtoContextType } from '../InjectResultDtoContext';
Expand Down Expand Up @@ -132,26 +130,134 @@ const AtomicTestingPayloadInfo: FunctionComponent<Props> = () => {
<Typography variant="h4">{t('Commands')}</Typography>
{injectResultDto ? (
<Paper variant="outlined" classes={{ root: classes.paper }}>
<Typography
variant="h3"
gutterBottom
>
{t('Command executor')}
</Typography>
{/* {injectResultDto?.inject_injector_contract?.injector_contract_payload?.} */}
<Typography
variant="h3"
gutterBottom
style={{ marginTop: 20 }}
>
{t('Attack commands')}
</Typography>
<pre>
{/* <ItemCopy content={
injectResultDto.inject_commands_lines?.content ?? ''
}
/> */}
</pre>
{injectResultDto?.inject_injector_contract?.injector_contract_payload?.payload_type === 'Command' && (
<>
<Typography
variant="h3"
gutterBottom
>
{t('Command executor')}
</Typography>
{injectResultDto?.inject_injector_contract?.injector_contract_payload?.command_executor}
<Typography
variant="h3"
gutterBottom
style={{ marginTop: 20 }}
>
{t('Attack commands')}
</Typography>
<pre>
<ItemCopy content={
injectResultDto?.inject_injector_contract?.injector_contract_payload?.command_content ?? ''
}
/>
</pre>
</>
)}
{injectResultDto?.inject_injector_contract?.injector_contract_payload?.payload_type === 'Executable' && (
<>
<Typography
variant="h3"
gutterBottom
>
{t('Executable files')}
</Typography>
{
injectResultDto?.inject_injector_contract?.injector_contract_payload?.executable_file !== undefined
? (
<Typography variant="body1">
{injectResultDto?.inject_injector_contract?.injector_contract_payload?.executable_file?.document_name ?? '-'}
</Typography>
)
: (
<Typography variant="body1" gutterBottom>
-
</Typography>
)
}
<Typography
variant="h3"
gutterBottom
style={{ marginTop: 20 }}
>
{t('Architecture')}
</Typography>
{injectResultDto?.inject_injector_contract?.injector_contract_payload?.executable_arch}
</>
)}
{injectResultDto?.inject_injector_contract?.injector_contract_payload?.payload_type === 'File' && (
<>
<Typography
variant="h3"
gutterBottom
>
{t('File drop file')}
</Typography>
{
injectResultDto?.inject_injector_contract?.injector_contract_payload?.file_drop_file !== undefined
? (
<Typography variant="body1">
{injectResultDto?.inject_injector_contract?.injector_contract_payload?.file_drop_file?.document_name ?? '-'}
</Typography>
)
: (
<Typography variant="body1" gutterBottom>
-
</Typography>
)
}
</>
)}
{injectResultDto?.inject_injector_contract?.injector_contract_payload?.payload_type === 'Dns' && (
<>
<Typography
variant="h3"
gutterBottom
>
{t('Dns resolution hostname')}
</Typography>
{injectResultDto?.inject_injector_contract?.injector_contract_payload?.dns_resolution_hostname}
</>
)}
{injectResultDto?.inject_injector_contract?.injector_contract_payload?.payload_type === 'Network' && (
<>
<Typography
variant="h3"
gutterBottom
>
{t('Network traffic ip destination')}
</Typography>
{injectResultDto?.inject_injector_contract?.injector_contract_payload?.network_traffic_ip_dst}
<Typography
variant="h3"
gutterBottom
>
{t('Network traffic port destination')}
</Typography>
{injectResultDto?.inject_injector_contract?.injector_contract_payload?.network_traffic_port_dst}
<Typography
variant="h3"
gutterBottom
>
{t('Network traffic ip source')}
</Typography>
{injectResultDto?.inject_injector_contract?.injector_contract_payload?.network_traffic_ip_src}
<Typography
variant="h3"
gutterBottom
>
{t('Network traffic port source')}
</Typography>
{injectResultDto?.inject_injector_contract?.injector_contract_payload?.network_traffic_port_src}
<Typography
variant="h3"
gutterBottom
>
{t('Network traffic protocol')}
</Typography>
{injectResultDto?.inject_injector_contract?.injector_contract_payload?.network_traffic_protocol}
</>
)}
<Typography
variant="h3"
gutterBottom
Expand Down
Loading

0 comments on commit a0f473d

Please sign in to comment.