Skip to content

Commit

Permalink
Add Setting for pointing at local Suricata rules (#3049)
Browse files Browse the repository at this point in the history
  • Loading branch information
philrz authored Apr 19, 2024
1 parent a9d64be commit f1aef59
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 10 deletions.
12 changes: 6 additions & 6 deletions apps/zui/src/domain/configurations/plugin-api.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
}
}
1 change: 1 addition & 0 deletions apps/zui/src/plugins/brimcap/config.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const pluginNamespace = "brimcap"
export const yamlConfigPropName = "yamlConfigPath"
export const suricataLocalRulesPropName = "suricataLocalRulesPath"
12 changes: 11 additions & 1 deletion apps/zui/src/plugins/brimcap/configurations.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import {pluginNamespace, yamlConfigPropName} from "./config"
import {
pluginNamespace,
yamlConfigPropName,
suricataLocalRulesPropName,
} from "./config"
import {configurations} from "src/zui"

export function activateBrimcapConfigurations() {
Expand All @@ -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: "",
},
},
})
}
20 changes: 17 additions & 3 deletions apps/zui/src/plugins/brimcap/suricata/update.ts
Original file line number Diff line number Diff line change
@@ -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}`)
Expand All @@ -18,5 +26,11 @@ function updateSuricata() {

export function activateSuricataUpdater() {
if (env.isTest) return
updateSuricata()
configurations.watch(
pluginNamespace,
suricataLocalRulesPropName,
(suricataLocalRulesPath) => {
updateSuricata(suricataLocalRulesPath)
}
)
}
25 changes: 25 additions & 0 deletions apps/zui/src/views/settings-modal/input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -57,6 +58,30 @@ export function Input(props: SettingProps) {
/>
</div>
)
case "folder":
return (
<div className="flex items-center gap-s">
<input
key={value}
type="text"
defaultValue={value}
onBlur={onChange}
placeholder="None"
/>
<button
onClick={async () => {
const {canceled, filePaths} = await invoke("openDirectory")
if (!canceled && filePaths[0]) {
update(filePaths[0])
}
}}
className="button"
type="button"
>
Choose Folder
</button>
</div>
)
case "string":
if (field.enum) {
return (
Expand Down

0 comments on commit f1aef59

Please sign in to comment.