From 1e76548b1a7c3506c7d1fb4f0e63bbafdfa35d10 Mon Sep 17 00:00:00 2001 From: Dimitris Paraskevopoulos Date: Sat, 17 Sep 2022 00:12:35 +0300 Subject: [PATCH] Tidy up code and removed unnecessary commands. Minor fixes that were done to test more easily. --- ddclient.conf.in | 2 +- ddclient.in | 38 +++++++++----------------------------- 2 files changed, 10 insertions(+), 30 deletions(-) diff --git a/ddclient.conf.in b/ddclient.conf.in index 02c0b72..d6bf96c 100644 --- a/ddclient.conf.in +++ b/ddclient.conf.in @@ -314,4 +314,4 @@ ssl=yes # use ssl-support. Works with # protocol=njalla, # password=mypassword # quietreply=no|yes -# my-host +# my-domain.com diff --git a/ddclient.in b/ddclient.in index 4fd6da4..f8360dc 100755 --- a/ddclient.in +++ b/ddclient.in @@ -768,7 +768,6 @@ my %services = ( 'examples' => \&nic_njalla_examples, 'variables' => { %{$variables{'service-common-defaults'}}, - 'login' => setv(T_STRING, 0, 0, 'unused', undef), 'server' => setv(T_FQDNP, 1, 0, 'njal.la', undef), 'quietreply' => setv(T_BOOL, 0, 1, 0, undef) }, @@ -5073,7 +5072,7 @@ Example ${program}.conf file entries: protocol=njalla \\ password=njal.la-key quietreply=no - hostname + domain.com EoEXAMPLE } @@ -5091,12 +5090,14 @@ sub nic_njalla_update { debug("\nnic_njalla_update -------------------"); foreach my $h (@_) { + # Read input params my $ipv4 = delete $config{$h}{'wantipv4'}; my $ipv6 = delete $config{$h}{'wantipv6'}; my $quietreply = delete $config{$h}{'quietreply'}; my $ip_output = ''; - my $url; - $url = "https://$config{$h}{'server'}/update/"; + + # Build url + my $url = "https://$config{$h}{'server'}/update/"; $url .= "?h="; $url .= $h; $url .= "&k="; @@ -5112,54 +5113,33 @@ sub nic_njalla_update { } $url .= (($auto eq 1)) ? '&auto' : ''; $url .= (($quietreply eq 1)) ? '&quiet' : ''; + info("setting address to%s for %s", ($ip_output eq '') ? ' auto' : $ip_output, $h); verbose("UPDATE:", "updating %s", $h); debug("url: %s", $url); # Try to get URL my $reply = geturl(proxy => opt('proxy'), url => $url); - $reply =~ qr/{(?:[^{}]*|(?R))*}/mp; my $response = ''; if ($quietreply) { - $reply =~ qr/^invalid host or key/mp; + $reply =~ qr/invalid host or key/mp; $response = ${^MATCH}; - } else { - $response = eval {decode_json(${^MATCH})}; - } - - next if !header_ok($h, $reply); - verbose("After getting url-*-*-*-*-*-*-*-*-*-\n\n"); - # verbose($reply); - # verbose($response); - verbose("\n\nAfter printing reply , response.-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-\n\n"); - # my @reply = split /\n/, $reply; - # my $returned = pop(@reply); - if ($quietreply) { if (!$response) { success("updating %s: good: IP address set to %s", $h, $ip_output); } elsif ($response =~ /invalid host or key/) { - # verbose($response); failed("Invalid host or key"); - # success("Invalid host or key"); } else { - # verbose($response); failed("Unknown response"); - # success("Unknown response"); } } else { + $reply =~ qr/{(?:[^{}]*|(?R))*}/mp; + $response = eval {decode_json(${^MATCH})}; # No response, declare as failed if (!defined($reply) || !$reply) { failed("updating %s: Could not connect to %s.", $h, $config{$h}{'server'}); } else { # Strip header - verbose("\n\n\nNo quietreply\n\n\n"); - - # info($response); - # verbose($response); - print($response->{status}); - print($response->{message}); - verbose("\n\n\nNo quietreply after printing messges\n\n\n"); if ($response->{status} == 401 && $response->{message} =~ /invalid host or key/) { failed("Invalid host or key"); } elsif ($response->{status} == 200 && $response->{message} =~ /record updated/) {