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) }
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") }
// Cleans up user module when exiting a device func leaveDevice(user api.User) { dev_id := user.GetDeviceId() if dev_id == 0 { return } dev, _ := core.GetDeviceById(dev_id) hax := dev.GetHackSession() if hax == nil { return } hax.RemoveUser(user) if hax.NumOfUsers() == 0 { dev.SetHackSession(nil) } }
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") }
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) } }
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) }
func candeviceInfoHandler(w http.ResponseWriter, r *http.Request) { 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 } data := CanDeviceJSON{} data.Id = dev.GetId() data.DeviceType = dev.DeviceType() data.DeviceDesc = dev.DeviceDesc() j, err := json.Marshal(data) if err != nil { logger.Log("Could not convert candevices to json") return } fmt.Fprintf(w, "%s", j) }
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) }