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

Last change on this file since 478 was 478, checked in by Kris Deugau, 11 years ago

/branches/htmlfrom

Set a global variable so we can move the site to any level of
web directory. See #17 - note this is an internal autoconfiguration
that shouldn't need to be exposed.
Make code/template structure for setting row colours in tables more
consistent - also tweak search.cgi so it spits out live colour
classes. See #3.

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