|
@@ -19,17 +19,18 @@ import (
|
|
"time"
|
|
"time"
|
|
|
|
|
|
"github.com/drakkan/sftpgo/v2/internal/dataprovider"
|
|
"github.com/drakkan/sftpgo/v2/internal/dataprovider"
|
|
|
|
+ "github.com/drakkan/sftpgo/v2/internal/logger"
|
|
)
|
|
)
|
|
|
|
|
|
// HostEvent is the enumerable for the supported host events
|
|
// HostEvent is the enumerable for the supported host events
|
|
-type HostEvent int
|
|
|
|
|
|
+type HostEvent string
|
|
|
|
|
|
// Supported host events
|
|
// Supported host events
|
|
const (
|
|
const (
|
|
- HostEventLoginFailed HostEvent = iota
|
|
|
|
- HostEventUserNotFound
|
|
|
|
- HostEventNoLoginTried
|
|
|
|
- HostEventLimitExceeded
|
|
|
|
|
|
+ HostEventLoginFailed HostEvent = "LoginFailed"
|
|
|
|
+ HostEventUserNotFound = "UserNotFound"
|
|
|
|
+ HostEventNoLoginTried = "NoLoginTried"
|
|
|
|
+ HostEventLimitExceeded = "LimitExceeded"
|
|
)
|
|
)
|
|
|
|
|
|
// Supported defender drivers
|
|
// Supported defender drivers
|
|
@@ -132,6 +133,36 @@ func (d *baseDefender) getScore(event HostEvent) int {
|
|
return score
|
|
return score
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// logEvent do log an defender event which modifies the score of an host
|
|
|
|
+func (d *baseDefender) logEvent(ip, protocol string, event HostEvent, totalScore int) {
|
|
|
|
+ // ignore events which do not change the host score
|
|
|
|
+ eventScore := d.getScore(event)
|
|
|
|
+ if eventScore == 0 {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ logger.GetLogger().Debug().
|
|
|
|
+ Timestamp().
|
|
|
|
+ Str("sender", "defender").
|
|
|
|
+ Str("client_ip", ip).
|
|
|
|
+ Str("protocol", protocol).
|
|
|
|
+ Str("event", string(event)).
|
|
|
|
+ Int("increase_score_by", eventScore).
|
|
|
|
+ Int("score", totalScore).
|
|
|
|
+ Send()
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// logBan do log a ban of an host due to a too high host score
|
|
|
|
+func (d *baseDefender) logBan(ip, protocol string) {
|
|
|
|
+ logger.GetLogger().Info().
|
|
|
|
+ Timestamp().
|
|
|
|
+ Str("sender", "defender").
|
|
|
|
+ Str("client_ip", ip).
|
|
|
|
+ Str("protocol", protocol).
|
|
|
|
+ Str("event", "banned").
|
|
|
|
+ Send()
|
|
|
|
+}
|
|
|
|
+
|
|
type hostEvent struct {
|
|
type hostEvent struct {
|
|
dateTime time.Time
|
|
dateTime time.Time
|
|
score int
|
|
score int
|