-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
50 lines (37 loc) · 804 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
42
43
44
45
46
47
48
49
50
package main
import (
"flag"
"fmt"
"log"
"os"
"github.com/ibice/go-rsh"
)
var (
port = flag.Uint("p", 22222, "listen port")
addr = flag.String("a", "127.0.0.1", "listen address")
shell = flag.String("s", os.Getenv("SHELL"), "default shell to use")
lastResortShell = "/bin/sh"
)
func parseArgs() {
flag.Parse()
if port == nil || *port == 0 {
log.Fatal("-p is required")
}
if *port > 65535 {
log.Fatal("Invalid port: ")
}
if addr == nil || *addr == "" {
log.Fatal("-a is required")
}
if shell == nil || *shell == "" {
shell = &lastResortShell
}
}
func main() {
parseArgs()
server := rsh.NewServer(fmt.Sprintf("%s:%d", *addr, *port), *shell)
log.Printf("Serving at %s:%d", *addr, *port)
if err := server.Serve(); err != nil {
log.Fatalf("Serve: %v", err)
}
}