|
@@ -3,6 +3,8 @@ package main
|
|
|
import (
|
|
|
"fmt"
|
|
|
"net/http"
|
|
|
+ "net/url"
|
|
|
+ "path/filepath"
|
|
|
"strings"
|
|
|
|
|
|
"imuslab.com/zoraxy/mod/sshprox"
|
|
@@ -15,17 +17,36 @@ import (
|
|
|
for the reverse proxy service
|
|
|
*/
|
|
|
|
|
|
-func AuthFsHandler(handler http.Handler) http.Handler {
|
|
|
+func FSHandler(handler http.Handler) http.Handler {
|
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
+ /*
|
|
|
+ Development Mode Override
|
|
|
+ => Web root is located in /
|
|
|
+ */
|
|
|
+ if development && strings.HasPrefix(r.URL.Path, "/web/") {
|
|
|
+ u, _ := url.Parse(strings.TrimPrefix(r.URL.Path, "/web"))
|
|
|
+ r.URL = u
|
|
|
+ }
|
|
|
+
|
|
|
+ /*
|
|
|
+ Production Mode Override
|
|
|
+ => Web root is located in /web
|
|
|
+ */
|
|
|
+ if !development && r.URL.Path == "/" {
|
|
|
+ //Redirect to web UI
|
|
|
+ http.Redirect(w, r, "/web/", http.StatusTemporaryRedirect)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
// Allow access to /script/*, /img/pubic/* and /login.html without authentication
|
|
|
- if strings.HasPrefix(r.URL.Path, "/script/") || strings.HasPrefix(r.URL.Path, "/img/public/") || r.URL.Path == "/login.html" || r.URL.Path == "/favicon.png" {
|
|
|
+ if strings.HasPrefix(r.URL.Path, ppf("/script/")) || strings.HasPrefix(r.URL.Path, ppf("/img/public/")) || r.URL.Path == ppf("/login.html") || r.URL.Path == ppf("/favicon.png") {
|
|
|
handler.ServeHTTP(w, r)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// check authentication
|
|
|
- if !authAgent.CheckAuth(r) {
|
|
|
- http.Redirect(w, r, "/login.html", http.StatusTemporaryRedirect)
|
|
|
+ if !authAgent.CheckAuth(r) && requireAuth {
|
|
|
+ http.Redirect(w, r, ppf("/login.html"), http.StatusTemporaryRedirect)
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -57,3 +78,11 @@ func AuthFsHandler(handler http.Handler) http.Handler {
|
|
|
handler.ServeHTTP(w, r)
|
|
|
})
|
|
|
}
|
|
|
+
|
|
|
+//Production path fix wrapper. Fix the path on production or development environment
|
|
|
+func ppf(relativeFilepath string) string {
|
|
|
+ if !development {
|
|
|
+ return strings.ReplaceAll(filepath.Join("/web/", relativeFilepath), "\\", "/")
|
|
|
+ }
|
|
|
+ return relativeFilepath
|
|
|
+}
|