summaryrefslogtreecommitdiff
path: root/src/components/ScanView.js
blob: 01b35c72064bc8ff81a48226aebe841c367e3ce9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
import React, { useState, useEffect } from "react";

import Alert from "@mui/material/Alert";
import Button from "@mui/material/Button";
import Card from "@mui/material/Card";
import CircularProgress from "@mui/material/CircularProgress";
import Tooltip from "@mui/material/Tooltip";

import InfoOutlinedIcon from "@mui/icons-material/InfoOutlined";

import dateFormat from "dateformat";

import { resultClassName } from "../util";

function ScanView(props) {
    let [rescanInProgress, setRescanInProgress] = useState(false);
    let [data, setData] = useState(null);
    let [timestamp, setTimestamp] = useState(null);

    useEffect(getData, []);

    function getData() {
        fetch(`${window.injectedEnv.COLLECTOR_URL}/sc/v0/get/${props.id}`, {
            headers: {
                Authorization: "Bearer " + props.token
            }
        })
            .then(resp => {
                if (resp.status !== 200)
                    throw new Error(
                        `Unexpected HTTP response code from soc_collector: ${resp.status} ${resp.statusText}`
                    );
                return resp.json();
            })
            .then(json => {
                setData(json.docs);
                setTimestamp(new Date(json.docs.timestamp));
            })
            .catch(e => props.setError(e.toString()));
    }

    // TODO: Trigger a real re-scan
    function rescan() {
        setRescanInProgress(true);
        setTimeout(() => {
            setRescanInProgress(false);
            setTimestamp(Date.now());
        }, 2000);
    }

    if (data === null) return null;
    else {
        return (
            <Card className="scan-detail" variant="outlined">
                <div className="id">
                    <a href={`/${data._id}`}>#{data._id}</a>
                </div>
                <h2>General info</h2>

                <table>
                    <tbody>
                        <tr>
                            <td>Domain</td>
                            <td>{data.domain}</td>
                        </tr>
                        <tr>
                            <td>Endpoint</td>
                            <td>{`${data.ip}:${data.port}`}</td>
                        </tr>
                        <tr>
                            <td>Hostname</td>
                            <td>{data.ptr}</td>
                        </tr>
                        <tr>
                            <td>Owner</td>
                            <td>{data.whois_description}</td>
                        </tr>
                        <tr>
                            <td>ASN</td>
                            <td>{`${data.asn} (${data.asn_country_code})`}</td>
                        </tr>
                        <tr>
                            <td>Abuse mail</td>
                            <td>{data.abuse_mail}</td>
                        </tr>
                    </tbody>
                </table>

                {data.description && (
                    <>
                        <br />
                        <Alert severity="info">{data.description}</Alert>
                    </>
                )}

                <h2>Custom info</h2>
                <Custom {...data.custom_data} />

                <h2
                    style={{
                        display: "flex",
                        justifyContent: "space-between"
                    }}
                >
                    <div>
                        Latest scan: &nbsp;&nbsp;&nbsp;
                        {dateFormat(timestamp, "isoUtcDateTime")}
                    </div>
                    <div
                        style={{
                            width: "93px",
                            height: "37px",
                            display: "flex",
                            flexDirection: "vertical",
                            justifyContent: "center",
                            alignItems: "center"
                        }}
                    >
                        {rescanInProgress ? (
                            <CircularProgress size="37px" />
                        ) : (
                            <Button variant="contained" onClick={rescan}>
                                Re-scan
                            </Button>
                        )}
                    </div>
                </h2>

                <div id="results">
                    {Object.entries(data.result)
                        // Sort by vulnerable, investigation_needed, reliability, name
                        .sort((a, b) =>
                            a[1].display_name > b[1].display_name ? -1 : 1
                        )
                        .sort((a, b) =>
                            a[1].reliability < b[1].reliability ? -1 : 1
                        )
                        .sort((a, b) =>
                            a[1].vulnerable || a[1].investigation_needed
                                ? -1
                                : 1
                        )
                        .sort((a, b) => (a[1].vulnerable ? -1 : 1))
                        .map(([id, res]) => (
                            <Result key={id} {...res} />
                        ))}
                </div>
            </Card>
        );
    }
}

function Custom(props) {
    return (
        <table>
            <tbody>
                {Object.entries(props).map(
                    ([key, { data, display_name, description }]) => (
                        <CustomElement
                            key={key}
                            data={data}
                            display_name={display_name}
                            description={description}
                        />
                    )
                )}
            </tbody>
        </table>
    );
}

function CustomElement(props) {
    return (
        <tr>
            <td>{props.display_name}</td>
            <td>{props.data.toString()}</td>
            <td style={{ fontStyle: "italic" }}>{props.description}</td>
        </tr>
    );
}

function Result(props) {
    return (
        <div className="resultContainer">
            <Card className={resultClassName(props)} variant="outlined">
                {props.display_name}
                {props.description && (
                    <Tooltip title={props.description}>
                        <InfoOutlinedIcon />
                    </Tooltip>
                )}
            </Card>
            {(props.vulnerable || props.investigation_needed) && (
                <Card className="reliability" variant="outlined">
                    {props.reliability}
                </Card>
            )}
        </div>
    );
}

export default ScanView;