diff --git a/apps/zui/src/domain/configurations/plugin-api.ts b/apps/zui/src/domain/configurations/plugin-api.ts index a545051788..ca00266b74 100644 --- a/apps/zui/src/domain/configurations/plugin-api.ts +++ b/apps/zui/src/domain/configurations/plugin-api.ts @@ -1,12 +1,8 @@ import ConfigPropValues from "src/js/state/ConfigPropValues" import {Store} from "src/js/state/types" +import {onStateChange} from "src/core/on-state-change" -export type ConfigItemType = - | "file" - | "string" - | "directory" - | "boolean" - | "char" +export type ConfigItemType = "file" | "string" | "folder" | "boolean" | "char" export type ConfigItem = { name: string @@ -56,4 +52,8 @@ export class ConfigurationsApi { this.set(config.name, prop, config.properties[prop].defaultValue) } } + + watch(namespace: string, name: string, onChange: (val: any) => void) { + onStateChange(this.store, ConfigPropValues.get(namespace, name), onChange) + } } diff --git a/apps/zui/src/plugins/brimcap/config.ts b/apps/zui/src/plugins/brimcap/config.ts index e14c81707e..4eb64d5eb3 100644 --- a/apps/zui/src/plugins/brimcap/config.ts +++ b/apps/zui/src/plugins/brimcap/config.ts @@ -1,2 +1,3 @@ export const pluginNamespace = "brimcap" export const yamlConfigPropName = "yamlConfigPath" +export const suricataLocalRulesPropName = "suricataLocalRulesPath" diff --git a/apps/zui/src/plugins/brimcap/configurations.ts b/apps/zui/src/plugins/brimcap/configurations.ts index 52fa765a37..0a73f782a0 100644 --- a/apps/zui/src/plugins/brimcap/configurations.ts +++ b/apps/zui/src/plugins/brimcap/configurations.ts @@ -1,4 +1,8 @@ -import {pluginNamespace, yamlConfigPropName} from "./config" +import { + pluginNamespace, + yamlConfigPropName, + suricataLocalRulesPropName, +} from "./config" import {configurations} from "src/zui" export function activateBrimcapConfigurations() { @@ -16,6 +20,12 @@ export function activateBrimcapConfigurations() { url: "https://github.com/brimdata/brimcap/wiki/Custom-Brimcap-Config", }, }, + [suricataLocalRulesPropName]: { + name: suricataLocalRulesPropName, + type: "folder", + label: "Local Suricata Rules Folder", + defaultValue: "", + }, }, }) } diff --git a/apps/zui/src/plugins/brimcap/suricata/update.ts b/apps/zui/src/plugins/brimcap/suricata/update.ts index d5b44ff60d..443786a220 100644 --- a/apps/zui/src/plugins/brimcap/suricata/update.ts +++ b/apps/zui/src/plugins/brimcap/suricata/update.ts @@ -1,12 +1,20 @@ import {env} from "src/zui" +import {configurations} from "src/zui" import {spawn, ChildProcess} from "child_process" import {error, debug} from "electron-log" +import {pluginNamespace, suricataLocalRulesPropName} from "../config" let proc: ChildProcess = null -function updateSuricata() { +function updateSuricata(suricataLocalRulesPath) { const exe = env.getExePath("suricata/suricataupdater") - proc = spawn(exe) + + if (suricataLocalRulesPath) { + proc = spawn(exe, ["--local", suricataLocalRulesPath]) + } else { + proc = spawn(exe) + } + proc .on("error", (e) => { error(`Error updating Suricata rules: ${e.message || e}`) @@ -18,5 +26,11 @@ function updateSuricata() { export function activateSuricataUpdater() { if (env.isTest) return - updateSuricata() + configurations.watch( + pluginNamespace, + suricataLocalRulesPropName, + (suricataLocalRulesPath) => { + updateSuricata(suricataLocalRulesPath) + } + ) } diff --git a/apps/zui/src/views/settings-modal/input.tsx b/apps/zui/src/views/settings-modal/input.tsx index 8e42bd0a7c..fd4a3af481 100644 --- a/apps/zui/src/views/settings-modal/input.tsx +++ b/apps/zui/src/views/settings-modal/input.tsx @@ -3,6 +3,7 @@ import {useSelector} from "react-redux" import {useDispatch} from "src/app/core/state" import ConfigPropValues from "src/js/state/ConfigPropValues" import {SettingProps} from "./section" +import {invoke} from "src/core/invoke" export function Input(props: SettingProps) { const dispatch = useDispatch() @@ -57,6 +58,30 @@ export function Input(props: SettingProps) { /> ) + case "folder": + return ( +
+ + +
+ ) case "string": if (field.enum) { return (