typedef.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. // A proxy endpoint record
  46. type ProxyEndpoint struct {
  47. ProxyType int //The type of this proxy, see const def
  48. RootOrMatchingDomain string //Root for vdir or Matching domain for subd
  49. Domain string //Domain or IP to proxy to
  50. RequireTLS bool //Target domain require TLS
  51. SkipCertValidations bool //Set to true to accept self signed certs
  52. RequireBasicAuth bool //Set to true to request basic auth before proxy
  53. BasicAuthCredentials []*BasicAuthCredentials `json:"-"`
  54. Proxy *dpcore.ReverseProxy `json:"-"`
  55. }
  56. type RootOptions struct {
  57. ProxyLocation string
  58. RequireTLS bool
  59. SkipCertValidations bool
  60. RequireBasicAuth bool
  61. BasicAuthCredentials []*BasicAuthCredentials
  62. }
  63. type VdirOptions struct {
  64. RootName string
  65. Domain string
  66. RequireTLS bool
  67. SkipCertValidations bool
  68. RequireBasicAuth bool
  69. BasicAuthCredentials []*BasicAuthCredentials
  70. }
  71. type SubdOptions struct {
  72. MatchingDomain string
  73. Domain string
  74. RequireTLS bool
  75. SkipCertValidations bool
  76. RequireBasicAuth bool
  77. BasicAuthCredentials []*BasicAuthCredentials
  78. }
  79. /*
  80. type ProxyEndpoint struct {
  81. Root string
  82. Domain string
  83. RequireTLS bool
  84. Proxy *reverseproxy.ReverseProxy `json:"-"`
  85. }
  86. type SubdomainEndpoint struct {
  87. MatchingDomain string
  88. Domain string
  89. RequireTLS bool
  90. Proxy *reverseproxy.ReverseProxy `json:"-"`
  91. }
  92. */