Cleanup SFTP server
alex wennerberg alex@alexwennerberg.com
Fri, 26 Feb 2021 21:39:42 -0800
4 files changed,
12 insertions(+),
6 deletions(-)
M
example-config.toml
→
example-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.go
→
main.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.go
→
sftp.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()