forked from tg123/sshpiper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
54 lines (42 loc) · 1.21 KB
/
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
51
52
53
54
//go:build full
package main
import (
"fmt"
"math/rand"
"strconv"
log "github.com/sirupsen/logrus"
"github.com/tg123/sshpiper/libplugin"
"github.com/urfave/cli/v2"
)
func main() {
libplugin.CreateAndRunPluginTemplate(&libplugin.PluginTemplate{
Name: "simplemath",
Usage: "sshpiperd simplemath plugin, do math before ssh login",
CreateConfig: func(_ *cli.Context) (*libplugin.SshPiperPluginConfig, error) {
return &libplugin.SshPiperPluginConfig{
KeyboardInteractiveCallback: func(conn libplugin.ConnMetadata, client libplugin.KeyboardInteractiveChallenge) (*libplugin.Upstream, error) {
_, _ = client("", "lets do math", "", false)
for {
a := rand.Intn(10)
b := rand.Intn(10)
ans, err := client("", "", fmt.Sprintf("what is %v + %v = ", a, b), true)
if err != nil {
return nil, err
}
log.Printf("got ans = %v", ans)
if ans == fmt.Sprintf("%v", a+b) {
log.Printf("got ans = %v", ans)
return &libplugin.Upstream{
Auth: libplugin.CreateNextPluginAuth(map[string]string{
"a": strconv.Itoa(a),
"b": strconv.Itoa(b),
"ans": ans,
}),
}, nil
}
}
},
}, nil
},
})
}