Skip to content

Commit

Permalink
Re-create routes path for my own ease
Browse files Browse the repository at this point in the history
  • Loading branch information
NHAS committed Jun 13, 2023
1 parent 15d5db6 commit c9efa56
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
Binary file modified internal/router/bpf_bpfeb.o
Binary file not shown.
Binary file modified internal/router/bpf_bpfel.o
Binary file not shown.
32 changes: 26 additions & 6 deletions internal/webserver/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ func Start(errChan chan<- error) error {
tunnel := http.NewServeMux()

tunnel.HandleFunc("/status/", status)
tunnel.HandleFunc("/routes/", routes)

tunnel.HandleFunc("/logout/", logout)
tunnel.HandleFunc("/static/", embeddedStatic)

Expand Down Expand Up @@ -545,7 +547,7 @@ func logout(w http.ResponseWriter, r *http.Request) {

}

func status(w http.ResponseWriter, r *http.Request) {
func routes(w http.ResponseWriter, r *http.Request) {
if r.Method != "GET" {
http.NotFound(w, r)
return
Expand All @@ -563,23 +565,41 @@ func status(w http.ResponseWriter, r *http.Request) {
if err != nil {
log.Println(user.Username, remoteAddress, "Getting routes from xdp failed: ", err)
http.Error(w, "Server Error", 500)
return
}

w.Header().Set("Content-Disposition", "attachment; filename=acl")
w.Header().Set("Content-Type", "text/plain")
w.Write([]byte(strings.Join(routes, ", ")))

}

if r.URL.Query().Get("routes") == "true" {
w.Header().Set("Content-Type", "text/plain")
w.Write([]byte(strings.Join(routes, ", ")))
func status(w http.ResponseWriter, r *http.Request) {
if r.Method != "GET" {
http.NotFound(w, r)
return
}

remoteAddress := utils.GetIPFromRequest(r)
user, err := users.GetUserFromAddress(remoteAddress)
if err != nil {
log.Println(user.Username, remoteAddress, "Could not find user: ", err)
http.Error(w, "Server Error", 500)
return
}

acl := config.GetEffectiveAcl(user.Username)

w.Header().Set("Content-Disposition", "attachment; filename=acl")
w.Header().Set("Content-Type", "application/json")
status := struct {
IsAuthorised bool
Routes []string
MFA []string
Public []string
}{
IsAuthorised: router.IsAuthed(remoteAddress.String()),
Routes: routes,
MFA: acl.Mfa,
Public: acl.Allow,
}

result, err := json.Marshal(&status)
Expand Down

0 comments on commit c9efa56

Please sign in to comment.