Skip to content

Commit

Permalink
Merge pull request #11 from gliderlabs/master
Browse files Browse the repository at this point in the history
v0.2.1
  • Loading branch information
progrium authored Jul 25, 2016
2 parents f1a52bd + ff9cab1 commit b47f727
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ NAME=sshfront
OWNER=gliderlabs
ARCH=$(shell uname -m)
RMFLAG=--rm
VERSION=0.2.0
VERSION=0.2.1

build:
mkdir -p build/Linux && GOOS=linux CGO_ENABLED=0 go build -a \
-ldflags "-X main.Version $(VERSION)" \
-ldflags "-X main.Version=$(VERSION)" \
-installsuffix cgo \
-o build/Linux/$(NAME)
mkdir -p build/Darwin && GOOS=darwin CGO_ENABLED=0 go build -a \
-ldflags "-X main.Version $(VERSION)" \
-ldflags "-X main.Version=$(VERSION)" \
-installsuffix cgo \
-o build/Darwin/$(NAME)

Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# sshfront

[![CircleCI](https://img.shields.io/circleci/project/gliderlabs/sshfront/release.svg)](https://circleci.com/gh/gliderlabs/sshfront)
[![IRC Channel](https://img.shields.io/badge/irc-%23gliderlabs-blue.svg)](https://kiwiirc.com/client/irc.freenode.net/#gliderlabs)

A lightweight SSH server frontend where authentication and connections
are controlled with command handlers / shell scripts.

Expand Down Expand Up @@ -74,3 +77,4 @@ This project was made possible thanks to [Deis](http://deis.io) and [DigitalOcea
## License

MIT
<img src="https://ga-beacon.appspot.com/UA-58928488-2/sshfront/readme?pixel" />
3 changes: 3 additions & 0 deletions example/stdinecho
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
echo "Stdin:"
cat
19 changes: 18 additions & 1 deletion handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,16 @@ func (h *sshHandler) Exit(err error) error {
return err
}

type EnvVar struct {
Name, Value string
}

func (h *sshHandler) Request(req *ssh.Request) {
switch req.Type {
case "exec":
h.handleExec(req)
case "env":
h.handleEnv(req)
case "pty-req":
h.handlePty(req)
case "window-change":
Expand All @@ -178,6 +184,14 @@ func (h *sshHandler) Request(req *ssh.Request) {
}
}

func (h *sshHandler) handleEnv(req *ssh.Request) {
var pair EnvVar
ssh.Unmarshal(req.Payload, &pair)
envvar := fmt.Sprintf("%s=%s", pair.Name, pair.Value)
h.Env = append(h.Env, envvar)
req.Reply(true, nil)
}

func (h *sshHandler) handleExec(req *ssh.Request) {
h.Lock()
defer h.Unlock()
Expand Down Expand Up @@ -207,7 +221,10 @@ func (h *sshHandler) handleExec(req *ssh.Request) {
h.channel.Close()
return
}
go io.Copy(stdinPipe, h.channel)
go func() {
defer stdinPipe.Close()
io.Copy(stdinPipe, h.channel)
}()

if req.WantReply {
req.Reply(true, nil)
Expand Down

0 comments on commit b47f727

Please sign in to comment.