flounder

A simple gemini site builder
Log | Files | Refs | README | LICENSE

commit d600ed485ac53c042d93fab1ec3fdc5249f183cc
parent 96f3a5ea10bc23f0e5c147fa6249122b6d810004
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Sun, 24 Oct 2021 13:10:12 -0700

Add finger server

Diffstat:
Mconfig.go | 3++-
Afinger.go | 42++++++++++++++++++++++++++++++++++++++++++
Mgo.mod | 1+
Mgo.sum | 2++
Mmain.go | 8+++++++-
5 files changed, 54 insertions(+), 2 deletions(-)

diff --git a/config.go b/config.go @@ -1,8 +1,9 @@ package main import ( - "github.com/BurntSushi/toml" "path/filepath" + + "github.com/BurntSushi/toml" ) const HiddenFolder = ".hidden" diff --git a/finger.go b/finger.go @@ -0,0 +1,42 @@ +package main + +import ( + "context" + "io" + "log" + "os" + "path" + "path/filepath" + "time" + + "github.com/mitchellh/go-finger" +) + +func runFingerServer() { + log.Println("Starting finger server") + s := &finger.Server{ + Handler: finger.HandlerFunc(func(ctx context.Context, w io.Writer, q *finger.Query) { + userName := filepath.Clean(q.Username) + fullPath := path.Join(c.FilesDirectory, userName, "finger") + f, err := os.Open(fullPath) + if err != nil { + w.Write([]byte("Not found\n")) + return + } + _, err = io.Copy(w, f) + if err != nil { + w.Write([]byte("Error\n")) + return + } + }), + Addr: ":7979", + ReadTimeout: 5 * time.Minute, + WriteTimeout: 5 * time.Minute, + MaxQueryBytes: 4096, + } + + err := s.ListenAndServe() + if err != nil { + panic(err) + } +} diff --git a/go.mod b/go.mod @@ -10,6 +10,7 @@ require ( github.com/gorilla/sessions v1.2.1 github.com/kr/pretty v0.2.1 // indirect github.com/mattn/go-sqlite3 v1.14.6 + github.com/mitchellh/go-finger v0.0.0-20170709001451-be12f0ff8b97 github.com/pkg/sftp v1.12.0 golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c // indirect diff --git a/go.sum b/go.sum @@ -22,6 +22,8 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/mattn/go-sqlite3 v1.14.6 h1:dNPt6NO46WmLVt2DLNpwczCmdV5boIZ6g/tlDrlRUbg= github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU= +github.com/mitchellh/go-finger v0.0.0-20170709001451-be12f0ff8b97 h1:FQ230TpgDLw7s/V5gOY0lSE+KgZzNnSX+/An2kyzqOc= +github.com/mitchellh/go-finger v0.0.0-20170709001451-be12f0ff8b97/go.mod h1:ZQVrI8EDYdnXy5EZl+dzJ9RdrSZjC78jzP1/rV4r910= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/sftp v1.12.0 h1:/f3b24xrDhkhddlaobPe2JgBqfdt+gC/NYl0QY9IOuI= diff --git a/main.go b/main.go @@ -3,12 +3,14 @@ package main import ( "flag" "fmt" + // "github.com/go-co-op/gocron" - "github.com/gorilla/sessions" "io" "log" "os" "sync" + + "github.com/gorilla/sessions" // "time" ) @@ -64,6 +66,10 @@ func main() { runSFTPServer() wg.Done() }() + go func() { + runFingerServer() + wg.Done() + }() wg.Wait() case "admin": runAdminCommand()