router.go 783 B

1234567891011121314151617181920212223242526272829303132
  1. package main
  2. import (
  3. "net/http"
  4. "strings"
  5. )
  6. /*
  7. router.go
  8. This script holds the static resources router
  9. for the reverse proxy service
  10. */
  11. func AuthFsHandler(handler http.Handler) http.Handler {
  12. return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
  13. // Allow access to /script/*, /img/pubic/* and /login.html without authentication
  14. if strings.HasPrefix(r.URL.Path, "/script/") || strings.HasPrefix(r.URL.Path, "/img/public/") || r.URL.Path == "/login.html" || r.URL.Path == "/favicon.png" {
  15. handler.ServeHTTP(w, r)
  16. return
  17. }
  18. // check authentication
  19. if !authAgent.CheckAuth(r) {
  20. http.Redirect(w, r, "/login.html", http.StatusTemporaryRedirect)
  21. return
  22. }
  23. //Authenticated
  24. handler.ServeHTTP(w, r)
  25. })
  26. }