Modify WebGUI IP fields to use CIDR format instead of a regular expression.

Multiple IPs are separated by commas, whitespace is ignored.
In groups, that affects the ipFilter field,  User::isInGroup.
In settings, that affects Settings::debugIp and Session::ErrorHandler::canShowDebug.

Fixed a bug in WebGUI::Utility::isInSubnet where Net::Subnets->check needs a scalar.

Modified t/User.t to use addresses in CIDR format.
This commit is contained in:
Colin Kuskie 2006-02-14 22:35:21 +00:00
parent c6bc09f79c
commit cd6759f311
7 changed files with 55 additions and 26 deletions

View file

@ -30,6 +30,7 @@ addEMSTables();
updateTemplates();
updateDatabaseLinksAndSQLReport();
addWorkflow();
ipsToCIDR();
finish($session); # this line required
@ -392,6 +393,39 @@ sub removeFiles {
rmtree('../../lib/WebGUI/Asset/Wobject/IndexedSearch');
}
#-------------------------------------------------
sub ipsToCIDR {
print "\tTranslating IP addresses to CIDR format.\n" unless ($quiet);
print "\t\tStarting with Group ipFilters.\n" unless ($quiet);
my $sth = $session->db->read('select groupId, ipFilter from groups');
while (my $hash = $sth->hashRef) {
next unless $hash->{ipFilter};
$hash->{ipFilter} =~ s/\s//g;
my @ips = split /;/, $hash->{ipFilter};
@ips = map { ip2cidr($_) } @ips;
$session->db->write('update groups set ipFilter=? where groupId=?',
[join(',', @ips), $hash->{groupId}]);
}
print "\t\tUpdating debug Ip.\n" unless ($quiet);
$sth = $session->db->read("select * from settings where name='debugIp'");
while (my $hash = $sth->hashRef) {
next unless $hash->{value};
my @ips = split /\s+/, $hash->{value};
@ips = map { ip2cidr($_) } @ips;
$session->db->write('update settings set value=? where name=?',
[join(',', @ips), $hash->{name}]);
}
}
sub ip2cidr {
my ($ip) = @_;
$ip =~ s/\.$//;
my $bytes = $ip =~ tr/././;
my $new_bytes = 3-$bytes;
my $prefixLength = 32 - 8*$new_bytes;
$ip .= ('.0' x $new_bytes) . "/$prefixLength";
return $ip;
}
# ---- DO NOT EDIT BELOW THIS LINE ----