From d203f3c7e3bcaa20895c0f32f348cd1513ae9876 Mon Sep 17 00:00:00 2001 From: Emiliano Ciavatta Date: Thu, 8 Oct 2020 22:17:04 +0200 Subject: Frontend folder structure refactor --- frontend/src/components/objects/Connection.js | 145 +++++++++++++++++++++ frontend/src/components/objects/Connection.scss | 68 ++++++++++ .../components/objects/ConnectionMatchedRules.js | 46 +++++++ .../components/objects/ConnectionMatchedRules.scss | 23 ++++ frontend/src/components/objects/MessageAction.js | 68 ++++++++++ frontend/src/components/objects/MessageAction.scss | 8 ++ 6 files changed, 358 insertions(+) create mode 100644 frontend/src/components/objects/Connection.js create mode 100644 frontend/src/components/objects/Connection.scss create mode 100644 frontend/src/components/objects/ConnectionMatchedRules.js create mode 100644 frontend/src/components/objects/ConnectionMatchedRules.scss create mode 100644 frontend/src/components/objects/MessageAction.js create mode 100644 frontend/src/components/objects/MessageAction.scss (limited to 'frontend/src/components/objects') diff --git a/frontend/src/components/objects/Connection.js b/frontend/src/components/objects/Connection.js new file mode 100644 index 0000000..5e2beba --- /dev/null +++ b/frontend/src/components/objects/Connection.js @@ -0,0 +1,145 @@ +/* + * This file is part of caronte (https://github.com/eciavatta/caronte). + * Copyright (c) 2020 Emiliano Ciavatta. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +import React, {Component} from 'react'; +import './Connection.scss'; +import {Form, OverlayTrigger, Popover} from "react-bootstrap"; +import backend from "../../backend"; +import {dateTimeToTime, durationBetween, formatSize} from "../../utils"; +import ButtonField from "../fields/ButtonField"; +import LinkPopover from "./LinkPopover"; + +const classNames = require('classnames'); + +class Connection extends Component { + + constructor(props) { + super(props); + this.state = { + update: false, + copiedMessage: false + }; + + this.copyTextarea = React.createRef(); + this.handleAction = this.handleAction.bind(this); + } + + handleAction(name) { + if (name === "hide") { + const enabled = !this.props.data.hidden; + backend.post(`/api/connections/${this.props.data.id}/${enabled ? "hide" : "show"}`) + .then(_ => { + this.props.onEnabled(!enabled); + this.setState({update: true}); + }); + } + if (name === "mark") { + const marked = this.props.data.marked; + backend.post(`/api/connections/${this.props.data.id}/${marked ? "unmark" : "mark"}`) + .then(_ => { + this.props.onMarked(!marked); + this.setState({update: true}); + }); + } + if (name === "copy") { + this.copyTextarea.current.select(); + document.execCommand('copy'); + this.setState({copiedMessage: true}); + setTimeout(() => this.setState({copiedMessage: false}), 3000); + } + } + + render() { + let conn = this.props.data; + let serviceName = "/dev/null"; + let serviceColor = "#0f192e"; + if (this.props.services[conn["port_dst"]]) { + const service = this.props.services[conn["port_dst"]]; + serviceName = service.name; + serviceColor = service.color; + } + let startedAt = new Date(conn["started_at"]); + let closedAt = new Date(conn["closed_at"]); + let processedAt = new Date(conn["processed_at"]); + let timeInfo =
+ Started at {startedAt.toLocaleDateString() + " " + startedAt.toLocaleTimeString()}
+ Processed at {processedAt.toLocaleDateString() + " " + processedAt.toLocaleTimeString()}
+ Closed at {closedAt.toLocaleDateString() + " " + closedAt.toLocaleTimeString()} +
; + + const popoverFor = function (name, content) { + return + + {content} + + ; + }; + + const commentPopoverContent =
+ Click to {conn.comment.length > 0 ? "edit" : "add"} comment + {conn.comment && } +
; + + const copyPopoverContent =
+ {this.state.copiedMessage ? Copied! : + Click to copy the connection id} + +
; + + return ( + 0})}> + + + this.props.addServicePortFilter(conn["port_dst"])}/> + + + {conn["ip_src"]} + {conn["port_src"]} + {conn["ip_dst"]} + {conn["port_dst"]} + + + + {durationBetween(startedAt, closedAt)} + {formatSize(conn["client_bytes"])} + {formatSize(conn["server_bytes"])} + + Mark this connection)}> + this.handleAction("mark")}>!! + + + this.handleAction("comment")}>@ + + + this.handleAction("copy")}># + + + + ); + } + +} + +export default Connection; diff --git a/frontend/src/components/objects/Connection.scss b/frontend/src/components/objects/Connection.scss new file mode 100644 index 0000000..3b9f479 --- /dev/null +++ b/frontend/src/components/objects/Connection.scss @@ -0,0 +1,68 @@ +@import "../../colors"; + +.connection { + border-top: 3px solid $color-primary-3; + border-bottom: 3px solid $color-primary-3; + background-color: $color-primary-0; + + td { + vertical-align: middle; + } + + .connection-service { + .btn { + width: 100%; + } + + .btn:hover { + color: $color-primary-4; + background-color: $color-primary-1 !important; + } + } + + .connection-icon { + font-size: 18px; + font-weight: 600; + margin-right: 6px; + cursor: pointer; + } + + .connection-icon.icon-enabled { + color: $color-secondary-2; + } + + &:hover { + background-color: $color-primary-2; + } + + &.connection-selected { + background-color: $color-primary-2; + } + + &.has-matched-rules { + border-bottom: 0; + } + + .link-popover { + font-weight: 400; + } +} + +.connection-popover { + border: none; + background-color: $color-primary-4; + + .popover-body { + color: $color-primary-1; + + textarea { + font-size: 12px; + width: 200px; + background-color: $color-primary-3; + } + } + + .arrow::after { + border-right-color: $color-primary-4; + } +} diff --git a/frontend/src/components/objects/ConnectionMatchedRules.js b/frontend/src/components/objects/ConnectionMatchedRules.js new file mode 100644 index 0000000..73d5c5d --- /dev/null +++ b/frontend/src/components/objects/ConnectionMatchedRules.js @@ -0,0 +1,46 @@ +/* + * This file is part of caronte (https://github.com/eciavatta/caronte). + * Copyright (c) 2020 Emiliano Ciavatta. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +import React, {Component} from 'react'; +import './ConnectionMatchedRules.scss'; +import ButtonField from "../fields/ButtonField"; + +class ConnectionMatchedRules extends Component { + + constructor(props) { + super(props); + this.state = { + }; + } + + render() { + const matchedRules = this.props.matchedRules.map(mr => { + const rule = this.props.rules.find(r => r.id === mr); + return this.props.addMatchedRulesFilter(rule.id)} name={rule.name} + color={rule.color} small />; + }); + + return ( + + matched_rules: + {matchedRules} + + ); + } +} + +export default ConnectionMatchedRules; diff --git a/frontend/src/components/objects/ConnectionMatchedRules.scss b/frontend/src/components/objects/ConnectionMatchedRules.scss new file mode 100644 index 0000000..f46a914 --- /dev/null +++ b/frontend/src/components/objects/ConnectionMatchedRules.scss @@ -0,0 +1,23 @@ +@import "../../colors"; + +.connection-matches { + background-color: $color-primary-0; + + .rule-buttons { + padding: 0; + } + + .button-field { + display: inline-block; + margin-right: 5px; + + button { + font-size: 0.8em; + padding: 2px 10px; + } + } + + .row-label { + font-size: 0.8em; + } +} diff --git a/frontend/src/components/objects/MessageAction.js b/frontend/src/components/objects/MessageAction.js new file mode 100644 index 0000000..9f199b7 --- /dev/null +++ b/frontend/src/components/objects/MessageAction.js @@ -0,0 +1,68 @@ +/* + * This file is part of caronte (https://github.com/eciavatta/caronte). + * Copyright (c) 2020 Emiliano Ciavatta. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +import React, {Component} from 'react'; +import './MessageAction.scss'; +import {Modal} from "react-bootstrap"; +import TextField from "../fields/TextField"; +import ButtonField from "../fields/ButtonField"; + +class MessageAction extends Component { + + constructor(props) { + super(props); + this.state = { + copyButtonText: "copy" + }; + this.actionValue = React.createRef(); + this.copyActionValue = this.copyActionValue.bind(this); + } + + copyActionValue() { + this.actionValue.current.select(); + document.execCommand('copy'); + this.setState({copyButtonText: "copied!"}); + setTimeout(() => this.setState({copyButtonText: "copy"}), 3000); + } + + render() { + return ( + + + + {this.props.actionName} + + + + + + + + + + + ); + } +} + +export default MessageAction; diff --git a/frontend/src/components/objects/MessageAction.scss b/frontend/src/components/objects/MessageAction.scss new file mode 100644 index 0000000..996007b --- /dev/null +++ b/frontend/src/components/objects/MessageAction.scss @@ -0,0 +1,8 @@ +@import "../../colors"; + +.message-action-value { + font-size: 13px; + padding: 15px; + color: $color-primary-4; + background-color: $color-primary-2; +} -- cgit v1.2.3-70-g09d2