import React, { useState } from "react"; import { Container, Box, TextField, Switch, Typography, Button, CircularProgress, Paper, } from "@mui/material"; import { toast } from "react-toastify"; import theme from '../theme.jsx'; import DetectionRuleCard from "../components/DetectionRuleCard.jsx"; const handleDirectoryChange = (folderDisabled, setFolderDisabled, globalUrl, isTenzirActive) => { if (!isTenzirActive) { toast.warn("Connect to siem first for global enable/disable to work"); return; } const action = folderDisabled ? "enable_folder" : "disable_folder"; const url = `${globalUrl}/api/v1/detections/${action}`; fetch(url, { method: "PUT", credentials: "include", headers: { "Content-Type": "application/json", }, }) .then((response) => response.json().then((responseJson) => { if (responseJson["success"] === true) { if (action === "enable_folder") setFolderDisabled(false); else setFolderDisabled(true); } else { //toast(`failed to disable rule`); } }) ) .catch((error) => { console.log(`Error in ${action} the rule: `, error); toast(`An error occurred while ${action} the rule`); }); }; const Detection = (props) => { const { globalUrl, ruleInfo, folderDisabled, setFolderDisabled, isTenzirActive, detectionInfo } = props; const [searchQuery, setSearchQuery] = useState(""); const [loading, setLoading] = useState(false); const handleConnectClick = () => { if (isTenzirActive) { return } if (detectionInfo.category === undefined || detectionInfo.category === null) { toast.warn("Detection category not found. Please try again or contact support@shuffler.io if you think this is a bug.") return } setLoading(true); const url = `${globalUrl}/api/v1/detections/${detectionInfo?.category}/connect`; fetch(url, { method: "GET", credentials: "include", headers: { "Content-Type": "application/json", }, }) .then((response) => response.json().then((responseJson) => { if (responseJson["success"] === true) { setTimeout(() => { setLoading(false); window.location.reload(); }, 15000); } else { if (responseJson.reason !== undefined && responseJson.reason !== null) { toast(responseJson.reason) } else { toast(`Failed to connect to ${detectionInfo?.category}`); } if (responseJson.action !== undefined && responseJson.actio !== null && responseJson.action.length > 0) { //if (responseJson.action === "environment_create") { // navigate("/admin?tab=environments") //} } setLoading(false); } }) ) .catch((error) => { setLoading(false); console.log(`Error in connecting to ${detectionInfo?.category}: `, error); toast(`An error occurred while connecting to ${detectionInfo?.category}`); }); } const filteredRules = ruleInfo === "default" ? [] : ruleInfo?.filter((rule) => rule.title.toLowerCase().includes(searchQuery.toLowerCase()) || rule.description.toLowerCase().includes(searchQuery.toLowerCase()) ) return ( {detectionInfo?.name} ({filteredRules?.length}) setSearchQuery(e.target.value)} /> {/* { uploadFiles(event.target.files); }} /> */} Global disable/enable handleDirectoryChange(folderDisabled, setFolderDisabled, globalUrl, isTenzirActive) } /> {filteredRules?.length > 0 ? filteredRules.map((rule, index) => { console.log("RULE CARD: ", rule); return ( ) }) : null } ); }; export default Detection;