X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fsvc_hardware.pm;h=af6865f12ab8d5a43b7beff1c15fe464d8a42610;hb=22a1feb55c4bb705064a04646ff5c321b8112ce1;hp=5b81a9c2b69bdfea4652c523971c71c7862eca7d;hpb=b65b8096089410001dfbcd35f9a56f9405b9f5f1;p=freeside.git diff --git a/FS/FS/svc_hardware.pm b/FS/FS/svc_hardware.pm index 5b81a9c2b..af6865f12 100644 --- a/FS/FS/svc_hardware.pm +++ b/FS/FS/svc_hardware.pm @@ -2,9 +2,13 @@ package FS::svc_hardware; 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 @@ -45,6 +49,8 @@ The following fields are currently supported: =item serial - Serial number +=item smartcard - Smartcard number, for devices that use a smartcard + =item statusnum - Service status (see L) =item note - Installation notes: location on property, physical access, etc. @@ -82,6 +88,7 @@ sub table_info { 'serial' => { label => 'Serial number', %opts }, 'hw_addr' => { label => 'Hardware address', %opts }, 'ip_addr' => { label => 'IP address', %opts }, + 'smartcard' => { label => 'Smartcard #', %opts }, 'statusnum' => { label => 'Service status', type => 'select', select_table => 'hardware_status', @@ -112,12 +119,17 @@ sub search_sql { $hex =~ s/\W//g; push @where, 'svc_hardware.hw_addr LIKE \'%'.$hex.'%\''; } - '(' . join(' OR ', @where) . ')'; + + if ( @where ) { + '(' . join(' OR ', @where) . ')'; + } else { + '1 = 0'; #false + } } sub label { my $self = shift; - $self->serial || $self->hw_addr; + $self->serial || $self->display_hw_addr; } =item insert @@ -146,22 +158,29 @@ and replace methods. 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)); + 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; @@ -198,6 +217,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