|
|
@ -12,17 +12,20 @@ import ( |
|
|
|
"strings" |
|
|
|
"time" |
|
|
|
|
|
|
|
"github.com/sirupsen/logrus" |
|
|
|
|
|
|
|
"github.com/miekg/dns" |
|
|
|
|
|
|
|
"github.com/labstack/echo/v4" |
|
|
|
"github.com/labstack/echo/v4/middleware" |
|
|
|
"github.com/miekg/dns" |
|
|
|
"github.com/sirupsen/logrus" |
|
|
|
) |
|
|
|
|
|
|
|
const ( |
|
|
|
queryTimeout = 5 * time.Second |
|
|
|
userAgent = "maze.io/doh 1.0" |
|
|
|
// DefaultQueryTimeout for doing DNS lookups.
|
|
|
|
DefaultQueryTimeout = 5 * time.Second |
|
|
|
|
|
|
|
// DefaultRedirect is the redirect page for the root.
|
|
|
|
DefaultRedirect = "https://maze.io" |
|
|
|
|
|
|
|
userAgent = "maze.io/doh 1.0" |
|
|
|
) |
|
|
|
|
|
|
|
type Server struct { |
|
|
@ -38,14 +41,18 @@ type Server struct { |
|
|
|
Verbose bool |
|
|
|
LogGuessedIP bool |
|
|
|
|
|
|
|
// Redirect URL
|
|
|
|
Redirect string |
|
|
|
|
|
|
|
udpClient *dns.Client |
|
|
|
tcpClient *dns.Client |
|
|
|
tcpClientTLS *dns.Client |
|
|
|
} |
|
|
|
|
|
|
|
func NewServer() *Server { |
|
|
|
func NewServer(queryTimeout time.Duration) *Server { |
|
|
|
server := &Server{ |
|
|
|
Echo: echo.New(), |
|
|
|
Echo: echo.New(), |
|
|
|
Redirect: DefaultRedirect, |
|
|
|
udpClient: &dns.Client{ |
|
|
|
Net: "udp", |
|
|
|
UDPSize: dns.DefaultMsgSize, |
|
|
@ -62,11 +69,17 @@ func NewServer() *Server { |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
// Tuning
|
|
|
|
server.HideBanner = true |
|
|
|
|
|
|
|
// Middleware
|
|
|
|
//server.Use(middleware.Recover())
|
|
|
|
server.Use(middleware.Recover()) |
|
|
|
server.Use(middleware.Logger()) |
|
|
|
|
|
|
|
// Routes
|
|
|
|
server.GET("/", func(c echo.Context) error { |
|
|
|
return c.Redirect(http.StatusFound, server.Redirect) |
|
|
|
}) |
|
|
|
server.GET("/dns-query", server.handleDNSQuery) |
|
|
|
server.POST("/dns-query", server.handleDNSQuery) |
|
|
|
|
|
|
|