Ejemplo n.º 1
0
// main sets up the routes (thanks Gorilla!).
func main() {
	r := mux.NewRouter()
	r.HandleFunc("/", showIndex)
	r.HandleFunc("/about", showAbout)
	r.HandleFunc("/archives", showArchives)
	r.PathPrefix("/static").
		Handler(http.StripPrefix("/static",
			http.FileServer(http.Dir(staticPath))))

	// Password protect data refreshing
	authenticator := auth.NewBasicAuthenticator(
		"Refresh data", auth.HtpasswdFileProvider(*htpasswd))
	r.HandleFunc("/refresh", auth.JustCheck(authenticator, showRefresh))

	// These must be last. The first shows blog posts, the second adds comments.
	r.HandleFunc("/{postname}", showPost).Methods("GET")
	r.HandleFunc("/{postname}", addComment).Methods("POST")

	// Captcha!
	http.Handle("/captcha/",
		captcha.Server(captcha.StdWidth, captcha.StdHeight))

	// Okay, let Gorilla do its work.
	http.Handle("/", r)
	http.ListenAndServe(":8082", nil)
}
Ejemplo n.º 2
0
func main() {

	pwd, _ := os.Getwd()

	//Set config path and type
	viper.SetConfigName("config")
	viper.AddConfigPath(pwd)
	viper.AddConfigPath("/etc/ddesktop/")
	viper.SetConfigType("yaml")

	//Read config
	err := viper.ReadInConfig()
	if err != nil {
		log.Fatalln(err)
	}

	log.Println(viper.GetString("container.prefix"))

	//Cleanup existing containers
	dockerhandler.CleanUp()

	//Pull new docker image
	if viper.GetBool("container.pull") {
		dockerhandler.PullImage()
	}

	//Get authentication setting
	htpasswd := auth.HtpasswdFileProvider(viper.GetString("htpasswd.path"))
	authenticator := auth.NewBasicAuthenticator(".ddesktop", htpasswd)

	//Start server
	log.Printf("Starting server on http://0.0.0.0:" + viper.GetString("server.port.http") + " and https://0.0.0.0:" + viper.GetString("server.port.https") + "...")
	http.Handle("/websockify", auth.JustCheck(authenticator, wsproxy.WsProxy()))
	http.HandleFunc("/", auth.JustCheck(authenticator, server.Static()))

	go func() {
		if err := http.ListenAndServeTLS(":"+viper.GetString("server.port.https"), viper.GetString("ssl.cert"), viper.GetString("ssl.key"), nil); err != nil {
			log.Fatalln(err)
		}
	}()
	if err := http.ListenAndServe(":"+viper.GetString("server.port.http"), http.HandlerFunc(server.RedirectHttps)); err != nil {
		log.Fatalln(err)
	}
}
Ejemplo n.º 3
0
func middleware(h http.HandlerFunc, middleware ...func(http.HandlerFunc) http.HandlerFunc) http.HandlerFunc {
	for _, m := range middleware {
		h = m(h)
	}

	// TODO: Get this to only be setup once.
	authenticator := auth.NewBasicAuthenticator(
		"trajectory.com", GetSecret(getLoginConfig()))
	return auth.JustCheck(authenticator, h)
}
Ejemplo n.º 4
0
func main() {

	flag.Parse()

	// seed the RNG, otherwise we would have same randomness on every startup
	// which should not, but might in worst case interfere with leftover-mails
	// from earlier starts of the binary
	rand.Seed(time.Now().Unix())

	err := parse_conf(*conf_path)

	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	wg := new(sync.WaitGroup)
	wg.Add(len(globalconf.Servers))

	// now fire up the monitoring jobs
	for _, c := range globalconf.Servers {
		fmt.Println("starting monitoring for config", c["Name"])
		go monitor(c, wg)

		// keep a timedelta between monitoring jobs to avoid strong interference
		time.Sleep(startupOffsetTime)
	}

	fmt.Println("starting HTTP-endpoint")
	if *useAuth {
		authenticator := auth.NewBasicAuthenticator("prometheus", Secret)
		http.HandleFunc(globalconf.Http_endpoint, auth.JustCheck(authenticator, prometheus.Handler().ServeHTTP))
	} else {
		http.Handle(globalconf.Http_endpoint, prometheus.Handler())
	}

	if *useTLS {
		err = http.ListenAndServeTLS(":"+globalconf.Http_port, globalconf.Crt_path, globalconf.Key_path, nil)
	} else {
		err = http.ListenAndServe(":"+globalconf.Http_port, nil)
	}

	if err != nil {
		fmt.Println(err)
	}

	// wait for goroutines to exit
	// otherwise main would terminate and the goroutines monitoring would be killed
	wg.Wait()

}
Ejemplo n.º 5
0
func main() {
	folderPath, errpath := osext.ExecutableFolder()

	if errpath != nil {
		fmt.Printf("Couldn't get cwd. Check permissions!\n")
		return
	}

	if _, err := os.Stat(folderPath + ".htpasswd"); os.IsNotExist(err) {
		fmt.Printf(folderPath + ".htpasswd doesn't exist in cwd!\n")
		return
	}

	secrets := auth.HtpasswdFileProvider(folderPath + ".htpasswd")
	authenticator := auth.NewBasicAuthenticator("Seyes Echelon", secrets)

	http.HandleFunc("/record_log", auth.JustCheck(authenticator, handle))

	fmt.Println("Server starting on port " + os.Args[1] + " ....\n")
	http.ListenAndServe(":"+os.Args[1], nil)
}