Ejemplo n.º 1
0
func (dal *SQLDal) SaveRedirectRequest(req *RedirectRequest) error {
	//If there are no agent types, the types dont begin with mozilla or opera, or they contain bot, ignore the request
	defer dal.Close()
	if len(req.AgentTypes) == 0 {
		return nil
	}

	agent := user_agent.UserAgent{}
	agent.Parse(req.AgentTypes[0])
	if agent.Bot() {
		return nil
	}

	linkId, err := dal.GetLinkId(req.Path, req.Host)
	if err != nil {
		fmt.Print(err)
		return err
	}

	ipNumber := inet_aton(net.ParseIP(req.IpAddress))
	country, code, err := dal.GetCountry(ipNumber)
	if err != nil {
		fmt.Print(err)
	}
	fmt.Println("LinkID: " + strconv.Itoa(linkId))
	resp, err := dal.sqlConn.Exec(`INSERT INTO FrontEnd_linkstat (Link_id,Referer,IpAddress,CountryCode,Country,TimeClicked) 
											VALUES(?,?,?,?,?,NOW())`,
		linkId, req.RefererUrl, req.IpAddress, code, country)

	if err != nil {
		fmt.Print(err)
		return err
	} else {

		//Now save all of the Agent Types and languages
		statId, err := resp.LastInsertId()
		if err != nil {
			//There was an error somewhere, exit
			return err
		}

		//increment the link total
		err = dal.IncrementTotal(linkId)
		if err != nil {
			return err
		}

		err = dal.saveAgentTypes(&agent, statId, req.AgentTypes[0])
		if err != nil {
			return err
		}

		//Last call, just return
		return dal.saveLanguages(req, statId)
	}
}
Ejemplo n.º 2
0
func (dal *SQLDal) saveAgentTypes(agent *user_agent.UserAgent, linkClickId int64, uaString string) error {
	browser, version := agent.Browser()
	browserString := browser + "/" + version
	_, err := dal.sqlConn.Exec("INSERT INTO FrontEnd_linkagenttype(Stat_Id,AgentType,Browser,OS,Device) VALUES(?, ?, ?, ?, ?)",
		linkClickId, uaString, browserString, agent.OS(), agent.Platform())

	return err
}