From 9a368cac2e08fb22841ddfce2da18434419f55b9 Mon Sep 17 00:00:00 2001 From: Laurence Jones Date: Wed, 3 Jan 2024 09:57:31 +0000 Subject: [PATCH] add new formatter (#77) * add f5 formatter * Add netmask * Add category scenario split / index 1 * Handle lists scenarios --- pkg/formatters/formatters.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/pkg/formatters/formatters.go b/pkg/formatters/formatters.go index d258acb..630f771 100644 --- a/pkg/formatters/formatters.go +++ b/pkg/formatters/formatters.go @@ -13,6 +13,7 @@ import ( var ByName = map[string]func(w http.ResponseWriter, r *http.Request){ "plain_text": PlainText, "mikrotik": MikroTik, + "f5": F5, } func PlainText(w http.ResponseWriter, r *http.Request) { @@ -49,3 +50,35 @@ func MikroTik(w http.ResponseWriter, r *http.Request) { ) } } + +func F5(w http.ResponseWriter, r *http.Request) { + decisions := r.Context().Value(registry.GlobalDecisionRegistry.Key).([]*models.Decision) + for _, decision := range decisions { + var category = *decision.Scenario + if strings.Contains(*decision.Scenario, "/") { + category = strings.Split(*decision.Scenario, "/")[1] + } + switch strings.ToLower(*decision.Scope) { + case "ip": + mask := 32 + if strings.Contains(*decision.Value, ":") { + mask = 64 + } + fmt.Fprintf(w, + "%s,%d,bl,%s\n", + *decision.Value, + mask, + category, + ) + case "range": + sep := strings.Split(*decision.Value, "/") + fmt.Fprintf(w, + "%s,%s,bl,%s\n", + sep[0], + sep[1], + category, + ) + default: + } + } +}