#!/usr/bin/perl package ProFtpconf; require "__WIZ_HOME__/common/scripts/DrakconnectConf.pm"; use MDK::Common; use strict; require "__WIZ_HOME__/common/scripts/Vareqval.pm"; 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; } my $o = DrakconnectConf->new(); sub check { $> and return 1; $o->is_dhcp() and return 2; 0; } sub do_it { my $wiz_ftp_internal = $ENV{wiz_ftp_external} ? 1 : true $ENV{wiz_ftp_internal}; my $wiz_ftp_external = true $ENV{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) = $o->get_from_known_dev("IP") =~ 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 () { if (m/^\s*/s...m/^\s*<\/Global>/s ) { if (m/^\s*/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*/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 { 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; } system("/etc/rc.d/init.d/proftpd restart"); 10; } 1;