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 "./objects/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;