Esempio n. 1
0
// DeleteSession terminates specified session.
func DeleteSession(params martini.Params, enc encoder.Encoder) (int, []byte) {
	token, ok := params["token"]
	if !ok {
		return http.StatusBadRequest, []byte("No token passed")
	}
	log.Printf("api: requesting session deletion for token %q", token)

	session, err := global.SessionRegistry.SessionByToken(token)
	if err != nil {
		log.Println(err)
		return http.StatusNotFound, []byte("No such session")
	}

	errch := session.Driver().Terminate()
	if err := <-errch; err != nil {
		log.Println(err)
		return http.StatusInternalServerError, []byte("Unable to terminate session")
	}

	info := struct {
		Status string `json:"status"`
	}{
		"ok",
	}
	return http.StatusOK, encoder.Must(enc.Encode(info))
}
Esempio n. 2
0
// SessionByToken responds to the API request to the session by token
func SessionByToken(params martini.Params, enc encoder.Encoder) (int, []byte) {
	token, ok := params["token"]
	if !ok {
		return http.StatusBadRequest, []byte("No token passed")
	}
	log.Printf("api: requesting session info for token %q", token)

	session, err := global.SessionRegistry.SessionByToken(token)
	if err != nil {
		log.Println(err)
		return http.StatusNotFound, []byte("No such session")
	}

	info := struct {
		State        string `json:"state"`
		ProfileName  string `json:"profile"`
		TunnelsCount uint32 `json:"tunnels_count"`
	}{
		session.Driver().State().String(),
		session.Profile().Name,
		session.TunnelsCount(),
	}
	return http.StatusOK, encoder.Must(enc.Encode(info))
}