mirror of
https://github.com/swissmakers/fail2ban-ui.git
synced 2026-04-17 05:53:15 +02:00
Remove old ReloadFail2ban function, because the new is combined
This commit is contained in:
@@ -18,6 +18,10 @@ package fail2ban
|
|||||||
|
|
||||||
import "context"
|
import "context"
|
||||||
|
|
||||||
|
// =========================================================================
|
||||||
|
// Types
|
||||||
|
// =========================================================================
|
||||||
|
|
||||||
type JailInfo struct {
|
type JailInfo struct {
|
||||||
JailName string `json:"jailName"`
|
JailName string `json:"jailName"`
|
||||||
TotalBanned int `json:"totalBanned"`
|
TotalBanned int `json:"totalBanned"`
|
||||||
@@ -26,7 +30,11 @@ type JailInfo struct {
|
|||||||
Enabled bool `json:"enabled"`
|
Enabled bool `json:"enabled"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetJails returns the jail names for the default server.
|
// =========================================================================
|
||||||
|
// Client Functions
|
||||||
|
// =========================================================================
|
||||||
|
|
||||||
|
// Returns jail names from the default server.
|
||||||
func GetJails() ([]string, error) {
|
func GetJails() ([]string, error) {
|
||||||
conn, err := GetManager().DefaultConnector()
|
conn, err := GetManager().DefaultConnector()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -44,7 +52,7 @@ func GetJails() ([]string, error) {
|
|||||||
return names, nil
|
return names, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetBannedIPs returns a slice of currently banned IPs for a specific jail.
|
// Returns a slice of currently banned IPs for a specific jail.
|
||||||
func GetBannedIPs(jail string) ([]string, error) {
|
func GetBannedIPs(jail string) ([]string, error) {
|
||||||
conn, err := GetManager().DefaultConnector()
|
conn, err := GetManager().DefaultConnector()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -53,7 +61,7 @@ func GetBannedIPs(jail string) ([]string, error) {
|
|||||||
return conn.GetBannedIPs(context.Background(), jail)
|
return conn.GetBannedIPs(context.Background(), jail)
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnbanIP unbans an IP from the given jail.
|
// Unbans an IP from the given jail.
|
||||||
func UnbanIP(jail, ip string) error {
|
func UnbanIP(jail, ip string) error {
|
||||||
conn, err := GetManager().DefaultConnector()
|
conn, err := GetManager().DefaultConnector()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -62,7 +70,7 @@ func UnbanIP(jail, ip string) error {
|
|||||||
return conn.UnbanIP(context.Background(), jail, ip)
|
return conn.UnbanIP(context.Background(), jail, ip)
|
||||||
}
|
}
|
||||||
|
|
||||||
// BuildJailInfos returns extended info for each jail on the default server.
|
// Returns extended info for each jail on the default server.
|
||||||
func BuildJailInfos(_ string) ([]JailInfo, error) {
|
func BuildJailInfos(_ string) ([]JailInfo, error) {
|
||||||
conn, err := GetManager().DefaultConnector()
|
conn, err := GetManager().DefaultConnector()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -71,18 +79,7 @@ func BuildJailInfos(_ string) ([]JailInfo, error) {
|
|||||||
return conn.GetJailInfos(context.Background())
|
return conn.GetJailInfos(context.Background())
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReloadFail2ban triggers a reload on the default server.
|
// Restarts (or reloads) the Fail2ban service.
|
||||||
func ReloadFail2ban() error {
|
|
||||||
conn, err := GetManager().DefaultConnector()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return conn.Reload(context.Background())
|
|
||||||
}
|
|
||||||
|
|
||||||
// RestartFail2ban restarts (or reloads) the Fail2ban service using the
|
|
||||||
// provided server or default connector and returns a mode string describing
|
|
||||||
// what actually happened ("restart" or "reload").
|
|
||||||
func RestartFail2ban(serverID string) (string, error) {
|
func RestartFail2ban(serverID string) (string, error) {
|
||||||
manager := GetManager()
|
manager := GetManager()
|
||||||
var (
|
var (
|
||||||
@@ -97,8 +94,6 @@ func RestartFail2ban(serverID string) (string, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
// If the connector supports a detailed restart mode, use it. Otherwise
|
|
||||||
// fall back to a plain Restart() and assume "restart".
|
|
||||||
if withMode, ok := conn.(interface {
|
if withMode, ok := conn.(interface {
|
||||||
RestartWithMode(ctx context.Context) (string, error)
|
RestartWithMode(ctx context.Context) (string, error)
|
||||||
}); ok {
|
}); ok {
|
||||||
|
|||||||
Reference in New Issue
Block a user