summaryrefslogtreecommitdiffstats
path: root/ftp_wizard/scripts/Ftpconf.pm
blob: fdd051190bedbc324d414227099d09e718541dd4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/perl

package Ftpconf;
require "/usr/share/wizards/common/scripts/Vareqval.pm";
use MDK::Common;
use strict;

sub	true_or_false {
    my	($val) = @_;

    $val eq "0" || $val eq "\'0\'" || $val eq "\"0\"" || 
	$val eq "false" || $val eq "\'false\'" || $val eq "\"false\"" and
	return 0;
    $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/ftphosts";
    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 $date = `date`;
    print NEW "# host access file
# Everything after a '#' is treated as comment,
# empty lines are ignored
# acces allowed without host restriction done
# by script $date\n";
	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 =~ /(.*)\..*/);
	    print NEW "allow * $wiz_ip_net.*\n";
	}
    elsif (!$wiz_ftp_external) {
	print NEW "deny * *\n";
    }

    system("service xinetd restart");
}