summaryrefslogtreecommitdiff
path: root/contrib/cgi/gopher.go
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/cgi/gopher.go')
-rw-r--r--contrib/cgi/gopher.go18
1 files changed, 12 insertions, 6 deletions
diff --git a/contrib/cgi/gopher.go b/contrib/cgi/gopher.go
index bb3e73e..7067a6d 100644
--- a/contrib/cgi/gopher.go
+++ b/contrib/cgi/gopher.go
@@ -21,7 +21,7 @@ import (
// a request for /foo/bar/baz can also run an executable found at /foo or /foo/bar. In
// such a case the PATH_INFO environment variable will include the remaining portion of
// the URI path.
-func GopherCGIDirectory(fsroot, urlroot string, settings *gophermap.FileSystemSettings) sr.Handler {
+func GopherCGIDirectory(fsroot, urlroot, cmd string, settings *gophermap.FileSystemSettings) sr.Handler {
if settings == nil || !settings.Exec {
return sr.HandlerFunc(func(ctx context.Context, request *sr.Request) *sr.Response { return nil })
}
@@ -41,12 +41,12 @@ func GopherCGIDirectory(fsroot, urlroot string, settings *gophermap.FileSystemSe
return nil
}
- return runGopherCGI(ctx, request, fullpath, pathinfo, *settings)
+ return runGopherCGI(ctx, request, fullpath, pathinfo, cmd, *settings)
})
}
// ExecGopherMaps runs any gophermaps
-func ExecGopherMaps(fsroot, urlroot string, settings *gophermap.FileSystemSettings) sr.Handler {
+func ExecGopherMaps(fsroot, urlroot, cmd string, settings *gophermap.FileSystemSettings) sr.Handler {
if settings == nil || !settings.Exec {
return sr.HandlerFunc(func(ctx context.Context, request *sr.Request) *sr.Response { return nil })
}
@@ -85,7 +85,7 @@ func ExecGopherMaps(fsroot, urlroot string, settings *gophermap.FileSystemSettin
if !m.IsRegular() || m&5 != 5 {
continue
}
- return runGopherCGI(ctx, request, fpath, "/", *settings)
+ return runGopherCGI(ctx, request, fpath, "/", cmd, *settings)
}
return nil
@@ -96,7 +96,7 @@ func ExecGopherMaps(fsroot, urlroot string, settings *gophermap.FileSystemSettin
return nil
}
- return runGopherCGI(ctx, request, fullpath, "/", *settings)
+ return runGopherCGI(ctx, request, fullpath, "/", cmd, *settings)
})
}
@@ -105,10 +105,16 @@ func runGopherCGI(
request *sr.Request,
fullpath string,
pathinfo string,
+ cmd string,
settings gophermap.FileSystemSettings,
) *sr.Response {
+ workdir := filepath.Dir(fullpath)
+ if cmd != "" {
+ fullpath = cmd
+ }
+
stderr := &bytes.Buffer{}
- stdout, exitCode, err := RunCGI(ctx, request, fullpath, pathinfo, stderr)
+ stdout, exitCode, err := RunCGI(ctx, request, fullpath, pathinfo, workdir, stderr)
if err != nil {
return gopher.Error(err).Response()
}