Exemplo n.º 1
0
func configHandler(w http.ResponseWriter, r *http.Request) {
	auth_err := checkAuth(w, r)
	if auth_err != nil {
		return
	}
	t, err := loadTemplate("config.html")
	if err != nil {
		http.Error(w, err.Error(), http.StatusNotFound)
		return
	}
	str_id := r.FormValue("id")
	id, id_err := strconv.Atoi(str_id)
	if id_err != nil {
		http.Error(w, err.Error(), http.StatusNotFound)
		return
	}
	dev, dev_err := core.GetDeviceById(id)
	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)
	// Now that we know we have a device setup hack session
	if dev.GetHackSession() == nil {
		hacks := hacksession.HackSession{}
		hacks.SetState(hacksession.STATE_CONFIG)
		hacks.SetDeviceId(dev.GetId())
		user.SetDeviceId(dev.GetId())
		dev.SetHackSession(&hacks)
	}
	data := ConfigTemplate{}
	data.Device = dev
	exec_err := t.Execute(w, data)
	if exec_err != nil {
		fmt.Println("Config Error: ", exec_err)
	}
}
Exemplo n.º 2
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)
}