diff --git a/controllers/api_controller.go b/controllers/api_controller.go index 621cabed4..ae552fe0f 100644 --- a/controllers/api_controller.go +++ b/controllers/api_controller.go @@ -12,6 +12,7 @@ import ( "git.rosy.net.cn/jx-callback/globals" "github.com/astaxie/beego/client/orm" "github.com/astaxie/beego/server/web" + "net/http" "net/url" "reflect" "strings" @@ -249,7 +250,7 @@ func (c *ApiController) UpdatePrinter(dataMap map[string]interface{}) (data, err printNo, name, sim, sound string appID, volume int ) - globals.SugarLogger.Debugf("Begin API UpdatePrinter data: [%v]", utils.Format4Output(dataMap, false)) + globals.SugarLogger.Debugf("Begin API UpdatePrinter data: [%v], ip: %v", utils.Format4Output(dataMap, false), getRealRemoteIP(c.Ctx.Request)) if _, ok := dataMap[keyPrintNo].(string); !ok { return buildParamErrCodeAndErr(keyPrintNo) } else { @@ -377,3 +378,18 @@ func (c *ApiController) GetPrinterStatus(dataMap map[string]interface{}) (data, } return data, errCode, err } + +func getRealRemoteIP(r *http.Request) (ip string) { + if r != nil { + ip = r.Header.Get("X-Forwarded-For") + if ip == "" { + ip = r.Header.Get("X-real-ip") + } + if ip == "" { + ip = strings.Split(r.RemoteAddr, ":")[0] + } else { + ip = strings.Split(ip, ",")[0] + } + } + return ip +}