Skip to content
This repository was archived by the owner on Feb 25, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
SHELL = /bin/sh

# Go tool and library path:
GO = /usr/local/go/bin/go
GO = /usr/bin/go
GOPATH = `pwd`/golibs

# Installation directories:
Expand Down
4 changes: 4 additions & 0 deletions etc/zfswatcher.conf
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,10 @@ devstatecssclassmap = OFFLINE:text-warning REMOVED:text-error \
usedstatecssclassmap = none:bar-info info:bar-info notice:bar-warning \
err:bar-warning crit:bar-danger

;
; alternate root directory - formatted as /zfs
rootdir = ""

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; The "wwwuser" sections define usernames and passwords for the web
; interface. The username is listed in quotes after the section name.
Expand Down
1 change: 1 addition & 0 deletions setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ type cfgType struct {
Keyfile string
Templatedir string
Resourcedir string
Rootdir string
Severitycssclassmap severityToWwwClassMap
Poolstatecssclassmap stringToStringMap
Devstatecssclassmap stringToStringMap
Expand Down
21 changes: 12 additions & 9 deletions webpagehandlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ type webNav struct {
Statistics bool
Logs bool
About bool
Root string
}

type webSubNav struct {
Expand Down Expand Up @@ -104,6 +105,7 @@ type poolStatusWeb struct {
Avail int64
AvailPercent int
Total int64
Root string
}

type dashboardWeb struct {
Expand Down Expand Up @@ -166,6 +168,7 @@ func makePoolStatusWeb(pool *PoolType, usage map[string]*PoolUsageType) *poolSta
See: pool.see,
Scan: pool.scan,
Errors: pool.errors,
Root: cfg.Www.Rootdir,
}
statusWeb.Avail = -1
statusWeb.Used = -1
Expand Down Expand Up @@ -210,9 +213,9 @@ func makePoolStatusWeb(pool *PoolType, usage map[string]*PoolUsageType) *poolSta
}

func statusHandler(w http.ResponseWriter, r *auth.AuthenticatedRequest) {
wn := webNav{PoolStatus: true}
wn := webNav{PoolStatus: true, Root: cfg.Www.Rootdir}

pool := r.URL.Path[len("/status/"):]
pool := r.URL.Path[len(cfg.Www.Rootdir + "/status/"):]

if !legalPoolName(pool) && !(pool == "") {
http.Error(w, "Bad Request", http.StatusBadRequest)
Expand Down Expand Up @@ -244,7 +247,7 @@ func statusHandler(w http.ResponseWriter, r *auth.AuthenticatedRequest) {
}
}
if pool == "" {
http.Redirect(w, &r.Request, "/status/"+subnav[0].Name, http.StatusSeeOther)
http.Redirect(w, &r.Request, cfg.Www.Rootdir + "/status/"+subnav[0].Name, http.StatusSeeOther)
return
}
if match == -1 {
Expand All @@ -271,9 +274,9 @@ func statusHandler(w http.ResponseWriter, r *auth.AuthenticatedRequest) {
}

func usageHandler(w http.ResponseWriter, r *auth.AuthenticatedRequest) {
wn := webNav{} // not available in menu
wn := webNav{Root: cfg.Www.Rootdir} // not available in menu

pool := r.URL.Path[len("/usage/"):]
pool := r.URL.Path[len(cfg.Www.Rootdir + "/usage/"):]

if pool == "" || !legalPoolName(pool) {
http.Error(w, "Bad Request", http.StatusBadRequest)
Expand All @@ -300,7 +303,7 @@ func usageHandler(w http.ResponseWriter, r *auth.AuthenticatedRequest) {
}

func dashboardHandler(w http.ResponseWriter, r *auth.AuthenticatedRequest) {
wn := webNav{Dashboard: true}
wn := webNav{Dashboard: true, Root: cfg.Www.Rootdir}

uptime, err := getSystemUptime()
if err != nil {
Expand Down Expand Up @@ -338,7 +341,7 @@ func dashboardHandler(w http.ResponseWriter, r *auth.AuthenticatedRequest) {
}

func statisticsHandler(w http.ResponseWriter, r *auth.AuthenticatedRequest) {
wn := webNav{Statistics: true}
wn := webNav{Statistics: true, Root: cfg.Www.Rootdir}
err := templates.ExecuteTemplate(w, "statistics.html", &webData{Nav: wn})
if err != nil {
notify.Printf(notifier.ERR, "error executing template: %s", err)
Expand All @@ -347,7 +350,7 @@ func statisticsHandler(w http.ResponseWriter, r *auth.AuthenticatedRequest) {
}

func logsHandler(w http.ResponseWriter, r *auth.AuthenticatedRequest) {
wn := webNav{Logs: true}
wn := webNav{Logs: true, Root: cfg.Www.Rootdir}
wwwLogMutex.RLock()
err := templates.ExecuteTemplate(w, "logs.html", &webData{Nav: wn, Data: wwwLogBuffer})
wwwLogMutex.RUnlock()
Expand All @@ -358,7 +361,7 @@ func logsHandler(w http.ResponseWriter, r *auth.AuthenticatedRequest) {
}

func aboutHandler(w http.ResponseWriter, r *auth.AuthenticatedRequest) {
wn := webNav{About: true}
wn := webNav{About: true, Root: cfg.Www.Rootdir}
err := templates.ExecuteTemplate(w, "about.html",
&webData{Nav: wn,
Data: map[string]string{
Expand Down
18 changes: 9 additions & 9 deletions webserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,20 @@ func webServer() {

authenticator := auth.NewBasicAuthenticator("zfswatcher", getUserSecret)

http.Handle("/resources/",
http.StripPrefix("/resources",
http.Handle(cfg.Www.Rootdir + "/resources/",
http.StripPrefix(cfg.Www.Rootdir + "/resources",
noDirListing(
authenticator.WrapHandler(
http.FileServer(
http.Dir(cfg.Www.Resourcedir))))))

http.HandleFunc("/", authenticator.Wrap(dashboardHandler))
http.HandleFunc("/status/", authenticator.Wrap(statusHandler))
http.HandleFunc("/usage/", authenticator.Wrap(usageHandler))
http.HandleFunc("/statistics/", authenticator.Wrap(statisticsHandler))
http.HandleFunc("/logs/", authenticator.Wrap(logsHandler))
http.HandleFunc("/about/", authenticator.Wrap(aboutHandler))
http.HandleFunc("/locate/", authenticator.Wrap(locateHandler))
http.HandleFunc(cfg.Www.Rootdir + "/", authenticator.Wrap(dashboardHandler))
http.HandleFunc(cfg.Www.Rootdir + "/status/", authenticator.Wrap(statusHandler))
http.HandleFunc(cfg.Www.Rootdir + "/usage/", authenticator.Wrap(usageHandler))
http.HandleFunc(cfg.Www.Rootdir + "/statistics/", authenticator.Wrap(statisticsHandler))
http.HandleFunc(cfg.Www.Rootdir + "/logs/", authenticator.Wrap(logsHandler))
http.HandleFunc(cfg.Www.Rootdir + "/about/", authenticator.Wrap(aboutHandler))
http.HandleFunc(cfg.Www.Rootdir + "/locate/", authenticator.Wrap(locateHandler))

if cfg.Www.Certfile != "" && cfg.Www.Keyfile != "" {
err = http.ListenAndServeTLS(cfg.Www.Bind, cfg.Www.Certfile, cfg.Www.Keyfile, nil)
Expand Down