Browse Source

Added help; Support cooked mode (no pty)

metathon_sep_2019/gate-maze
parent
commit
4ff193d4c9
3 changed files with 35 additions and 6 deletions
  1. +3
    -0
      pkg/net/secureshell/command.go
  2. +1
    -1
      pkg/net/secureshell/server.go
  3. +31
    -5
      pkg/net/secureshell/session.go

+ 3
- 0
pkg/net/secureshell/command.go View File

@ -136,12 +136,15 @@ In order to terminate this session, use "exit" or hit ^D.`,
Run: func(_ *SessionTerminal, _ []string) error {
return io.EOF
},
Help: "Terminate the session.",
}
idCommand = Command{
Name: "id",
Syntax: "id",
Run: idRun,
Help: `The id command displays the user and group names and IDs, of the calling
user, to the standard output.`,
}
)


+ 1
- 1
pkg/net/secureshell/server.go View File

@ -235,7 +235,7 @@ func (sshd *Server) handleSession(session secureshell.Session) {
if sshd.Prompt != "" {
t.SetPrompt(sshd.Prompt)
}
if sshd.Message != "" {
if t.IsInteractive() && sshd.Message != "" {
// TODO(maze): string formatting?
fmt.Fprintln(t, strings.TrimSpace(sshd.Message))
}


+ 31
- 5
pkg/net/secureshell/session.go View File

@ -14,13 +14,16 @@ import (
"maze.io/x/secureshell"
"maze.io/gate/pkg/core"
"maze.io/gate/pkg/core/logger"
"maze.io/gate/pkg/text"
"maze.io/gate/pkg/text/prompt"
"maze.io/gate/pkg/text/terminfo"
"maze.io/gate/pkg/util/compact"
)
type SessionTerminal struct {
secureshell.Session
log *logger.Logger
transport core.Transport
w io.Writer
r *bufio.Reader
@ -42,12 +45,31 @@ func NewSessionTerminal(transport core.Transport, session secureshell.Session) *
avail: make(chan struct{}),
promptFormat: "%u@%h%% ",
}
term.log = logger.Default.WithFields(logger.Fields{
logger.Component: "sshd",
logger.User: wrapMetadata(session).User(),
logger.Session: compact.Bytes(session.SessionID()),
}).WithSourceAddr(transport.RemoteAddr())
pty, winch, ok := session.PseudoTerminal()
if ok && pty.Type != "" {
term.log.WithField("term", pty.Type).Debug("shell starting")
go func(changes <-chan secureshell.WindowChange) {
for window := range changes {
term.window = window
term.log.WithField("size", window.String()).Trace("window changed")
}
}(winch)
var err error
if term.prompt, err = prompt.New(fmt.Sprintf("%s@gate> ", session.User()), term); err != nil {
if err != terminfo.ErrTermNotFound {
term.err = err
var err error
if term.prompt, err = prompt.New(fmt.Sprintf("%s@gate> ", session.User()), term); err != nil {
if err != terminfo.ErrTermNotFound {
term.err = err
}
}
} else {
term.log.Info("dumb shell starting")
}
if term.prompt != nil {
@ -60,6 +82,10 @@ func NewSessionTerminal(transport core.Transport, session secureshell.Session) *
return term
}
func (term *SessionTerminal) IsInteractive() bool {
return term.prompt != nil
}
// Transport is the underlying transport for this session.
func (term *SessionTerminal) Transport() core.Transport {
return term.transport
@ -195,7 +221,7 @@ func (term *SessionTerminal) readLine() (string, error) {
term.updatePrompt()
return term.prompt.Readline()
}
return "", io.EOF
return term.r.ReadString('\n')
}
func (term *SessionTerminal) handleWindowChanges(changes <-chan secureshell.WindowChange) {


Loading…
Cancel
Save