From 4c0e1bc89de2a60baaa098c049cf69bac8537055 Mon Sep 17 00:00:00 2001 From: tjpcc Date: Fri, 8 Sep 2023 14:54:59 -0600 Subject: finger support --- routes.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'routes.go') diff --git a/routes.go b/routes.go index 0683924..35bdfc1 100644 --- a/routes.go +++ b/routes.go @@ -13,7 +13,9 @@ import ( "tildegit.org/tjp/sliderule/contrib/cgi" "tildegit.org/tjp/sliderule/contrib/fs" "tildegit.org/tjp/sliderule/contrib/tlsauth" + "tildegit.org/tjp/sliderule/finger" "tildegit.org/tjp/sliderule/gemini" + "tildegit.org/tjp/sliderule/logging" ) func geminiRouter(conf config) sr.Handler { @@ -66,3 +68,27 @@ func tlsAuth(uploaders []string) tlsauth.Approver { return found } } + +func fingerHandler(conf config) sr.Handler { + return sr.HandlerFunc(func(ctx context.Context, request *sr.Request) *sr.Response { + name := strings.TrimPrefix(request.Path, "/") + if name == "" { + return finger.Error("listings not permitted") + } + + path, ok := conf.fingerResponses[strings.ToLower(name)] + if !ok { + return finger.Error("user not found") + } + + file, err := os.Open(path) + if err != nil { + ctx.Value("errorlog").(logging.Logger).Log( + "msg", "finger response file open error", + "error", err, + ) + } + + return finger.Success(file) + }) +} -- cgit v1.2.3