Ejemplo n.º 1
0
func configCanHandler(w http.ResponseWriter, r *http.Request) {
	logger.Log("Config CAN Device, checking auth...")
	auth_err := checkAuth(w, r)
	if auth_err != nil {
		return
	}
	vars := mux.Vars(r)
	canId, canId_err := strconv.Atoi(vars["id"])
	if canId_err != nil {
		http.Error(w, canId_err.Error(), http.StatusNotFound)
		return
	}
	dev, dev_err := core.GetDeviceById(canId)
	if dev_err != nil {
		http.Error(w, dev_err.Error(), http.StatusNotFound)
		return
	}
	session, _ := store.Get(r, "canibus")
	userName := session.Values["user"].(string)
	user, _ := core.GetUserByName(userName)

	if dev.GetHackSession() == nil {
		hacks := hacksession.HackSession{}
		hacks.SetState(hacksession.STATE_CONFIG)
		hacks.SetDevice(dev)
		user.SetDeviceId(dev.GetId())
		dev.SetHackSession(&hacks)
		hacks.AddUser(user)
	}

	p, err := loadPage("partials/config.html")
	if err != nil {
		http.Error(w, err.Error(), http.StatusNotFound)
		return
	}
	fmt.Fprintf(w, "%s", p.Body)
}