Add base interface and ufw realisation
All checks were successful
CI.yml / build (push) Successful in 36s
All checks were successful
CI.yml / build (push) Successful in 36s
This commit is contained in:
8
internal/blocker/interface.go
Normal file
8
internal/blocker/interface.go
Normal file
@@ -0,0 +1,8 @@
|
||||
package blocker
|
||||
|
||||
type BlockerEngine interface {
|
||||
Ban(ip string) error
|
||||
Unban(ip string) error
|
||||
IsBanned(ip string) (bool, error)
|
||||
Flush() error
|
||||
}
|
||||
28
internal/blocker/ufw.go
Normal file
28
internal/blocker/ufw.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package blocker
|
||||
|
||||
import (
|
||||
"github.com/d3m0k1d/BanForge/internal/logger"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
type Ufw struct {
|
||||
logger *logger.Logger
|
||||
}
|
||||
|
||||
func NewUfw(logger *logger.Logger) *Ufw {
|
||||
return &Ufw{
|
||||
logger: logger,
|
||||
}
|
||||
}
|
||||
|
||||
func (ufw *Ufw) Ban(ip string) error {
|
||||
cmd := exec.Command("sudo", "ufw", "--force", "deny", "from", ip)
|
||||
ufw.logger.Info("Banning " + ip)
|
||||
return cmd.Run()
|
||||
}
|
||||
|
||||
func (ufw *Ufw) Unban(ip string) error {
|
||||
cmd := exec.Command("sudo", "ufw", "--force", "delete", "deny", "from", ip)
|
||||
ufw.logger.Info("Unbanning " + ip)
|
||||
return cmd.Run()
|
||||
}
|
||||
Reference in New Issue
Block a user