mirror of
https://tildegit.org/solderpunk/molly-brown
synced 2024-09-22 12:10:41 +02:00
Switch CGI implementation to actual CGI.
This commit is contained in:
parent
de119aa0bb
commit
a16a5fac12
25
handler.go
25
handler.go
@ -132,7 +132,7 @@ func handleGeminiRequest(conn net.Conn, config Config, logEntries chan LogEntry)
|
|||||||
// If this file is executable, get dynamic content
|
// If this file is executable, get dynamic content
|
||||||
inCGIPath, err := regexp.Match(config.CGIPath, []byte(path))
|
inCGIPath, err := regexp.Match(config.CGIPath, []byte(path))
|
||||||
if inCGIPath && info.Mode().Perm() & 0111 == 0111 {
|
if inCGIPath && info.Mode().Perm() & 0111 == 0111 {
|
||||||
handleCGI(path, URL, log, conn)
|
handleCGI(config, path, URL, log, conn)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,20 +200,23 @@ func serveFile(path string, log LogEntry, conn net.Conn) {
|
|||||||
conn.Write(contents)
|
conn.Write(contents)
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleCGI(path string, URL *url.URL, log LogEntry, conn net.Conn) {
|
func handleCGI(config Config, path string, URL *url.URL, log LogEntry, conn net.Conn) {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
cmd := exec.CommandContext(ctx, path)
|
cmd := exec.CommandContext(ctx, path)
|
||||||
stdin, err := cmd.StdinPipe()
|
// Set environment variables
|
||||||
if err != nil {
|
cmd.Env = []string{
|
||||||
conn.Write([]byte("42 CGI error!\r\n"))
|
"GATEWAY_INTERFACE=CGI/1.1",
|
||||||
log.Status = 42
|
"PATH_INFO=/",
|
||||||
return
|
"QUERY_STRING=" + URL.RawQuery,
|
||||||
|
"REMOTE_ADDR=" + conn.RemoteAddr().String(),
|
||||||
|
"REQUEST_METHOD=",
|
||||||
|
"SCRIPT_PATH=" + path,
|
||||||
|
"SERVER_NAME=" + config.Hostname,
|
||||||
|
"SERVER_PORT=" + strconv.Itoa(config.Port),
|
||||||
|
"SERVER_PROTOCL=GEMINI",
|
||||||
|
"SERVER_SOFTWARE=MOLLY_BROWN",
|
||||||
}
|
}
|
||||||
defer stdin.Close()
|
|
||||||
io.WriteString(stdin, URL.String())
|
|
||||||
io.WriteString(stdin, "\r\n")
|
|
||||||
stdin.Close()
|
|
||||||
response, err := cmd.Output()
|
response, err := cmd.Output()
|
||||||
if ctx.Err() == context.DeadlineExceeded {
|
if ctx.Err() == context.DeadlineExceeded {
|
||||||
conn.Write([]byte("42 CGI process timed out!\r\n"))
|
conn.Write([]byte("42 CGI process timed out!\r\n"))
|
||||||
|
Loading…
Reference in New Issue
Block a user