-
Notifications
You must be signed in to change notification settings - Fork 0
/
cthulhu.go
118 lines (113 loc) · 2.94 KB
/
cthulhu.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package main
import (
"log"
"os"
"cthulhu/clog"
"cthulhu/logic"
"cthulhu/utils"
"github.com/urfave/cli/v2"
)
func main() {
sshInfo := utils.SSHInfo{}
app := cli.NewApp()
app.Name = "Cthulhu"
app.Usage = `Cthulhu is an automatic tool which can easily manage network devices.
For example:
./cthulhu -C "show clock" -A "192.168.2.200:22" -U test -P test`
app.Version = "1.2.0"
app.Authors = []*cli.Author{
{
Name: "Draven",
},
}
app.Flags = []cli.Flag{
&cli.StringFlag{
Name: "address", Aliases: []string{"A"},
Value: "192.168.2.200:22;192.168.2.201:22",
Usage: "ip address -- such as '192.168.1.1:22;192.168.1.2:22'",
Destination: &sshInfo.AddrStr,
},
&cli.StringFlag{
Name: "command", Aliases: []string{"C"},
Value: "show clock",
Usage: "commands -- such as 'show clock;config t;do show run;exit'",
Destination: &sshInfo.Cmd,
},
&cli.StringFlag{
Name: "user", Aliases: []string{"U"},
Value: "admin",
Usage: "the account to sign in. -- such as 'admin'",
Destination: &sshInfo.User,
},
&cli.StringFlag{
Name: "password", Aliases: []string{"P"},
Value: "admin",
Usage: "provide password to sign in. -- such as 'admin'",
Destination: &sshInfo.Password,
},
&cli.StringFlag{
Name: "key", Aliases: []string{"K"},
Value: "",
Usage: "provide Private key to sign in(if it's necessary).",
Destination: &sshInfo.Key,
},
&cli.StringFlag{
Name: "ciphers", Aliases: []string{"CI"},
Value: "",
Usage: "provide ciphers(if it's necessary). -- such as 'aes128-ctr;arcfour256'",
Destination: &sshInfo.Ciphers,
},
&cli.Int64Flag{
Name: "timeout", Aliases: []string{"T"},
Value: 30,
Usage: "will be timeout if there's no response. -- such as '30'",
Destination: &sshInfo.Timeout,
},
&cli.IntFlag{
Name: "routineLimit", Aliases: []string{"RL"},
Value: 30,
Usage: "pause establish connection if there's too many goroutine. -- such as '30'",
Destination: &sshInfo.RoutineLimit,
},
}
app.Action = func(c *cli.Context) error {
deviceSSH := logic.NewDeviceSSH(sshInfo)
_ = logic.MultiEstablish(deviceSSH)
return nil
}
app.Commands = []*cli.Command{
{
Name: "serve", Aliases: []string{"S"},
Usage: "start an rpc server",
Action: rpcHandler,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "client", Aliases: []string{""},
Value: "127.0.0.1:8880",
Usage: "rpc server address",
},
},
},
}
cli.HelpFlag = &cli.BoolFlag{
Name: "help", Aliases: []string{"H"},
Usage: "show options",
}
cli.VersionFlag = &cli.BoolFlag{
Name: "version", Aliases: []string{"V"},
Usage: "print version",
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}
func rpcHandler(c *cli.Context) error {
// init logger
if err := clog.InitLogger(); err != nil {
return err
}
// init rpc
logic.StartServer()
return nil
}