summaryrefslogtreecommitdiffstats
path: root/postfix_wizard
diff options
context:
space:
mode:
authorFlorent Villard <warly@mandriva.com>2003-08-22 19:59:48 +0000
committerFlorent Villard <warly@mandriva.com>2003-08-22 19:59:48 +0000
commit150bc87396011253a541ca0ad32250e926ab0ecc (patch)
tree1b90808250fc42a37248dfeb726b55f8203e8ba2 /postfix_wizard
parent817bcd2c3a985552620cece5905d5b5982ae14c4 (diff)
downloaddrakwizard-150bc87396011253a541ca0ad32250e926ab0ecc.tar
drakwizard-150bc87396011253a541ca0ad32250e926ab0ecc.tar.gz
drakwizard-150bc87396011253a541ca0ad32250e926ab0ecc.tar.bz2
drakwizard-150bc87396011253a541ca0ad32250e926ab0ecc.tar.xz
drakwizard-150bc87396011253a541ca0ad32250e926ab0ecc.zip
switch to perl only
Diffstat (limited to 'postfix_wizard')
-rwxr-xr-xpostfix_wizard/Postfix.pm187
1 files changed, 187 insertions, 0 deletions
diff --git a/postfix_wizard/Postfix.pm b/postfix_wizard/Postfix.pm
new file mode 100755
index 00000000..9b3c514a
--- /dev/null
+++ b/postfix_wizard/Postfix.pm
@@ -0,0 +1,187 @@
+#!/usr/bin/perl
+
+# Drakwizard
+
+# Copyright (C) 2002 Arnaud Desmons <adesmons@mandrakesoft.com>
+# 2003 Florent Villard <warly@mandrakesoft.com>
+#
+# 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 Postfix;
+use strict;
+
+use standalone;
+use interactive;
+use common;
+use MDK::Wizard::Wizcommon;
+
+my $wiz = new 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 => ''
+ }
+ };
+
+$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 => '' },
+ { 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('') },
+ { 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 => '' },
+ { 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 => '' },
+ { label => N('Form of the Address'), fixed_val => \$o->{var}{wiz_mail_masquerade} },
+ ],
+ post => \&do_it,
+ next => 'end'
+ },
+ end => {
+ name => N('Congratulation'),
+ 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 {
+ $::DEBUG 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");
+ if (services::is_service_running('postfix')) {
+ services::restart('postfix')
+ } else {
+ services::start('postfix')
+ }
+ services::is_service_running('xinetd') and services::restart('xinetd');
+}
+
+1;