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.
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
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")
flagGatewayUsername = flag.String("username", "", "The user 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 (
@ -93,6 +94,7 @@ type FritzboxCollector struct {
Gateway string
Username string
Password string
VerifyTls bool
sync.Mutex // protects Root
Root *upnp.Root
@ -124,7 +126,7 @@ func (w *TestResponseWriter) String() string {
// LoadServices tries to load the service information. Retries until success.
func (fc *FritzboxCollector) LoadServices() {
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 {
fmt.Printf("cannot load services: %s\n", err)
@ -315,7 +317,7 @@ func (fc *FritzboxCollector) Collect(ch chan<- prometheus.Metric) {
}
func test() {
root, err := upnp.LoadServices(*flagGatewayUrl, *flagGatewayUsername, *flagGatewayPassword)
root, err := upnp.LoadServices(*flagGatewayUrl, *flagGatewayUsername, *flagGatewayPassword, *flagGatewayVerifyTLS)
if err != nil {
panic(err)
}
@ -453,6 +455,7 @@ func main() {
Gateway: u.Hostname(),
Username: *flagGatewayUsername,
Password: *flagGatewayPassword,
VerifyTls: *flagGatewayVerifyTLS,
}
if *flagCollect {

Loading…
Cancel
Save