func main() { var port = flag.Int("port", 8081, "port") var debug = flag.Bool("debug", false, "run in debug mode") var domain = flag.String("domain", "thymio.tk", "Domain name (for the cookie)") var mongoServer = flag.String("mongo-server", "localhost", "MongoDB server URL") var secretKey = flag.String("secret-key", "not-so-secret", "Secret key (for secure cookies)") flag.Parse() if *debug { log.SetLevel(log.DebugLevel) log.Debug("Debug mode") } else { log.SetLevel(log.InfoLevel) } var err error mongoSession, err := mgo.Dial(*mongoServer) if err != nil { log.Fatal(err) } database = mongoSession.DB(dbName) store = mongostore.NewMongoStore( database.C(sessionC), 0, true, []byte(*secretKey)) store.Options.Domain = *domain r := mux.NewRouter() // Info r.HandleFunc(prefix+"/info", GetInfo).Methods("GET") // Card management r.HandleFunc(prefix+"/card/{cardId}", GetCard).Methods("GET") r.HandleFunc(prefix+"/card/{cardId}", PutCard).Methods("PUT", "POST") // Robot management r.HandleFunc(prefix+"/robots", GetRobots).Methods("GET") r.HandleFunc(prefix+"/robot/{robotName}", GetRobot).Methods("GET") r.HandleFunc(prefix+"/robot/{robotName}", PutRobot).Methods("PUT", "POST") r.HandleFunc(prefix+"/robot/{robotName}", DelRobot).Methods("DELETE") r.HandleFunc(prefix+"/robot/{robotName}/ping", PingRobot).Methods("GET") // Robot/Card associations r.HandleFunc(prefix+"/robot/{robotName}/card/{cardId}", AssociateRobot).Methods("PUT", "POST") r.HandleFunc(prefix+"/robot/{robotName}/card", DissociateRobot).Methods("DELETE") // Robot control r.HandleFunc(prefix+"/card/{cardId}/ping", PingCardRobot).Methods("GET") r.HandleFunc(prefix+"/card/{cardId}/run", RunCardRobot).Methods("GET") r.HandleFunc(prefix+"/card/{cardId}/stop", StopCardRobot).Methods("GET") r.HandleFunc(prefix+"/card/{cardId}/upload", UploadCardRobot).Methods("GET", "PUT", "POST") http.Handle("/", &CorsServer{r}) log.Infof("Ready, listening on port %d", *port) log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", *port), nil)) }
func initializeAuth(authCfg conf.AuthConfig) error { //Load authorization middleware for session //TODO - make this plugin based, we should be able //to plug in based on the configuration - token, jwt token etc //Right we are supporting only session based auth session := db.GetDatastore().Copy() c := session.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_SESSION_STORE) Store = mongostore.NewMongoStore(c, DefaultMaxAge, true, []byte("SkyRing-secret")) //Initailize the backend auth provider based on the configuartion if aaa, err := authprovider.InitAuthProvider(authCfg.ProviderName, authCfg.ConfigFile); err != nil { logger.Get().Error("Error Initializing the Authentication Provider. error: %v", err) return err } else { AuthProviderInstance = aaa } AddDefaultUser() return nil }
func main() { var port = flag.Int("port", 8080, "port") var debug = flag.Bool("debug", false, "run in debug mode") var domain = flag.String("domain", "thymio.tk", "Domain name (for the cookie)") var mongoServer = flag.String("mongo-server", "localhost", "MongoDB server URL") var cookieSecretKey = flag.String("cookie-secret-key", "not-so-secret", "Secret key (for secure cookies)") adminSecretKey = flag.String("admin-secret-key", "change-me", "Secret key (for admin card-login)") startSecretKey = flag.String("start-secret-key", "", "Secret key (for start ID)") flag.Parse() if *debug { log.SetLevel(log.DebugLevel) log.Debug("Debug mode") } else { log.SetLevel(log.InfoLevel) } if *startSecretKey == "" { log.Warn("Running without start id validation") } else { log.Info("Start id validation enabled") } var err error database, err = mgo.Dial(*mongoServer) if err != nil { log.Fatal(err) } store = mongostore.NewMongoStore( database.DB(dbName).C(sessionC), maxAge, true, []byte(*cookieSecretKey)) store.Options.Domain = *domain tpls := template.Must(template.ParseGlob("internal_pages/templates/*")) nameList, err := filepath.Glob("internal_pages/*.html") if err != nil { panic(err) } for _, name := range nameList { log.Debugf("Reading %s", name) key := filepath.Base(name) t, _ := tpls.Clone() templates[key] = t _, err = templates[key].ParseFiles(name) if err != nil { panic(err) } } r := mux.NewRouter() r.HandleFunc("/start/{CardId}", Start) r.HandleFunc("/cardlogin/{CardId}", CardLogin) r.HandleFunc("/logout", Logout) r.HandleFunc("/debug", Debug) r.HandleFunc("/", Index) r.HandleFunc("/about", About) r.HandleFunc("/help", Help) r.NotFoundHandler = http.HandlerFunc(notFound) http.Handle("/img/", http.StripPrefix("/img/", http.FileServer(http.Dir("img")))) http.Handle("/css/", http.StripPrefix("/css/", http.FileServer(http.Dir("css")))) http.Handle("/vendor/", http.StripPrefix("/vendor/", http.FileServer(http.Dir("vendor")))) http.Handle("/", r) log.Infof("Ready, listening on port %d", *port) log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", *port), nil)) }
func NewMongoStore(collection *mgo.Collection, maxAge int, ensureTTL bool, keyPairs ...[]byte) MongoStore { store := mongostore.NewMongoStore(collection, maxAge, ensureTTL, keyPairs...) return &mongoStore{store} }
func setupMongostore() *mongostore.MongoStore { return mongostore.NewMongoStore(db.Database.C("sessions"), 3600, true, []byte("mariageP&BKey")) }