Support multiple CGI paths.

This commit is contained in:
Solderpunk 2020-06-08 21:46:39 +02:00
parent bec952c66a
commit 4681d3f971
2 changed files with 10 additions and 6 deletions

View File

@ -14,7 +14,7 @@ type Config struct {
LogPath string
TempRedirects map[string]string
PermRedirects map[string]string
CGIPath string
CGIPaths []string
SCGIPaths map[string]string
}
@ -32,7 +32,7 @@ func getConfig(filename string) (Config, error) {
config.LogPath = "molly.log"
config.TempRedirects = make(map[string]string)
config.PermRedirects = make(map[string]string)
config.CGIPath = "^/var/gemini/cgi-bin/"
config.CGIPaths = make([]string, 0)
config.SCGIPaths = make(map[string]string)
// Return defaults if no filename given

View File

@ -149,10 +149,14 @@ func handleGeminiRequest(conn net.Conn, config Config, logEntries chan LogEntry)
}
// If this file is executable, get dynamic content
inCGIPath, err := regexp.Match(config.CGIPath, []byte(path))
if inCGIPath && info.Mode().Perm() & 0111 == 0111 {
handleCGI(config, path, URL, &log, conn)
return
if info.Mode().Perm() & 0111 == 0111 {
for _, cgiPath := range(config.CGIPaths) {
inCGIPath, err := regexp.Match(cgiPath, []byte(path))
if err == nil && inCGIPath {
handleCGI(config, path, URL, &log, conn)
return
}
}
}
// Otherwise, serve the file contents