From 175fc8d68b1cd4741ce2649c8b3a18b0eb8fc88a Mon Sep 17 00:00:00 2001 From: ahh Date: Thu, 15 Nov 2018 13:38:18 -0500 Subject: [PATCH 1/2] add timeout and flag --- config.go | 3 +++ main.go | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/config.go b/config.go index 3dd875c..26a9287 100644 --- a/config.go +++ b/config.go @@ -3,6 +3,7 @@ package main import ( "fmt" "os" + "time" "github.com/urfave/cli" ) @@ -13,6 +14,7 @@ type configServe struct { logsLocation string bindAddr string debug, demo bool + idleTimeout time.Duration } func parseServeConfig(c *cli.Context) (*configServe, error) { @@ -24,6 +26,7 @@ func parseServeConfig(c *cli.Context) (*configServe, error) { debug: c.Bool("debug"), demo: c.Bool("demo"), logsLocation: c.String("logs-location"), + idleTimeout: c.Duration("idle-timeout"), } switch len(ret.aesKey) { case 0, 16, 24, 32: diff --git a/main.go b/main.go index 3b5c1f0..8b06cdc 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "fmt" "log" + "math" "math/rand" "net" "os" @@ -79,6 +80,11 @@ func main() { Value: "./log", Usage: "Store user session files", }, + cli.DurationFlag{ + Name: "idle-timeout", + Value: 0, + Usage: "Duration before an inactive connection is timed out (0 to disable)", + }, }, }, { Name: "healthcheck", @@ -144,6 +150,12 @@ func server(c *configServe) (err error) { Version: fmt.Sprintf("sshportal-%s", Version), ChannelHandler: channelHandler, } + if c.idleTimeout != 0 { + srv.IdleTimeout = c.idleTimeout + // gliderlabs/ssh requires MaxTimeout to be non-zero if we want to use IdleTimeout. + // So, set it to the max value, because we don't want a max timeout. + srv.MaxTimeout = math.MaxInt64 + } for _, opt := range []ssh.Option{ // custom PublicKeyAuth handler From acce797e552c20a9dc395bee487ec488ee3deb14 Mon Sep 17 00:00:00 2001 From: ahh Date: Thu, 15 Nov 2018 13:56:10 -0500 Subject: [PATCH 2/2] add logging --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 8b06cdc..b62d0fa 100644 --- a/main.go +++ b/main.go @@ -169,6 +169,6 @@ func server(c *configServe) (err error) { } } - log.Printf("info: SSH Server accepting connections on %s", c.bindAddr) + log.Printf("info: SSH Server accepting connections on %s, idle-timout=%v", c.bindAddr, c.idleTimeout) return srv.Serve(ln) }