mirror of
https://github.com/m13253/dns-over-https.git
synced 2026-03-30 05:19:56 +00:00
log real client ip behind a HTTPS gateway (#38)
* log real client ip behind a HTTPS gateway * fix tab/space indent * better compatible for apache/nginx log default format * add config option
This commit is contained in:
@@ -40,6 +40,7 @@ type config struct {
|
||||
TCPOnly bool `toml:"tcp_only"`
|
||||
Verbose bool `toml:"verbose"`
|
||||
DebugHTTPHeaders []string `toml:"debug_http_headers"`
|
||||
LogGuessedIP bool `toml:"log_guessed_client_ip"`
|
||||
}
|
||||
|
||||
func loadConfig(path string) (*config, error) {
|
||||
|
||||
@@ -38,3 +38,7 @@ tcp_only = false
|
||||
|
||||
# Enable logging
|
||||
verbose = false
|
||||
|
||||
# Enable log IP from HTTPS-reverse proxy header: X-Forwarded-For or X-Real-IP
|
||||
# Note: http uri/useragent log cannot be controlled by this config
|
||||
log_guessed_client_ip = false
|
||||
|
||||
@@ -30,6 +30,7 @@ import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -94,7 +95,15 @@ func (s *Server) parseRequestIETF(ctx context.Context, w http.ResponseWriter, r
|
||||
} else {
|
||||
questionType = strconv.FormatUint(uint64(question.Qtype), 10)
|
||||
}
|
||||
fmt.Printf("%s - - [%s] \"%s %s %s\"\n", r.RemoteAddr, time.Now().Format("02/Jan/2006:15:04:05 -0700"), questionName, questionClass, questionType)
|
||||
var clientip net.IP = nil
|
||||
if s.conf.LogGuessedIP {
|
||||
clientip = s.findClientIP(r)
|
||||
}
|
||||
if clientip != nil {
|
||||
fmt.Printf("%s - - [%s] \"%s %s %s\"\n", clientip, time.Now().Format("02/Jan/2006:15:04:05 -0700"), questionName, questionClass, questionType)
|
||||
} else {
|
||||
fmt.Printf("%s - - [%s] \"%s %s %s\"\n", r.RemoteAddr, time.Now().Format("02/Jan/2006:15:04:05 -0700"), questionName, questionClass, questionType)
|
||||
}
|
||||
}
|
||||
|
||||
transactionID := msg.Id
|
||||
|
||||
Reference in New Issue
Block a user