From 44af615b32faf53c04cd38cb63782cf1b1332c94 Mon Sep 17 00:00:00 2001
From: Emiliano Ciavatta
Date: Sat, 26 Sep 2020 12:05:27 +0200
Subject: General refactor
---
frontend/src/components/fields/BooleanField.js | 37 ------
frontend/src/components/fields/BooleanField.scss | 34 -----
frontend/src/components/fields/CheckField.js | 36 +++++
frontend/src/components/fields/CheckField.scss | 35 +++++
frontend/src/components/fields/InputField.js | 75 +++++++++++
frontend/src/components/fields/InputField.scss | 147 +++++++++++++++++++++
frontend/src/components/fields/StringField.js | 66 ---------
frontend/src/components/fields/StringField.scss | 117 ----------------
frontend/src/components/fields/TextField.js | 42 ++++++
frontend/src/components/fields/TextField.scss | 79 +++++++++++
.../components/filters/BooleanConnectionsFilter.js | 6 +-
.../components/filters/StringConnectionsFilter.js | 8 +-
frontend/src/components/panels/PcapPane.js | 86 +++++++++---
frontend/src/components/panels/PcapPane.scss | 14 +-
14 files changed, 501 insertions(+), 281 deletions(-)
delete mode 100644 frontend/src/components/fields/BooleanField.js
delete mode 100644 frontend/src/components/fields/BooleanField.scss
create mode 100644 frontend/src/components/fields/CheckField.js
create mode 100644 frontend/src/components/fields/CheckField.scss
create mode 100644 frontend/src/components/fields/InputField.js
create mode 100644 frontend/src/components/fields/InputField.scss
delete mode 100644 frontend/src/components/fields/StringField.js
delete mode 100644 frontend/src/components/fields/StringField.scss
create mode 100644 frontend/src/components/fields/TextField.js
create mode 100644 frontend/src/components/fields/TextField.scss
(limited to 'frontend/src/components')
diff --git a/frontend/src/components/fields/BooleanField.js b/frontend/src/components/fields/BooleanField.js
deleted file mode 100644
index 06a6da7..0000000
--- a/frontend/src/components/fields/BooleanField.js
+++ /dev/null
@@ -1,37 +0,0 @@
-import React, {Component} from 'react';
-import './BooleanField.scss';
-import {randomClassName} from "../../utils";
-
-const classNames = require('classnames');
-
-class BooleanField extends Component {
-
- constructor(props) {
- super(props);
-
- this.id = `field-${this.props.name || "noname"}-${randomClassName()}`;
- }
-
- render() {
-
- const checked = this.props.checked || false;
- const small = this.props.small || false;
- const name = this.props.name || null;
- const handler = () => {
- if (this.props.onChange) {
- this.props.onChange(!checked);
- }
- };
-
- return (
-
-
-
-
-
-
- );
- }
-}
-
-export default BooleanField;
diff --git a/frontend/src/components/fields/BooleanField.scss b/frontend/src/components/fields/BooleanField.scss
deleted file mode 100644
index 6ec25f7..0000000
--- a/frontend/src/components/fields/BooleanField.scss
+++ /dev/null
@@ -1,34 +0,0 @@
-@import '../../colors.scss';
-
-.boolean-field {
- font-size: 0.9em;
-
- .field-input {
- border-radius: 5px;
- width: fit-content;
- background-color: $color-primary-2;
-
- input {
- display: none;
- }
-
- label {
- margin: 0;
- padding: 6px 15px;
- cursor: pointer;
- }
-
- &:hover {
- background-color: $color-primary-1;
- }
- }
-
- &.field-checked .field-input {
- background-color: $color-primary-4 !important;
- color: $color-primary-3;
- }
-
- &.field-small {
- font-size: 0.8em;
- }
-}
diff --git a/frontend/src/components/fields/CheckField.js b/frontend/src/components/fields/CheckField.js
new file mode 100644
index 0000000..5cceac4
--- /dev/null
+++ b/frontend/src/components/fields/CheckField.js
@@ -0,0 +1,36 @@
+import React, {Component} from 'react';
+import './CheckField.scss';
+import {randomClassName} from "../../utils";
+
+const classNames = require('classnames');
+
+class CheckField extends Component {
+
+ constructor(props) {
+ super(props);
+
+ this.id = `field-${this.props.name || "noname"}-${randomClassName()}`;
+ }
+
+ render() {
+ const checked = this.props.checked || false;
+ const small = this.props.small || false;
+ const name = this.props.name || null;
+ const handler = () => {
+ if (this.props.onChange) {
+ this.props.onChange(!checked);
+ }
+ };
+
+ return (
+
+
+
+
+
+
+ );
+ }
+}
+
+export default CheckField;
diff --git a/frontend/src/components/fields/CheckField.scss b/frontend/src/components/fields/CheckField.scss
new file mode 100644
index 0000000..7b0ac5f
--- /dev/null
+++ b/frontend/src/components/fields/CheckField.scss
@@ -0,0 +1,35 @@
+@import '../../colors.scss';
+
+.check-field {
+ font-size: 0.9em;
+ margin: 5px 0;
+
+ .field-input {
+ border-radius: 5px;
+ width: fit-content;
+ background-color: $color-primary-2;
+
+ input {
+ display: none;
+ }
+
+ label {
+ margin: 0;
+ padding: 6px 15px;
+ cursor: pointer;
+ }
+
+ &:hover {
+ background-color: $color-primary-1;
+ }
+ }
+
+ &.field-checked .field-input {
+ background-color: $color-primary-4 !important;
+ color: $color-primary-3;
+ }
+
+ &.field-small {
+ font-size: 0.8em;
+ }
+}
diff --git a/frontend/src/components/fields/InputField.js b/frontend/src/components/fields/InputField.js
new file mode 100644
index 0000000..af3b3df
--- /dev/null
+++ b/frontend/src/components/fields/InputField.js
@@ -0,0 +1,75 @@
+import React, {Component} from 'react';
+import './InputField.scss';
+import {randomClassName} from "../../utils";
+
+const classNames = require('classnames');
+
+class InputField extends Component {
+
+ constructor(props) {
+ super(props);
+
+ this.id = `field-${this.props.name || "noname"}-${randomClassName()}`;
+ }
+
+ render() {
+ const active = this.props.active || false;
+ const invalid = this.props.invalid || false;
+ const small = this.props.small || false;
+ const inline = this.props.inline || false;
+ const name = this.props.name || null;
+ const value = this.props.value || "";
+ const type = this.props.type || "text";
+ const error = this.props.error || null;
+ const defaultValue = this.props.defaultValue || null;
+ const handler = (e) => {
+ if (this.props.onChange) {
+ if (type === "file") {
+ let file = e.target.files[0];
+ this.props.onChange(file);
+ } else if (e == null) {
+ this.props.onChange("");
+ } else {
+ this.props.onChange(e.target.value);
+ }
+ }
+ };
+ let inputProps = {};
+ if (type !== "file") {
+ inputProps["value"] = value;
+ }
+
+ return (
+
+
+ { name &&
+
+
+
+ }
+
+
+ { type === "file" && }
+
+
+ { type !== "file" && value !== "" &&
+
+ handler(null)}>del
+
+ }
+
+
+ {error &&
+
+ error: {error}
+
+ }
+
+ );
+ }
+}
+
+export default InputField;
diff --git a/frontend/src/components/fields/InputField.scss b/frontend/src/components/fields/InputField.scss
new file mode 100644
index 0000000..cdb8c9f
--- /dev/null
+++ b/frontend/src/components/fields/InputField.scss
@@ -0,0 +1,147 @@
+@import '../../colors.scss';
+
+.input-field {
+ font-size: 0.9em;
+ margin: 5px 0;
+
+ .field-name {
+ label {
+ margin: 0;
+ }
+ }
+
+ .field-input {
+ position: relative;
+
+ .field-value {
+ input, .file-label {
+ background-color: $color-primary-2;
+ width: 100%;
+ border: none;
+ color: $color-primary-4;
+ border-radius: 5px;
+ padding: 7px 10px;
+
+ &:focus {
+ background-color: $color-primary-1;
+ color: $color-primary-4;
+ box-shadow: none;
+ outline: none;
+ }
+
+ &[readonly] {
+ background-color: $color-primary-2;
+ border: none;
+ color: $color-primary-4;
+ }
+
+ &[readonly]:focus {
+ background-color: $color-primary-1;
+ color: $color-primary-4;
+ box-shadow: none;
+ }
+ }
+
+ input[type="file"] {
+ display: none;
+ }
+
+ .file-label {
+ margin: 0;
+ }
+
+ .file-label:after {
+ content: "Browse";
+ position: absolute;
+ right: 0;
+ top: 0;
+ padding: 7px 10px 7px 12px;
+ background-color: $color-primary-1;
+ border-bottom-right-radius: 5px;
+ border-top-right-radius: 5px;
+ }
+ }
+ }
+
+ &.field-active {
+ &.field-inline .field-name {
+ background-color: $color-primary-4 !important;
+ color: $color-primary-3 !important;
+ }
+
+ .field-value input, .field-value .file-label {
+ background-color: $color-primary-4 !important;
+ color: $color-primary-3 !important;
+ }
+
+ .file-label:after {
+ background-color: $color-secondary-4 !important;
+ }
+ }
+
+ &.field-invalid {
+ &.field-inline .field-name {
+ background-color: $color-secondary-2 !important;
+ color: $color-primary-4 !important;
+ }
+
+ .field-value input, .field-value .file-label {
+ background-color: $color-secondary-2 !important;
+ color: $color-primary-4 !important;
+ }
+
+ .file-label:after {
+ background-color: $color-secondary-1 !important;
+ }
+ }
+
+ &.field-small {
+ font-size: 0.8em;
+ }
+
+ &.field-inline .field-wrapper {
+ display: flex;
+
+ .field-name {
+ background-color: $color-primary-2;
+ padding: 6px 7px;
+ border-top-left-radius: 5px;
+ border-bottom-left-radius: 5px;
+ }
+
+ .field-input {
+ width: 100%;
+
+ input, .file-label {
+ border-bottom-left-radius: 0;
+ border-top-left-radius: 0;
+ padding-left: 3px;
+ }
+ }
+
+ &:focus-within .field-name {
+ background-color: $color-primary-1;
+ }
+ }
+
+ .field-clear {
+ position: absolute;
+ right: 8px;
+ top: 8px;
+ z-index: 10;
+ font-size: 0.9em;
+ font-weight: 600;
+ letter-spacing: -0.5px;
+ cursor: pointer;
+ }
+
+ &.field-active .field-clear {
+ color: $color-primary-2;
+ }
+
+ .field-error {
+ padding: 5px 10px;
+ font-size: 0.9em;
+ color: $color-secondary-0;
+ }
+}
diff --git a/frontend/src/components/fields/StringField.js b/frontend/src/components/fields/StringField.js
deleted file mode 100644
index 7781b2d..0000000
--- a/frontend/src/components/fields/StringField.js
+++ /dev/null
@@ -1,66 +0,0 @@
-import React, {Component} from 'react';
-import './StringField.scss';
-import {randomClassName} from "../../utils";
-
-const classNames = require('classnames');
-
-class StringField extends Component {
-
- constructor(props) {
- super(props);
-
- this.id = `field-${this.props.name || "noname"}-${randomClassName()}`;
- }
-
- render() {
-
- const active = this.props.active || false;
- const invalid = this.props.invalid || false;
- const small = this.props.small || false;
- const inline = this.props.inline || false;
- const name = this.props.name || null;
- const value = this.props.value || "";
- const type = this.props.type || "text";
- const error = this.props.error || null;
- const handler = (e) => {
- if (this.props.onChange) {
- if (e == null) {
- this.props.onChange("");
- } else {
- this.props.onChange(e.target.value);
- }
- }
- };
-
- return (
-
-
- { name &&
-
-
-
- }
-
-
-
-
- { value !== "" &&
-
- handler(null)}>del
-
- }
-
-
- {error &&
-
- error: {error}
-
- }
-
- );
- }
-}
-
-export default StringField;
diff --git a/frontend/src/components/fields/StringField.scss b/frontend/src/components/fields/StringField.scss
deleted file mode 100644
index 2523c8d..0000000
--- a/frontend/src/components/fields/StringField.scss
+++ /dev/null
@@ -1,117 +0,0 @@
-@import '../../colors.scss';
-
-.string-field {
- font-size: 0.9em;
-
- .field-name {
- label {
- margin: 0;
- }
- }
-
- .field-input {
- position: relative;
-
- .field-value input {
- background-color: $color-primary-2;
- width: 100%;
- border: none;
- color: $color-primary-4;
- border-radius: 5px;
- padding: 7px 10px;
-
- &:focus {
- background-color: $color-primary-1;
- color: $color-primary-4;
- box-shadow: none;
- outline: none;
- }
-
- &[readonly] {
- background-color: $color-primary-2;
- border: none;
- color: $color-primary-4;
- }
-
- &[readonly]:focus {
- background-color: $color-primary-1;
- color: $color-primary-4;
- box-shadow: none;
- }
- }
- }
-
- &.field-active {
- &.field-inline .field-name {
- background-color: $color-primary-4 !important;
- color: $color-primary-3 !important;
- }
-
- .field-value input {
- background-color: $color-primary-4 !important;
- color: $color-primary-3 !important;
- }
- }
-
- &.field-invalid {
- &.field-inline .field-name {
- background-color: $color-secondary-2 !important;
- color: $color-primary-4 !important;
- }
-
- .field-value input {
- background-color: $color-secondary-2 !important;
- color: $color-primary-4 !important;
- }
- }
-
- &.field-small {
- font-size: 0.8em;
- }
-
- &.field-inline .field-wrapper {
- display: flex;
-
- .field-name {
- background-color: $color-primary-2;
- padding: 6px 7px;
- border-top-left-radius: 5px;
- border-bottom-left-radius: 5px;
- }
-
- .field-input {
- width: 100%;
-
- input {
- border-bottom-left-radius: 0;
- border-top-left-radius: 0;
- padding-left: 3px;
- }
- }
-
- &:focus-within .field-name {
- background-color: $color-primary-1;
- }
- }
-
- .field-clear {
- position: absolute;
- right: 8px;
- top: 8px;
- z-index: 10;
- font-size: 0.9em;
- font-weight: 600;
- letter-spacing: -0.5px;
- cursor: pointer;
- }
-
- &.field-active .field-clear {
- color: $color-primary-2;
- }
-
- .field-error {
- padding: 5px 10px;
- font-size: 0.9em;
- color: $color-secondary-0;
- }
-}
diff --git a/frontend/src/components/fields/TextField.js b/frontend/src/components/fields/TextField.js
new file mode 100644
index 0000000..86b98ed
--- /dev/null
+++ b/frontend/src/components/fields/TextField.js
@@ -0,0 +1,42 @@
+import React, {Component} from 'react';
+import './TextField.scss';
+import {randomClassName} from "../../utils";
+
+const classNames = require('classnames');
+
+class TextField extends Component {
+
+ constructor(props) {
+ super(props);
+
+ this.id = `field-${this.props.name || "noname"}-${randomClassName()}`;
+ }
+
+ render() {
+ const name = this.props.name || null;
+ const error = this.props.error || null;
+ const rows = this.props.rows || 3;
+
+ const handler = (e) => {
+ if (this.props.onChange) {
+ if (e == null) {
+ this.props.onChange("");
+ } else {
+ this.props.onChange(e.target.value);
+ }
+ }
+ };
+
+ return (
+
+ {name &&
}
+
+ {error &&
error: {error}
}
+
+ );
+ }
+}
+
+export default TextField;
diff --git a/frontend/src/components/fields/TextField.scss b/frontend/src/components/fields/TextField.scss
new file mode 100644
index 0000000..606f537
--- /dev/null
+++ b/frontend/src/components/fields/TextField.scss
@@ -0,0 +1,79 @@
+@import '../../colors.scss';
+
+.text-field {
+ font-size: 0.9em;
+ margin: 5px 0;
+
+ label {
+ display: block;
+ margin: 0;
+ }
+
+ textarea {
+ background-color: $color-primary-2;
+ width: 100%;
+ border: none;
+ color: $color-primary-4;
+ border-radius: 5px;
+ padding: 7px 10px;
+ resize: none;
+
+ &:focus {
+ background-color: $color-primary-1;
+ color: $color-primary-4;
+ box-shadow: none;
+ outline: none;
+ }
+
+ &[readonly] {
+ background-color: $color-primary-2;
+ border: none;
+ color: $color-primary-4;
+ }
+
+ &[readonly]:focus {
+ background-color: $color-primary-1;
+ color: $color-primary-4;
+ box-shadow: none;
+ }
+ }
+
+ &.field-active {
+ textarea {
+ background-color: $color-primary-4 !important;
+ color: $color-primary-3 !important;
+ }
+ }
+
+ &.field-invalid {
+ textarea {
+ background-color: $color-secondary-2 !important;
+ color: $color-primary-4 !important;
+ }
+ }
+
+ &.field-small {
+ font-size: 0.8em;
+ }
+
+ .field-clear {
+ position: absolute;
+ right: 8px;
+ top: 8px;
+ z-index: 10;
+ font-size: 0.9em;
+ font-weight: 600;
+ letter-spacing: -0.5px;
+ cursor: pointer;
+ }
+
+ &.field-active .field-clear {
+ color: $color-primary-2;
+ }
+
+ .field-error {
+ padding: 5px 10px;
+ font-size: 0.9em;
+ color: $color-secondary-0;
+ }
+}
diff --git a/frontend/src/components/filters/BooleanConnectionsFilter.js b/frontend/src/components/filters/BooleanConnectionsFilter.js
index 490d185..4c5a78a 100644
--- a/frontend/src/components/filters/BooleanConnectionsFilter.js
+++ b/frontend/src/components/filters/BooleanConnectionsFilter.js
@@ -1,7 +1,7 @@
import React, {Component} from 'react';
import {withRouter} from "react-router-dom";
import {Redirect} from "react-router";
-import BooleanField from "../fields/BooleanField";
+import CheckField from "../fields/CheckField";
class BooleanConnectionsFilter extends Component {
@@ -56,8 +56,8 @@ class BooleanConnectionsFilter extends Component {
return (
-
+
{redirect}
);
diff --git a/frontend/src/components/filters/StringConnectionsFilter.js b/frontend/src/components/filters/StringConnectionsFilter.js
index 0d7f063..a304198 100644
--- a/frontend/src/components/filters/StringConnectionsFilter.js
+++ b/frontend/src/components/filters/StringConnectionsFilter.js
@@ -1,7 +1,7 @@
import React, {Component} from 'react';
import {withRouter} from "react-router-dom";
import {Redirect} from "react-router";
-import StringField from "../fields/StringField";
+import InputField from "../fields/InputField";
class StringConnectionsFilter extends Component {
@@ -114,9 +114,9 @@ class StringConnectionsFilter extends Component {
return (
-
+
{redirect}
);
diff --git a/frontend/src/components/panels/PcapPane.js b/frontend/src/components/panels/PcapPane.js
index 9f3bc19..701edf2 100644
--- a/frontend/src/components/panels/PcapPane.js
+++ b/frontend/src/components/panels/PcapPane.js
@@ -2,10 +2,11 @@ import React, {Component} from 'react';
import './PcapPane.scss';
import Table from "react-bootstrap/Table";
import backend from "../../backend";
-import {formatSize, timestampToTime2} from "../../utils";
-import {Container, Row, Col, Form} from "react-bootstrap";
-import StringField from "../fields/StringField";
-import BooleanField from "../fields/BooleanField";
+import {createCurlCommand, formatSize, timestampToTime2} from "../../utils";
+import {Button, Col, Container, Form, Row} from "react-bootstrap";
+import InputField from "../fields/InputField";
+import CheckField from "../fields/CheckField";
+import TextField from "../fields/TextField";
class PcapPane extends Component {
@@ -14,10 +15,17 @@ class PcapPane extends Component {
this.state = {
sessions: [],
- test: false
+ isFileValid: true,
+ isFileFocused: false,
+ selectedFile: null,
+ uploadFlushAll: false,
+ uploadStatusCode: null,
+ uploadOutput: null
};
this.loadSessions = this.loadSessions.bind(this);
+ this.handleFileChange = this.handleFileChange.bind(this);
+ this.handleUploadPcap = this.handleUploadPcap.bind(this);
}
componentDidMount() {
@@ -28,6 +36,34 @@ class PcapPane extends Component {
backend.get("/api/pcap/sessions").then(res => this.setState({sessions: res}));
}
+ handleFileChange(file) {
+ this.setState({
+ isFileValid: file != null && file.type.endsWith("pcap"),
+ isFileFocused: false,
+ selectedFile: file
+ });
+ }
+
+ handleUploadPcap() {
+ if (this.state.selectedFile == null || !this.state.isFileValid) {
+ this.setState({isFileFocused: true});
+ return;
+ }
+
+ const formData = new FormData();
+ formData.append(
+ "file",
+ this.state.selectedFile
+ );
+
+ backend.postFile("/api/pcap/upload", formData).then(response =>
+ response.json().then(result => this.setState({
+ uploadStatusCode: response.status + " " + response.statusText,
+ uploadOutput: JSON.stringify(result)
+ }))
+ );
+ }
+
render() {
let sessions = this.state.sessions.map(s =>
@@ -38,10 +74,20 @@ class PcapPane extends Component {
{s["processed_packets"]} |
{s["invalid_packets"]} |
undefined |
- download |
+ download
+ |
);
+ const uploadOutput = this.state.uploadOutput != null ? this.state.uploadOutput :
+ createCurlCommand("pcap/upload", "POST", null, {
+ file: "@" + ((this.state.selectedFile != null && this.state.isFileValid) ? this.state.selectedFile.name :
+ "invalid.pcap"),
+ flush_all: this.state.uploadFlushAll
+ })
+ ;
+
return (
@@ -77,19 +123,25 @@ class PcapPane extends Component {
POST /api/pcap/upload
-
+ {this.state.uploadStatusCode}
-
-
-
-
-
this.setState({test: v})} />
-
+
+
+
+
+ options:
+ this.setState({uploadFlushAll: v})}/>
+
+
+
+
+
@@ -110,8 +162,6 @@ class PcapPane extends Component {
-
-
diff --git a/frontend/src/components/panels/PcapPane.scss b/frontend/src/components/panels/PcapPane.scss
index 3df87f5..ce28227 100644
--- a/frontend/src/components/panels/PcapPane.scss
+++ b/frontend/src/components/panels/PcapPane.scss
@@ -38,8 +38,6 @@
padding: 10px;
}
-
-
th {
background-color: $color-primary-2;
border-top: 3px solid $color-primary-3;
@@ -50,6 +48,18 @@
padding: 5px;
}
+ .upload-actions {
+ display: flex;
+ align-items: flex-end;
+ margin-bottom: 20px;
+ }
+
+ .upload-options {
+ flex: 1;
+ span {
+ font-size: 0.9em;
+ }
+ }
}
\ No newline at end of file
--
cgit v1.2.3-70-g09d2