summaryrefslogtreecommitdiff
path: root/FS
diff options
context:
space:
mode:
authorjeff <jeff>2008-09-27 03:01:44 +0000
committerjeff <jeff>2008-09-27 03:01:44 +0000
commit4b5d4c82766ef1869d03df63fa1e2f0dd050cb6a (patch)
treec5c814482090bb5e0799db17940250d700857c05 /FS
parentf411189684b0ca7cc1b4b3e9be1895607245b595 (diff)
per address block ip auto assignment and auto router selection
Diffstat (limited to 'FS')
-rw-r--r--FS/FS/Conf.pm7
-rw-r--r--FS/FS/Schema.pm1
-rwxr-xr-xFS/FS/addr_block.pm8
-rwxr-xr-xFS/FS/svc_broadband.pm24
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