typedef.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. package dynamicproxy
  2. import (
  3. "net"
  4. "net/http"
  5. "sync"
  6. "imuslab.com/zoraxy/mod/dynamicproxy/dpcore"
  7. "imuslab.com/zoraxy/mod/dynamicproxy/redirection"
  8. "imuslab.com/zoraxy/mod/geodb"
  9. "imuslab.com/zoraxy/mod/statistic"
  10. "imuslab.com/zoraxy/mod/tlscert"
  11. )
  12. const (
  13. ProxyType_Subdomain = 0
  14. ProxyType_Vdir = 1
  15. )
  16. type ProxyHandler struct {
  17. Parent *Router
  18. }
  19. type RouterOption struct {
  20. HostUUID string //The UUID of Zoraxy, use for heading mod
  21. Port int //Incoming port
  22. UseTls bool //Use TLS to serve incoming requsts
  23. ForceTLSLatest bool //Force TLS1.2 or above
  24. ForceHttpsRedirect bool //Force redirection of http to https endpoint
  25. TlsManager *tlscert.Manager
  26. RedirectRuleTable *redirection.RuleTable
  27. GeodbStore *geodb.Store //GeoIP blacklist and whitelist
  28. StatisticCollector *statistic.Collector
  29. }
  30. type Router struct {
  31. Option *RouterOption
  32. ProxyEndpoints *sync.Map
  33. SubdomainEndpoint *sync.Map
  34. Running bool
  35. Root *ProxyEndpoint
  36. RootRoutingOptions *RootRoutingOptions
  37. mux http.Handler
  38. server *http.Server
  39. tlsListener net.Listener
  40. routingRules []*RoutingRule
  41. tlsRedirectStop chan bool //Stop channel for tls redirection server
  42. tldMap map[string]int //Top level domain map, see tld.json
  43. }
  44. // Auth credential for basic auth on certain endpoints
  45. type BasicAuthCredentials struct {
  46. Username string
  47. PasswordHash string
  48. }
  49. // Auth credential for basic auth on certain endpoints
  50. type BasicAuthUnhashedCredentials struct {
  51. Username string
  52. Password string
  53. }
  54. // Paths to exclude in basic auth enabled proxy handler
  55. type BasicAuthExceptionRule struct {
  56. PathPrefix string
  57. }
  58. // A proxy endpoint record
  59. type ProxyEndpoint struct {
  60. ProxyType int //The type of this proxy, see const def
  61. RootOrMatchingDomain string //Root for vdir or Matching domain for subd, also act as key
  62. Domain string //Domain or IP to proxy to
  63. RequireTLS bool //Target domain require TLS
  64. BypassGlobalTLS bool //Bypass global TLS setting options if TLS Listener enabled (parent.tlsListener != nil)
  65. SkipCertValidations bool //Set to true to accept self signed certs
  66. RequireBasicAuth bool //Set to true to request basic auth before proxy
  67. BasicAuthCredentials []*BasicAuthCredentials `json:"-"` //Basic auth credentials
  68. BasicAuthExceptionRules []*BasicAuthExceptionRule //Path to exclude in a basic auth enabled proxy target
  69. Proxy *dpcore.ReverseProxy `json:"-"`
  70. parent *Router
  71. }
  72. // Root options are those that are required for reverse proxy handler to work
  73. type RootOptions struct {
  74. ProxyLocation string //Proxy Root target, all unset traffic will be forward to here
  75. RequireTLS bool //Proxy root target require TLS connection (not recommended)
  76. BypassGlobalTLS bool //Bypass global TLS setting and make root http only (not recommended)
  77. SkipCertValidations bool //Skip cert validation, suitable for self-signed certs, CURRENTLY NOT USED
  78. //Basic Auth Related
  79. RequireBasicAuth bool //Require basic auth, CURRENTLY NOT USED
  80. BasicAuthCredentials []*BasicAuthCredentials
  81. BasicAuthExceptionRules []*BasicAuthExceptionRule
  82. }
  83. // Additional options are here for letting router knows how to route exception cases for root
  84. type RootRoutingOptions struct {
  85. //Root only configs
  86. EnableRedirectForUnsetRules bool //Force unset rules to redirect to custom domain
  87. UnsetRuleRedirectTarget string //Custom domain to redirect to for unset rules
  88. }
  89. type VdirOptions struct {
  90. RootName string
  91. Domain string
  92. RequireTLS bool
  93. BypassGlobalTLS bool
  94. SkipCertValidations bool
  95. RequireBasicAuth bool
  96. BasicAuthCredentials []*BasicAuthCredentials
  97. BasicAuthExceptionRules []*BasicAuthExceptionRule
  98. }
  99. type SubdOptions struct {
  100. MatchingDomain string
  101. Domain string
  102. RequireTLS bool
  103. BypassGlobalTLS bool
  104. SkipCertValidations bool
  105. RequireBasicAuth bool
  106. BasicAuthCredentials []*BasicAuthCredentials
  107. BasicAuthExceptionRules []*BasicAuthExceptionRule
  108. }