X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fsvc_hardware.pm;h=dbb8b68293560d063916882c9655169215d4a023;hb=db5785cba180e2c210d3ab4d37064c7e61898614;hp=22e627538b1d517bca80143e8707776d0e3e491f;hpb=7d68066ea33f9f85fe14ce663372642d7ec2ad20;p=freeside.git diff --git a/FS/FS/svc_hardware.pm b/FS/FS/svc_hardware.pm index 22e627538..dbb8b6829 100644 --- a/FS/FS/svc_hardware.pm +++ b/FS/FS/svc_hardware.pm @@ -1,10 +1,13 @@ package FS::svc_hardware; +use base qw( FS::svc_Common ); use strict; -use base qw( FS::svc_Common ); -use FS::Record qw( qsearch qsearchs ); -use FS::hardware_type; +use vars qw( $conf ); +use FS::Record qw( qsearchs ); #qsearch qsearchs ); use FS::hardware_status; +use FS::Conf; + +FS::UID->install_callback(sub { $conf = FS::Conf->new; }); =head1 NAME @@ -72,6 +75,7 @@ sub table_info { 'name_plural' => 'Hardware', 'display_weight' => 59, 'cancel_weight' => 86, + 'manual_require' => 1, 'fields' => { 'svcnum' => { label => 'Service' }, 'typenum' => { label => 'Device type', @@ -80,6 +84,7 @@ sub table_info { disable_fixed => 1, disable_default => 1, disable_inventory => 1, + required => 1, }, 'serial' => { label => 'Serial number', %opts }, 'hw_addr' => { label => 'Hardware address', %opts }, @@ -101,9 +106,13 @@ sub search_sql { my ($class, $string) = @_; my @where = (); - my $ip = NetAddr::IP->new($string); - if ( $ip ) { - push @where, $class->search_sql_field('ip_addr', $ip->addr); + if ( $string =~ /^[\d\.:]+$/ ) { + # if the string isn't an IP address, this will waste several seconds + # attempting a DNS lookup. so try to filter those out. + my $ip = NetAddr::IP->new($string); + if ( $ip ) { + push @where, $class->search_sql_field('ip_addr', $ip->addr); + } } if ( $string =~ /^(\w+)$/ ) { @@ -125,7 +134,17 @@ sub search_sql { sub label { my $self = shift; - $self->serial || $self->hw_addr; + my @label = (); + if (my $type = $self->hardware_type) { + push @label, 'Type:' . $type->description; + } + if (my $ser = $self->serial) { + push @label, 'Serial#' . $ser; + } + if (my $mac = $self->display_hw_addr) { + push @label, 'MAC:'. $mac; + } + return join(', ', @label); } =item insert @@ -160,7 +179,7 @@ sub check { return $x unless ref $x; my $hw_addr = $self->getfield('hw_addr'); - $hw_addr = join('', split(/\W/, $hw_addr)); + $hw_addr = join('', split(/[_\W]/, $hw_addr)); if ( $conf->exists('svc_hardware-check_mac_addr') ) { $hw_addr = uc($hw_addr); $hw_addr =~ /^[0-9A-F]{12}$/ @@ -192,13 +211,6 @@ sub check { Returns the L object associated with this installation. -=cut - -sub hardware_type { - my $self = shift; - return qsearchs('hardware_type', { 'typenum' => $self->typenum }); -} - =item status_label Returns the 'label' field of the L object associated @@ -213,6 +225,18 @@ sub status_label { $status->label; } +=item display_hw_addr + +Returns the 'hw_addr' field, formatted as a MAC address if the +'svc_hardware-check_mac_addr' option is enabled. + +=cut + +sub display_hw_addr { + my $self = shift; + ($conf->exists('svc_hardware-check_mac_addr') ? + join(':', $self->hw_addr =~ /../g) : $self->hw_addr) +} =back