Browse Source

Add additional flag to control the verification of tls connections.

pull/1/head
Christian Fritz 5 years ago
parent
commit
3f6ecd4a81
No known key found for this signature in database GPG Key ID: AB40486FCA9FA29C
  1. 4
      fritzbox_upnp/service.go
  2. 7
      main.go

4
fritzbox_upnp/service.go

@ -493,9 +493,9 @@ func convertResult(val string, arg *Argument) (interface{}, error) {
} }
// Load the services tree from an device. // Load 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}
} }

7
main.go

@ -49,6 +49,7 @@ var (
flagGatewayUrl = flag.String("gateway-url", "http://fritz.box:49000", "The URL of the FRITZ!Box") flagGatewayUrl = flag.String("gateway-url", "http://fritz.box:49000", "The URL of the FRITZ!Box")
flagGatewayUsername = flag.String("username", "", "The user for the FRITZ!Box UPnP service") flagGatewayUsername = flag.String("username", "", "The user for the FRITZ!Box UPnP service")
flagGatewayPassword = flag.String("password", "", "The password for the FRITZ!Box UPnP service") flagGatewayPassword = 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 (
@ -93,6 +94,7 @@ type FritzboxCollector struct {
Gateway string Gateway string
Username string Username string
Password string Password string
VerifyTls bool
sync.Mutex // protects Root sync.Mutex // protects Root
Root *upnp.Root Root *upnp.Root
@ -124,7 +126,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)
@ -315,7 +317,7 @@ func (fc *FritzboxCollector) Collect(ch chan<- prometheus.Metric) {
} }
func test() { func test() {
root, err := upnp.LoadServices(*flagGatewayUrl, *flagGatewayUsername, *flagGatewayPassword) root, err := upnp.LoadServices(*flagGatewayUrl, *flagGatewayUsername, *flagGatewayPassword, *flagGatewayVerifyTLS)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -453,6 +455,7 @@ func main() {
Gateway: u.Hostname(), Gateway: u.Hostname(),
Username: *flagGatewayUsername, Username: *flagGatewayUsername,
Password: *flagGatewayPassword, Password: *flagGatewayPassword,
VerifyTls: *flagGatewayVerifyTLS,
} }
if *flagCollect { if *flagCollect {

Loading…
Cancel
Save