mirror of
https://github.com/tobychui/zoraxy.git
synced 2025-09-16 17:19:42 +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:
@@ -10,6 +10,8 @@ import (
|
||||
"github.com/microcosm-cc/bluemonday"
|
||||
|
||||
"imuslab.com/zoraxy/mod/access"
|
||||
"imuslab.com/zoraxy/mod/plugins"
|
||||
"imuslab.com/zoraxy/mod/plugins/zoraxy_plugin"
|
||||
"imuslab.com/zoraxy/mod/utils"
|
||||
)
|
||||
|
||||
@@ -97,6 +99,17 @@ func handleCreateAccessRule(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
// emit an event for the new access rule creation
|
||||
plugins.EventSystem.Emit(
|
||||
&zoraxy_plugin.AccessRuleCreatedEvent{
|
||||
ID: ruleUUID,
|
||||
Name: ruleName,
|
||||
Desc: ruleDesc,
|
||||
BlacklistEnabled: false,
|
||||
WhitelistEnabled: false,
|
||||
},
|
||||
)
|
||||
|
||||
utils.SendOK(w)
|
||||
}
|
||||
|
||||
@@ -359,6 +372,11 @@ func handleBlacklistEnable(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
plugins.EventSystem.Emit(&zoraxy_plugin.BlacklistToggledEvent{
|
||||
RuleID: ruleID,
|
||||
Enabled: rule.BlacklistEnabled,
|
||||
})
|
||||
|
||||
utils.SendOK(w)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user