Support for selecting a file for new aliases
authorJamie Cameron <jcameron@webmin.com>
Mon, 9 Nov 2009 22:13:22 +0000 (14:13 -0800)
committerJamie Cameron <jcameron@webmin.com>
Mon, 9 Nov 2009 22:13:22 +0000 (14:13 -0800)
sendmail/CHANGELOG
sendmail/aliases-lib.pl
sendmail/help/alias_file.html [new file with mode: 0644]
sendmail/lang/en
sendmail/list_aliases.cgi
sendmail/save_alias.cgi

index bc6290c..64bfa38 100644 (file)
@@ -44,3 +44,5 @@ A custom command to rebuild all maps can be specified on the Module Config page,
 Changed the mail queue date format to yyyy/mm/dd, for easier sorting.
 ---- Changes since 1.470 ----
 When flushing selected queued quarantined messages, the -qQ flag is added so that it actually works.
+---- Changes since 1.490 ----
+If multiple alias files are defined, one can be selected when adding a new alias.
index 4eb8067..efb1248 100755 (executable)
@@ -96,7 +96,7 @@ return @$c;
 # 1 or more programs, files, lists or users
 sub alias_form
 {
-local ($a, $nocmt) = @_;
+local ($a, $nocmt, $afile) = @_;
 local (@values, $v, $type, $val, @typenames);
 if ($a) { @values = @{$a->{'values'}}; }
 @typenames = map { $text{"aform_type$_"} } (0 .. 6);
@@ -128,6 +128,12 @@ print &ui_table_row(&hlink($text{'aform_name'},"alias_name"),
 print &ui_table_row(&hlink($text{'aform_enabled'}, "alias_enabled"),
                    &ui_yesno_radio("enabled", !$a || $a->{'enabled'} ? 1 : 0));
 
+# Alias file, if more than one possible
+if ($afile && @$afile > 1) {
+       print &ui_table_row(&hlink($text{'aform_file'}, "alias_file"),
+               &ui_select("afile", undef, $afile));
+       }
+
 # Destinations
 local @typeopts;
 for($j=0; $j<@typenames; $j++) {
@@ -176,16 +182,17 @@ sub create_alias
 
 # Update the config file
 local(%aliases);
-local $lref = &read_file_lines($_[1]->[0]);
+$_[0]->{'file'} ||= $_[1]->[0];
+local $lref = &read_file_lines($_[0]->{'file'});
 $_[0]->{'line'} = scalar(@$lref);
 push(@$lref, &make_table_comment($_[0]->{'cmt'}, 1));
 local $str = ($_[0]->{'enabled'} ? "" : "# ") . $_[0]->{'name'} . ": " .
             join(',', map { /\s/ ? "\"$_\"" : $_ } @{$_[0]->{'values'}});
 push(@$lref, $str);
 $_[0]->{'eline'} = scalar(@$lref)-1;
-&flush_file_lines($_[1]->[0]);
+&flush_file_lines($_[0]->{'file'});
 if (!$_[2]) {
-       if (!&rebuild_map_cmd($_[1]->[0])) {
+       if (!&rebuild_map_cmd($_[0]->{'file'})) {
                &system_logged("newaliases >/dev/null 2>&1");
                }
        }
@@ -193,7 +200,6 @@ if (!$_[2]) {
 # Add to the cache
 local $jfiles = join(",", @{$_[1]});
 local $c = $list_aliases_cache{$jfiles};
-$_[0]->{'file'} = $_[1]->[0];
 $_[0]->{'num'} = scalar(@$c);
 push(@$c, $_[0]);
 }
diff --git a/sendmail/help/alias_file.html b/sendmail/help/alias_file.html
new file mode 100644 (file)
index 0000000..9c66dd3
--- /dev/null
@@ -0,0 +1,7 @@
+<header>Add to aliases file</header>
+
+If Sendmail is configured to use multiple files for aliases, this field
+allows you to select which file to append a new alias to. <p>
+
+<footer>
+
index c653638..bf387c9 100644 (file)
@@ -88,6 +88,7 @@ aform_edit=Edit Alias
 aform_create=Create Alias
 aform_name=Address
 aform_enabled=Enabled?
+aform_file=Add to aliases file
 aform_val=Alias to
 aform_afile=Edit..
 aform_return=alias
index 7dd829b..c1fae53 100755 (executable)
@@ -25,7 +25,7 @@ elsif ($access{'amode'} == 3) {
                  $rv;
                } @aliases;
 
-&alias_form();
+&alias_form(undef, undef, $afile);
 
 if ($in{'search'}) {
        # Restrict to search results
index 3edb0f8..e43b0b9 100755 (executable)
@@ -114,8 +114,17 @@ else {
        $newa{'values'} = \@values;
        $newa{'enabled'} = $in{'enabled'};
        $newa{'cmt'} = $in{'cmt'};
-       if ($in{'new'}) { &create_alias(\%newa, $afile); }
-       else { &modify_alias($a, \%newa); }
+       if ($in{'new'}) {
+               $newa{'file'} = $in{'afile'};
+               }
+
+       # Actually create or update
+       if ($in{'new'}) {
+               &create_alias(\%newa, $afile);
+               }
+       else {
+               &modify_alias($a, \%newa);
+               }
        $loga = \%newa;
        }
 &unlock_alias_files($afile);