diff options
author | tjpcc <tjp@ctrl-c.club> | 2023-10-10 14:47:54 -0600 |
---|---|---|
committer | tjpcc <tjp@ctrl-c.club> | 2023-10-10 14:47:54 -0600 |
commit | 04449ed66e4272ee08bc1dd00f6bdefb2be51a43 (patch) | |
tree | 665ce77a841144bd9b70becba7e541f187867406 /contrib/cgi/gopher.go | |
parent | d467d044798f61b34684e885cf5b1544c3fb2ee2 (diff) |
support an overridden "cmd" for CGIs
Diffstat (limited to 'contrib/cgi/gopher.go')
-rw-r--r-- | contrib/cgi/gopher.go | 18 |
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() } |