router.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package main
  2. import (
  3. "fmt"
  4. "net/http"
  5. "strings"
  6. )
  7. /*
  8. router.go
  9. This script holds the static resources router
  10. for the reverse proxy service
  11. */
  12. func AuthFsHandler(handler http.Handler) http.Handler {
  13. return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
  14. // Allow access to /script/*, /img/pubic/* and /login.html without authentication
  15. if strings.HasPrefix(r.URL.Path, "/script/") || strings.HasPrefix(r.URL.Path, "/img/public/") || r.URL.Path == "/login.html" || r.URL.Path == "/favicon.png" {
  16. handler.ServeHTTP(w, r)
  17. return
  18. }
  19. // check authentication
  20. if !authAgent.CheckAuth(r) {
  21. http.Redirect(w, r, "/login.html", http.StatusTemporaryRedirect)
  22. return
  23. }
  24. //For WebSSH Routing
  25. //Example URL Path: /web.ssh/{{instance_uuid}}/*
  26. if strings.HasPrefix(r.URL.Path, "/web.ssh/") {
  27. parts := strings.Split(r.URL.Path, "/")
  28. if len(parts) > 2 {
  29. instanceUUID := parts[2]
  30. fmt.Println(instanceUUID)
  31. }
  32. }
  33. //Authenticated
  34. handler.ServeHTTP(w, r)
  35. })
  36. }