diff --git a/node/api.go b/node/api.go index 5e2fcde..30ab927 100644 --- a/node/api.go +++ b/node/api.go @@ -143,7 +143,13 @@ func (es ESConf) UPointHandler(w http.ResponseWriter, r *http.Request) { LogRequest(r) // Log request - content, _ := ioutil.ReadAll(r.Body) + content, err := ioutil.ReadAll(r.Body) + if err != nil { + log.Error("Fail to parse POST body: ", err.Error()) + w.WriteHeader(500) + w.Write([]byte(fmt.Sprintf("error: %s", err.Error()))) + return + } log.Debugf("Point request is: ", string(content)) // Get plain POST variables @@ -152,6 +158,10 @@ func (es ESConf) UPointHandler(w http.ResponseWriter, r *http.Request) { } pauth := r.Form.Get("pauth") tmsg := r.Form.Get("tmsg") + if pauth == "" && tmsg == "" { + log.Debug("Trying parse body request") + pauth, tmsg = parsePointBody(string(content)) + } req.Pauth = pauth req.Tmsg = tmsg diff --git a/node/helpers.go b/node/helpers.go index 2830d1b..46a3d85 100644 --- a/node/helpers.go +++ b/node/helpers.go @@ -1,11 +1,13 @@ package node import ( - "log" "time" mrand "math/rand" + "strings" + + log "github.com/Sirupsen/logrus" "golang.org/x/crypto/bcrypt" ) @@ -28,3 +30,25 @@ func genAuthString() []byte { return authString } + +// parsePointBody without regexp +// it dirty hack mades because *http.Request.Form not parsed it +func parsePointBody(content string) (string, string) { + var pauth, tmsg string + log.Debug("Body parser: ", content) + if strings.Contains(content, "&") { + log.Debug("Found &") + for _, v := range strings.Split(content, "&") { + if strings.Contains(v, "pauth") { + log.Debug("Found pauth") + pauth = strings.Split(v, "pauth=")[1] + } + if strings.Contains(v, "tmsg") { + log.Debug("Found tmsg") + tmsg = strings.Split(v, "tmsg=")[1] + } + } + } + + return pauth, tmsg +}