Implemented authentication for list operator

(closes #7)
This commit is contained in:
2019-08-05 21:56:44 +02:00
parent acf4bc9979
commit fb75de8dcb
2 changed files with 9 additions and 2 deletions

View File

@@ -26,6 +26,8 @@
# hours, weeks or seconds. format: [0-9]+[mhws]? # hours, weeks or seconds. format: [0-9]+[mhws]?
# Authentication Settings # Authentication Settings
#domain_list_key = off # List operation, 'off' to disable, '' to always
# allow and other values to enable with secret
#auth_mode = remote # either 'static', 'remote' or 'both' #auth_mode = remote # either 'static', 'remote' or 'both'
#static_signer = # required for AuthMode 'static' or 'both' #static_signer = # required for AuthMode 'static' or 'both'
#static_key = # required for AuthMode 'static' or 'both' #static_key = # required for AuthMode 'static' or 'both'

View File

@@ -41,6 +41,8 @@ my @DNSDomain = ( '?', '!', 0 ); # DNS Domain to support, match hostname with:
my $ExpandCNAMEs = 1; # CNAME levels to expand (0 to disable) my $ExpandCNAMEs = 1; # CNAME levels to expand (0 to disable)
my $AllowDebugKey = 'off'; # Debuging, 'off' to disable, '' for always on my $AllowDebugKey = 'off'; # Debuging, 'off' to disable, '' for always on
# and other values to enable with debug= param. # and other values to enable with debug= param.
my $DomainListKey = 'off'; # List operation, 'off' to disable, '' to always
# allow and other values to enable with secret
my $AuthMode = 'remote'; # either 'static', 'remote' or 'both' my $AuthMode = 'remote'; # either 'static', 'remote' or 'both'
my $StaticSigner = ''; # required for AuthMode 'static' or 'both' my $StaticSigner = ''; # required for AuthMode 'static' or 'both'
my $StaticKey = ''; # required for AuthMode 'static' or 'both' my $StaticKey = ''; # required for AuthMode 'static' or 'both'
@@ -133,7 +135,6 @@ my $CE = 'Configuration Error';
my $PE = 'Required parameter missing'; my $PE = 'Required parameter missing';
sub fail($$;$) { sub fail($$;$) {
my ($errormsg, $debugmsg, $exitcode) = @_; my ($errormsg, $debugmsg, $exitcode) = @_;
print $debug . "\n";
print $cgi->header(-status=>$exitcode || 503, -type=>'text/plain'), print $cgi->header(-status=>$exitcode || 503, -type=>'text/plain'),
"ERROR - $errormsg" . ($debug ? ": $debugmsg\n" : "\n"); "ERROR - $errormsg" . ($debug ? ": $debugmsg\n" : "\n");
exit 0; exit 0;
@@ -323,6 +324,10 @@ sub handle_list($$$$) {
my ($mode, $host, $dnsdomain, $debug) = @_; my ($mode, $host, $dnsdomain, $debug) = @_;
my $title = "DynDNS Updater - $dnsdomain"; my $title = "DynDNS Updater - $dnsdomain";
fail("Operation not allowed", ($DomainListKey eq 'off') ? "List is disabled"
: "No/incorrect authentication information provided", 403)
if ($DomainListKey eq 'off') || (($DomainListKey cmp '') && ($DomainListKey cmp $cgi->param('secret')));
print $cgi->header(-status=>200), print $cgi->header(-status=>200),
$cgi->start_html(-title => $title), $cgi->start_html(-title => $title),
$cgi->h1($title); $cgi->h1($title);
@@ -354,7 +359,7 @@ if ($ConfigFile cmp 'ignore') {
$CFGFile =~ s/(\.pl)?$/.cfg/; $CFGFile =~ s/(\.pl)?$/.cfg/;
if (open (CONFIG, $CFGFile)) { if (open (CONFIG, $CFGFile)) {
my %CONFIG = ( my %CONFIG = (
allow_debug_key => \$AllowDebugKey, allow_debug_key => \$AllowDebugKey, domain_list_key => \$DomainListKey,
dns_server => \$DNSServer, dns_domain => \@DNSDomain, dns_server => \$DNSServer, dns_domain => \@DNSDomain,
expand_cnames => \$ExpandCNAMEs, auth_mode => \$AuthMode, expand_cnames => \$ExpandCNAMEs, auth_mode => \$AuthMode,
static_signer => \$StaticSigner, static_key => \$StaticKey, static_signer => \$StaticSigner, static_key => \$StaticKey,