typedef.go 2.9 KB

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