diff options
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | domain.go | 14 | ||||
-rw-r--r-- | main.go | 15 |
3 files changed, 21 insertions, 10 deletions
@@ -35,7 +35,7 @@ lint: complexity: go get github.com/fzipp/gocyclo - gocyclo -over 9 $(wildcard *.go) + gocyclo -over 7 $(wildcard *.go) test: go get golang.org/x/tools/cmd/cover @@ -40,7 +40,7 @@ func (d *domain) serveFile(w http.ResponseWriter, r *http.Request, fullPath stri return true } -func (d *domain) fullPath(w http.ResponseWriter, r *http.Request, projectName, subPath string) (fullPath string, err error) { +func (d *domain) resolvePath(w http.ResponseWriter, r *http.Request, projectName, subPath string) (fullPath string, err error) { publicPath := filepath.Join(*pagesRoot, d.Group, projectName, "public") fullPath = filepath.Join(publicPath, subPath) @@ -53,7 +53,11 @@ func (d *domain) fullPath(w http.ResponseWriter, r *http.Request, projectName, s err = fmt.Errorf("%q should be in %q", fullPath, publicPath) return } + return +} +func (d *domain) checkPath(w http.ResponseWriter, r *http.Request, path string) (fullPath string, err error) { + fullPath = path fi, err := os.Lstat(fullPath) if err != nil { return @@ -77,11 +81,15 @@ func (d *domain) fullPath(w http.ResponseWriter, r *http.Request, projectName, s } func (d *domain) tryFile(w http.ResponseWriter, r *http.Request, projectName, subPath string) bool { - fullPath, err := d.fullPath(w, r, projectName, subPath) + path, err := d.resolvePath(w, r, projectName, subPath) + if err != nil { + return false + } + path, err = d.checkPath(w, r, path) if err != nil { return false } - return d.serveFile(w, r, fullPath) + return d.serveFile(w, r, path) } func (d *domain) serveFromGroup(w http.ResponseWriter, r *http.Request) { @@ -102,6 +102,14 @@ func (a *theApp) UpdateDomains(domains domains) { a.lock.Unlock() } +func resolve() { + fullPath, err := filepath.EvalSymlinks(*pagesRoot) + if err != nil { + log.Fatalln(err) + } + *pagesRoot = fullPath +} + func main() { var wg sync.WaitGroup var app theApp @@ -109,12 +117,7 @@ func main() { fmt.Printf("GitLab Pages Daemon %s (%s)", VERSION, REVISION) fmt.Printf("URL: https://gitlab.com/gitlab-org/gitlab-pages") flag.Parse() - - fullPath, err := filepath.EvalSymlinks(*pagesRoot) - if err != nil { - log.Fatalln(err) - } - *pagesRoot = fullPath + resolve() // Listen for HTTP if *listenHTTP != "" { |