X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2FRecord.pm;h=b24b69e82cbacccd7e5e2a6cccbe16230234ff2b;hb=121510b6337b7f75f25d583730a65f3fc63bbfbe;hp=97a60b777bcec4e72e454354d297a702f3f69873;hpb=cc8918dd73e3bf01fe69bdda09e2229a5c302f10;p=freeside.git diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm index 97a60b777..b24b69e82 100644 --- a/FS/FS/Record.pm +++ b/FS/FS/Record.pm @@ -25,6 +25,7 @@ use FS::Schema qw(dbdef); use FS::SearchCache; use FS::Msgcat qw(gettext); #use FS::Conf; #dependency loop bs, in install_callback below instead +use Email::Valid; use FS::part_virtual_field; @@ -2916,18 +2917,9 @@ Check/untaint IPv4 or IPv6 address. sub ut_ip46 { my( $self, $field ) = @_; - my $ip_addr = $self->getfield( $field ); - - # strip user-entered leading 0's from IPv4 addresses - # Parsers like NetAddr::IP interpret them as octal instead of decimal - $ip_addr = join( '.', ( - map{ int($_) } - split( /\./, $ip_addr ) - ) - ) if $ip_addr =~ /\./ && $ip_addr =~ /[\.^]0/; - - my $ip = NetAddr::IP->new( $ip_addr ) - or return "Illegal (IP address) $field: ".$self->getfield($field); + my $ip = NetAddr::IP->new( + $self->_ut_ip_strip_leading_zeros( $self->getfield( $field ) ) + ) or return "Illegal (IP address) $field: ".$self->getfield($field); $self->setfield($field, lc($ip->addr)); return ''; } @@ -2947,6 +2939,21 @@ sub ut_ip46n { $self->ut_ip46($field); } +sub _ut_ip_strip_leading_zeros { + # strip user-entered leading 0's from IP addresses + # so parsers like NetAddr::IP don't mangle the address + # e.g. NetAddr::IP converts 10.0.022.220 into 10.0.18.220 + + my ( $self, $ip ) = @_; + + return join '.', map int, split /\./, $ip + if $ip + && $ip =~ /\./ + && $ip =~ /[\.^]0/; + $ip; +} + + =item ut_coord COLUMN [ LOWER [ UPPER ] ] Check/untaint coordinates. @@ -3358,6 +3365,36 @@ sub ut_agentnum_acl { } + +=item ut_email COLUMN + +Check column contains a valid E-Mail address + +=cut + +sub ut_email { + my ( $self, $field ) = @_; + Email::Valid->address( $self->getfield( $field ) ) + ? '' + : "Illegal (email) field $field: ". $self->getfield( $field ); +} + +=item ut_emailn COLUMN + +Check column contains a valid E-Mail address + +May be null + +=cut + +sub ut_emailn { + my ( $self, $field ) = @_; + + $self->getfield( $field ) =~ /^$/ + ? $self->getfield( $field, '' ) + : $self->ut_email( $field ); +} + =item trim_whitespace FIELD[, FIELD ... ] Strip leading and trailing spaces from the value in the named FIELD(s).