feat: add new interface method to firewals
All checks were successful
build / build (push) Successful in 3m9s
All checks were successful
build / build (push) Successful in 3m9s
This commit is contained in:
17
cmd/banforge/command/version.go
Normal file
17
cmd/banforge/command/version.go
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package command
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
var version = "0.4.3"
|
||||||
|
|
||||||
|
var VersionCmd = &cobra.Command{
|
||||||
|
Use: "version",
|
||||||
|
Short: "BanForge version",
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
fmt.Println("BanForge version:", version)
|
||||||
|
},
|
||||||
|
}
|
||||||
@@ -13,7 +13,6 @@ var rootCmd = &cobra.Command{
|
|||||||
Use: "banforge",
|
Use: "banforge",
|
||||||
Short: "IPS log-based written on Golang",
|
Short: "IPS log-based written on Golang",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,6 +27,7 @@ func Execute() {
|
|||||||
rootCmd.AddCommand(command.BanCmd)
|
rootCmd.AddCommand(command.BanCmd)
|
||||||
rootCmd.AddCommand(command.UnbanCmd)
|
rootCmd.AddCommand(command.UnbanCmd)
|
||||||
rootCmd.AddCommand(command.BanListCmd)
|
rootCmd.AddCommand(command.BanListCmd)
|
||||||
|
rootCmd.AddCommand(command.VersionCmd)
|
||||||
command.RuleRegister()
|
command.RuleRegister()
|
||||||
command.FwRegister()
|
command.FwRegister()
|
||||||
if err := rootCmd.Execute(); err != nil {
|
if err := rootCmd.Execute(); err != nil {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package blocker
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/d3m0k1d/BanForge/internal/logger"
|
"github.com/d3m0k1d/BanForge/internal/logger"
|
||||||
)
|
)
|
||||||
@@ -58,6 +59,31 @@ func (f *Firewalld) Unban(ip string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (f *Firewalld) PortOpen(port int) error {
|
||||||
|
// #nosec G204 - handle is extracted from nftables output and validated
|
||||||
|
if port >= 0 && port <= 65535 {
|
||||||
|
s := strconv.Itoa(port)
|
||||||
|
cmd := exec.Command("firewall-cmd", "--zone=public", "--add-port="+s+"/tcp", "--permanent")
|
||||||
|
output, err := cmd.CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
f.logger.Error(err.Error())
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
f.logger.Info("Add port " + s + " " + string(output))
|
||||||
|
output, err = exec.Command("firewall-cmd", "--reload").CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
f.logger.Error(err.Error())
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
f.logger.Info("Reload " + string(output))
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *Firewalld) PortClose(port int) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (f *Firewalld) Setup(config string) error {
|
func (f *Firewalld) Setup(config string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ type BlockerEngine interface {
|
|||||||
Ban(ip string) error
|
Ban(ip string) error
|
||||||
Unban(ip string) error
|
Unban(ip string) error
|
||||||
Setup(config string) error
|
Setup(config string) error
|
||||||
|
PortOpen(port int) error
|
||||||
|
PortClose(port int) error
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetBlocker(fw string, config string) BlockerEngine {
|
func GetBlocker(fw string, config string) BlockerEngine {
|
||||||
|
|||||||
@@ -102,6 +102,14 @@ func (f *Iptables) Unban(ip string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (f *Iptables) PortOpen(port int) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *Iptables) PortClose(port int) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (f *Iptables) Setup(config string) error {
|
func (f *Iptables) Setup(config string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -166,6 +166,14 @@ func (n *Nftables) findRuleHandle(ip string) (string, error) {
|
|||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (n *Nftables) PortOpen(port int) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *Nftables) PortClose(port int) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func saveNftablesConfig(configPath string) error {
|
func saveNftablesConfig(configPath string) error {
|
||||||
err := validateConfigPath(configPath)
|
err := validateConfigPath(configPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -56,6 +56,14 @@ func (u *Ufw) Unban(ip string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (u *Ufw) PortOpen(port int) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u *Ufw) PortClose(port int) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (u *Ufw) Setup(config string) error {
|
func (u *Ufw) Setup(config string) error {
|
||||||
if config != "" {
|
if config != "" {
|
||||||
fmt.Printf("Ufw dont support config file\n")
|
fmt.Printf("Ufw dont support config file\n")
|
||||||
|
|||||||
Reference in New Issue
Block a user