Skip to content

Commit

Permalink
[api/frontend/documentation] Enhance works and doc (#322)
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Hassine authored Feb 23, 2020
1 parent 567d024 commit f0e9d6f
Show file tree
Hide file tree
Showing 8 changed files with 369 additions and 256 deletions.
2 changes: 1 addition & 1 deletion opencti-documentation/docs/installation/auto.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ The OVA file is available on the [Luatix Google Drive folder](https://drive.goog

Then open the OVA file with VirtualBox or convert the OVA to another type of virtual machine image and launch it. You can login within the VM or connect in SSH with the default login `opencti` and the default password `opencti`.

> Once the virtual machine is launched, the **OpenCTI platform can take 3 to 5 minutes to start the first time**. Then you have access to the plaform using the URL **http://{IP_ADDRESS}:8080**.
> Once the virtual machine is launched, the **OpenCTI platform can take 3 to 5 minutes to start the first time**. Then you have access to the plaform using the URL **http://{IP_ADDRESS}:8080** and credentials `[email protected]` / `admin`.
# Using Docker

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ The OVA file is available on the [Luatix Google Drive folder](https://drive.goog

Then open the OVA file with VirtualBox or convert the OVA to another type of virtual machine image and launch it. You can login within the VM or connect in SSH with the default login `opencti` and the default password `opencti`.

> Once the virtual machine is launched, the **OpenCTI platform can take 3 to 5 minutes to start the first time**. Then you have access to the plaform using the URL **http://{IP_ADDRESS}:8080**.
> Once the virtual machine is launched, the **OpenCTI platform can take 3 to 5 minutes to start the first time**. Then you have access to the plaform using the URL **http://{IP_ADDRESS}:8080** and credentials `[email protected]` / `admin`.
# Using Docker

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
id: version-3.0.2-entities
title: Entities
sidebar_label: Entities
original_id: entities
---

## Introduction

Here is the reference about OpenCTI entities

## Stix-Entity
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React, { Component } from 'react';
import * as PropTypes from 'prop-types';
import { propOr, compose } from 'ramda';
import {
propOr, compose, last, join,
} from 'ramda';
import uuid from 'uuid/v4';
import { createFragmentContainer } from 'react-relay';
import graphql from 'babel-plugin-relay/macro';
Expand All @@ -14,6 +16,7 @@ import { CheckCircle, Delete, Warning } from '@material-ui/icons';

import ListItemSecondaryAction from '@material-ui/core/ListItemSecondaryAction';
import IconButton from '@material-ui/core/IconButton';
import Tooltip from '@material-ui/core/Tooltip';
import inject18n from '../../../../components/i18n';
import { commitMutation } from '../../../../relay/environment';

Expand All @@ -40,46 +43,54 @@ class FileWorkComponent extends Component {
render() {
const {
t,
nsdt,
classes,
file: { works },
} = this.props;
return (
<List component="div" disablePadding={true}>
{works
&& works.map((work) => (
<ListItem
key={uuid()}
dense={true}
button={true}
divider={true}
classes={{ root: classes.nested }}
>
<ListItemIcon>
{(work.status === 'error' || work.status === 'partial') && (
<Warning style={{ fontSize: 15, color: '#f44336' }} />
)}
{work.status === 'complete' && (
<CheckCircle style={{ fontSize: 15, color: '#4caf50' }} />
)}
{work.status === 'progress' && (
<CircularProgress
size={20}
thickness={2}
style={{ marginRight: 10 }}
&& works.map((work) => {
const message = join(
' | ',
propOr([], 'messages', last(propOr([], 'jobs', work))),
);
return (
<Tooltip title={message} key={uuid()}>
<ListItem
dense={true}
button={true}
divider={true}
classes={{ root: classes.nested }}
>
<ListItemIcon>
{(work.status === 'error' || work.status === 'partial') && (
<Warning style={{ fontSize: 15, color: '#f44336' }} />
)}
{work.status === 'complete' && (
<CheckCircle style={{ fontSize: 15, color: '#4caf50' }} />
)}
{work.status === 'progress' && (
<CircularProgress
size={20}
thickness={2}
style={{ marginRight: 10 }}
/>
)}
</ListItemIcon>
<ListItemText
primary={propOr(t('Deleted'), 'name', work.connector)}
secondary={nsdt(work.created_at)}
/>
)}
</ListItemIcon>
<ListItemText
primary={propOr(t('Deleted'), 'name', work.connector)}
secondary={t(work.status)}
/>
<ListItemSecondaryAction style={{ right: 0 }}>
<IconButton onClick={this.deleteWork.bind(this, work.id)}>
<Delete color="primary" />
</IconButton>
</ListItemSecondaryAction>
</ListItem>
))}
<ListItemSecondaryAction style={{ right: 0 }}>
<IconButton onClick={this.deleteWork.bind(this, work.id)}>
<Delete color="primary" />
</IconButton>
</ListItemSecondaryAction>
</ListItem>
</Tooltip>
);
})}
</List>
);
}
Expand All @@ -88,6 +99,7 @@ class FileWorkComponent extends Component {
FileWorkComponent.propTypes = {
classes: PropTypes.object,
file: PropTypes.object.isRequired,
nsdt: PropTypes.func,
};

const FileWork = createFragmentContainer(FileWorkComponent, {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
import React, { useEffect } from 'react';
import { interval } from 'rxjs';
import {
pipe, propOr, compose, filter, last, join,
} from 'ramda';
import { createRefetchContainer } from 'react-relay';
import graphql from 'babel-plugin-relay/macro';
import Tooltip from '@material-ui/core/Tooltip';
import IconButton from '@material-ui/core/IconButton';
import {
CheckCircle,
Delete,
Extension,
Refresh,
Warning,
} from '@material-ui/icons';
import CircularProgress from '@material-ui/core/CircularProgress';
import { withStyles } from '@material-ui/core';
import ListItem from '@material-ui/core/ListItem';
import ListItemIcon from '@material-ui/core/ListItemIcon';
import ListItemText from '@material-ui/core/ListItemText';
import ListItemSecondaryAction from '@material-ui/core/ListItemSecondaryAction';
import List from '@material-ui/core/List';
import Paper from '@material-ui/core/Paper';
import uuid from 'uuid/v4';
import { FIVE_SECONDS } from '../../../../utils/Time';
import { commitMutation } from '../../../../relay/environment';
import inject18n from '../../../../components/i18n';
import Security, { KNOWLEDGE_KNENRICHMENT } from '../../../../utils/Security';

const interval$ = interval(FIVE_SECONDS);

const StixObservableEnrichmentQuery = graphql`
query StixObservableEnrichmentQuery($id: String!) {
stixObservable(id: $id) {
...StixObservableEnrichment_stixObservable
}
}
`;

const StixObservableEnrichmentDeleteMutation = graphql`
mutation StixObservableEnrichmentDeleteMutation($workId: ID!) {
deleteWork(id: $workId)
}
`;

const StixObservableEnrichmentAskEnrich = graphql`
mutation StixObservableEnrichmentMutation($id: ID!, $connectorId: ID!) {
stixObservableEdit(id: $id) {
askEnrichment(connectorId: $connectorId) {
id
}
}
}
`;

const styles = (theme) => ({
container: {
margin: 0,
},
gridContainer: {
marginBottom: 20,
},
paper: {
height: '100%',
minHeight: '100%',
margin: '13px 0 0 0',
padding: '10px 15px 10px 15px',
borderRadius: 6,
},
nested: {
paddingLeft: theme.spacing(4),
},
});

const StixObservableEnrichment = (props) => {
const {
stixObservable, relay, classes, t, nsdt,
} = props;
const { id } = stixObservable;
const askEnrich = (connectorId) => {
commitMutation({
mutation: StixObservableEnrichmentAskEnrich,
variables: { id, connectorId },
onCompleted: () => relay.refetch({ id, entityType: stixObservable.entity_type }),
});
};
const deleteWork = (workId) => {
commitMutation({
mutation: StixObservableEnrichmentDeleteMutation,
variables: { workId },
onCompleted: () => relay.refetch({ id, entityType: stixObservable.entity_type }),
});
};
useEffect(() => {
const subscription = interval$.subscribe(() => {
relay.refetch({
id: stixObservable.id,
entityType: stixObservable.entity_type,
});
});
return () => {
subscription.unsubscribe();
};
});
return (
<Paper classes={{ root: classes.paper }} elevation={2}>
<List>
{stixObservable.connectors.length > 0 ? (
stixObservable.connectors.map((connector) => {
const jobs = pipe(
propOr([], 'jobs'),
filter((n) => n.connector.id === connector.id),
)(stixObservable);
const isRefreshing = filter((node) => node.status !== 'complete', jobs).length > 0;
return (
<div key={connector.id}>
<ListItem
divider={true}
classes={{ root: classes.item }}
button={true}
>
<Tooltip
title={
connector.active
? t('This connector is active')
: t('This connector is disconnected')
}
>
<ListItemIcon
style={{
color: connector.active ? '#4caf50' : '#f44336',
}}
>
<Extension />
</ListItemIcon>
</Tooltip>
<ListItemText primary={connector.name} />
<Security needs={[KNOWLEDGE_KNENRICHMENT]}>
<ListItemSecondaryAction style={{ right: 0 }}>
<Tooltip
title={t('Refresh the knowledge using this connector')}
>
<IconButton
disabled={!connector.active || isRefreshing}
onClick={() => askEnrich(connector.id)}
>
<Refresh />
</IconButton>
</Tooltip>
</ListItemSecondaryAction>
</Security>
</ListItem>
<List component="div" disablePadding={true}>
{jobs.map((work) => {
const message = join(
' | ',
propOr([], 'messages', last(propOr([], 'jobs', work))),
);
return (
<Tooltip title={message} key={uuid()}>
<ListItem
dense={true}
button={true}
divider={true}
classes={{ root: classes.nested }}
>
<ListItemIcon>
{(work.status === 'error'
|| work.status === 'partial') && (
<Warning
style={{
fontSize: 15,
color: '#f44336',
}}
/>
)}
{work.status === 'complete' && (
<CheckCircle
style={{
fontSize: 15,
color: '#4caf50',
}}
/>
)}
{work.status === 'progress' && (
<CircularProgress
size={20}
thickness={2}
style={{ marginRight: 10 }}
/>
)}
</ListItemIcon>
<ListItemText primary={nsdt(work.created_at)} />
<ListItemSecondaryAction style={{ right: 0 }}>
<IconButton onClick={() => deleteWork(work.id)}>
<Delete />
</IconButton>
</ListItemSecondaryAction>
</ListItem>
</Tooltip>
);
})}
</List>
</div>
);
})
) : (
<div>{t('No connectors for this type of observable')}</div>
)}
</List>
</Paper>
);
};

const StixObservableEnrichmentFragment = createRefetchContainer(
StixObservableEnrichment,
{
stixObservable: graphql`
fragment StixObservableEnrichment_stixObservable on StixObservable {
id
entity_type
jobs(first: 100) {
id
created_at
connector {
id
name
}
jobs {
messages
}
status
}
connectors(onlyAlive: false) {
id
name
active
updated_at
}
}
`,
},
StixObservableEnrichmentQuery,
);

export default compose(
inject18n,
withStyles(styles),
)(StixObservableEnrichmentFragment);
Loading

0 comments on commit f0e9d6f

Please sign in to comment.