feat: add fail2ban service
This commit is contained in:
@@ -3,18 +3,21 @@ package handler
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"gitea.urkob.com/urko/prosody-password/internal/services/fail2ban"
|
||||
"gitea.urkob.com/urko/prosody-password/internal/services/prosody"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
func NewProsodyHandler(prosodyService *prosody.Prosody) ProsodyHandler {
|
||||
return ProsodyHandler{
|
||||
prosodyService: prosodyService,
|
||||
}
|
||||
}
|
||||
|
||||
type ProsodyHandler struct {
|
||||
prosodyService *prosody.Prosody
|
||||
fail2banSrv *fail2ban.Fail2Ban
|
||||
}
|
||||
|
||||
func NewProsodyHandler(prosodyService *prosody.Prosody, fail2banSrv *fail2ban.Fail2Ban) ProsodyHandler {
|
||||
return ProsodyHandler{
|
||||
prosodyService: prosodyService,
|
||||
fail2banSrv: fail2banSrv,
|
||||
}
|
||||
}
|
||||
|
||||
type changePasswordReq struct {
|
||||
@@ -30,6 +33,9 @@ func (handler ProsodyHandler) Post(c *fiber.Ctx) error {
|
||||
}
|
||||
|
||||
if err := handler.prosodyService.ChangePassword(req.User, req.CurrentPassword, req.NewPassword); err != nil {
|
||||
for _, ip := range c.IPs() {
|
||||
handler.fail2banSrv.FailedAttempt(ip)
|
||||
}
|
||||
return RenderError(c, fmt.Errorf("ChangePassword: %w", err), defaultErrMessage)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user