Ejemplo n.º 1
0
func lobbyHandler(w http.ResponseWriter, r *http.Request) {
	auth_err := checkAuth(w, r)
	if auth_err != nil {
		return
	}
	t, err := loadTemplate("lobby.html")
	if err != nil {
		http.Error(w, err.Error(), http.StatusNotFound)
		return
	}
	session, _ := store.Get(r, "canibus")
	userName := session.Values["user"].(string)
	user, _ := core.GetUserByName(userName)
	if user.GetDeviceId() != 0 {
		leaveDevice(user)
	}
	data := LobbyTemplate{}
	data.Host = r.Host
	data.Config = core.GetConfig()
	data.NumOfUsers = core.NumberOfUsers()
	exec_err := t.Execute(w, data)
	if exec_err != nil {
		fmt.Println("Lobby Error: ", exec_err)
	}
}
Ejemplo n.º 2
0
func joinHaxHandler(w http.ResponseWriter, r *http.Request) {
	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)

	hax := dev.GetHackSession()
	hax.AddUser(user)
	var p *Page
	var err error
	if hax.GetStateValue() == hacksession.STATE_SNIFF {
		p, err = loadPage("partials/sniff.html")
	} else {
		p, err = loadPage("partials/config.html")
	}
	if err != nil {
		http.Error(w, err.Error(), http.StatusNotFound)
		return
	}
	fmt.Fprintf(w, "%s", p.Body)
}
Ejemplo n.º 3
0
func haxStopHandler(w http.ResponseWriter, r *http.Request) {
	logger.Log("Stop Sniffer")
	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)

	hax := dev.GetHackSession()
	if hax == nil {
		http.Error(w, "Session not configured", http.StatusNotFound)
		return
	}
	if !hax.IsActiveUser(user) {
		http.Error(w, "You are not a part of this hacksession", http.StatusNotFound)
		return
	}
	dev.StopSniffing()
	fmt.Fprintf(w, "%s", "OK")
}
Ejemplo n.º 4
0
func haxTransmitHandler(w http.ResponseWriter, r *http.Request) {
	logger.Log("Transmit Packet")
	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)

	hax := dev.GetHackSession()
	if hax == nil {
		http.Error(w, "Session not configured", http.StatusNotFound)
		return
	}
	if !hax.IsActiveUser(user) {
		http.Error(w, "You are not a part of this hacksession", http.StatusNotFound)
		return
	}
	jsonTx := r.FormValue("tx")
	var TxPkts []api.TransmitPacket
	jerr := json.Unmarshal([]byte(jsonTx), &TxPkts)
	if jerr != nil {
		logger.Log("Transmit unmarshal error on: " + jsonTx)
		http.Error(w, jerr.Error(), http.StatusNotFound)
		return
	}
	for i := range TxPkts {
		inject_err := hax.InjectPacket(user, TxPkts[i])
		if inject_err != nil {
			logger.Log("Transmit packet error: " + inject_err.Error())
			http.Error(w, inject_err.Error(), http.StatusNotFound)
			return
		}
	}
	fmt.Fprintf(w, "%s", "OK")
}
Ejemplo n.º 5
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)
	}
}
Ejemplo n.º 6
0
func haxPacketsHandler(w http.ResponseWriter, r *http.Request) {
	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)

	hax := dev.GetHackSession()
	if hax == nil {
		http.Error(w, "Session not configured", http.StatusNotFound)
		return
	}
	if !hax.IsActiveUser(user) {
		http.Error(w, "You are not a part of this hacksession", http.StatusNotFound)
		return
	}
	packets := hax.GetPackets(user)

	j, err := json.Marshal(packets)
	if err != nil {
		logger.Log("Could not convert can packets to json")
		return
	}
	fmt.Fprintf(w, "%s", j)
}
Ejemplo n.º 7
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)
}