source: branches/htmlform/cgi-bin/main.cgi@ 474

Last change on this file since 474 was 474, checked in by Kris Deugau, 14 years ago

/branches/htmlform

Fix buglet in showmaster.tmpl that prevented block from being
passed on for deletion
Fix formatting buglet in showrouted.tmpl
Convert confirm-delete to template.
See #3.

  • Property svn:executable set to *
  • Property svn:keywords set to Date Rev Author
File size: 41.2 KB
Line 
1#!/usr/bin/perl
2# ipdb/cgi-bin/main.cgi
3###
4# SVN revision info
5# $Date: 2010-08-17 21:42:26 +0000 (Tue, 17 Aug 2010) $
6# SVN revision $Rev: 474 $
7# Last update by $Author: kdeugau $
8###
9# Copyright (C) 2004-2010 - Kris Deugau
10
11use strict;
12use warnings;
13use CGI::Carp qw(fatalsToBrowser);
14use CGI::Simple;
15use HTML::Template;
16use DBI;
17use CommonWeb qw(:ALL);
18use CustIDCK;
19use POSIX qw(ceil);
20use NetAddr::IP;
21
22use Sys::Syslog;
23
24# don't remove! required for GNU/FHS-ish install from tarball
25##uselib##
26
27use MyIPDB;
28
29openlog "IPDB","pid","$IPDB::syslog_facility";
30
31# Collect the username from HTTP auth. If undefined, we're in
32# a test environment, or called without a username.
33my $authuser;
34if (!defined($ENV{'REMOTE_USER'})) {
35 $authuser = '__temptest';
36} else {
37 $authuser = $ENV{'REMOTE_USER'};
38}
39
40syslog "debug", "$authuser active, $ENV{'REMOTE_ADDR'}";
41
42# Why not a global DB handle? (And a global statement handle, as well...)
43# Use the connectDB function, otherwise we end up confusing ourselves
44my $ip_dbh;
45my $sth;
46my $errstr;
47($ip_dbh,$errstr) = connectDB_My;
48if (!$ip_dbh) {
49 exitError("Database error: $errstr\n");
50}
51initIPDBGlobals($ip_dbh);
52
53# Set up some globals
54##fixme - need to autofill this somehow
55$ENV{HTML_TEMPLATE_ROOT} = '/home/kdeugau/dev/ipdb/trunk/templates';
56
57my $header = HTML::Template->new(filename => "header.tmpl");
58my $footer = HTML::Template->new(filename => "footer.tmpl");
59
60$header->param(version => $IPDB::VERSION);
61$header->param(addperm => $IPDBacl{$authuser} =~ /a/);
62print "Content-type: text/html\n\n", $header->output;
63
64# Set up the CGI object...
65my $q = new CGI::Simple;
66# ... and get query-string params as well as POST params if necessary
67$q->parse_query_string;
68
69# Convenience; saves changing all references to %webvar
70##fixme: tweak for handling <select multiple='y' size=3> (list with multiple selection)
71my %webvar = $q->Vars;
72
73
74#main()
75
76if(!defined($webvar{action})) {
77 $webvar{action} = "index"; #shuts up the warnings.
78}
79
80my $page = HTML::Template->new(filename => "$webvar{action}.tmpl");
81
82if($webvar{action} eq 'index') {
83 showSummary();
84} elsif ($webvar{action} eq 'addmaster') {
85 if ($IPDBacl{$authuser} !~ /a/) {
86 printError("You shouldn't have been able to get here. Access denied.");
87 }
88} elsif ($webvar{action} eq 'newmaster') {
89
90 if ($IPDBacl{$authuser} !~ /a/) {
91 printError("You shouldn't have been able to get here. Access denied.");
92 } else {
93 my $cidr = new NetAddr::IP $webvar{cidr};
94 $page->param(cidr => "$cidr");
95
96 my ($code,$msg) = addMaster($ip_dbh, $webvar{cidr});
97
98 if ($code eq 'FAIL') {
99 syslog "err", "Could not add master block '$webvar{cidr}' to database: '$msg'";
100 $page->param(err => $msg);
101 } else {
102 syslog "info", "$authuser added master block $webvar{cidr}";
103 }
104
105 } # ACL check
106
107} # end add new master
108
109elsif($webvar{action} eq 'showmaster') {
110 showMaster();
111}
112elsif($webvar{action} eq 'showrouted') {
113 showRBlock();
114}
115elsif($webvar{action} eq 'listpool') {
116 listPool();
117}
118
119# Not modified or added; just shuffled
120elsif($webvar{action} eq 'assign') {
121 assignBlock();
122}
123elsif($webvar{action} eq 'confirm') {
124 confirmAssign();
125}
126elsif($webvar{action} eq 'insert') {
127 insertAssign();
128}
129elsif($webvar{action} eq 'edit') {
130 edit();
131}
132elsif($webvar{action} eq 'update') {
133 update();
134}
135elsif($webvar{action} eq 'delete') {
136 remove();
137}
138elsif($webvar{action} eq 'finaldelete') {
139 finalDelete();
140}
141elsif ($webvar{action} eq 'nodesearch') {
142 open HTML, "<../nodesearch.html";
143 my $html = join('',<HTML>);
144 close HTML;
145
146 $sth = $ip_dbh->prepare("SELECT node_id, node_name FROM nodes ORDER BY node_type,node_id");
147 $sth->execute() or print "DEBUG: failed retrieval from nodes: ".$sth->errstr,"<br>\n";
148 my $nodes = '';
149 while (my ($nid,$nname) = $sth->fetchrow_array()) {
150 $nodes .= "<option value='$nid'>$nname</option>\n";
151 }
152 $html =~ s/\$\$NODELIST\$\$/$nodes/;
153
154 print $html;
155}
156
157# Default is an error. It shouldn't be possible to easily get here.
158# The only way I can think of offhand is to just call main.cgi bare-
159# which is not in any way guaranteed to provide anything useful.
160else {
161 my $rnd = rand 500;
162 my $boing = sprintf("%.2f", rand 500);
163 my @excuses = ("Aether cloudy. Ask again later.","The gods are unhappy with your sacrifice.",
164 "Because one of it's legs are both the same", "*wibble*",
165 "Hey! Stop pushing my buttons!", "I ain't done nuttin'", "9",
166 "8", "9", "10", "11", "12", "13", "14", "15", "16", "17");
167 printAndExit("Error $boing: ".$excuses[$rnd/30.0]);
168}
169## Finally! Done with that NASTY "case" emulation!
170
171
172
173# Clean up IPDB globals, DB handle, etc.
174finish($ip_dbh);
175
176#print qq(<div align=right style="position: absolute; right: 30px;">).
177# qq(<a href="/ip/cgi-bin/admin.cgi">Admin tools</a></div><br>\n)
178# if $IPDBacl{$authuser} =~ /A/;
179
180## Do all our printing here so we can generate errors and stick them into the slots in the templates.
181
182# can't do this yet, too many blowups
183#print "Content-type: text/html\n\n", $header->output;
184
185print $page->output;
186
187# include the admin tools link in the output?
188$footer->param(adminlink => ($IPDBacl{$authuser} =~ /A/));
189
190print $footer->output;
191
192# Just in case something waaaayyy down isn't in place
193# properly... we exit explicitly.
194exit;
195
196
197
198# args are: a reference to an array with the row to be printed and the
199# class(stylesheet) to use for formatting.
200# if ommitting the class - call the sub as &printRow(\@array)
201sub printRow {
202 my ($rowRef,$class) = @_;
203
204 if (!$class) {
205 print "<tr>\n";
206 } else {
207 print "<tr class=\"$class\">\n";
208 }
209
210ELEMENT: foreach my $element (@$rowRef) {
211 if (!defined($element)) {
212 print "<td></td>\n";
213 next ELEMENT;
214 }
215 $element =~ s|\n|</br>|g;
216 print "<td>$element</td>\n";
217 }
218 print "</tr>";
219} # printRow
220
221
222# Prints table headings. Accepts any number of arguments;
223# each argument is a table heading.
224sub startTable {
225 print qq(<center><table width="98%" cellspacing="0" class="center"><tr>);
226
227 foreach(@_) {
228 print qq(<td class="heading">$_</td>);
229 }
230 print "</tr>\n";
231} # startTable
232
233
234# Initial display: Show master blocks with total allocated subnets, total free subnets
235sub showSummary {
236 my %allocated;
237 my %free;
238 my %routed;
239 my %bigfree;
240
241 # Count the allocations.
242 $sth = $ip_dbh->prepare("select count(*) from allocations where cidr <<= ?");
243 foreach my $master (@masterblocks) {
244 $sth->execute("$master");
245 $sth->bind_columns(\$allocated{"$master"});
246 $sth->fetch();
247 }
248
249 # Count routed blocks
250 $sth = $ip_dbh->prepare("select count(*) from routed where cidr <<= ?");
251 foreach my $master (@masterblocks) {
252 $sth->execute("$master");
253 $sth->bind_columns(\$routed{"$master"});
254 $sth->fetch();
255 }
256
257 # Count the free blocks.
258 $sth = $ip_dbh->prepare("select count(*) from freeblocks where cidr <<= ? and ".
259 "(routed='y' or routed='n')");
260 foreach my $master (@masterblocks) {
261 $sth->execute("$master");
262 $sth->bind_columns(\$free{"$master"});
263 $sth->fetch();
264 }
265
266 # Find the largest free block in each master
267 $sth = $ip_dbh->prepare("select maskbits from freeblocks where cidr <<= ? and ".
268 "(routed='y' or routed='n') order by maskbits limit 1");
269 foreach my $master (@masterblocks) {
270 $sth->execute("$master");
271 $sth->bind_columns(\$bigfree{"$master"});
272 $sth->fetch();
273 }
274
275 # Assemble the data to stuff into the template.
276 my @masterlist;
277 my $rowclass=0;
278 foreach my $master (@masterblocks) {
279 my %row = (rowclass => "row$rowclass",
280 master => "$master",
281 routed => $routed{"$master"},
282 allocated => $allocated{"$master"},
283 free => $free{"$master"},
284 bigfree => ( ($bigfree{"$master"} eq '') ? ("&lt;NONE&gt;") : ("/".$bigfree{"$master"}) )
285 );
286 push (@masterlist, \%row);
287 $rowclass++; $rowclass = $rowclass % 2;
288 }
289 $page->param(masterlist => \@masterlist);
290
291 $page->param(addmaster => ($IPDBacl{$authuser} =~ /a/) );
292
293} # showSummary
294
295
296# Display detail on master
297# Alrighty then! We're showing routed blocks within a single master this time.
298# We should be able to steal code from showSummary(), and if I'm really smart
299# I'll figger a way to munge the two together. (Once I've done that, everything
300# else should follow. YMMV.)
301sub showMaster {
302
303 $page->param(master => $webvar{block});
304
305 my %allocated;
306 my %free;
307 my %cities;
308 my %bigfree;
309
310 my $master = new NetAddr::IP $webvar{block};
311 my @localmasters;
312
313 # Fetch only the blocks relevant to this master
314 $sth = $ip_dbh->prepare("select cidr,city from routed where cidr <<= '$master' order by cidr");
315 $sth->execute();
316
317 my $i=0;
318 while (my @data = $sth->fetchrow_array()) {
319 my $cidr = new NetAddr::IP $data[0];
320 $localmasters[$i++] = $cidr;
321 $free{"$cidr"} = 0;
322 $allocated{"$cidr"} = 0;
323 $bigfree{"$cidr"} = 128;
324 # Retain the routing destination
325 $cities{"$cidr"} = $data[1];
326 }
327
328 # Check if there were actually any blocks routed from this master
329 if ($i > 0) {
330
331 # Count the allocations
332 $sth = $ip_dbh->prepare("select count(*) from allocations where cidr <<= ?");
333 foreach my $master (@localmasters) {
334 $sth->execute("$master");
335 $sth->bind_columns(\$allocated{"$master"});
336 $sth->fetch();
337 }
338
339 # Count the free blocks.
340 $sth = $ip_dbh->prepare("select count(*) from freeblocks where cidr <<= ? and ".
341 "(routed='y' or routed='n')");
342 foreach my $master (@localmasters) {
343 $sth->execute("$master");
344 $sth->bind_columns(\$free{"$master"});
345 $sth->fetch();
346 }
347
348 # Get the size of the largest free block
349 $sth = $ip_dbh->prepare("select maskbits from freeblocks where cidr <<= ? and ".
350 "(routed='y' or routed='n') order by maskbits limit 1");
351 foreach my $master (@localmasters) {
352 $sth->execute("$master");
353 $sth->bind_columns(\$bigfree{"$master"});
354 $sth->fetch();
355 }
356
357 my @routed;
358 my $rowclass = 0;
359 foreach my $master (@localmasters) {
360 my %row = (
361 rowclass => $rowclass % 2,
362 block => "$master",
363 city => $cities{"$master"},
364 nsubs => $allocated{"$master"},
365 nfree => $free{"$master"},
366 lfree => ( ($bigfree{"$master"} eq 128) ? ("&lt;NONE&gt;") : ("/".$bigfree{"$master"}) )
367 );
368 push @routed, \%row;
369 $rowclass++;
370 }
371 $page->param(routedlist => \@routed);
372
373 } # end check for existence of routed blocks in master
374
375 $page->param(delmaster => ($IPDBacl{$authuser} =~ /d/));
376
377 # Snag the free blocks.
378 my $count = 0;
379 $sth = $ip_dbh->prepare("select cidr from freeblocks where cidr <<='$master' and ".
380 "routed='n' order by cidr");
381 $sth->execute();
382 my @unrouted;
383 my $rowclass = 0;
384 while (my @data = $sth->fetchrow_array()) {
385 my $cidr = new NetAddr::IP $data[0];
386 my %row = (
387 rowclass => $rowclass % 2,
388 fblock => "$cidr",
389 frange => $cidr->range
390 );
391 push @unrouted, \%row;
392 $rowclass++;
393 }
394 $page->param(unrouted => \@unrouted);
395
396} # showMaster
397
398
399# Display details of a routed block
400# Alrighty then! We're showing allocations within a routed block this time.
401# We should be able to steal code from showSummary() and showMaster(), and if
402# I'm really smart I'll figger a way to munge all three together. (Once I've
403# done that, everything else should follow. YMMV.
404# This time, we check the database before spewing, because we may
405# not have anything useful to spew.
406sub showRBlock {
407
408 my $master = new NetAddr::IP $webvar{block};
409
410 $sth = $ip_dbh->prepare("select city from routed where cidr='$master'");
411 $sth->execute;
412 my ($rcity) = $sth->fetchrow_array;
413
414 $page->param(master => "$master");
415 $page->param(rcity => $rcity);
416
417 # Snag the allocations for this block
418 $sth = $ip_dbh->prepare("select cidr,city,type,custid,swip,description".
419 " from allocations where cidr <<= '$master' order by cidr");
420 $sth->execute();
421
422 # hack hack hack
423 # set up to flag swip=y records if they don't actually have supporting data in the customers table
424 my $custsth = $ip_dbh->prepare("select count(*) from customers where custid=?");
425
426 my $rowclass = 0;
427 my @blocklist;
428 while (my ($cidr,$city,$type,$custid,$swip,$desc) = $sth->fetchrow_array()) {
429 $custsth->execute($custid);
430 my ($ncust) = $custsth->fetchrow_array();
431
432 my %row = (
433 rowclass => $rowclass++ % 2,
434 block => $cidr,
435 city => $city,
436 type => $disp_alloctypes{$type},
437 custid => $custid,
438 swip => ($swip eq 'y' ? ($ncust == 0 ? 'Yes<small>*</small>' : 'Yes') : 'No'),
439 desc => $desc
440 );
441 $row{subblock} = ($type =~ /^.r$/); # hmf. wonder why these won't work in the hash declaration...
442 $row{listpool} = ($type =~ /^.[pd]$/);
443 push (@blocklist, \%row);
444 }
445 $page->param(blocklist => \@blocklist);
446
447 $page->param(delrouted => $IPDBacl{$authuser} =~ /d/);
448
449 # Snag the free blocks. We don't really *need* to be pedantic about avoiding
450 # unrouted free blocks, but it's better to let the database do the work if we can.
451 $rowclass = 0;
452 my @unassigned;
453 $sth = $ip_dbh->prepare("select cidr,routed from freeblocks where cidr <<= '$master'".
454 " order by cidr");
455 $sth->execute();
456 while (my ($cidr_db,$routed) = $sth->fetchrow_array()) {
457 my $cidr = new NetAddr::IP $cidr_db;
458
459 my %row = (
460 rowclass => $rowclass++ % 2,
461 subblock => ($routed ne 'y' && $routed ne 'n'),
462 fblock => $cidr_db,
463 fbtype => $routed,
464 frange => $cidr->range,
465 );
466 push @unassigned, \%row;
467 }
468 $page->param(unassigned => \@unassigned);
469
470} # showRBlock
471
472
473# List the IPs used in a pool
474sub listPool {
475
476 my $cidr = new NetAddr::IP $webvar{pool};
477
478 $page->param(block => $webvar{pool});
479 $page->param(netip => $cidr->addr);
480 $cidr++;
481 $page->param(gate => $cidr->addr);
482 $cidr--; $cidr--;
483 $page->param(bcast => $cidr->addr);
484 $page->param(mask => $cidr->mask);
485
486 # Snag pool info for heading
487 $sth = $ip_dbh->prepare("select type,city from allocations where cidr=?");
488 $sth->execute($webvar{pool});
489 my ($pooltype, $poolcity) = $sth->fetchrow_array;
490
491 $page->param(disptype => $disp_alloctypes{$pooltype});
492 $page->param(city => $poolcity);
493
494# print qq(<center><div class="heading">Listing pool IPs for $cidr<br>\n).
495# qq(($disp_alloctypes{$pooltype} in $poolcity)</div></center><br>\n);
496 # Only display net/gw/bcast if it's a "real" netblock and not a PPP(oE) lunacy
497 $page->param(realblock => $pooltype =~ /^.d$/);
498
499# probably have to add an "edit IP allocation" link here somewhere.
500
501 $sth = $ip_dbh->prepare("select ip,custid,available,description,type".
502 " from poolips where pool='$webvar{pool}' order by ip");
503 $sth->execute;
504 my @poolips;
505 my $rowclass = 0;
506 while (my ($ip,$custid,$available,$desc,$type) = $sth->fetchrow_array) {
507 my %row = (
508 rowclass => $rowclass++ % 2,
509 ip => $ip,
510 custid => $custid,
511 available => $available,
512 desc => $desc,
513 maydel => $IPDBacl{$authuser} =~ /d/,
514 delme => $available eq 'n'
515 );
516 push @poolips, \%row;
517 }
518 $page->param(poolips => \@poolips);
519
520} # end listPool
521
522
523# Show "Add new allocation" page. Note that the actual page may
524# be one of two templates, and the lists come from the database.
525sub assignBlock {
526
527 if ($IPDBacl{$authuser} !~ /a/) {
528 printError("You shouldn't have been able to get here. Access denied.");
529 return;
530 }
531
532 # hack pthbttt eww
533 $webvar{block} = '' if !$webvar{block};
534
535# hmm. TMPL_IF block and TMPL_ELSE block on these instead?
536 $page->param(rowa => 'row'.($webvar{block} eq '' ? 1 : 0));
537 $page->param(rowb => 'row'.($webvar{block} eq '' ? 0 : 1));
538 $page->param(block => $webvar{block}); # fb-assign flag, if block is set, we're in fb-assign
539 $page->param(iscontained => ($webvar{fbtype} && $webvar{fbtype} ne 'y'));
540
541 # New special case- block to assign is specified
542 if ($webvar{block} ne '') {
543 my $block = new NetAddr::IP $webvar{block};
544
545 # Handle contained freeblock allocation.
546 # This is a little dangerous, as it's *theoretically* possible to
547 # get fbtype='n' (aka a non-routed freeblock). However, should
548 # someone manage to get there, they get what they deserve.
549 if ($webvar{fbtype} ne 'y') {
550 # Snag the type of the container block from the database.
551 $sth = $ip_dbh->prepare("select type from allocations where cidr >>='$block'");
552 $sth->execute;
553 my @data = $sth->fetchrow_array;
554 $data[0] =~ s/c$/r/; # Munge the type into the correct form
555 $page->param(fbdisptype => $list_alloctypes{$data[0]});
556 $page->param(type => $data[0]);
557 } else {
558 $sth = $ip_dbh->prepare("select type,listname from alloctypes where listorder < 500 ".
559 "and type not like '_i' and type not like '_r' order by listorder");
560 $sth->execute;
561 my @data = $sth->fetchrow_array;
562 my @typelist;
563 my $selflag = 0;
564 while (my @data = $sth->fetchrow_array) {
565 my %row = (tval => $data[0],
566 type => $data[1],
567 sel => ($selflag == 0 ? ' selected' : '')
568 );
569 push (@typelist, \%row);
570 $selflag++;
571 }
572 $page->param(typelist => \@typelist);
573 }
574 } else {
575 my @masterlist;
576 foreach my $master (@masterblocks) {
577 my %row = (master => "$master");
578 push (@masterlist, \%row);
579 }
580 $page->param(masterlist => \@masterlist);
581
582 my @pops;
583 foreach my $pop (@poplist) {
584 my %row = (pop => $pop);
585 push (@pops, \%row);
586 }
587 $page->param(pops => \@pops);
588
589 # could arguably include routing (500) in the list, but ATM it doesn't
590 # make sense, and in any case that shouldn't be structurally possible here.
591 $sth = $ip_dbh->prepare("select type,listname from alloctypes where listorder <= 500 order by listorder");
592 $sth->execute;
593 my @typelist;
594 my $selflag = 0;
595 while (my @data = $sth->fetchrow_array) {
596 my %row = (tval => $data[0],
597 type => $data[1],
598 sel => ($selflag == 0 ? ' selected' : '')
599 );
600 push (@typelist, \%row);
601 $selflag++;
602 }
603 $page->param(typelist => \@typelist);
604 }
605
606 my @cities;
607 foreach my $city (@citylist) {
608 my %row = (city => $city);
609 push (@cities, \%row);
610 }
611 $page->param(citylist => \@cities);
612
613## node hack
614 $sth = $ip_dbh->prepare("SELECT node_id, node_name FROM nodes ORDER BY node_type,node_id");
615 $sth->execute() or print "DEBUG: failed retrieval from nodes: ".$sth->errstr,"<br>\n";
616 my @nodes;
617 while (my ($nid,$nname) = $sth->fetchrow_array()) {
618 my %row = (nid => $nid, nname => $nname);
619 push (@nodes, \%row);
620 }
621 $page->param(nodelist => \@nodes);
622## end node hack
623
624 $page->param(privdata => $IPDBacl{$authuser} =~ /s/);
625
626} # assignBlock
627
628
629# Take info on requested IP assignment and see what we can provide.
630sub confirmAssign {
631 if ($IPDBacl{$authuser} !~ /a/) {
632 printError("You shouldn't have been able to get here. Access denied.");
633 return;
634 }
635
636 my $cidr;
637 my $alloc_from;
638
639 # Going to manually validate some items.
640 # custid and city are automagic.
641 return if !validateInput();
642
643# Several different cases here.
644# Static IP vs netblock
645# + Different flavours of static IP
646# + Different flavours of netblock
647
648 if ($webvar{alloctype} =~ /^.i$/) {
649 my ($base,undef) = split //, $webvar{alloctype}; # split into individual chars
650
651# Ewww. But it works.
652 $sth = $ip_dbh->prepare("SELECT (SELECT city FROM allocations WHERE cidr=poolips.pool), ".
653 "poolips.pool, COUNT(*) FROM poolips,allocations WHERE poolips.available='y' AND ".
654 "poolips.pool=allocations.cidr AND allocations.city='$webvar{pop}' AND poolips.type LIKE '".$base."_' ".
655 "GROUP BY pool");
656 $sth->execute;
657 my $optionlist;
658
659 my @poollist;
660 while (my ($poolcit,$poolblock,$poolfree) = $sth->fetchrow_array) {
661 # city,pool cidr,free IP count
662 if ($poolfree > 0) {
663 my %row = (poolcit => $poolcit, poolblock => $poolblock, poolfree => $poolfree);
664 push (@poollist, \%row);
665 }
666 }
667 $page->param(staticip => 1);
668 $page->param(poollist => \@poollist);
669 $cidr = "Single static IP";
670##fixme: need to handle "no available pools"
671
672 } else { # end show pool options
673
674 if ($webvar{fbassign} eq 'y') {
675 $cidr = new NetAddr::IP $webvar{block};
676 $webvar{maskbits} = $cidr->masklen;
677 } else { # done with direct freeblocks assignment
678
679 if (!$webvar{maskbits}) {
680 $page->param(err => "Please specify a CIDR mask length.");
681 return;
682 }
683 my $sql;
684 my $city;
685 my $failmsg;
686 my $extracond = '';
687 if ($webvar{allocfrom} eq '-') {
688 $extracond = ($webvar{allowpriv} eq 'on' ? '' :
689 " and not (cidr <<= '192.168.0.0/16'".
690 " or cidr <<= '10.0.0.0/8'".
691 " or cidr <<= '172.16.0.0/12')");
692 }
693 my $sortorder;
694 if ($webvar{alloctype} eq 'rm') {
695 if ($webvar{allocfrom} ne '-') {
696 $sql = "select * from freeblocks where maskbits<=$webvar{maskbits} and routed='n'".
697 " and cidr <<= '$webvar{allocfrom}'";
698 $sortorder = "maskbits desc";
699 } else {
700 $sql = "select * from freeblocks where maskbits<=$webvar{maskbits} and routed='n'";
701 $sortorder = "maskbits desc";
702 }
703 $failmsg = "No suitable free block found.<br>\nWe do not have a free".
704 " routeable block of that size.<br>\nYou will have to either route".
705 " a set of smaller netblocks or a single smaller netblock.";
706 } else {
707##fixme
708# This section needs serious Pondering.
709 # Pools of most types get assigned to the POP they're "routed from"
710 # This includes WAN blocks and other netblock "containers"
711 # This does NOT include cable pools.
712 if ($webvar{alloctype} =~ /^.[pc]$/) {
713 $city = $webvar{city};
714 $failmsg = "No suitable free block found.<br>\nYou will have to route another".
715 " superblock from one of the<br>\nmaster blocks or chose a smaller".
716 " block size for the pool.";
717 } else {
718 $city = $webvar{pop};
719 $failmsg = "No suitable free block found.<br>\nYou will have to route another".
720 " superblock to $webvar{pop}<br>\nfrom one of the master blocks or".
721 " chose a smaller blocksize.";
722 }
723 if (defined $webvar{allocfrom} && $webvar{allocfrom} ne '-') {
724 $sql = "select cidr from freeblocks where city='$city' and maskbits<=$webvar{maskbits}".
725 " and cidr <<= '$webvar{allocfrom}' and routed='".
726 (($webvar{alloctype} =~ /^(.)r$/) ? "$1" : 'y')."'";
727 $sortorder = "maskbits desc,cidr";
728 } else {
729 $sql = "select cidr from freeblocks where city='$city' and maskbits<=$webvar{maskbits}".
730 " and routed='".(($webvar{alloctype} =~ /^(.)r$/) ? "$1" : 'y')."'";
731 $sortorder = "maskbits desc,cidr";
732 }
733 }
734 $sql = $sql.$extracond." order by ".$sortorder;
735 $sth = $ip_dbh->prepare($sql);
736 $sth->execute;
737 my @data = $sth->fetchrow_array();
738 if ($data[0] eq "") {
739 $page->param(err => $failmsg);
740 return;
741 }
742 $cidr = new NetAddr::IP $data[0];
743 } # check for freeblocks assignment or IPDB-controlled assignment
744
745 $alloc_from = "$cidr";
746
747 # If the block to be allocated is smaller than the one we found,
748 # figure out the "real" block to be allocated.
749 if ($cidr->masklen() ne $webvar{maskbits}) {
750 my $maskbits = $cidr->masklen();
751 my @subblocks;
752 while ($maskbits++ < $webvar{maskbits}) {
753 @subblocks = $cidr->split($maskbits);
754 }
755 $cidr = $subblocks[0];
756 }
757 } # if ($webvar{alloctype} =~ /^.i$/)
758
759## node hack
760 if ($webvar{node} && $webvar{node} ne '-') {
761 $sth = $ip_dbh->prepare("SELECT node_name FROM nodes WHERE node_id=?");
762 $sth->execute($webvar{node});
763 my ($nodename) = $sth->fetchrow_array();
764 $page->param(nodename => $nodename);
765 $page->param(nodeid => $webvar{node});
766 }
767## end node hack
768
769 # Stick in the allocation data
770 $page->param(alloc_type => $webvar{alloctype});
771 $page->param(typefull => $q->escapeHTML($disp_alloctypes{$webvar{alloctype}}));
772 $page->param(alloc_from => $alloc_from);
773 $page->param(cidr => $cidr);
774 $page->param(city => $q->escapeHTML($webvar{city}));
775 $page->param(custid => $webvar{custid});
776 $page->param(circid => $q->escapeHTML($webvar{circid}));
777 $page->param(desc => $q->escapeHTML($webvar{desc}));
778
779##fixme: find a way to have the displayed copy have <br> substitutions
780# for newlines, and the <input> value have either encoded or bare newlines.
781# Also applies to privdata.
782 $page->param(notes => $q->escapeHTML($webvar{notes},'y'));
783
784 # Check to see if user is allowed to do anything with sensitive data
785 my $privdata = '';
786 $page->param(privdata => $q->escapeHTML($webvar{privdata},'y'))
787 if $IPDBacl{$authuser} =~ /s/;
788
789 # Yay! This now has it's very own little home.
790 $page->param(billinguser => $webvar{userid})
791 if $webvar{userid};
792
793##fixme: this is only needed iff confirm.tmpl/confirm.html and
794# confirmRemove.html/confirmRemove.tmpl are merged (quite possible, just
795# a little tedious)
796 $page->param(action => "insert");
797
798} # end confirmAssign
799
800
801# Do the work of actually inserting a block in the database.
802sub insertAssign {
803 if ($IPDBacl{$authuser} !~ /a/) {
804 printError("You shouldn't have been able to get here. Access denied.");
805 return;
806 }
807 # Some things are done more than once.
808 return if !validateInput();
809
810 if (!defined($webvar{privdata})) {
811 $webvar{privdata} = '';
812 }
813 # $code is "success" vs "failure", $msg contains OK for a
814 # successful netblock allocation, the IP allocated for static
815 # IP, or the error message if an error occurred.
816
817 my ($code,$msg) = allocateBlock($ip_dbh, $webvar{fullcidr}, $webvar{alloc_from},
818 $webvar{custid}, $webvar{alloctype}, $webvar{city}, $webvar{desc}, $webvar{notes},
819 $webvar{circid}, $webvar{privdata}, $webvar{node});
820
821 if ($code eq 'OK') {
822 if ($webvar{alloctype} =~ /^.i$/) {
823 $msg =~ s|/32||;
824 $page->param(staticip => $msg);
825 $page->param(custid => $webvar{custid});
826 $page->param(billinguser => $webvar{billinguser});
827 mailNotify($ip_dbh, "a$webvar{alloctype}", "ADDED: $disp_alloctypes{$webvar{alloctype}} allocation",
828 "$disp_alloctypes{$webvar{alloctype}} $msg allocated to customer $webvar{custid}\n".
829 "Description: $webvar{desc}\n\nAllocated by: $authuser\n");
830 } else {
831 my $netblock = new NetAddr::IP $webvar{fullcidr};
832 $page->param(fullcidr => $webvar{fullcidr});
833 $page->param(alloctype => $disp_alloctypes{$webvar{alloctype}});
834 $page->param(custid => $webvar{custid});
835 if ($webvar{alloctype} eq 'pr' && $webvar{billinguser}) {
836 $page->param(billinguser => $webvar{billinguser});
837 $page->param(custid => $webvar{custid});
838 $page->param(netaddr => $netblock->addr);
839 $page->param(masklen => $netblock->masklen);
840 }
841 mailNotify($ip_dbh, "a$webvar{alloctype}", "ADDED: $disp_alloctypes{$webvar{alloctype}} allocation",
842 "$disp_alloctypes{$webvar{alloctype}} $webvar{fullcidr} allocated to customer $webvar{custid}\n".
843 "Description: $webvar{desc}\n\nAllocated by: $authuser\n");
844 }
845 syslog "notice", "$authuser allocated '$webvar{fullcidr}' to '$webvar{custid}' as ".
846 "'$webvar{alloctype}' ($msg)";
847 } else {
848 syslog "err", "Allocation of '$webvar{fullcidr}' to '$webvar{custid}' as ".
849 "'$webvar{alloctype}' by $authuser failed: '$msg'";
850 $page->param(err => "Allocation of $webvar{fullcidr} as '$disp_alloctypes{$webvar{alloctype}}'".
851 " failed:<br>\n$msg\n");
852 }
853
854} # end insertAssign()
855
856
857# Does some basic checks on common input data to make sure nothing
858# *really* weird gets in to the database through this script.
859# Does NOT do complete input validation!!!
860sub validateInput {
861 if ($webvar{city} eq '-') {
862 printError("Please choose a city.");
863 return;
864 }
865
866 # Alloctype check.
867 chomp $webvar{alloctype};
868 if (!grep /$webvar{alloctype}/, keys %disp_alloctypes) {
869 # Danger! Danger! alloctype should ALWAYS be set by a dropdown. Anyone
870 # managing to call things in such a way as to cause this deserves a cryptic error.
871 printError("Invalid alloctype");
872 return;
873 }
874
875 # CustID check
876 # We have different handling for customer allocations and "internal" or "our" allocations
877 if ($def_custids{$webvar{alloctype}} eq '') {
878 if (!$webvar{custid}) {
879 printError("Please enter a customer ID.");
880 return;
881 }
882 if ($webvar{custid} !~ /^(?:\d{10}|\d{7}|STAFF)(?:-\d\d?)?$/) {
883 # Force uppercase for now...
884 $webvar{custid} =~ tr/a-z/A-Z/;
885 # Crosscheck with billing.
886 my $status = CustIDCK->custid_exist($webvar{custid});
887 if ($CustIDCK::Error) {
888 printError("Error verifying customer ID: ".$CustIDCK::ErrMsg);
889 return;
890 }
891 if (!$status) {
892 printError("Customer ID not valid. Make sure the Customer ID ".
893 "is correct.<br>\nUse STAFF for staff static IPs, and $IPDB::defcustid for any other ".
894 "non-customer assignments.");
895 return;
896 }
897 }
898# print "<!-- [ In validateInput(). Insert customer ID cross-check here. ] -->\n";
899 } else {
900 # New! Improved! And now Loaded From The Database!!
901 if ((!$webvar{custid}) || ($webvar{custid} ne 'STAFF')) {
902 $webvar{custid} = $def_custids{$webvar{alloctype}};
903 }
904 }
905
906 # Check POP location
907 my $flag;
908 if ($webvar{alloctype} eq 'rm') {
909 $flag = 'for a routed netblock';
910 foreach (@poplist) {
911 if (/^$webvar{city}$/) {
912 $flag = 'n';
913 last;
914 }
915 }
916 } else {
917 $flag = 'n';
918##fixme: hook to force-set POP or city on certain alloctypes
919# if ($webvar{alloctype =~ /foo,bar,bz/ { $webvar{pop} = 'blah'; }
920 if ($webvar{pop} =~ /^-$/) {
921 $flag = 'to route the block from/through';
922 }
923 }
924 if ($flag ne 'n') {
925 printError("Please choose a valid POP location $flag. Valid ".
926 "POP locations are currently:<br>\n".join (" - ", @poplist));
927 return;
928 }
929
930 return 'OK';
931} # end validateInput
932
933
934# Displays details of a specific allocation in a form
935# Allows update/delete
936# action=edit
937sub edit {
938
939 my $sql;
940
941 # Two cases: block is a netblock, or block is a static IP from a pool
942 # because I'm lazy, we'll try to make the SELECT's bring out identical)ish) data
943##fixme: allow "SWIP" (publication to rWHOIS) of static IP data
944 if ($webvar{block} =~ /\/32$/) {
945 $sql = "select ip,custid,type,city,circuitid,description,notes,modifystamp,privdata from poolips where ip='$webvar{block}'";
946 } else {
947 $sql = "select cidr,custid,type,city,circuitid,description,notes,modifystamp,privdata,swip from allocations where cidr='$webvar{block}'"
948 }
949
950 # gotta snag block info from db
951 $sth = $ip_dbh->prepare($sql);
952 $sth->execute;
953 my @data = $sth->fetchrow_array;
954
955 # Clean up extra whitespace on alloc type
956 $data[2] =~ s/\s//;
957
958 # We can't let the city be changed here; this block is a part of
959 # a larger routed allocation and therefore by definition can't be moved.
960 # block and city are static.
961##fixme
962# Needs thinking. Have to allow changes to city to correct errors, no?
963# Also have areas where a routed block at a POP serves "many" cities/towns/named crossroads
964
965# @data: cidr,custid,type,city,circuitid,description,notes,modifystamp,privdata,swip
966
967 $page->param(block => $webvar{block});
968
969 $page->param(custid => $data[1]);
970 $page->param(city => $data[3]);
971 $page->param(circid => $data[4]);
972 $page->param(desc => $data[5]);
973 $page->param(notes => $data[6]);
974
975##fixme The check here should be built from the database
976# Need to expand to support pool types too
977 if ($data[2] =~ /^.[ne]$/ && $IPDBacl{$authuser} =~ /c/) {
978 $page->param(changetype => 1);
979 $page->param(alloctype => [
980 { selme => ($data[2] eq 'me'), type => "me", disptype => "Dialup netblock" },
981 { selme => ($data[2] eq 'de'), type => "de", disptype => "Dynamic DSL netblock" },
982 { selme => ($data[2] eq 'ce'), type => "ce", disptype => "Dynamic cable netblock" },
983 { selme => ($data[2] eq 'we'), type => "we", disptype => "Dynamic wireless netblock" },
984 { selme => ($data[2] eq 'cn'), type => "cn", disptype => "Customer netblock" },
985 { selme => ($data[2] eq 'en'), type => "en", disptype => "End-use netblock" },
986 { selme => ($data[2] eq 'in'), type => "in", disptype => "Internal netblock" },
987 ]
988 );
989 } else {
990 $page->param(disptype => $disp_alloctypes{$data[2]});
991 $page->param(type => $data[2]);
992 }
993
994## node hack
995 $sth = $ip_dbh->prepare("SELECT nodes.node_id,node_name FROM nodes INNER JOIN noderef".
996 " ON nodes.node_id=noderef.node_id WHERE noderef.block='$webvar{block}'");
997 $sth->execute;
998 my ($nodeid,$nodename) = $sth->fetchrow_array();
999 $page->param(havenodeid => $nodeid);
1000
1001 if ($data[2] eq 'fr' || $data[2] eq 'bi') {
1002 $page->param(typesupportsnodes => 1);
1003 $page->param(nodename => $nodename);
1004
1005##fixme: this whole hack needs cleanup and generalization for all alloctypes
1006##fixme: arguably a bug that presence of a nodeid implies it can be changed..
1007# but except for manual database changes, only the two types fr and bi can
1008# (currently) have a nodeid set in the first place.
1009 if ($IPDBacl{$authuser} =~ /c/) {
1010 $sth = $ip_dbh->prepare("SELECT node_id, node_name FROM nodes ORDER BY node_type,node_id");
1011 $sth->execute;
1012 my @nodelist;
1013 while (my ($nid,$nname) = $sth->fetchrow_array()) {
1014 my %row = (
1015 selme => ($nodeid == $nid),
1016 nodeid => $nid,
1017 nodename => $nname,
1018 );
1019 push (@nodelist, \%row);
1020 }
1021 $page->param(nodelist => \@nodelist);
1022 }
1023 }
1024## end node hack
1025
1026 my ($lastmod,undef) = split /\s+/, $data[7];
1027 $page->param(lastmod => $lastmod);
1028
1029 # not happy with the upside-down logic, but...
1030 $page->param(swipable => $data[2] !~ /.i/);
1031 $page->param(swip => $data[10] ne 'n');
1032
1033 # Check to see if we can display sensitive data
1034 $page->param(nocling => $IPDBacl{$authuser} =~ /s/);
1035 $page->param(privdata => $data[8]);
1036
1037 # ACL trickery - these two template booleans control the presence of all form/input tags
1038 $page->param(maychange => $IPDBacl{$authuser} =~ /c/);
1039 $page->param(maydel => $IPDBacl{$authuser} =~ /d/);
1040
1041} # edit()
1042
1043
1044# Stuff new info about a block into the db
1045# action=update
1046sub update {
1047 if ($IPDBacl{$authuser} !~ /c/) {
1048 printError("You shouldn't have been able to get here. Access denied.");
1049 return;
1050 }
1051
1052 # Check to see if we can update restricted data
1053 my $privdata = '';
1054 if ($IPDBacl{$authuser} =~ /s/) {
1055 $privdata = ",privdata='$webvar{privdata}'";
1056 }
1057
1058 # Make sure incoming data is in correct format - custID among other things.
1059 return if !validateInput;
1060
1061 # SQL transaction wrapper
1062 eval {
1063 # Relatively simple SQL transaction here.
1064 my $sql;
1065 if (my $pooltype = ($webvar{alloctype} =~ /^(.)i$/) ) {
1066 $sql = "update poolips set custid='$webvar{custid}',notes='$webvar{notes}',".
1067 "circuitid='$webvar{circid}',description='$webvar{desc}',city='$webvar{city}'".
1068 "$privdata where ip='$webvar{block}'";
1069 } else {
1070 $sql = "update allocations set custid='$webvar{custid}',".
1071 "description='$webvar{desc}',notes='$webvar{notes}',city='$webvar{city}',".
1072 "type='$webvar{alloctype}',circuitid='$webvar{circid}'$privdata,".
1073 "swip='".($webvar{swip} eq 'on' ? 'y' : 'n')."' ".
1074 "where cidr='$webvar{block}'";
1075 }
1076 # Log the details of the change.
1077 syslog "debug", $sql;
1078 $sth = $ip_dbh->prepare($sql);
1079 $sth->execute;
1080## node hack
1081 if ($webvar{node}) {
1082 $ip_dbh->do("DELETE FROM noderef WHERE block='$webvar{block}'");
1083 $sth = $ip_dbh->prepare("INSERT INTO noderef (block,node_id) VALUES (?,?)");
1084 $sth->execute($webvar{block},$webvar{node});
1085 }
1086## end node hack
1087 $ip_dbh->commit;
1088 };
1089 if ($@) {
1090 my $msg = $@;
1091 carp "Transaction aborted because $msg";
1092 eval { $ip_dbh->rollback; };
1093 syslog "err", "$authuser could not update block/IP '$webvar{block}': '$msg'";
1094 printError("Could not update block/IP $webvar{block}: $msg");
1095 return;
1096 }
1097
1098 # If we get here, the operation succeeded.
1099 syslog "notice", "$authuser updated $webvar{block}";
1100##fixme: need to wedge something in to allow "update:field" notifications
1101## hmm. how to tell what changed? O_o
1102mailNotify($ip_dbh, 's:swi', "SWIPed: $disp_alloctypes{$webvar{alloctype}} $webvar{block}",
1103 "$webvar{block} had SWIP status changed to \"Yes\" by $authuser") if $webvar{swip} eq 'on';
1104 open (HTML, "../updated.html")
1105 or croak "Could not open updated.html :$!";
1106 my $html = join('', <HTML>);
1107
1108 # Link back to browse-routed or list-pool page on "Update complete" page.
1109 my $backlink = "/ip/cgi-bin/main.cgi?action=";
1110 my $cblock; # to contain the CIDR of the container block we're retrieving.
1111 my $sql;
1112 if (my $pooltype = ($webvar{alloctype} =~ /^(.)i$/) ) {
1113 $sql = "select pool from poolips where ip='$webvar{block}'";
1114 $backlink .= "listpool&pool=";
1115 } else {
1116 $sql = "select cidr from routed where cidr >>= '$webvar{block}'";
1117 $backlink .= "showrouted&block=";
1118 }
1119 # I define there to be no errors on this operation... so we don't need to check for them.
1120 $sth = $ip_dbh->prepare($sql);
1121 $sth->execute;
1122 $sth->bind_columns(\$cblock);
1123 $sth->fetch();
1124 $sth->finish;
1125 $backlink .= $cblock;
1126
1127my $swiptmp = ($webvar{swip} eq 'on' ? 'Yes' : 'No');
1128 $html =~ s/\$\$BLOCK\$\$/$webvar{block}/g;
1129 $webvar{city} = $q->escapeHTML($webvar{city});
1130 $html =~ s/\$\$CITY\$\$/$webvar{city}/g;
1131 $html =~ s/\$\$ALLOCTYPE\$\$/$webvar{alloctype}/g;
1132 $html =~ s/\$\$TYPEFULL\$\$/$disp_alloctypes{$webvar{alloctype}}/g;
1133 $html =~ s/\$\$CUSTID\$\$/$webvar{custid}/g;
1134 $html =~ s/\$\$SWIP\$\$/$swiptmp/g;
1135 $webvar{circid} = $q->escapeHTML($webvar{circid});
1136 $html =~ s/\$\$CIRCID\$\$/$webvar{circid}/g;
1137 $webvar{desc} = $q->escapeHTML($webvar{desc});
1138 $html =~ s/\$\$DESC\$\$/$webvar{desc}/g;
1139 $webvar{notes} = $q->escapeHTML($webvar{notes});
1140 $html =~ s/\$\$NOTES\$\$/$webvar{notes}/g;
1141 $html =~ s/\$\$BACKLINK\$\$/$backlink/g;
1142 $html =~ s/\$\$BACKBLOCK\$\$/$cblock/g;
1143
1144 if ($IPDBacl{$authuser} =~ /s/) {
1145 $privdata = qq(<tr class="color2"><td valign="top">Restricted data:</td>).
1146 qq(<td class="regular">).$q->escapeHTML($webvar{privdata}).qq(</td></tr>\n);
1147 }
1148 $html =~ s/\$\$PRIVDATA\$\$/$privdata/g;
1149
1150 print $html;
1151
1152} # update()
1153
1154
1155# Delete an allocation.
1156sub remove {
1157 if ($IPDBacl{$authuser} !~ /d/) {
1158 printError("You shouldn't have been able to get here. Access denied.");
1159 return;
1160 }
1161
1162 # Serves'em right for getting here...
1163 if (!defined($webvar{block})) {
1164 printError("Error 332");
1165 return;
1166 }
1167
1168 my ($cidr, $custid, $type, $city, $circid, $desc, $notes, $alloctype, $privdata);
1169
1170 if ($webvar{alloctype} eq 'rm') {
1171 $sth = $ip_dbh->prepare("select cidr,city from routed where cidr='$webvar{block}'");
1172 $sth->execute();
1173
1174# This feels... extreme.
1175 croak $sth->errstr() if($sth->errstr());
1176
1177 $sth->bind_columns(\$cidr,\$city);
1178 $sth->execute();
1179 $sth->fetch || croak $sth->errstr();
1180 $custid = "N/A";
1181 $alloctype = $webvar{alloctype};
1182 $circid = "N/A";
1183 $desc = "N/A";
1184 $notes = "N/A";
1185 $privdata = "N/A";
1186
1187 } elsif ($webvar{alloctype} eq 'mm') {
1188
1189 $cidr = $webvar{block};
1190 $city = "N/A";
1191 $custid = "N/A";
1192 $alloctype = $webvar{alloctype};
1193 $circid = "N/A";
1194 $desc = "N/A";
1195 $notes = "N/A";
1196 $privdata = "N/A";
1197
1198 } elsif ($webvar{alloctype} =~ /^.i$/) { # done with alloctype=[rm]m
1199
1200 # Unassigning a static IP
1201 my $sth = $ip_dbh->prepare("select ip,custid,city,type,notes,circuitid,privdata".
1202 " from poolips where ip='$webvar{block}'");
1203 $sth->execute();
1204# croak $sth->errstr() if($sth->errstr());
1205
1206 $sth->bind_columns(\$cidr, \$custid, \$city, \$alloctype, \$notes, \$circid,
1207 \$privdata);
1208 $sth->fetch() || croak $sth->errstr;
1209
1210 } else { # done with alloctype=~ /^.i$/
1211
1212 my $sth = $ip_dbh->prepare("select cidr,custid,type,city,circuitid,description,notes,privdata".
1213 " from allocations where cidr='$webvar{block}'");
1214 $sth->execute();
1215# croak $sth->errstr() if($sth->errstr());
1216
1217 $sth->bind_columns(\$cidr, \$custid, \$alloctype, \$city, \$circid, \$desc,
1218 \$notes, \$privdata);
1219 $sth->fetch() || carp $sth->errstr;
1220 } # end cases for different alloctypes
1221
1222 $page->param(block => $cidr);
1223 $page->param(disptype => $disp_alloctypes{$alloctype});
1224 $page->param(type => $alloctype);
1225 $page->param(city => $city);
1226 $page->param(custid => $custid);
1227 $page->param(circid => $circid);
1228 $page->param(desc => $desc);
1229 $page->param(notes => $notes);
1230 $privdata = '&nbsp;' if $privdata eq '';
1231 $page->param(privdata => $privdata) if $IPDBacl{$authuser} =~ /s/;
1232 $page->param(delpool => $alloctype =~ /^.[pd]$/);
1233
1234} # end remove()
1235
1236
1237# Delete an allocation. Return it to the freeblocks table; munge
1238# data as necessary to keep as few records as possible in freeblocks
1239# to prevent weirdness when allocating blocks later.
1240# Remove IPs from pool listing if necessary
1241sub finalDelete {
1242 if ($IPDBacl{$authuser} !~ /d/) {
1243 printError("You shouldn't have been able to get here. Access denied.");
1244 return;
1245 }
1246
1247 # need to retrieve block data before deleting so we can notify on that
1248 my ($cidr,$custid,$type,$city,$description) = getBlockData($ip_dbh, $webvar{block});
1249
1250 my ($code,$msg) = deleteBlock($ip_dbh, $webvar{block}, $webvar{alloctype});
1251
1252 if ($code eq 'OK') {
1253 print "<div class=heading align=center>Success! $webvar{block} deallocated.</div>\n";
1254 syslog "notice", "$authuser deallocated '$webvar{alloctype}'-type netblock $webvar{block}".
1255 " $custid, $city, desc='$description'";
1256 mailNotify($ip_dbh, 'da', "REMOVED: $disp_alloctypes{$webvar{alloctype}} $webvar{block}",
1257 "$disp_alloctypes{$webvar{alloctype}} $webvar{block} deallocated by $authuser\n".
1258 "CustID: $custid\nCity: $city\nDescription: $description\n");
1259 } else {
1260 if ($webvar{alloctype} =~ /^.i$/) {
1261 syslog "err", "$authuser could not deallocate static IP '$webvar{block}': '$msg'";
1262 printError("Could not deallocate static IP $webvar{block}: $msg");
1263 } else {
1264 syslog "err", "$authuser could not deallocate netblock '$webvar{block}': '$msg'";
1265 printError("Could not deallocate netblock $webvar{block}: $msg");
1266 }
1267 }
1268
1269} # finalDelete
1270
1271
1272# going, going, gone... this sub to be removed Any Day Real Soon Now(TM)
1273sub exitError {
1274 my $errStr = $_[0];
1275 printHeader('','');
1276 print qq(<center><p class="regular"> $errStr </p>
1277<input type="button" value="Back" onclick="history.go(-1)">
1278</center>
1279);
1280
1281 # We print the footer here, so we don't have to do it elsewhere.
1282 # include the admin tools link in the output?
1283 $footer->param(adminlink => ($IPDBacl{$authuser} =~ /A/));
1284
1285 print $footer->output;
1286
1287 exit;
1288} # errorExit
1289
1290
1291# Just in case we manage to get here.
1292exit 0;
Note: See TracBrowser for help on using the repository browser.