From a192ca696d9531f3f80223cbe31ec361583b921c Mon Sep 17 00:00:00 2001 From: Sergey Poznyakoff Date: Tue, 17 Jun 2014 11:49:33 +0300 Subject: renewck: minor changes --- renewck/renewck | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/renewck/renewck b/renewck/renewck index 8c2dea4..9659c05 100755 --- a/renewck/renewck +++ b/renewck/renewck @@ -334,6 +334,13 @@ sub whois($$) { return $expiration; } +sub interpret { + my ($subject, $dict) = @_; + $subject =~ s/\$([a-zA-Z_][a-zA-Z0-9_]*)/defined($dict->{$1}) ? $dict->{$1} : \$$1/gex; + $subject =~ s/\$\{([a-zA-Z_][a-zA-Z0-9_]*\})/defined($dict->{$1}) ? $dict->{$1} : \$$1/gex; + return $subject; +} + sub notify($$$) { my ($domain,$expiration,$timeleft) = @_; my $msg = new Mail::Send; @@ -358,23 +365,19 @@ sub notify($$$) { } $msg->to($notify_address); - my $subject = $notify_subject; - $subject =~ s/\$domain/$domain/g; - $subject =~ s/\$expiration/$expstr/g; - $subject =~ s/\$daysleft/$timeleft/g; - $subject =~ s/\$days/$days/g; - $msg->subject($subject); + my %dict = ( + domain => $domain, + expiration => $expstr, + daysleft => $timeleft, + days => $days + ); + + $msg->subject(interpret($notify_subject, \%dict)); $msg->add("Cc", $notify_cc) if $notify_cc; $msg->add("User-Agent", "renewck"); if ($tmpl) { - while (<$tmpl>) { - s/\$domain/$domain/g; - s/\$expiration/$expstr/g; - s/\$daysleft/$timeleft/g; - s/\$days/$days/g; - $body .= $_; - } + $body .= interpret($_, \%dict) while (<$tmpl>); close($tmpl); } my $fh = $msg->open; @@ -388,14 +391,13 @@ sub check_expiration($$) { my $timeleft = $expiration - $now; debug('MAIN',1,"$domain expires in $timeleft seconds"); return if ($timeleft < 0); - foreach my $entry (@notify_interval) { - my @interval = @{$entry}; - if ($interval[0] >= $timeleft) { - debug('MAIN',2,"$domain expires in less than $interval[0] seconds; using notification interval $interval[1]"); + foreach my $interval (@notify_interval) { + if ($interval->[0] >= $timeleft) { + debug('MAIN',2,"$domain expires in less than $interval->[0] seconds; using notification interval $interval->[1]"); my $ts = $cache{$domain}; debug('DBM',1, strftime("$domain: last notification on %c", localtime($ts))); - if ($now - $ts >= $interval[1]) { + if ($now - $ts >= $interval->[1]) { notify($domain, $expiration, $timeleft); $cache{$domain} = $now; return; @@ -404,7 +406,7 @@ sub check_expiration($$) { } } -##########################################3 +########################################## ($script = $0) =~ s/.*\///; -- cgit v1.2.1