includes.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. package plugins
  2. /*
  3. Plugins Includes.go
  4. This file contains the common types and structs that are used by the plugins
  5. If you are building a Zoraxy plugin with Golang, you can use this file to include
  6. the common types and structs that are used by the plugins
  7. */
  8. type PluginType int
  9. const (
  10. PluginType_Router PluginType = 0 //Router Plugin, used for handling / routing / forwarding traffic
  11. PluginType_Utilities PluginType = 1 //Utilities Plugin, used for utilities like Zerotier or Static Web Server that do not require interception with the dpcore
  12. )
  13. type CaptureRule struct {
  14. CapturePath string `json:"capture_path"`
  15. IncludeSubPaths bool `json:"include_sub_paths"`
  16. }
  17. type ControlStatusCode int
  18. const (
  19. ControlStatusCode_CAPTURED ControlStatusCode = 280 //Traffic captured by plugin, ask Zoraxy not to process the traffic
  20. ControlStatusCode_UNHANDLED ControlStatusCode = 284 //Traffic not handled by plugin, ask Zoraxy to process the traffic
  21. ControlStatusCode_ERROR ControlStatusCode = 580 //Error occurred while processing the traffic, ask Zoraxy to process the traffic and log the error
  22. )
  23. type SubscriptionEvent struct {
  24. EventName string `json:"event_name"`
  25. EventSource string `json:"event_source"`
  26. Payload string `json:"payload"` //Payload of the event, can be empty
  27. }
  28. type RuntimeConstantValue struct {
  29. ZoraxyVersion string `json:"zoraxy_version"`
  30. ZoraxyUUID string `json:"zoraxy_uuid"`
  31. }
  32. /*
  33. IntroSpect Payload
  34. When the plugin is initialized with -introspect flag,
  35. the plugin shell return this payload as JSON and exit
  36. */
  37. type IntroSpect struct {
  38. /* Plugin metadata */
  39. ID string `json:"id"` //Unique ID of your plugin, recommended using your own domain in reverse like com.yourdomain.pluginname
  40. Name string `json:"name"` //Name of your plugin
  41. Author string `json:"author"` //Author name of your plugin
  42. AuthorContact string `json:"author_contact"` //Author contact of your plugin, like email
  43. Description string `json:"description"` //Description of your plugin
  44. URL string `json:"url"` //URL of your plugin
  45. Type PluginType `json:"type"` //Type of your plugin, Router(0) or Utilities(1)
  46. VersionMajor int `json:"version_major"` //Major version of your plugin
  47. VersionMinor int `json:"version_minor"` //Minor version of your plugin
  48. VersionPatch int `json:"version_patch"` //Patch version of your plugin
  49. /*
  50. Endpoint Settings
  51. */
  52. /*
  53. Global Capture Settings
  54. Once plugin is enabled these rules always applies, no matter which HTTP Proxy rule it is enabled on
  55. This captures the whole traffic of Zoraxy
  56. Notes: Will raise a warning on the UI when the user enables the plugin on a HTTP Proxy rule
  57. */
  58. GlobalCapturePath []CaptureRule `json:"global_capture_path"` //Global traffic capture path of your plugin
  59. GlobalCaptureIngress string `json:"global_capture_ingress"` //Global traffic capture ingress path of your plugin (e.g. /g_handler)
  60. /*
  61. Always Capture Settings
  62. Once the plugin is enabled on a given HTTP Proxy rule,
  63. these always applies
  64. */
  65. AlwaysCapturePath []CaptureRule `json:"always_capture_path"` //Always capture path of your plugin when enabled on a HTTP Proxy rule (e.g. /myapp)
  66. AlwaysCaptureIngress string `json:"always_capture_ingress"` //Always capture ingress path of your plugin when enabled on a HTTP Proxy rule (e.g. /a_handler)
  67. /*
  68. Dynamic Capture Settings
  69. Once the plugin is enabled on a given HTTP Proxy rule,
  70. the plugin can capture the request and decided if the request
  71. shall be handled by itself or let it pass through
  72. */
  73. DynmaicCaptureIngress string `json:"capture_path"` //Traffic capture path of your plugin (e.g. /capture)
  74. DynamicHandleIngress string `json:"handle_path"` //Traffic handle path of your plugin (e.g. /handler)
  75. /* UI Path for your plugin */
  76. 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
  77. /* Subscriptions Settings */
  78. 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
  79. SubscriptionsEvents map[string]string `json:"subscriptions_events"` //Subscriptions events of your plugin, see Zoraxy documentation for more details
  80. }
  81. /*
  82. ConfigureSpec Payload
  83. Zoraxy will start your plugin with -configure flag,
  84. the plugin shell read this payload as JSON and configure itself
  85. by the supplied values like starting a web server at given port
  86. that listens to 127.0.0.1:port
  87. */
  88. type ConfigureSpec struct {
  89. Port int `json:"port"` //Port to listen
  90. RuntimeConst RuntimeConstantValue `json:"runtime_const"` //Runtime constant values
  91. //To be expanded
  92. }