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

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

/trunk

Add IP count and percent-free to the heading and showsubs layout 2 by request

  • Property svn:executable set to *
  • Property svn:keywords set to Date Rev Author
File size: 60.2 KB
Line 
1#!/usr/bin/perl
2# ipdb/cgi-bin/main.cgi
3###
4# SVN revision info
5# $Date: 2017-11-02 20:24:13 +0000 (Thu, 02 Nov 2017) $
6# SVN revision $Rev: 913 $
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 $page->param(blockpctfree => sprintf("%0.1f", $pinfo->{nfree}/2**(32-$pinfo->{masklen}) * 100 ) );
433
434##fixme: do we add a wrapper to not show the edit link for master blocks?
435#$page->param(editme => 1) unless $pinfo->{type} ne 'mm';
436
437 my $crumbs = getBreadCrumbs($ip_dbh, $pinfo->{parent_id}, $pinfo->{vrf});
438 my @rcrumbs = reverse (@$crumbs);
439 $utilbar->param(breadcrumb => \@rcrumbs);
440
441 $page->param(self_id => $webvar{parent});
442 $page->param(block => $pinfo->{block});
443 $page->param(mayadd => ($IPDBacl{$authuser} =~ /a/));
444
445 my $flist = listFree($ip_dbh, parent => $webvar{parent});
446 $page->param(freelist => $flist);
447} # showSubs
448
449
450# List the IPs used in a pool
451sub showPool {
452
453 my $poolinfo = getBlockData($ip_dbh, $webvar{pool});
454 my $cidr = new NetAddr::IP $poolinfo->{block};
455 $page->param(vlan => $poolinfo->{vlan});
456 $page->param(poolpctfree => sprintf("%0.1f", $poolinfo->{nfree}/2**(32-$poolinfo->{masklen}) * 100 ) );
457
458 # Tree navigation
459 my $crumbs = getBreadCrumbs($ip_dbh, $poolinfo->{parent_id});
460 my @rcrumbs = reverse (@$crumbs);
461 $utilbar->param(breadcrumb => \@rcrumbs);
462
463 $page->param(block => $cidr);
464 $page->param(netip => $cidr->addr);
465 $cidr++;
466 $page->param(gate => $cidr->addr);
467 $cidr--; $cidr--;
468 $page->param(bcast => $cidr->addr);
469 $page->param(mask => $cidr->mask);
470
471 $page->param(disptype => $disp_alloctypes{$poolinfo->{type}});
472 $page->param(city => $poolinfo->{city});
473
474 # Only display net/gw/bcast if it's a "real" netblock and not a PPP(oE) lunacy
475 $page->param(realblock => $poolinfo->{type} =~ /^.d$/);
476
477# probably have to add an "edit IP allocation" link here somewhere.
478
479 # this will cascade into the IP list below
480 $page->param(maydel => $IPDBacl{$authuser} =~ /d/);
481
482 my $plist = listPool($ip_dbh, $webvar{pool}, 1);
483 $page->param(poolips => $plist);
484} # end showPool
485
486
487# Show "Add new allocation" page. Note that the actual page may
488# be one of two templates, and the lists come from the database.
489sub assignBlock {
490
491 if ($IPDBacl{$authuser} !~ /a/) {
492 $aclerr = 'addblock';
493 return;
494 }
495
496 # hack pthbttt eww
497 $webvar{parent} = 0 if !$webvar{parent};
498 $webvar{block} = '' if !$webvar{block};
499
500 $page->param(allocfrom => $webvar{block}); # fb-assign flag, if block is set, we're in fb-assign
501
502 if ($webvar{fbid} || $webvar{fbtype}) {
503
504 # Common case, according to reported usage. Block to assign is specified.
505 my $block = new NetAddr::IP $webvar{block};
506
507 my ($rdns,$cached) = getBlockRDNS($ip_dbh, id => $webvar{parent}, type => $webvar{fbtype}, user => $authuser);
508 $page->param(rdns => $rdns) if $rdns;
509 $page->param(parent => $webvar{parent});
510 $page->param(fbid => $webvar{fbid});
511 # visual flag that we're working IPDB-local, not off more authoritative data in dnsadmin
512 $page->param(cached => $cached);
513
514 my $pinfo = getBlockData($ip_dbh, $webvar{parent});
515
516 my @cities;
517 foreach my $city (@citylist) {
518 my %row = (city => $city, sel => ($pinfo->{city} eq $city) );
519 push (@cities, \%row);
520 }
521 $page->param(preselected => 1);
522 $page->param(citylist => \@cities);
523
524 # Tree navigation
525 my $crumbs = getBreadCrumbs($ip_dbh, $webvar{parent});
526 my @rcrumbs = reverse (@$crumbs);
527 $utilbar->param(breadcrumb => \@rcrumbs);
528
529 $webvar{fbtype} = '' if !$webvar{fbtype};
530 if ($webvar{fbtype} eq 'i') {
531 my $ipinfo = getBlockData($ip_dbh, $webvar{block}, 'i');
532 $page->param(
533 fbip => 1,
534 block => $ipinfo->{block},
535 fbdisptype => $list_alloctypes{$ipinfo->{type}},
536 type => $ipinfo->{type},
537 allocfrom => $pinfo->{block},
538 );
539 } else {
540 # get "primary" alloctypes, since these are all that can correctly be assigned if we're in this branch
541 my $tlist = getTypeList($ip_dbh, 'n');
542 $tlist->[0]->{sel} = 1;
543 $page->param(typelist => $tlist, block => $block);
544 }
545
546 } else {
547
548 # Uncommon case, according to reported usage. Block to assign needs to be found based on criteria.
549 my $mlist = getMasterList($ip_dbh, 'c');
550 $page->param(masterlist => $mlist);
551
552 my @pops;
553 foreach my $pop (@citylist) {
554 my %row = (pop => $pop);
555 push (@pops, \%row);
556 }
557 $page->param(pops => \@pops);
558
559 my @cities;
560 foreach my $city (@citylist) {
561 my %row = (city => $city);
562 push (@cities, \%row);
563 }
564 $page->param(citylist => \@cities);
565
566 # get all standard alloctypes
567 my $tlist = getTypeList($ip_dbh, 'a');
568 $tlist->[0]->{sel} = 1;
569 $page->param(typelist => $tlist);
570 }
571
572## node hack
573 my $nlist = getNodeList($ip_dbh);
574 $page->param(nodelist => $nlist);
575## end node hack
576
577 $page->param(nocling => $IPDBacl{$authuser} =~ /s/);
578
579} # assignBlock
580
581
582# Take info on requested IP assignment and see what we can provide.
583sub confirmAssign {
584 if ($IPDBacl{$authuser} !~ /a/) {
585 $aclerr = 'addblock';
586 return;
587 }
588
589 my $cidr;
590 my $resv; # Reserved for expansion.
591 my $alloc_from;
592 my $fbid = $webvar{fbid};
593 my $p_id = $webvar{parent};
594
595 # Going to manually validate some items.
596 # custid and city are automagic.
597 return if !validateInput();
598
599 # make sure this is defined
600 $webvar{fbassign} = 'n' if !$webvar{fbassign};
601
602# Several different cases here.
603# Static IP vs netblock
604# + Different flavours of static IP
605# + Different flavours of netblock
606
607 if ($webvar{alloctype} =~ /^.i$/ && $webvar{fbassign} ne 'y') {
608 if (!$webvar{pop}) {
609 $page->param(err => "Please select a location/POP site to allocate from.");
610 return;
611 }
612 my $plist = getPoolSelect($ip_dbh, $webvar{alloctype}, $webvar{pop});
613 $page->param(staticip => 1);
614 $page->param(poollist => $plist) if $plist;
615 $cidr = "Single static IP";
616##fixme: need to handle "no available pools"
617
618 } else { # end show pool options
619
620 if ($webvar{fbassign} && $webvar{fbassign} eq 'y') {
621
622 # Tree navigation
623 my $crumbs = getBreadCrumbs($ip_dbh, $webvar{parent});
624 my @rcrumbs = reverse (@$crumbs);
625 $utilbar->param(breadcrumb => \@rcrumbs);
626
627 $cidr = new NetAddr::IP $webvar{block};
628 $alloc_from = new NetAddr::IP $webvar{allocfrom};
629 $webvar{maskbits} = $cidr->masklen;
630 # Some additional checks are needed for reserving free space
631 if ($webvar{reserve}) {
632 if ($cidr == $alloc_from) {
633# We could still squirm and fiddle to try to find a way to reserve space, but the storage model for
634# IPDB means that all continguous free space is kept in the smallest number of strict CIDR netblocks
635# possible. (In theory.) If the request and the freeblock are the same, it is theoretically impossible
636# to reserve an equivalent-sized block either ahead or behind the requested one, because the pair
637# together would never be a strict CIDR block.
638 $page->param(warning => "Can't reserve space for expansion; free block and requested allocation are the same.");
639 delete $webvar{reserve};
640 } else {
641 # Find which new free block will match the reqested block.
642 # Take the requested mask, shift by one
643 my $tmpmask = $webvar{maskbits};
644 $tmpmask--;
645 # find the subnets with that mask in the selected free block
646 my @pieces = $alloc_from->split($tmpmask);
647 foreach my $slice (@pieces) {
648 if ($slice->contains($cidr)) {
649 # For the subnet that contains the requested block, split that in two,
650 # and flag/cache the one that's not the requested block.
651 my @bits = $slice->split($webvar{maskbits});
652 if ($bits[0] == $cidr) {
653 $resv = $bits[1];
654 } else {
655 $resv = $bits[0];
656 }
657 }
658 }
659 }
660 } # reserve block check
661
662 } else { # done with direct freeblocks assignment
663
664 if (!$webvar{maskbits}) {
665 $page->param(err => "Please specify a CIDR mask length.");
666 return;
667 }
668
669##fixme ick, ew, bleh. gotta handle the failure message generation better. push it into findAllocateFrom()?
670 my $failmsg = "No suitable free block found.<br>\n";
671 if ($webvar{alloctype} eq 'rm') {
672 $failmsg .= "We do not have a free routeable block of that size.<br>\n".
673 "You will have to either route a set of smaller netblocks or a single smaller netblock.";
674 } else {
675 if ($webvar{alloctype} =~ /^.[pc]$/) {
676 $failmsg .= "You will have to route another superblock from one of the<br>\n".
677 "master blocks or chose a smaller block size for the pool.";
678 } else {
679 if (!$webvar{pop}) {
680 $page->param(err => 'Please select a POP to route the block from/through.');
681 return;
682 }
683 $failmsg .= "You will have to route another superblock to $webvar{pop}<br>\n".
684 "from one of the master blocks";
685 if ($webvar{reserve}) {
686 $failmsg .= ', choose a smaller blocksize, or uncheck "Reserve space for expansion".';
687 } else {
688 $failmsg .= " or chose a smaller blocksize.";
689 }
690 }
691 }
692
693 # if requesting extra space "reserved for expansion", we need to find a free
694 # block at least double the size of the request.
695 if ($webvar{reserve}) {
696 $webvar{maskbits}--;
697 }
698
699 ($fbid,$cidr,$p_id) = findAllocateFrom($ip_dbh, $webvar{maskbits}, $webvar{alloctype},
700 $webvar{city}, $webvar{pop}, (master => $webvar{allocfrom}, allowpriv => $webvar{allowpriv}) );
701 if (!$cidr) {
702 $page->param(err => $failmsg);
703 return;
704 }
705 $cidr = new NetAddr::IP $cidr;
706
707 $alloc_from = "$cidr";
708
709 # when autofinding a block to allocate from, use the first piece of the found
710 # block for the allocation, and the next piece for the "reserved for expansion".
711 if ($webvar{reserve}) {
712 # reset the mask to the real requested one, now that we've got a
713 # block large enough for the request plus reserve
714 $webvar{maskbits}++;
715 ($cidr,$resv) = $cidr->split($webvar{maskbits});
716 }
717
718 # If the block to be allocated is smaller than the one we found,
719 # figure out the "real" block to be allocated.
720 if ($cidr->masklen() ne $webvar{maskbits}) {
721 my $maskbits = $cidr->masklen();
722 # we reset $cidr each time around the loop to better allow for the huge
723 # address space of IPv6; many allocation schemes in v6 will break NetAddr::IP's
724 # hard limit of 65536 subnets from a split()
725 while ($maskbits++ < $webvar{maskbits}) {
726 $cidr = ($cidr->split($maskbits))[0];
727 }
728 }
729 } # check for freeblocks assignment or IPDB-controlled assignment
730
731 # Generate the IP list for the new allocation in case someone wants to set per-IP rDNS right away.
732 # We don't do this on the previous page because we don't know how big a block or even what IP range
733 # it's for (if following the "normal" allocation process)
734 if ($IPDBacl{$authuser} =~ /c/
735 && $cidr->masklen != $cidr->bits
736 && ($cidr->bits - $cidr->masklen) <= $IPDB::maxrevlist
737 # config flag for "all block types" OR "not-a-pool-or-IP type"
738 && ($IPDB::revlistalltypes || $webvar{alloctype} !~ /^.[dpi]/)
739 # safety against trying to retrieve and display more than 1k (10 bits, /22 v4) worth of individual IPs
740 # ever. If you really need to manage a long list of IPs like that all in one place, you can use the DNS
741 # management tool. Even a /26 is a bit much, really.
742 && ($cidr->bits - $cidr->masklen) <= 10
743 # do we want to allow v6 at all?
744 #&& ! $cidr->{isv6}
745 ) {
746 my @list;
747 foreach my $ip (@{$cidr->splitref()}) {
748 my %row;
749 $row{r_ip} = $ip->addr;
750 $row{iphost} = '';
751 push @list, \%row;
752 }
753 $page->param(r_iplist => \@list);
754 # We don't use this here, because these IPs should already be bare.
755 # ... or should we be paranoid? Make it a config option?
756 #getRDNSbyIP($ip_dbh, type => $webvar{alloctype}, range => "$cidr", user => $authuser) );
757 }
758 } # if ($webvar{alloctype} =~ /^.i$/)
759
760## node hack
761 if ($webvar{node} && $webvar{node} ne '-') {
762 my $nodename = getNodeName($ip_dbh, $webvar{node});
763 $page->param(nodename => $nodename);
764 $page->param(nodeid => $webvar{node});
765 }
766## end node hack
767
768 # flag DNS info if we can't publish the entry remotely
769 my $pinfo = getBlockData($ip_dbh, $webvar{parent});
770 $page->param(dnslocal => 1) unless ($pinfo->{revpartial} || $pinfo->{revavail});
771
772 # reserve for expansion
773 $page->param(reserve => $webvar{reserve});
774 # probably just preventing a little log noise doing this; could just set the param
775 # all the time since it won't be shown if the reserve param above isn't set.
776# if ($webvar{reserve}) {
777 $page->param(resvblock => $resv);
778# }
779
780 # Stick in the allocation data
781 $page->param(alloc_type => $webvar{alloctype});
782 $page->param(typefull => $q->escapeHTML($disp_alloctypes{$webvar{alloctype}}));
783 $page->param(alloc_from => $alloc_from);
784 $page->param(parent => $p_id);
785 $page->param(fbid => $fbid);
786 $page->param(cidr => $cidr);
787 $page->param(rdns => $webvar{rdns});
788 $page->param(vrf => $webvar{vrf});
789 $page->param(vlan => $webvar{vlan});
790 $page->param(city => $q->escapeHTML($webvar{city}));
791 $page->param(custid => $webvar{custid});
792 $page->param(circid => $q->escapeHTML($webvar{circid}));
793 $page->param(desc => $q->escapeHTML($webvar{desc}));
794
795##fixme: find a way to have the displayed copy have <br> substitutions
796# for newlines, and the <input> value have either encoded or bare newlines.
797# Also applies to privdata.
798 $page->param(notes => $q->escapeHTML($webvar{notes},'y'));
799
800 # Check to see if user is allowed to do anything with sensitive data
801 if ($IPDBacl{$authuser} =~ /s/) {
802 $page->param(nocling => 1);
803 $page->param(privdata => $q->escapeHTML($webvar{privdata},'y'));
804
805 $page->param(backupfields => $webvar{backupfields});
806 $page->param(bkbrand => $webvar{bkbrand});
807 $page->param(bkmodel => $webvar{bkmodel});
808 $page->param(bktype => $webvar{bktype});
809 $page->param(bksrc => $webvar{bksrc});
810 $page->param(bkuser => $webvar{bkuser});
811 # these two could use virtually any character
812 $page->param(bkvpass => $q->escapeHTML($webvar{bkvpass}));
813 $page->param(bkepass => $q->escapeHTML($webvar{bkepass}));
814 $page->param(bkport => $webvar{bkport});
815 $page->param(bkip => $webvar{bkip});
816 }
817
818 # Yay! This now has it's very own little home.
819 $page->param(billinguser => $webvar{userid})
820 if $webvar{userid};
821
822 syslog "debug", "billinguser used ($authuser): alloc_from $alloc_from, type $webvar{alloctype}" if $webvar{userid};
823
824##fixme: this is only needed iff confirm.tmpl and
825# confirmRemove.tmpl are merged (quite possible, just
826# a little tedious)
827 $page->param(action => "insert");
828
829} # end confirmAssign
830
831
832# Do the work of actually inserting a block in the database.
833sub insertAssign {
834 if ($IPDBacl{$authuser} !~ /a/) {
835 $aclerr = 'addblock';
836 return;
837 }
838 # Some things are done more than once.
839 return if !validateInput();
840
841##fixme: permission check
842 if (!defined($webvar{privdata})) {
843 $webvar{privdata} = '';
844 }
845
846 # $code is "success" vs "failure", $msg contains OK for a
847 # successful netblock allocation, the IP allocated for static
848 # IP, or the error message if an error occurred.
849
850##fixme: consider just passing \%webvar to allocateBlock()?
851 # collect per-IP rDNS fields. only copy over the ones that actually have something in them.
852 my %iprev;
853 foreach (keys %webvar) {
854 $iprev{$_} = $webvar{$_} if /host_[\d.a-fA-F:]+/ && $webvar{$_};
855 }
856
857 # Easier to see and cosmetically fiddle the list like this
858 my %insert_args = (
859 cidr => $webvar{fullcidr},
860 fbid => $webvar{fbid},
861 reserve => $webvar{reserve},
862 parent => $webvar{parent},
863 custid => $webvar{custid},
864 type => $webvar{alloctype},
865 city => $webvar{city},
866 desc => $webvar{desc},
867 notes => $webvar{notes},
868 circid => $webvar{circid},
869 privdata => $webvar{privdata},
870 nodeid => $webvar{node},
871 rdns => $webvar{rdns},
872 vrf => $webvar{vrf},
873 vlan => $webvar{vlan},
874 user => $authuser,
875 );
876
877##fixme: permission check
878 # fill in backup data, if present/allowed
879 if ($webvar{backupfields}) {
880 $insert_args{backup} = 1;
881 for my $bkfield (@IPDB::backupfields) {
882 $insert_args{"bk$bkfield"} = ($webvar{"bk$bkfield"} ? $webvar{"bk$bkfield"} : '');
883 }
884 }
885
886 my $pinfo = getBlockData($ip_dbh, $webvar{parent});
887
888 # clean up a minor mess with guided allocation of static IPs
889 if ($webvar{alloctype} =~ /^.i$/) {
890 $insert_args{alloc_from} = $pinfo->{block};
891 }
892
893 my ($code,$msg) = allocateBlock($ip_dbh, %insert_args, iprev => \%iprev);
894
895 if ($code eq 'OK') {
896 # breadcrumbs lite! provide at least a link to the parent of the block we just allocated.
897 $page->param(parentid => $webvar{parent});
898 $page->param(parentblock => $pinfo->{block});
899
900 if ($webvar{alloctype} =~ /^.i$/) {
901 $msg =~ s|/32||;
902 $page->param(staticip => $msg);
903 $page->param(custid => $webvar{custid});
904 $page->param(billinguser => $webvar{billinguser});
905 $page->param(billinglink => $IPDB::billinglink);
906 mailNotify($ip_dbh, "a$webvar{alloctype}", "ADDED: $disp_alloctypes{$webvar{alloctype}} allocation",
907 "$disp_alloctypes{$webvar{alloctype}} $msg allocated to customer $webvar{custid}\n".
908 "Description: $webvar{desc}\n".
909 ($webvar{rdns} ? "DNS name: $webvar{rdns}\n" : '').
910 "\nAllocated by: $authuser\n");
911 } else {
912 my $netblock = new NetAddr::IP $webvar{fullcidr};
913 $page->param(fullcidr => $webvar{fullcidr});
914 $page->param(alloctype => $disp_alloctypes{$webvar{alloctype}});
915 $page->param(custid => $webvar{custid});
916
917 # Full breadcrumbs
918 my $crumbs = getBreadCrumbs($ip_dbh, $webvar{parent});
919 my @rcrumbs = reverse (@$crumbs);
920 $utilbar->param(breadcrumb => \@rcrumbs);
921
922 if ($webvar{alloctype} eq 'pr' && $webvar{billinguser}) {
923 $page->param(billinguser => $webvar{billinguser});
924 $page->param(billinglink => $IPDB::billinglink);
925 $page->param(custid => $webvar{custid});
926 $page->param(netaddr => $netblock->addr);
927 $page->param(masklen => $netblock->masklen);
928 }
929 syslog "debug", "billinguser used ($authuser): allocated $netblock, type $webvar{alloctype}" if $webvar{billinguser};
930 mailNotify($ip_dbh, "a$webvar{alloctype}", "ADDED: $disp_alloctypes{$webvar{alloctype}} allocation",
931 "$disp_alloctypes{$webvar{alloctype}} $webvar{fullcidr} allocated to customer $webvar{custid}\n".
932 "Description: $webvar{desc}\n".
933 ($webvar{rdns} ? "DNS name/pattern: $webvar{rdns}\n" : '').
934 "\nAllocated by: $authuser\n");
935 }
936 syslog "notice", "$authuser allocated '$webvar{fullcidr}' to '$webvar{custid}' as ".
937 "'$webvar{alloctype}' ($msg)";
938 } else {
939 syslog "err", "Allocation of '$webvar{fullcidr}' to '$webvar{custid}' as ".
940 "'$webvar{alloctype}' by $authuser failed: '$msg'";
941 $page->param(err => "Allocation of $webvar{fullcidr} as '$disp_alloctypes{$webvar{alloctype}}' failed:");
942 $page->param(errmsg => $msg);
943 }
944
945} # end insertAssign()
946
947
948# Does some basic checks on common input data to make sure nothing
949# *really* weird gets in to the database through this script.
950# Does NOT do complete input validation!!!
951sub validateInput {
952 if ($webvar{city} eq '-') {
953 $page->param(err => 'Please choose a city');
954 return;
955 }
956
957 # Alloctype check.
958 chomp $webvar{alloctype};
959 if (!grep /$webvar{alloctype}/, keys %disp_alloctypes) {
960 # Danger! Danger! alloctype should ALWAYS be set by a dropdown. Anyone
961 # managing to call things in such a way as to cause this deserves a cryptic error.
962 $page->param(err => 'Invalid alloctype');
963 return;
964 }
965
966 # CustID check
967 # We have different handling for customer allocations and "internal" or "our" allocations
968 if ($def_custids{$webvar{alloctype}} eq '') {
969 if (!$webvar{custid}) {
970 $page->param(err => 'Please enter a customer ID.');
971 return;
972 }
973 # Crosscheck with billing.
974 my $status = CustIDCK->custid_exist($webvar{custid});
975 if ($CustIDCK::Error) {
976 $page->param(err => "Error verifying customer ID: ".$CustIDCK::ErrMsg);
977 return;
978 }
979 if (!$status) {
980 $page->param(err => "Customer ID not valid. Make sure the Customer ID ".
981 "is correct.<br>\nUse STAFF for staff static IPs, and $IPDB::defcustid for any other ".
982 "non-customer assignments.");
983 return;
984 }
985# print "<!-- [ In validateInput(). Insert customer ID cross-check here. ] -->\n";
986 } else {
987 # New! Improved! And now Loaded From The Database!!
988 if ((!$webvar{custid}) || ($webvar{custid} ne 'STAFF')) {
989 $webvar{custid} = $def_custids{$webvar{alloctype}};
990 }
991 }
992
993## hmmm.... is this even useful?
994if (0) {
995 # Check POP location
996 my $flag;
997 if ($webvar{alloctype} eq 'rm') {
998 $flag = 'for a routed netblock';
999 foreach (@poplist) {
1000 if (/^$webvar{city}$/) {
1001 $flag = 'n';
1002 last;
1003 }
1004 }
1005 } else {
1006 $flag = 'n';
1007##fixme: hook to force-set POP or city on certain alloctypes
1008# if ($webvar{alloctype =~ /foo,bar,bz/ { $webvar{pop} = 'blah'; }
1009 if ($webvar{pop} && $webvar{pop} =~ /^-$/) {
1010 $flag = 'to route the block from/through';
1011 }
1012 }
1013
1014 # if the alloctype has a restricted city/POP list as determined above,
1015 # and the reqested city/POP does not match that list, complain
1016 if ($flag ne 'n') {
1017 $page->param(err => "Please choose a valid POP location $flag. Valid ".
1018 "POP locations are currently:<br>\n".join (" - ", @poplist));
1019 return;
1020 }
1021}
1022
1023 # VRF. Not a full validity check, just a basic sanity check.
1024 if ($webvar{vrf}) {
1025 # Trim leading and trailing whitespace first
1026 $webvar{vrf} =~ s/^\s+//;
1027 $webvar{vrf} =~ s/\s+$//;
1028 if ($webvar{vrf} !~ /^[\w\d_.-]{1,32}$/) {
1029 $page->param(err => "VRF values may only contain alphanumerics, and may not be more than 32 characters");
1030 return;
1031 }
1032 }
1033
1034 # VLAN. Should we allow/use VLAN names, or just the numeric ID?
1035 if ($webvar{vlan}) {
1036 # Trim leading and trailing whitespace first
1037 $webvar{vlan} =~ s/^\s+//;
1038 $webvar{vlan} =~ s/\s+$//;
1039 # Then any surrounding a comma
1040 $webvar{vlan} =~ s/\s*,\s*/,/g;
1041 # ... ve make it ze configurable thingy!
1042 if ($IPDB::numeric_vlan) {
1043 if ($webvar{vlan} !~ /^[\d,-]+$/) {
1044 $page->param(err => "VLANs must be numeric");
1045 return;
1046 }
1047 } else {
1048 if ($webvar{vlan} !~ /^[\w\d_.,-]+$/) {
1049 $page->param(err => "VLANs must be alphanumeric");
1050 return;
1051 }
1052 }
1053 }
1054
1055 # Backup fields. Minimal sanity checks.
1056 # Bypass if the user isn't authorized for backup data, or if the checkbox is unchecked
1057 if ($IPDBacl{$authuser} =~ /s/ && defined($webvar{backupfields})) {
1058 for my $bkfield (qw(brand model)) {
1059 if (!$webvar{"bk$bkfield"}) {
1060 $page->param(err => "Backup $bkfield must be filled in if IP/netblock is flagged for backup");
1061 return;
1062 }
1063 if ($webvar{"bk$bkfield"} !~ /^[a-zA-Z0-9\s_.-]+$/) {
1064 $page->param(err => "Invalid characters in backup $bkfield");
1065 return;
1066 }
1067 }
1068 for my $bkfield (qw(type src user)) { # no spaces in these!
1069 if ($webvar{"bk$bkfield"} && $webvar{"bk$bkfield"} !~ /^[a-zA-Z0-9_.-]+$/) {
1070 $page->param(err => "Invalid characters in backup $bkfield");
1071 return;
1072 }
1073 }
1074 if ($webvar{bkport}) {
1075 $webvar{bkport} =~ s/^\s+//g;
1076 $webvar{bkport} =~ s/\s+$//g;
1077 if ($webvar{bkport} !~ /^\d+$/) {
1078 $page->param(err => "Backup port must be numeric");
1079 return;
1080 }
1081 }
1082##fixme: code review: should normalize $webvar{cidr} variants so we can
1083# check for non-/32 allocations having the backup IP field filled in here,
1084# instead of failing on the allocation or update attempt
1085 if ($webvar{bkip}) {
1086 $webvar{bkip} =~ s/^\s+//g;
1087 $webvar{bkip} =~ s/\s+$//g;
1088 if ($webvar{bkip} !~ /^[\da-fA-F:.]+$/) {
1089 $page->param(err => "Backup IP must be an IP");
1090 return;
1091 }
1092 }
1093 } # backup
1094
1095 return 'OK';
1096} # end validateInput
1097
1098
1099# Displays details of a specific allocation in a form
1100# Allows update/delete
1101# action=edit
1102sub edit {
1103
1104 # snag block info from db
1105 my $blockinfo = getBlockData($ip_dbh, $webvar{id}, $webvar{basetype});
1106 my $cidr = new NetAddr::IP $blockinfo->{block};
1107 $page->param(id => $webvar{id});
1108 $page->param(basetype => $webvar{basetype});
1109
1110 # Tree navigation
1111 my $crumbs = getBreadCrumbs($ip_dbh, $blockinfo->{parent_id});
1112 my @rcrumbs = reverse (@$crumbs);
1113 $utilbar->param(breadcrumb => \@rcrumbs);
1114
1115 # Show link to IP list for pools
1116 $page->param(ispool => 1) if $blockinfo->{type} =~ /^.[dp]$/;
1117
1118 # Clean up extra whitespace on alloc type. Mainly a legacy-data cleanup.
1119 $blockinfo->{type} =~ s/\s//;
1120
1121##fixme: The case of "allocation larger than a /24" (or any similar case
1122# where the allocation is larger than the zone(s) in DNS) doesn't work well.
1123# Best solution may just be to add a warning that the entry shown may not be
1124# correct/complete.
1125 if ($blockinfo->{revavail} || $blockinfo->{revpartial}) {
1126 $page->param(showrev => ($blockinfo->{revavail} || $blockinfo->{revpartial}) );
1127 $page->param(v6 => $cidr->{isv6});
1128 $page->param(dnslink => $IPDB::dnsadmin_url);
1129
1130 # get the DNSAdmin zone ID(s) for this allocation.
1131 # Multiple zones should be rare, but are NOT impossible!
1132 my $revlist = getRevID($ip_dbh, user => $authuser, cidr => $blockinfo->{block},
1133 location => $blockinfo->{location});
1134 $page->param(revlist => $revlist) if $revlist;
1135
1136 my $cached;
1137 # Get rDNS info; duplicates a bit of getBlockData but also does the RPC call if possible
1138 ($blockinfo->{rdns},$cached) = getBlockRDNS($ip_dbh, id => $webvar{id}, type => $blockinfo->{type}, user => $authuser);
1139 $page->param(rdns => $blockinfo->{rdns});
1140 # visual flag that we're working IPDB-local, not off more authoritative data in dnsadmin
1141 $page->param(cached => $cached);
1142
1143 # Limit the per-IP rDNS list based on CIDR length; larger ones just take up too much space.
1144 # Also, don't show on IP pools; the individual IPs will have a space for rDNS
1145 # Don't show on single IPs; these use the "pattern" field
1146 if ($IPDBacl{$authuser} =~ /c/
1147 && $cidr->masklen != $cidr->bits
1148 && ($cidr->bits - $cidr->masklen) <= $IPDB::maxrevlist
1149 # config flag for "all block types" OR "not-a-pool-or-IP type"
1150 && ($IPDB::revlistalltypes || $blockinfo->{type} !~ /^.[dpi]/)
1151 # safety against trying to retrieve and display more than 1k (10 bits, /22 v4) worth of individual IPs
1152 # ever. If you really need to manage a long list of IPs like that all in one place, you can use the DNS
1153 # management tool. Even a /26 is a bit much, really.
1154 && ($cidr->bits - $cidr->masklen) <= 10
1155 # do we want to allow v6 at all?
1156 #&& ! $cidr->{isv6}
1157 ) {
1158 $page->param(r_iplist => getRDNSbyIP($ip_dbh, id => $webvar{id}, type => $blockinfo->{type},
1159 range => $blockinfo->{block}, user => $authuser) );
1160 }
1161 } # rDNS availability check
1162
1163 # backup data
1164 if ($blockinfo->{hasbk}) {
1165 $page->param(hasbackup => $blockinfo->{hasbk});
1166 for my $bkfield (@IPDB::backupfields) {
1167 $page->param("bk$bkfield" => $blockinfo->{"bk$bkfield"});
1168 }
1169 $page->param(bktelnet => 1) if $blockinfo->{bktype} eq 'telnet';
1170 $page->param(bkssh => 1) if $blockinfo->{bktype} eq 'SSH';
1171 }
1172
1173 # consider extending this to show time as well as date
1174 my ($lastmod,undef) = split /\s+/, $blockinfo->{lastmod};
1175 $page->param(lastmod => $lastmod);
1176
1177 $page->param(block => $blockinfo->{block});
1178 $page->param(city => $blockinfo->{city});
1179 $page->param(custid => $blockinfo->{custid});
1180
1181##fixme The check here should be built from the database
1182# Need to expand to support pool types too
1183 if ($blockinfo->{type} =~ /^.[ne]$/ && $IPDBacl{$authuser} =~ /c/) {
1184 $page->param(changetype => 1);
1185 $page->param(alloctype => [
1186 { selme => ($blockinfo->{type} eq 'me'), type => "me", disptype => "Dialup netblock" },
1187 { selme => ($blockinfo->{type} eq 'de'), type => "de", disptype => "Dynamic DSL netblock" },
1188 { selme => ($blockinfo->{type} eq 'ce'), type => "ce", disptype => "Dynamic cable netblock" },
1189 { selme => ($blockinfo->{type} eq 'we'), type => "we", disptype => "Dynamic wireless netblock" },
1190 { selme => ($blockinfo->{type} eq 'cn'), type => "cn", disptype => "Customer netblock" },
1191 { selme => ($blockinfo->{type} eq 'en'), type => "en", disptype => "End-use netblock" },
1192 { selme => ($blockinfo->{type} eq 'in'), type => "in", disptype => "Internal netblock" },
1193 ]
1194 );
1195 } else {
1196 $page->param(disptype => $disp_alloctypes{$blockinfo->{type}});
1197 $page->param(type => $blockinfo->{type});
1198 }
1199
1200## node hack
1201 my ($nodeid,$nodename) = getNodeInfo($ip_dbh, $blockinfo->{block});
1202# $page->param(havenodeid => $nodeid);
1203 $page->param(nodename => $nodename);
1204
1205##fixme: this whole hack needs cleanup and generalization for all alloctypes
1206##fixme: arguably a bug that presence of a nodeid implies it can be changed..
1207 if ($IPDBacl{$authuser} =~ /c/) {
1208 my $nlist = getNodeList($ip_dbh);
1209 if ($nodeid) {
1210 foreach (@{$nlist}) {
1211 $$_{selme} = ($$_{node_id} == $nodeid);
1212 }
1213 }
1214 $page->param(nodelist => $nlist);
1215 }
1216## end node hack
1217
1218# $page->param(vrf => $blockinfo->{vrf});
1219 $page->param(vlan => $blockinfo->{vlan});
1220
1221 # Reserved-for-expansion
1222 $page->param(reserve => $blockinfo->{reserve});
1223 $page->param(reserve_id => $blockinfo->{reserve_id});
1224 my $newblock = NetAddr::IP->new($cidr->addr, $cidr->masklen - 1)->network;
1225 $page->param(newblock => $newblock);
1226
1227 # not happy with the upside-down logic, but...
1228 $page->param(swipable => $blockinfo->{type} !~ /.i/);
1229 $page->param(swip => $blockinfo->{swip} ne 'n') if $blockinfo->{swip};
1230
1231 $page->param(circid => $blockinfo->{circuitid});
1232 $page->param(desc => $blockinfo->{description});
1233 $page->param(notes => $blockinfo->{notes});
1234
1235 # Check to see if we can display sensitive data
1236 $page->param(nocling => $IPDBacl{$authuser} =~ /s/);
1237 $page->param(privdata => $blockinfo->{privdata});
1238
1239 # ACL trickery - these two template booleans control the presence of all form/input tags
1240 $page->param(maychange => $IPDBacl{$authuser} =~ /c/);
1241 $page->param(maydel => $IPDBacl{$authuser} =~ /d/);
1242
1243 # Need to find internal knobs to twist to actually vary these. (Ab)use "change" flag for now
1244 $page->param(maymerge => ($IPDBacl{$authuser} =~ /m/ && $blockinfo->{type} !~ /^.i$/));
1245
1246 if ($IPDBacl{$authuser} =~ /c/ && $blockinfo->{type} !~ /^.i$/) {
1247 if ($blockinfo->{type} =~ /^.p$/) {
1248 # PPP pools
1249 $page->param(maysplit => 1) if $cidr->masklen+1 < $cidr->bits;
1250 } elsif ($blockinfo->{type} =~ /.d/) {
1251 # Non-PPP pools
1252 $page->param(maysplit => 1) if $cidr->masklen+2 < $cidr->bits;
1253 } else {
1254 # Standard netblocks. Arguably allowing splitting these down to single IPs
1255 # doesn't make much sense, but forcing users to apply allocation types
1256 # "properly" is worse than herding cats.
1257 $page->param(maysplit => 1) if $cidr->masklen < $cidr->bits;
1258 }
1259 }
1260
1261} # edit()
1262
1263
1264# Stuff new info about a block into the db
1265# action=update
1266sub update {
1267 if ($IPDBacl{$authuser} !~ /c/) {
1268 $aclerr = 'updateblock';
1269 return;
1270 }
1271
1272 # Collect existing block info here, since we need it for the breadcrumb nav
1273 my $binfo = getBlockData($ip_dbh, $webvar{block}, $webvar{basetype});
1274 my $crumbs = getBreadCrumbs($ip_dbh, $binfo->{parent_id});
1275 my @rcrumbs = reverse (@$crumbs);
1276 $utilbar->param(breadcrumb => \@rcrumbs);
1277
1278 # Make sure incoming data is in correct format - custID among other things.
1279 return if !validateInput;
1280
1281 $webvar{swip} = 'n' if !$webvar{swip};
1282
1283 my %updargs = (
1284 custid => $webvar{custid},
1285 city => $webvar{city},
1286 description => $webvar{desc},
1287 notes => $webvar{notes},
1288 circuitid => $webvar{circid},
1289 block => $webvar{block},
1290 type => $webvar{alloctype},
1291 swip => $webvar{swip},
1292 rdns => $webvar{rdns},
1293 vrf => $webvar{vrf},
1294 vlan => $webvar{vlan},
1295 user => $authuser,
1296 );
1297
1298 # Check to see if user is allowed to do anything with sensitive data
1299 if ($IPDBacl{$authuser} =~ /s/) {
1300 $updargs{privdata} = $webvar{privdata};
1301 for my $bkfield (@IPDB::backupfields) {
1302 $updargs{"bk$bkfield"} = $webvar{"bk$bkfield"};
1303 }
1304 $updargs{backup} = $webvar{backupfields};
1305 } else {
1306 # If the user doesn't have permissions to monkey with NOC-things, pass
1307 # a flag so we don't treat it as "backup data removed"
1308 $updargs{ignorebk} = 1;
1309 }
1310
1311 # Semioptional values
1312 $updargs{node} = $webvar{node} if $webvar{node};
1313
1314 # collect per-IP rDNS fields. only copy over the ones that actually have something in them.
1315 my %iprev;
1316 foreach (keys %webvar) {
1317 $iprev{$_} = $webvar{$_} if /host_[\d.a-fA-F:]+/ && $webvar{$_};
1318 }
1319
1320 # and now IPv6
1321##fixme: how to remove an entry? maybe treat empty host as "delete meeeee!"?
1322 if ($webvar{v6list}) {
1323 my @v6lines = split /\n/, $webvar{v6list};
1324 foreach (@v6lines) {
1325 s/^\s+//;
1326 s/\s+$//;
1327 next if /^$/;
1328 my ($ip,$name) = split /,/;
1329 $iprev{"host_$ip"} = $name;
1330 }
1331 }
1332
1333 # Merge with reserved freeblock
1334 $updargs{fbmerge} = $webvar{expandme} if $webvar{expandme};
1335
1336 my ($code,$msg) = updateBlock($ip_dbh, %updargs, iprev => \%iprev);
1337
1338 if ($code eq 'FAIL') {
1339 syslog "err", "$authuser could not update block/IP $webvar{block} ($binfo->{block}): '$msg'";
1340 $page->param(err => "Could not update block/IP $binfo->{block}: $msg");
1341 return;
1342 }
1343
1344 # If we get here, the operation succeeded.
1345 syslog "notice", "$authuser updated $webvar{block} ($binfo->{block})";
1346##fixme: log details of the change? old way is in the .debug stream anyway.
1347##fixme: need to wedge something in to allow "update:field" notifications
1348## hmm. how to tell what changed? O_o
1349mailNotify($ip_dbh, 's:swi', "SWIPed: $disp_alloctypes{$webvar{alloctype}} $binfo->{block}",
1350 "$binfo->{block} had SWIP status changed to \"Yes\" by $authuser") if $webvar{swip} eq 'on';
1351
1352## node hack
1353 if ($webvar{node} && $webvar{node} ne '-') {
1354 my $nodename = getNodeName($ip_dbh, $webvar{node});
1355 $page->param(nodename => $nodename);
1356 }
1357## end node hack
1358
1359 # Link back to browse-routed or list-pool page on "Update complete" page.
1360 my $pblock = getBlockData($ip_dbh, $binfo->{parent_id});
1361 $page->param(backid => $binfo->{parent_id});
1362 $page->param(backblock => $pblock->{block});
1363 $page->param(backpool => ($webvar{basetype} eq 'i'));
1364
1365 # Do some HTML fiddling here instead of using ESCAPE=HTML in the template,
1366 # because otherwise we can't convert \n to <br>. *sigh*
1367 $webvar{notes} = $q->escapeHTML($webvar{notes}); # escape first...
1368 $webvar{notes} =~ s/\n/<br>\n/; # ... then convert newlines
1369 $webvar{privdata} = ($webvar{privdata} ? $q->escapeHTML($webvar{privdata}) : "&nbsp;");
1370 $webvar{privdata} =~ s/\n/<br>\n/;
1371
1372 if ($webvar{expandme}) {
1373 # this is fugly but still faster than hitting the DB again with getBlockData()
1374 my $tmp = new NetAddr::IP $binfo->{block};
1375 my $fb = new NetAddr::IP $binfo->{reserve};
1376 my @newblock = $tmp->compact($fb);
1377 $page->param(cidr => $newblock[0]);
1378 } else {
1379 $page->param(cidr => $binfo->{block});
1380 }
1381 $page->param(rdns => $webvar{rdns});
1382 $page->param(city => $webvar{city});
1383 $page->param(disptype => $disp_alloctypes{$webvar{alloctype}});
1384 $page->param(custid => $webvar{custid});
1385 $page->param(swip => $webvar{swip} eq 'on' ? 'Yes' : 'No');
1386 $page->param(circid => $webvar{circid});
1387 $page->param(desc => $webvar{desc});
1388 $page->param(notes => $webvar{notes});
1389 if ($IPDBacl{$authuser} =~ /s/) {
1390 $page->param(nocling => 1);
1391 $page->param(privdata => $webvar{privdata});
1392 if ($webvar{backupfields} && $webvar{backupfields} eq 'on') {
1393 $page->param(hasbackup => 1);
1394 for my $bkfield (@IPDB::backupfields) {
1395 $page->param("bk$bkfield" => $webvar{"bk$bkfield"});
1396 }
1397 }
1398 }
1399
1400} # update()
1401
1402
1403sub prepSplit {
1404 if ($IPDBacl{$authuser} !~ /c/) {
1405 $aclerr = 'splitblock';
1406 return;
1407 }
1408
1409 my $blockinfo = getBlockData($ip_dbh, $webvar{block});
1410
1411 # Tree navigation
1412 my $crumbs = getBreadCrumbs($ip_dbh, $blockinfo->{parent_id});
1413 my @rcrumbs = reverse (@$crumbs);
1414 $utilbar->param(breadcrumb => \@rcrumbs);
1415
1416 if ($blockinfo->{type} =~ /^.i$/) {
1417 $page->param(err => "Can't split a single IP allocation");
1418 return;
1419 }
1420
1421 # Info about current allocation
1422 $page->param(oldblock => $blockinfo->{block});
1423 $page->param(block => $webvar{block});
1424
1425# Note that there are probably different rules that should be followed to restrict splitting IPv6 blocks;
1426# strictly speaking it will be exceptionally rare to see smaller than a /64 assigned to a customer, since that
1427# breaks auto-addressing schemes.
1428
1429 # Generate possible splits
1430 my $block = new NetAddr::IP $blockinfo->{block};
1431 my $oldmask = $block->masklen;
1432 if ($blockinfo->{type} =~ /^.d$/) {
1433 # Non-PPP pools
1434 $page->param(ispool => 1);
1435 if ($oldmask+2 >= $block->bits) {
1436 $page->param(err => "Can't split a standard netblock pool any further");
1437 return;
1438 }
1439 # Allow splitting down to v4 /30 (which results in one usable IP; dubiously useful)
1440 $page->param(sp4mask => $oldmask+2) if $oldmask+2 <= $block->bits-2;
1441 } elsif ($blockinfo->{type} =~ /.p/) {
1442 $page->param(ispool => 1);
1443 # Allow splitting PPP pools down to v4 /31
1444 $page->param(sp4mask => $oldmask+2) if $oldmask+2 <= $block->bits-1;
1445 } else {
1446 # Allow splitting all other non-pool netblocks down to single IPs, which...
1447 # arguably should be *aggregated* in a pool. Except where they shouldn't.
1448 $page->param(sp4mask => $oldmask+2) if $oldmask+2 <= $block->bits;
1449 }
1450 # set the split-in-half mask
1451 $page->param(sp2mask => $oldmask+1);
1452
1453 # Generate possible shrink targets
1454 my @keepers = $block->split($block->masklen+1);
1455 $page->param(newblockA => $keepers[0]);
1456 $page->param(newblockB => $keepers[1]);
1457} # prepSplit()
1458
1459
1460sub doSplit {
1461 if ($IPDBacl{$authuser} !~ /c/) {
1462 $aclerr = 'splitblock';
1463 return;
1464 }
1465
1466##fixme: need consistent way to identify "this thing that is this thing" with only the ID
1467# also applies to other locations
1468 my $blockinfo = getBlockData($ip_dbh, $webvar{block});
1469
1470 # Tree navigation
1471 my $crumbs = getBreadCrumbs($ip_dbh, $blockinfo->{parent_id});
1472 my @rcrumbs = reverse (@$crumbs);
1473 $utilbar->param(breadcrumb => \@rcrumbs);
1474
1475 if ($blockinfo->{type} =~ /^.i$/) {
1476 $page->param(err => "Can't split a single IP allocation");
1477 return;
1478 }
1479
1480 if ($webvar{subact} eq 'split') {
1481 $page->param(issplit => 1);
1482 my $block = new NetAddr::IP $blockinfo->{block};
1483 my $newblocks = splitBlock($ip_dbh, id => $webvar{block}, basetype => 'b', newmask => $webvar{split},
1484 user => $authuser);
1485 if ($newblocks) {
1486 $page->param(newblocks => $newblocks);
1487 } else {
1488 $page->param(err => $IPDB::errstr);
1489 }
1490
1491 } elsif ($webvar{subact} eq 'shrink') {
1492 $page->param(nid => $webvar{block});
1493 $page->param(newblock => $webvar{shrink});
1494 my $newfree = shrinkBlock($ip_dbh, $webvar{block}, $webvar{shrink});
1495 if ($newfree) {
1496 $page->param(newfb => $newfree);
1497 } else {
1498 $page->param(err => $IPDB::errstr);
1499 }
1500
1501 } else {
1502 # Your llama is on fire.
1503 $page->param(err => "Missing form field that shouldn't be missing.");
1504 return;
1505 }
1506
1507 # common bits
1508 $page->param(cidr => $blockinfo->{block});
1509 # and the backlink to the parent container
1510 my $pinfo = getBlockData($ip_dbh, $blockinfo->{parent_id});
1511 $page->param(backid => $blockinfo->{parent_id});
1512 $page->param(backblock => $pinfo->{block});
1513} # doSplit()
1514
1515
1516# Set up for merge
1517sub prepMerge {
1518 if ($IPDBacl{$authuser} !~ /m/) {
1519 $aclerr = 'mergeblock';
1520 return;
1521 }
1522
1523 my $binfo = getBlockData($ip_dbh, $webvar{block});
1524
1525 # Tree navigation
1526 my $crumbs = getBreadCrumbs($ip_dbh, $binfo->{parent_id});
1527 my @rcrumbs = reverse (@$crumbs);
1528 $utilbar->param(breadcrumb => \@rcrumbs);
1529
1530 $page->param(block => $webvar{block});
1531 $page->param(ispool => $binfo->{type} =~ /.[dp]/);
1532 $page->param(ismaster => $binfo->{type} eq 'mm');
1533 $page->param(oldblock => $binfo->{block});
1534 $page->param(oldtype => $disp_alloctypes{$binfo->{type}});
1535 $page->param(typelist => getTypeList($ip_dbh, 'n', $binfo->{type})); # down the rabbit hole we go...
1536
1537 # Strings for scope; do this way so we don't have to edit them many places
1538 $page->param(vis_keepall => $merge_display{keepall});
1539 $page->param(vis_mergepeer => $merge_display{mergepeer});
1540 $page->param(vis_clearpeer => $merge_display{clearpeer});
1541 $page->param(vis_clearall => $merge_display{clearall});
1542
1543} # prepMerge()
1544
1545
1546# Show what will be merged, present warnings about data loss
1547sub confMerge {
1548 if ($IPDBacl{$authuser} !~ /m/) {
1549 $aclerr = 'mergeblock';
1550 return;
1551 }
1552
1553 if (!$webvar{newmask} || $webvar{newmask} !~ /^\d+$/) {
1554 $page->param(err => 'New netmask required');
1555 return;
1556 }
1557
1558 $page->param(block => $webvar{block});
1559 my $binfo = getBlockData($ip_dbh, $webvar{block});
1560 my $pinfo = getBlockData($ip_dbh, $binfo->{parent_id});
1561 my $minfo = getBlockData($ip_dbh, $binfo->{master_id});
1562 my $block = new NetAddr::IP $binfo->{block};
1563
1564 # Tree navigation
1565 my $crumbs = getBreadCrumbs($ip_dbh, $binfo->{parent_id});
1566 my @rcrumbs = reverse (@$crumbs);
1567 $utilbar->param(breadcrumb => \@rcrumbs);
1568
1569 $page->param(oldblock => $binfo->{block});
1570 $page->param(oldtype => $disp_alloctypes{$binfo->{type}});
1571 $page->param(ismaster => $binfo->{type} eq 'mm');
1572 $page->param(ispool => $webvar{alloctype} =~ /.[dp]/);
1573 $page->param(isleaf => $webvar{alloctype} =~ /.[enr]/);
1574 $page->param(newtype => $webvar{alloctype});
1575 $page->param(newdisptype => $disp_alloctypes{$webvar{alloctype}});
1576 my $newblock = new NetAddr::IP $block->addr."/$webvar{newmask}";
1577 $newblock = $newblock->network;
1578 $page->param(newmask => $webvar{newmask});
1579 $page->param(newblock => "$newblock");
1580
1581 # get list of allocations and freeblocks to be merged
1582 my $malloc_list = listForMerge($ip_dbh, $binfo->{parent_id}, $newblock, 'a');
1583 $page->param(mergealloc => $malloc_list);
1584
1585 $page->param(vis_scope => $merge_display{$webvar{scope}});
1586 $page->param(scope => $webvar{scope});
1587} # confMerge()
1588
1589
1590# Make it so
1591sub doMerge {
1592 if ($IPDBacl{$authuser} !~ /m/) {
1593 $aclerr = 'mergeblock';
1594 return;
1595 }
1596
1597 if (!$webvar{newmask} || $webvar{newmask} !~ /^\d+$/) {
1598 $page->param(err => 'New netmask required');
1599 return;
1600 }
1601
1602 $page->param(block => $webvar{block});
1603 my $binfo = getBlockData($ip_dbh, $webvar{block});
1604 my $pinfo = getBlockData($ip_dbh, $binfo->{parent_id});
1605 my $block = new NetAddr::IP $binfo->{block};
1606
1607 # Tree navigation
1608 my $crumbs = getBreadCrumbs($ip_dbh, $binfo->{parent_id});
1609 my @rcrumbs = reverse (@$crumbs);
1610 $utilbar->param(breadcrumb => \@rcrumbs);
1611
1612 $page->param(oldblock => $binfo->{block});
1613 $page->param(oldtype => $disp_alloctypes{$binfo->{type}});
1614 $page->param(newdisptype => $disp_alloctypes{$webvar{newtype}});
1615 my $newblock = new NetAddr::IP $block->addr."/$webvar{newmask}";
1616 $newblock = $newblock->network;
1617 $page->param(newblock => $newblock);
1618 $page->param(vis_scope => $merge_display{$webvar{scope}});
1619
1620 my $mlist = mergeBlocks($ip_dbh, $webvar{block}, %webvar, user => $authuser);
1621
1622 if ($mlist) {
1623 #(newtype => $webvar{newtype}, newmask => $webvar{newmask}));
1624 # Slice off first entry (the new parent - note this may be a new allocation,
1625 # not the same ID that was "merged"!
1626 my $parent = shift @$mlist;
1627 $page->param(backpool => $webvar{newtype} =~ /.[dp]/);
1628 if ($webvar{newtype} =~ /.[enr]/) {
1629 $page->param(backleaf => 1);
1630 $page->param(backid => $binfo->{parent_id});
1631 $page->param(backblock => $pinfo->{block});
1632 } else {
1633 $page->param(backid => $parent->{id});
1634 $page->param(backblock => $parent->{block});
1635 }
1636 $page->param(mergelist => $mlist);
1637 } else {
1638 $page->param(err => "Merge failed: $IPDB::errstr");
1639 }
1640} # doMerge()
1641
1642
1643# Delete an allocation.
1644sub remove {
1645 if ($IPDBacl{$authuser} !~ /d/) {
1646 $aclerr = 'delblock';
1647 return;
1648 }
1649
1650 # Serves'em right for getting here...
1651 if (!defined($webvar{block})) {
1652 $page->param(err => "Can't delete a block that doesn't exist");
1653 return;
1654 }
1655
1656 my $blockdata;
1657 $blockdata = getBlockData($ip_dbh, $webvar{block}, $webvar{basetype});
1658
1659 # Tree navigation
1660 my $crumbs = getBreadCrumbs($ip_dbh, $blockdata->{parent_id});
1661 my @rcrumbs = reverse (@$crumbs);
1662 $utilbar->param(breadcrumb => \@rcrumbs);
1663
1664 if ($blockdata->{parent_id} == 0) { # $webvar{alloctype} eq 'mm'
1665 $blockdata->{city} = "N/A";
1666 $blockdata->{custid} = "N/A";
1667 $blockdata->{circuitid} = "N/A";
1668 $blockdata->{description} = "N/A";
1669 $blockdata->{notes} = "N/A";
1670 $blockdata->{privdata} = "N/A";
1671 } # end cases for different alloctypes
1672
1673 $page->param(blockid => $webvar{block});
1674 $page->param(basetype => $webvar{basetype});
1675
1676 $page->param(block => $blockdata->{block});
1677 $page->param(rdns => $blockdata->{rdns});
1678
1679 # maybe need to apply more magic here?
1680 # most allocations we *do* want to autodelete the forward as well as reverse; for a handful we don't.
1681 # -> all real blocks (nb: pool IPs need extra handling)
1682 # -> NOC/private-IP (how to ID?)
1683 # -> anything with a pattern matching $IPDB::domain?
1684 if ($blockdata->{type} !~ /^.i$/) {
1685 $page->param(autodel => 1);
1686 }
1687
1688 $page->param(disptype => $disp_alloctypes{$blockdata->{type}});
1689 $page->param(city => $blockdata->{city});
1690 $page->param(custid => $blockdata->{custid});
1691 $page->param(circid => $blockdata->{circuitid});
1692 $page->param(desc => $blockdata->{description});
1693 $blockdata->{notes} = $q->escapeHTML($blockdata->{notes});
1694 $blockdata->{notes} =~ s/\n/<br>\n/;
1695 $page->param(notes => $blockdata->{notes});
1696 $blockdata->{privdata} = $q->escapeHTML($blockdata->{privdata});
1697 $blockdata->{privdata} = '&nbsp;' if !$blockdata->{privdata};
1698 $blockdata->{privdata} =~ s/\n/<br>\n/;
1699 $page->param(privdata => $blockdata->{privdata}) if $IPDBacl{$authuser} =~ /s/;
1700 $page->param(delpool => $blockdata->{type} =~ /^.[pd]$/);
1701
1702} # end remove()
1703
1704
1705# Delete an allocation. Return it to the freeblocks table; munge
1706# data as necessary to keep as few records as possible in freeblocks
1707# to prevent weirdness when allocating blocks later.
1708# Remove IPs from pool listing if necessary
1709sub finalDelete {
1710 if ($IPDBacl{$authuser} !~ /d/) {
1711 $aclerr = 'delblock';
1712 return;
1713 }
1714
1715 # need to retrieve block data before deleting so we can notify on that
1716 my $blockinfo = getBlockData($ip_dbh, $webvar{block}, $webvar{basetype});
1717 my $pinfo = getBlockData($ip_dbh, $blockinfo->{parent_id}, 'b');
1718
1719 # Tree navigation
1720 my $crumbs = getBreadCrumbs($ip_dbh, $blockinfo->{parent_id});
1721 my @rcrumbs = reverse (@$crumbs);
1722 $utilbar->param(breadcrumb => \@rcrumbs);
1723
1724 my ($code,$msg) = deleteBlock($ip_dbh, $webvar{block}, $webvar{basetype}, $webvar{delforward}, $authuser);
1725
1726 $page->param(block => $blockinfo->{block});
1727 $page->param(bdisp => $q->escapeHTML($disp_alloctypes{$blockinfo->{type}}));
1728 $page->param(delparent_id => $blockinfo->{parent_id});
1729 if ($pinfo) {
1730 $page->param(delparent => $pinfo->{block});
1731 $page->param(pdisp => $q->escapeHTML($disp_alloctypes{$pinfo->{type}}));
1732 }
1733 $page->param(returnpool => ($webvar{basetype} eq 'i') );
1734 if ($code =~ /^WARN(POOL|MERGE)/) {
1735 my ($pid,$pcidr) = split /,/, $msg;
1736 my $real_pinfo = getBlockData($ip_dbh, $pid, 'b');
1737 $page->param(parent_id => $pid);
1738 $page->param(parent => $pcidr);
1739 $page->param(real_disp => $q->escapeHTML($disp_alloctypes{$real_pinfo->{type}}));
1740 $page->param(mergeip => $code eq 'WARNPOOL');
1741 }
1742 if ($code eq 'WARN') {
1743 $msg =~ s/\n/<br>\n/g;
1744 $page->param(genwarn => $msg);
1745 }
1746 if ($code eq 'OK' || $code =~ /^WARN/) {
1747 syslog "notice", "$authuser deallocated '".$blockinfo->{type}."'-type netblock ID $webvar{block} ".
1748 "($blockinfo->{block}), $blockinfo->{custid}, $blockinfo->{city}, desc='$blockinfo->{description}'";
1749 mailNotify($ip_dbh, 'da', "REMOVED: $disp_alloctypes{$blockinfo->{type}} $blockinfo->{block}",
1750# $webvar{block} useful? do we care about the block ID here?
1751 "$disp_alloctypes{$blockinfo->{type}} $blockinfo->{block} deallocated by $authuser\n".
1752 "CustID: $blockinfo->{custid}\nCity: $blockinfo->{city}\n".
1753 "Description: $blockinfo->{description}\n");
1754 } else {
1755 $page->param(failmsg => $msg);
1756 if ($webvar{alloctype} =~ /^.i$/) {
1757 syslog "err", "$authuser could not deallocate static IP $webvar{block} ($blockinfo->{block}): '$msg'";
1758 } else {
1759 syslog "err", "$authuser could not deallocate netblock $webvar{block} ($blockinfo->{block}): '$msg'";
1760 $page->param(netblock => 1);
1761 }
1762 }
1763
1764} # finalDelete
Note: See TracBrowser for help on using the repository browser.