feat: add new logic for rule based bans
All checks were successful
CI.yml / build (push) Successful in 1m51s

This commit is contained in:
d3m0k1d
2026-01-13 18:02:22 +03:00
parent 9767bb70f1
commit 5362761b82
3 changed files with 49 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
package config
import (
"fmt"
"github.com/BurntSushi/toml"
"github.com/d3m0k1d/BanForge/internal/logger"
)
func LoadRuleConfig() ([]Rule, error) {
log := logger.New(false)
var cfg Rules
_, err := toml.DecodeFile("/etc/banforge/rules.toml", &cfg)
if err != nil {
log.Error(fmt.Sprintf("failed to decode config: %v", err))
return nil, err
}
log.Info(fmt.Sprintf("loaded %d rules", len(cfg.Rules)))
return cfg.Rules, nil
}

View File

@@ -46,6 +46,20 @@ func CreateConf() error {
return fmt.Errorf("failed to write config file: %w", err) return fmt.Errorf("failed to write config file: %w", err)
} }
fmt.Printf(" Config file created: %s\n", configPath) fmt.Printf(" Config file created: %s\n", configPath)
file, err = os.Create("/etc/banforge/rules.toml")
if err != nil {
return fmt.Errorf("failed to create rules file: %w", err)
}
defer func() {
err = file.Close()
if err != nil {
fmt.Println(err)
}
}()
if err := os.Chmod(configPath, 0600); err != nil {
return fmt.Errorf("failed to set permissions: %w", err)
}
fmt.Printf(" Rules file created: %s\n", configPath)
return nil return nil
} }

View File

@@ -16,3 +16,16 @@ type Config struct {
Firewall Firewall `toml:"firewall"` Firewall Firewall `toml:"firewall"`
Service Service `toml:"service"` Service Service `toml:"service"`
} }
// Rules
type Rules struct {
Rules []Rule `toml:"rule"`
}
type Rule struct {
Name string `toml:"name"`
ServiceName string `toml:"service"`
Path string `toml:"path"`
Status string `toml:"status"`
Method string `toml:"method"`
}