add timeout and flag

This commit is contained in:
ahh 2018-11-15 13:38:18 -05:00
parent 41eeb364f8
commit 175fc8d68b
2 changed files with 15 additions and 0 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:

12
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