Merge pull request #80 from ahhx/idle-timeout

add idle connection timeout and idle-timeout flag
This commit is contained in:
Manfred Touron 2018-11-16 09:53:02 +01:00 committed by GitHub
commit 64c8e01c33
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View file

@ -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:

14
main.go
View file

@ -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
@ -157,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)
}