Exemplo n.º 1
0
func Router(session *mgo.Session) func(http.ResponseWriter, *http.Request) {
	return func(w http.ResponseWriter, req *http.Request) {
		user_agent := new(ua.UserAgent)
		user_agent.Parse(req.Header.Get("User-Agent"))

		url := req.FormValue("url")

		engine_name, engine_version := user_agent.Engine()
		browser_name, browser_version := user_agent.Browser()

		url_document := &URL{
			Date:           time.Now(),
			Uri:            url,
			Mobile:         user_agent.Mobile(),
			Bot:            user_agent.Bot(),
			Mozilla:        user_agent.Mozilla(),
			Platform:       user_agent.Platform(),
			Os:             user_agent.OS(),
			EngineName:     engine_name,
			EngineVersion:  engine_version,
			BrowserName:    browser_name,
			BrowserVersion: browser_version,
		}

		c := session.DB("goanywhere").C("urls")

		err := c.Insert(url_document)

		if err != nil {
			panic(err)
		}

		http.Redirect(w, req, url, http.StatusFound)
	}
}
Exemplo n.º 2
0
func ParseUserAgent(req *http.Request) *UserAgent {
	ua := new(user_agent.UserAgent)
	ua.Parse(req.UserAgent())
	val := &UserAgent{
		Header:   req.UserAgent(),
		Bot:      ua.Bot(),
		Mobile:   ua.Mobile(),
		Platform: ua.Platform(),
		OS:       ua.OS(),
		Make:     req.UserAgent(), // TODO - fix the library
	}
	val.Browser, val.BrowserVersion = ua.Browser()
	return val
}
Exemplo n.º 3
0
func (this *RequestParser) Parse(req *http.Request) (r *Request, err error) {
	r = &Request{}
	r.Country, err = this.geo(req)
	ua := new(user_agent.UserAgent)
	ua.Parse(req.UserAgent())
	r.Referrer = req.Referer()
	if r.Referrer == "" {
		r.Referrer = "DIRECT"
	}
	r.Bot = ua.Bot()
	r.Mobile = ua.Mobile()
	r.OS = ua.OS()
	r.Browser, r.Version = ua.Browser()
	return r, err
}
Exemplo n.º 4
0
func prefix(r *http.Request) string {
	ua := new(user_agent.UserAgent)
	ua.Parse(r.UserAgent())

	os := ua.OS()
	var ret string
	if strings.Contains(os, "Linux") {
		ret = "lin"
	} else if strings.Contains(os, "Windows") {
		ret = "win"
	} else {
		ret = "srv"
	}

	return ret
}
Exemplo n.º 5
0
func ProcessAndSend(params map[string]string, query url.Values, publisher *udp.Publisher) {
	defer func() {
		if err := recover(); err != nil {
			log.Println("Goroutine failed:", err)
		}
	}()

	data := make(map[string]interface{})

	data["app"] = params["app_name"]
	data["account"] = params["account_name"]

	ua := new(user_agent.UserAgent)
	ua.Parse(params["ua"])

	name, version := ua.Browser()

	browser := make(map[string]string)
	browser["name"] = name
	browser["version"] = version
	browser["os"] = ua.OS()

	data["browser"] = browser

	for k, _ := range query {
		if k != "ua" {
			data[k] = query[k][0]
		}
	}

	event := make(map[string]interface{})
	event["time"] = time.Now()
	event["type"] = params["type"]
	event["data"] = data

	publisher.Publish(event)
}
Exemplo n.º 6
0
func (this *RequestParser) Browser(req *http.Request) (bot bool, mobile bool, os string, browser string, version string) {
	ua := new(user_agent.UserAgent)
	ua.Parse(req.UserAgent())
	browserName, browserVersion := ua.Browser()
	return ua.Bot(), ua.Mobile(), ua.OS(), browserName, browserVersion
}