feat: add new logic for rule based bans
All checks were successful
CI.yml / build (push) Successful in 1m51s
All checks were successful
CI.yml / build (push) Successful in 1m51s
This commit is contained in:
22
internal/config/appconf.go
Normal file
22
internal/config/appconf.go
Normal 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
|
||||
}
|
||||
@@ -46,6 +46,20 @@ func CreateConf() error {
|
||||
return fmt.Errorf("failed to write config file: %w", err)
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
@@ -16,3 +16,16 @@ type Config struct {
|
||||
Firewall Firewall `toml:"firewall"`
|
||||
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"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user