From 47079c956fde5d5e85e1300dd7a6a600137f4fb9 Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Sun, 28 Oct 2018 15:14:30 -0700 Subject: [PATCH] config for svc_hardware dup checking, RT#81534 --- FS/FS/Conf.pm | 7 +++++++ FS/FS/svc_hardware.pm | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index 7f3231367..5c0fdffa4 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -3345,6 +3345,13 @@ and customer address. Include units.', }, { + 'key' => 'global_unique-svc_hardware', + 'section' => '', + 'description' => 'Turn on duplicate checking for svc_hardware services. Unique fields are IP address, hardware address, and serial number (per device type).', + 'type' => 'checkbox', + }, + + { 'key' => 'svc_external-skip_manual', 'section' => 'UI', 'description' => 'When provisioning svc_external services, skip manual entry of id and title fields in the UI. Usually used in conjunction with an export that populates these fields (i.e. artera_turbo).', diff --git a/FS/FS/svc_hardware.pm b/FS/FS/svc_hardware.pm index 62556ba6a..f260502f5 100644 --- a/FS/FS/svc_hardware.pm +++ b/FS/FS/svc_hardware.pm @@ -215,6 +215,40 @@ sub check { $self->SUPER::check; } +sub _check_duplicate { + my $self = shift; + + return '' unless $conf->exists('global_unique-svc_hardware'); + + $self->lock_table; + + if ( $self->hw_addr ) { + my @dup_mac; + @dup_mac = $self->find_duplicates('global', 'hw_addr'); + if ( @dup_mac ) { + return "MAC address in use (svcnum ".$dup_mac[0]->svcnum.")"; + } + } + + if ( $self->ip_addr ) { + my @dup_ip; + @dup_ip = $self->find_duplicates('global', 'ip_addr'); + if ( @dup_ip ) { + return "IP address in use (svcnum ".$dup_ip[0]->svcnum.")"; + } + } + + if ( $self->serialnum ) { + my @dup_serial; + @dup_serial = $self->find_duplicates('global', 'typenum', 'serialnum'); + if ( @dup_serial ) { + return "Serial number in use (svcnum ".$dup_serial[0]->svcnum.")"; + } + } + + ''; +} + =item hardware_type Returns the L object associated with this installation. -- 2.11.0