Completed AWL management
authorJamie Cameron <jcameron@webmin.com>
Tue, 1 Apr 2008 20:48:15 +0000 (20:48 +0000)
committerJamie Cameron <jcameron@webmin.com>
Tue, 1 Apr 2008 20:48:15 +0000 (20:48 +0000)
spam/CHANGELOG
spam/config
spam/config-debian-linux
spam/config-freebsd
spam/config.info
spam/delete_awl.cgi
spam/deleteone_awl.cgi [new file with mode: 0644]
spam/edit_awl.cgi
spam/lang/en
spam/spam-lib.pl

index a7f3b6b..bca53c6 100644 (file)
@@ -11,3 +11,5 @@ Added Module Config options for commands to run before and after saving SpamAssa
 ---- Changes since 1.360 ----
 Added the SQL and LDAP Databases page for configuring SpamAssassin to use a MySQL, PostgreSQL or LDAP database for user preferences.
 Added global configuration settings to use MySQL, PostgreSQL or LDAP backends for storing preferences.
+---- Changes since 1.410 ----
+Auto-whitelists can now be viewed, deleted from and cleared for all users on the system. An access control option allows this to be limited to just certain users or group members.
index 96bcbcc..b502646 100644 (file)
@@ -8,3 +8,4 @@ processes=spamd amavisd
 procmail_cmd=*
 mode=0
 addto=0
+max_awl=200
index 5668302..237f2c5 100644 (file)
@@ -9,3 +9,4 @@ restart_cmd=/etc/init.d/spamassassin restart
 procmail_cmd=*
 mode=0
 addto=0
+max_awl=200
index 7a30b8c..2428982 100644 (file)
@@ -8,3 +8,4 @@ processes=spamd amavisd
 procmail_cmd=*
 mode=0
 addto=0
+max_awl=200
index 86911e3..9cb8145 100644 (file)
@@ -9,6 +9,7 @@ restart_cmd=Command to restart processes,3,Just send HUP signal
 procmail_cmd=SpamAssassin command for Procmail configuration,10,*-Detect automatically
 before_cmd=Command to run before changing rules,3,None
 after_cmd=Command to run after changing rules,3,None
+max_awl=Maximum number of auto-whitelist entries to display,0,5
 line1=LDAP and SQL server options,11
 mode=Store SpamAssassin settings in,1,0-Configuration files,1-MySQL database,2-PostgreSQL database,3-LDAP database
 server=LDAP or SQL server hostname,0
index b07a516..ac5b814 100644 (file)
@@ -5,6 +5,7 @@ require './spam-lib.pl';
 &error_setup($text{'dawl_err'});
 &can_use_check("awl");
 &ReadParse();
+&can_edit_awl($in{'user'}) || &error($text{'dawl_ecannot'});
 
 # Check stuff
 &open_auto_whitelist_dbm($in{'user'}) || &error($text{'dawl_eopen'});
diff --git a/spam/deleteone_awl.cgi b/spam/deleteone_awl.cgi
new file mode 100644 (file)
index 0000000..78b0eb3
--- /dev/null
@@ -0,0 +1,18 @@
+#!/usr/local/bin/perl
+# Delete all auto-whitelist entries
+
+require './spam-lib.pl';
+&error_setup($text{'dawl_err'});
+&can_use_check("awl");
+&ReadParse();
+&can_edit_awl($in{'user'}) || &error($text{'dawl_ecannot'});
+
+# Delete them
+&open_auto_whitelist_dbm($in{'user'}) || &error($text{'dawl_eopen'});
+foreach $k (keys %awl) {
+       delete($awl{$k});
+       }
+&close_auto_whitelist_dbm();
+&redirect("edit_awl.cgi?search=".&urlize($in{'search'}).
+         "&user=".&urlize($in{'user'}));
+
index 15ffc85..de19f12 100644 (file)
@@ -1,7 +1,6 @@
 #!/usr/local/bin/perl
 # Display entries in the auto-whitelist
 # XXX delete all
