package main import ( "fmt" "html" "io/ioutil" "log" "net/http" "os" "path/filepath" "strings" ) func htErr(w http.ResponseWriter, msg string, err error) { w.Header().Set("Content-Type", "text/plain") w.Header().Set("Cache-Control", *cacheCtl) fmt.Fprintln(w, msg, ":", err) log.Printf("error: %v : %v", msg, err) } func header(w http.ResponseWriter, uDir, sort string) { eDir := html.EscapeString(uDir) w.Header().Set("Content-Type", "text/html") w.Header().Set("Cache-Control", *cacheCtl) w.Write([]byte(` WFM ` + eDir + `
`)) } func footer(w http.ResponseWriter) { w.Write([]byte(`
`)) } func redirect(w http.ResponseWriter, uUrl string) { w.Header().Set("Location", uUrl) w.Header().Set("Content-Type", "text/html") w.Header().Set("Cache-Control", *cacheCtl) w.WriteHeader(302) w.Write([]byte(` Go here... `)) } func emit(s string, c int) string { o := strings.Builder{} for c > 0 { o.WriteString(s) c-- } return o.String() } func upDnDir(uDir, uBn string) string { if deniedPfx(uDir) { return "" } o := strings.Builder{} o.WriteString("\n") p := "/" i := 0 for _, n := range strings.Split(uDir, string(os.PathSeparator))[1:] { p = p + n + "/" opt := "" if p == uDir+"/" { opt = "DISABLED" } i++ o.WriteString("\n") } d, err := ioutil.ReadDir(uDir) if err != nil { return o.String() } for _, n := range d { if !n.IsDir() || strings.HasPrefix(n.Name(), ".") || deniedPfx(uDir+"/"+n.Name()) { continue } o.WriteString("\n") } return o.String() }