#!/usr/bin/perl # Drakwizard # Copyright (C) 2002 Arnaud Desmons # 2003 Florent Villard # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. package MDK::Wizard::Postfix; use strict; use lib qw(/usr/lib/libDrakX); # required for service package use common; use MDK::Wizard::Wizcommon; my $wiz = new MDK::Wizard::Wizcommon; my $wiz_domain_name = $wiz->{net}->network_get("DOMAINNAME"); my $wiz_host_name = $wiz->{net}->network_get("HOSTNAME"); my $o = { name => 'Postfix wizard', var => { wiz_mail_masquerade => '', wiz_ext_mail_relay => '' }, needed_rpm => [ 'postfix' ], defaultimage => "$ENV{__WIZARD_HOME__}postfix_wizard/images/courrier.png" }; $o->{pages} = { welcome => { name => N("Internet Mail Configuration Wizard") . "\n\n" . N("This wizard will help you configuring the Internet Mail services for your network."), no_back => 1, next => 'config' }, config => { name => N("Outgoing Mail Address") . "\n\n" . N("You can select the kind of address that outgoing mail will show in the \qFrom:\q and \qReply-to\q field.") . "\n\n" . N("This should be chosen consistently with the address you use for incoming mail."), pre => sub { $o->{var}{wiz_mail_masquerade} ||= get_mail_masquerade(); }, post => \&check_masquerade, data => [ { label => N("Mail Address:"), val => \$o->{var}{wiz_mail_masquerade} }, ], next => 'isp' }, warning => { name => N("Warning:"), data => [ { label => N("You entered an empty address for the mail gateway.") }, { label => N("Your choice can be accepted, but this will not allow you to send mail outside your local network. Press next to continue, or back to enter a value.") } ], next => 'summary' }, masquerade_not_good => { name => N("Error."), data => [ { label => N("Masquerade not good!") } ], next => 'config' }, isp => { name => N("Internet Mail Gateway") . "\n\n" . N("Your server will send the outgoing through a mail gateway, that will take care of the final delivery.") . "\n\n" . N("Internet host names must be in the form \qhost.domain.domaintype\q; for example, if your provider is \qprovider.com\q, the internet mail server is usually \qsmtp.provider.com\q."), pre => sub { $o->{var}{wiz_ext_mail_relay} ||= get_mail_relay(); }, post => \&check_relay, data => [ { label => N("Mail Server Name:"), val => \$o->{var}{wiz_ext_mail_relay} }, ], next => 'summary' }, summary => { name => N("Configuring the Internet Mail") . "\n\n" . N("The wizard collected the following parameters needed to configure your Internet Mail Service:") . "\n\n" . N("To accept these values, and configure your server, click the Next button or use the Back button to correct them."), data => [ { label => N("Internet Mail Gateway"), fixed_val => \$o->{var}{wiz_ext_mail_relay} }, { label => N("Form of the Address"), fixed_val => \$o->{var}{wiz_mail_masquerade} }, ], post => \&do_it, next => 'end' }, end => { name => N("Congratulations"), data => [ { label => N("The wizard successfully configured your Internet Mail service of your server.") } ], end => 1, next => 0 }, }; sub new { my ($class, $_conf) = @_; bless { o => $o, }, $class; } sub check_masquerade { $o->{var}{wiz_mail_masquerade} or return 'masquerade_not_good'; $o->{var}{wiz_mail_masquerade} =~ /@(\S+)$/ or return 'masquerade_not_good'; } sub check_relay { $o->{var}{wiz_ext_mail_relay} or return 'warning'; $o->{var}{wiz_ext_mail_relay} =~ /(\S+)\.(\S+)$/ or return 'warning'; } sub get_mail_masquerade { my $login = `logname`; my $relayhost = `/usr/sbin/postconf -h relayhost`; chomp($relayhost); ($relayhost) = $relayhost =~ /.*\.(.*\..*)/; !length $relayhost and $relayhost = $wiz_domain_name; chomp($login); "$login\@$relayhost"; } sub get_mail_relay { my $relayhost = `/usr/sbin/postconf -h relayhost`; chomp $relayhost; !length $relayhost and $relayhost = "smtp.$wiz_domain_name"; $relayhost; } sub do_it { $::testing and return my @conf = qw(/etc/postfix/aliases /etc/postfix/canonical /etc/postfix/main.cf /etc/postfix/master.cf /etc/postfix/virtual); foreach (@conf) { -f $_ and MDK::Common::cp_af($_, $_.".orig"); } @conf = ("myhostname = $wiz_host_name", 'myorigin = $mydomain', 'inet_interfaces = all', 'mydestination = $myhostname, localhost.$mydomain', 'masquerade_domains = $mydomain', 'alias_maps = hash:/etc/postfix/aliases', 'alias_database = hash:/etc/postfix/aliases', 'virtual_maps = hash:/etc/postfix/virtual', 'canonical_maps = hash:/etc/postfix/canonical', "relayhost = $o->{var}{wiz_ext_mail_relay}" ); foreach (@conf) { system("/usr/sbin/postconf -e '$_'"); } if (defined $o->{var}{wiz_ext_mail_relay}) { my $file = "/etc/postfix/canonical"; my $canon = "\n\@$wiz_domain_name $o->{var}{wiz_mail_masquerade}"; my $t; foreach (cat_($file)) { if (/^\s*(?!#)\s*\@$wiz_domain_name/) { $t = $_; last; } } if ($t) { substInFile { s|$t|#$&$canon| } $file } else { append_to_file($file, $canon) } } system("/usr/sbin/postmap /etc/postfix/canonical"); system("/usr/sbin/postmap /etc/postfix/virtual"); system("/usr/sbin/postalias /etc/postfix/aliases"); system("/usr/sbin/postfix check"); require services; if (services::is_service_running('postfix')) { services::restart('postfix') } else { services::start('postfix') } services::is_service_running('xinetd') and services::restart('xinetd'); } 1;