diff --git a/src/mod/plugins/lifecycle.go b/src/mod/plugins/lifecycle.go index cf8282f..d2d9752 100644 --- a/src/mod/plugins/lifecycle.go +++ b/src/mod/plugins/lifecycle.go @@ -157,6 +157,10 @@ func (m *Manager) StartPlugin(pluginID string) error { if thisPlugin.Spec.SubscriptionsEvents != nil { for eventName := range thisPlugin.Spec.SubscriptionsEvents { eventType := events.EventName(eventName) + if !eventType.IsValid() { + m.Log("Invalid event name: "+string(eventName), nil) + continue + } err := eventsystem.Publisher.RegisterSubscriberToEvent(thisPlugin, eventType) if err != nil { m.Log("Failed to subscribe plugin "+thisPlugin.Spec.Name+" to event "+string(eventName), err) diff --git a/src/mod/plugins/zoraxy_plugin/events/events.go b/src/mod/plugins/zoraxy_plugin/events/events.go index 3f54b2e..2bd6536 100644 --- a/src/mod/plugins/zoraxy_plugin/events/events.go +++ b/src/mod/plugins/zoraxy_plugin/events/events.go @@ -32,6 +32,19 @@ const ( // Add more event types as needed ) +var validEventNames = map[EventName]bool{ + EventBlacklistedIPBlocked: true, + EventBlacklistToggled: true, + EventAccessRuleCreated: true, + // Add more event types as needed + // NOTE: Keep up-to-date with event names specified above +} + +// Check if the event name is valid +func (name EventName) IsValid() bool { + return validEventNames[name] +} + // BlacklistedIPBlockedEvent represents an event when a blacklisted IP is blocked type BlacklistedIPBlockedEvent struct { IP string `json:"ip"` diff --git a/src/mod/plugins/zoraxy_plugin/zoraxy_plugin.go b/src/mod/plugins/zoraxy_plugin/zoraxy_plugin.go index 17180bb..761b313 100644 --- a/src/mod/plugins/zoraxy_plugin/zoraxy_plugin.go +++ b/src/mod/plugins/zoraxy_plugin/zoraxy_plugin.go @@ -5,8 +5,6 @@ import ( "fmt" "os" "strings" - - "imuslab.com/zoraxy/mod/plugins/zoraxy_plugin/events" ) /* @@ -104,8 +102,8 @@ type IntroSpect struct { UIPath string `json:"ui_path"` //UI path of your plugin (e.g. /ui), will proxy the whole subpath tree to Zoraxy Web UI as plugin UI /* Subscriptions Settings */ - SubscriptionPath string `json:"subscription_path"` //Subscription event path of your plugin (e.g. /notifyme), a POST request with SubscriptionEvent as body will be sent to this path when the event is triggered - SubscriptionsEvents map[events.EventName]string `json:"subscriptions_events"` //Subscriptions events of your plugin, paired with comments describing how the event is used, see Zoraxy documentation for more details + SubscriptionPath string `json:"subscription_path"` //Subscription event path of your plugin (e.g. /notifyme), a POST request with SubscriptionEvent as body will be sent to this path when the event is triggered + SubscriptionsEvents map[string]string `json:"subscriptions_events"` //Subscriptions events of your plugin, paired with comments describing how the event is used, see Zoraxy documentation for more details /* API Access Control */ PermittedAPIEndpoints []PermittedAPIEndpoint `json:"permitted_api_endpoints"` //List of API endpoints this plugin can access, and a description of why the plugin needs to access this endpoint