From 3cd48a76f002e382fc2c1ffb0becfc9d52d0ca25 Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Thu, 22 Jan 2009 02:12:21 +0000 Subject: [PATCH] Work on support for multiple spamassassin config files --- spam/lang/en | 1 + spam/spam-lib.pl | 43 +++++++++++++++++++++++++++++++++++++++---- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/spam/lang/en b/spam/lang/en index e4976daf9..c78137fc7 100644 --- a/spam/lang/en +++ b/spam/lang/en @@ -11,6 +11,7 @@ index_apply=Apply Changes index_applydesc=Click this button to apply the current SpamAssassin configuration by sending a HUP signal to all running $1 processes. index_cpan=Because SpamAssassin is a Perl module, you can also install it automatically using Webmin's Perl Modules module to download $1 from CPAN. index_spamassassin=SpamAssassin +index_ecannot=You are not allowed to manage the SpamAssassin configuration file $1 white_title=Allowed and Denied Addresses white_desc=The tables on this page allow you to specify From: and To: addresses for email that is always or never categorized as spam. Any other email will be processed as normal by SpamAssassin's rules. All email addresses can contain wildcards, like *@foo.com or *.foo.com to match entire domains. diff --git a/spam/spam-lib.pl b/spam/spam-lib.pl index 5df4b31c3..61c75da13 100644 --- a/spam/spam-lib.pl +++ b/spam/spam-lib.pl @@ -6,18 +6,21 @@ do '../web-lib.pl'; do '../ui-lib.pl'; use Fcntl; -$local_cf = $config{'local_cf'}; $warn_procmail = $config{'warn_procmail'}; if ($module_info{'usermin'}) { # Running under Usermin, editing user's personal config file &switch_to_remote_user(); &create_user_config_dirs(); - if ($local_cf !~ /^\//) { - $local_cf = "$remote_user_info[7]/$local_cf"; + if ($config{'local_cf'} !~ /^\//) { + # Path is relative to home dir + &set_config_file("$remote_user_info[7]/$config{'local_cf'}"); if ($local_cf =~ /^(.*)\// && !-d $1) { mkdir($1, 0700); } } + else { + &set_config_file($config{'local_cf'}); + } $database_userpref_name = $remote_user; $include_config_files = !$config{'mode'} || $config{'readfiles'}; $add_to_db = 1; @@ -27,7 +30,10 @@ else { # Running under Webmin, typically editing global config file %access = &get_module_acl(); if ($access{'file'}) { - $local_cf = $access{'file'}; + &set_config_file($access{'file'}); + } + else { + &set_config_file($config{'local_cf'}); } if ($access{'nocheck'}) { $warn_procmail = 0; @@ -39,9 +45,38 @@ else { } $ldap_spamassassin_attr = $config{'attr'} || 'spamassassin'; $ldap_username_attr = $config{'uid'} || 'uid'; + +# set_config_file(file) +# Change the default file read by get_config. Under Webmin, checks if this file +# is accessible to the current user +sub set_config_file +{ +local ($file) = @_; +if (!$module_info{'usermin'}) { + # Check for valid file + local %cans; + $cans{$access{'file'}} = 1 if ($access{'file'}); + foreach my $f (split(/\s+/, $access{'file'})) { + $cans{$f} = 1; + } + if (keys %cans) { + $cans{$file} || &error(&text('index_ecannot', + "".&html_escape($file)."")); + } + } +$local_cf = $file; $add_cf = !-d $local_cf ? $local_cf : $module_info{'usermin'} ? "$local_cf/user_prefs" : "$local_cf/local.cf"; +} + +sub set_config_file_in +{ +local ($in) = @_; +if (!$module_info{'usermin'} && $in{'file'}) { + &set_config_file($in{'file'}); + } +} # get_config([file], [for-global]) # Return a structure containing the contents of the spamassassin config file