diff options
| author | tjpcc <tjp@ctrl-c.club> | 2023-09-08 14:54:50 -0600 |
|---|---|---|
| committer | tjpcc <tjp@ctrl-c.club> | 2023-09-08 14:55:02 -0600 |
| commit | 7517538d2fccd75dbfb4f8b5ac9194bf0bbbda76 (patch) | |
| tree | 6e1e530beb0693119ef11a4a2d7062bf774ad5ec /routes.go | |
| parent | 62eb4353f72ad2fee2d5e30a6444c980ecf0d9ab (diff) | |
fixes & improvements
- refactored main.go to do everything which requires root *first*,
before dropping privs. this includes binding to finger and gopher
ports.
- added gopher support!
- fixed CGI handling
- new cgi-bin/private directory handling in gemini which requires
specific TLS client certs (can't do this in gopher, no TLS)
- sliderule version bump brings in lots of fixes on the sliderule side
Diffstat (limited to 'routes.go')
| -rw-r--r-- | routes.go | 46 |
1 files changed, 44 insertions, 2 deletions
@@ -21,12 +21,14 @@ import ( func geminiRouter(conf config) sr.Handler { fsys := os.DirFS(conf.geminiRoot) + privileged := tlsAuth(conf.privilegedUsers) + router := &sr.Router{} router.Route( "/*", gemini.GeminiOnly(true)(sr.FallthroughHandler( - fs.TitanUpload(tlsAuth(conf.uploaderFingerprints), conf.geminiRoot)(postUploadRedirect), + fs.TitanUpload(privileged, conf.geminiRoot)(postUploadRedirect), fs.GeminiFileHandler(fsys), fs.GeminiDirectoryDefault(fsys, "index.gmi"), fs.GeminiDirectoryListing(fsys, nil), @@ -35,7 +37,47 @@ func geminiRouter(conf config) sr.Handler { router.Route( "/cgi-bin/*", - gemini.GeminiOnly(false)(cgi.GeminiCGIDirectory("/cgi-bin/", "./cgi-bin/")), + gemini.GeminiOnly(false)(cgi.GeminiCGIDirectory( + "/cgi-bin/", + strings.Join([]string{".", strings.Trim(conf.geminiRoot, "/"), "cgi-bin"}, "/"), + )), + ) + + router.Route( + "/cgi-bin/private/*", + gemini.GeminiOnly(false)(tlsauth.GeminiAuth(privileged)( + cgi.GeminiCGIDirectory("/cgi-bin/private/", strings.Join([]string{ + ".", + strings.Trim(conf.geminiRoot, "/"), + "cgi-bin", + "private", + }, "/")), + )), + ) + + return router.Handler() +} + +func gopherRouter(conf config) sr.Handler { + fsys := os.DirFS(conf.gopherRoot) + + router := &sr.Router{} + + router.Route( + "/*", + sr.FallthroughHandler( + fs.GopherFileHandler(fsys), + fs.GopherDirectoryDefault(fsys, "index.gophermap"), + fs.GopherDirectoryListing(fsys, nil), + ), + ) + + router.Route( + "/cgi-bin/*", + cgi.GopherCGIDirectory( + "/cgi-bin/", + strings.Join([]string{".", strings.Trim(conf.gopherRoot, "/"), "cgi-bin"}, "/"), + ), ) return router.Handler() |
