Browse Source

Add additional flag to control the verification of tls connections.

master
Christian Fritz 4 years ago
parent
commit
5fda388374
No known key found for this signature in database GPG Key ID: AB40486FCA9FA29C
  1. 6
      fritzbox_upnp/service.go
  2. 9
      main.go

6
fritzbox_upnp/service.go

@ -500,10 +500,10 @@ func convertResult(val string, arg *Argument) (interface{}, error) {
} }
} }
// LoadServices load the services tree from an device. // LoadServices loads the services tree from an device.
func LoadServices(baseurl string, username string, password string) (*Root, error) { func LoadServices(baseurl string, username string, password string, verifyTls bool) (*Root, error) {
if strings.HasPrefix(baseurl, "https://") { if !verifyTls && strings.HasPrefix(baseurl, "https://") {
// disable certificate validation, since fritz.box uses self signed cert // disable certificate validation, since fritz.box uses self signed cert
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true} http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
} }

9
main.go

@ -56,6 +56,7 @@ var (
flagGatewayLuaURL = flag.String("gateway-luaurl", "http://fritz.box", "The URL of the FRITZ!Box UI") flagGatewayLuaURL = flag.String("gateway-luaurl", "http://fritz.box", "The URL of the FRITZ!Box UI")
flagUsername = flag.String("username", "", "The user for the FRITZ!Box UPnP service") flagUsername = flag.String("username", "", "The user for the FRITZ!Box UPnP service")
flagPassword = flag.String("password", "", "The password for the FRITZ!Box UPnP service") flagPassword = flag.String("password", "", "The password for the FRITZ!Box UPnP service")
flagGatewayVerifyTLS = flag.Bool("verifyTls", false, "Verify the tls connection when connecting to the FRITZ!Box")
) )
var ( var (
@ -183,6 +184,7 @@ type FritzboxCollector struct {
Gateway string Gateway string
Username string Username string
Password string Password string
VerifyTls bool
// support for lua collector // support for lua collector
LuaSession *lua.LuaSession LuaSession *lua.LuaSession
@ -218,7 +220,7 @@ func (w *testResponseWriter) String() string {
// LoadServices tries to load the service information. Retries until success. // LoadServices tries to load the service information. Retries until success.
func (fc *FritzboxCollector) LoadServices() { func (fc *FritzboxCollector) LoadServices() {
for { for {
root, err := upnp.LoadServices(fc.URL, fc.Username, fc.Password) root, err := upnp.LoadServices(fc.URL, fc.Username, fc.Password, fc.VerifyTls)
if err != nil { if err != nil {
fmt.Printf("cannot load services: %s\n", err) fmt.Printf("cannot load services: %s\n", err)
@ -535,7 +537,7 @@ func (fc *FritzboxCollector) reportLuaMetric(ch chan<- prometheus.Metric, lm *Lu
} }
func test() { func test() {
root, err := upnp.LoadServices(*flagGatewayURL, *flagUsername, *flagPassword) root, err := upnp.LoadServices(*flagGatewayURL, *flagUsername, *flagPassword, *flagGatewayVerifyTLS)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -805,8 +807,9 @@ func main() {
Gateway: u.Hostname(), Gateway: u.Hostname(),
Username: *flagUsername, Username: *flagUsername,
Password: *flagPassword, Password: *flagPassword,
VerifyTls: *flagGatewayVerifyTLS,
LuaSession: luaSession, LuaSession: luaSession,
LabelRenames: luaLabelRenames, LabelRenames: luaLabelRenames,
} }

Loading…
Cancel
Save