-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
41 lines (33 loc) · 797 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main // import "github.com/simon-engledew/mock-ssh-server"
import (
"fmt"
"github.com/gliderlabs/ssh"
"github.com/simon-engledew/mock-ssh-server/pkg"
"golang.org/x/text/encoding/unicode"
"log"
"os"
)
func main() {
log.SetFlags(0)
if len(os.Args) < 2 {
log.Fatal("usage: gosshim <script.star>")
}
script, err := pkg.Load(os.Args[1], nil)
if err != nil {
log.Fatal(err)
}
encoding := unicode.UTF8
ssh.Handle(func(s ssh.Session) {
log.Print("client connected: ", s.RemoteAddr())
w := encoding.NewEncoder().Writer(s)
r := encoding.NewDecoder().Reader(s)
err := script(w, r)
if err != nil {
if _, fmtErr := fmt.Fprint(w, err.Error()+"\r\n"); fmtErr != nil {
log.Print(err)
}
log.Print(err)
}
})
log.Fatal(ssh.ListenAndServe(":2222", nil))
}