diff options
author | Arnaud Desmons <adesmons@mandriva.com> | 2002-08-12 15:54:43 +0000 |
---|---|---|
committer | Arnaud Desmons <adesmons@mandriva.com> | 2002-08-12 15:54:43 +0000 |
commit | 78df6523bd5b9e67bed4983c0ece0faed17c6cf1 (patch) | |
tree | b4f06b62ff255f15017c0dd71c7ebc04d3687034 /ftp_wizard/scripts | |
parent | 1b7a1f66cab605cac0afc3c0ee9eac0ebff68f90 (diff) | |
download | drakwizard-78df6523bd5b9e67bed4983c0ece0faed17c6cf1.tar drakwizard-78df6523bd5b9e67bed4983c0ece0faed17c6cf1.tar.gz drakwizard-78df6523bd5b9e67bed4983c0ece0faed17c6cf1.tar.bz2 drakwizard-78df6523bd5b9e67bed4983c0ece0faed17c6cf1.tar.xz drakwizard-78df6523bd5b9e67bed4983c0ece0faed17c6cf1.zip |
First proftpd parser
Diffstat (limited to 'ftp_wizard/scripts')
-rw-r--r-- | ftp_wizard/scripts/ProFtpconf.pm | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/ftp_wizard/scripts/ProFtpconf.pm b/ftp_wizard/scripts/ProFtpconf.pm new file mode 100644 index 00000000..0893099d --- /dev/null +++ b/ftp_wizard/scripts/ProFtpconf.pm @@ -0,0 +1,113 @@ +#!/usr/bin/perl + +package ProFtpconf; +use MDK::Common; +use strict; +require "__WIZ_HOME__/common/scripts/Vareqval.pm"; + +sub true_or_false { + 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 do_it { + my %mdk = Vareqval->get("/etc/sysconfig/mdk_serv"); + $mdk{wiz_ftp_external} = $ENV{wiz_ftp_external} if defined $ENV{wiz_ftp_external} or + die "wiz_ftp_external not defined in env !"; + $mdk{wiz_ftp_internal} = $ENV{wiz_ftp_internal} if defined $ENV{wiz_ftp_internal} or + die "wiz_ftp_internal not defined in env !"; + $mdk{wiz_ftp_external} = true_or_false($mdk{wiz_ftp_external}); + $mdk{wiz_ftp_internal} = $mdk{wiz_ftp_external} ? 1 : true_or_false($mdk{wiz_ftp_internal}); + my $wiz_ftp_internal = $mdk{wiz_ftp_internal}; + my $wiz_ftp_external = $mdk{wiz_ftp_external}; + my $wiz_device = $mdk{wiz_device} if defined $mdk{wiz_device} or + die "wiz_device not in /etc/sysconfig/mdk_serv"; + Vareqval->commit("/etc/sysconfig/mdk_serv", \%mdk); + + 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) { + my %mdk = Vareqval->get("/etc/sysconfig/network-scripts/ifcfg-".$wiz_device); + my $wiz_ip_net = $mdk{NETWORK} if defined $mdk{NETWORK} or + die "NETWORK not in /etc/sysconfig/network-scripts/ifcfg-".$wiz_device; + ($wiz_ip_net) = ($wiz_ip_net =~ /(.*)\..*/); + $allow = "$wiz_ip_net."; + } + elsif (!$wiz_ftp_external) { + $allow = "none"; + } + my $file = "/etc/proftpd.conf"; + open (NEW, "< $file"); + my $exist = 0; + while (<NEW>) { + if (m/^\s*<Global>/s...m/^\s*<\/Global>/s ) { + if (m/^\s*<Limit LOGIN>/s...m/^\s*<\/Limit>/s ) { + if (/^\s*(?!\#)\s*Order .*$/) { + $exist += 1; + } + if (/^\s*(?!\#)\s*Allow .*$/) { + $exist += 1; + } + if (/^\s*(?!\#)\s*Deny .*$/) { + $exist += 1; + } + } + } + } + close (NEW); + if ($exist < 3) { + 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 ' +<Global> + <Limit LOGIN> + Order allow,deny + Allow from ' .$allow.' + Deny from all + </Limit> +</Global>'; + close NEW; + } + else { + 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"); + 10; +} +1; + |