option to validate MAC address in svc_hardware, #16266
authorMark Wells <mark@freeside.biz>
Sat, 3 Mar 2012 22:42:40 +0000 (14:42 -0800)
committerMark Wells <mark@freeside.biz>
Sat, 3 Mar 2012 22:42:40 +0000 (14:42 -0800)
FS/FS/Conf.pm
FS/FS/svc_hardware.pm

index 4b2bc30..ac80a55 100644 (file)
@@ -4402,6 +4402,13 @@ and customer address. Include units.',
   },
 
   {
+    'key'         => 'svc_hardware-check_mac_addr',
+    'section'     => '', #?
+    'description' => 'Require the "hardware address" field in hardware services to be a valid MAC address.',
+    'type'        => 'checkbox',
+  },
+
+  {
     'key'         => 'tax-report_groups',
     'section'     => '',
     'description' => 'List of grouping possibilities for tax names on reports, one per line, "label op value" (op can be = or !=).',
index 4970b3e..b4eb8cc 100644 (file)
@@ -154,19 +154,25 @@ 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')