aboutsummaryrefslogtreecommitdiff
path: root/renewck
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2014-06-17 11:49:33 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2014-06-17 11:49:33 +0300
commita192ca696d9531f3f80223cbe31ec361583b921c (patch)
treeff456b4ae2538656afc449563ef819647827e637 /renewck
parentd430fb041a224347f07ae1dd65f317aa9c6f4d9b (diff)
downloaddnstools-a192ca696d9531f3f80223cbe31ec361583b921c.tar.gz
dnstools-a192ca696d9531f3f80223cbe31ec361583b921c.tar.bz2
renewck: minor changes
Diffstat (limited to 'renewck')
-rwxr-xr-xrenewck/renewck40
1 files 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/.*\///;

Return to:

Send suggestions and report system problems to the System administrator.