#!/usr/bin/perl # Drakwizard # Copyright (C) 2002, 2003 Mandrakesoft # # Authors: Arnaud Desmons # 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; use MDK::Wizard::Varspaceval; use Libconf qw(:functions); use Libconf::Glueconf::Postfix::Main_cf; my $postfix = new Libconf::Glueconf::Postfix::Main_cf({ filename => '/etc/postfix/main.cf', }); use Data::Dumper; print Dumper($postfix); 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 $wiz_postfix_etc = "/etc/sysconfig/wizard_postfix"; my $o = { name => N("Postfix wizard"), var => { wiz_myhostname => '', wiz_mydomain => '', wiz_myorigin => '', wiz_inet_interfaces => '', wiz_mydestination => '', wiz_mynetworks => '', wiz_smtpd_helo_required => '', wiz_disable_vrfy_command => '', wiz_smtpd_recipient_restrictions => '', wiz_smtpd_data_restrictions => '', wiz_maximal_queue_lifetime => '', wiz_message_size_limit => '', wiz_smtpd_banner => '', wiz_debug_peer_level => '', wiz_debugger_command => '', wiz_delay_warning_time => '', wiz_sendmail_path => '', wiz_newaliases_path => '', wiz_mailq_path => '', wiz_setgid_group => '', wiz_manpage_directory => '', wiz_sample_directory => '', wiz_readme_directory => '', wiz_masquerade_domains => '', wiz_default_destination_concurrency_limit => '', wiz_content_filter => '', wiz_smtp_amavis_destination_concurrency_limit => '', wiz_html_directory => '', wiz_content_filter => '', wiz_receive_override_options => '', wiz_mail_masquerade => '', wiz_ext_mail_relay => '', wiz_relayhost => '', wiz_relay_domains => '', }, init => sub { check_sendmail(); my $t = any { /$wiz_host_name/ } cat_("/etc/hosts"); if ($t == 0) { return 0, N("Error, can't find your hostname in /etc/hosts. Exiting. Please launch drakconnect and choose static IP address.") } 1 }, needed_rpm => [ 'postfix' ], defaultimage => "$ENV{__WIZ_HOME__}postfix_wizard/images/courrier.png" }; my %type = ( 1 => N("Main mail server"), 2 => N("Relay mail server"), ); my %understanding = ( 1 => N('Newbie - classical options'), 2 => N('Expert - advanced options'), ); $o->{pages} = { welcome => { name => N("Internet mail configuration wizard") . "\n\n" . N("This wizard will help you configure an Postifx mail server for your network, or a Postfix mail relay."), no_back => 1, pre => sub { $postfix->{relayhost} and $o->{var}{wiz_type} = 2; if (-f $wiz_postfix_etc) { $::in->ask_warn(N("Information"), N("It seems you previously setup a Postfix server. This wizard will re-read your old configuration, and show you the Postfix server type you choose")); my $data = cat_($wiz_postfix_etc); # detect old Postfix type my ($old_type) = $data =~ /type=(\d)/; $o->{var}{wiz_type} = chomp_($old_type); } else { $o->{var}{wiz_type} = 1 } }, data => [ { label => N("What do you want to do:"), val => \$o->{var}{wiz_type}, list => [ keys %type ], format => sub { $type{$_[0]} } }, ], next => 'global_config', }, understanding => { name => N('Now i need to know your undestanding in Postfix server configuration'), data => [ { label => N("What kind of user are you:"), val => \$o->{var}{wiz_understanding}, list => [ keys %understanding ], format => sub { $understanding{$_[0]} } }, ], no_back => 1, next => 'global_config', }, global_config => { name => N('Global postfix configuration'), pre => sub { $o->{var}{wiz_smtpd_banner} ||= $postfix->{smtpd_banner}; $o->{var}{wiz_myhostname} ||= $postfix->{myhostname} or $o->{var}{wiz_myhostname} = "\$myhostname"; $o->{var}{wiz_mydomain} ||= $postfix->{mydomain} or $o->{var}{wiz_mydomain} = "\$mydomain"; $o->{var}{wiz_myorigin} ||= $postfix->{myorigin}; }, post => sub { if ($o->{var}{wiz_type} == 1) { return 'main_server' ; } else { return 'relay_server'; } }, data => [ { label => N('Smtpd banner:'), val => \$o->{var}{wiz_smtpd_banner}, help => 'You MUST specify $myhostname at the start of the text. That is an RFC requirement. ie: $myhostname ESMTP $mail_name ($mail_version) (Mandriva Linux)' }, { label => N('Hostname:'), val => \$o->{var}{wiz_myhostname}, help => N('The myhostname parameter specifies the internet hostname of this mail system. ie: myhostname = $myhostname') }, { label => N('Domain:'), val => \$o->{var}{wiz_mydomain}, help => N('The mydomain parameter specifies the local internet domain name. ie: mydomain = $mydomain') }, { label => N('Origin:'), val => \$o->{var}{wiz_myorigin}, help => N('The myorigin parameter specifies the domain that locally-posted mail appears to come from. ie: myorigin = $myhostname') }, ], complete => sub { if (!$o->{var}{wiz_smtpd_banner}) { $::in->ask_warn(N('Error'), N('Please provide an Smtpd banner.')); return 1; } if (!$o->{var}{wiz_myhostname}) { $::in->ask_warn(N('Error'), N('You must provide an internet hostname of this mail system.')); return 1; } if (!$o->{var}{wiz_domain_name}) { $::in->ask_warn(N('Error'), N('You must specifies the local internet domain name.')); return 1; } }, }, main_server => { name => N('Main Postfix server'), pre => sub { $o->{var}{wiz_smtpd_helo_required} ||= $postfix->{smtpd_helo_required}; $o->{var}{wiz_disable_vrfy_command} ||= $postfix->{disable_vrfy_command}; smtpd_recipient_restrictions smtpd_data_restrictions }, data => [ { label => N('helo required:'), val => \$o->{var}{wiz_smtpd_helo_required}, fixed_list => \@yesrorno, help => '' }, { label => N('Disable verify command:'), val => \$o->{var}{wiz_disable_vrfy_command}, fixed_list => \@yesrorno, help => '' }, ], next => 'message_config', }, relay_server => { name => N('Relay server'), pre => sub { $o->{var}{wiz_relayhost} ||= $postfix->{relayhost}; $postfix->{relay_domains} and $o->{var}{wiz_relay_domains} = $postfix->{relay_domains} or $o->{var}{wiz_relay_domains} = "mydomain.com"; }, data => [ { label => N('Relay host:'), val => \$o->{var}{wiz_relayhost}, help => '192.168.10.13' }, { label => N('Relay domains:'), val => \$o->{var}{wiz_relay_domains}, help => 'mydomain.com' }, ], next => 'message_config', }, masquerade => { name => N("Masquerade") . "\n" . N("This should be chosen consistently with the address you use for incoming mail.") . "\n\n" . N("Address masquerading is a method to hide all hosts inside a domain behind their mail gateway, and to make it appear as if the mail comes from the gateway itself, instead of from individual machines."), pre => sub { $o->{var}{wiz_mail_masquerade} ||= $postfix->{masquerade_domains}; }, complete => sub { if ($o->{var}{wiz_mail_masquerade} !~ /\w+\.\w+$/) { $::in->ask_warn(N("Error"), N("Masquerade should be a valid domain name such as \"mydomain.com\"!")); return 1; } else { return 0; }; }, data => [ { label => N("Masquerade domain name:"), val => \$o->{var}{wiz_mail_masquerade} }, ], next => 'isp', }, network_config => { name => N('Network config'), pre => sub { if ($postfix->{inet_interfaces}) { $o->{var}{wiz_inet_interfaces} = $postfix->{inet_interfaces}; } else { $o->{var}{wiz_inet_interfaces} = 'all'; } $postfix->{mydestination} and $o->{var}{wiz_mydestination} = $postfix->{mydestination}; $postfix->{mynetworks} and $o->{var}{wiz_mynetworks} = $postfix->{mynetworks}; $o->{var}{wiz_mynetworks_style} ||= $postfix->{mynetworks_style}; }, data => [ { label => N('inet interfaces:'), val => \$o->{var}{wiz_inet_interfaces}, help => N('all') }, { label => N('my destination:'), val => \$o->{var}{wiz_mydestination}, help => N('$myhostname, localhost.$mydomain, /etc/postfix/destinations') }, { label => N('my networks:'), val => \$o->{var}{wiz_mynetworks}, help => N('127.0.0.0/32, 192.168.1.0/24') }, ], next => 'message_config', }, message_config => { name => N('Message options'), pre => sub { $postfix->{maximal_queue_lifetime} and $o->{var}{wiz_maximal_queue_lifetime} = $postfix->{maximal_queue_lifetime}; $postfix->{message_size_limit} and $o->{var}{wiz_message_size_limit} = $postfix->{message_size_limit}; }, data => [ { label => N('Maximal queue life'), val => \$o->{var}{wiz_maximal_queue_lifetime} }, { label => N('Message size limit'), val => \$o->{var}{wiz_message_size_limit} }, { label => N('Default destination concurrency limit'), val => \$o->{var}{wiz_default_destination_concurrency_limit}, help => N('How many parallel deliveries to the same user or domain ?') }, ], next => 'summary_main', }, error_sendmail => { name => N("Error, sendmail is installed. Please remove it before installing or configuring Postfix"), no_back => 1, next => 0, end => 1, }, summary_relay => { name => N("Configuring your relay mail server") . "\n\n" . N("The wizard collected the following parameters needed to configure your relay mail server:") . "\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} }, { label => N("myorigin:"), fixed_val => \$o->{var}{wiz_myorigin} }, ], post => \&do_it_relay_server, next => 'end' }, summary_main => { name => N("The wizard will now configure your mail server."), post => \&do_it_main_server, next => 'end' }, end => { name => N("Congratulations") . "\n\n" . N("The wizard successfully configured your Postfix Mail server."), post => sub { store_postfix_type($o->{var}{wiz_type}); }, no_back => 1, end => 1, next => 0 }, error_end => { name => N("Failed"), data => [ { label => N("Please relaunch drakwizard, and try to change some parameters.") } ], no_back => 1, end => 1, next => 0, }, }; sub new { my ($class, $_conf) = @_; bless { o => $o, }, $class; } sub check_sendmail { my $in = 'interactive'->vnew('su', 'Check sendmail'); my $w = $in->wait_message(N("Postfix Server"), N("removing Sendmail to avoid conflict....")); my $test = any { /sendmail/ } system("rpm -q sendmail"); !$test or return 'error_sendmail'; undef $w; } sub postfix_options { $o->{var}{wiz_myhostname} and $postfix->{myhostname} = $o->{var}{wiz_myhostname}; $o->{var}{wiz_mydomain} and $postfix->{mydomain} = $o->{var}{wiz_mydomain}; $o->{var}{wiz_myorigin} and $postfix->{myorigin} = $o->{var}{wiz_myorigin}; $o->{var}{wiz_inet_interfaces} and $postfix->{inet_interfaces} = $o->{var}{wiz_inet_interfaces}; $o->{var}{wiz_mydestination} and $postfix->{mydestination} = $o->{var}{wiz_mydestination}; $o->{var}{wiz_mynetworks} and $postfix->{mynetworks} = $o->{var}{wiz_mynetworks}; $o->{var}{wiz_smtpd_helo_required} and $postfix->{smtpd_helo_required} = $o->{vawiz_smtpd_helo_required}; $o->{var}{wiz_disable_vrfy_command} and $postfix->{disable_vrfy_command} = $o->{var}{wiz_disable_vrfy_command}; $o->{var}{wiz_smtpd_recipient_restrictions} and $postfix->{smtpd_recipient_restrictions} = $o->{var}{wiz_smtpd_recipient_restrictions}; $o->{var}{wiz_smtpd_data_restrictions} and $postfix->{smtpd_data_restrictions} = $o->{var}{wiz_smtpd_data_restrictions}; $o->{var}{wiz_maximal_queue_lifetime} and $postfix->{maximal_queue_lifetime} = $o->{var}{wiz_maximal_queue_lifetime}; $o->{var}{wiz_message_size_limit} and $postfix->{message_size_limit} = $o->{var}{wiz_message_size_limit}; $o->{var}{wiz_smtpd_banner} and $postfix->{smtpd_banner} = $o->{var}{wiz_smtpd_banner}; $o->{var}{wiz_debug_peer_level} and $postfix->{debug_peer_level} = $o->{var}{wiz_debug_peer_level}; $o->{var}{wiz_debugger_command} and $postfix->{debugger_command} = $o->{var}{wiz_debugger_command}; $o->{var}{wiz_delay_warning_time} and $postfix->{delay_warning_time} = $o->{var}{wiz_delay_warning_time}; $o->{var}{wiz_sendmail_path} and $postfix->{sendmail_path} = $o->{var}{wiz_sendmail_path}; $o->{var}{wiz_newaliases_path} and $postfix->{newaliases_path} = $o->{var}{wiz_newaliases_path}; $o->{var}{wiz_mailq_path} and $postfix->{mailq_path} = $o->{var}{wiz_mailq_path}; $o->{var}{wiz_setgid_group} and $postfix->{setgid_group} = $o->{var}{wiz_setgid_group}; $o->{var}{wiz_masquerade_domains} and $postfix->{masquerade_domains} = $o->{var}{wiz_masquerade_domains}; $o->{var}{wiz_default_destination_concurrency_limit} and $postfix->{default_destination_concurrency_limiwiz_default_destination_concurrency_limit} = $o->{var}{wiz_default_destination_concurrency_limit}; $o->{var}{wiz_content_filter} and $postfix->{content_filter} = $o->{var}{wiz_content_filter}; $o->{var}{wiz_smtp_amavis_destination_concurrency_limit} and $postfix->{wiz_smtp_amavis_destination_concurrency_limit} = $o->{var}{wiz_html_directory}; $o->{var}{wiz_html_directory} and $postfix->{wiz_html_directory} = $o->{var}{wiz_html_directory}; $o->{var}{wiz_content_filter} and $postfix->{wiz_content_filter} = $o->{var}{wiz_content_filter}; $o->{var}{wiz_receive_override_options} and $postfix->{wiz_receive_override_options} = $o->{var}{wiz_receive_override_options}; $o->{var}{wiz_mail_masquerade} and $postfix->{wiz_mail_masquerade} = $o->{var}{wiz_mail_masquerade}; $o->{var}{wiz_ext_mail_relay} and $postfix->{wiz_ext_mail_relay} = $o->{var}{wiz_ext_mail_relay}; $o->{var}{wiz_relayhost} and $postfix->{wiz_relayhost} = $o->{var}{wiz_relayhost}; $o->{var}{wiz_relay_domains} and $postfix->{wiz_relay_domains} = $o->{var}{wiz_relay_domains}; } sub store_postfix_type { # write config file to store Postfix type my ($type) = @_; output($wiz_postfix_etc, <vnew('su', 'postfix configuration'); my $w = $in->wait_message(N("Postfix Server"), N("Configuring your Postfix server.....")); save_config(); $o->{var}{wiz_inet_interfaces} and $postfix->{inet_interfaces} = $o->{var}{wiz_inet_interfaces}; $o->{var}{wiz_myhostname} and $postfix->{myhostname} = $o->{var}{wiz_myhostname}; $o->{var}{wiz_mydomain} and $postfix->{mydomain} = $o->{var}{wiz_mydomain}; $postfix->{mydestination}; $postfix->{alias_maps}; $postfix->{alias_database}; $postfix->{virtual_maps}; $postfix->{canonical_maps}; $o->{var}{wiz_mail_masquerade} and $postfix->{masquerade_domains} = $o->{var}{wiz_mail_masquerade}; $o->{var}{wiz_myorigin} and $postfix->{myorigin} = $o->{var}{wiz_myorigin}; $postfix->{relayhost} and delete $postfix->{relayhost}; $o->{var}{wiz_mail_masquerade}; $o->{var}{wiz_ext_mail_relay}; $o->{var}{wiz_myhostname}; $o->{var}{wiz_mydomain}; $o->{var}{wiz_inet_interfaces}; $o->{var}{wiz_mynetworks_style}; $o->{var}{wiz_smtpd_banner}; $o->{var}{wiz_inet_interfaces}; $o->{var}{wiz_mydestination}; $o->{var}{wiz_myorigin}; # example of internal mail working confoguration #myhostname = xp2400.guibland.com #virtual_maps = hash:/etc/postfix/virtual #canonical_maps = hash:/etc/postfix/canonical #masquerade_domains = guibland.com cmd_needed(); undef $w; check_started('master'); } sub do_it_main_server { $::testing and return; my $in = 'interactive'->vnew('su', 'postfix configuration'); my $w = $in->wait_message(N("Postfix Server"), N("Configuring your Postfix server.....")); save_config(); $postfix->{inet_interfaces} ; $postfix->{myhostname}; $postfix->{mydomain} ; $postfix->{mydestination}; $postfix->{alias_maps}; $postfix->{alias_database}; $postfix->{virtual_maps}; $postfix->{canonical_maps}; $o->{var}{wiz_myorigin} and $postfix->{myorigin} = $o->{var}{wiz_myorigin}; $o->{var}{wiz_ext_mail_relay} and $postfix->{relayhost} = $o->{var}{relayhost}; my @conf = ("myhostname = $wiz_host_name", 'inet_interfaces = $myhostname,localhost', 'mydestination = $myhostname, localhost.$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', "mydomain = $wiz_domain_name", ); cmd_needed(); undef $w; check_started('master'); } 1;