typedef.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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
  21. Port int
  22. UseTls bool
  23. ForceHttpsRedirect bool
  24. TlsManager *tlscert.Manager
  25. RedirectRuleTable *redirection.RuleTable
  26. GeodbStore *geodb.Store
  27. StatisticCollector *statistic.Collector
  28. }
  29. type Router struct {
  30. Option *RouterOption
  31. ProxyEndpoints *sync.Map
  32. SubdomainEndpoint *sync.Map
  33. Running bool
  34. Root *ProxyEndpoint
  35. mux http.Handler
  36. server *http.Server
  37. tlsListener net.Listener
  38. routingRules []*RoutingRule
  39. tlsRedirectStop chan bool
  40. }
  41. // Auth credential for basic auth on certain endpoints
  42. type BasicAuthCredentials struct {
  43. Username string
  44. PasswordHash string
  45. }
  46. // Auth credential for basic auth on certain endpoints
  47. type BasicAuthUnhashedCredentials struct {
  48. Username string
  49. Password string
  50. }
  51. // A proxy endpoint record
  52. type ProxyEndpoint struct {
  53. ProxyType int //The type of this proxy, see const def
  54. RootOrMatchingDomain string //Root for vdir or Matching domain for subd
  55. Domain string //Domain or IP to proxy to
  56. RequireTLS bool //Target domain require TLS
  57. SkipCertValidations bool //Set to true to accept self signed certs
  58. RequireBasicAuth bool //Set to true to request basic auth before proxy
  59. BasicAuthCredentials []*BasicAuthCredentials `json:"-"`
  60. Proxy *dpcore.ReverseProxy `json:"-"`
  61. }
  62. type RootOptions struct {
  63. ProxyLocation string
  64. RequireTLS bool
  65. SkipCertValidations bool
  66. RequireBasicAuth bool
  67. BasicAuthCredentials []*BasicAuthCredentials
  68. }
  69. type VdirOptions struct {
  70. RootName string
  71. Domain string
  72. RequireTLS bool
  73. SkipCertValidations bool
  74. RequireBasicAuth bool
  75. BasicAuthCredentials []*BasicAuthCredentials
  76. }
  77. type SubdOptions struct {
  78. MatchingDomain string
  79. Domain string
  80. RequireTLS bool
  81. SkipCertValidations bool
  82. RequireBasicAuth bool
  83. BasicAuthCredentials []*BasicAuthCredentials
  84. }
  85. /*
  86. type ProxyEndpoint struct {
  87. Root string
  88. Domain string
  89. RequireTLS bool
  90. Proxy *reverseproxy.ReverseProxy `json:"-"`
  91. }
  92. type SubdomainEndpoint struct {
  93. MatchingDomain string
  94. Domain string
  95. RequireTLS bool
  96. Proxy *reverseproxy.ReverseProxy `json:"-"`
  97. }
  98. */