Island: Pass island mode as a prop from Main.js to child components

This commit is contained in:
Mike Salvatore 2021-07-14 12:52:24 -04:00
parent f725efd41a
commit a786428652
3 changed files with 20 additions and 19 deletions

View File

@ -27,6 +27,7 @@ import {StandardLayoutComponent} from './layouts/StandardLayoutComponent';
import LoadingScreen from './ui-components/LoadingScreen';
const reportZeroTrustRoute = '/report/zeroTrust';
const islandModeRoute = '/api/island-mode'
class AppComponent extends AuthComponent {
updateStatus = () => {
@ -113,15 +114,26 @@ class AppComponent extends AuthComponent {
infection_done: false,
report_done: false,
isLoggedIn: undefined,
needsRegistration: undefined
needsRegistration: undefined,
islandMode: undefined
},
noAuthLoginAttempted: undefined
};
}
updateIslandMode() {
this.authFetch(islandModeRoute)
.then(res => res.json())
.then(res => {
this.setState({islandMode: res.mode})
}
);
}
componentDidMount() {
this.updateStatus();
this.interval = setInterval(this.updateStatus, 10000);
this.updateIslandMode()
}
componentWillUnmount() {
@ -147,6 +159,7 @@ class AppComponent extends AuthComponent {
completedSteps={this.state.completedSteps}/>)}
{this.renderRoute('/run-monkey',
<StandardLayoutComponent component={RunMonkeyPage}
islandMode={this.state.islandMode}
onStatusChange={this.updateStatus}
completedSteps={this.state.completedSteps}/>)}
{this.renderRoute('/infection/map',

View File

@ -17,7 +17,7 @@ class RunMonkeyPageComponent extends AuthComponent {
Go ahead and run the monkey!
<i> (Or <Link to="/configure">configure the monkey</Link> to fine tune its behavior)</i>
</p>
<RunOptions />
<RunOptions islandMode={this.props.islandMode}/>
</Col>
);
}

View File

@ -11,7 +11,6 @@ import AWSRunButton from './RunOnAWS/AWSRunButton';
import CloudOptions from './scoutsuite-setup/CloudOptions';
const CONFIG_URL = '/api/configuration/island';
const MODE_URL = '/api/island-mode'
function RunOptions(props) {
@ -57,22 +56,11 @@ function RunOptions(props) {
return InlineSelection(defaultContents, newProps);
}
function getIslandMode() {
let mode = 'advanced';
authComponent.authFetch(MODE_URL)
.then(res => res.json())
.then(res => {
mode = res.mode
}
);
return mode;
function shouldShowScoutsuite(islandMode){
return islandMode !== 'ransomware';
}
function shouldShowScoutsuite(){
return getIslandMode() === 'advanced';
}
function defaultContents() {
function defaultContents(props) {
return (
<>
<RunOnIslandButton title={'From Island'}
@ -85,8 +73,8 @@ function RunOptions(props) {
setComponent(LocalManualRunOptions,
{ips: ips, setComponent: setComponent})
}}/>
{shouldShowScoutsuite() && <AWSRunButton setComponent={setComponent}/> }
{shouldShowScoutsuite() && <NextSelectionButton title={'Cloud security scan'}
{shouldShowScoutsuite(props.islandMode) && <AWSRunButton setComponent={setComponent}/> }
{shouldShowScoutsuite(props.islandMode) && <NextSelectionButton title={'Cloud security scan'}
description={'Explains how to enable cloud security scan.'}
icon={faCloud}
onButtonClick={() => {