|
|
|
@@ -79,14 +79,25 @@ func getLeadIDFromCookie(r *http.Request) (leadID string, ok bool) { |
|
|
|
|
|
|
|
func createNewCookie(r *http.Request) (ret http.Cookie, info crmdLead) { |
|
|
|
info = crmCreateNewAnonymousLeadByHTTPRequest(r) |
|
|
|
ret = createNewCookieByLeadID(info.ID) |
|
|
|
ret = cookieFromLeadID(info.ID) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
func createNewCookieByLeadID(leadID string) (ret http.Cookie) { |
|
|
|
func cookieFromLeadID(leadID string) (ret http.Cookie) { |
|
|
|
return cookieCreateLongTerm(cookLeadID, leadID) |
|
|
|
} |
|
|
|
|
|
|
|
func cookieCreateLongTerm(name, value string) (ret http.Cookie) { |
|
|
|
expiration := time.Now().Add(10 * 365 * 24 * time.Hour) |
|
|
|
cookieValue := buildBiukopCLValue(leadID) |
|
|
|
ret = http.Cookie{Name: cookLeadID, Value: cookieValue, Expires: expiration} |
|
|
|
signedValue := cookieSignValue(value) |
|
|
|
ret = http.Cookie{Name: name, Value: signedValue, Expires: expiration} |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
func cookieCreate(name, value string, expireInSeconds int) (ret http.Cookie) { |
|
|
|
expiration := time.Now().Add(time.Duration(expireInSeconds) * time.Second) |
|
|
|
signedValue := cookieSignValue(value) |
|
|
|
ret = http.Cookie{Name: name, Value: signedValue, Expires: expiration} |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
@@ -148,7 +159,7 @@ func buildBiukopCLsignature(id, nonce string) (timestamp, signature string) { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
func buildBiukopCLValue(id string) (ret string) { |
|
|
|
func cookieSignValue(id string) (ret string) { |
|
|
|
rand.Seed(time.Now().Unix()) |
|
|
|
nonce := fmt.Sprintf("%d", rand.Intn(655352017)) |
|
|
|
timestamp, signature := buildBiukopCLsignature(id, nonce) |
|
|
|
@@ -184,25 +195,53 @@ func crmpixelLead(id string) (info crmdLead, err error) { |
|
|
|
// |
|
|
|
func setTrackingCookieAndRecirect(w http.ResponseWriter, r *http.Request) { |
|
|
|
|
|
|
|
rq := r.URL.RawQuery |
|
|
|
m, _ := url.ParseQuery(rq) |
|
|
|
//check signature and then perform redirect |
|
|
|
if !checkSignatureByToken(r, IntraAPIConfig.CRMSecrete) { |
|
|
|
response403Handler(w) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
m, err := url.ParseQuery(r.URL.RawQuery) |
|
|
|
if err != nil { |
|
|
|
response400Handler(w) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
url, ok := m["url"] |
|
|
|
if !ok { |
|
|
|
response400Handler(w) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
//set cookie if any |
|
|
|
leadID, ok := m["lid"] |
|
|
|
if ok { |
|
|
|
log.Println("setlead cookie :" + leadID[0]) |
|
|
|
cookie := createNewCookieByLeadID(leadID[0]) |
|
|
|
cookie := cookieFromLeadID(leadID[0]) |
|
|
|
http.SetCookie(w, &cookie) |
|
|
|
} else { |
|
|
|
cookie := crmpixelCookie(r) |
|
|
|
http.SetCookie(w, &cookie) |
|
|
|
} |
|
|
|
|
|
|
|
url, ok := m["url"] |
|
|
|
//get expire settings if any |
|
|
|
expire := 7200 //2 hours |
|
|
|
expireTime, ok := m["expire"] |
|
|
|
if ok { |
|
|
|
http.Redirect(w, r, url[0], 307) //302 temp redirect |
|
|
|
return |
|
|
|
expire, _ = strconv.Atoi(expireTime[0]) |
|
|
|
} |
|
|
|
w.WriteHeader(http.StatusNotFound) |
|
|
|
fmt.Fprintf(w, "Not Found URL") |
|
|
|
|
|
|
|
//set all cookie from url |
|
|
|
for k, v := range m { |
|
|
|
if k == "lid" || k == "url" || k == "expire" { //skip lead id and URL and expire |
|
|
|
continue |
|
|
|
} |
|
|
|
log.Printf("set cookie %s=%s", k, v) |
|
|
|
cookie := cookieCreate(k, v[0], expire) |
|
|
|
http.SetCookie(w, &cookie) |
|
|
|
} |
|
|
|
|
|
|
|
//perform redirect |
|
|
|
http.Redirect(w, r, url[0], 307) //302 temp redirect |
|
|
|
return |
|
|
|
} |