forked from virtualmin/virtualmin-registrar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
auto.pl
executable file
·121 lines (114 loc) · 3.17 KB
/
auto.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/usr/local/bin/perl
# Automatically renew domains close to expiry
use strict;
no strict 'refs';
use warnings;
our (%text);
package virtualmin_registrar;
no warnings "once";
$main::no_acl_check++;
use warnings "once";
require './virtualmin-registrar-lib.pl';
&foreign_require("mailboxes", "mailboxes-lib.pl");
# Do accounts with renewal
foreach my $account (grep { $_->{'autodays'} ||
$_->{'autowarn'} } &list_registrar_accounts()) {
# Find domains, and get expiry for each
my @rv;
my @wrv;
my $warncount = my $donecount = 0;
my @doms = &find_account_domains($account);
my $efunc = "type_".$account->{'registrar'}."_get_expiry";
my $rfunc = "type_".$account->{'registrar'}."_renew_domain";
foreach my $d (@doms) {
my $msg;
my $wmsg;
my ($ok, $exp) = &$efunc($account, $d);
if (!$ok) {
# Couldn't get it!
$msg = &text('auto_eget', $exp);
}
elsif ($account->{'autodays'} &&
$exp - time() < $account->{'autodays'}*24*60*60) {
# Time to renew!
$account->{'rcom_account'} = "xxx";
my ($ok, $rmsg) = &$rfunc($account, $d,
$account->{'autoyears'});
if ($ok) {
$msg = &text('auto_done',
$account->{'autoyears'});
}
else {
$msg = &text('auto_failed', $rmsg);
}
$donecount++;
}
elsif ($account->{'autowarn'} &&
$exp - time() < $account->{'autowarn'}*24*60*60) {
# Time to send warning
$wmsg = &text('auto_warnmsg', int(($exp - time()) /
(24*60*60)));
$warncount++;
}
# Add to results lists
if ($msg) {
push(@rv, [ $account, $d, $msg ]);
}
if ($wmsg) {
push(@wrv, [ $account, $d, $wmsg ]);
}
}
# Send email to master admin and possibly domain owners if any
# renewals were done
if ($donecount) {
if ($account->{'autoemail'}) {
&send_auto_email(\@rv, $account->{'autoemail'},
$text{'auto_subject'},
$text{'auto_results'});
}
if ($account->{'autoowner'}) {
foreach my $e (&unique(map { $_->[1]->{'emailto'} } @rv)) {
my @rve = grep { $_->[1]->{'emailto'} eq $e } @rv;
&send_auto_email(\@rve, $e,
$text{'auto_subject'},
$text{'auto_results'});
}
}
}
# Send email to if any expiry warnings were generated
if ($warncount) {
if ($account->{'autoemail'}) {
&send_auto_email(\@wrv, $account->{'autoemail'},
$text{'auto_wsubject'},
$text{'auto_wresults'});
}
if ($account->{'autoowner'}) {
foreach my $e (&unique(map { $_->[1]->{'emailto'}} @wrv)) {
my @rve = grep { $_->[1]->{'emailto'} eq $e } @wrv;
&send_auto_email(\@rve, $e,
$text{'auto_wsubject'},
$text{'auto_wresults'});
}
}
}
}
# send_auto_email(&messages, email, subject-line, body-heading)
# Send email about some renewals or warnings to an address
sub send_auto_email
{
my ($rv, $email, $subject, $heading) = @_;
my $msg = join("\n", &mailboxes::wrap_lines($heading, 70))."\n\n";
my $fmt = "%-40.40s %-39.39s\n";
$msg .= sprintf $fmt, $text{'auto_rdom'}, $text{'auto_rmsg'};
$msg .= sprintf $fmt, ("-" x 40), ("-" x 39);
foreach my $r (@$rv) {
$msg .= sprintf $fmt, $r->[1]->{'dom'}, $r->[2];
}
$msg .= "\n";
&mailboxes::send_text_mail(
&virtual_server::get_global_from_address(),
$email,
undef,
$subject,
$msg);
}