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

Last change on this file since 698 was 697, checked in by Kris Deugau, 10 years ago

/trunk

Add "breadcrumb" navigation trace to most pages.

  • Property svn:executable set to *
  • Property svn:keywords set to Date Rev Author
File size: 39.5 KB
RevLine 
[4]1#!/usr/bin/perl
2# ipdb/cgi-bin/main.cgi
[8]3###
4# SVN revision info
5# $Date: 2015-02-18 22:16:21 +0000 (Wed, 18 Feb 2015) $
6# SVN revision $Rev: 697 $
7# Last update by $Author: kdeugau $
8###
[417]9# Copyright (C) 2004-2010 - Kris Deugau
[4]10
11use strict;
12use warnings;
13use CGI::Carp qw(fatalsToBrowser);
[517]14use CGI::Simple;
15use HTML::Template;
[4]16use DBI;
17use POSIX qw(ceil);
18use NetAddr::IP;
[582]19use Frontier::Client;
[4]20
21use Sys::Syslog;
22
[417]23# don't remove! required for GNU/FHS-ish install from tarball
24##uselib##
25
[515]26use CustIDCK;
[417]27use MyIPDB;
28
[431]29openlog "IPDB","pid","$IPDB::syslog_facility";
[4]30
[517]31## Environment. Collect some things, process some things, set some things...
32
[233]33# Collect the username from HTTP auth. If undefined, we're in
34# a test environment, or called without a username.
[4]35my $authuser;
36if (!defined($ENV{'REMOTE_USER'})) {
37 $authuser = '__temptest';
38} else {
39 $authuser = $ENV{'REMOTE_USER'};
40}
41
[517]42# anyone got a better name? :P
43my $thingroot = $ENV{SCRIPT_FILENAME};
44$thingroot =~ s|cgi-bin/main.cgi||;
45
[402]46syslog "debug", "$authuser active, $ENV{'REMOTE_ADDR'}";
[4]47
[517]48##fixme there *must* be a better order to do things in so this can go back where it was
49# CGI fiddling done here so we can declare %webvar so we can alter $webvar{action}
50# to show the right page on DB errors.
51# Set up the CGI object...
52my $q = new CGI::Simple;
53# ... and get query-string params as well as POST params if necessary
54$q->parse_query_string;
55
56# Convenience; saves changing all references to %webvar
57##fixme: tweak for handling <select multiple='y' size=3> (list with multiple selection)
58my %webvar = $q->Vars;
59
[106]60# Why not a global DB handle? (And a global statement handle, as well...)
61# Use the connectDB function, otherwise we end up confusing ourselves
62my $ip_dbh;
63my $errstr;
[142]64($ip_dbh,$errstr) = connectDB_My;
[106]65if (!$ip_dbh) {
[517]66 $webvar{action} = "dberr";
67} else {
68 initIPDBGlobals($ip_dbh);
[106]69}
[4]70
[517]71# Set up some globals
72$ENV{HTML_TEMPLATE_ROOT} = $thingroot."templates";
[233]73
[517]74my $header = HTML::Template->new(filename => "header.tmpl");
75my $footer = HTML::Template->new(filename => "footer.tmpl");
[697]76my $utilbar = HTML::Template->new(filename => "utilbar.tmpl", loop_context_vars => 1, global_vars => 1);
[233]77
[697]78print "Content-type: text/html\n\n";
79
[517]80$header->param(version => $IPDB::VERSION);
81$header->param(addperm => $IPDBacl{$authuser} =~ /a/);
82$header->param(webpath => $IPDB::webpath);
[4]83
[697]84$utilbar->param(webpath => $IPDB::webpath);
[4]85
[697]86print $header->output;
87
88
[4]89#main()
[517]90my $aclerr;
[4]91
92if(!defined($webvar{action})) {
[517]93 $webvar{action} = "index"; #shuts up the warnings.
[4]94}
95
[517]96my $page;
97if (-e "$ENV{HTML_TEMPLATE_ROOT}/$webvar{action}.tmpl") {
[553]98 $page = HTML::Template->new(filename => "$webvar{action}.tmpl", loop_context_vars => 1, global_vars => 1);
[517]99} else {
100 $page = HTML::Template->new(filename => "dunno.tmpl");
101}
102
[4]103if($webvar{action} eq 'index') {
104 showSummary();
[233]105} elsif ($webvar{action} eq 'addmaster') {
106 if ($IPDBacl{$authuser} !~ /a/) {
[517]107 $aclerr = 'addmaster';
[233]108 }
[582]109
110 # Retrieve the list of DNS locations if we've got a place to grab them from
111 if ($IPDB::rpc_url) {
112
113 my %rpcargs = (
114 rpcuser => $authuser,
115 group => 1, # bleh
116 defloc => '',
117 );
[623]118 my $result = IPDB::_rpc('getLocDropdown', %rpcargs);
[582]119 $page->param(loclist => $result);
120 }
121
[4]122} elsif ($webvar{action} eq 'newmaster') {
123
[233]124 if ($IPDBacl{$authuser} !~ /a/) {
[517]125 $aclerr = 'addmaster';
[233]126 } else {
127 my $cidr = new NetAddr::IP $webvar{cidr};
[517]128 $page->param(cidr => "$cidr");
[4]129
[582]130 my ($code,$msg) = addMaster($ip_dbh, $webvar{cidr}, (vrf => $webvar{vrf}, rdns => $webvar{rdns},
131 rwhois => $webvar{rwhois}, defloc => $webvar{loc}, user => $authuser) );
[4]132
[371]133 if ($code eq 'FAIL') {
[320]134 syslog "err", "Could not add master block '$webvar{cidr}' to database: '$msg'";
[517]135 $page->param(err => $msg);
[233]136 } else {
[624]137 $page->param(parent => $msg);
[582]138 if ($code eq 'WARN') {
[624]139 $IPDB::errstr =~ s/\n\n/<br>\n/g;
140 $IPDB::errstr =~ s/:\n/:<br>\n/g;
141 $page->param(warn => $IPDB::errstr);
[582]142 }
[233]143 syslog "info", "$authuser added master block $webvar{cidr}";
144 }
[4]145
[233]146 } # ACL check
147
[4]148} # end add new master
149
[567]150elsif ($webvar{action} eq 'showsubs') {
151 showSubs();
152}
153
[4]154elsif($webvar{action} eq 'listpool') {
[528]155 showPool();
[4]156}
157
158# Not modified or added; just shuffled
159elsif($webvar{action} eq 'assign') {
160 assignBlock();
161}
162elsif($webvar{action} eq 'confirm') {
163 confirmAssign();
164}
165elsif($webvar{action} eq 'insert') {
166 insertAssign();
167}
168elsif($webvar{action} eq 'edit') {
169 edit();
170}
171elsif($webvar{action} eq 'update') {
172 update();
173}
174elsif($webvar{action} eq 'delete') {
175 remove();
176}
177elsif($webvar{action} eq 'finaldelete') {
178 finalDelete();
179}
[397]180elsif ($webvar{action} eq 'nodesearch') {
[519]181 my $nodelist = getNodeList($ip_dbh);
182 $page->param(nodelist => $nodelist);
[517]183}
[397]184
[517]185# DB failure. Can't do much here, really.
186elsif ($webvar{action} eq 'dberr') {
187 $page->param(errmsg => $errstr);
[397]188}
189
[517]190# Default is an error. It shouldn't be possible to get here unless you're
191# randomly feeding in values for webvar{action}.
[4]192else {
193 my $rnd = rand 500;
194 my $boing = sprintf("%.2f", rand 500);
[517]195 my @excuses = (
196 "Aether cloudy. Ask again later about $webvar{action}.",
197 "The gods are unhappy with your sacrificial $webvar{action}.",
198 "Because one of $webvar{action}'s legs are both the same",
199 "<b>wibble</b><br>Can't $webvar{action}, the grue will get me!<br>Can't $webvar{action}, the grue will get me!",
200 "Hey, man, you've had your free $webvar{action}. Next one's gonna... <i>cost</i>....",
201 "I ain't done $webvar{action}",
202 "Oooo, look! A flying $webvar{action}!",
203 "$webvar{action} too evil, avoiding.",
204 "Rocks fall, $webvar{action} dies.",
205 "Bit bucket must be emptied before I can $webvar{action}..."
206 );
207 $page->param(dunno => $excuses[$rnd/50.0]);
[4]208}
[111]209## Finally! Done with that NASTY "case" emulation!
[4]210
211
[517]212# Switch to a different template if we've tripped on an ACL error.
213# Note that this should only be exercised in development, when
214# deeplinked, or when being attacked; normal ACL handling should
215# remove the links a user is not allowed to click on.
216if ($aclerr) {
217 $page = HTML::Template->new(filename => "aclerror.tmpl");
218 $page->param(ipdbfunc => $aclmsg{$aclerr});
219}
[4]220
[106]221# Clean up IPDB globals, DB handle, etc.
[111]222finish($ip_dbh);
[199]223
[517]224## Do all our printing here so we can generate errors and stick them into the slots in the templates.
[199]225
[517]226# can't do this yet, too many blowups
227#print "Content-type: text/html\n\n", $header->output;
228$page->param(webpath => $IPDB::webpath);
[697]229print $utilbar->output;
[517]230print $page->output;
231
232# include the admin tools link in the output?
233$footer->param(adminlink => ($IPDBacl{$authuser} =~ /A/));
234$footer->param(webpath => $IPDB::webpath);
235print $footer->output;
236
[106]237# Just in case something waaaayyy down isn't in place
238# properly... we exit explicitly.
[517]239exit 0;
[4]240
241
242# Initial display: Show master blocks with total allocated subnets, total free subnets
[118]243sub showSummary {
[523]244 my $masterlist = listSummary($ip_dbh);
245 $page->param(masterlist => $masterlist);
[106]246
[517]247 $page->param(addmaster => ($IPDBacl{$authuser} =~ /a/) );
[4]248} # showSummary
249
250
[566]251# Display blocks immediately within a given parent
252sub showSubs {
[682]253 # Which layout?
254 if ($IPDB::sublistlayout == 2) {
255
256 # 2-part layout; mixed containers and end-use allocations and free blocks.
257 # Containers have a second line for the subblock metadata.
258 # We need to load an alternate template for this case.
259 $page = HTML::Template->new(filename => "showsubs2.tmpl", loop_context_vars => 1, global_vars => 1);
260
261 $page->param(maydel => ($IPDBacl{$authuser} =~ /d/));
262
263 my $sublist = listSubs($ip_dbh, parent => $webvar{parent});
264 $page->param(sublist => $sublist);
265
266 } else {
267
[685]268 # 3-part layout; containers, end-use allocations, and free blocks
[682]269
270 my $contlist = listContainers($ip_dbh, parent => $webvar{parent});
271 $page->param(contlist => $contlist);
272
273 my $alloclist = listAllocations($ip_dbh, parent => $webvar{parent});
274 $page->param(alloclist => $alloclist);
275
276 # only show "delete" button if we have no container or usage allocations
277 $page->param(maydel => ($IPDBacl{$authuser} =~ /d/) && !(@$contlist || @$alloclist));
278
279 }
280
281 # Common elements
[627]282 my $pinfo = getBlockData($ip_dbh, $webvar{parent});
283
[685]284##fixme: do we add a wrapper to not show the edit link for master blocks?
285#$page->param(editme => 1) unless $pinfo->{type} ne 'mm';
286
[697]287 my $crumbs = getBreadCrumbs($ip_dbh, $pinfo->{parent_id});
288 my @rcrumbs = reverse (@$crumbs);
289 $utilbar->param(breadcrumb => \@rcrumbs);
290
[685]291 $page->param(self_id => $webvar{parent});
[627]292 $page->param(block => $pinfo->{block});
[566]293 $page->param(mayadd => ($IPDBacl{$authuser} =~ /a/));
[4]294
[627]295 my $flist = listFree($ip_dbh, parent => $webvar{parent});
[566]296 $page->param(freelist => $flist);
297} # showSubs
[4]298
299
300# List the IPs used in a pool
[528]301sub showPool {
[4]302
[631]303 my $poolinfo = getBlockData($ip_dbh, $webvar{pool});
304 my $cidr = new NetAddr::IP $poolinfo->{block};
[4]305
[697]306 # Tree navigation
307 my $crumbs = getBreadCrumbs($ip_dbh, $poolinfo->{parent_id});
308 my @rcrumbs = reverse (@$crumbs);
309 $utilbar->param(breadcrumb => \@rcrumbs);
310
[631]311 $page->param(block => $cidr);
[517]312 $page->param(netip => $cidr->addr);
313 $cidr++;
314 $page->param(gate => $cidr->addr);
315 $cidr--; $cidr--;
316 $page->param(bcast => $cidr->addr);
317 $page->param(mask => $cidr->mask);
[157]318
[528]319 $page->param(disptype => $disp_alloctypes{$poolinfo->{type}});
320 $page->param(city => $poolinfo->{city});
[517]321
[157]322 # Only display net/gw/bcast if it's a "real" netblock and not a PPP(oE) lunacy
[528]323 $page->param(realblock => $poolinfo->{type} =~ /^.d$/);
[4]324
325# probably have to add an "edit IP allocation" link here somewhere.
326
[528]327 my $plist = listPool($ip_dbh, $webvar{pool});
328 # technically slightly more efficient to check the ACL in an if () once outside the foreach
329 foreach (@{$plist}) {
330 $$_{maydel} = $IPDBacl{$authuser} =~ /d/;
[4]331 }
[528]332 $page->param(poolips => $plist);
333} # end showPool
[4]334
335
[106]336# Show "Add new allocation" page. Note that the actual page may
337# be one of two templates, and the lists come from the database.
[4]338sub assignBlock {
339
[233]340 if ($IPDBacl{$authuser} !~ /a/) {
[517]341 $aclerr = 'addblock';
[233]342 return;
343 }
344
[517]345 # hack pthbttt eww
[633]346 $webvar{parent} = 0 if !$webvar{parent};
[517]347 $webvar{block} = '' if !$webvar{block};
[21]348
[575]349 $page->param(allocfrom => $webvar{block}); # fb-assign flag, if block is set, we're in fb-assign
[517]350
[633]351 if ($webvar{fbid} || $webvar{fbtype}) {
[575]352
353 # Common case, according to reported usage. Block to assign is specified.
[21]354 my $block = new NetAddr::IP $webvar{block};
[187]355
[675]356 my ($rdns,$cached) = getBlockRDNS($ip_dbh, id => $webvar{parent}, type => $webvar{fbtype}, user => $authuser);
[585]357 $page->param(rdns => $rdns) if $rdns;
[633]358 $page->param(parent => $webvar{parent});
359 $page->param(fbid => $webvar{fbid});
[675]360 # visual flag that we're working IPDB-local, not off more authoritative data in dnsadmin
361 $page->param(cached => $cached);
[585]362
[691]363 my $pinfo = getBlockData($ip_dbh, $webvar{parent});
364 # seems reasonable that a new allocation would share a VRF with its parent
365 $page->param(pvrf => $pinfo->{vrf});
366
[697]367 # Tree navigation
368 my $crumbs = getBreadCrumbs($ip_dbh, $webvar{parent});
369 my @rcrumbs = reverse (@$crumbs);
370 $utilbar->param(breadcrumb => \@rcrumbs);
371
[575]372 $webvar{fbtype} = '' if !$webvar{fbtype};
373 if ($webvar{fbtype} eq 'i') {
[633]374 my $ipinfo = getBlockData($ip_dbh, $webvar{block}, 'i');
[575]375 $page->param(
376 fbip => 1,
[633]377 block => $ipinfo->{block},
[575]378 fbdisptype => $list_alloctypes{$ipinfo->{type}},
379 type => $ipinfo->{type},
[633]380 allocfrom => $pinfo->{block},
[575]381 );
[187]382 } else {
[529]383 # get "primary" alloctypes, since these are all that can correctly be assigned if we're in this branch
[575]384 my $tlist = getTypeList($ip_dbh, 'n');
[529]385 $tlist->[0]->{sel} = 1;
[575]386 $page->param(typelist => $tlist, block => $block);
[106]387 }
[575]388
[21]389 } else {
[575]390
391 # Uncommon case, according to reported usage. Block to assign needs to be found based on criteria.
[541]392 my $mlist = getMasterList($ip_dbh, 'c');
393 $page->param(masterlist => $mlist);
[517]394
395 my @pops;
[633]396 foreach my $pop (@citylist) {
[517]397 my %row = (pop => $pop);
398 push (@pops, \%row);
[92]399 }
[517]400 $page->param(pops => \@pops);
401
[529]402 # get all standard alloctypes
403 my $tlist = getTypeList($ip_dbh, 'a');
404 $tlist->[0]->{sel} = 1;
405 $page->param(typelist => $tlist);
[21]406 }
[517]407
408 my @cities;
[92]409 foreach my $city (@citylist) {
[517]410 my %row = (city => $city);
411 push (@cities, \%row);
[92]412 }
[517]413 $page->param(citylist => \@cities);
[4]414
[397]415## node hack
[530]416 my $nlist = getNodeList($ip_dbh);
417 $page->param(nodelist => $nlist);
[397]418## end node hack
419
[517]420 $page->param(privdata => $IPDBacl{$authuser} =~ /s/);
[284]421
[4]422} # assignBlock
423
424
425# Take info on requested IP assignment and see what we can provide.
426sub confirmAssign {
[233]427 if ($IPDBacl{$authuser} !~ /a/) {
[517]428 $aclerr = 'addblock';
[233]429 return;
430 }
[4]431
432 my $cidr;
[692]433 my $resv; # Reserved for expansion.
[4]434 my $alloc_from;
[633]435 my $fbid = $webvar{fbid};
436 my $p_id = $webvar{parent};
[4]437
438 # Going to manually validate some items.
439 # custid and city are automagic.
[111]440 return if !validateInput();
[4]441
[665]442 # make sure this is defined
443 $webvar{fbassign} = 'n' if !$webvar{fbassign};
444
[4]445# Several different cases here.
446# Static IP vs netblock
447# + Different flavours of static IP
448# + Different flavours of netblock
449
[575]450 if ($webvar{alloctype} =~ /^.i$/ && $webvar{fbassign} ne 'y') {
[665]451 if (!$webvar{pop}) {
452 $page->param(err => "Please select a location/POP site to allocate from.");
453 return;
454 }
[532]455 my $plist = getPoolSelect($ip_dbh, $webvar{alloctype}, $webvar{pop});
[517]456 $page->param(staticip => 1);
[532]457 $page->param(poollist => $plist) if $plist;
[4]458 $cidr = "Single static IP";
[517]459##fixme: need to handle "no available pools"
[4]460
461 } else { # end show pool options
[21]462
[533]463 if ($webvar{fbassign} && $webvar{fbassign} eq 'y') {
[697]464
465 # Tree navigation
466 my $crumbs = getBreadCrumbs($ip_dbh, $webvar{parent});
467 my @rcrumbs = reverse (@$crumbs);
468 $utilbar->param(breadcrumb => \@rcrumbs);
469
[21]470 $cidr = new NetAddr::IP $webvar{block};
[575]471 $alloc_from = new NetAddr::IP $webvar{allocfrom};
[21]472 $webvar{maskbits} = $cidr->masklen;
[692]473 # Some additional checks are needed for reserving free space
474 if ($webvar{reserve}) {
475 if ($cidr == $alloc_from) {
476# We could still squirm and fiddle to try to find a way to reserve space, but the storage model for
477# IPDB means that all continguous free space is kept in the smallest number of strict CIDR netblocks
478# possible. (In theory.) If the request and the freeblock are the same, it is theoretically impossible
479# to reserve an equivalent-sized block either ahead or behind the requested one, because the pair
480# together would never be a strict CIDR block.
481 $page->param(warning => "Can't reserve space for expansion; free block and requested allocation are the same.");
482 delete $webvar{reserve};
483 } else {
484 # Find which new free block will match the reqested block.
485 # Take the requested mask, shift by one
486 my $tmpmask = $webvar{maskbits};
487 $tmpmask--;
488 # find the subnets with that mask in the selected free block
489 my @pieces = $alloc_from->split($tmpmask);
490 foreach my $slice (@pieces) {
491 if ($slice->contains($cidr)) {
492 # For the subnet that contains the requested block, split that in two,
493 # and flag/cache the one that's not the requested block.
494 my @bits = $slice->split($webvar{maskbits});
495 if ($bits[0] == $cidr) {
496 $resv = $bits[1];
497 } else {
498 $resv = $bits[0];
499 }
500 }
501 }
502 }
503 } # reserve block check
504
[21]505 } else { # done with direct freeblocks assignment
506
507 if (!$webvar{maskbits}) {
[517]508 $page->param(err => "Please specify a CIDR mask length.");
[111]509 return;
[21]510 }
[533]511
512##fixme ick, ew, bleh. gotta handle the failure message generation better. push it into findAllocateFrom()?
513 my $failmsg = "No suitable free block found.<br>\n";
[187]514 if ($webvar{alloctype} eq 'rm') {
[533]515 $failmsg .= "We do not have a free routeable block of that size.<br>\n".
516 "You will have to either route a set of smaller netblocks or a single smaller netblock.";
[4]517 } else {
[214]518 if ($webvar{alloctype} =~ /^.[pc]$/) {
[533]519 $failmsg .= "You will have to route another superblock from one of the<br>\n".
520 "master blocks or chose a smaller block size for the pool.";
[21]521 } else {
[517]522 if (!$webvar{pop}) {
523 $page->param(err => 'Please select a POP to route the block from/through.');
524 return;
525 }
[533]526 $failmsg .= "You will have to route another superblock to $webvar{pop}<br>\n".
[692]527 "from one of the master blocks";
528 if ($webvar{reserve}) {
529 $failmsg .= ', choose a smaller blocksize, or uncheck "Reserve space for expansion".';
530 } else {
531 $failmsg .= " or chose a smaller blocksize.";
532 }
[21]533 }
[4]534 }
[533]535
[692]536 # if requesting extra space "reserved for expansion", we need to find a free
537 # block at least double the size of the request.
538 if ($webvar{reserve}) {
539 $webvar{maskbits}--;
540 }
541
[633]542 ($fbid,$cidr,$p_id) = findAllocateFrom($ip_dbh, $webvar{maskbits}, $webvar{alloctype},
543 $webvar{city}, $webvar{pop}, (master => $webvar{allocfrom}, allowpriv => $webvar{allowpriv}) );
[533]544 if (!$cidr) {
[517]545 $page->param(err => $failmsg);
[111]546 return;
[21]547 }
[533]548 $cidr = new NetAddr::IP $cidr;
[575]549
550 $alloc_from = "$cidr";
[692]551
552 # when autofinding a block to allocate from, use the first piece of the found
553 # block for the allocation, and the next piece for the "reserved for expansion".
554 if ($webvar{reserve}) {
555 # reset the mask to the real requested one, now that we've got a
556 # block large enough for the request plus reserve
557 $webvar{maskbits}++;
558 ($cidr,$resv) = $cidr->split($webvar{maskbits});
559 }
560
[575]561 # If the block to be allocated is smaller than the one we found,
562 # figure out the "real" block to be allocated.
563 if ($cidr->masklen() ne $webvar{maskbits}) {
564 my $maskbits = $cidr->masklen();
565 my @subblocks;
566 while ($maskbits++ < $webvar{maskbits}) {
567 @subblocks = $cidr->split($maskbits);
568 }
569 $cidr = $subblocks[0];
570 }
[21]571 } # check for freeblocks assignment or IPDB-controlled assignment
[4]572
[674]573 # Generate the IP list for the new allocation in case someone wants to set per-IP rDNS right away.
574 # We don't do this on the previous page because we don't know how big a block or even what IP range
575 # it's for (if following the "normal" allocation process)
576 if ($IPDBacl{$authuser} =~ /c/
577 && $cidr->masklen != $cidr->bits
578 && ($cidr->bits - $cidr->masklen) <= $IPDB::maxrevlist
579 && $webvar{alloctype} !~ /^.[dpi]/
580 # do we want to allow v6 at all?
581 #&& ! $cidr->{isv6}
582 ) {
583 my @list;
584 foreach my $ip (@{$cidr->splitref()}) {
585 my %row;
586 $row{r_ip} = $ip->addr;
587 $row{iphost} = '';
588 push @list, \%row;
589 }
590 $page->param(r_iplist => \@list);
591 # We don't use this here, because these IPs should already be bare.
592 # ... or should we be paranoid? Make it a config option?
593 #getRDNSbyIP($ip_dbh, type => $webvar{alloctype}, range => "$cidr", user => $authuser) );
594 }
[157]595 } # if ($webvar{alloctype} =~ /^.i$/)
[4]596
[397]597## node hack
598 if ($webvar{node} && $webvar{node} ne '-') {
[530]599 my $nodename = getNodeName($ip_dbh, $webvar{node});
[517]600 $page->param(nodename => $nodename);
601 $page->param(nodeid => $webvar{node});
[397]602 }
603## end node hack
604
[692]605 # reserve for expansion
606 $page->param(reserve => $webvar{reserve});
607 # probably just preventing a little log noise doing this; could just set the param
608 # all the time since it won't be shown if the reserve param above isn't set.
609# if ($webvar{reserve}) {
610 $page->param(resvblock => $resv);
611# }
612
[4]613 # Stick in the allocation data
[517]614 $page->param(alloc_type => $webvar{alloctype});
615 $page->param(typefull => $q->escapeHTML($disp_alloctypes{$webvar{alloctype}}));
616 $page->param(alloc_from => $alloc_from);
[633]617 $page->param(parent => $p_id);
618 $page->param(fbid => $fbid);
[517]619 $page->param(cidr => $cidr);
[585]620 $page->param(rdns => $webvar{rdns});
[691]621 $page->param(vrf => $webvar{vrf});
622 $page->param(vlan => $webvar{vlan});
[517]623 $page->param(city => $q->escapeHTML($webvar{city}));
624 $page->param(custid => $webvar{custid});
625 $page->param(circid => $q->escapeHTML($webvar{circid}));
626 $page->param(desc => $q->escapeHTML($webvar{desc}));
[4]627
[517]628##fixme: find a way to have the displayed copy have <br> substitutions
629# for newlines, and the <input> value have either encoded or bare newlines.
630# Also applies to privdata.
631 $page->param(notes => $q->escapeHTML($webvar{notes},'y'));
632
[284]633 # Check to see if user is allowed to do anything with sensitive data
634 my $privdata = '';
[517]635 $page->param(privdata => $q->escapeHTML($webvar{privdata},'y'))
636 if $IPDBacl{$authuser} =~ /s/;
637
638 # Yay! This now has it's very own little home.
639 $page->param(billinguser => $webvar{userid})
[299]640 if $webvar{userid};
[284]641
[517]642##fixme: this is only needed iff confirm.tmpl and
643# confirmRemove.tmpl are merged (quite possible, just
644# a little tedious)
645 $page->param(action => "insert");
[284]646
[4]647} # end confirmAssign
648
649
650# Do the work of actually inserting a block in the database.
651sub insertAssign {
[233]652 if ($IPDBacl{$authuser} !~ /a/) {
[517]653 $aclerr = 'addblock';
[233]654 return;
655 }
[4]656 # Some things are done more than once.
[111]657 return if !validateInput();
[4]658
[284]659 if (!defined($webvar{privdata})) {
660 $webvar{privdata} = '';
661 }
[575]662
663 # split up some linked data for static IPs via guided allocation. needed for breadcrumbs lite.
[584]664 ($webvar{alloc_from},$webvar{rdepth}) = split /,/, $webvar{alloc_from} if $webvar{alloc_from} =~ /,/;
[575]665
[106]666 # $code is "success" vs "failure", $msg contains OK for a
667 # successful netblock allocation, the IP allocated for static
668 # IP, or the error message if an error occurred.
[517]669
[677]670##fixme: consider just passing \%webvar to allocateBlock()?
671 # collect per-IP rDNS fields. only copy over the ones that actually have something in them.
672 my %iprev;
673 foreach (keys %webvar) {
674 $iprev{$_} = $webvar{$_} if /host_[\d.a-fA-F:]+/ && $webvar{$_};
675 }
676
[691]677 # Easier to see and cosmetically fiddle the list like this
678 my %insert_args = (
679 cidr => $webvar{fullcidr},
680 fbid => $webvar{fbid},
[692]681 reserve => $webvar{reserve},
[691]682 parent => $webvar{parent},
683 custid => $webvar{custid},
684 type => $webvar{alloctype},
685 city => $webvar{city},
686 desc => $webvar{desc},
687 notes => $webvar{notes},
688 circid => $webvar{circid},
689 privdata => $webvar{privdata},
690 nodeid => $webvar{node},
691 rdns => $webvar{rdns},
692 vrf => $webvar{vrf},
693 vlan => $webvar{vlan},
694 user => $authuser,
695 );
[4]696
[691]697 my ($code,$msg) = allocateBlock($ip_dbh, %insert_args, iprev => \%iprev);
698
[111]699 if ($code eq 'OK') {
[106]700 if ($webvar{alloctype} =~ /^.i$/) {
[300]701 $msg =~ s|/32||;
[517]702 $page->param(staticip => $msg);
703 $page->param(custid => $webvar{custid});
[633]704 $page->param(parent => $webvar{parent}, pool => $webvar{alloc_from});
[517]705 $page->param(billinguser => $webvar{billinguser});
[416]706 mailNotify($ip_dbh, "a$webvar{alloctype}", "ADDED: $disp_alloctypes{$webvar{alloctype}} allocation",
707 "$disp_alloctypes{$webvar{alloctype}} $msg allocated to customer $webvar{custid}\n".
708 "Description: $webvar{desc}\n\nAllocated by: $authuser\n");
[106]709 } else {
[301]710 my $netblock = new NetAddr::IP $webvar{fullcidr};
[517]711 $page->param(fullcidr => $webvar{fullcidr});
712 $page->param(alloctype => $disp_alloctypes{$webvar{alloctype}});
713 $page->param(custid => $webvar{custid});
[697]714
[575]715 # breadcrumbs lite! provide at least a link to the parent of the block we just allocated.
[633]716 my $binfo = getBlockData($ip_dbh, $webvar{parent});
717 $page->param(parentid => $webvar{parent});
718 $page->param(parentblock => $binfo->{block});
[697]719
720 # Full breadcrumbs
721 my $crumbs = getBreadCrumbs($ip_dbh, $webvar{parent});
722 my @rcrumbs = reverse (@$crumbs);
723 $utilbar->param(breadcrumb => \@rcrumbs);
724
[517]725 if ($webvar{alloctype} eq 'pr' && $webvar{billinguser}) {
726 $page->param(billinguser => $webvar{billinguser});
727 $page->param(custid => $webvar{custid});
728 $page->param(netaddr => $netblock->addr);
729 $page->param(masklen => $netblock->masklen);
730 }
[416]731 mailNotify($ip_dbh, "a$webvar{alloctype}", "ADDED: $disp_alloctypes{$webvar{alloctype}} allocation",
732 "$disp_alloctypes{$webvar{alloctype}} $webvar{fullcidr} allocated to customer $webvar{custid}\n".
733 "Description: $webvar{desc}\n\nAllocated by: $authuser\n");
[4]734 }
[106]735 syslog "notice", "$authuser allocated '$webvar{fullcidr}' to '$webvar{custid}' as ".
[256]736 "'$webvar{alloctype}' ($msg)";
[111]737 } else {
738 syslog "err", "Allocation of '$webvar{fullcidr}' to '$webvar{custid}' as ".
739 "'$webvar{alloctype}' by $authuser failed: '$msg'";
[517]740 $page->param(err => "Allocation of $webvar{fullcidr} as '$disp_alloctypes{$webvar{alloctype}}'".
[157]741 " failed:<br>\n$msg\n");
[106]742 }
[4]743
744} # end insertAssign()
745
746
747# Does some basic checks on common input data to make sure nothing
748# *really* weird gets in to the database through this script.
749# Does NOT do complete input validation!!!
750sub validateInput {
751 if ($webvar{city} eq '-') {
[517]752 $page->param(err => 'Please choose a city');
[111]753 return;
[4]754 }
[138]755
756 # Alloctype check.
[4]757 chomp $webvar{alloctype};
[138]758 if (!grep /$webvar{alloctype}/, keys %disp_alloctypes) {
759 # Danger! Danger! alloctype should ALWAYS be set by a dropdown. Anyone
760 # managing to call things in such a way as to cause this deserves a cryptic error.
[517]761 $page->param(err => 'Invalid alloctype');
[138]762 return;
763 }
764
765 # CustID check
[4]766 # We have different handling for customer allocations and "internal" or "our" allocations
[214]767 if ($def_custids{$webvar{alloctype}} eq '') {
[4]768 if (!$webvar{custid}) {
[517]769 $page->param(err => 'Please enter a customer ID.');
[111]770 return;
[4]771 }
[546]772 # Crosscheck with billing.
773 my $status = CustIDCK->custid_exist($webvar{custid});
774 if ($CustIDCK::Error) {
775 $page->param(err => "Error verifying customer ID: ".$CustIDCK::ErrMsg);
776 return;
[4]777 }
[546]778 if (!$status) {
779 $page->param(err => "Customer ID not valid. Make sure the Customer ID ".
780 "is correct.<br>\nUse STAFF for staff static IPs, and $IPDB::defcustid for any other ".
781 "non-customer assignments.");
782 return;
783 }
[400]784# print "<!-- [ In validateInput(). Insert customer ID cross-check here. ] -->\n";
[138]785 } else {
[167]786 # New! Improved! And now Loaded From The Database!!
[320]787 if ((!$webvar{custid}) || ($webvar{custid} ne 'STAFF')) {
788 $webvar{custid} = $def_custids{$webvar{alloctype}};
789 }
[4]790 }
[111]791
[571]792## hmmm.... is this even useful?
793if (0) {
[111]794 # Check POP location
795 my $flag;
[187]796 if ($webvar{alloctype} eq 'rm') {
[111]797 $flag = 'for a routed netblock';
798 foreach (@poplist) {
799 if (/^$webvar{city}$/) {
800 $flag = 'n';
801 last;
802 }
803 }
804 } else {
805 $flag = 'n';
[442]806##fixme: hook to force-set POP or city on certain alloctypes
807# if ($webvar{alloctype =~ /foo,bar,bz/ { $webvar{pop} = 'blah'; }
[536]808 if ($webvar{pop} && $webvar{pop} =~ /^-$/) {
[111]809 $flag = 'to route the block from/through';
810 }
811 }
[517]812
813 # if the alloctype has a restricted city/POP list as determined above,
814 # and the reqested city/POP does not match that list, complain
[111]815 if ($flag ne 'n') {
[517]816 $page->param(err => "Please choose a valid POP location $flag. Valid ".
[111]817 "POP locations are currently:<br>\n".join (" - ", @poplist));
818 return;
819 }
[571]820}
[111]821
[691]822 # VRF. Not a full validity check, just a basic sanity check.
823 if ($webvar{vrf}) {
824 # Trim leading and trailing whitespace first
825 $webvar{vrf} =~ s/^\s+//;
826 $webvar{vrf} =~ s/\s+$//;
827 if ($webvar{vrf} !~ /^[\w\d_.-]{1,32}$/) {
828 $page->param(err => "VRF values may only contain alphanumerics, and may not be more than 32 characters");
829 return;
830 }
831 }
832
833 # VLAN. Should we allow/use VLAN names, or just the numeric ID?
834 if ($webvar{vlan}) {
835 # Trim leading and trailing whitespace first
836 $webvar{vlan} =~ s/^\s+//;
837 $webvar{vlan} =~ s/\s+$//;
838 # ... ve make it ze configurable thingy!
839 if ($IPDB::numeric_vlan) {
840 if ($webvar{vlan} !~ /^\d+$/) {
841 $page->param(err => "VLANs must be numeric");
842 return;
843 }
844 } else {
845 if ($webvar{vlan} !~ /^[\w\d_.-]+$/) {
846 $page->param(err => "VLANs must be alphanumeric");
847 return;
848 }
849 }
850 }
851
[111]852 return 'OK';
[4]853} # end validateInput
854
855
856# Displays details of a specific allocation in a form
857# Allows update/delete
858# action=edit
859sub edit {
860
[534]861 # snag block info from db
[634]862 my $blockinfo = getBlockData($ip_dbh, $webvar{id}, $webvar{basetype});
[691]863 $page->param(id => $webvar{id});
[634]864 $page->param(basetype => $webvar{basetype});
[4]865
[697]866 # Tree navigation
867 my $crumbs = getBreadCrumbs($ip_dbh, $blockinfo->{parent_id});
868 my @rcrumbs = reverse (@$crumbs);
869 $utilbar->param(breadcrumb => \@rcrumbs);
870
[534]871 # Clean up extra whitespace on alloc type. Mainly a legacy-data cleanup.
872 $blockinfo->{type} =~ s/\s//;
[4]873
[675]874 my $cached;
[586]875 # Get rDNS info; duplicates a bit of getBlockData but also does the RPC call if possible
[675]876 ($blockinfo->{rdns},$cached) = getBlockRDNS($ip_dbh, id => $webvar{id}, type => $blockinfo->{type}, user => $authuser);
877 # visual flag that we're working IPDB-local, not off more authoritative data in dnsadmin
[691]878 $page->param(cached => $cached);
[586]879
[675]880 my $cidr = new NetAddr::IP $blockinfo->{block};
881 # Limit the per-IP rDNS list based on CIDR length; larger ones just take up too much space.
882 # Also, don't show on IP pools; the individual IPs will have a space for rDNS
883 # Don't show on single IPs; these use the "pattern" field
884 if ($IPDBacl{$authuser} =~ /c/
885 && $cidr->masklen != $cidr->bits
886 && ($cidr->bits - $cidr->masklen) <= $IPDB::maxrevlist
[683]887 && $blockinfo->{type} !~ /^.[dpi]/
[675]888 # do we want to allow v6 at all?
889 #&& ! $cidr->{isv6}
890 ) {
891 $page->param(r_iplist => getRDNSbyIP($ip_dbh, id => $webvar{id}, type => $blockinfo->{type},
892 range => $blockinfo->{block}, user => $authuser) );
893 }
894
[691]895 # consider extending this to show time as well as date
896 my ($lastmod,undef) = split /\s+/, $blockinfo->{lastmod};
897 $page->param(lastmod => $lastmod);
898# $page->param(lastmod => $blockinfo->{lastmod});
[4]899
[691]900 $page->param(block => $blockinfo->{block});
901 $page->param(city => $blockinfo->{city});
902 $page->param(custid => $blockinfo->{custid});
[4]903
[187]904##fixme The check here should be built from the database
[517]905# Need to expand to support pool types too
[534]906 if ($blockinfo->{type} =~ /^.[ne]$/ && $IPDBacl{$authuser} =~ /c/) {
[517]907 $page->param(changetype => 1);
908 $page->param(alloctype => [
[534]909 { selme => ($blockinfo->{type} eq 'me'), type => "me", disptype => "Dialup netblock" },
910 { selme => ($blockinfo->{type} eq 'de'), type => "de", disptype => "Dynamic DSL netblock" },
911 { selme => ($blockinfo->{type} eq 'ce'), type => "ce", disptype => "Dynamic cable netblock" },
912 { selme => ($blockinfo->{type} eq 'we'), type => "we", disptype => "Dynamic wireless netblock" },
913 { selme => ($blockinfo->{type} eq 'cn'), type => "cn", disptype => "Customer netblock" },
914 { selme => ($blockinfo->{type} eq 'en'), type => "en", disptype => "End-use netblock" },
915 { selme => ($blockinfo->{type} eq 'in'), type => "in", disptype => "Internal netblock" },
[517]916 ]
917 );
918 } else {
[534]919 $page->param(disptype => $disp_alloctypes{$blockinfo->{type}});
920 $page->param(type => $blockinfo->{type});
[517]921 }
922
[397]923## node hack
[634]924 my ($nodeid,$nodename) = getNodeInfo($ip_dbh, $blockinfo->{block});
925# $page->param(havenodeid => $nodeid);
926 $page->param(nodename => $nodename);
[517]927
928##fixme: this whole hack needs cleanup and generalization for all alloctypes
929##fixme: arguably a bug that presence of a nodeid implies it can be changed..
[634]930 if ($IPDBacl{$authuser} =~ /c/) {
931 my $nlist = getNodeList($ip_dbh);
932 if ($nodeid) {
[530]933 foreach (@{$nlist}) {
[634]934 $$_{selme} = ($$_{node_id} == $nodeid);
[397]935 }
936 }
[634]937 $page->param(nodelist => $nlist);
[397]938 }
939## end node hack
[517]940
[691]941 $page->param(rdns => $blockinfo->{rdns});
942 $page->param(vrf => $blockinfo->{vrf});
943 $page->param(vlan => $blockinfo->{vlan});
[33]944
[695]945 # Reserved-for-expansion
946 $page->param(reserve => $blockinfo->{reserve});
947 $page->param(reserve_id => $blockinfo->{reserve_id});
948 my $newblock = NetAddr::IP->new($cidr->addr, $cidr->masklen - 1)->network;
949 $page->param(newblock => $newblock);
950
[517]951 # not happy with the upside-down logic, but...
[534]952 $page->param(swipable => $blockinfo->{type} !~ /.i/);
[691]953 $page->param(swip => $blockinfo->{swip} ne 'n') if $blockinfo->{swip};
[320]954
[691]955 $page->param(circid => $blockinfo->{circuitid});
956 $page->param(desc => $blockinfo->{description});
957 $page->param(notes => $blockinfo->{notes});
958
[284]959 # Check to see if we can display sensitive data
[691]960 $page->param(nocling => $IPDBacl{$authuser} =~ /s/);
[534]961 $page->param(privdata => $blockinfo->{privdata});
[284]962
[517]963 # ACL trickery - these two template booleans control the presence of all form/input tags
964 $page->param(maychange => $IPDBacl{$authuser} =~ /c/);
965 $page->param(maydel => $IPDBacl{$authuser} =~ /d/);
[4]966
967} # edit()
968
969
970# Stuff new info about a block into the db
971# action=update
972sub update {
[284]973 if ($IPDBacl{$authuser} !~ /c/) {
[517]974 $aclerr = 'updateblock';
[284]975 return;
976 }
[4]977
978 # Make sure incoming data is in correct format - custID among other things.
[228]979 return if !validateInput;
[4]980
[536]981 $webvar{swip} = 'n' if !$webvar{swip};
982
[531]983 my %updargs = (
984 custid => $webvar{custid},
985 city => $webvar{city},
986 description => $webvar{desc},
987 notes => $webvar{notes},
988 circuitid => $webvar{circid},
989 block => $webvar{block},
990 type => $webvar{alloctype},
[536]991 swip => $webvar{swip},
[588]992 rdns => $webvar{rdns},
[691]993 vrf => $webvar{vrf},
994 vlan => $webvar{vlan},
[588]995 user => $authuser,
[531]996 );
997
998 # Semioptional values
999 $updargs{privdata} = $webvar{privdata} if $IPDBacl{$authuser} =~ /s/;
1000 $updargs{node} = $webvar{node} if $webvar{node};
1001
[677]1002 # collect per-IP rDNS fields. only copy over the ones that actually have something in them.
1003 my %iprev;
1004 foreach (keys %webvar) {
1005 $iprev{$_} = $webvar{$_} if /host_[\d.a-fA-F:]+/ && $webvar{$_};
1006 }
[531]1007
[695]1008 # Merge with reserved freeblock
1009 $updargs{fbmerge} = $webvar{expandme} if $webvar{expandme};
1010
[677]1011 my ($code,$msg) = updateBlock($ip_dbh, %updargs, iprev => \%iprev);
1012
[531]1013 if ($code eq 'FAIL') {
[166]1014 syslog "err", "$authuser could not update block/IP '$webvar{block}': '$msg'";
[517]1015 $page->param(err => "Could not update block/IP $webvar{block}: $msg");
[111]1016 return;
[4]1017 }
1018
1019 # If we get here, the operation succeeded.
1020 syslog "notice", "$authuser updated $webvar{block}";
[531]1021##fixme: log details of the change? old way is in the .debug stream anyway.
[416]1022##fixme: need to wedge something in to allow "update:field" notifications
1023## hmm. how to tell what changed? O_o
[426]1024mailNotify($ip_dbh, 's:swi', "SWIPed: $disp_alloctypes{$webvar{alloctype}} $webvar{block}",
[416]1025 "$webvar{block} had SWIP status changed to \"Yes\" by $authuser") if $webvar{swip} eq 'on';
[4]1026
[517]1027## node hack
1028 if ($webvar{node} && $webvar{node} ne '-') {
[530]1029 my $nodename = getNodeName($ip_dbh, $webvar{node});
[517]1030 $page->param(nodename => $nodename);
1031 }
1032## end node hack
1033
[380]1034 # Link back to browse-routed or list-pool page on "Update complete" page.
[634]1035 my $binfo = getBlockData($ip_dbh, $webvar{block}, $webvar{basetype});
1036 my $pblock = getBlockData($ip_dbh, $binfo->{parent_id});
1037 $page->param(backid => $binfo->{parent_id});
1038 $page->param(backblock => $pblock->{block});
1039 $page->param(backpool => ($webvar{basetype} eq 'i'));
[380]1040
[536]1041 # Do some HTML fiddling here instead of using ESCAPE=HTML in the template,
1042 # because otherwise we can't convert \n to <br>. *sigh*
1043 $webvar{notes} = $q->escapeHTML($webvar{notes}); # escape first...
1044 $webvar{notes} =~ s/\n/<br>\n/; # ... then convert newlines
1045 $webvar{privdata} = ($webvar{privdata} ? $q->escapeHTML($webvar{privdata}) : "&nbsp;");
1046 $webvar{privdata} =~ s/\n/<br>\n/;
1047
[634]1048 $page->param(cidr => $binfo->{block});
[588]1049 $page->param(rdns => $webvar{rdns});
[517]1050 $page->param(city => $webvar{city});
1051 $page->param(disptype => $disp_alloctypes{$webvar{alloctype}});
1052 $page->param(custid => $webvar{custid});
1053 $page->param(swip => $webvar{swip} eq 'on' ? 'Yes' : 'No');
[536]1054 $page->param(circid => $webvar{circid});
1055 $page->param(desc => $webvar{desc});
1056 $page->param(notes => $webvar{notes});
[517]1057 $page->param(privdata => $webvar{privdata})
1058 if $IPDBacl{$authuser} =~ /s/;
[4]1059
1060} # update()
1061
1062
1063# Delete an allocation.
[106]1064sub remove {
[233]1065 if ($IPDBacl{$authuser} !~ /d/) {
[517]1066 $aclerr = 'delblock';
[233]1067 return;
1068 }
1069
[4]1070 # Serves'em right for getting here...
1071 if (!defined($webvar{block})) {
[517]1072 $page->param(err => "Can't delete a block that doesn't exist");
[111]1073 return;
[4]1074 }
1075
[538]1076 my $blockdata;
[638]1077 $blockdata = getBlockData($ip_dbh, $webvar{block}, $webvar{basetype});
[4]1078
[638]1079 if ($blockdata->{parent_id} == 0) { # $webvar{alloctype} eq 'mm'
[538]1080 $blockdata->{city} = "N/A";
1081 $blockdata->{custid} = "N/A";
1082 $blockdata->{circuitid} = "N/A";
1083 $blockdata->{description} = "N/A";
1084 $blockdata->{notes} = "N/A";
1085 $blockdata->{privdata} = "N/A";
[638]1086 } # end cases for different alloctypes
[517]1087
[638]1088 $page->param(blockid => $webvar{block});
1089 $page->param(basetype => $webvar{basetype});
[4]1090
[538]1091 $page->param(block => $blockdata->{block});
[589]1092 $page->param(rdns => $blockdata->{rdns});
1093
1094 # maybe need to apply more magic here?
1095 # most allocations we *do* want to autodelete the forward as well as reverse; for a handful we don't.
1096 # -> all real blocks (nb: pool IPs need extra handling)
1097 # -> NOC/private-IP (how to ID?)
1098 # -> anything with a pattern matching $IPDB::domain?
1099 if ($blockdata->{type} !~ /^.i$/) {
1100 $page->param(autodel => 1);
1101 }
1102
[538]1103 $page->param(disptype => $disp_alloctypes{$blockdata->{type}});
1104 $page->param(city => $blockdata->{city});
1105 $page->param(custid => $blockdata->{custid});
1106 $page->param(circid => $blockdata->{circuitid});
1107 $page->param(desc => $blockdata->{description});
1108 $blockdata->{notes} = $q->escapeHTML($blockdata->{notes});
1109 $blockdata->{notes} =~ s/\n/<br>\n/;
1110 $page->param(notes => $blockdata->{notes});
1111 $blockdata->{privdata} = $q->escapeHTML($blockdata->{privdata});
[540]1112 $blockdata->{privdata} = '&nbsp;' if !$blockdata->{privdata};
[538]1113 $blockdata->{privdata} =~ s/\n/<br>\n/;
1114 $page->param(privdata => $blockdata->{privdata}) if $IPDBacl{$authuser} =~ /s/;
1115 $page->param(delpool => $blockdata->{type} =~ /^.[pd]$/);
[4]1116
[517]1117} # end remove()
[4]1118
1119
1120# Delete an allocation. Return it to the freeblocks table; munge
1121# data as necessary to keep as few records as possible in freeblocks
1122# to prevent weirdness when allocating blocks later.
1123# Remove IPs from pool listing if necessary
1124sub finalDelete {
[233]1125 if ($IPDBacl{$authuser} !~ /d/) {
[517]1126 $aclerr = 'delblock';
[233]1127 return;
1128 }
[4]1129
[370]1130 # need to retrieve block data before deleting so we can notify on that
[638]1131 my $blockinfo = getBlockData($ip_dbh, $webvar{block}, $webvar{basetype});
1132 my $pinfo = getBlockData($ip_dbh, $blockinfo->{parent_id}, 'b');
[370]1133
[638]1134 my ($code,$msg) = deleteBlock($ip_dbh, $webvar{block}, $webvar{basetype}, $webvar{delforward}, $authuser);
[4]1135
[638]1136 $page->param(block => $blockinfo->{block});
[651]1137 $page->param(bdisp => $q->escapeHTML($disp_alloctypes{$blockinfo->{type}}));
[638]1138 $page->param(delparent_id => $blockinfo->{parent_id});# if $webvar{rdepth};
[651]1139 if ($pinfo) {
1140 $page->param(delparent => $pinfo->{block});
1141 $page->param(pdisp => $q->escapeHTML($disp_alloctypes{$pinfo->{type}}));
1142 }
[638]1143 $page->param(returnpool => ($webvar{basetype} eq 'i') );
[591]1144 if ($code =~ /^WARN(POOL|MERGE)/) {
[638]1145 my ($pid,$pcidr) = split /,/, $msg;
[654]1146 my $real_pinfo = getBlockData($ip_dbh, $pid, 'b');
[638]1147 $page->param(parent_id => $pid);
1148 $page->param(parent => $pcidr);
[654]1149 $page->param(real_disp => $q->escapeHTML($disp_alloctypes{$real_pinfo->{type}}));
[577]1150 $page->param(mergeip => $code eq 'WARNPOOL');
1151 }
[591]1152 if ($code eq 'WARN') {
1153 $msg =~ s/\n/<br>\n/g;
1154 $page->param(genwarn => $msg);
1155 }
[577]1156 if ($code eq 'OK' || $code =~ /^WARN/) {
[638]1157 syslog "notice", "$authuser deallocated '".$blockinfo->{type}."'-type netblock $webvar{block} ".
[528]1158 $blockinfo->{custid}.", ".$blockinfo->{city}.", desc='".$blockinfo->{description}."'";
[638]1159 mailNotify($ip_dbh, 'da', "REMOVED: ".$disp_alloctypes{$blockinfo->{type}}." $webvar{block}",
1160 $disp_alloctypes{$blockinfo->{type}}." $webvar{block} deallocated by $authuser\n".
[528]1161 "CustID: ".$blockinfo->{custid}."\nCity: ".$blockinfo->{city}.
1162 "\nDescription: ".$blockinfo->{description}."\n");
[106]1163 } else {
[517]1164 $page->param(failmsg => $msg);
[106]1165 if ($webvar{alloctype} =~ /^.i$/) {
1166 syslog "err", "$authuser could not deallocate static IP '$webvar{block}': '$msg'";
1167 } else {
1168 syslog "err", "$authuser could not deallocate netblock '$webvar{block}': '$msg'";
[517]1169 $page->param(netblock => 1);
[4]1170 }
[106]1171 }
[4]1172
1173} # finalDelete
Note: See TracBrowser for help on using the repository browser.