1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- package main
- import (
- "fmt"
- "net/http"
- "strings"
- "imuslab.com/zoraxy/mod/sshprox"
- )
- /*
- router.go
- This script holds the static resources router
- for the reverse proxy service
- */
- func AuthFsHandler(handler http.Handler) http.Handler {
- return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- // 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" {
- handler.ServeHTTP(w, r)
- return
- }
- // check authentication
- if !authAgent.CheckAuth(r) {
- http.Redirect(w, r, "/login.html", http.StatusTemporaryRedirect)
- return
- }
- //For WebSSH Routing
- //Example URL Path: /web.ssh/{{instance_uuid}}/*
- if strings.HasPrefix(r.URL.Path, "/web.ssh/") {
- parts := strings.Split(r.URL.Path, "/")
- if len(parts) > 2 {
- //Extract the instance ID from the request path
- instanceUUID := parts[2]
- fmt.Println(instanceUUID)
- //Rewrite the url so the proxy knows how to serve stuffs
- r.URL, _ = sshprox.RewriteURL("/web.ssh/"+instanceUUID, r.RequestURI)
- webSshManager.HandleHttpByInstanceId(instanceUUID, w, r)
- } else {
- http.Error(w, "Invalid Usage", http.StatusInternalServerError)
- }
- return
- }
- //Authenticated
- handler.ServeHTTP(w, r)
- })
- }
|