-# XXX access control
 
 require './spam-lib.pl';
 &can_use_check("awl");
@@ -27,8 +26,17 @@ if (&supports_auto_whitelist() == 2) {
 # Open the DBM, or give up
 $awf = &get_auto_whitelist_file($in{'user'});
 $ok = &open_auto_whitelist_dbm($in{'user'});
-if (!$awf) {
-       &ui_print_endpage("<b>".&text('awl_nofile')."</b>");
+if (!&can_edit_awl($in{'user'})) {
+       &ui_print_endpage("<b>".&text('awl_cannotuser',
+               "<tt>".&html_escape($in{'user'})."</tt>")."</b>");
+       }
+elsif (!defined(getpwnam($in{'user'}))) {
+       &ui_print_endpage("<b>".&text('awl_nouser',
+               "<tt>".&html_escape($in{'user'})."</tt>")."</b>");
+       }
+elsif (!$awf) {
+       &ui_print_endpage("<b>".&text('awl_nofile',
+               "<tt>".&html_escape($in{'user'})."</tt>")."</b>");
        }
 elsif ($ok == 0) {
        &ui_print_endpage("<b>".&text('awl_cannot', $awf)."</b>");
@@ -39,6 +47,7 @@ elsif ($ok < 0) {
 
 # Show search form
 @keys = sort { $a cmp $b } keys %awl;
+@keys = grep { !/\|totscore/ } @keys;
 print &ui_form_start("edit_awl.cgi");
 print "<b>$text{'awl_search'}</b>\n";
 print &ui_textbox("search", $in{'search'}, 30),"\n",
@@ -52,35 +61,59 @@ if ($in{'search'}) {
                    "<i>".&html_escape($in{'search'})."</i>"),"<p>\n";
        }
 
-# Show table
-print &ui_form_start("delete_awl.cgi", "post");
-print &ui_hidden("search", $in{'search'});
-print &ui_hidden("user", $in{'user'});
-@links = ( &select_all_link("d", $formno), &select_invert_link("d", $formno) );
-@tds = ( "width=5" );
-print &ui_links_row(\@links);
-print &ui_columns_start([ "",
-                         $text{'awl_email'},
-                         $text{'awl_ip'},
-                         $text{'awl_score'} ], \@tds);
-foreach $k (@keys) {
-       ($email, $ip, $rest) = split(/\|/, $k);
-       next if ($rest eq "totscore");
-       if ($ip eq "ip=none") {
-               $ip = $text{'awl_none'};
-               }
-       elsif ($ip =~ /^ip=(\S+)$/) {
-               $ip = $1;
-               }
-       else {
-               $ip = $text{'awl_unknown'};
+if (@keys > $max_awl_keys && !$in{'search'}) {
+       # Too many to show
+       print "<b>",&text('awl_toomany', scalar(@keys),
+                         $max_awl_keys),"</b><p>\n";
+       }
+else {
+       # Show table
+       print &ui_form_start("delete_awl.cgi", "post");
+       print &ui_hidden("search", $in{'search'});
+       print &ui_hidden("user", $in{'user'});
+       @links = ( &select_all_link("d", $formno),
+                  &select_invert_link("d", $formno) );
+       @tds = ( "width=5" );
+       print &ui_links_row(\@links);
+       print &ui_columns_start([ "",
+                                 $text{'awl_email'},
+                                 $text{'awl_ip'},
+                                 $text{'awl_score'} ], \@tds);
+       foreach $k (@keys) {
+               ($email, $ip, $rest) = split(/\|/, $k);
+               if ($ip eq "ip=none") {
+                       $ip = $text{'awl_none'};
+                       }
+               elsif ($ip =~ /^ip=(\S+)$/) {
+                       $ip = $1;
+                       }
+               else {
+                       $ip = $text{'awl_unknown'};
+                       }
+               print &ui_checked_columns_row([ $email, $ip, $awl{$k} ],
+                                             \@tds, "d", $k);
                }
-       print &ui_checked_columns_row([ $email, $ip, $awl{$k} ],
-                                     \@tds, "d", $k);
+       print &ui_columns_end();
+       print &ui_links_row(\@links);
+       print &ui_form_end([ [ undef, $text{'awl_delete'} ] ]);
        }
-print &ui_columns_end();
-print &ui_links_row(\@links);
-print &ui_form_end([ [ undef, $text{'awl_delete'} ] ]);
 &close_auto_whitelist_dbm();
 
+# Show delete buttons
+print "<hr>\n";
+print &ui_buttons_start();
+if ($in{'user'} || &supports_auto_whitelist() == 1) {
+       # Delete for this user
+       print &ui_buttons_row("deleteone_awl.cgi",
+                     $text{'awl_deleteone'}, &text('awl_deleteonedesc',
+                               "<tt>".&html_escape($in{'user'})."</tt>"),
+                     &ui_hidden("user", $in{'user'}));
+       }
+if (&supports_auto_whitelist() == 2) {
+       # Delete for all users
+       print &ui_buttons_row("deleteall_awl.cgi",
+                     $text{'awl_deleteall'}, $text{'awl_deletealldesc'});
+       }
+print &ui_buttons_end();
+
 &ui_print_footer("", $text{'index_return'});
index 0df69b2..ec7e599 100644 (file)
@@ -343,7 +343,7 @@ db_eldapdn=Missing or invalid base DN - no spaces are allowed
 db_eldapattr=Missing or invalid SpamAssassin attribute
 db_eldapuid=Missing or invalid username attribute
 
-awl_title=Manage Auto-Whitelist
+awl_title=Manage Auto-Whitelists
 awl_search=Search whitelist for:
 awl_ok=Search
 awl_searching=Showing auto-whitelist entries matching $1 ..
@@ -357,8 +357,19 @@ awl_cannot=Usermin could not open your auto-whitelist file <tt>$1</tt>, perhaps
 awl_empty=Your auto-whitelist file <tt>$1</tt> does not contain any entries. It will be populated by SpamAsssassin as mail is processed by the system.
 awl_user=Show auto-whitelist for user:
 awl_uok=Show
-awl_nofile=This user does not have an auto-whitelist file.
+awl_nofile=The user $1 does not have an auto-whitelist file.
+awl_nouser=The user $1 does not exist.
+awl_cannotuser=You are not allowed to edit the auto-whitelist for user $1.
+awl_toomany=There are $1 entries in the auto-whitelist, but at most $2 can be displayed. Use the search form above to limit those shown.
+awl_deleteone=Clear Auto-Whitelist
+awl_deleteonedesc=Remove all auto-whitelist entries for the user $1.
+awl_deleteall=Clear All Auto-Whitelists
+awl_deletealldesc=Remove all auto-whitelist entries for all users on the system.
 
 dawl_err=Failed to delete from auto-whitelist
 dawl_eopen=Could not open whitelist
 dawl_enone=No addresses to delete selected
+dawl_ecannot=You are not allowed to manage the auto-whitelist for this user
+dawl_doing=Deleting auto-whitelists for all users ..
+dawl_done=.. deleted $2 entries from $1 users.
+dawl_title=Delete All Auto-Whitelists
index ee1f592..3397d0c 100644 (file)
@@ -21,6 +21,7 @@ if ($module_info{'usermin'}) {
        $database_userpref_name = $remote_user;
        $include_config_files = !$config{'mode'} || $config{'readfiles'};
        $add_to_db = 1;
+       $max_awl_keys = $userconfig{'max_awl'} || 200;
        }
 else {
        # Running under Webmin, typically editing global config file
@@ -34,6 +35,7 @@ else {
        $database_userpref_name = $config{'dbglobal'} || '@GLOBAL';
        $include_config_files = 1;
        $add_to_db = $config{'addto'};
+       $max_awl_keys = $config{'max_awl'} || 200;
        }
 $ldap_spamassassin_attr = $config{'attr'} || 'spamassassin';
 $ldap_username_attr = $config{'uid'} || 'uid';