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

Last change on this file since 906 was 906, checked in by Kris Deugau, 7 years ago

/trunk

Bulk addition of "add 'the directory the script is in' to @INC" for Perls
that have dropped '.' from @INC

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