This repository has been archived by the owner on Feb 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
154 lines (145 loc) · 3.49 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
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package main
import (
"errors"
"fmt"
"log"
"os"
"github.com/austindizzy/securitycenter-cli/auth"
"github.com/austindizzy/securitycenter-cli/menu"
"github.com/austindizzy/securitycenter-cli/utils"
"github.com/urfave/cli"
)
func main() {
app := cli.NewApp()
app.EnableBashCompletion = true
app.Name = "securitycenter-cli"
app.Usage = "a trusty cli for your trusty nvs"
app.Version = "0.1a"
app.Authors = []cli.Author{
cli.Author{
Name: "Austin Siford",
Email: "[email protected]",
},
}
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "host",
Usage: "Tenable Nessus SecurityCenter API host",
EnvVar: "TNS_HOST",
},
cli.StringFlag{
Name: "token, t",
Usage: "Auth token for SecurityCenter.",
EnvVar: "TNS_TOKEN",
},
cli.StringFlag{
Name: "session",
Usage: "Auth session for SecurityCenter",
EnvVar: "TNS_SESSION",
},
cli.BoolFlag{
Name: "debug",
Usage: "Enable verbose logging.",
},
cli.IntFlag{
Name: "throttle",
Usage: "Throttle requests by N milliseconds",
Value: -1,
},
}
app.Before = func(c *cli.Context) error {
println()
var err error
if !(len(c.GlobalString("host")) > 0) {
err = errors.New("Error: \"--host\" flag not set.")
}
return err
}
app.Action = func(c *cli.Context) error {
cli.ShowAppHelp(c)
return nil
}
app.After = func(c *cli.Context) error {
println()
return nil
}
app.Commands = []cli.Command{
{
Name: "export",
Aliases: []string{"x"},
Usage: "export objects from SecurityCenter to a flat file",
UsageText: fmt.Sprintf("%s export [command options] [data type to export]", app.Name),
Action: func(c *cli.Context) error {
return export(c)
},
Flags: []cli.Flag{
cli.StringFlag{Name: "fields", Usage: "fields to export"},
cli.StringFlag{Name: "filter", Usage: "filter exported records"},
cli.StringFlag{Name: "output", Usage: "optional file output"},
},
},
{
Name: "import",
Aliases: []string{"i"},
Usage: "import objects from a flat file to SecurityCenter",
Action: func(c *cli.Context) error {
return doImport(c)
},
Flags: []cli.Flag{
cli.StringFlag{Name: "input", Usage: "file to read/import"},
cli.BoolFlag{Name: "dryrun", Usage: "no data is sent in dryrun mode"},
},
},
{
Name: "test",
Aliases: []string{"t"},
Usage: "test auth token for validity",
Action: func(c *cli.Context) error {
auth.Test(c)
return nil
},
}, {
Name: "menu",
Aliases: []string{"m"},
Usage: "start interactive menu",
Action: func(c *cli.Context) error {
if auth.Test(c) {
var m = new(menu.Main)
m.Start(c)
}
return nil
},
},
{
Name: "auth",
Aliases: []string{"c"},
Usage: "get/set auth tokens",
Action: func(c *cli.Context) error {
keys, err := auth.Get(c)
utils.LogErr(c, err)
if len(keys) == 0 {
auth.Do(c)
keys, err = auth.Get(c)
}
utils.LogErr(c, err, keys)
// i, err := strconv.ParseInt(keys["__timestamp"], 10, 64)
// utils.LogErr(c, err)
// fmt.Printf("%s Keys:\ntoken: %s\tsession: %s\n", time.Unix(i, 0), keys["token"], keys["session"])
return err
},
Subcommands: []cli.Command{{
Name: "delete",
Aliases: []string{"d", "del"},
Usage: "delete stored authentication",
Action: func(c *cli.Context) error {
err := auth.Delete(c)
if err == nil {
log.Println("Authentication deleted.")
}
return err
},
}},
},
}
app.Run(os.Args)
}