diff options
Diffstat (limited to 'FS')
-rw-r--r-- | FS/FS/Conf.pm | 7 | ||||
-rw-r--r-- | FS/FS/Schema.pm | 1 | ||||
-rwxr-xr-x | FS/FS/addr_block.pm | 8 | ||||
-rwxr-xr-x | FS/FS/svc_broadband.pm | 24 |
4 files changed, 37 insertions, 3 deletions
diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index 274b109db..79e9feb3c 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -731,6 +731,13 @@ worry that config_items is freeside-specific and icky. }, { + 'key' => 'auto_router', + 'section' => '', + 'description' => 'Automatically choose the correct router/block based on supplied ip address when possible while provisioning broadband services', + 'type' => 'checkbox', + }, + + { 'key' => 'hidecancelledpackages', 'section' => 'UI', 'description' => 'Prevent cancelled packages from showing up in listings (though they will still be in the database)', diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index 5c9f6248c..0b121db3e 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -1586,6 +1586,7 @@ sub tables_hashref { 'ip_gateway', 'varchar', '', 15, '', '', 'ip_netmask', 'int', '', '', '', '', 'agentnum', 'int', 'NULL', '', '', '', + 'manual_flag', 'char', 'NULL', 1, '', '', ], 'primary_key' => 'blocknum', 'unique' => [ [ 'blocknum', 'routernum' ] ], diff --git a/FS/FS/addr_block.pm b/FS/FS/addr_block.pm index 9d523e1fc..0fe2476a2 100755 --- a/FS/FS/addr_block.pm +++ b/FS/FS/addr_block.pm @@ -48,6 +48,8 @@ block is assigned. =item ip_netmask - the netmask of the block, expressed as an integer. +=item manual_flag - prohibit automatic ip assignment from this block when true. + =item agentnum - optional agent number (see L<FS::agent>) =back @@ -124,6 +126,7 @@ sub check { $self->ut_number('routernum') || $self->ut_ip('ip_gateway') || $self->ut_number('ip_netmask') + || $self->ut_enum('manual_flag', [ '', 'Y' ]) || $self->ut_agentnum_acl('agentnum', 'Broadband global configuration') ; return $error if $error; @@ -202,13 +205,16 @@ sub cidr { Returns a NetAddr::IP object corresponding to the first unassigned address in the block (other than the network, broadcast, or gateway address). If -there are no free addresses, returns false. +there are no free addresses, returns false. There are never free addresses +when manual_flag is true. =cut sub next_free_addr { my $self = shift; + return '' if $self->manual_flag; + my $conf = new FS::Conf; my @excludeaddr = $conf->config('exclude_ip_addr'); diff --git a/FS/FS/svc_broadband.pm b/FS/FS/svc_broadband.pm index fa904370b..b808527a1 100755 --- a/FS/FS/svc_broadband.pm +++ b/FS/FS/svc_broadband.pm @@ -203,7 +203,7 @@ sub check { my $error = $self->ut_numbern('svcnum') - || $self->ut_foreign_key('blocknum', 'addr_block', 'blocknum') + || $self->ut_numbern('blocknum') || $self->ut_textn('description') || $self->ut_number('speed_up') || $self->ut_number('speed_down') @@ -231,7 +231,12 @@ sub check { return "Invalid pkgnum" unless $cust_pkg; } - if ($cust_pkg) { + if ($self->blocknum) { + $error = $self->ut_foreign_key('blocknum', 'addr_block', 'blocknum'); + return $error if $error; + } + + if ($cust_pkg && $self->blocknum) { my $addr_agentnum = $self->addr_block->agentnum; if ($addr_agentnum && $addr_agentnum != $cust_pkg->cust_main->agentnum) { return "Address block does not service this customer"; @@ -239,6 +244,8 @@ sub check { } if (not($self->ip_addr) or $self->ip_addr eq '0.0.0.0') { + return "Must supply either address or block" + unless $self->blocknum; my $next_addr = $self->addr_block->next_free_addr; if ($next_addr) { $self->ip_addr($next_addr->addr); @@ -247,6 +254,19 @@ sub check { } } + if (not($self->blocknum)) { + return "Must supply either address or block" + unless ($self->ip_addr and $self->ip_addr ne '0.0.0.0'); + my @block = grep { $_->NetAddr->contains($self->NetAddr) } + map { $_->addr_block } + $self->allowed_routers; + if (scalar(@block)) { + $self->blocknum($block[0]->blocknum); + }else{ + return "Address not with available block."; + } + } + # This should catch errors in the ip_addr. If it doesn't, # they'll almost certainly not map into the block anyway. my $self_addr = $self->NetAddr; #netmask is /32 |