Work on outgoing SMTP support
authorJamie Cameron <jcameron@webmin.com>
Wed, 1 Jun 2011 05:31:45 +0000 (22:31 -0700)
committerJamie Cameron <jcameron@webmin.com>
Wed, 1 Jun 2011 05:31:45 +0000 (22:31 -0700)
postfix/CHANGELOG
postfix/lang/en
postfix/sasl.cgi
postfix/save_sasl.cgi

index ba62dc5..508bb90 100644 (file)
@@ -78,3 +78,4 @@ Added support for CIDR maps and multiple SMTP client restriction maps.
 Added spam checking to the autoreply script, if spamassassin is installed.
 ---- Changes since 1.550 ----
 Fixed a bug that prevented editing of server processes with the same name but different types, and add detection of clashes for servers with the same name and type.
+Added an option to the SMTP Authentication page for setting the login and password for Postfix to use when sending email via another mail server.
index cc393ee..568ac8f 100644 (file)
@@ -811,6 +811,11 @@ sasl_eca=Missing or invalid TLS certificate authority file
 sasl_level_none=Never
 sasl_level_may=If requested by client
 sasl_level_encrypt=Always
+sasl_login=SMTP login to outgoing mail host
+sasl_nologin=None needed
+sasl_userpass=Login as $1 with password $2
+sasl_elogin=Missing or invalid SMTP login
+sasl_epass=Invalid SMTP password
 
 client_title=SMTP Client Restrictions
 client_ecannot=You are not allowed to edit SMTP client restrictions
index 4329f62..2310465 100755 (executable)
@@ -62,6 +62,28 @@ else {
 
 &option_radios_freefield("smtpd_tls_CAfile", 60, $none);
 
+print &ui_table_hr();
+
+# Outgoing authentication options
+&option_radios_freefield("relayhost", 45, $text{'opts_direct'});
+
+# Get the current map value for the relayhost
+$rh = &get_current_value("relayhost");
+if ($rh) {
+       $pmap = &get_maps("smtp_sasl_password_maps");
+       foreach my $o (@$pmap) {
+               if ($o->{'name'} eq $rh) {
+                       ($ruser, $rpass) = split(/:/, $o->{'value'});
+                       }
+               }
+       }
+print &ui_table_row($text{'sasl_login'},
+       &ui_radio("login_none", $ruser ? 0 : 1,
+                 [ [ 1, $text{'sasl_nologin'}."<br>" ],
+                   [ 0, &text('sasl_userpass',
+                               &ui_textbox("login_user", $ruser, 20), 
+                               &ui_textbox("login_pass", $rpass, 20)) ] ]), 3);
+
 print &ui_table_end();
 print &ui_form_end([ [ undef, $text{'opts_save'} ] ]);
 
index 2464d3b..c97acfa 100755 (executable)
@@ -20,6 +20,12 @@ if ($in{'smtpd_tls_CAfile_def'} eq "__USE_FREE_FIELD__") {
        -r $in{'smtpd_tls_CAfile'} || &error($text{'sasl_eca'});
        }
 
+# Validate remote mail server login
+if (!$in{'login_none'}) {
+       $in{'login_user'} =~ /^[^: ]+$/ || &error($text{'sasl_elogin'});
+       $in{'login_pass'} =~ /^[^: ]*$/ || &error($text{'sasl_epass'});
+       }
+
 &lock_postfix_files();
 &save_options(\%in);
 
@@ -46,6 +52,38 @@ if ($postfix_version >= 2.3) {
                           $in{'smtpd_tls_security_level'});
        }
 
+# Save SMTP relay options
+$rh = &get_current_value("relayhost");
+if ($rh) {
+       if ($in{'login_none'} == 0 &&
+           !&get_current_value("smtp_sasl_password_maps")) {
+               # Setup initial map
+               &set_current_value("smtp_sasl_password_maps",
+                               "hash:".&guess_config_dir()."/smtp_sasl_password_map");
+               }
+        $pmap = &get_maps("smtp_sasl_password_maps");
+       foreach my $o (@$pmap) {
+                if ($o->{'name'} eq $rh) {
+                       $old = $o;
+                       }
+               }
+       $newmap = { 'name' => $rh,
+                   'value' => $in{'login_user'}.":".$in{'login_pass'} };
+       if ($old && $in{'login_def'}) {
+               # Delete entry
+               &delete_mapping("smtp_sasl_password_maps", $old);
+               }
+       elsif ($old && !$in{'login_def'}) {
+               # Update entry
+               &modify_mapping("smtp_sasl_password_maps", $old, $newmap);
+               }
+       elsif (!$old && !$in{'login_def'}) {
+               # Add entry
+               &create_mapping("smtp_sasl_password_maps", $newmap);
+               }
+       &regenerate_any_table("smtp_sasl_password_maps");
+       }
+
 &unlock_postfix_files();
 
 &reload_postfix();