3 $ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin';
5 delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
14 use PVE
::RESTEnvironment
;
18 use PMG
::ClusterConfig
;
20 use PMG
::API2
::Subscription
;
22 use PMG
::API2
::Certificates
;
26 $SIG{'__WARN__'} = sub {
31 syslog
('warning', "%s", $t);
35 PVE
::RESTEnvironment-
>setup_default_cli_env();
37 initlog
('pmg-daily', 'mail');
39 my $nodename = PVE
::INotify
::nodename
();
41 eval { PMG
::API2
::Subscription-
>update({ node
=> $nodename }); };
43 syslog
('err', "update subscription info failed: $err");
46 my $cfg = PMG
::Config-
>new();
48 if (my $statlifetime = $cfg->get ('admin', 'statlifetime')) {
51 my $dbh = PMG
::DBTools
::open_ruledb
();
52 $count = PMG
::DBTools
::purge_statistic_database
($dbh, $statlifetime);
57 syslog
('info', "cleanup removed $count entries from statistic database") if $count;
61 # check for available updates
62 # We assume that users with subscriptions want information
64 my $info = eval { PMG
::API2
::Subscription
::read_etc_subscription
() };
65 my $notify = ($info && $info->{status
} eq 'active') ?
1 : 0;
66 eval { PMG
::API2
::APT-
>update_database({ node
=> $nodename, notify
=> $notify, quiet
=> 1 }); };
68 syslog
('err', "update apt database failed: $err");
71 # rotate razor log file
72 rename('/root/.razor/razor-agent.log', '/root/.razor/razor-agent.log.0');
74 # setup proxy env (assume sa-update use http)
75 if (my $http_proxy = $cfg->get('admin', 'http_proxy')) {
76 $ENV{http_proxy
} = $http_proxy;
79 # update spamassassin rules
80 my $restart_filter = 0;
81 if (system('sa-update') == 0) {
82 # if the exit code is 0, new updates were downloaded
83 # then restart the pmg-smtp-filter to load the new rules
88 $restart_filter = 1 if PMG
::Utils
::update_local_spamassassin_channels
(0);
90 syslog
('err', "$@") if $@;
92 PMG
::Utils
::service_cmd
('pmg-smtp-filter', 'restart') if $restart_filter;
93 # run bayes database maintenance
94 system('sa-learn --force-expire >/dev/null 2>&1');
97 my $node_config = PMG
::NodeConfig
::load_config
();
98 my $acme_node_config = PMG
::NodeConfig
::get_acme_conf
($node_config);
99 my $acme_domains = $acme_node_config && $acme_node_config->{domains
};
101 my %typed_domains = map {
102 $_ => PMG
::NodeConfig
::filter_domains_by_type
($acme_domains, $_)
105 foreach my $type (qw(api smtp)) {
106 next if !$typed_domains{$type};
108 # Guard both certificates separately.
110 my $cert = PMG
::CertHelpers
::cert_path
($type);
112 syslog
('info', "ACME config found for '$type' certificate, but no custom certificate exists. Skipping ACME renewal until initial certificate has been deployed.");
116 if (PVE
::Certificate
::check_expiry
($cert, time() + 30*24*60*60)) {
117 PMG
::API2
::Certificates-
>renew_acme_cert({ node
=> $nodename, type
=> $type });
119 syslog
('info', "Custom '$type' certificate does not expire soon, skipping ACME renewal.");
122 syslog
('err', "Renewing '$type' ACME certificate failed: $@") if $@;
126 syslog
('err', "Renewing ACME certificate failed: $@") if $@;