adding a select option for the sigma rules

This commit is contained in:
satti-hari-krishna-reddy
2024-06-24 20:28:32 +05:30
parent e24550a641
commit 073b9f3f79
+94 -40
View File
@@ -534,6 +534,7 @@ const AngularWorkflow = (defaultprops) => {
const [listCache, setListCache] = React.useState([]); const [listCache, setListCache] = React.useState([]);
const [selectedOption, setSelectedOption] = React.useState(""); const [selectedOption, setSelectedOption] = React.useState("");
const [tenzirConfigModalOpen, setTenzirConfigModalOpen] = React.useState(false); const [tenzirConfigModalOpen, setTenzirConfigModalOpen] = React.useState(false);
const [rules, setRules] = React.useState([]);
const [distributedFromParent, setDistributedFromParent] = React.useState("") const [distributedFromParent, setDistributedFromParent] = React.useState("")
const [suborgWorkflows, setSuborgWorkflows] = React.useState([]) const [suborgWorkflows, setSuborgWorkflows] = React.useState([])
@@ -992,6 +993,12 @@ const releaseToConnectLabel = "Release to Connect"
} }
}, [authenticationModalOpen]) }, [authenticationModalOpen])
useEffect(() =>{
if (tenzirConfigModalOpen === false) return;
getSigmaInfo();
},[tenzirConfigModalOpen])
const listOrgCache = (orgId) => { const listOrgCache = (orgId) => {
fetch(`${globalUrl}/api/v1/orgs/${orgId}/list_cache`, { fetch(`${globalUrl}/api/v1/orgs/${orgId}/list_cache`, {
method: "GET", method: "GET",
@@ -8308,6 +8315,32 @@ const releaseToConnectLabel = "Release to Connect"
}); });
}; };
const getSigmaInfo = () => {
const url = globalUrl + "/api/v1/files/detection/sigma_rules";
fetch(url, {
method: "GET",
credentials: "include",
headers: {
"Content-Type": "application/json",
},
})
.then((response) =>
response.json().then((responseJson) => {
if (responseJson["success"] === false) {
toast("Failed to get sigma rules");
} else {
setRules(responseJson.sigma_info);
}
})
)
.catch((error) => {
console.log("Error in getting sigma files: ", error);
toast("An error occurred while fetching sigma rules");
});
};
const parsedHeight = isMobile ? bodyHeight - appBarSize * 4 : bodyHeight - appBarSize - 50 const parsedHeight = isMobile ? bodyHeight - appBarSize * 4 : bodyHeight - appBarSize - 50
const appViewStyle = { const appViewStyle = {
marginLeft: 5, marginLeft: 5,
@@ -21160,7 +21193,38 @@ const releaseToConnectLabel = "Release to Connect"
</Dialog> </Dialog>
) : null; ) : null;
const tenzirConfigModal = tenzirConfigModalOpen ? ( const tenzirConfigModal = () => {
if (!tenzirConfigModalOpen) return null;
const [loading, setLoading] = useState(true);
const [selectedRules, setSelectedRules] = useState([]);
const handleRuleChange = (event) => {
setSelectedRules(event.target.value);
};
const handleSelectAll = () => {
const allEnabledRules = rules.filter(rule => rule.is_enabled).map(rule => rule.file_id);
setSelectedRules(allEnabledRules);
};
const handleClose = () => {
setTenzirConfigModalOpen(false);
};
const handleSubmit = () => {
const selectedRuleFiles = rules
.filter(rule => selectedRules.includes(rule.file_id));
console.log('Selected Rule Files:', selectedRuleFiles);
console.log('Selected Rule File Names:', selectedRuleFiles.map(rule => rule.file_id));
setTenzirConfigModalOpen(false);
};
const enabledSigmaInfo = rules.filter(rule => rule.is_enabled);
<Dialog <Dialog
PaperComponent={PaperComponent} PaperComponent={PaperComponent}
hideBackdrop={true} hideBackdrop={true}
@@ -21182,6 +21246,9 @@ const releaseToConnectLabel = "Release to Connect"
}, },
}} }}
> >
{loading ? (
<CircularProgress />
) : (
<div <div
style={{ style={{
flex: 2, flex: 2,
@@ -21193,45 +21260,34 @@ const releaseToConnectLabel = "Release to Connect"
}} }}
> >
<DialogContent> <DialogContent>
{selectedOption === 'sigmaRule' && (
<b>command</b> <>
<TextField <FormControl fullWidth>
id="sigma" <InputLabel>Select Sigma Rules</InputLabel>
style={{ <Select
backgroundColor: theme.palette.inputColor, multiple
borderRadius: theme.palette.borderRadius, value={selectedRules}
}} onChange={handleRuleChange}
InputProps={{ renderValue={(selected) => selected.join(', ')}
style: {}, >
}} {enabledSigmaInfo.map(rule => (
fullWidth <MenuItem key={rule.file_id} value={rule.file_id}>
color="primary" <Checkbox checked={selectedRules.indexOf(rule.file_id) > -1} />
placeholder={"command"} <ListItemText primary={rule.title} />
defaultValue={(selectedTrigger?.parameters?.find(param => param.name === "command")?.value) || ''} </MenuItem>
/> ))}
</Select>
</FormControl>
<Button onClick={handleSelectAll}>Select All</Button>
</>
)}
</DialogContent> </DialogContent>
<DialogActions> <DialogActions>
<Button <Button style={{ borderRadius: "0px" }} onClick={handleClose} color="primary">Cancel</Button>
style={{ borderRadius: "0px" }} <Button style={{ borderRadius: "0px" }} onClick={handleSubmit} color="primary">Submit</Button>
onClick={() => {
setTenzirConfigModalOpen(false);
}}
color="primary"
>
Cancel
</Button>
<Button
style={{ borderRadius: "0px" }}
onClick={() => {
handleCommandSubmit(selectedTrigger);
}}
color="primary"
>
Submit
</Button>
</DialogActions> </DialogActions>
</div> </div>
)}
<IconButton <IconButton
style={{ style={{
@@ -21241,14 +21297,12 @@ const releaseToConnectLabel = "Release to Connect"
right: 18, right: 18,
color: "grey", color: "grey",
}} }}
onClick={() => { onClick={handleClose}
setTenzirConfigModalOpen(false);
}}
> >
<CloseIcon /> <CloseIcon />
</IconButton> </IconButton>
</Dialog> </Dialog>
) : null; }