#!/usr/bin/perl # Drakwizard # Copyright (C) 2003 Mandrakesoft # # Author: 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::Proftpd; use strict; use common; use services; require MDK::Wizard::Wizcommon; my $wiz = new MDK::Wizard::Wizcommon; my $o = { name => N("FTP wizard"), var => { wiz_ftp_external => '', wiz_ftp_anon => '', wiz_ftp_home => '' }, needed_rpm => [ 'proftpd', 'proftpd-anonymous' ], defaultimage => "$ENV{__WIZ_HOME__}ftp_wizard/images/FTP.png" }; $o->{pages} = { welcome => { name => N("FTP Server Configuration Wizard") . "\n\n" . N("This wizard will help you configuring the FTP Server for your network."), no_back => 1, post => \&check, next => 'config' }, config => { name => N("FTP Server") . "\n\n" . N("Your server can act as an FTP Server toward your internal network (intranet) and as an FTP Server for the Internet.") . "\n\n" . N("Select the kind of FTP service you want to activate:") . "\n\n" . N("Don't check any box if you don't want to activate your FTP Server."), pre => sub { $o->{var}{wiz_ftp_internal} ||= 1; $o->{var}{wiz_ftp_external} ||= 0; }, data => [ { text => N("Enable the FTP Server for the Intranet"), type => 'bool', val => \$o->{var}{wiz_ftp_internal} }, { text => N("Enable the FTP Server for the Internet"), type => 'bool', val => \$o->{var}{wiz_ftp_external} }, ], next => 'summary' }, warning_dhcp => { name => N("Warning.") . "\n\n" . N("Warning\nYou are in dhcp, server may not work with your configuration."), ignore => 1, next => 'config' }, must_be_root => { name => N("Error.") . "\n\n" . N("Sorry, you must be root to do this..."), ignore => 1, next => 'config' }, summary => { name => N("Configuring the FTP Server") . "\n\n" . N("The wizard collected the following parameters needed to configure your FTP Server") . "\n\n" . N("To accept these values, and configure your server, click the Next button or use the Back button to correct them"), pre => sub { $o->{var}{internal} = $o->{var}{wiz_ftp_internal} ? N("enabled") : N("disabled"); $o->{var}{external} = $o->{var}{wiz_ftp_external} ? N("enabled") : N("disabled") }, data => [ { label => N("Intranet FTP Server:"), fixed_val => \$o->{var}{internal} }, { label => N("Internet FTP Server:"), fixed_val => \$o->{var}{external} }, ], post => \&do_it, next => 'end' }, end => { name => N("Congratulations") . "\n\n" . N("The wizard successfully configured your Intranet/Internet FTP Server"), end => 1, next => 0 }, }; sub new { my ($class, $conf) = @_; bless { o => $o, }, $class; } sub true { my ($val) = @_; $val eq "1" || $val eq "\'1\'" || $val eq "\"1\"" || $val eq "true" || $val eq "\'true\'" || $val eq "\"true\"" and return 1; 0 } sub check_dir { -d $o->{var}{wiz_dir} and return 10; 1 } sub get_dir { my $file = "/etc/proftpd.conf"; die "no ftp configuration file found ! warning." if (!-f $file); open(NEW, "< $file") or die "error while opening $file: $!"; while () { # we need 3 elements to consider section as known if (m/^\s*/s...m/^\s*<\/drakwizard>/s ) { if (m/^\s*/s ) { return $1; } } } "" } sub check { $> and return 'must_be_root'; $wiz->{net}->is_dhcp() and return 'warning_dhcp'; '' } sub print_anonymous() { print ' # User ftp Group ftp UserAlias anonymous ftp MaxClients 10 DenyAll # '; } sub do_it { $::testing and return; my $wiz_ftp_internal = $o->{var}{wiz_ftp_external} ? 1 : true $o->{var}{wiz_ftp_internal}; my $wiz_ftp_external = true $o->{var}{wiz_ftp_external}; my $file = "/etc/proftpd.conf"; die "no ftp configuration file found ! warning." if (!-f $file); MDK::Common::cp_af($file, $file . ".orig"); open(NEW, "< $file") or die "error while opening $file: $!"; my $allow = "all"; if ($wiz_ftp_internal && !$wiz_ftp_external) { ($allow) = $wiz->{net}->itf_get("IPADDR") =~ qr/^(\d{1,3}\.\d{1,3}\.\d{1,3}\.)\d{1,3}$/; $allow .= " 127.0.0.1"; } elsif (!$wiz_ftp_external) { $allow = "none"; } my $file = "/etc/proftpd.conf"; open (NEW, "< $file"); my $exist = 0; while () { # we need 3 elements to consider section as known if (m/^\s*/s...m/^\s*<\/Global>/s ) { if (m/^\s*/s...m/^\s*<\/Limit>/s ) { if (/^\s*(?!\#)\s*Order .*$/) { $exist++; } if (/^\s*(?!\#)\s*Allow .*$/) { $exist++; } if (/^\s*(?!\#)\s*Deny .*$/) { $exist++; } } } } close (NEW); if ($exist < 3) { # Odd parameters are commented if exists to then add a known section substInFile { if (m/^\s*/s...m/^\s*<\/Global>/s ) { if (m/^\s*/s...m/^\s*<\/Limit>/s ) { s/^\s*(?!\#)\s*Order .*$/\#$&\n/s; s/^\s*(?!\#)\s*Allow .*$/\#$&\n/s; s/^\s*(?!\#)\s*Deny .*$/\#$&\n/s; } } } $file; open (NEW, ">> $file"); print NEW ' # Order allow,deny Allow from '.$allow.' Deny from all # '; close NEW; } else { # the known section (3 parameters ) is replaced with our needs substInFile { if (m/^\s*/s...m/^\s*<\/Global>/s ) { if (m/^\s*/s...m/^\s*<\/Limit>/s ) { if (/^\s*(?!\#)\s*Order .*$/i) { if (!/\s*Order\s*allow,\s*deny\s*$/) { s//\#$&\n Order allow,deny\n/; } } if (/^\s*(?!\#)\s*Allow .*$/i) { if (!/\s*Allow\s*from\s*$allow\s*$/) { s//\#$&\n Allow from $allow/; } } if (/^\s*(?!\#)\s*Deny .*$/i) { if (!/\s*Deny\s*from\s*all\s*$/) { s//\#$&\n Deny from all\n/; } } } } } $file; } if (services::is_service_running('proftpd')) { services::restart('proftpd') } else { services::start('proftpd') } } 1;