[pmg-devel] [PATCH pmg-api 02/12] fix #2371: reload pmg-smtp-filter on config change
Stoiko Ivanov
s.ivanov at proxmox.com
Mon Oct 7 21:28:46 CEST 2019
the external services (postfix, clamav,...) are restarted if their configfile
changes (which Template::Toolkit tells us). Since pmg-smtp-filter has no
config file, we save the options affecting it - currently hide_received - in
the PMG::Config object on load, and check for a change of them when restarting
the services.
Signed-off-by: Stoiko Ivanov <s.ivanov at proxmox.com>
---
src/PMG/Config.pm | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/src/PMG/Config.pm b/src/PMG/Config.pm
index 0c907a2..f94688c 100755
--- a/src/PMG/Config.pm
+++ b/src/PMG/Config.pm
@@ -731,6 +731,11 @@ sub pmg_verify_dnsbl_entry {
return $name;
}
+#parameters affecting services w/o config-file (pmgpolicy, pmg-smtp-filter)
+my $pmg_service_params = {
+ mail => { hide_received => 1 },
+};
+
sub new {
my ($type) = @_;
@@ -738,6 +743,15 @@ sub new {
my $cfg = PVE::INotify::read_file("pmg.conf");
+ $cfg->{current} = {};
+ my $val;
+ foreach my $sec (keys %$pmg_service_params) {
+ foreach my $keep (keys %{$pmg_service_params->{$sec}}) {
+ $val = $cfg->{ids}->{$sec}->{$keep};
+ $cfg->{current}->{$sec}->{$keep} = $val if defined($val);
+ }
+ }
+
return bless $cfg, $class;
}
@@ -1548,6 +1562,21 @@ sub rewrite_config_postfix {
return $changes;
}
+sub check_smtp_filter_config {
+ my ($self) = @_;
+
+ my ($oldval, $newval);
+ foreach my $sec (keys %$pmg_service_params) {
+ foreach my $keep (keys %{$pmg_service_params->{$sec}}) {
+ my $oldval = $self->{current}->{$sec}->{$keep} // '';
+ my $newval = $self->{ids}->{$sec}->{$keep} // '';
+ return 1 if ($oldval ne $newval);
+ }
+ }
+
+ return 0;
+}
+
sub rewrite_config {
my ($self, $rulecache, $restart_services, $force_restart) = @_;
@@ -1589,6 +1618,12 @@ sub rewrite_config {
$log_restart->('clamav-freshclam');
PMG::Utils::service_cmd('clamav-freshclam', 'restart');
}
+
+ if (($self->check_smtp_filter_config() && $restart_services) ||
+ $force_restart->{spam}) {
+ syslog ('info', "scheduled reload for pmg-smtp-filter");
+ PMG::Utils::reload_smtp_filter();
+ }
}
1;
--
2.20.1
More information about the pmg-devel
mailing list