version 1.6, 2010/03/25 01:47:45
|
version 1.7, 2010/12/30 18:40:29
|
Line 183 sub firewall_is_port_open {
|
Line 183 sub firewall_is_port_open {
|
# check if firewall is active or installed |
# check if firewall is active or installed |
return if (! &firewall_is_active()); |
return if (! &firewall_is_active()); |
my $count = 0; |
my $count = 0; |
if (open(PIPE,"$iptables -L $fw_chain -n 2>/dev/null |")) { |
if (open(PIPE,"$iptables -L $fw_chain -n |")) { |
while(<PIPE>) { |
while(<PIPE>) { |
if ($port eq $lond_port) { |
if ($port eq $lond_port) { |
if (ref($iphost) eq 'HASH') { |
if (ref($iphost) eq 'HASH') { |
if (/^ACCEPT\s+tcp\s+\-{2}\s+([\S]+)\s+/) { |
if (/^ACCEPT\s+tcp\s+\-{2}\s+(\S+)\s+\S+\s+tcp\s+dpt\:\Q$port\E/) { |
my $ip = $1; |
my $ip = $1; |
if ($iphost->{$ip}) { |
if ($iphost->{$ip}) { |
$count ++; |
$count ++; |
Line 218 sub firewall_is_active {
|
Line 218 sub firewall_is_active {
|
} |
} |
|
|
sub firewall_close_port { |
sub firewall_close_port { |
my ($iptables,$fw_chains,$lond_port,$ports) = @_; |
my ($iptables,$fw_chains,$lond_port,$iphost,$ports) = @_; |
return 'inactive firewall' if (!&firewall_is_active()); |
return 'inactive firewall' if (!&firewall_is_active()); |
return 'port number unknown' if !$lond_port; |
return 'port number unknown' if !$lond_port; |
return 'invalid firewall chain' unless (ref($fw_chains) eq 'ARRAY'); |
return 'invalid firewall chain' unless (ref($fw_chains) eq 'ARRAY'); |
Line 254 sub firewall_close_port {
|
Line 254 sub firewall_close_port {
|
chomp(); |
chomp(); |
next unless (/dpt:\Q$port\E\s*$/); |
next unless (/dpt:\Q$port\E\s*$/); |
if (/^ACCEPT\s+tcp\s+\-{2}\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s+/) { |
if (/^ACCEPT\s+tcp\s+\-{2}\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s+/) { |
$to_close{$1} = $port; |
my $ip = $1; |
|
my $keepopen = 0; |
|
if (ref($iphost) eq 'HASH') { |
|
if (exists($iphost->{$ip})) { |
|
$keepopen = 1; |
|
} |
|
} |
|
unless ($keepopen) { |
|
$to_close{$ip} = $port; |
|
} |
} |
} |
} |
} |
close(PIPE); |
close(PIPE); |
Line 446 The following methods are available:
|
Line 455 The following methods are available:
|
|
|
=over 4 |
=over 4 |
|
|
=item LONCAPA::Firewall::firewall_close_port( $iptables,$fw_chains,$lond_port,$ports ); |
=item LONCAPA::Firewall::firewall_close_port( $iptables,$fw_chains,$lond_port,$iphost,$ports ); |
|
|
=back |
=back |
|
|