Example #1
1
// Handler uses a multiplexing router to route http requests
func (ws *webServer) Handler() http.Handler {
	mux := mux.NewRouter()

	mux.PathPrefix("/t/cc/").HandlerFunc(ws.Cloudconfig).Methods("GET")
	mux.PathPrefix("/t/ig/").HandlerFunc(ws.Ignition).Methods("GET")
	mux.PathPrefix("/t/bp/").HandlerFunc(ws.Bootparams).Methods("GET")

	mux.HandleFunc("/api/version", ws.Version)

	mux.HandleFunc("/api/machines", ws.MachinesList)
	mux.HandleFunc("/api/machines/{mac}", ws.MachineDelete).Methods("DELETE")

	// mux.PathPrefix("/api/machine/").HandlerFunc(ws.NodeSetIPMI).Methods("PUT")

	// Machine variables; used in templates
	mux.PathPrefix("/api/machines/{mac}/variables").HandlerFunc(ws.MachineVariables).Methods("GET")
	mux.PathPrefix("/api/machines/{mac}/variables/{name}").HandlerFunc(ws.SetMachineVariable).Methods("PUT")
	mux.PathPrefix("/api/machines/{mac}/variables/{name}").HandlerFunc(ws.DelMachineVariable).Methods("DELETE")

	// Cluster variables; used in templates
	mux.PathPrefix("/api/variables/{name}").HandlerFunc(ws.GetClusterVariables).Methods("GET")
	mux.PathPrefix("/api/variables/{name}").HandlerFunc(ws.SetClusterVariables).Methods("PUT")
	mux.PathPrefix("/api/variables/{name}").HandlerFunc(ws.DelClusterVariables).Methods("DELETE")
	mux.PathPrefix("/api/variables").HandlerFunc(ws.ClusterVariablesList).Methods("GET")

	// TODO: returning other files functionalities
	mux.PathPrefix("/files/images/").Handler(http.StripPrefix("/files/images",
		http.FileServer(http.Dir(filepath.Join(ws.ds.WorkspacePath(), "images")))))
	mux.PathPrefix("/files/").Handler(http.StripPrefix("/files/",
		http.FileServer(http.Dir(filepath.Join(ws.ds.WorkspacePath(), "files")))))

	mux.Path("/ui").Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		http.Redirect(w, r, "/ui/", 302)
	}))

	mux.PathPrefix("/ui/").Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		index, _ := FSByte(false, "/static/index.html")
		w.Write(index)
	}))

	mux.PathPrefix("/static/").Handler(http.FileServer(FS(false)))

	mux.PathPrefix("/uploadworkspace/{hash}").HandlerFunc(ws.WorkspaceUploadHandler).Methods("POST")

	return mux
}
Example #2
0
func (a *RestServer) Mux() *mux.Router {
	mux := mux.NewRouter()
	mux.HandleFunc("/api/nodes", a.nodesList)
	mux.HandleFunc("/api/etcd-endpoints", a.etcdEndpoints)

	mux.HandleFunc("/upload/", a.upload)
	mux.HandleFunc("/files", a.files).Methods("GET")
	mux.HandleFunc("/files", a.deleteFile).Methods("DELETE")
	mux.PathPrefix("/files/").Handler(http.StripPrefix("/files/", http.FileServer(http.Dir(filepath.Join(a.runtimeConfig.WorkspacePath, "files")))))
	mux.PathPrefix("/ui/").Handler(http.FileServer(FS(false)))

	return mux
}
Example #3
0
// Handler uses a multiplexing router to route http requests
func (ws *webServer) Handler() http.Handler {
	mux := mux.NewRouter()

	mux.PathPrefix("/t/cc/").HandlerFunc(ws.Cloudconfig).Methods("GET")
	mux.PathPrefix("/t/ig/").HandlerFunc(ws.Ignition).Methods("GET")
	mux.PathPrefix("/t/bp/").HandlerFunc(ws.Bootparams).Methods("GET")

	mux.HandleFunc("/api/version", ws.Version)

	mux.HandleFunc("/api/nodes", ws.NodesList)
	mux.PathPrefix("/api/node/").HandlerFunc(ws.NodeFlags).Methods("GET")

	mux.PathPrefix("/api/flag/").HandlerFunc(ws.SetFlag).Methods("PUT")
	mux.PathPrefix("/api/flag/").HandlerFunc(ws.DelFlag).Methods("DELETE")

	mux.HandleFunc("/upload/", ws.Upload)
	mux.HandleFunc("/files", ws.Files).Methods("GET")
	mux.HandleFunc("/files", ws.DeleteFile).Methods("DELETE")
	mux.PathPrefix("/files/").Handler(http.StripPrefix("/files/",
		http.FileServer(http.Dir(filepath.Join(ws.ds.WorkspacePath(), "files")))))

	mux.PathPrefix("/ui/").Handler(http.FileServer(FS(false)))

	return mux
}
Example #4
0
func main() {
	log.Level = logrus.DebugLevel
	log.Print("Starting Reclus Issue Tracker...")

	if err := loadConfig(conf); err != nil {
		log.Fatal(err)
	}

	db, err := NewDatabase(conf)

	if err != nil {
		log.Fatal(err)
	}

	defer db.Close()

	if err = setupAuth(db); err != nil {
		log.Fatal(err)
	}

	mux := mux.NewRouter()

	mux.PathPrefix("/auth").Handler(authManager.NewRouter())
	mux.Handle("/", authProtect(loggedIn))

	http.ListenAndServe(":9090", mux)
}
Example #5
0
func main() {

	handlers := BaseHandlers()

	mux := mux.NewRouter()

	mux.HandleFunc("/", handlers.landing)
	mux.HandleFunc("/signup", handlers.signup)

	accounts := mux.PathPrefix("/account").Subrouter()
	accounts.HandleFunc("/", handlers.accountIndex)

	n := negroni.Classic()

	n.UseHandler(mux)
	n.Run(*httpAddr)
}
func main() {
	/*cookieStoreKey, _ := base64.StdEncoding.DecodeString(`uHQ6CzpKyNn4lif0o+f5VT9CbbklmJ/V2kdDMEIvh/ClCzrUF8tpRBQaUB1+JDe4jQ/QbFXwCib+4W8uaD/KGg==`)
	sessionStoreKey, _ := base64.StdEncoding.DecodeString(`+EbJe+rqHqCNdgE8zSrk3YwRnBdvuxVYf3sabsg2/G6Ek/fsU+pri8zVeoZzlo3Z2GNbR5Jj6ggEjjtqWrDJUg==`)
	cookieStore = securecookie.New(cookieStoreKey, nil)
	sessionStore = sessions.NewCookieStore(sessionStoreKey)*/

	setupAuthboss()

	mux := mux.NewRouter()

	// Routes

	mux.PathPrefix("/auth").Handler(ab.NewRouter())

	port := os.Getenv("PORT")
	if len(port) == 0 {
		port = "3030"
	}
	log.Println(http.ListenAndServe("localhost:"+port, nil))
}
Example #7
0
func main() {

	// Store
	var store = (configstore.Store)(file.NewFileStore("/var/tmp/data", file.DefaultDateFormat))

	// HTTP endpoints
	mux := mux.NewRouter()
	mux.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
	mux.HandleFunc("/api", apiDoc)
	mux.Handle("/", http.RedirectHandler("/dashboard", 302))
	mux.HandleFunc("/dashboard", func(w http.ResponseWriter, req *http.Request) {
		dashboard(store, w, req)
	})
	mux.HandleFunc("/hosts", func(w http.ResponseWriter, req *http.Request) {
		listHosts(store, w, req)
	})
	mux.HandleFunc("/hosts/{hostname}", func(w http.ResponseWriter, req *http.Request) {
		listDates(store, w, req)
	})
	mux.HandleFunc("/hosts/{hostname}/dates/{date}", func(w http.ResponseWriter, req *http.Request) {
		hostBackup(store, w, req)
	})
	mux.HandleFunc("/hosts/{hostname}/on/{date}", func(w http.ResponseWriter, req *http.Request) {
		showBackupDate(store, w, req)
	})
	mux.HandleFunc("/hosts/{hostname}/diff/{date1}/{date2}", func(w http.ResponseWriter, req *http.Request) {
		diffBackup(store, w, req)
	})

	// Start HTTP server
	s := &http.Server{
		Addr:    ":8080",
		Handler: mux,
	}
	s.ListenAndServe()

}
Example #8
0
func main() {
	// Initialize Sessions and Cookies
	// Typically gorilla securecookie and sessions packages require
	// highly random secret keys that are not divulged to the public.
	//
	// In this example we use keys generated one time (if these keys ever become
	// compromised the gorilla libraries allow for key rotation, see gorilla docs)
	// The keys are 64-bytes as recommended for HMAC keys as per the gorilla docs.
	//
	// These values MUST be changed for any new project as these keys are already "compromised"
	// as they're in the public domain, if you do not change these your application will have a fairly
	// wide-opened security hole. You can generate your own with the code below, or using whatever method
	// you prefer:
	//
	//    func main() {
	//        fmt.Println(base64.StdEncoding.EncodeToString(securecookie.GenerateRandomKey(64)))
	//    }
	//
	// We store them in base64 in the example to make it easy if we wanted to move them later to
	// a configuration environment var or file.
	cookieStoreKey, _ := base64.StdEncoding.DecodeString(`NpEPi8pEjKVjLGJ6kYCS+VTCzi6BUuDzU0wrwXyf5uDPArtlofn2AG6aTMiPmN3C909rsEWMNqJqhIVPGP3Exg==`)
	sessionStoreKey, _ := base64.StdEncoding.DecodeString(`AbfYwmmt8UCwUuhd9qvfNA9UCuN1cVcKJN1ofbiky6xCyyBj20whe40rJa3Su0WOWLWcPpO1taqJdsEI/65+JA==`)
	cookieStore = securecookie.New(cookieStoreKey, nil)
	sessionStore = sessions.NewCookieStore(sessionStoreKey)

	// Initialize ab.
	setupAuthboss()

	// Set up our router
	schemaDec.IgnoreUnknownKeys(true)
	mux := mux.NewRouter()

	// Routes
	gets := mux.Methods("GET").Subrouter()
	posts := mux.Methods("POST").Subrouter()

	mux.PathPrefix("/auth").Handler(ab.NewRouter())

	gets.Handle("/blogs/new", authProtect(newblog))
	gets.Handle("/blogs/{id}/edit", authProtect(edit))
	gets.HandleFunc("/blogs", index)
	gets.HandleFunc("/", index)

	posts.Handle("/blogs/{id}/edit", authProtect(update))
	posts.Handle("/blogs/new", authProtect(create))

	// This should actually be a DELETE but I can't be bothered to make a proper
	// destroy link using javascript atm.
	gets.HandleFunc("/blogs/{id}/destroy", destroy)

	mux.NotFoundHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		w.WriteHeader(http.StatusNotFound)
		io.WriteString(w, "Not found")
	})

	// Set up our middleware chain
	stack := alice.New(logger, nosurfing, ab.ExpireMiddleware).Then(mux)

	// Start the server
	port := os.Getenv("PORT")
	if len(port) == 0 {
		port = "3000"
	}
	log.Println(http.ListenAndServe("localhost:"+port, stack))
}