import React, {Component} from 'react'; import './PcapPane.scss'; import './common.scss'; import Table from "react-bootstrap/Table"; import backend from "../../backend"; import {createCurlCommand, dateTimeToTime, durationBetween, formatSize} from "../../utils"; import InputField from "../fields/InputField"; import CheckField from "../fields/CheckField"; import TextField from "../fields/TextField"; import ButtonField from "../fields/ButtonField"; import LinkPopover from "../objects/LinkPopover"; import dispatcher from "../../dispatcher"; class PcapPane extends Component { state = { sessions: [], isUploadFileValid: true, isUploadFileFocused: false, uploadFlushAll: false, isFileValid: true, isFileFocused: false, fileValue: "", processFlushAll: false, deleteOriginalFile: false }; componentDidMount() { this.loadSessions(); dispatcher.register("notifications", payload => { if (payload.event === "pcap.upload" || payload.event === "pcap.file") { this.loadSessions(); } }); document.title = "caronte:~/pcaps$"; } loadSessions = () => { backend.get("/api/pcap/sessions") .then(res => this.setState({sessions: res.json, sessionsStatusCode: res.status})) .catch(res => this.setState({ sessions: res.json, sessionsStatusCode: res.status, sessionsResponse: JSON.stringify(res.json) })); }; uploadPcap = () => { if (this.state.uploadSelectedFile == null || !this.state.isUploadFileValid) { this.setState({isUploadFileFocused: true}); return; } const formData = new FormData(); formData.append("file", this.state.uploadSelectedFile); formData.append("flush_all", this.state.uploadFlushAll); backend.postFile("/api/pcap/upload", formData).then(res => { this.setState({ uploadStatusCode: res.status, uploadResponse: JSON.stringify(res.json) }); this.resetUpload(); this.loadSessions(); }).catch(res => this.setState({ uploadStatusCode: res.status, uploadResponse: JSON.stringify(res.json) }) ); }; processPcap = () => { if (this.state.fileValue === "" || !this.state.isFileValid) { this.setState({isFileFocused: true}); return; } backend.post("/api/pcap/file", { file: this.state.fileValue, flush_all: this.state.processFlushAll, delete_original_file: this.state.deleteOriginalFile }).then(res => { this.setState({ processStatusCode: res.status, processResponse: JSON.stringify(res.json) }); this.resetProcess(); this.loadSessions(); }).catch(res => this.setState({ processStatusCode: res.status, processResponse: JSON.stringify(res.json) }) ); }; resetUpload = () => { this.setState({ isUploadFileValid: true, isUploadFileFocused: false, uploadFlushAll: false, uploadSelectedFile: null }); }; resetProcess = () => { this.setState({ isFileValid: true, isFileFocused: false, fileValue: "", processFlushAll: false, deleteOriginalFile: false, }); }; render() { let sessions = this.state.sessions.map(s =>
id | started_at | duration | size | processed_packets | invalid_packets | packets_per_service | actions |
---|