all repos — flounder @ deb0c5ae2a24efdbaa79345b0fbddfd3ad74e972

A small site builder for the Gemini protocol

Cleanup SFTP server
alex wennerberg alex@alexwennerberg.com
Fri, 26 Feb 2021 21:39:42 -0800
commit

deb0c5ae2a24efdbaa79345b0fbddfd3ad74e972

parent

92225891d3ccf5a64c99b5e4e73da078c3ed81ed

4 files changed, 12 insertions(+), 6 deletions(-)

jump to
M config.goconfig.go

@@ -28,6 +28,7 @@ MaxUserBytes int64

SMTPServer string SMTPUsername string SMTPPassword string + EnableSFTP bool } func getConfig(filename string) (Config, error) {
M example-config.tomlexample-config.toml

@@ -23,7 +23,7 @@ # SMTPPassword = hunter2

# Whether to enable user SFTP access # experimental feature, enable at your own risk -EnableSFTP=false +EnableSFTP=true # Templates and static files # Everything in the static subfolder will be served at /
M main.gomain.go

@@ -49,16 +49,19 @@ }

switch args[0] { case "serve": - runSFTPServer() // s1.StartAsync() wg := new(sync.WaitGroup) - wg.Add(2) + wg.Add(3) go func() { runHTTPServer() wg.Done() }() go func() { runGeminiServer() + wg.Done() + }() + go func() { + runSFTPServer() wg.Done() }() wg.Wait()
M sftp.gosftp.go

@@ -111,7 +111,9 @@ }

// Based on example server code from golang.org/x/crypto/ssh and server_standalone func runSFTPServer() { - + if !c.EnableSFTP { + return + } // An SSH server is represented by a ServerConfig, which holds // certificate details and handles authentication of ServerConns. config := &ssh.ServerConfig{

@@ -150,7 +152,7 @@ if err != nil {

log.Fatal("failed to listen for connection", err) } - fmt.Printf("Listening on %v\n", listener.Addr()) + log.Printf("SFTP server listening on %v\n", listener.Addr()) for { conn, err := listener.Accept()

@@ -168,7 +170,7 @@ log.Println("panic in AcceptInboundConnection: %#v stack strace: %v", r, string(debug.Stack()))

} }() ipAddr := GetIPFromRemoteAddress(conn.RemoteAddr().String()) - fmt.Println("Request from IP " + ipAddr) + log.Println("Request from IP " + ipAddr) limiter := getVisitor(ipAddr) if limiter.Allow() == false { conn.Close()