use strict;
use base qw( FS::svc_Common );
+use vars qw( $conf );
use FS::Record qw( qsearch qsearchs );
use FS::hardware_type;
use FS::hardware_status;
+use FS::Conf;
+
+FS::UID->install_callback(sub { $conf = FS::Conf->new; });
=head1 NAME
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+)$/ ) {
sub label {
my $self = shift;
- $self->serial || $self->hw_addr;
+ $self->serial || $self->display_hw_addr;
}
=item insert
sub check {
my $self = shift;
+ my $conf = FS::Conf->new;
my $x = $self->setfixed;
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}$/
+ or return "Illegal (MAC address) '".$self->getfield('hw_addr')."'";
+ }
$self->setfield('hw_addr', $hw_addr);
my $error =
$self->ut_numbern('svcnum')
|| $self->ut_foreign_key('typenum', 'hardware_type', 'typenum')
|| $self->ut_ip46n('ip_addr')
- || $self->ut_hexn('hw_addr')
+ || $self->ut_alphan('hw_addr')
|| $self->ut_alphan('serial')
|| $self->ut_alphan('smartcard')
|| $self->ut_foreign_keyn('statusnum', 'hardware_status', 'statusnum')
- || $self->ut_textn('note')
+ || $self->ut_anything('note')
;
return $error if $error;
$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