diff options
Diffstat (limited to 'cmd/web/util.go')
| -rw-r--r-- | cmd/web/util.go | 43 |
1 files changed, 8 insertions, 35 deletions
diff --git a/cmd/web/util.go b/cmd/web/util.go index 294079c..bac0493 100644 --- a/cmd/web/util.go +++ b/cmd/web/util.go @@ -2,27 +2,11 @@ package main import ( "fmt" - "io" "net" - "net/http" - "os" + "os/exec" "strings" ) -// UnauthorizedIfNotLocal is a middleware that returns unauthorized if not -// being accessed from loopback, as a basic form of host authentication. -func UnauthorizedIfNotLocal(h http.Handler) http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if !isLocal(r.RemoteAddr) { - http.Error(w, "Unauthorized", http.StatusUnauthorized) - Logger.Printf("Unauthorized request from: %s for %s", - r.RemoteAddr, r.RequestURI) - return - } - h.ServeHTTP(w, r) - }) -} - var isLocalCIDR = "127.0.0.1/8" func isLocal(addr string) bool { @@ -47,6 +31,7 @@ func isLocal(addr string) bool { } } +// Allows the shareLink to be overridden instead of relying on autodetect var shareLink = "" func getShareLink() string { @@ -67,24 +52,12 @@ func getPort() string { return s[1] } -// ServeSelf tries to locate the currently running executable and serve -// it down to the client. -func ServeSelf(w http.ResponseWriter, r *http.Request) { - s, err := os.Executable() - if err != nil { - Logger.Println("While trying to get my executable path: ", err) - http.Error(w, "Internal server error", http.StatusInternalServerError) - return - } - - fh, err := os.Open(s) - if err != nil { - Logger.Println("While opening my own executable for reading: ", err) - http.Error(w, "Internal server error", http.StatusInternalServerError) - return - } +// startBrowser runs the BrowserCommand func which just returns a []string +// containing our URL that varies based on each platform +func startBrowser(url string) { + command := BrowserCommand(url) - _, err = io.Copy(w, fh) - fh.Close() + c := exec.Command(command[0], command[1:]...) + Logger.Printf("Running command: %s result: %v", command, c.Run()) return } |
