/* * 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 {Form} from "react-bootstrap"; import backend from "../../backend"; import dispatcher from "../../dispatcher"; import {dateTimeToTime, durationBetween, formatSize} from "../../utils"; import ButtonField from "../fields/ButtonField"; import "./Connection.scss"; import CopyLinkPopover from "./CopyLinkPopover"; import LinkPopover from "./LinkPopover"; const classNames = require("classnames"); class Connection extends Component { state = { update: false }; 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}); }); } }; 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 commentPopoverContent =
Click to {conn.comment.length > 0 ? "edit" : "add"} comment {conn.comment && }
; return ( 0})}> dispatcher.dispatch("connections_filters", {"service_port": conn["port_dst"].toString()})}/> {conn["ip_src"]} {conn["port_src"]} {conn["ip_dst"]} {conn["port_dst"]} {durationBetween(startedAt, closedAt)} {formatSize(conn["client_bytes"])} {formatSize(conn["server_bytes"])} this.handleAction("mark")}>!!} content={Mark this connection} placement="right"/> this.handleAction("comment")}>@} content={commentPopoverContent} placement="right"/> ); } } export default Connection;