diff options
author | tjpcc <tjp@ctrl-c.club> | 2023-09-07 12:36:17 -0600 |
---|---|---|
committer | tjpcc <tjp@ctrl-c.club> | 2023-09-07 12:36:17 -0600 |
commit | 38ff3807b3b97da22006b5bdcf03fdfaaa4b0582 (patch) | |
tree | 2b66d01de970a14bbf6d9a29acb3a1499c82f9e7 /contrib/cgi/cgi.go | |
parent | 9330d8546fff5e0397b4eec1a24bf37277a6b745 (diff) |
all the gopher CGI handlers to support gophernicus behaviorsv1.3.0
Diffstat (limited to 'contrib/cgi/cgi.go')
-rw-r--r-- | contrib/cgi/cgi.go | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/contrib/cgi/cgi.go b/contrib/cgi/cgi.go index bcdd5e1..749a284 100644 --- a/contrib/cgi/cgi.go +++ b/contrib/cgi/cgi.go @@ -25,11 +25,11 @@ import ( // a request for /foo/bar/baz can run an executable found at /foo or /foo/bar. In such // a case the PATH_INFO would include the remaining portion of the URI path. func ResolveCGI(requestPath, fsRoot string) (string, string, error) { + fsRoot = strings.TrimRight(fsRoot, "/") segments := strings.Split(strings.TrimLeft(requestPath, "/"), "/") for i := range append(segments, "") { filepath := strings.Join(append([]string{fsRoot}, segments[:i]...), "/") - filepath = strings.TrimRight(filepath, "/") isDir, isExecutable, err := executableFile(filepath) if err != nil { return "", "", err @@ -52,26 +52,20 @@ func ResolveCGI(requestPath, fsRoot string) (string, string, error) { } func executableFile(filepath string) (bool, bool, error) { - file, err := os.Open(filepath) + info, err := os.Stat(filepath) if isNotExistError(err) { return false, false, nil } if err != nil { return false, false, err } - defer file.Close() - - info, err := file.Stat() - if err != nil { - return false, false, err - } if info.IsDir() { return true, false, nil } // readable + executable by anyone - return false, info.Mode()&0005 == 0005, nil + return false, info.Mode()&5 == 5, nil } func isNotExistError(err error) bool { @@ -94,7 +88,7 @@ func RunCGI( request *sr.Request, executable string, pathInfo string, -) (io.Reader, int, error) { +) (*bytes.Buffer, int, error) { pathSegments := strings.Split(executable, "/") dirPath := "." @@ -105,7 +99,7 @@ func RunCGI( infoLen := len(pathInfo) if pathInfo == "/" { - infoLen -= 1 + infoLen = 0 } scriptName := request.Path[:len(request.Path)-infoLen] |