From b289fa3e9fcfaa8c8d0208c45631cf51796a8746 Mon Sep 17 00:00:00 2001 From: Frederic Jung Date: Fri, 26 Jun 2026 11:29:53 +0200 Subject: [PATCH 1/2] Add support for configuring ban in/out + calculation method This allows a user to set the `enable_ban_incoming`, `enable_ban_outgoing` as well as the `calculation_method` on hostgroups or alike. --- main.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/main.go b/main.go index b5d5824..0271dd0 100644 --- a/main.go +++ b/main.go @@ -255,6 +255,9 @@ type Ban_settings_t struct { Description string `bson:"description" json:"description" fastnetmon_type:"string"` Networks []string `bson:"networks" json:"networks" fastnetmon_type:"cidr_networks_list"` Enable_ban bool `bson:"enable_ban" json:"enable_ban" fastnetmon_type:"bool"` + Enable_ban_incoming bool `bson:"enable_ban_incoming" json:"enable_ban_incoming" fastnetmon_type:"bool"` + Enable_ban_outgoing bool `bson:"enable_ban_outgoing" json:"enable_ban_outgoing" fastnetmon_type:"bool"` + Calculation_method string `bson:"calculation_method" json:"calculation_method" fastnetmon_type:"string"` Ban_for_pps bool `bson:"ban_for_pps" json:"ban_for_pps" fastnetmon_type:"bool"` Ban_for_bandwidth bool `bson:"ban_for_bandwidth" json:"ban_for_bandwidth" fastnetmon_type:"bool"` Ban_for_flows bool `bson:"ban_for_flows" json:"ban_for_flows" fastnetmon_type:"bool"` From 13f8445bc3e4927920b7abf7e2f727bfbbd90384 Mon Sep 17 00:00:00 2001 From: Frederic Jung Date: Fri, 26 Jun 2026 12:09:26 +0200 Subject: [PATCH 2/2] Add AddNetwork, RemoveNetwork, and Commit methods Extend the client with first-class methods for managing the global networks_list and committing configuration changes: - AddNetwork(cidr): PUT /main/networks_list/ - RemoveNetwork(cidr): DELETE /main/networks_list/ - Commit(): PUT /commit These complement the existing GetNetworks() method to provide full CRUD lifecycle for the networks_list without requiring callers to construct raw HTTP requests. --- main.go | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/main.go b/main.go index 0271dd0..c9dc470 100644 --- a/main.go +++ b/main.go @@ -549,6 +549,86 @@ func (client *FastNetMonClient) GetNetworks() ([]string, error) { return networks_response.Values, nil } +func (client *FastNetMonClient) AddNetwork(cidr string) error { + encoded := strings.Replace(cidr, "/", "%2f", 1) + resp, err := grequests.Put(client.Prefix+"/main/networks_list/"+encoded, grequests.FromRequestOptions(client.Ro)) + + if err != nil { + return fmt.Errorf("Cannot connect to API: %w", err) + } + + if !resp.Ok { + if resp.StatusCode == 401 { + return errors.New("Auth denied") + } + return fmt.Errorf("Did not return OK: %d", resp.StatusCode) + } + + response := ErrorJson{} + if err := resp.JSON(&response); err != nil { + return err + } + + if !response.Success { + return fmt.Errorf("API error: %s", response.ErrorText) + } + + return nil +} + +func (client *FastNetMonClient) RemoveNetwork(cidr string) error { + encoded := strings.Replace(cidr, "/", "%2f", 1) + resp, err := grequests.Delete(client.Prefix+"/main/networks_list/"+encoded, grequests.FromRequestOptions(client.Ro)) + + if err != nil { + return fmt.Errorf("Cannot connect to API: %w", err) + } + + if !resp.Ok { + if resp.StatusCode == 401 { + return errors.New("Auth denied") + } + return fmt.Errorf("Did not return OK: %d", resp.StatusCode) + } + + response := ErrorJson{} + if err := resp.JSON(&response); err != nil { + return err + } + + if !response.Success { + return fmt.Errorf("API error: %s", response.ErrorText) + } + + return nil +} + +func (client *FastNetMonClient) Commit() error { + resp, err := grequests.Put(client.Prefix+"/commit", grequests.FromRequestOptions(client.Ro)) + + if err != nil { + return fmt.Errorf("Cannot connect to API: %w", err) + } + + if !resp.Ok { + if resp.StatusCode == 401 { + return errors.New("Auth denied") + } + return fmt.Errorf("Did not return OK: %d", resp.StatusCode) + } + + response := ErrorJson{} + if err := resp.JSON(&response); err != nil { + return err + } + + if !response.Success { + return fmt.Errorf("API error: %s", response.ErrorText) + } + + return nil +} + // Retrieves all host groups func (client *FastNetMonClient) GetAllHostgroups() ([]Ban_settings_t, error) { resp, err := grequests.Get(client.Prefix+"/hostgroup", grequests.FromRequestOptions(client.Ro))