source: trunk/cgi-bin/main.cgi@ 883

Last change on this file since 883 was 883, checked in by Kris Deugau, 9 years ago

/trunk

Fix lurking issue with guided assignment of IPv6; there is a much larger
mask length gap between "layers" resulting in poor performance and
tripping NetAddr::IP->split()'s return count limits

  • Property svn:executable set to *
  • Property svn:keywords set to Date Rev Author
File size: 59.3 KB
Line 
1#!/usr/bin/perl
2# ipdb/cgi-bin/main.cgi
3###
4# SVN revision info
5# $Date: 2016-06-15 20:48:01 +0000 (Wed, 15 Jun 2016) $
6# SVN revision $Rev: 883 $
7# Last update by $Author: kdeugau $
8###
9# Copyright (C) 2004-2010 - Kris Deugau
10
11use strict;
12use warnings;
13use CGI::Carp qw(fatalsToBrowser);
14use CGI::Simple;
15use HTML::Template;
16use DBI;
17use POSIX qw(ceil);
18use NetAddr::IP;
19use Frontier::Client;
20
21use Sys::Syslog;
22
23# don't remove! required for GNU/FHS-ish install from tarball
24##uselib##
25
26use CustIDCK;
27use MyIPDB;
28
29openlog "IPDB","pid","$IPDB::syslog_facility";
30
31## Environment. Collect some things, process some things, set some things...
32
33# Collect the username from HTTP auth. If undefined, we're in
34# a test environment, or called without a username.
35my $authuser;
36if (!defined($ENV{'REMOTE_USER'})) {
37 $authuser = '__temptest';
38} else {
39 $authuser = $ENV{'REMOTE_USER'};
40}
41
42# anyone got a better name? :P
43my $thingroot = $ENV{SCRIPT_FILENAME};
44$thingroot =~ s|cgi-bin/main.cgi||;
45
46syslog "debug", "$authuser active, $ENV{'REMOTE_ADDR'}";
47
48##fixme there *must* be a better order to do things in so this can go back where it was
49# CGI fiddling done here so we can declare %webvar so we can alter $webvar{action}
50# to show the right page on DB errors.
51# Set up the CGI object...
52my $q = new CGI::Simple;
53# ... and get query-string params as well as POST params if necessary
54$q->parse_query_string;
55
56# Convenience; saves changing all references to %webvar
57##fixme: tweak for handling <select multiple='y' size=3> (list with multiple selection)
58my %webvar = $q->Vars;
59
60# Why not a global DB handle? (And a global statement handle, as well...)
61# Use the connectDB function, otherwise we end up confusing ourselves
62my $ip_dbh;
63my $errstr;
64($ip_dbh,$errstr) = connectDB_My;
65if (!$ip_dbh) {
66 $webvar{action} = "dberr";
67} else {
68 initIPDBGlobals($ip_dbh);
69}
70
71# Set up some globals
72$ENV{HTML_TEMPLATE_ROOT} = $thingroot;
73my @templatepath = [ "localtemplates", "templates" ];
74
75my $header = HTML::Template->new(filename => "header.tmpl", path => @templatepath);
76my $footer = HTML::Template->new(filename => "footer.tmpl", path => @templatepath);
77my $utilbar = HTML::Template->new(filename => "utilbar.tmpl", loop_context_vars => 1, global_vars => 1,
78 path => @templatepath);
79
80print "Content-type: text/html\n\n";
81
82$header->param(version => $IPDB::VERSION);
83$header->param(addperm => $IPDBacl{$authuser} =~ /a/);
84$header->param(webpath => $IPDB::webpath);
85
86$utilbar->param(webpath => $IPDB::webpath);
87
88print $header->output;
89
90##fixme: whine and complain when the user is not present in the ACL hash above
91
92#main()
93my $aclerr;
94
95if(!defined($webvar{action})) {
96 $webvar{action} = "index"; #shuts up the warnings.
97}
98
99my $page;
100if (-e "$ENV{HTML_TEMPLATE_ROOT}/templates/$webvar{action}.tmpl") {
101 $page = HTML::Template->new(filename => "$webvar{action}.tmpl", loop_context_vars => 1, global_vars => 1,
102 path => @templatepath);
103} else {
104 $page = HTML::Template->new(filename => "dunno.tmpl", die_on_bad_params => 0,
105 path => @templatepath);
106}
107
108if($webvar{action} eq 'index') {
109 showSummary();
110} elsif ($webvar{action} eq 'showvrf') {
111 showVRF();
112
113} elsif ($webvar{action} eq 'addvrf') {
114 if ($IPDBacl{$authuser} !~ /s/) {
115 $aclerr = 'addvrf';
116 }
117
118 # Retrieve the list of DNS locations if we've got a place to grab them from
119 if ($IPDB::rpc_url) {
120 my %rpcargs = (
121 rpcuser => $authuser,
122 group => 1, # bleh
123 defloc => '',
124 );
125 my $result = IPDB::_rpc('getLocDropdown', %rpcargs);
126 $page->param(loclist => $result);
127 }
128
129} elsif ($webvar{action} eq 'newvrf') {
130 if ($IPDBacl{$authuser} !~ /s/) {
131 $aclerr = 'addvrf';
132 } else {
133 my ($code,$msg) = addVRF($ip_dbh, $webvar{vrf}, comment => $webvar{comment}, location => $webvar{loc});
134
135 if ($code eq 'FAIL') {
136 syslog "err", "Could not add VRF '$webvar{vrf}' to database: '$msg'";
137 $page->param(err => $msg);
138 $page->param(vrf => $webvar{vrf});
139 } else {
140 $page->param(vrf => $msg);
141 if ($code eq 'WARN') {
142 $IPDB::errstr =~ s/\n\n/<br>\n/g;
143 $IPDB::errstr =~ s/:\n/:<br>\n/g;
144 $page->param(warn => $IPDB::errstr);
145 }
146 syslog "info", "$authuser added VRF $webvar{vrf}";
147 }
148
149 } # ACL check
150
151} elsif ($webvar{action} eq 'delvrf') {
152 if ($IPDBacl{$authuser} !~ /s/) {
153 $aclerr = 'delvrf';
154 }
155
156 my $vrf = getVRF($ip_dbh, $webvar{vrf});
157
158 $page->param(vrf => $webvar{vrf});
159 $page->param(vrfcomment => $vrf->{comment});
160
161} elsif ($webvar{action} eq 'finaldelvrf') {
162 if ($IPDBacl{$authuser} !~ /s/) {
163 $aclerr = 'finaldelvrf';
164 }
165
166 my $vrf = getVRF($ip_dbh, $webvar{vrf});
167 $page->param(vrf => $webvar{vrf});
168 $page->param(vrfcomment => $vrf->{comment});
169
170 my ($code,$msg) = deleteVRF($ip_dbh, $webvar{vrf}, $authuser);
171
172 if ($code eq 'FAIL') {
173 $page->param(failmsg => $msg);
174 }
175
176} elsif ($webvar{action} eq 'addmaster') {
177 if ($IPDBacl{$authuser} !~ /a/) {
178 $aclerr = 'addmaster';
179 }
180
181 my $vrf = getVRF($ip_dbh, $webvar{vrf});
182
183 # Retrieve the list of DNS locations if we've got a place to grab them from
184 if ($IPDB::rpc_url) {
185 my %rpcargs = (
186 rpcuser => $authuser,
187 group => 1, # bleh
188 defloc => $vrf->{location},
189 );
190 my $result = IPDB::_rpc('getLocDropdown', %rpcargs);
191 $page->param(loclist => $result);
192 }
193
194 # we don't have a netblock; pass 0 for the block ID
195 # Tree navigation
196 my $crumbs = getBreadCrumbs($ip_dbh, 0, $webvar{vrf});
197 my @rcrumbs = reverse (@$crumbs);
198 $utilbar->param(breadcrumb => \@rcrumbs);
199
200 $page->param(vrf => $webvar{vrf});
201
202} elsif ($webvar{action} eq 'newmaster') {
203
204 if ($IPDBacl{$authuser} !~ /a/) {
205 $aclerr = 'addmaster';
206 } else {
207 my $cidr = new NetAddr::IP $webvar{cidr};
208 $page->param(cidr => "$cidr");
209
210 my ($code,$msg) = addMaster($ip_dbh, $webvar{cidr}, (vrf => $webvar{vrf}, rdns => $webvar{rdns},
211 rwhois => $webvar{rwhois}, defloc => $webvar{loc}, user => $authuser) );
212
213 if ($code eq 'FAIL') {
214 syslog "err", "Could not add master block '$webvar{cidr}' to database: '$msg'";
215 $page->param(err => $msg);
216 } else {
217 $page->param(parent => $msg);
218 if ($code eq 'WARN') {
219 $IPDB::errstr =~ s/\n\n/<br>\n/g;
220 $IPDB::errstr =~ s/:\n/:<br>\n/g;
221 $page->param(warn => $IPDB::errstr);
222 }
223 syslog "info", "$authuser added master block $webvar{cidr}";
224 }
225
226 # we don't have a netblock; pass 0 for the block ID
227 # Tree navigation
228 my $crumbs = getBreadCrumbs($ip_dbh, 0, $webvar{vrf});
229 my @rcrumbs = reverse (@$crumbs);
230 $utilbar->param(breadcrumb => \@rcrumbs);
231
232 } # ACL check
233
234} # end add new master
235
236elsif ($webvar{action} eq 'showsubs') {
237 showSubs();
238}
239
240elsif($webvar{action} eq 'listpool') {
241 showPool();
242}
243
244# Not modified or added; just shuffled
245elsif($webvar{action} eq 'assign') {
246 assignBlock();
247}
248elsif($webvar{action} eq 'confirm') {
249 confirmAssign();
250}
251elsif($webvar{action} eq 'insert') {
252 insertAssign();
253}
254elsif($webvar{action} eq 'edit') {
255 edit();
256}
257elsif($webvar{action} eq 'update') {
258 update();
259}
260elsif($webvar{action} eq 'split') {
261 prepSplit();
262}
263elsif($webvar{action} eq 'dosplit') {
264 doSplit();
265}
266elsif($webvar{action} eq 'merge') {
267 prepMerge();
268}
269elsif($webvar{action} eq 'confmerge') {
270 confMerge();
271}
272elsif($webvar{action} eq 'domerge') {
273 doMerge();
274}
275elsif($webvar{action} eq 'delete') {
276 remove();
277}
278elsif($webvar{action} eq 'finaldelete') {
279 finalDelete();
280}
281elsif ($webvar{action} eq 'nodesearch') {
282 my $nodelist = getNodeList($ip_dbh);
283 $page->param(nodelist => $nodelist);
284}
285
286# DB failure. Can't do much here, really.
287elsif ($webvar{action} eq 'dberr') {
288 $page->param(errmsg => $errstr);
289}
290
291# Default is an error. It shouldn't be possible to get here unless you're
292# randomly feeding in values for webvar{action}.
293else {
294 my $rnd = rand 500;
295 my $boing = sprintf("%.2f", rand 500);
296 my @excuses = (
297 "Aether cloudy. Ask again later about $webvar{action}.",
298 "The gods are unhappy with your sacrificial $webvar{action}.",
299 "Because one of $webvar{action}'s legs are both the same",
300 "<b>wibble</b><br>Can't $webvar{action}, the grue will get me!<br>Can't $webvar{action}, the grue will get me!",
301 "Hey, man, you've had your free $webvar{action}. Next one's gonna... <i>cost</i>....",
302 "I ain't done $webvar{action}",
303 "Oooo, look! A flying $webvar{action}!",
304 "$webvar{action} too evil, avoiding.",
305 "Rocks fall, $webvar{action} dies.",
306 "Bit bucket must be emptied before I can $webvar{action}..."
307 );
308 $page->param(dunno => $excuses[$rnd/50.0]);
309}
310## Finally! Done with that NASTY "case" emulation!
311
312
313# Switch to a different template if we've tripped on an ACL error.
314# Note that this should only be exercised in development, when
315# deeplinked, or when being attacked; normal ACL handling should
316# remove the links a user is not allowed to click on.
317if ($aclerr) {
318 $page = HTML::Template->new(filename => "aclerror.tmpl", path => @templatepath);
319 $page->param(ipdbfunc => $aclmsg{$aclerr});
320}
321
322# Clean up IPDB globals, DB handle, etc.
323finish($ip_dbh);
324
325## Do all our printing here so we can generate errors and stick them into the slots in the templates.
326
327# can't do this yet, too many blowups
328#print "Content-type: text/html\n\n", $header->output;
329$page->param(webpath => $IPDB::webpath);
330print $utilbar->output;
331print $page->output;
332
333# include the admin tools link in the output?
334$footer->param(adminlink => ($IPDBacl{$authuser} =~ /A/));
335$footer->param(webpath => $IPDB::webpath);
336print $footer->output;
337
338# Just in case something waaaayyy down isn't in place
339# properly... we exit explicitly.
340exit 0;
341
342
343# Initial display: Show list of VRFs
344sub showSummary {
345 my $vrflist = listVRF($ip_dbh);
346
347 if ($IPDB::masterswithvrfs == 2) {
348 $page = HTML::Template->new(filename => "index2.tmpl", loop_context_vars => 1, global_vars => 1,
349 path => @templatepath);
350 # alternate layout; put master blocks on the front summary page instead of "out"/"down" a
351 # layer in the browse tree. Leaving the manual include of showvrf.tmpl for reference; not
352 # sure why setting webpath here didn't seem to make it to the output.
353# my $vrfinfo = HTML::Template->new(filename => "showvrf.tmpl", path => @templatepath);
354 foreach my $vrf (@$vrflist) {
355 my $masterlist = listSummary($ip_dbh, $vrf->{vrf});
356 $vrf->{masterlist} = $masterlist;
357 $vrf->{addmaster} = ($IPDBacl{$authuser} =~ /s/);
358 $vrf->{maydel} = ($IPDBacl{$authuser} =~ /s/);
359 $vrf->{sub} = 1;
360# $vrfinfo->param(vrf => $vrf->{vrf});
361# $vrfinfo->param(masterlist => $masterlist);
362# $vrfinfo->param(addmaster => ($IPDBacl{$authuser} =~ /s/) );
363# $vrfinfo->param(maydel => ($IPDBacl{$authuser} =~ /s/) );
364# $vrfinfo->param(sub => 1);
365# $vrfinfo->param(webpath => $IPDB::webpath);
366# $vrf->{vrfinfo} = $vrfinfo->output;
367 }
368 }
369
370 $page->param(vrflist => $vrflist);
371
372 # Only systems/network should be allowed to add VRFs - or maybe higher?
373 $page->param(addvrf => ($IPDBacl{$authuser} =~ /s/) );
374
375} # showSummary
376
377
378# Show IP blocks in a VRF
379sub showVRF {
380 my $masterlist = listSummary($ip_dbh, $webvar{vrf});
381 $page->param(vrf => $webvar{vrf});
382 $page->param(masterlist => $masterlist);
383
384 # we don't have a netblock; pass 0 for the block ID
385 # Tree navigation
386 my $crumbs = getBreadCrumbs($ip_dbh, 0, $webvar{vrf});
387 my @rcrumbs = reverse (@$crumbs);
388 $utilbar->param(breadcrumb => \@rcrumbs);
389
390 $page->param(maydel => ($IPDBacl{$authuser} =~ /s/) );
391 $page->param(addmaster => ($IPDBacl{$authuser} =~ /s/) );
392} # showVRF
393
394
395# Display blocks immediately within a given parent
396sub showSubs {
397 # Which layout?
398 if ($IPDB::sublistlayout == 2) {
399
400 # 2-part layout; mixed containers and end-use allocations and free blocks.
401 # Containers have a second line for the subblock metadata.
402 # We need to load an alternate template for this case.
403 $page = HTML::Template->new(filename => "showsubs2.tmpl", loop_context_vars => 1, global_vars => 1,
404 path => @templatepath);
405
406 $page->param(maydel => ($IPDBacl{$authuser} =~ /d/));
407
408 my $sublist = listSubs($ip_dbh, parent => $webvar{parent});
409 $page->param(sublist => $sublist);
410
411 } else {
412
413 # 3-part layout; containers, end-use allocations, and free blocks
414
415 my $contlist = listContainers($ip_dbh, parent => $webvar{parent});
416 $page->param(contlist => $contlist);
417
418 my $alloclist = listAllocations($ip_dbh, parent => $webvar{parent});
419 $page->param(alloclist => $alloclist);
420
421 # only show "delete" button if we have no container or usage allocations
422 $page->param(maydel => ($IPDBacl{$authuser} =~ /d/) && !(@$contlist || @$alloclist));
423
424 }
425
426 # Common elements
427 my $pinfo = getBlockData($ip_dbh, $webvar{parent});
428
429##fixme: do we add a wrapper to not show the edit link for master blocks?
430#$page->param(editme => 1) unless $pinfo->{type} ne 'mm';
431
432 my $crumbs = getBreadCrumbs($ip_dbh, $pinfo->{parent_id}, $pinfo->{vrf});
433 my @rcrumbs = reverse (@$crumbs);
434 $utilbar->param(breadcrumb => \@rcrumbs);
435
436 $page->param(self_id => $webvar{parent});
437 $page->param(block => $pinfo->{block});
438 $page->param(mayadd => ($IPDBacl{$authuser} =~ /a/));
439
440 my $flist = listFree($ip_dbh, parent => $webvar{parent});
441 $page->param(freelist => $flist);
442} # showSubs
443
444
445# List the IPs used in a pool
446sub showPool {
447
448 my $poolinfo = getBlockData($ip_dbh, $webvar{pool});
449 my $cidr = new NetAddr::IP $poolinfo->{block};
450 $page->param(vlan => $poolinfo->{vlan});
451
452 # Tree navigation
453 my $crumbs = getBreadCrumbs($ip_dbh, $poolinfo->{parent_id});
454 my @rcrumbs = reverse (@$crumbs);
455 $utilbar->param(breadcrumb => \@rcrumbs);
456
457 $page->param(block => $cidr);
458 $page->param(netip => $cidr->addr);
459 $cidr++;
460 $page->param(gate => $cidr->addr);
461 $cidr--; $cidr--;
462 $page->param(bcast => $cidr->addr);
463 $page->param(mask => $cidr->mask);
464
465 $page->param(disptype => $disp_alloctypes{$poolinfo->{type}});
466 $page->param(city => $poolinfo->{city});
467
468 # Only display net/gw/bcast if it's a "real" netblock and not a PPP(oE) lunacy
469 $page->param(realblock => $poolinfo->{type} =~ /^.d$/);
470
471# probably have to add an "edit IP allocation" link here somewhere.
472
473 # this will cascade into the IP list below
474 $page->param(maydel => $IPDBacl{$authuser} =~ /d/);
475
476 my $plist = listPool($ip_dbh, $webvar{pool}, 1);
477 $page->param(poolips => $plist);
478} # end showPool
479
480
481# Show "Add new allocation" page. Note that the actual page may
482# be one of two templates, and the lists come from the database.
483sub assignBlock {
484
485 if ($IPDBacl{$authuser} !~ /a/) {
486 $aclerr = 'addblock';
487 return;
488 }
489
490 # hack pthbttt eww
491 $webvar{parent} = 0 if !$webvar{parent};
492 $webvar{block} = '' if !$webvar{block};
493
494 $page->param(allocfrom => $webvar{block}); # fb-assign flag, if block is set, we're in fb-assign
495
496 if ($webvar{fbid} || $webvar{fbtype}) {
497
498 # Common case, according to reported usage. Block to assign is specified.
499 my $block = new NetAddr::IP $webvar{block};
500
501 my ($rdns,$cached) = getBlockRDNS($ip_dbh, id => $webvar{parent}, type => $webvar{fbtype}, user => $authuser);
502 $page->param(rdns => $rdns) if $rdns;
503 $page->param(parent => $webvar{parent});
504 $page->param(fbid => $webvar{fbid});
505 # visual flag that we're working IPDB-local, not off more authoritative data in dnsadmin
506 $page->param(cached => $cached);
507
508 my $pinfo = getBlockData($ip_dbh, $webvar{parent});
509
510 # Tree navigation
511 my $crumbs = getBreadCrumbs($ip_dbh, $webvar{parent});
512 my @rcrumbs = reverse (@$crumbs);
513 $utilbar->param(breadcrumb => \@rcrumbs);
514
515 $webvar{fbtype} = '' if !$webvar{fbtype};
516 if ($webvar{fbtype} eq 'i') {
517 my $ipinfo = getBlockData($ip_dbh, $webvar{block}, 'i');
518 $page->param(
519 fbip => 1,
520 block => $ipinfo->{block},
521 fbdisptype => $list_alloctypes{$ipinfo->{type}},
522 type => $ipinfo->{type},
523 allocfrom => $pinfo->{block},
524 );
525 } else {
526 # get "primary" alloctypes, since these are all that can correctly be assigned if we're in this branch
527 my $tlist = getTypeList($ip_dbh, 'n');
528 $tlist->[0]->{sel} = 1;
529 $page->param(typelist => $tlist, block => $block);
530 }
531
532 } else {
533
534 # Uncommon case, according to reported usage. Block to assign needs to be found based on criteria.
535 my $mlist = getMasterList($ip_dbh, 'c');
536 $page->param(masterlist => $mlist);
537
538 my @pops;
539 foreach my $pop (@citylist) {
540 my %row = (pop => $pop);
541 push (@pops, \%row);
542 }
543 $page->param(pops => \@pops);
544
545 # get all standard alloctypes
546 my $tlist = getTypeList($ip_dbh, 'a');
547 $tlist->[0]->{sel} = 1;
548 $page->param(typelist => $tlist);
549 }
550
551 my @cities;
552 foreach my $city (@citylist) {
553 my %row = (city => $city);
554 push (@cities, \%row);
555 }
556 $page->param(citylist => \@cities);
557
558## node hack
559 my $nlist = getNodeList($ip_dbh);
560 $page->param(nodelist => $nlist);
561## end node hack
562
563 $page->param(nocling => $IPDBacl{$authuser} =~ /s/);
564
565} # assignBlock
566
567
568# Take info on requested IP assignment and see what we can provide.
569sub confirmAssign {
570 if ($IPDBacl{$authuser} !~ /a/) {
571 $aclerr = 'addblock';
572 return;
573 }
574
575 my $cidr;
576 my $resv; # Reserved for expansion.
577 my $alloc_from;
578 my $fbid = $webvar{fbid};
579 my $p_id = $webvar{parent};
580
581 # Going to manually validate some items.
582 # custid and city are automagic.
583 return if !validateInput();
584
585 # make sure this is defined
586 $webvar{fbassign} = 'n' if !$webvar{fbassign};
587
588# Several different cases here.
589# Static IP vs netblock
590# + Different flavours of static IP
591# + Different flavours of netblock
592
593 if ($webvar{alloctype} =~ /^.i$/ && $webvar{fbassign} ne 'y') {
594 if (!$webvar{pop}) {
595 $page->param(err => "Please select a location/POP site to allocate from.");
596 return;
597 }
598 my $plist = getPoolSelect($ip_dbh, $webvar{alloctype}, $webvar{pop});
599 $page->param(staticip => 1);
600 $page->param(poollist => $plist) if $plist;
601 $cidr = "Single static IP";
602##fixme: need to handle "no available pools"
603
604 } else { # end show pool options
605
606 if ($webvar{fbassign} && $webvar{fbassign} eq 'y') {
607
608 # Tree navigation
609 my $crumbs = getBreadCrumbs($ip_dbh, $webvar{parent});
610 my @rcrumbs = reverse (@$crumbs);
611 $utilbar->param(breadcrumb => \@rcrumbs);
612
613 $cidr = new NetAddr::IP $webvar{block};
614 $alloc_from = new NetAddr::IP $webvar{allocfrom};
615 $webvar{maskbits} = $cidr->masklen;
616 # Some additional checks are needed for reserving free space
617 if ($webvar{reserve}) {
618 if ($cidr == $alloc_from) {
619# We could still squirm and fiddle to try to find a way to reserve space, but the storage model for
620# IPDB means that all continguous free space is kept in the smallest number of strict CIDR netblocks
621# possible. (In theory.) If the request and the freeblock are the same, it is theoretically impossible
622# to reserve an equivalent-sized block either ahead or behind the requested one, because the pair
623# together would never be a strict CIDR block.
624 $page->param(warning => "Can't reserve space for expansion; free block and requested allocation are the same.");
625 delete $webvar{reserve};
626 } else {
627 # Find which new free block will match the reqested block.
628 # Take the requested mask, shift by one
629 my $tmpmask = $webvar{maskbits};
630 $tmpmask--;
631 # find the subnets with that mask in the selected free block
632 my @pieces = $alloc_from->split($tmpmask);
633 foreach my $slice (@pieces) {
634 if ($slice->contains($cidr)) {
635 # For the subnet that contains the requested block, split that in two,
636 # and flag/cache the one that's not the requested block.
637 my @bits = $slice->split($webvar{maskbits});
638 if ($bits[0] == $cidr) {
639 $resv = $bits[1];
640 } else {
641 $resv = $bits[0];
642 }
643 }
644 }
645 }
646 } # reserve block check
647
648 } else { # done with direct freeblocks assignment
649
650 if (!$webvar{maskbits}) {
651 $page->param(err => "Please specify a CIDR mask length.");
652 return;
653 }
654
655##fixme ick, ew, bleh. gotta handle the failure message generation better. push it into findAllocateFrom()?
656 my $failmsg = "No suitable free block found.<br>\n";
657 if ($webvar{alloctype} eq 'rm') {
658 $failmsg .= "We do not have a free routeable block of that size.<br>\n".
659 "You will have to either route a set of smaller netblocks or a single smaller netblock.";
660 } else {
661 if ($webvar{alloctype} =~ /^.[pc]$/) {
662 $failmsg .= "You will have to route another superblock from one of the<br>\n".
663 "master blocks or chose a smaller block size for the pool.";
664 } else {
665 if (!$webvar{pop}) {
666 $page->param(err => 'Please select a POP to route the block from/through.');
667 return;
668 }
669 $failmsg .= "You will have to route another superblock to $webvar{pop}<br>\n".
670 "from one of the master blocks";
671 if ($webvar{reserve}) {
672 $failmsg .= ', choose a smaller blocksize, or uncheck "Reserve space for expansion".';
673 } else {
674 $failmsg .= " or chose a smaller blocksize.";
675 }
676 }
677 }
678
679 # if requesting extra space "reserved for expansion", we need to find a free
680 # block at least double the size of the request.
681 if ($webvar{reserve}) {
682 $webvar{maskbits}--;
683 }
684
685 ($fbid,$cidr,$p_id) = findAllocateFrom($ip_dbh, $webvar{maskbits}, $webvar{alloctype},
686 $webvar{city}, $webvar{pop}, (master => $webvar{allocfrom}, allowpriv => $webvar{allowpriv}) );
687 if (!$cidr) {
688 $page->param(err => $failmsg);
689 return;
690 }
691 $cidr = new NetAddr::IP $cidr;
692
693 $alloc_from = "$cidr";
694
695 # when autofinding a block to allocate from, use the first piece of the found
696 # block for the allocation, and the next piece for the "reserved for expansion".
697 if ($webvar{reserve}) {
698 # reset the mask to the real requested one, now that we've got a
699 # block large enough for the request plus reserve
700 $webvar{maskbits}++;
701 ($cidr,$resv) = $cidr->split($webvar{maskbits});
702 }
703
704 # If the block to be allocated is smaller than the one we found,
705 # figure out the "real" block to be allocated.
706 if ($cidr->masklen() ne $webvar{maskbits}) {
707 my $maskbits = $cidr->masklen();
708 while ($maskbits++ < $webvar{maskbits}) {
709 $cidr = ($cidr->split($maskbits))[0];
710 }
711 }
712 } # check for freeblocks assignment or IPDB-controlled assignment
713
714 # Generate the IP list for the new allocation in case someone wants to set per-IP rDNS right away.
715 # We don't do this on the previous page because we don't know how big a block or even what IP range
716 # it's for (if following the "normal" allocation process)
717 if ($IPDBacl{$authuser} =~ /c/
718 && $cidr->masklen != $cidr->bits
719 && ($cidr->bits - $cidr->masklen) <= $IPDB::maxrevlist
720 # config flag for "all block types" OR "not-a-pool-or-IP type"
721 && ($IPDB::revlistalltypes || $webvar{alloctype} !~ /^.[dpi]/)
722 # safety against trying to retrieve and display more than 1k (10 bits, /22 v4) worth of individual IPs
723 # ever. If you really need to manage a long list of IPs like that all in one place, you can use the DNS
724 # management tool. Even a /26 is a bit much, really.
725 && ($cidr->bits - $cidr->masklen) <= 10
726 # do we want to allow v6 at all?
727 #&& ! $cidr->{isv6}
728 ) {
729 my @list;
730 foreach my $ip (@{$cidr->splitref()}) {
731 my %row;
732 $row{r_ip} = $ip->addr;
733 $row{iphost} = '';
734 push @list, \%row;
735 }
736 $page->param(r_iplist => \@list);
737 # We don't use this here, because these IPs should already be bare.
738 # ... or should we be paranoid? Make it a config option?
739 #getRDNSbyIP($ip_dbh, type => $webvar{alloctype}, range => "$cidr", user => $authuser) );
740 }
741 } # if ($webvar{alloctype} =~ /^.i$/)
742
743## node hack
744 if ($webvar{node} && $webvar{node} ne '-') {
745 my $nodename = getNodeName($ip_dbh, $webvar{node});
746 $page->param(nodename => $nodename);
747 $page->param(nodeid => $webvar{node});
748 }
749## end node hack
750
751 # flag DNS info if we can't publish the entry remotely
752 my $pinfo = getBlockData($ip_dbh, $webvar{parent});
753 $page->param(dnslocal => 1) unless ($pinfo->{revpartial} || $pinfo->{revavail});
754
755 # reserve for expansion
756 $page->param(reserve => $webvar{reserve});
757 # probably just preventing a little log noise doing this; could just set the param
758 # all the time since it won't be shown if the reserve param above isn't set.
759# if ($webvar{reserve}) {
760 $page->param(resvblock => $resv);
761# }
762
763 # Stick in the allocation data
764 $page->param(alloc_type => $webvar{alloctype});
765 $page->param(typefull => $q->escapeHTML($disp_alloctypes{$webvar{alloctype}}));
766 $page->param(alloc_from => $alloc_from);
767 $page->param(parent => $p_id);
768 $page->param(fbid => $fbid);
769 $page->param(cidr => $cidr);
770 $page->param(rdns => $webvar{rdns});
771 $page->param(vrf => $webvar{vrf});
772 $page->param(vlan => $webvar{vlan});
773 $page->param(city => $q->escapeHTML($webvar{city}));
774 $page->param(custid => $webvar{custid});
775 $page->param(circid => $q->escapeHTML($webvar{circid}));
776 $page->param(desc => $q->escapeHTML($webvar{desc}));
777
778##fixme: find a way to have the displayed copy have <br> substitutions
779# for newlines, and the <input> value have either encoded or bare newlines.
780# Also applies to privdata.
781 $page->param(notes => $q->escapeHTML($webvar{notes},'y'));
782
783 # Check to see if user is allowed to do anything with sensitive data
784 if ($IPDBacl{$authuser} =~ /s/) {
785 $page->param(nocling => 1);
786 $page->param(privdata => $q->escapeHTML($webvar{privdata},'y'));
787
788 $page->param(backupfields => $webvar{backupfields});
789 $page->param(bkbrand => $webvar{bkbrand});
790 $page->param(bkmodel => $webvar{bkmodel});
791 $page->param(bktype => $webvar{bktype});
792 $page->param(bksrc => $webvar{bksrc});
793 $page->param(bkuser => $webvar{bkuser});
794 # these two could use virtually any character
795 $page->param(bkvpass => $q->escapeHTML($webvar{bkvpass}));
796 $page->param(bkepass => $q->escapeHTML($webvar{bkepass}));
797 $page->param(bkport => $webvar{bkport});
798 $page->param(bkip => $webvar{bkip});
799 }
800
801 # Yay! This now has it's very own little home.
802 $page->param(billinguser => $webvar{userid})
803 if $webvar{userid};
804
805 syslog "debug", "billinguser used ($authuser): alloc_from $alloc_from, type $webvar{alloctype}" if $webvar{userid};
806
807##fixme: this is only needed iff confirm.tmpl and
808# confirmRemove.tmpl are merged (quite possible, just
809# a little tedious)
810 $page->param(action => "insert");
811
812} # end confirmAssign
813
814
815# Do the work of actually inserting a block in the database.
816sub insertAssign {
817 if ($IPDBacl{$authuser} !~ /a/) {
818 $aclerr = 'addblock';
819 return;
820 }
821 # Some things are done more than once.
822 return if !validateInput();
823
824##fixme: permission check
825 if (!defined($webvar{privdata})) {
826 $webvar{privdata} = '';
827 }
828
829 # $code is "success" vs "failure", $msg contains OK for a
830 # successful netblock allocation, the IP allocated for static
831 # IP, or the error message if an error occurred.
832
833##fixme: consider just passing \%webvar to allocateBlock()?
834 # collect per-IP rDNS fields. only copy over the ones that actually have something in them.
835 my %iprev;
836 foreach (keys %webvar) {
837 $iprev{$_} = $webvar{$_} if /host_[\d.a-fA-F:]+/ && $webvar{$_};
838 }
839
840 # Easier to see and cosmetically fiddle the list like this
841 my %insert_args = (
842 cidr => $webvar{fullcidr},
843 fbid => $webvar{fbid},
844 reserve => $webvar{reserve},
845 parent => $webvar{parent},
846 custid => $webvar{custid},
847 type => $webvar{alloctype},
848 city => $webvar{city},
849 desc => $webvar{desc},
850 notes => $webvar{notes},
851 circid => $webvar{circid},
852 privdata => $webvar{privdata},
853 nodeid => $webvar{node},
854 rdns => $webvar{rdns},
855 vrf => $webvar{vrf},
856 vlan => $webvar{vlan},
857 user => $authuser,
858 );
859
860##fixme: permission check
861 # fill in backup data, if present/allowed
862 if ($webvar{backupfields}) {
863 $insert_args{backup} = 1;
864 for my $bkfield (@IPDB::backupfields) {
865 $insert_args{"bk$bkfield"} = ($webvar{"bk$bkfield"} ? $webvar{"bk$bkfield"} : '');
866 }
867 }
868
869 my $pinfo = getBlockData($ip_dbh, $webvar{parent});
870
871 # clean up a minor mess with guided allocation of static IPs
872 if ($webvar{alloctype} =~ /^.i$/) {
873 $insert_args{alloc_from} = $pinfo->{block};
874 }
875
876 my ($code,$msg) = allocateBlock($ip_dbh, %insert_args, iprev => \%iprev);
877
878 if ($code eq 'OK') {
879 # breadcrumbs lite! provide at least a link to the parent of the block we just allocated.
880 $page->param(parentid => $webvar{parent});
881 $page->param(parentblock => $pinfo->{block});
882
883 if ($webvar{alloctype} =~ /^.i$/) {
884 $msg =~ s|/32||;
885 $page->param(staticip => $msg);
886 $page->param(custid => $webvar{custid});
887 $page->param(billinguser => $webvar{billinguser});
888 $page->param(billinglink => $IPDB::billinglink);
889 mailNotify($ip_dbh, "a$webvar{alloctype}", "ADDED: $disp_alloctypes{$webvar{alloctype}} allocation",
890 "$disp_alloctypes{$webvar{alloctype}} $msg allocated to customer $webvar{custid}\n".
891 "Description: $webvar{desc}\n".
892 ($webvar{rdns} ? "DNS name: $webvar{rdns}\n" : '').
893 "\nAllocated by: $authuser\n");
894 } else {
895 my $netblock = new NetAddr::IP $webvar{fullcidr};
896 $page->param(fullcidr => $webvar{fullcidr});
897 $page->param(alloctype => $disp_alloctypes{$webvar{alloctype}});
898 $page->param(custid => $webvar{custid});
899
900 # Full breadcrumbs
901 my $crumbs = getBreadCrumbs($ip_dbh, $webvar{parent});
902 my @rcrumbs = reverse (@$crumbs);
903 $utilbar->param(breadcrumb => \@rcrumbs);
904
905 if ($webvar{alloctype} eq 'pr' && $webvar{billinguser}) {
906 $page->param(billinguser => $webvar{billinguser});
907 $page->param(billinglink => $IPDB::billinglink);
908 $page->param(custid => $webvar{custid});
909 $page->param(netaddr => $netblock->addr);
910 $page->param(masklen => $netblock->masklen);
911 }
912 syslog "debug", "billinguser used ($authuser): allocated $netblock, type $webvar{alloctype}" if $webvar{billinguser};
913 mailNotify($ip_dbh, "a$webvar{alloctype}", "ADDED: $disp_alloctypes{$webvar{alloctype}} allocation",
914 "$disp_alloctypes{$webvar{alloctype}} $webvar{fullcidr} allocated to customer $webvar{custid}\n".
915 "Description: $webvar{desc}\n".
916 ($webvar{rdns} ? "DNS name/pattern: $webvar{rdns}\n" : '').
917 "\nAllocated by: $authuser\n");
918 }
919 syslog "notice", "$authuser allocated '$webvar{fullcidr}' to '$webvar{custid}' as ".
920 "'$webvar{alloctype}' ($msg)";
921 } else {
922 syslog "err", "Allocation of '$webvar{fullcidr}' to '$webvar{custid}' as ".
923 "'$webvar{alloctype}' by $authuser failed: '$msg'";
924 $page->param(err => "Allocation of $webvar{fullcidr} as '$disp_alloctypes{$webvar{alloctype}}' failed:");
925 $page->param(errmsg => $msg);
926 }
927
928} # end insertAssign()
929
930
931# Does some basic checks on common input data to make sure nothing
932# *really* weird gets in to the database through this script.
933# Does NOT do complete input validation!!!
934sub validateInput {
935 if ($webvar{city} eq '-') {
936 $page->param(err => 'Please choose a city');
937 return;
938 }
939
940 # Alloctype check.
941 chomp $webvar{alloctype};
942 if (!grep /$webvar{alloctype}/, keys %disp_alloctypes) {
943 # Danger! Danger! alloctype should ALWAYS be set by a dropdown. Anyone
944 # managing to call things in such a way as to cause this deserves a cryptic error.
945 $page->param(err => 'Invalid alloctype');
946 return;
947 }
948
949 # CustID check
950 # We have different handling for customer allocations and "internal" or "our" allocations
951 if ($def_custids{$webvar{alloctype}} eq '') {
952 if (!$webvar{custid}) {
953 $page->param(err => 'Please enter a customer ID.');
954 return;
955 }
956 # Crosscheck with billing.
957 my $status = CustIDCK->custid_exist($webvar{custid});
958 if ($CustIDCK::Error) {
959 $page->param(err => "Error verifying customer ID: ".$CustIDCK::ErrMsg);
960 return;
961 }
962 if (!$status) {
963 $page->param(err => "Customer ID not valid. Make sure the Customer ID ".
964 "is correct.<br>\nUse STAFF for staff static IPs, and $IPDB::defcustid for any other ".
965 "non-customer assignments.");
966 return;
967 }
968# print "<!-- [ In validateInput(). Insert customer ID cross-check here. ] -->\n";
969 } else {
970 # New! Improved! And now Loaded From The Database!!
971 if ((!$webvar{custid}) || ($webvar{custid} ne 'STAFF')) {
972 $webvar{custid} = $def_custids{$webvar{alloctype}};
973 }
974 }
975
976## hmmm.... is this even useful?
977if (0) {
978 # Check POP location
979 my $flag;
980 if ($webvar{alloctype} eq 'rm') {
981 $flag = 'for a routed netblock';
982 foreach (@poplist) {
983 if (/^$webvar{city}$/) {
984 $flag = 'n';
985 last;
986 }
987 }
988 } else {
989 $flag = 'n';
990##fixme: hook to force-set POP or city on certain alloctypes
991# if ($webvar{alloctype =~ /foo,bar,bz/ { $webvar{pop} = 'blah'; }
992 if ($webvar{pop} && $webvar{pop} =~ /^-$/) {
993 $flag = 'to route the block from/through';
994 }
995 }
996
997 # if the alloctype has a restricted city/POP list as determined above,
998 # and the reqested city/POP does not match that list, complain
999 if ($flag ne 'n') {
1000 $page->param(err => "Please choose a valid POP location $flag. Valid ".
1001 "POP locations are currently:<br>\n".join (" - ", @poplist));
1002 return;
1003 }
1004}
1005
1006 # VRF. Not a full validity check, just a basic sanity check.
1007 if ($webvar{vrf}) {
1008 # Trim leading and trailing whitespace first
1009 $webvar{vrf} =~ s/^\s+//;
1010 $webvar{vrf} =~ s/\s+$//;
1011 if ($webvar{vrf} !~ /^[\w\d_.-]{1,32}$/) {
1012 $page->param(err => "VRF values may only contain alphanumerics, and may not be more than 32 characters");
1013 return;
1014 }
1015 }
1016
1017 # VLAN. Should we allow/use VLAN names, or just the numeric ID?
1018 if ($webvar{vlan}) {
1019 # Trim leading and trailing whitespace first
1020 $webvar{vlan} =~ s/^\s+//;
1021 $webvar{vlan} =~ s/\s+$//;
1022 # ... ve make it ze configurable thingy!
1023 if ($IPDB::numeric_vlan) {
1024 if ($webvar{vlan} !~ /^\d+$/) {
1025 $page->param(err => "VLANs must be numeric");
1026 return;
1027 }
1028 } else {
1029 if ($webvar{vlan} !~ /^[\w\d_.-]+$/) {
1030 $page->param(err => "VLANs must be alphanumeric");
1031 return;
1032 }
1033 }
1034 }
1035
1036 # Backup fields. Minimal sanity checks.
1037 # Bypass if the user isn't authorized for backup data, or if the checkbox is unchecked
1038 if ($IPDBacl{$authuser} =~ /s/ && defined($webvar{backupfields})) {
1039 for my $bkfield (qw(brand model)) {
1040 if (!$webvar{"bk$bkfield"}) {
1041 $page->param(err => "Backup $bkfield must be filled in if IP/netblock is flagged for backup");
1042 return;
1043 }
1044 if ($webvar{"bk$bkfield"} !~ /^[a-zA-Z0-9\s_.-]+$/) {
1045 $page->param(err => "Invalid characters in backup $bkfield");
1046 return;
1047 }
1048 }
1049 for my $bkfield (qw(type src user)) { # no spaces in these!
1050 if ($webvar{"bk$bkfield"} && $webvar{"bk$bkfield"} !~ /^[a-zA-Z0-9_.-]+$/) {
1051 $page->param(err => "Invalid characters in backup $bkfield");
1052 return;
1053 }
1054 }
1055 if ($webvar{bkport}) {
1056 $webvar{bkport} =~ s/^\s+//g;
1057 $webvar{bkport} =~ s/\s+$//g;
1058 if ($webvar{bkport} !~ /^\d+$/) {
1059 $page->param(err => "Backup port must be numeric");
1060 return;
1061 }
1062 }
1063##fixme: code review: should normalize $webvar{cidr} variants so we can
1064# check for non-/32 allocations having the backup IP field filled in here,
1065# instead of failing on the allocation or update attempt
1066 if ($webvar{bkip}) {
1067 $webvar{bkip} =~ s/^\s+//g;
1068 $webvar{bkip} =~ s/\s+$//g;
1069 if ($webvar{bkip} !~ /^[\da-fA-F:.]+$/) {
1070 $page->param(err => "Backup IP must be an IP");
1071 return;
1072 }
1073 }
1074 } # backup
1075
1076 return 'OK';
1077} # end validateInput
1078
1079
1080# Displays details of a specific allocation in a form
1081# Allows update/delete
1082# action=edit
1083sub edit {
1084
1085 # snag block info from db
1086 my $blockinfo = getBlockData($ip_dbh, $webvar{id}, $webvar{basetype});
1087 my $cidr = new NetAddr::IP $blockinfo->{block};
1088 $page->param(id => $webvar{id});
1089 $page->param(basetype => $webvar{basetype});
1090
1091 # Tree navigation
1092 my $crumbs = getBreadCrumbs($ip_dbh, $blockinfo->{parent_id});
1093 my @rcrumbs = reverse (@$crumbs);
1094 $utilbar->param(breadcrumb => \@rcrumbs);
1095
1096 # Show link to IP list for pools
1097 $page->param(ispool => 1) if $blockinfo->{type} =~ /^.[dp]$/;
1098
1099 # Clean up extra whitespace on alloc type. Mainly a legacy-data cleanup.
1100 $blockinfo->{type} =~ s/\s//;
1101
1102##fixme: The case of "allocation larger than a /24" (or any similar case
1103# where the allocation is larger than the zone(s) in DNS) doesn't work well.
1104# Best solution may just be to add a warning that the entry shown may not be
1105# correct/complete.
1106 if ($blockinfo->{revavail} || $blockinfo->{revpartial}) {
1107 $page->param(showrev => ($blockinfo->{revavail} || $blockinfo->{revpartial}) );
1108 $page->param(v6 => $cidr->{isv6});
1109 $page->param(dnslink => $IPDB::dnsadmin_url);
1110
1111 # get the DNSAdmin zone ID(s) for this allocation.
1112 # Multiple zones should be rare, but are NOT impossible!
1113 my $revlist = getRevID($ip_dbh, user => $authuser, cidr => $blockinfo->{block},
1114 location => $blockinfo->{location});
1115 $page->param(revlist => $revlist) if $revlist;
1116
1117 my $cached;
1118 # Get rDNS info; duplicates a bit of getBlockData but also does the RPC call if possible
1119 ($blockinfo->{rdns},$cached) = getBlockRDNS($ip_dbh, id => $webvar{id}, type => $blockinfo->{type}, user => $authuser);
1120 $page->param(rdns => $blockinfo->{rdns});
1121 # visual flag that we're working IPDB-local, not off more authoritative data in dnsadmin
1122 $page->param(cached => $cached);
1123
1124 # Limit the per-IP rDNS list based on CIDR length; larger ones just take up too much space.
1125 # Also, don't show on IP pools; the individual IPs will have a space for rDNS
1126 # Don't show on single IPs; these use the "pattern" field
1127 if ($IPDBacl{$authuser} =~ /c/
1128 && $cidr->masklen != $cidr->bits
1129 && ($cidr->bits - $cidr->masklen) <= $IPDB::maxrevlist
1130 # config flag for "all block types" OR "not-a-pool-or-IP type"
1131 && ($IPDB::revlistalltypes || $blockinfo->{type} !~ /^.[dpi]/)
1132 # safety against trying to retrieve and display more than 1k (10 bits, /22 v4) worth of individual IPs
1133 # ever. If you really need to manage a long list of IPs like that all in one place, you can use the DNS
1134 # management tool. Even a /26 is a bit much, really.
1135 && ($cidr->bits - $cidr->masklen) <= 10
1136 # do we want to allow v6 at all?
1137 #&& ! $cidr->{isv6}
1138 ) {
1139 $page->param(r_iplist => getRDNSbyIP($ip_dbh, id => $webvar{id}, type => $blockinfo->{type},
1140 range => $blockinfo->{block}, user => $authuser) );
1141 }
1142 } # rDNS availability check
1143
1144 # backup data
1145 if ($blockinfo->{hasbk}) {
1146 $page->param(hasbackup => $blockinfo->{hasbk});
1147 for my $bkfield (@IPDB::backupfields) {
1148 $page->param("bk$bkfield" => $blockinfo->{"bk$bkfield"});
1149 }
1150 $page->param(bktelnet => 1) if $blockinfo->{bktype} eq 'telnet';
1151 $page->param(bkssh => 1) if $blockinfo->{bktype} eq 'SSH';
1152 }
1153
1154 # consider extending this to show time as well as date
1155 my ($lastmod,undef) = split /\s+/, $blockinfo->{lastmod};
1156 $page->param(lastmod => $lastmod);
1157
1158 $page->param(block => $blockinfo->{block});
1159 $page->param(city => $blockinfo->{city});
1160 $page->param(custid => $blockinfo->{custid});
1161
1162##fixme The check here should be built from the database
1163# Need to expand to support pool types too
1164 if ($blockinfo->{type} =~ /^.[ne]$/ && $IPDBacl{$authuser} =~ /c/) {
1165 $page->param(changetype => 1);
1166 $page->param(alloctype => [
1167 { selme => ($blockinfo->{type} eq 'me'), type => "me", disptype => "Dialup netblock" },
1168 { selme => ($blockinfo->{type} eq 'de'), type => "de", disptype => "Dynamic DSL netblock" },
1169 { selme => ($blockinfo->{type} eq 'ce'), type => "ce", disptype => "Dynamic cable netblock" },
1170 { selme => ($blockinfo->{type} eq 'we'), type => "we", disptype => "Dynamic wireless netblock" },
1171 { selme => ($blockinfo->{type} eq 'cn'), type => "cn", disptype => "Customer netblock" },
1172 { selme => ($blockinfo->{type} eq 'en'), type => "en", disptype => "End-use netblock" },
1173 { selme => ($blockinfo->{type} eq 'in'), type => "in", disptype => "Internal netblock" },
1174 ]
1175 );
1176 } else {
1177 $page->param(disptype => $disp_alloctypes{$blockinfo->{type}});
1178 $page->param(type => $blockinfo->{type});
1179 }
1180
1181## node hack
1182 my ($nodeid,$nodename) = getNodeInfo($ip_dbh, $blockinfo->{block});
1183# $page->param(havenodeid => $nodeid);
1184 $page->param(nodename => $nodename);
1185
1186##fixme: this whole hack needs cleanup and generalization for all alloctypes
1187##fixme: arguably a bug that presence of a nodeid implies it can be changed..
1188 if ($IPDBacl{$authuser} =~ /c/) {
1189 my $nlist = getNodeList($ip_dbh);
1190 if ($nodeid) {
1191 foreach (@{$nlist}) {
1192 $$_{selme} = ($$_{node_id} == $nodeid);
1193 }
1194 }
1195 $page->param(nodelist => $nlist);
1196 }
1197## end node hack
1198
1199# $page->param(vrf => $blockinfo->{vrf});
1200 $page->param(vlan => $blockinfo->{vlan});
1201
1202 # Reserved-for-expansion
1203 $page->param(reserve => $blockinfo->{reserve});
1204 $page->param(reserve_id => $blockinfo->{reserve_id});
1205 my $newblock = NetAddr::IP->new($cidr->addr, $cidr->masklen - 1)->network;
1206 $page->param(newblock => $newblock);
1207
1208 # not happy with the upside-down logic, but...
1209 $page->param(swipable => $blockinfo->{type} !~ /.i/);
1210 $page->param(swip => $blockinfo->{swip} ne 'n') if $blockinfo->{swip};
1211
1212 $page->param(circid => $blockinfo->{circuitid});
1213 $page->param(desc => $blockinfo->{description});
1214 $page->param(notes => $blockinfo->{notes});
1215
1216 # Check to see if we can display sensitive data
1217 $page->param(nocling => $IPDBacl{$authuser} =~ /s/);
1218 $page->param(privdata => $blockinfo->{privdata});
1219
1220 # ACL trickery - these two template booleans control the presence of all form/input tags
1221 $page->param(maychange => $IPDBacl{$authuser} =~ /c/);
1222 $page->param(maydel => $IPDBacl{$authuser} =~ /d/);
1223
1224 # Need to find internal knobs to twist to actually vary these. (Ab)use "change" flag for now
1225 $page->param(maymerge => ($IPDBacl{$authuser} =~ /m/ && $blockinfo->{type} !~ /^.i$/));
1226
1227 if ($IPDBacl{$authuser} =~ /c/ && $blockinfo->{type} !~ /^.i$/) {
1228 if ($blockinfo->{type} =~ /^.p$/) {
1229 # PPP pools
1230 $page->param(maysplit => 1) if $cidr->masklen+1 < $cidr->bits;
1231 } elsif ($blockinfo->{type} =~ /.d/) {
1232 # Non-PPP pools
1233 $page->param(maysplit => 1) if $cidr->masklen+2 < $cidr->bits;
1234 } else {
1235 # Standard netblocks. Arguably allowing splitting these down to single IPs
1236 # doesn't make much sense, but forcing users to apply allocation types
1237 # "properly" is worse than herding cats.
1238 $page->param(maysplit => 1) if $cidr->masklen < $cidr->bits;
1239 }
1240 }
1241
1242} # edit()
1243
1244
1245# Stuff new info about a block into the db
1246# action=update
1247sub update {
1248 if ($IPDBacl{$authuser} !~ /c/) {
1249 $aclerr = 'updateblock';
1250 return;
1251 }
1252
1253 # Collect existing block info here, since we need it for the breadcrumb nav
1254 my $binfo = getBlockData($ip_dbh, $webvar{block}, $webvar{basetype});
1255 my $crumbs = getBreadCrumbs($ip_dbh, $binfo->{parent_id});
1256 my @rcrumbs = reverse (@$crumbs);
1257 $utilbar->param(breadcrumb => \@rcrumbs);
1258
1259 # Make sure incoming data is in correct format - custID among other things.
1260 return if !validateInput;
1261
1262 $webvar{swip} = 'n' if !$webvar{swip};
1263
1264 my %updargs = (
1265 custid => $webvar{custid},
1266 city => $webvar{city},
1267 description => $webvar{desc},
1268 notes => $webvar{notes},
1269 circuitid => $webvar{circid},
1270 block => $webvar{block},
1271 type => $webvar{alloctype},
1272 swip => $webvar{swip},
1273 rdns => $webvar{rdns},
1274 vrf => $webvar{vrf},
1275 vlan => $webvar{vlan},
1276 user => $authuser,
1277 );
1278
1279 # Check to see if user is allowed to do anything with sensitive data
1280 if ($IPDBacl{$authuser} =~ /s/) {
1281 $updargs{privdata} = $webvar{privdata};
1282 for my $bkfield (@IPDB::backupfields) {
1283 $updargs{"bk$bkfield"} = $webvar{"bk$bkfield"};
1284 }
1285 $updargs{backup} = $webvar{backupfields};
1286 } else {
1287 # If the user doesn't have permissions to monkey with NOC-things, pass
1288 # a flag so we don't treat it as "backup data removed"
1289 $updargs{ignorebk} = 1;
1290 }
1291
1292 # Semioptional values
1293 $updargs{node} = $webvar{node} if $webvar{node};
1294
1295 # collect per-IP rDNS fields. only copy over the ones that actually have something in them.
1296 my %iprev;
1297 foreach (keys %webvar) {
1298 $iprev{$_} = $webvar{$_} if /host_[\d.a-fA-F:]+/ && $webvar{$_};
1299 }
1300
1301 # and now IPv6
1302##fixme: how to remove an entry? maybe treat empty host as "delete meeeee!"?
1303 if ($webvar{v6list}) {
1304 my @v6lines = split /\n/, $webvar{v6list};
1305 foreach (@v6lines) {
1306 s/^\s+//;
1307 s/\s+$//;
1308 next if /^$/;
1309 my ($ip,$name) = split /,/;
1310 $iprev{"host_$ip"} = $name;
1311 }
1312 }
1313
1314 # Merge with reserved freeblock
1315 $updargs{fbmerge} = $webvar{expandme} if $webvar{expandme};
1316
1317 my ($code,$msg) = updateBlock($ip_dbh, %updargs, iprev => \%iprev);
1318
1319 if ($code eq 'FAIL') {
1320 syslog "err", "$authuser could not update block/IP $webvar{block} ($binfo->{block}): '$msg'";
1321 $page->param(err => "Could not update block/IP $binfo->{block}: $msg");
1322 return;
1323 }
1324
1325 # If we get here, the operation succeeded.
1326 syslog "notice", "$authuser updated $webvar{block} ($binfo->{block})";
1327##fixme: log details of the change? old way is in the .debug stream anyway.
1328##fixme: need to wedge something in to allow "update:field" notifications
1329## hmm. how to tell what changed? O_o
1330mailNotify($ip_dbh, 's:swi', "SWIPed: $disp_alloctypes{$webvar{alloctype}} $binfo->{block}",
1331 "$binfo->{block} had SWIP status changed to \"Yes\" by $authuser") if $webvar{swip} eq 'on';
1332
1333## node hack
1334 if ($webvar{node} && $webvar{node} ne '-') {
1335 my $nodename = getNodeName($ip_dbh, $webvar{node});
1336 $page->param(nodename => $nodename);
1337 }
1338## end node hack
1339
1340 # Link back to browse-routed or list-pool page on "Update complete" page.
1341 my $pblock = getBlockData($ip_dbh, $binfo->{parent_id});
1342 $page->param(backid => $binfo->{parent_id});
1343 $page->param(backblock => $pblock->{block});
1344 $page->param(backpool => ($webvar{basetype} eq 'i'));
1345
1346 # Do some HTML fiddling here instead of using ESCAPE=HTML in the template,
1347 # because otherwise we can't convert \n to <br>. *sigh*
1348 $webvar{notes} = $q->escapeHTML($webvar{notes}); # escape first...
1349 $webvar{notes} =~ s/\n/<br>\n/; # ... then convert newlines
1350 $webvar{privdata} = ($webvar{privdata} ? $q->escapeHTML($webvar{privdata}) : "&nbsp;");
1351 $webvar{privdata} =~ s/\n/<br>\n/;
1352
1353 if ($webvar{expandme}) {
1354 # this is fugly but still faster than hitting the DB again with getBlockData()
1355 my $tmp = new NetAddr::IP $binfo->{block};
1356 my $fb = new NetAddr::IP $binfo->{reserve};
1357 my @newblock = $tmp->compact($fb);
1358 $page->param(cidr => $newblock[0]);
1359 } else {
1360 $page->param(cidr => $binfo->{block});
1361 }
1362 $page->param(rdns => $webvar{rdns});
1363 $page->param(city => $webvar{city});
1364 $page->param(disptype => $disp_alloctypes{$webvar{alloctype}});
1365 $page->param(custid => $webvar{custid});
1366 $page->param(swip => $webvar{swip} eq 'on' ? 'Yes' : 'No');
1367 $page->param(circid => $webvar{circid});
1368 $page->param(desc => $webvar{desc});
1369 $page->param(notes => $webvar{notes});
1370 if ($IPDBacl{$authuser} =~ /s/) {
1371 $page->param(nocling => 1);
1372 $page->param(privdata => $webvar{privdata});
1373 if ($webvar{backupfields} && $webvar{backupfields} eq 'on') {
1374 $page->param(hasbackup => 1);
1375 for my $bkfield (@IPDB::backupfields) {
1376 $page->param("bk$bkfield" => $webvar{"bk$bkfield"});
1377 }
1378 }
1379 }
1380
1381} # update()
1382
1383
1384sub prepSplit {
1385 if ($IPDBacl{$authuser} !~ /c/) {
1386 $aclerr = 'splitblock';
1387 return;
1388 }
1389
1390 my $blockinfo = getBlockData($ip_dbh, $webvar{block});
1391
1392 # Tree navigation
1393 my $crumbs = getBreadCrumbs($ip_dbh, $blockinfo->{parent_id});
1394 my @rcrumbs = reverse (@$crumbs);
1395 $utilbar->param(breadcrumb => \@rcrumbs);
1396
1397 if ($blockinfo->{type} =~ /^.i$/) {
1398 $page->param(err => "Can't split a single IP allocation");
1399 return;
1400 }
1401
1402 # Info about current allocation
1403 $page->param(oldblock => $blockinfo->{block});
1404 $page->param(block => $webvar{block});
1405
1406# Note that there are probably different rules that should be followed to restrict splitting IPv6 blocks;
1407# strictly speaking it will be exceptionally rare to see smaller than a /64 assigned to a customer, since that
1408# breaks auto-addressing schemes.
1409
1410 # Generate possible splits
1411 my $block = new NetAddr::IP $blockinfo->{block};
1412 my $oldmask = $block->masklen;
1413 if ($blockinfo->{type} =~ /^.d$/) {
1414 # Non-PPP pools
1415 $page->param(ispool => 1);
1416 if ($oldmask+2 >= $block->bits) {
1417 $page->param(err => "Can't split a standard netblock pool any further");
1418 return;
1419 }
1420 # Allow splitting down to v4 /30 (which results in one usable IP; dubiously useful)
1421 $page->param(sp4mask => $oldmask+2) if $oldmask+2 <= $block->bits-2;
1422 } elsif ($blockinfo->{type} =~ /.p/) {
1423 $page->param(ispool => 1);
1424 # Allow splitting PPP pools down to v4 /31
1425 $page->param(sp4mask => $oldmask+2) if $oldmask+2 <= $block->bits-1;
1426 } else {
1427 # Allow splitting all other non-pool netblocks down to single IPs, which...
1428 # arguably should be *aggregated* in a pool. Except where they shouldn't.
1429 $page->param(sp4mask => $oldmask+2) if $oldmask+2 <= $block->bits;
1430 }
1431 # set the split-in-half mask
1432 $page->param(sp2mask => $oldmask+1);
1433
1434 # Generate possible shrink targets
1435 my @keepers = $block->split($block->masklen+1);
1436 $page->param(newblockA => $keepers[0]);
1437 $page->param(newblockB => $keepers[1]);
1438} # prepSplit()
1439
1440
1441sub doSplit {
1442 if ($IPDBacl{$authuser} !~ /c/) {
1443 $aclerr = 'splitblock';
1444 return;
1445 }
1446
1447##fixme: need consistent way to identify "this thing that is this thing" with only the ID
1448# also applies to other locations
1449 my $blockinfo = getBlockData($ip_dbh, $webvar{block});
1450
1451 # Tree navigation
1452 my $crumbs = getBreadCrumbs($ip_dbh, $blockinfo->{parent_id});
1453 my @rcrumbs = reverse (@$crumbs);
1454 $utilbar->param(breadcrumb => \@rcrumbs);
1455
1456 if ($blockinfo->{type} =~ /^.i$/) {
1457 $page->param(err => "Can't split a single IP allocation");
1458 return;
1459 }
1460
1461 if ($webvar{subact} eq 'split') {
1462 $page->param(issplit => 1);
1463 my $block = new NetAddr::IP $blockinfo->{block};
1464 my $newblocks = splitBlock($ip_dbh, id => $webvar{block}, basetype => 'b', newmask => $webvar{split},
1465 user => $authuser);
1466 if ($newblocks) {
1467 $page->param(newblocks => $newblocks);
1468 } else {
1469 $page->param(err => $IPDB::errstr);
1470 }
1471
1472 } elsif ($webvar{subact} eq 'shrink') {
1473 $page->param(nid => $webvar{block});
1474 $page->param(newblock => $webvar{shrink});
1475 my $newfree = shrinkBlock($ip_dbh, $webvar{block}, $webvar{shrink});
1476 if ($newfree) {
1477 $page->param(newfb => $newfree);
1478 } else {
1479 $page->param(err => $IPDB::errstr);
1480 }
1481
1482 } else {
1483 # Your llama is on fire.
1484 $page->param(err => "Missing form field that shouldn't be missing.");
1485 return;
1486 }
1487
1488 # common bits
1489 $page->param(cidr => $blockinfo->{block});
1490 # and the backlink to the parent container
1491 my $pinfo = getBlockData($ip_dbh, $blockinfo->{parent_id});
1492 $page->param(backid => $blockinfo->{parent_id});
1493 $page->param(backblock => $pinfo->{block});
1494} # doSplit()
1495
1496
1497# Set up for merge
1498sub prepMerge {
1499 if ($IPDBacl{$authuser} !~ /m/) {
1500 $aclerr = 'mergeblock';
1501 return;
1502 }
1503
1504 my $binfo = getBlockData($ip_dbh, $webvar{block});
1505
1506 # Tree navigation
1507 my $crumbs = getBreadCrumbs($ip_dbh, $binfo->{parent_id});
1508 my @rcrumbs = reverse (@$crumbs);
1509 $utilbar->param(breadcrumb => \@rcrumbs);
1510
1511 $page->param(block => $webvar{block});
1512 $page->param(ispool => $binfo->{type} =~ /.[dp]/);
1513 $page->param(ismaster => $binfo->{type} eq 'mm');
1514 $page->param(oldblock => $binfo->{block});
1515 $page->param(oldtype => $disp_alloctypes{$binfo->{type}});
1516 $page->param(typelist => getTypeList($ip_dbh, 'n', $binfo->{type})); # down the rabbit hole we go...
1517
1518 # Strings for scope; do this way so we don't have to edit them many places
1519 $page->param(vis_keepall => $merge_display{keepall});
1520 $page->param(vis_mergepeer => $merge_display{mergepeer});
1521 $page->param(vis_clearpeer => $merge_display{clearpeer});
1522 $page->param(vis_clearall => $merge_display{clearall});
1523
1524} # prepMerge()
1525
1526
1527# Show what will be merged, present warnings about data loss
1528sub confMerge {
1529 if ($IPDBacl{$authuser} !~ /m/) {
1530 $aclerr = 'mergeblock';
1531 return;
1532 }
1533
1534 if (!$webvar{newmask} || $webvar{newmask} !~ /^\d+$/) {
1535 $page->param(err => 'New netmask required');
1536 return;
1537 }
1538
1539 $page->param(block => $webvar{block});
1540 my $binfo = getBlockData($ip_dbh, $webvar{block});
1541 my $pinfo = getBlockData($ip_dbh, $binfo->{parent_id});
1542 my $minfo = getBlockData($ip_dbh, $binfo->{master_id});
1543 my $block = new NetAddr::IP $binfo->{block};
1544
1545 # Tree navigation
1546 my $crumbs = getBreadCrumbs($ip_dbh, $binfo->{parent_id});
1547 my @rcrumbs = reverse (@$crumbs);
1548 $utilbar->param(breadcrumb => \@rcrumbs);
1549
1550 $page->param(oldblock => $binfo->{block});
1551 $page->param(oldtype => $disp_alloctypes{$binfo->{type}});
1552 $page->param(ismaster => $binfo->{type} eq 'mm');
1553 $page->param(ispool => $webvar{alloctype} =~ /.[dp]/);
1554 $page->param(isleaf => $webvar{alloctype} =~ /.[enr]/);
1555 $page->param(newtype => $webvar{alloctype});
1556 $page->param(newdisptype => $disp_alloctypes{$webvar{alloctype}});
1557 my $newblock = new NetAddr::IP $block->addr."/$webvar{newmask}";
1558 $newblock = $newblock->network;
1559 $page->param(newmask => $webvar{newmask});
1560 $page->param(newblock => "$newblock");
1561
1562 # get list of allocations and freeblocks to be merged
1563 my $malloc_list = listForMerge($ip_dbh, $binfo->{parent_id}, $newblock, 'a');
1564 $page->param(mergealloc => $malloc_list);
1565
1566 $page->param(vis_scope => $merge_display{$webvar{scope}});
1567 $page->param(scope => $webvar{scope});
1568} # confMerge()
1569
1570
1571# Make it so
1572sub doMerge {
1573 if ($IPDBacl{$authuser} !~ /m/) {
1574 $aclerr = 'mergeblock';
1575 return;
1576 }
1577
1578 if (!$webvar{newmask} || $webvar{newmask} !~ /^\d+$/) {
1579 $page->param(err => 'New netmask required');
1580 return;
1581 }
1582
1583 $page->param(block => $webvar{block});
1584 my $binfo = getBlockData($ip_dbh, $webvar{block});
1585 my $pinfo = getBlockData($ip_dbh, $binfo->{parent_id});
1586 my $block = new NetAddr::IP $binfo->{block};
1587
1588 # Tree navigation
1589 my $crumbs = getBreadCrumbs($ip_dbh, $binfo->{parent_id});
1590 my @rcrumbs = reverse (@$crumbs);
1591 $utilbar->param(breadcrumb => \@rcrumbs);
1592
1593 $page->param(oldblock => $binfo->{block});
1594 $page->param(oldtype => $disp_alloctypes{$binfo->{type}});
1595 $page->param(newdisptype => $disp_alloctypes{$webvar{newtype}});
1596 my $newblock = new NetAddr::IP $block->addr."/$webvar{newmask}";
1597 $newblock = $newblock->network;
1598 $page->param(newblock => $newblock);
1599 $page->param(vis_scope => $merge_display{$webvar{scope}});
1600
1601 my $mlist = mergeBlocks($ip_dbh, $webvar{block}, %webvar, user => $authuser);
1602
1603 if ($mlist) {
1604 #(newtype => $webvar{newtype}, newmask => $webvar{newmask}));
1605 # Slice off first entry (the new parent - note this may be a new allocation,
1606 # not the same ID that was "merged"!
1607 my $parent = shift @$mlist;
1608 $page->param(backpool => $webvar{newtype} =~ /.[dp]/);
1609 if ($webvar{newtype} =~ /.[enr]/) {
1610 $page->param(backleaf => 1);
1611 $page->param(backid => $binfo->{parent_id});
1612 $page->param(backblock => $pinfo->{block});
1613 } else {
1614 $page->param(backid => $parent->{id});
1615 $page->param(backblock => $parent->{block});
1616 }
1617 $page->param(mergelist => $mlist);
1618 } else {
1619 $page->param(err => "Merge failed: $IPDB::errstr");
1620 }
1621} # doMerge()
1622
1623
1624# Delete an allocation.
1625sub remove {
1626 if ($IPDBacl{$authuser} !~ /d/) {
1627 $aclerr = 'delblock';
1628 return;
1629 }
1630
1631 # Serves'em right for getting here...
1632 if (!defined($webvar{block})) {
1633 $page->param(err => "Can't delete a block that doesn't exist");
1634 return;
1635 }
1636
1637 my $blockdata;
1638 $blockdata = getBlockData($ip_dbh, $webvar{block}, $webvar{basetype});
1639
1640 # Tree navigation
1641 my $crumbs = getBreadCrumbs($ip_dbh, $blockdata->{parent_id});
1642 my @rcrumbs = reverse (@$crumbs);
1643 $utilbar->param(breadcrumb => \@rcrumbs);
1644
1645 if ($blockdata->{parent_id} == 0) { # $webvar{alloctype} eq 'mm'
1646 $blockdata->{city} = "N/A";
1647 $blockdata->{custid} = "N/A";
1648 $blockdata->{circuitid} = "N/A";
1649 $blockdata->{description} = "N/A";
1650 $blockdata->{notes} = "N/A";
1651 $blockdata->{privdata} = "N/A";
1652 } # end cases for different alloctypes
1653
1654 $page->param(blockid => $webvar{block});
1655 $page->param(basetype => $webvar{basetype});
1656
1657 $page->param(block => $blockdata->{block});
1658 $page->param(rdns => $blockdata->{rdns});
1659
1660 # maybe need to apply more magic here?
1661 # most allocations we *do* want to autodelete the forward as well as reverse; for a handful we don't.
1662 # -> all real blocks (nb: pool IPs need extra handling)
1663 # -> NOC/private-IP (how to ID?)
1664 # -> anything with a pattern matching $IPDB::domain?
1665 if ($blockdata->{type} !~ /^.i$/) {
1666 $page->param(autodel => 1);
1667 }
1668
1669 $page->param(disptype => $disp_alloctypes{$blockdata->{type}});
1670 $page->param(city => $blockdata->{city});
1671 $page->param(custid => $blockdata->{custid});
1672 $page->param(circid => $blockdata->{circuitid});
1673 $page->param(desc => $blockdata->{description});
1674 $blockdata->{notes} = $q->escapeHTML($blockdata->{notes});
1675 $blockdata->{notes} =~ s/\n/<br>\n/;
1676 $page->param(notes => $blockdata->{notes});
1677 $blockdata->{privdata} = $q->escapeHTML($blockdata->{privdata});
1678 $blockdata->{privdata} = '&nbsp;' if !$blockdata->{privdata};
1679 $blockdata->{privdata} =~ s/\n/<br>\n/;
1680 $page->param(privdata => $blockdata->{privdata}) if $IPDBacl{$authuser} =~ /s/;
1681 $page->param(delpool => $blockdata->{type} =~ /^.[pd]$/);
1682
1683} # end remove()
1684
1685
1686# Delete an allocation. Return it to the freeblocks table; munge
1687# data as necessary to keep as few records as possible in freeblocks
1688# to prevent weirdness when allocating blocks later.
1689# Remove IPs from pool listing if necessary
1690sub finalDelete {
1691 if ($IPDBacl{$authuser} !~ /d/) {
1692 $aclerr = 'delblock';
1693 return;
1694 }
1695
1696 # need to retrieve block data before deleting so we can notify on that
1697 my $blockinfo = getBlockData($ip_dbh, $webvar{block}, $webvar{basetype});
1698 my $pinfo = getBlockData($ip_dbh, $blockinfo->{parent_id}, 'b');
1699
1700 # Tree navigation
1701 my $crumbs = getBreadCrumbs($ip_dbh, $blockinfo->{parent_id});
1702 my @rcrumbs = reverse (@$crumbs);
1703 $utilbar->param(breadcrumb => \@rcrumbs);
1704
1705 my ($code,$msg) = deleteBlock($ip_dbh, $webvar{block}, $webvar{basetype}, $webvar{delforward}, $authuser);
1706
1707 $page->param(block => $blockinfo->{block});
1708 $page->param(bdisp => $q->escapeHTML($disp_alloctypes{$blockinfo->{type}}));
1709 $page->param(delparent_id => $blockinfo->{parent_id});
1710 if ($pinfo) {
1711 $page->param(delparent => $pinfo->{block});
1712 $page->param(pdisp => $q->escapeHTML($disp_alloctypes{$pinfo->{type}}));
1713 }
1714 $page->param(returnpool => ($webvar{basetype} eq 'i') );
1715 if ($code =~ /^WARN(POOL|MERGE)/) {
1716 my ($pid,$pcidr) = split /,/, $msg;
1717 my $real_pinfo = getBlockData($ip_dbh, $pid, 'b');
1718 $page->param(parent_id => $pid);
1719 $page->param(parent => $pcidr);
1720 $page->param(real_disp => $q->escapeHTML($disp_alloctypes{$real_pinfo->{type}}));
1721 $page->param(mergeip => $code eq 'WARNPOOL');
1722 }
1723 if ($code eq 'WARN') {
1724 $msg =~ s/\n/<br>\n/g;
1725 $page->param(genwarn => $msg);
1726 }
1727 if ($code eq 'OK' || $code =~ /^WARN/) {
1728 syslog "notice", "$authuser deallocated '".$blockinfo->{type}."'-type netblock ID $webvar{block} ".
1729 "($blockinfo->{block}), $blockinfo->{custid}, $blockinfo->{city}, desc='$blockinfo->{description}'";
1730 mailNotify($ip_dbh, 'da', "REMOVED: $disp_alloctypes{$blockinfo->{type}} $blockinfo->{block}",
1731# $webvar{block} useful? do we care about the block ID here?
1732 "$disp_alloctypes{$blockinfo->{type}} $blockinfo->{block} deallocated by $authuser\n".
1733 "CustID: $blockinfo->{custid}\nCity: $blockinfo->{city}\n".
1734 "Description: $blockinfo->{description}\n");
1735 } else {
1736 $page->param(failmsg => $msg);
1737 if ($webvar{alloctype} =~ /^.i$/) {
1738 syslog "err", "$authuser could not deallocate static IP $webvar{block} ($blockinfo->{block}): '$msg'";
1739 } else {
1740 syslog "err", "$authuser could not deallocate netblock $webvar{block} ($blockinfo->{block}): '$msg'";
1741 $page->param(netblock => 1);
1742 }
1743 }
1744
1745} # finalDelete
Note: See TracBrowser for help on using the repository browser.