Esempio n. 1
0
// RenderTemplate - render given templates.
func RenderTemplate(w http.ResponseWriter, ctx PageContextInterface, name string, filenames ...string) {
	ctemplate := getTemplate(name, logging.DebugLevel() > 0, filenames...)
	if ctemplate == nil {
		return
	}
	err := ctemplate.ExecuteTemplate(w, MainTemplateName, ctx)
	if err != nil {
		log.Error("RenderTemplate execution failed", "err", err, "name", name, "filenames", filenames)
	}
}
Esempio n. 2
0
func settingsPageHandler(w http.ResponseWriter, r *http.Request, bctx *BasePageContext) {
	ctx := &struct {
		*BasePageContext
		LogLevel      int
		Configuration string
	}{
		BasePageContext: bctx,
		LogLevel:        logging.DebugLevel(),
		Configuration:   bctx.Globals.Config.String(),
	}

	RenderTemplateStd(w, ctx, "settings.tmpl")
}
Esempio n. 3
0
func StartAdmin(globals *config.Globals) {

	debug := logging.DebugLevel() > 0

	InitSessionStore(globals.Config)
	appRouter.HandleFunc("/", SecurityContextHandler(mainPageHandler, globals, ""))

	appRouter.HandleFunc("/login", ContextHandler(loginPageHandler, globals)).Name("auth-login")
	appRouter.HandleFunc("/logout", logoffHandler)
	appRouter.HandleFunc("/chpass", SecurityContextHandler(chpassPageHandler, globals, ""))

	appRouter.HandleFunc("/logs", SecurityContextHandler(logsPageHandler, globals, "ADMIN"))

	InitUsersHandlers(globals, appRouter.PathPrefix("/users"))
	InitEndpointsHandlers(globals, appRouter.PathPrefix("/endpoints"))
	InitCertsHandlers(globals, appRouter.PathPrefix("/certs"))
	InitStatsHandlers(globals, appRouter.PathPrefix("/stats"))
	InitSettingsHandlers(globals, appRouter.PathPrefix("/settings"))

	http.Handle("/static/", http.StripPrefix("/static",
		FileServer(http.Dir(globals.Config.AdminPanel.StaticDir), debug)))
	http.Handle("/favicon.ico", FileServer(http.Dir(globals.Config.AdminPanel.StaticDir), debug))

	http.Handle("/", globals.StatsAdmin.Handler(common.LogHandler(CsrfHandler(SessionHandler(appRouter)), "admin:", "module", "admin")))

	if globals.Config.AdminPanel.HTTPSAddress != "" {
		log.Info("admin.StartAdmin Listen HTTPS ", "port", globals.Config.AdminPanel.HTTPSAddress)

		go func() {
			if err := http.ListenAndServeTLS(globals.Config.AdminPanel.HTTPSAddress,
				globals.Config.AdminPanel.SslCert, globals.Config.AdminPanel.SslKey, nil); err != nil {
				log.Error("admin.StartAdmin Error listening https, ", "err", err)
			}
		}()
	}

	if globals.Config.AdminPanel.HTTPAddress != "" {
		log.Info("admin.StartAdmin Listen", "port", globals.Config.AdminPanel.HTTPAddress)

		go func() {
			if err := http.ListenAndServe(globals.Config.AdminPanel.HTTPAddress, nil); err != nil {
				log.Error("admin.StartAdmin Error listening http, ", "err", err)
			}
		}()
	}
}