diff options
Diffstat (limited to 'ftp_wizard/Proftpd.pm')
-rwxr-xr-x | ftp_wizard/Proftpd.pm | 189 |
1 files changed, 165 insertions, 24 deletions
diff --git a/ftp_wizard/Proftpd.pm b/ftp_wizard/Proftpd.pm index 500bd5b5..fbee9a5b 100755 --- a/ftp_wizard/Proftpd.pm +++ b/ftp_wizard/Proftpd.pm @@ -27,56 +27,62 @@ require MDK::Wizard::Wizcommon; my $wiz = new MDK::Wizard::Wizcommon; my $o = { - name => 'configuration wizard', + name => 'FTP wizard', var => { - ip1 => '', - ip2 => '' - } + wiz_ftp_external => '', + wiz_ftp_anon => '', + wiz_ftp_home => '' + }, + needed_rpm => [ 'proftpd' ], + defaultimage => "$ENV{__WIZARD_HOME__}ftp_wizard/images/FTP.png" }; $o->{pages} = { welcome => { - name => N('') . "\n\n" . N('') . "\n\n" . N(''), + name => N('FTP Server Configuration Wizard') . "\n\n" . N('This wizard will help you configuring the FTP Server for your network.'), no_back => 1, - next => 'ip_range' + post => \&check, + next => 'config' }, - confige => { - name => N('') . "\n\n" . N('') . "\n\n" . N(''), + 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}{ip1} ||= f1(); - $o->{var}{ip2} ||= f2(); + $o->{var}{wiz_ftp_internal} ||= 1; + $o->{var}{wiz_ftp_external} ||= 0; }, - post => \&check, data => [ - { label => '' }, - { label => N(''), val => \$o->{var}{ip1} }, - { label => N(''), val => \$o->{var}{ip2} }, + { 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 => { + warning_dhcp => { name => N('Warning.'), - data => [ { label => N('') } ], + data => [ { label => N('Warning\nYou are in dhcp, server may not work with your configuration.') } ], next => 'summary' }, - error => { + must_be_root => { name => N('Error.'), - data => [ { label => N('') } ], + data => [ { label => N('Sorry, you must be root to do this...') } ], next => 'config' }, summary => { - name => N('') . "\n\n" . N('') . "\n\n" . N(''), - data => [ - { label => N(''), type => 'field', val => \$o->{var}{ip1} }, - { label => '' }, - { label => N(''), type => 'field', val => \$o->{var}{ip2} }, + 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('Congratulation'), - data => [ { label => N('') } ], + data => [ { label => N('The wizard successfully configured your Intranet/Internet FTP Server') } ], end => 1, next => 0 }, @@ -89,4 +95,139 @@ sub new { }, $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 (<NEW>) { # we need 3 elements to consider section as known + if (m/^\s*<drakwizard>/s...m/^\s*<\/drakwizard>/s ) { + if (m/^\s*<Anonymous\s*(.*)>/s ) { + return $1; + } + } + } + return ""; +} + +sub check { + $> and return 'must_be_root'; + $wiz->{net}->is_dhcp() and return 'warning_dhcp'; + ''; +} + +sub print_anonymous() { + print ' +#<drakwizard> +<Anonymous '.$_[0].'> + User ftp + Group ftp + UserAlias anonymous ftp + MaxClients 10 + <Limit WRITE> + DenyAll + </Limit> +</Anonymous> +#</drakwizard> +'; +} + +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 (<NEW>) { # we need 3 elements to consider section as known + if (m/^\s*<Global>/s...m/^\s*<\/Global>/s ) { + if (m/^\s*<Limit LOGIN>/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*<Global>/s...m/^\s*<\/Global>/s ) { + if (m/^\s*<Limit LOGIN>/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 ' +#<drakwizard> +<Global> + <Limit LOGIN> + Order allow,deny + Allow from '.$allow.' + Deny from all + </Limit> +</Global> +#</drakwizard>'; + close NEW; + } + else { # the known section (3 parameters ) is replaced with our needs + substInFile { + if (m/^\s*<Global>/s...m/^\s*<\/Global>/s ) { + if (m/^\s*<Limit LOGIN>/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; + } + system("/etc/rc.d/init.d/proftpd restart"); +} + 1; |