Example #1
0
func (h *Homepage) isiOS() bool {
	ua := uaparser.Parse(h.r.UserAgent())
	desktop, _ := h.r.Cookie("mw-desktop")

	return desktop != nil ||
		ua.Device.Name == "iPad" ||
		ua.Device.Name == "iPod" ||
		ua.Device.Name == "iPhone"
}
Example #2
0
func ParseRequest(args handler.RegexpArgs, r *http.Request) Event {
	// move it into init
	gi, err := geoip.Open(GEOIP_DATA)
	if err != nil {
		log.Fatal("Could not open GEOIP")
	}
	remote_ip := strings.Split(r.RemoteAddr, IP_SEP)[0]

	// FIXME scopes?
	// apparently I have no clue in understanding difference between = and :=
	country_code := "???"
	//tz := "???"
	if strings.HasPrefix(remote_ip, "192.168.") || strings.HasPrefix(remote_ip, "10.") || strings.HasPrefix(remote_ip, "127.") {
		//server side
		country_code = "GB"
		//tz = "Europe/London"
	} else {
		//client side
		country_code = "???"
		// return self.geoip.country_code_by_addr(self.request.remote_ip)
		//tz = "???"
		//return self.geoip.time_zone_by_addr(self.request.remote_ip)
	}

	country, geo_err := gi.GetCountry(remote_ip)
	if geo_err != 0 {
		log.Fatal("Could not resolve country")
	}

	log.Printf(country)

	user_agent := r.Header.Get("User-Agent")
	uainfo := uaparser.Parse(user_agent)

	event := Event{
		recipient_identifier: args["recipient_id"],
		job_identifier:       args["job_id"],
		blakey_identifier:    args["blakey_id"],
		link_id:              args["link_id"],
		link:                 args["link"],
		remote_ip:            remote_ip,
		user_agent:           user_agent,
		os:                   strings.Trim(uainfo.OS.Name+" "+uainfo.OS.Version, " "),
		client:               uainfo.Browser.Name,
		client_version:       uainfo.Browser.Version,
		country_code:         country_code,
	}
	return event
}