typedef.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. mux http.Handler
  37. server *http.Server
  38. tlsListener net.Listener
  39. routingRules []*RoutingRule
  40. tlsRedirectStop chan bool
  41. }
  42. // Auth credential for basic auth on certain endpoints
  43. type BasicAuthCredentials struct {
  44. Username string
  45. PasswordHash string
  46. }
  47. // Auth credential for basic auth on certain endpoints
  48. type BasicAuthUnhashedCredentials struct {
  49. Username string
  50. Password string
  51. }
  52. // Paths to exclude in basic auth enabled proxy handler
  53. type BasicAuthExceptionRule struct {
  54. PathPrefix string
  55. }
  56. // A proxy endpoint record
  57. type ProxyEndpoint struct {
  58. ProxyType int //The type of this proxy, see const def
  59. RootOrMatchingDomain string //Root for vdir or Matching domain for subd
  60. Domain string //Domain or IP to proxy to
  61. RequireTLS bool //Target domain require TLS
  62. SkipCertValidations bool //Set to true to accept self signed certs
  63. RequireBasicAuth bool //Set to true to request basic auth before proxy
  64. BasicAuthCredentials []*BasicAuthCredentials `json:"-"` //Basic auth credentials
  65. BasicAuthExceptionRules []*BasicAuthExceptionRule //Path to exclude in a basic auth enabled proxy target
  66. Proxy *dpcore.ReverseProxy `json:"-"`
  67. }
  68. type RootOptions struct {
  69. ProxyLocation string
  70. RequireTLS bool
  71. SkipCertValidations bool
  72. RequireBasicAuth bool
  73. BasicAuthCredentials []*BasicAuthCredentials
  74. BasicAuthExceptionRules []*BasicAuthExceptionRule
  75. }
  76. type VdirOptions struct {
  77. RootName string
  78. Domain string
  79. RequireTLS bool
  80. SkipCertValidations bool
  81. RequireBasicAuth bool
  82. BasicAuthCredentials []*BasicAuthCredentials
  83. BasicAuthExceptionRules []*BasicAuthExceptionRule
  84. }
  85. type SubdOptions struct {
  86. MatchingDomain string
  87. Domain string
  88. RequireTLS bool
  89. SkipCertValidations bool
  90. RequireBasicAuth bool
  91. BasicAuthCredentials []*BasicAuthCredentials
  92. BasicAuthExceptionRules []*BasicAuthExceptionRule
  93. }