aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2014-03-25 14:28:59 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2014-03-25 14:28:59 +0200
commitf65436abbfe64f380ee7af600bf569333fccb3bb (patch)
tree83aac7bd608a823c190a7345a774909fcb3974f9
parentb28248e7fe7f52811f6430eee8c8241eb51f9ecd (diff)
downloaddnstools-f65436abbfe64f380ee7af600bf569333fccb3bb.tar.gz
dnstools-f65436abbfe64f380ee7af600bf569333fccb3bb.tar.bz2
Improve variable expansion in subject and message body.
-rwxr-xr-xrenewck/renewck41
1 files changed, 29 insertions, 12 deletions
diff --git a/renewck/renewck b/renewck/renewck
index 015b005..8c2dea4 100755
--- a/renewck/renewck
+++ b/renewck/renewck
@@ -16,7 +16,7 @@
use strict;
use Getopt::Long qw(:config gnu_getopt no_ignore_case);
-use POSIX qw(strftime time);
+use POSIX qw(strftime time floor);
use IO::Socket;
use Mail::Send;
use Pod::Usage;
@@ -334,8 +334,8 @@ sub whois($$) {
return $expiration;
}
-sub notify($$) {
- my ($domain,$expiration) = @_;
+sub notify($$$) {
+ my ($domain,$expiration,$timeleft) = @_;
my $msg = new Mail::Send;
my $tmpl;
my $body;
@@ -347,9 +347,22 @@ sub notify($$) {
die("cannot open notification template $notify_template_file: $!");
}
+ $timeleft = floor($timeleft / 86400);
+ my $days;
+ if ($timeleft == 0) {
+ $days = "less than one day";
+ } elsif ($timeleft == 1) {
+ $days = "one day";
+ } else {
+ $days = "$timeleft days";
+ }
+
$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);
$msg->add("Cc", $notify_cc) if $notify_cc;
$msg->add("User-Agent", "renewck");
@@ -358,6 +371,8 @@ sub notify($$) {
while (<$tmpl>) {
s/\$domain/$domain/g;
s/\$expiration/$expstr/g;
+ s/\$daysleft/$timeleft/g;
+ s/\$days/$days/g;
$body .= $_;
}
close($tmpl);
@@ -381,7 +396,7 @@ sub check_expiration($$) {
debug('DBM',1,
strftime("$domain: last notification on %c", localtime($ts)));
if ($now - $ts >= $interval[1]) {
- notify($domain, $expiration);
+ notify($domain, $expiration, $timeleft);
$cache{$domain} = $now;
return;
}
@@ -551,9 +566,14 @@ A comma-separated list of addresses for the notification mail Cc: header.
=item B<--notify_subject>=I<text>
-Use I<text> as the subject of notification emails. Any occurrence of
-B<$domain> within the text is replaced with the name of the domain the
-notification is about.
+Use I<text> as the subject of notification emails. The following
+variables are expanded within the template text:
+
+ $domain domain the notification refers to;
+ $expiration expiration date, in the preferred date and time
+ representation for the current locale;
+ $daysleft number of days left to the expiration date;
+ $days number of days as a string, e.g. "two days";
The default subject line is:
@@ -561,11 +581,8 @@ The default subject line is:
=item B<--notify-template>=F<FILE>
-The file to be used as a template for the message body. The following
-variables are expanded within the template text: B<$domain>, which is
-replaced with the domain the notification refers to, and B<$expiration>,
-which expands to the expiration date in the preferred date and time
-representation for the current locale.
+The file to be used as a template for the message body. This text
+is expanded as described for B<--notify-subject> above.
=item B<--whois-server>=I<server>[:I<port>]

Return to:

Send suggestions and report system problems to the System administrator.