diff --git a/handlers_tracking.go b/handlers_tracking.go index 735a1e2..69ff62c 100644 --- a/handlers_tracking.go +++ b/handlers_tracking.go @@ -109,7 +109,7 @@ func post_tracking_handle(c *gin.Context, rtenv *RouteEnv) { } } } - ip, _ := getIP(c.Request) + ip, _ := getIP(c.Request,true) trackaction := &TrackAction{ When: trackpost.When, Where: trackpost.Where, diff --git a/logs.go b/logs.go index 631474f..66c05c0 100644 --- a/logs.go +++ b/logs.go @@ -57,9 +57,16 @@ func setLog(cfg *cfg.Config) { }) } -func getIP(r *http.Request) (string, error) { +func getIP(r *http.Request,show bool) (string, error) { //Get IP from X-FORWARDED-FOR header ips := r.Header.Get("X-FORWARDED-FOR") + if show { + fmt.Println("X-Forwarded-For : ", ips) + ipreal := r.Header.Get("X-REAL-IP") + fmt.Println("X-REAL-IP : ", ipreal) + iprem, _, _ := net.SplitHostPort(r.RemoteAddr) + fmt.Println("RemoteAddr : ", iprem) + } splitIps := strings.Split(ips, ",") for _, ip := range splitIps { netIP := net.ParseIP(ip) @@ -88,7 +95,7 @@ func getIP(r *http.Request) (string, error) { func logRequest(c *gin.Context, rtenv *RouteEnv, run string, route string, info string, infoReq string, tkn string) { accept_langs := strings.Split(c.Request.Header.Get("Accept-Language"),";") langs := strings.Split(accept_langs[0], ",") - ip, _ := getIP(c.Request) + ip, _ := getIP(c.Request,false) // header, _ := ioutil.ReadAll(c.Request.Header) //println(string(c.header)) // println(c.Header) @@ -125,7 +132,7 @@ func logRequest(c *gin.Context, rtenv *RouteEnv, run string, route string, info func requestInfo(c *gin.Context, rtenv *RouteEnv, run string, route string, tkn string) LogInfo { accept_langs := strings.Split(c.Request.Header.Get("Accept-Language"),";") langs := strings.Split(accept_langs[0], ",") - ip, _ := getIP(c.Request) + ip, _ := getIP(c.Request,false) return LogInfo{ Run: run, Route: route,