Fix: fix init nftables, fix logic ban/unban command
All checks were successful
build / build (push) Successful in 2m39s
All checks were successful
build / build (push) Successful in 2m39s
This commit is contained in:
@@ -104,15 +104,14 @@ func (n *Nftables) Setup(config string) error {
|
||||
|
||||
nftConfig := `table inet banforge {
|
||||
chain input {
|
||||
type filter hook input priority 0
|
||||
policy accept
|
||||
type filter hook input priority filter; policy accept;
|
||||
jump banned
|
||||
}
|
||||
|
||||
chain banned {
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
cmd := exec.Command("sudo", "tee", config)
|
||||
stdin, err := cmd.StdinPipe()
|
||||
if err != nil {
|
||||
|
||||
@@ -129,6 +129,10 @@ func (j *Judge) UnbanChecker() {
|
||||
}
|
||||
|
||||
for _, ip := range ips {
|
||||
err = j.db.RemoveBan(ip)
|
||||
if err != nil {
|
||||
j.logger.Error(fmt.Sprintf("Failed to remove ban: %v", err))
|
||||
}
|
||||
if err := j.Blocker.Unban(ip); err != nil {
|
||||
j.logger.Error(fmt.Sprintf("Failed to unban IP %s: %v", ip, err))
|
||||
continue
|
||||
|
||||
@@ -111,6 +111,15 @@ func (d *DB) AddBan(ip string, ttl string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *DB) RemoveBan(ip string) error {
|
||||
_, err := d.db.Exec("DELETE FROM bans WHERE ip = ?", ip)
|
||||
if err != nil {
|
||||
d.logger.Error("Failed to remove ban", "error", err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *DB) BanList() error {
|
||||
|
||||
var count int
|
||||
|
||||
Reference in New Issue
Block a user