Exemple #1
0
func getRouterList(w http.ResponseWriter, r *http.Request) {
	log.Tracef("getRouterList")
	var (
		uid      string
		tid      string
		response ResponseRouterList
		router   RouterInfo
		devices  map[string]devcenter.Device
		err      error
	)

	response.Status = -1
	if r.Method != "GET" {
		response.Descr = "must using 'GET' method\n"
		goto resp
	}
	r.ParseForm()

	uid = r.FormValue("uid")
	if uid == "" {
		response.Descr = "missing 'uid'"
		goto resp
	}

	tid = r.FormValue("tid")
	if tid == "" {
		response.Descr = "missing 'tid'"
		goto resp
	}

	devices, err = devcenter.GetDevices(uid, devcenter.DEV_ROUTER)
	if err != nil {
		log.Errorf("GetDevices failed: %s", err.Error())
		response.Descr = err.Error()
		goto resp
	}

	for _, dev := range devices {
		router = RouterInfo{
			Rid:   dev.Id,
			Rname: dev.Title,
		}
		response.List = append(response.List, router)
	}

	//router = RouterInfo{
	//	Rid:   "c80e774a1e73",
	//	Rname: "router1",
	//}
	//response.List = append(response.List, router)

	response.Status = 0
	response.Descr = "OK"

resp:
	b, _ := json.Marshal(response)
	log.Debugf("getRoutelist write: %s", string(b))
	w.Write(b)
}
Exemple #2
0
func checkAuthz(uid string, devid string) bool {
	log.Tracef("checkAuthz")

	devices, err := devcenter.GetDevices(uid, devcenter.DEV_ROUTER)
	if err != nil {
		log.Errorf("GetDevices failed: %s", err.Error())
		return false
	}

	for _, dev := range devices {
		if devid == dev.Id {
			return true
		}
	}
	return false
}