forked from messede-degod/SF-UI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrouter.go
52 lines (45 loc) · 1.36 KB
/
router.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"net/http"
"regexp"
)
var routes map[string]func(w http.ResponseWriter, r *http.Request)
var isFbPath = regexp.MustCompile(`(?m)^/filebrowser.*`).MatchString
func (sfui *SfUI) InitRouter() {
routes = map[string]func(w http.ResponseWriter, r *http.Request){
"/secret": sfui.handleLogin, // login
"/logout": sfui.handleLogout,
"/config": sfui.handleUIConfig,
"/ws": sfui.handleTerminalWs,
"/desktopws": sfui.handleDesktopWS,
"/sharedDesktopWs": sfui.handleSharedDesktopWS,
"/filebrowser": sfui.handleSetupFileBrowser,
"/desktop/share": sfui.handleSetupDesktopSharing,
//
// Administrative
//
"/ban/add": sfui.AddBan,
"/ban/remove": sfui.RemoveBan,
"/ban/list": sfui.ListBans,
"/client/stats": sfui.handleClientStats,
"/client/kill": sfui.handleKillClient,
}
}
func (sfui *SfUI) requestHandler(w http.ResponseWriter, r *http.Request) {
if sfui.Debug {
// log.Println(r.RemoteAddr, " ", r.URL, " ", r.UserAgent())
w.Header().Add("Access-Control-Allow-Origin", "*")
w.Header().Add("Access-Control-Allow-Methods", "*")
w.Header().Add("Access-Control-Allow-Headers", "*")
}
if handler, ok := routes[r.URL.Path]; ok {
handler(w, r)
return
}
// /filebrowser/*
if isFbPath(r.URL.Path) {
sfui.handleFileBrowser(w, r)
return
}
handleUIRequest(w, r)
}