|
|
|
@ -1,3 +1,4 @@
@@ -1,3 +1,4 @@
|
|
|
|
|
// Package gate provides SSH portals to applications.
|
|
|
|
|
package gate |
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
@ -19,10 +20,14 @@ import (
@@ -19,10 +20,14 @@ import (
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
const ( |
|
|
|
|
// ListenTimeout is the maximum time to start listening on an address.
|
|
|
|
|
ListenTimeout = 1 * time.Second |
|
|
|
|
IdleTimeout = 1 * time.Minute |
|
|
|
|
|
|
|
|
|
// IdleTimeout is the maximum time for a connection to be inactive.
|
|
|
|
|
IdleTimeout = 1 * time.Minute |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
// Portal is an SSH portal to an application.
|
|
|
|
|
type Portal struct { |
|
|
|
|
Name string |
|
|
|
|
Address string |
|
|
|
@ -30,11 +35,7 @@ type Portal struct {
@@ -30,11 +35,7 @@ type Portal struct {
|
|
|
|
|
Server *ssh.Server |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func setWinsize(f *os.File, w, h int) { |
|
|
|
|
syscall.Syscall(syscall.SYS_IOCTL, f.Fd(), uintptr(syscall.TIOCSWINSZ), |
|
|
|
|
uintptr(unsafe.Pointer(&struct{ h, w, x, y uint16 }{uint16(h), uint16(w), 0, 0}))) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// NewPortal opens an SSH portal to an application.
|
|
|
|
|
func NewPortal(name string, address string, command []string) (*Portal, error) { |
|
|
|
|
if address == "" { |
|
|
|
|
return nil, errors.New("no address supplied") |
|
|
|
@ -137,6 +138,17 @@ func NewPortal(name string, address string, command []string) (*Portal, error) {
@@ -137,6 +138,17 @@ func NewPortal(name string, address string, command []string) (*Portal, error) {
|
|
|
|
|
return &p, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (p *Portal) Shutdown() { |
|
|
|
|
// Close closes the portal immediately.
|
|
|
|
|
func (p *Portal) Close() { |
|
|
|
|
p.Server.Close() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Shutdown closes the portal without interrupting active connections.
|
|
|
|
|
func (p *Portal) Shutdown() { |
|
|
|
|
p.Server.Shutdown(context.Background()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func setWinsize(f *os.File, w, h int) { |
|
|
|
|
syscall.Syscall(syscall.SYS_IOCTL, f.Fd(), uintptr(syscall.TIOCSWINSZ), |
|
|
|
|
uintptr(unsafe.Pointer(&struct{ h, w, x, y uint16 }{uint16(h), uint16(w), 0, 0}))) |
|
|
|
|
} |
|
|
|
|