Fix handling of multiple reject_rbl_client
authorJamie Cameron <jcameron@webmin.com>
Thu, 12 Jun 2008 00:32:50 +0000 (00:32 +0000)
committerJamie Cameron <jcameron@webmin.com>
Thu, 12 Jun 2008 00:32:50 +0000 (00:32 +0000)
postfix/CHANGELOG
postfix/client.cgi
postfix/postfix-lib.pl
postfix/save_client.cgi

index 81668fa..a31ca54 100644 (file)
@@ -55,3 +55,5 @@ Changed the default LDAP class for maps to inetLocalMailRecipient.
 ---- Changes since 1.410 ----
 Added the SMTP Client Restrictions page, and replaced some oddly-designed UI fields on the SMTP Server Options page to it with more Webmin-standard inputs for configuring RBLs and client access.
 Updated the BCC Mappings page to allow both sender and recipient maps to be defined and edited.
+---- Changes since 1.420 ----
+Properly handle multiple reject_rbl_client DNS domains on the SMTP Client Restrictions page.
index 9d53f92..065766c 100755 (executable)
@@ -14,10 +14,11 @@ $no_ = $text{'opts_no'};
 print &ui_form_start("save_client.cgi", "post");
 print &ui_table_start($text{'client_title'}, undef, 2);
 
-# Parse current settings
+# Parse current settings, by building a map from names to indexes
 @opts = split(/[\s,]+/, &get_current_value('smtpd_client_restrictions'));
 for(my $i=0; $i<@opts; $i++) {
-       $opts{$opts[$i]} = $i;
+       $opts{$opts[$i]} ||= [ ];
+       push(@{$opts{$opts[$i]}}, $i);
        }
 
 # Add binary restrictions to list
@@ -31,15 +32,20 @@ foreach $r (&list_client_restrictions()) {
 
 # Add restrictions with values
 foreach $r (&list_multi_client_restrictions()) {
-       $v = $opts{$r};
+       @v = @{$opts{$r}};
+       $vals = undef;
+       if (scalar(@v)) {
+               $vals = join(" ", map { $opts[$_+1] } @v);
+               }
        push(@grid, &ui_checkbox("client", $r, $text{'sasl_'.$r},
-                                defined($v)),
-                   &ui_textbox("value_$r",
-                               defined($v) ? $opts[$v+1] : undef, 40).
+                                scalar(@v)),
+                   &ui_textbox("value_$r", $vals, 40).
                    ($r eq "check_client_access" ?
                        " ".&map_chooser_button("value_$r", $r) : ""));
        $done{$r} = 1;
-       $done{$opts[$v+1]} = 1;
+       foreach $v (@v) {
+               $done{$opts[$v+1]} = 1;
+               }
        if ($r eq "check_client_access" && defined($v)) {
                # Can show client access map
                $has_client_access = 1;
index 603ec78..a6d741d 100644 (file)
@@ -1754,7 +1754,7 @@ sub get_backend_config
 {
 local ($file) = @_;
 local %rv;
-local $lref = &read_file_lines($file);
+local $lref = &read_file_lines($file, 1);
 foreach my $l (@$lref) {
        if ($l =~ /^\s*([a-z0-9\_]+)\s*=\s*(.*)/i) {
                $rv{$1} = $2;
index bf2a5e5..f737eff 100755 (executable)
@@ -34,27 +34,37 @@ else {
 
        # Save options with values
        foreach $o (&list_multi_client_restrictions()) {
-               $idx = &indexof($o, @opts);
+               # Find all current positions
+               local @pos;
+               for(my $i=0; $i<@opts; $i++) {
+                       push(@pos, $i) if ($opts[$i] eq $o);
+                       }
+
+               # Make sure something was entered
                if ($newopts{$o}) {
-                       $in{"value_$o"} =~ /^\S+$/ ||
+                       $in{"value_$o"} =~ /\S/ ||
                            &error(&text('client_evalue', $text{'sasl_'.$o}));
                        }
-               if ($newopts{$o} && !$oldopts{$o}) {
-                       # Add to end
-                       push(@opts, $o, $in{"value_$o"});
-                       }
-               elsif ($newopts{$o} && $oldopts{$o}) {
-                       # Update value
-                       $opts[$idx+1] = $in{"value_$o"};
-                       }
-               elsif (!$newopts{$o} && $oldopts{$o}) {
-                       # Remove and value
-                       splice(@opts, $idx, 2);
+
+               # Sync with values entered
+               @v = split(/\s+/, $in{"value_$o"});
+               for(my $i=0; $i<@pos || $i<@v; $i++) {
+                       if ($i<@pos && $i<@v) {
+                               # Updating a value
+                               $opts[$pos[$i]+1] = $v[$i];
+                               }
+                       elsif ($i<@pos && $i>=@v) {
+                               # Removing a value
+                               splice(@opts, $pos[$i], 2);
+                               }
+                       elsif ($i>=@pos && $i<@v) {
+                               # Adding a value, at the end
+                               push(@opts, $o, $v[$i]);
+                               }
                        }
                }
 
-       &set_current_value("smtpd_client_restrictions",
-                          join(" ", &unique(@opts)));
+       &set_current_value("smtpd_client_restrictions", join(" ", @opts));
        }
 
 &unlock_postfix_files();