mirror of
https://github.com/moul/sshportal.git
synced 2025-09-10 22:54:49 +08:00
Merge pull request #80 from ahhx/idle-timeout
add idle connection timeout and idle-timeout flag
This commit is contained in:
commit
64c8e01c33
2 changed files with 16 additions and 1 deletions
|
@ -3,6 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
|
@ -13,6 +14,7 @@ type configServe struct {
|
||||||
logsLocation string
|
logsLocation string
|
||||||
bindAddr string
|
bindAddr string
|
||||||
debug, demo bool
|
debug, demo bool
|
||||||
|
idleTimeout time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseServeConfig(c *cli.Context) (*configServe, error) {
|
func parseServeConfig(c *cli.Context) (*configServe, error) {
|
||||||
|
@ -24,6 +26,7 @@ func parseServeConfig(c *cli.Context) (*configServe, error) {
|
||||||
debug: c.Bool("debug"),
|
debug: c.Bool("debug"),
|
||||||
demo: c.Bool("demo"),
|
demo: c.Bool("demo"),
|
||||||
logsLocation: c.String("logs-location"),
|
logsLocation: c.String("logs-location"),
|
||||||
|
idleTimeout: c.Duration("idle-timeout"),
|
||||||
}
|
}
|
||||||
switch len(ret.aesKey) {
|
switch len(ret.aesKey) {
|
||||||
case 0, 16, 24, 32:
|
case 0, 16, 24, 32:
|
||||||
|
|
14
main.go
14
main.go
|
@ -3,6 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"math"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
|
@ -79,6 +80,11 @@ func main() {
|
||||||
Value: "./log",
|
Value: "./log",
|
||||||
Usage: "Store user session files",
|
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",
|
Name: "healthcheck",
|
||||||
|
@ -144,6 +150,12 @@ func server(c *configServe) (err error) {
|
||||||
Version: fmt.Sprintf("sshportal-%s", Version),
|
Version: fmt.Sprintf("sshportal-%s", Version),
|
||||||
ChannelHandler: channelHandler,
|
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{
|
for _, opt := range []ssh.Option{
|
||||||
// custom PublicKeyAuth handler
|
// 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)
|
return srv.Serve(ln)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue