aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/components/panels/RulePane.js
blob: fbc8785b5a69e3b109981cea3d3998a171d3966b (plain) (blame)
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
import React, {Component} from 'react';
import './RulePane.scss';
import Table from "react-bootstrap/Table";
import {Button, Col, Container, Row} from "react-bootstrap";
import InputField from "../fields/InputField";
import CheckField from "../fields/CheckField";
import TextField from "../fields/TextField";
import backend from "../../backend";
import NumericField from "../fields/extensions/NumericField";
import ColorField from "../fields/extensions/ColorField";
import ChoiceField from "../fields/ChoiceField";
import ButtonField from "../fields/ButtonField";

class RulePane extends Component {

    constructor(props) {
        super(props);

        this.state = {
            rules: [],
        };
    }

    componentDidMount() {
        this.loadRules();
    }

    loadRules = () => {
        backend.getJson("/api/rules").then(res => this.setState({rules: res}));
    };


    render() {
        let rules = this.state.rules.map(r =>
            <tr className="table-row">
                <td>{r["id"].substring(0, 8)}</td>
                <td>{r["name"]}</td>
                <td>{r["notes"]}</td>
                {/*<td>{((new Date(s["completed_at"]) - new Date(s["started_at"])) / 1000).toFixed(3)}s</td>*/}
                {/*<td>{formatSize(s["size"])}</td>*/}
                {/*<td>{s["processed_packets"]}</td>*/}
                {/*<td>{s["invalid_packets"]}</td>*/}
                {/*<td>undefined</td>*/}
                {/*<td className="table-cell-action"><a target="_blank"*/}
                {/*                                     href={"/api/pcap/sessions/" + s["id"] + "/download"}>download</a>*/}
                {/*</td>*/}
            </tr>
        );

        return (
            <div className="pane-container rule-pane">
                <div className="pane-section">
                    <div className="section-header">
                        <span className="api-request">GET /api/rules</span>
                        <span className="api-response">200 OK</span>
                    </div>

                    <div className="section-table">
                        <Table borderless size="sm">
                            <thead>
                            <tr>
                                <th>id</th>
                                <th>name</th>
                                <th>notes</th>
                            </tr>
                            </thead>
                            <tbody>
                            {rules}
                            </tbody>
                        </Table>
                    </div>
                </div>

                <div className="pane-section">
                    <div className="section-header">
                        <span className="api-request">POST /api/rules</span>
                        <span className="api-response"></span>
                    </div>

                    <div className="section-content">
                        <Container className="p-0">
                            <Row>
                                <Col>
                                    <InputField name="name" inline />
                                    <ColorField value={this.state.test1} onChange={(e) => this.setState({test1: e})} inline />
                                    <TextField name="notes" rows={2} />
                                </Col>

                                <Col>
                                    <div >filters:</div>
                                    <NumericField name="service_port" inline value={this.state.test} onChange={(e) => this.setState({test: e})} validate={(e) => e%2 === 0} />

                                    <NumericField name="client_port" inline />
                                    <InputField name="client_address" />
                                </Col>

                                <Col>
                                    <NumericField name="min_duration" inline />
                                    <NumericField name="max_duration" inline />
                                    <NumericField name="min_bytes" inline />
                                    <NumericField name="max_bytes" inline />

                                </Col>
                            </Row>
                        </Container>

                        <div className="post-rules-actions">
                            <label>options:</label>
                            <div className="rules-options">
                                <CheckField name={"enabled"} />
                            </div>

                            <ButtonField variant="blue" name="clear" bordered />
                            <ButtonField variant="green" name="add_rule" bordered />
                        </div>

                        patterns:
                        <div className="section-table">
                            <Table borderless size="sm">
                                <thead>
                                <tr>
                                    <th>regex</th>
                                    <th>Aa</th>
                                    <th>.*</th>
                                    <th>\n+</th>
                                    <th>UTF8</th>
                                    <th>Uni_</th>
                                    <th>min</th>
                                    <th>max</th>
                                    <th>direction</th>
                                    <th>actions</th>
                                </tr>
                                </thead>
                                <tbody>
                                    <tr>
                                        <td style={{"width": "500px"}}><InputField small /></td>
                                        <td><CheckField small /></td>
                                        <td><CheckField small /></td>
                                        <td><CheckField small /></td>
                                        <td><CheckField small /></td>
                                        <td><CheckField small /></td>
                                        <td style={{"width": "70px"}}><NumericField small /></td>
                                        <td style={{"width": "70px"}}><NumericField small /></td>
                                        <td><ChoiceField small keys={[0, 1, 2]} values={["both", "c->s", "s->c"]} value="both" /></td>
                                        <td><Button  variant="green" size="sm">add</Button></td>
                                    </tr>
                                </tbody>
                            </Table>
                        </div>

                        <ButtonField name="add_rule" variant="green" bordered />
                        <br />
                        <ButtonField name="add_rule" small color="red"/>
                        <br />
                        <ButtonField name="add_rule" bordered border={"green"} />
                    </div>
                </div>


            </div>
        );
    }

}

export default RulePane;