mirror of
https://github.com/tobychui/zoraxy.git
synced 2025-09-20 19:19:50 +02:00
feat(plugins): Implement event system w/ POC events
Implements the partially created event system with 3 events implemented as proof of concepts. The 3 events are: - `blacklistedIpBlocked`: emitted when a request from a blacklisted IP - `accessRuleCreated`: emitted when a new access rule is created - `blacklistToggled`: emitted when the blacklist is toggled for a given access rule Why these events? Because these are the ones I forsee myself needing in the next version of the zoraxy_crowdsec_bouncer Events are dispatched via a global event manager `plugins.EventSystem.Emit`
This commit is contained in:
@@ -7,6 +7,8 @@ import (
|
||||
|
||||
"imuslab.com/zoraxy/mod/access"
|
||||
"imuslab.com/zoraxy/mod/netutils"
|
||||
"imuslab.com/zoraxy/mod/plugins"
|
||||
"imuslab.com/zoraxy/mod/plugins/zoraxy_plugin"
|
||||
)
|
||||
|
||||
// Handle access check (blacklist / whitelist), return true if request is handled (aka blocked)
|
||||
@@ -43,6 +45,23 @@ func accessRequestBlocked(accessRule *access.AccessRule, templateDirectory strin
|
||||
w.Write(template)
|
||||
}
|
||||
|
||||
// Emit blacklisted IP blocked event
|
||||
// Get the comment for this IP
|
||||
comment, err := accessRule.GetBlacklistedIPComment(clientIpAddr)
|
||||
if err != nil {
|
||||
comment = "blacklisted"
|
||||
}
|
||||
plugins.EventSystem.Emit(
|
||||
&zoraxy_plugin.BlacklistedIPBlockedEvent{
|
||||
IP: clientIpAddr,
|
||||
Comment: comment,
|
||||
RequestedURL: r.URL.String(),
|
||||
Hostname: r.Host,
|
||||
UserAgent: r.Header.Get("User-Agent"),
|
||||
Method: r.Method,
|
||||
},
|
||||
)
|
||||
|
||||
return true, "blacklist"
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user