From 55a734433fe1625cecca50f85c6da3cecf7c8618 Mon Sep 17 00:00:00 2001 From: Mark Wells Date: Sat, 3 Mar 2012 14:42:40 -0800 Subject: [PATCH] option to validate MAC address in svc_hardware, #16266 --- FS/FS/Conf.pm | 7 +++++++ FS/FS/svc_hardware.pm | 8 +++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index 4b2bc3062..ac80a55bd 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -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 !=).', diff --git a/FS/FS/svc_hardware.pm b/FS/FS/svc_hardware.pm index 4970b3e92..b4eb8ccfa 100644 --- a/FS/FS/svc_hardware.pm +++ b/FS/FS/svc_hardware.pm @@ -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') -- 2.11.0