forked from Velocidex/velociraptor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_frontend.go
99 lines (78 loc) · 2.93 KB
/
config_frontend.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
// +build !aix
package main
import (
"fmt"
"github.com/Velocidex/survey"
kingpin "gopkg.in/alecthomas/kingpin.v2"
config_proto "www.velocidex.com/golang/velociraptor/config/proto"
)
var (
config_frontend_command = config_command.Command(
"frontend", "Add a new frontend configuration")
)
func reportCurrentSetup(config_obj *config_proto.Config) string {
result := fmt.Sprintf("Master frontend is at %v:%v \n\n",
config_obj.Frontend.Hostname, config_obj.Frontend.BindPort)
if len(config_obj.ExtraFrontends) > 0 {
result += fmt.Sprintf("Currently configured %v minion frontends\n\n", len(config_obj.ExtraFrontends))
for idx, frontend := range config_obj.ExtraFrontends {
result += fmt.Sprintf("Minion %v: %v:%v\n", idx+1,
frontend.Hostname, frontend.BindPort)
}
}
return result + "\n"
}
func doConfigFrontend() {
config_obj, err := DefaultConfigLoader.WithRequiredFrontend().LoadAndValidate()
kingpin.FatalIfError(err, "Unable to load config.")
doit := false
kingpin.FatalIfError(survey.AskOne(&survey.Confirm{
Message: `
Welcome to the Velociraptor configuration generator
---------------------------------------------------
I will be adding an extra minion frontend to the configuration. I will not be changing the master frontend configuration at all.
` + reportCurrentSetup(config_obj) + `
Do you wish to continue?`,
},
&doit, survey.WithValidator(survey.Required)), "")
if !doit {
return
}
// Create a new frontend config
frontend_config := &config_proto.FrontendConfig{
BindAddress: "0.0.0.0",
}
// Set a better default for the url question
url_question.Default = config_obj.Frontend.Hostname
// Figure out the install type
if config_obj.Client.UseSelfSignedSsl {
kingpin.FatalIfError(survey.Ask([]*survey.Question{
{Name: "Hostname", Prompt: &survey.Input{
Message: "What is the public name of the minion frontend (e.g. 192.168.1.22 or ns2.example.com)",
Default: config_obj.Frontend.Hostname,
}},
{Name: "BindPort", Prompt: &survey.Input{
Message: "What port should this frontend listen on?",
Default: fmt.Sprintf("%v", config_obj.Frontend.BindPort),
}},
}, frontend_config, survey.WithValidator(survey.Required)), "")
// Add the frontend into the client's configuration.
config_obj.Client.ServerUrls = append(config_obj.Client.ServerUrls,
fmt.Sprintf("https://%v:%v/", frontend_config.Hostname,
frontend_config.BindPort))
} else {
kingpin.FatalIfError(survey.AskOne(url_question, &frontend_config.Hostname,
survey.WithValidator(survey.Required)), "")
}
if config_obj.Frontend.DynDns != nil &&
config_obj.Frontend.DynDns.DdnsUsername != "" {
kingpin.FatalIfError(dynDNSConfig(config_obj.Frontend), "")
}
// Add the additional frontend.
config_obj.ExtraFrontends = append(config_obj.ExtraFrontends,
frontend_config)
// API server must be exposed to allow multiple frontends to
// call it.
config_obj.API.BindAddress = "0.0.0.0"
storeServerConfig(config_obj)
}