Commit 89b504e6d307f834f75ce633aedbbf8376069f51

Authored by Frederik Lindenaar
1 parent ec25394c

moved obtaining $signer and $key into a function, which now also ensures that bo…

…th have a value (if not, abort with an HTTP 400 errro)

renamed LICENSE file for clarity
LICENSE renamed to LICENSE.txt
dyndns.pl
@@ -138,7 +138,28 @@ sub expand_CNAME($;$) { @@ -138,7 +138,28 @@ sub expand_CNAME($;$) {
138 return $host; 138 return $host;
139 } 139 }
140 140
141 -# Method to perform an DNS Update for a single host 141 +# Get signer and key CGI paramseters, abort with HTTP 400 error if not present
  142 +sub get_authinfo($$) {
  143 + my ($cgi, $host) = @_;
  144 +
  145 + # Get signer and key parameters
  146 + my $signer = ($AuthMode eq 'static') ? $StaticSigner : ($cgi->param('user')
  147 + || (($AuthMode eq 'both') ? $StaticSigner : $host));
  148 + my $key = ($AuthMode eq 'static') ? $StaticKey : ($cgi->param('secret')
  149 + || (($AuthMode eq 'both') ? $StaticSigner : undef));
  150 +
  151 + # Ensure we have a value for signer and key, otherwise abort the processing
  152 + if($signer eq '' or $key eq '') {
  153 + print $cgi->header(-status=>400, -type=>'text/plain'),
  154 + "ERROR - No/incomplete authentication information provided\n";
  155 + exit
  156 + }
  157 +
  158 + # and return the values
  159 + return($signer, $key);
  160 +}
  161 +
  162 +# Perform an DNS Update for a single host
142 sub DNS_Update($$$$$$$) { 163 sub DNS_Update($$$$$$$) {
143 my ($dnsdomain, $dnshost, $ipv4, $ipv6, $signer, $key, $debug) = @_; 164 my ($dnsdomain, $dnshost, $ipv4, $ipv6, $signer, $key, $debug) = @_;
144 my $dnsupdate = Net::DNS::Update->new($dnsdomain); 165 my $dnsupdate = Net::DNS::Update->new($dnsdomain);
@@ -190,12 +211,7 @@ sub DNS_Update($$$$$$$) { @@ -190,12 +211,7 @@ sub DNS_Update($$$$$$$) {
190 # Handlers for the different requests 211 # Handlers for the different requests
191 sub handle_update($$$$$$) { 212 sub handle_update($$$$$$) {
192 my ($cgi, $mode, $host, $dnshost, $dnsdomain, $debug) = @_; 213 my ($cgi, $mode, $host, $dnshost, $dnsdomain, $debug) = @_;
193 -  
194 - # Get signer and key parameters  
195 - my $signer = ($AuthMode eq 'static') ? $StaticSigner : ($cgi->param('user')  
196 - || (($AuthMode eq 'both') ? $StaticSigner : $host));  
197 - my $key = ($AuthMode eq 'static') ? $StaticKey : ($cgi->param('secret')  
198 - || (($AuthMode eq 'both') ? $StaticSigner : undef)); 214 + my ($signer, $key) = get_authinfo($cgi, $host);
199 215
200 # perform the action 216 # perform the action
201 my ($statuscode, $statusmessage); 217 my ($statuscode, $statusmessage);
@@ -221,13 +237,8 @@ sub handle_update($$$$$$) { @@ -221,13 +237,8 @@ sub handle_update($$$$$$) {
221 237
222 sub handle_expire($$$$$$) { 238 sub handle_expire($$$$$$) {
223 my ($cgi, $mode, $host, $dnshost, $dnsdomain, $debug) = @_; 239 my ($cgi, $mode, $host, $dnshost, $dnsdomain, $debug) = @_;
  240 + my ($signer, $key) = get_authinfo($cgi, $host);
224 241
225 - # Get signer and key parameters  
226 - my $signer = ($AuthMode eq 'static') ? $StaticSigner : ($cgi->param('user')  
227 - || (($AuthMode eq 'both') ? $StaticSigner : $host));  
228 - my $key = ($AuthMode eq 'static') ? $StaticKey : ($cgi->param('secret')  
229 - || (($AuthMode eq 'both') ? $StaticSigner : undef));  
230 -  
231 my $debugmsg = ($debug) ? "\n" : ''; 242 my $debugmsg = ($debug) ? "\n" : '';
232 243
233 # perform the action 244 # perform the action