From 4681d3f971a0bfd910f4ff51a8673cf8ed4f0dc4 Mon Sep 17 00:00:00 2001 From: Solderpunk Date: Mon, 8 Jun 2020 21:46:39 +0200 Subject: [PATCH] Support multiple CGI paths. --- config.go | 4 ++-- handler.go | 12 ++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/config.go b/config.go index 438f6d3..90bb6bd 100644 --- a/config.go +++ b/config.go @@ -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 diff --git a/handler.go b/handler.go index 6fc9c95..665eb1b 100644 --- a/handler.go +++ b/handler.go @@ -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