예제 #1
0
파일: analytics.go 프로젝트: 2722/lantern
func trackSession(args string, proxyAddrFN eventual.Getter) {
	r, err := http.NewRequest("POST", ApiEndpoint, bytes.NewBufferString(args))

	if err != nil {
		log.Errorf("Error constructing GA request: %s", err)
		return
	}

	r.Header.Add("Content-Type", "application/x-www-form-urlencoded")
	r.Header.Add("Content-Length", strconv.Itoa(len(args)))

	if req, err := httputil.DumpRequestOut(r, true); err != nil {
		log.Debugf("Could not dump request: %v", err)
	} else {
		log.Debugf("Full analytics request: %v", string(req))
	}

	var httpClient *http.Client
	httpClient, err = util.HTTPClient("", proxyAddrFN)
	if err != nil {
		log.Errorf("Could not create HTTP client: %s", err)
		return
	}
	resp, err := httpClient.Do(r)
	if err != nil {
		log.Errorf("Could not send HTTP request to GA: %s", err)
		return
	}
	log.Debugf("Successfully sent request to GA: %s", resp.Status)
	if err := resp.Body.Close(); err != nil {
		log.Debugf("Unable to close response body: %v", err)
	}
}
예제 #2
0
파일: flashlight.go 프로젝트: kidaa/lantern
func updateServerSideConfigClient(cfg *config.Config) {
	client, err := util.HTTPClient(cfg.CloudConfigCA, "")
	if err != nil {
		log.Errorf("Couldn't create http.Client for fetching the config")
		return
	}
	config.Configure(client)
}
예제 #3
0
파일: analytics.go 프로젝트: kidaa/lantern
func trackSession(ip string, version string, proxyAddr string, clientId string) {
	vals := make(url.Values, 0)

	vals.Add("v", "1")
	vals.Add("cid", clientId)
	vals.Add("tid", trackingId)

	// Override the users IP so we get accurate geo data.
	vals.Add("uip", ip)

	// Make call to anonymize the user's IP address -- basically a policy thing where
	// Google agrees not to store it.
	vals.Add("aip", "1")

	vals.Add("dp", "localhost")
	vals.Add("t", "pageview")

	// Custom variable for the Lantern version
	vals.Add("cd1", version)

	args := vals.Encode()

	r, err := http.NewRequest("POST", ApiEndpoint, bytes.NewBufferString(args))

	if err != nil {
		log.Errorf("Error constructing GA request: %s", err)
		return
	}

	r.Header.Add("Content-Type", "application/x-www-form-urlencoded")
	r.Header.Add("Content-Length", strconv.Itoa(len(args)))

	if req, err := httputil.DumpRequestOut(r, true); err != nil {
		log.Debugf("Could not dump request: %v", err)
	} else {
		log.Debugf("Full analytics request: %v", string(req))
	}

	var httpClient *http.Client
	httpClient, err = util.HTTPClient("", proxyAddr)
	if err != nil {
		log.Errorf("Could not create HTTP client via %s: %s", proxyAddr, err)
		return
	}
	resp, err := httpClient.Do(r)
	if err != nil {
		log.Errorf("Could not send HTTP request to GA: %s", err)
		return
	}
	log.Debugf("Successfully sent request to GA: %s", resp.Status)
	if err := resp.Body.Close(); err != nil {
		log.Debugf("Unable to close response body: %v", err)
	}
}
예제 #4
0
func enableAutoupdate(cfg *config.Config) {
	var err error

	httpClient, err = util.HTTPClient(cfg.CloudConfigCA, client.Addr)
	if err != nil {
		log.Errorf("Could not create proxied HTTP client, disabling auto-updates: %v", err)
		return
	}

	go watchForUpdate()
}
예제 #5
0
파일: analytics.go 프로젝트: shizhh/lantern
func Configure(trackingId string, version string, proxyAddr string) {
	var err error
	go func() {
		httpClient, err = util.HTTPClient("", proxyAddr)
		if err != nil {
			log.Errorf("Could not create HTTP client via %s: %s", proxyAddr, err)
			return
		}
		// Store new session info whenever client proxy is ready
		sessionEvent(version, trackingId)
	}()
}
예제 #6
0
// updateConfig attempts to pull a configuration file from the network using
// the client proxy itself.
func (client *Client) updateConfig() error {
	var err error
	var buf []byte
	var cli *http.Client

	if cli, err = util.HTTPClient(cloudConfigCA, client.addr); err != nil {
		return err
	}

	if buf, err = pullConfigFile(cli); err != nil {
		return err
	}

	return client.cfg.updateFrom(buf)
}
예제 #7
0
파일: analytics.go 프로젝트: kidaa/lantern
func Configure(addr string, trackingId string, version string, proxyAddr string) {
	ip = addr
	var err error
	go func() {
		httpClient, err = util.HTTPClient("", proxyAddr)
		if err != nil {
			log.Errorf("Could not create HTTP client via %s: %s", proxyAddr, err)
			return
		}
		// Store new session info whenever client proxy is ready
		if status, err := sessionEvent(trackingId, version); err != nil {
			log.Errorf("Unable to store new session info: %v", err)
		} else {
			log.Tracef("Storing new session info: %v", status)
		}
	}()
}
예제 #8
0
func (client *Client) initAnalytics() {
	var err error
	var cli *http.Client

	if cli, err = util.HTTPClient(cloudConfigCA, client.addr); err != nil {
		return
	}

	sessionPayload := &analytics.Payload{
		HitType:  analytics.EventType,
		Hostname: "localhost",
		Event: &analytics.Event{
			Category: "Session",
			Action:   "Start",
			Label:    runtime.GOOS,
		},
	}
	analytics.SessionEvent(cli, sessionPayload)
}