Commit 082373dd authored by sunnavy's avatar sunnavy
Browse files

ParseIPRange should be in ObjectCustomFieldValue

parent f5ba076e
......@@ -54,10 +54,6 @@ no warnings qw(redefine);
use RT::CustomFieldValues;
use RT::ObjectCustomFields;
use RT::ObjectCustomFieldValues;
use Regexp::Common qw(RE_net_IPv4);
use Regexp::Common::net::CIDR;
require Net::CIDR;
our %FieldTypes = (
Select => {
......@@ -1634,29 +1630,4 @@ sub BasedOnObj {
return $obj;
}
sub ParseIPRange {
my $self = shift;
my $arg = shift or return ();
if ( $arg =~ /^\s*$RE{net}{CIDR}{IPv4}{-keep}\s*$/go ) {
my $cidr = join( '.', map $_||0, (split /\./, $1)[0..3] ) ."/$2";
$arg = (Net::CIDR::cidr2range( $cidr ))[0] || $arg;
}
my ($sIP, $eIP);
if ( $arg =~ /^\s*($RE{net}{IPv4})\s*$/o ) {
$sIP = $eIP = sprintf "%03d.%03d.%03d.%03d", split /\./, $1;
}
elsif ( $arg =~ /^\s*($RE{net}{IPv4})-($RE{net}{IPv4})\s*$/o ) {
$sIP = sprintf "%03d.%03d.%03d.%03d", split /\./, $1;
$eIP = sprintf "%03d.%03d.%03d.%03d", split /\./, $2;
}
else {
return ();
}
($sIP, $eIP) = ($eIP, $sIP) if $sIP gt $eIP;
return $sIP, $eIP;
}
1;
......@@ -51,6 +51,10 @@ package RT::ObjectCustomFieldValue;
use strict;
use warnings;
use RT::Interface::Web;
use Regexp::Common qw(RE_net_IPv4);
use Regexp::Common::net::CIDR;
require Net::CIDR;
no warnings qw(redefine);
......@@ -364,4 +368,30 @@ sub IncludeContentForValue {
return $self->_FillInTemplateURL($self->CustomFieldObj->IncludeContentForValue);
}
sub ParseIPRange {
my $self = shift;
my $arg = shift or return ();
if ( $arg =~ /^\s*$RE{net}{CIDR}{IPv4}{-keep}\s*$/go ) {
my $cidr = join( '.', map $_||0, (split /\./, $1)[0..3] ) ."/$2";
$arg = (Net::CIDR::cidr2range( $cidr ))[0] || $arg;
}
my ($sIP, $eIP);
if ( $arg =~ /^\s*($RE{net}{IPv4})\s*$/o ) {
$sIP = $eIP = sprintf "%03d.%03d.%03d.%03d", split /\./, $1;
}
elsif ( $arg =~ /^\s*($RE{net}{IPv4})-($RE{net}{IPv4})\s*$/o ) {
$sIP = sprintf "%03d.%03d.%03d.%03d", split /\./, $1;
$eIP = sprintf "%03d.%03d.%03d.%03d", split /\./, $2;
}
else {
return ();
}
($sIP, $eIP) = ($eIP, $sIP) if $sIP gt $eIP;
return $sIP, $eIP;
}
1;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment