Ejemplo n.º 1
0
func login() {

	usr, pwd := "", ""

	if *usrF != "" && *pwdF != "" {
		usr = *usrF
		pwd = *pwdF
	} else {
		usr, pwd = getCreds()
	}

	cert, err := spi.Login(usr, pwd)
	if err != nil {
		cli.Fatal(fmt.Sprintf("login failed: %v", err))
	}

	localUser, err := user.Current()
	if err != nil {
		cli.Fatal(fmt.Sprintf("could not get current user: %v", err))
	}

	spiDir := localUser.HomeDir + "/.spi"
	os.MkdirAll(spiDir, 0755)

	ioutil.WriteFile(spiDir+"/spi.cert", cert, 0644)
	ioutil.WriteFile(spiDir+"/spi.user", []byte(usr), 0644)
}
Ejemplo n.º 2
0
Archivo: spi.go Proyecto: cycps/addie
func CreateDeterXP(user string, dsg *addie.Design) error {

	xp := DesignTopDL(dsg)

	//create a session with the DeterLab SPI
	_, err := spi.Login("deterboss", "muffins")
	if err != nil {
		log.Println(err)
		return fmt.Errorf("unable to login as deterboss")
	}

	topdl, err := xml.MarshalIndent(xp, "  ", "  ")
	if err != nil {
		log.Println(err)
		return fmt.Errorf("failed to serialize topology to topdl xml")
	}

	createResponse, err := spi.CreateExperiment(
		user+":"+dsg.Name, "deterboss", string(topdl), false)

	if err != nil {
		log.Println(err)
		return fmt.Errorf("failed to create experiment")
	}
	log.Printf("createResponse: %v", createResponse)

	return nil
}
Ejemplo n.º 3
0
Archivo: main.go Proyecto: cycps/addie
func onLogin(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {

	u := r.FormValue("username")
	p := r.FormValue("password")

	log.Printf("user login: '******'", u)

	isValidUser, err := authUser(u, p)
	if err != nil {
		log.Println(err)
		log.Println("user auth failed")
		w.WriteHeader(500)
		return
	}
	if !isValidUser {
		log.Printf("scalawagerry detected from '%s'", u)
		w.WriteHeader(401) //unauthorized
		return
	}

	//if we are here the user is valid
	cookie, err := newSessionCookie()
	if err != nil {
		log.Println("error creating session cookie")
		log.Println(err)
		w.WriteHeader(500)
		return
	}
	userCookies[cookie.Value] = u
	http.SetCookie(w, cookie)

	//log into the DeterLab SPI
	cert, err := spi.Login(u, p)
	if err != nil {
		log.Println("Unable to login to Deter")
		log.Println(err)
		w.WriteHeader(401) //unauthorized
	}
	//if the cert is empty that means we are already logged in and the existing
	//cert file should be fine
	err = os.MkdirAll("/cypress/"+u, 0755)
	if err != nil {
		log.Println(err)
		log.Printf("failed to create user directory for %s", u)
	}

	if string(cert) != "" {
		err := ioutil.WriteFile("/cypress/"+u+"/spi.cert", cert, 0644)
		if err != nil {
			log.Println(err)
			log.Printf("failed to write user cert for %s", u)
		}
	}

	log.Printf("user login success: '%s'", u)

	w.WriteHeader(200)
}