feat: update ban/unban command
All checks were successful
build / build (push) Successful in 3m13s

This commit is contained in:
d3m0k1d
2026-01-25 21:13:56 +03:00
parent b0fc0646d2
commit e907fb0b1a
2 changed files with 20 additions and 4 deletions

View File

@@ -12,12 +12,20 @@ import (
) )
var ( var (
ip string ttl_fw string
) )
var UnbanCmd = &cobra.Command{ var UnbanCmd = &cobra.Command{
Use: "unban", Use: "unban",
Short: "Unban IP", Short: "Unban IP",
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
fmt.Println("IP can't be empty")
os.Exit(1)
}
if ttl_fw == "" {
ttl_fw = "1y"
}
ip := args[0]
db, err := storage.NewBanWriter() db, err := storage.NewBanWriter()
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
@@ -60,6 +68,14 @@ var BanCmd = &cobra.Command{
Use: "ban", Use: "ban",
Short: "Ban IP", Short: "Ban IP",
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
fmt.Println("IP can't be empty")
os.Exit(1)
}
if ttl_fw == "" {
ttl_fw = "1y"
}
ip := args[0]
db, err := storage.NewBanWriter() db, err := storage.NewBanWriter()
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
@@ -89,7 +105,7 @@ var BanCmd = &cobra.Command{
fmt.Println(err) fmt.Println(err)
os.Exit(1) os.Exit(1)
} }
err = db.AddBan(ip, "1y") err = db.AddBan(ip, ttl_fw)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
os.Exit(1) os.Exit(1)
@@ -99,6 +115,5 @@ var BanCmd = &cobra.Command{
} }
func FwRegister() { func FwRegister() {
BanCmd.Flags().StringVarP(&ip, "ip", "i", "", "ip to ban") BanCmd.Flags().StringVarP(&ttl_fw, "ttl", "t", "", "ban time")
UnbanCmd.Flags().StringVarP(&ip, "ip", "i", "", "ip to unban")
} }

View File

@@ -31,6 +31,7 @@ banforge unban <ip>
**Description** **Description**
These commands provide an abstraction over your firewall. If you want to simplify the interface to your firewall, you can use these commands. These commands provide an abstraction over your firewall. If you want to simplify the interface to your firewall, you can use these commands.
Flag -t or -ttl add bantime if not used default ban 1 year
### list - Lists the IP addresses that are currently blocked ### list - Lists the IP addresses that are currently blocked
```shell ```shell
banforge list banforge list