[4] | 1 | #!/usr/bin/perl
|
---|
| 2 | # ipdb/cgi-bin/main.cgi
|
---|
[8] | 3 | ###
|
---|
| 4 | # SVN revision info
|
---|
| 5 | # $Date: 2012-10-31 19:47:53 +0000 (Wed, 31 Oct 2012) $
|
---|
| 6 | # SVN revision $Rev: 533 $
|
---|
| 7 | # Last update by $Author: kdeugau $
|
---|
| 8 | ###
|
---|
[417] | 9 | # Copyright (C) 2004-2010 - Kris Deugau
|
---|
[4] | 10 |
|
---|
| 11 | use strict;
|
---|
| 12 | use warnings;
|
---|
| 13 | use CGI::Carp qw(fatalsToBrowser);
|
---|
[517] | 14 | use CGI::Simple;
|
---|
| 15 | use HTML::Template;
|
---|
[4] | 16 | use DBI;
|
---|
| 17 | use POSIX qw(ceil);
|
---|
| 18 | use NetAddr::IP;
|
---|
| 19 |
|
---|
| 20 | use Sys::Syslog;
|
---|
| 21 |
|
---|
[417] | 22 | # don't remove! required for GNU/FHS-ish install from tarball
|
---|
| 23 | ##uselib##
|
---|
| 24 |
|
---|
[515] | 25 | use CustIDCK;
|
---|
[417] | 26 | use MyIPDB;
|
---|
| 27 |
|
---|
[431] | 28 | openlog "IPDB","pid","$IPDB::syslog_facility";
|
---|
[4] | 29 |
|
---|
[517] | 30 | ## Environment. Collect some things, process some things, set some things...
|
---|
| 31 |
|
---|
[233] | 32 | # Collect the username from HTTP auth. If undefined, we're in
|
---|
| 33 | # a test environment, or called without a username.
|
---|
[4] | 34 | my $authuser;
|
---|
| 35 | if (!defined($ENV{'REMOTE_USER'})) {
|
---|
| 36 | $authuser = '__temptest';
|
---|
| 37 | } else {
|
---|
| 38 | $authuser = $ENV{'REMOTE_USER'};
|
---|
| 39 | }
|
---|
| 40 |
|
---|
[517] | 41 | # anyone got a better name? :P
|
---|
| 42 | my $thingroot = $ENV{SCRIPT_FILENAME};
|
---|
| 43 | $thingroot =~ s|cgi-bin/main.cgi||;
|
---|
| 44 |
|
---|
[402] | 45 | syslog "debug", "$authuser active, $ENV{'REMOTE_ADDR'}";
|
---|
[4] | 46 |
|
---|
[517] | 47 | ##fixme there *must* be a better order to do things in so this can go back where it was
|
---|
| 48 | # CGI fiddling done here so we can declare %webvar so we can alter $webvar{action}
|
---|
| 49 | # to show the right page on DB errors.
|
---|
| 50 | # Set up the CGI object...
|
---|
| 51 | my $q = new CGI::Simple;
|
---|
| 52 | # ... and get query-string params as well as POST params if necessary
|
---|
| 53 | $q->parse_query_string;
|
---|
| 54 |
|
---|
| 55 | # Convenience; saves changing all references to %webvar
|
---|
| 56 | ##fixme: tweak for handling <select multiple='y' size=3> (list with multiple selection)
|
---|
| 57 | my %webvar = $q->Vars;
|
---|
| 58 |
|
---|
[106] | 59 | # Why not a global DB handle? (And a global statement handle, as well...)
|
---|
| 60 | # Use the connectDB function, otherwise we end up confusing ourselves
|
---|
| 61 | my $ip_dbh;
|
---|
| 62 | my $sth;
|
---|
| 63 | my $errstr;
|
---|
[142] | 64 | ($ip_dbh,$errstr) = connectDB_My;
|
---|
[106] | 65 | if (!$ip_dbh) {
|
---|
[517] | 66 | $webvar{action} = "dberr";
|
---|
| 67 | } else {
|
---|
| 68 | initIPDBGlobals($ip_dbh);
|
---|
[106] | 69 | }
|
---|
[4] | 70 |
|
---|
[517] | 71 | # Set up some globals
|
---|
| 72 | $ENV{HTML_TEMPLATE_ROOT} = $thingroot."templates";
|
---|
[233] | 73 |
|
---|
[517] | 74 | my $header = HTML::Template->new(filename => "header.tmpl");
|
---|
| 75 | my $footer = HTML::Template->new(filename => "footer.tmpl");
|
---|
[233] | 76 |
|
---|
[517] | 77 | $header->param(version => $IPDB::VERSION);
|
---|
| 78 | $header->param(addperm => $IPDBacl{$authuser} =~ /a/);
|
---|
| 79 | $header->param(webpath => $IPDB::webpath);
|
---|
| 80 | print "Content-type: text/html\n\n", $header->output;
|
---|
[4] | 81 |
|
---|
| 82 |
|
---|
| 83 | #main()
|
---|
[517] | 84 | my $aclerr;
|
---|
[4] | 85 |
|
---|
| 86 | if(!defined($webvar{action})) {
|
---|
[517] | 87 | $webvar{action} = "index"; #shuts up the warnings.
|
---|
[4] | 88 | }
|
---|
| 89 |
|
---|
[517] | 90 | my $page;
|
---|
| 91 | if (-e "$ENV{HTML_TEMPLATE_ROOT}/$webvar{action}.tmpl") {
|
---|
[523] | 92 | $page = HTML::Template->new(filename => "$webvar{action}.tmpl", loop_context_vars => 1);
|
---|
[517] | 93 | } else {
|
---|
| 94 | $page = HTML::Template->new(filename => "dunno.tmpl");
|
---|
| 95 | }
|
---|
| 96 |
|
---|
[4] | 97 | if($webvar{action} eq 'index') {
|
---|
| 98 | showSummary();
|
---|
[233] | 99 | } elsif ($webvar{action} eq 'addmaster') {
|
---|
| 100 | if ($IPDBacl{$authuser} !~ /a/) {
|
---|
[517] | 101 | $aclerr = 'addmaster';
|
---|
[233] | 102 | }
|
---|
[4] | 103 | } elsif ($webvar{action} eq 'newmaster') {
|
---|
| 104 |
|
---|
[233] | 105 | if ($IPDBacl{$authuser} !~ /a/) {
|
---|
[517] | 106 | $aclerr = 'addmaster';
|
---|
[233] | 107 | } else {
|
---|
| 108 | my $cidr = new NetAddr::IP $webvar{cidr};
|
---|
[517] | 109 | $page->param(cidr => "$cidr");
|
---|
[4] | 110 |
|
---|
[371] | 111 | my ($code,$msg) = addMaster($ip_dbh, $webvar{cidr});
|
---|
[4] | 112 |
|
---|
[371] | 113 | if ($code eq 'FAIL') {
|
---|
[320] | 114 | syslog "err", "Could not add master block '$webvar{cidr}' to database: '$msg'";
|
---|
[517] | 115 | $page->param(err => $msg);
|
---|
[233] | 116 | } else {
|
---|
| 117 | syslog "info", "$authuser added master block $webvar{cidr}";
|
---|
| 118 | }
|
---|
[4] | 119 |
|
---|
[233] | 120 | } # ACL check
|
---|
| 121 |
|
---|
[4] | 122 | } # end add new master
|
---|
| 123 |
|
---|
| 124 | elsif($webvar{action} eq 'showmaster') {
|
---|
| 125 | showMaster();
|
---|
| 126 | }
|
---|
| 127 | elsif($webvar{action} eq 'showrouted') {
|
---|
| 128 | showRBlock();
|
---|
| 129 | }
|
---|
| 130 | elsif($webvar{action} eq 'listpool') {
|
---|
[528] | 131 | showPool();
|
---|
[4] | 132 | }
|
---|
| 133 |
|
---|
| 134 | # Not modified or added; just shuffled
|
---|
| 135 | elsif($webvar{action} eq 'assign') {
|
---|
| 136 | assignBlock();
|
---|
| 137 | }
|
---|
| 138 | elsif($webvar{action} eq 'confirm') {
|
---|
| 139 | confirmAssign();
|
---|
| 140 | }
|
---|
| 141 | elsif($webvar{action} eq 'insert') {
|
---|
| 142 | insertAssign();
|
---|
| 143 | }
|
---|
| 144 | elsif($webvar{action} eq 'edit') {
|
---|
| 145 | edit();
|
---|
| 146 | }
|
---|
| 147 | elsif($webvar{action} eq 'update') {
|
---|
| 148 | update();
|
---|
| 149 | }
|
---|
| 150 | elsif($webvar{action} eq 'delete') {
|
---|
| 151 | remove();
|
---|
| 152 | }
|
---|
| 153 | elsif($webvar{action} eq 'finaldelete') {
|
---|
| 154 | finalDelete();
|
---|
| 155 | }
|
---|
[397] | 156 | elsif ($webvar{action} eq 'nodesearch') {
|
---|
[519] | 157 | my $nodelist = getNodeList($ip_dbh);
|
---|
| 158 | $page->param(nodelist => $nodelist);
|
---|
[517] | 159 | }
|
---|
[397] | 160 |
|
---|
[517] | 161 | # DB failure. Can't do much here, really.
|
---|
| 162 | elsif ($webvar{action} eq 'dberr') {
|
---|
| 163 | $page->param(errmsg => $errstr);
|
---|
[397] | 164 | }
|
---|
| 165 |
|
---|
[517] | 166 | # Default is an error. It shouldn't be possible to get here unless you're
|
---|
| 167 | # randomly feeding in values for webvar{action}.
|
---|
[4] | 168 | else {
|
---|
| 169 | my $rnd = rand 500;
|
---|
| 170 | my $boing = sprintf("%.2f", rand 500);
|
---|
[517] | 171 | my @excuses = (
|
---|
| 172 | "Aether cloudy. Ask again later about $webvar{action}.",
|
---|
| 173 | "The gods are unhappy with your sacrificial $webvar{action}.",
|
---|
| 174 | "Because one of $webvar{action}'s legs are both the same",
|
---|
| 175 | "<b>wibble</b><br>Can't $webvar{action}, the grue will get me!<br>Can't $webvar{action}, the grue will get me!",
|
---|
| 176 | "Hey, man, you've had your free $webvar{action}. Next one's gonna... <i>cost</i>....",
|
---|
| 177 | "I ain't done $webvar{action}",
|
---|
| 178 | "Oooo, look! A flying $webvar{action}!",
|
---|
| 179 | "$webvar{action} too evil, avoiding.",
|
---|
| 180 | "Rocks fall, $webvar{action} dies.",
|
---|
| 181 | "Bit bucket must be emptied before I can $webvar{action}..."
|
---|
| 182 | );
|
---|
| 183 | $page->param(dunno => $excuses[$rnd/50.0]);
|
---|
[4] | 184 | }
|
---|
[111] | 185 | ## Finally! Done with that NASTY "case" emulation!
|
---|
[4] | 186 |
|
---|
| 187 |
|
---|
[517] | 188 | # Switch to a different template if we've tripped on an ACL error.
|
---|
| 189 | # Note that this should only be exercised in development, when
|
---|
| 190 | # deeplinked, or when being attacked; normal ACL handling should
|
---|
| 191 | # remove the links a user is not allowed to click on.
|
---|
| 192 | if ($aclerr) {
|
---|
| 193 | $page = HTML::Template->new(filename => "aclerror.tmpl");
|
---|
| 194 | $page->param(ipdbfunc => $aclmsg{$aclerr});
|
---|
| 195 | }
|
---|
[4] | 196 |
|
---|
[519] | 197 | $sth->finish if $sth;
|
---|
[106] | 198 | # Clean up IPDB globals, DB handle, etc.
|
---|
[111] | 199 | finish($ip_dbh);
|
---|
[199] | 200 |
|
---|
[517] | 201 | ## Do all our printing here so we can generate errors and stick them into the slots in the templates.
|
---|
[199] | 202 |
|
---|
[517] | 203 | # can't do this yet, too many blowups
|
---|
| 204 | #print "Content-type: text/html\n\n", $header->output;
|
---|
| 205 | $page->param(webpath => $IPDB::webpath);
|
---|
| 206 | print $page->output;
|
---|
| 207 |
|
---|
| 208 | # include the admin tools link in the output?
|
---|
| 209 | $footer->param(adminlink => ($IPDBacl{$authuser} =~ /A/));
|
---|
| 210 | $footer->param(webpath => $IPDB::webpath);
|
---|
| 211 | print $footer->output;
|
---|
| 212 |
|
---|
[106] | 213 | # Just in case something waaaayyy down isn't in place
|
---|
| 214 | # properly... we exit explicitly.
|
---|
[517] | 215 | exit 0;
|
---|
[4] | 216 |
|
---|
| 217 |
|
---|
| 218 | # Initial display: Show master blocks with total allocated subnets, total free subnets
|
---|
[118] | 219 | sub showSummary {
|
---|
[523] | 220 | my $masterlist = listSummary($ip_dbh);
|
---|
| 221 | $page->param(masterlist => $masterlist);
|
---|
[106] | 222 |
|
---|
[517] | 223 | $page->param(addmaster => ($IPDBacl{$authuser} =~ /a/) );
|
---|
[4] | 224 | } # showSummary
|
---|
| 225 |
|
---|
| 226 |
|
---|
| 227 | # Display detail on master
|
---|
| 228 | # Alrighty then! We're showing routed blocks within a single master this time.
|
---|
| 229 | # We should be able to steal code from showSummary(), and if I'm really smart
|
---|
| 230 | # I'll figger a way to munge the two together. (Once I've done that, everything
|
---|
| 231 | # else should follow. YMMV.)
|
---|
| 232 | sub showMaster {
|
---|
| 233 |
|
---|
[517] | 234 | $page->param(master => $webvar{block});
|
---|
| 235 | $page->param(delmaster => ($IPDBacl{$authuser} =~ /d/));
|
---|
[4] | 236 |
|
---|
[524] | 237 | my $rlist = listMaster($ip_dbh, $webvar{block});
|
---|
| 238 | $page->param(routedlist => $rlist);
|
---|
[4] | 239 |
|
---|
[527] | 240 | my $flist = listFree($ip_dbh, $webvar{block});
|
---|
[524] | 241 | $page->param(unrouted => $flist);
|
---|
[4] | 242 | } # showMaster
|
---|
| 243 |
|
---|
| 244 |
|
---|
| 245 | # Display details of a routed block
|
---|
| 246 | # Alrighty then! We're showing allocations within a routed block this time.
|
---|
| 247 | # We should be able to steal code from showSummary() and showMaster(), and if
|
---|
| 248 | # I'm really smart I'll figger a way to munge all three together. (Once I've
|
---|
| 249 | # done that, everything else should follow. YMMV.
|
---|
| 250 | # This time, we check the database before spewing, because we may
|
---|
| 251 | # not have anything useful to spew.
|
---|
| 252 | sub showRBlock {
|
---|
| 253 |
|
---|
[527] | 254 | $page->param(master => $webvar{block});
|
---|
| 255 | $page->param(delrouted => $IPDBacl{$authuser} =~ /d/);
|
---|
[4] | 256 |
|
---|
[527] | 257 | my $rcity = getRoutedCity($ip_dbh, $webvar{block});
|
---|
[517] | 258 | $page->param(rcity => $rcity);
|
---|
[4] | 259 |
|
---|
[527] | 260 | my $blist = listRBlock($ip_dbh, $webvar{block});
|
---|
| 261 | $page->param(blocklist => $blist);
|
---|
[4] | 262 |
|
---|
[527] | 263 | my $flist = listFree($ip_dbh, $webvar{block}, 'y');
|
---|
| 264 | $page->param(unassigned => $flist);
|
---|
[4] | 265 | } # showRBlock
|
---|
| 266 |
|
---|
| 267 |
|
---|
| 268 | # List the IPs used in a pool
|
---|
[528] | 269 | sub showPool {
|
---|
[4] | 270 |
|
---|
| 271 | my $cidr = new NetAddr::IP $webvar{pool};
|
---|
| 272 |
|
---|
[517] | 273 | $page->param(block => $webvar{pool});
|
---|
| 274 | $page->param(netip => $cidr->addr);
|
---|
| 275 | $cidr++;
|
---|
| 276 | $page->param(gate => $cidr->addr);
|
---|
| 277 | $cidr--; $cidr--;
|
---|
| 278 | $page->param(bcast => $cidr->addr);
|
---|
| 279 | $page->param(mask => $cidr->mask);
|
---|
[157] | 280 |
|
---|
[4] | 281 | # Snag pool info for heading
|
---|
[528] | 282 | my $poolinfo = getBlockData($ip_dbh, $webvar{pool});
|
---|
[4] | 283 |
|
---|
[528] | 284 | $page->param(disptype => $disp_alloctypes{$poolinfo->{type}});
|
---|
| 285 | $page->param(city => $poolinfo->{city});
|
---|
[517] | 286 |
|
---|
[157] | 287 | # Only display net/gw/bcast if it's a "real" netblock and not a PPP(oE) lunacy
|
---|
[528] | 288 | $page->param(realblock => $poolinfo->{type} =~ /^.d$/);
|
---|
[4] | 289 |
|
---|
| 290 | # probably have to add an "edit IP allocation" link here somewhere.
|
---|
| 291 |
|
---|
[528] | 292 | my $plist = listPool($ip_dbh, $webvar{pool});
|
---|
| 293 | # technically slightly more efficient to check the ACL in an if () once outside the foreach
|
---|
| 294 | foreach (@{$plist}) {
|
---|
| 295 | $$_{maydel} = $IPDBacl{$authuser} =~ /d/;
|
---|
[4] | 296 | }
|
---|
[528] | 297 | $page->param(poolips => $plist);
|
---|
| 298 | } # end showPool
|
---|
[4] | 299 |
|
---|
| 300 |
|
---|
[106] | 301 | # Show "Add new allocation" page. Note that the actual page may
|
---|
| 302 | # be one of two templates, and the lists come from the database.
|
---|
[4] | 303 | sub assignBlock {
|
---|
| 304 |
|
---|
[233] | 305 | if ($IPDBacl{$authuser} !~ /a/) {
|
---|
[517] | 306 | $aclerr = 'addblock';
|
---|
[233] | 307 | return;
|
---|
| 308 | }
|
---|
| 309 |
|
---|
[517] | 310 | # hack pthbttt eww
|
---|
| 311 | $webvar{block} = '' if !$webvar{block};
|
---|
[21] | 312 |
|
---|
[517] | 313 | # hmm. TMPL_IF block and TMPL_ELSE block on these instead?
|
---|
| 314 | $page->param(rowa => 'row'.($webvar{block} eq '' ? 1 : 0));
|
---|
| 315 | $page->param(rowb => 'row'.($webvar{block} eq '' ? 0 : 1));
|
---|
| 316 | $page->param(block => $webvar{block}); # fb-assign flag, if block is set, we're in fb-assign
|
---|
| 317 | $page->param(iscontained => ($webvar{fbtype} && $webvar{fbtype} ne 'y'));
|
---|
| 318 |
|
---|
[21] | 319 | # New special case- block to assign is specified
|
---|
| 320 | if ($webvar{block} ne '') {
|
---|
| 321 | my $block = new NetAddr::IP $webvar{block};
|
---|
[187] | 322 |
|
---|
[517] | 323 | # Handle contained freeblock allocation.
|
---|
[187] | 324 | # This is a little dangerous, as it's *theoretically* possible to
|
---|
| 325 | # get fbtype='n' (aka a non-routed freeblock). However, should
|
---|
| 326 | # someone manage to get there, they get what they deserve.
|
---|
| 327 | if ($webvar{fbtype} ne 'y') {
|
---|
[517] | 328 | # Snag the type of the container block from the database.
|
---|
[529] | 329 | ## hmm. need a flag for parent class/type, sort of?
|
---|
| 330 | my $pblock = getParent($ip_dbh, $webvar{block});
|
---|
| 331 | my $ptype = $pblock->{type};
|
---|
| 332 | $ptype =~ s/c$/r/;
|
---|
| 333 | $page->param(fbdisptype => $list_alloctypes{$ptype});
|
---|
| 334 | $page->param(type => $ptype);
|
---|
[187] | 335 | } else {
|
---|
[529] | 336 | # get "primary" alloctypes, since these are all that can correctly be assigned if we're in this branch
|
---|
| 337 | my $tlist = getTypeList($ip_dbh, 'p');
|
---|
| 338 | $tlist->[0]->{sel} = 1;
|
---|
| 339 | $page->param(typelist => $tlist);
|
---|
[106] | 340 | }
|
---|
[21] | 341 | } else {
|
---|
[517] | 342 | my @masterlist;
|
---|
[31] | 343 | foreach my $master (@masterblocks) {
|
---|
[517] | 344 | my %row = (master => "$master");
|
---|
| 345 | push (@masterlist, \%row);
|
---|
[31] | 346 | }
|
---|
[517] | 347 | $page->param(masterlist => \@masterlist);
|
---|
| 348 |
|
---|
| 349 | my @pops;
|
---|
[92] | 350 | foreach my $pop (@poplist) {
|
---|
[517] | 351 | my %row = (pop => $pop);
|
---|
| 352 | push (@pops, \%row);
|
---|
[92] | 353 | }
|
---|
[517] | 354 | $page->param(pops => \@pops);
|
---|
| 355 |
|
---|
[529] | 356 | # get all standard alloctypes
|
---|
| 357 | my $tlist = getTypeList($ip_dbh, 'a');
|
---|
| 358 | $tlist->[0]->{sel} = 1;
|
---|
| 359 | $page->param(typelist => $tlist);
|
---|
[21] | 360 | }
|
---|
[517] | 361 |
|
---|
| 362 | my @cities;
|
---|
[92] | 363 | foreach my $city (@citylist) {
|
---|
[517] | 364 | my %row = (city => $city);
|
---|
| 365 | push (@cities, \%row);
|
---|
[92] | 366 | }
|
---|
[517] | 367 | $page->param(citylist => \@cities);
|
---|
[4] | 368 |
|
---|
[397] | 369 | ## node hack
|
---|
[530] | 370 | my $nlist = getNodeList($ip_dbh);
|
---|
| 371 | $page->param(nodelist => $nlist);
|
---|
[397] | 372 | ## end node hack
|
---|
| 373 |
|
---|
[517] | 374 | $page->param(privdata => $IPDBacl{$authuser} =~ /s/);
|
---|
[284] | 375 |
|
---|
[4] | 376 | } # assignBlock
|
---|
| 377 |
|
---|
| 378 |
|
---|
| 379 | # Take info on requested IP assignment and see what we can provide.
|
---|
| 380 | sub confirmAssign {
|
---|
[233] | 381 | if ($IPDBacl{$authuser} !~ /a/) {
|
---|
[517] | 382 | $aclerr = 'addblock';
|
---|
[233] | 383 | return;
|
---|
| 384 | }
|
---|
[4] | 385 |
|
---|
| 386 | my $cidr;
|
---|
| 387 | my $alloc_from;
|
---|
| 388 |
|
---|
| 389 | # Going to manually validate some items.
|
---|
| 390 | # custid and city are automagic.
|
---|
[111] | 391 | return if !validateInput();
|
---|
[4] | 392 |
|
---|
| 393 | # Several different cases here.
|
---|
| 394 | # Static IP vs netblock
|
---|
| 395 | # + Different flavours of static IP
|
---|
| 396 | # + Different flavours of netblock
|
---|
| 397 |
|
---|
[157] | 398 | if ($webvar{alloctype} =~ /^.i$/) {
|
---|
[532] | 399 | my $plist = getPoolSelect($ip_dbh, $webvar{alloctype}, $webvar{pop});
|
---|
[517] | 400 | $page->param(staticip => 1);
|
---|
[532] | 401 | $page->param(poollist => $plist) if $plist;
|
---|
[4] | 402 | $cidr = "Single static IP";
|
---|
[517] | 403 | ##fixme: need to handle "no available pools"
|
---|
[4] | 404 |
|
---|
| 405 | } else { # end show pool options
|
---|
[21] | 406 |
|
---|
[533] | 407 | if ($webvar{fbassign} && $webvar{fbassign} eq 'y') {
|
---|
[21] | 408 | $cidr = new NetAddr::IP $webvar{block};
|
---|
| 409 | $webvar{maskbits} = $cidr->masklen;
|
---|
| 410 | } else { # done with direct freeblocks assignment
|
---|
| 411 |
|
---|
| 412 | if (!$webvar{maskbits}) {
|
---|
[517] | 413 | $page->param(err => "Please specify a CIDR mask length.");
|
---|
[111] | 414 | return;
|
---|
[21] | 415 | }
|
---|
[533] | 416 |
|
---|
| 417 | ##fixme ick, ew, bleh. gotta handle the failure message generation better. push it into findAllocateFrom()?
|
---|
| 418 | my $failmsg = "No suitable free block found.<br>\n";
|
---|
[187] | 419 | if ($webvar{alloctype} eq 'rm') {
|
---|
[533] | 420 | $failmsg .= "We do not have a free routeable block of that size.<br>\n".
|
---|
| 421 | "You will have to either route a set of smaller netblocks or a single smaller netblock.";
|
---|
[4] | 422 | } else {
|
---|
[214] | 423 | if ($webvar{alloctype} =~ /^.[pc]$/) {
|
---|
[533] | 424 | $failmsg .= "You will have to route another superblock from one of the<br>\n".
|
---|
| 425 | "master blocks or chose a smaller block size for the pool.";
|
---|
[21] | 426 | } else {
|
---|
[517] | 427 | if (!$webvar{pop}) {
|
---|
| 428 | $page->param(err => 'Please select a POP to route the block from/through.');
|
---|
| 429 | return;
|
---|
| 430 | }
|
---|
[533] | 431 | $failmsg .= "You will have to route another superblock to $webvar{pop}<br>\n".
|
---|
| 432 | "from one of the master blocks or chose a smaller blocksize.";
|
---|
[21] | 433 | }
|
---|
[4] | 434 | }
|
---|
[533] | 435 |
|
---|
| 436 | $cidr = findAllocateFrom($ip_dbh, $webvar{maskbits}, $webvar{alloctype}, $webvar{city}, $webvar{pop},
|
---|
| 437 | (master => $webvar{allocfrom}, allowpriv => $webvar{allowpriv}) );
|
---|
| 438 | if (!$cidr) {
|
---|
[517] | 439 | $page->param(err => $failmsg);
|
---|
[111] | 440 | return;
|
---|
[21] | 441 | }
|
---|
[533] | 442 | $cidr = new NetAddr::IP $cidr;
|
---|
[21] | 443 | } # check for freeblocks assignment or IPDB-controlled assignment
|
---|
[4] | 444 |
|
---|
[517] | 445 | $alloc_from = "$cidr";
|
---|
[4] | 446 |
|
---|
| 447 | # If the block to be allocated is smaller than the one we found,
|
---|
| 448 | # figure out the "real" block to be allocated.
|
---|
| 449 | if ($cidr->masklen() ne $webvar{maskbits}) {
|
---|
| 450 | my $maskbits = $cidr->masklen();
|
---|
| 451 | my @subblocks;
|
---|
| 452 | while ($maskbits++ < $webvar{maskbits}) {
|
---|
| 453 | @subblocks = $cidr->split($maskbits);
|
---|
| 454 | }
|
---|
| 455 | $cidr = $subblocks[0];
|
---|
| 456 | }
|
---|
[157] | 457 | } # if ($webvar{alloctype} =~ /^.i$/)
|
---|
[4] | 458 |
|
---|
[397] | 459 | ## node hack
|
---|
| 460 | if ($webvar{node} && $webvar{node} ne '-') {
|
---|
[530] | 461 | my $nodename = getNodeName($ip_dbh, $webvar{node});
|
---|
[517] | 462 | $page->param(nodename => $nodename);
|
---|
| 463 | $page->param(nodeid => $webvar{node});
|
---|
[397] | 464 | }
|
---|
| 465 | ## end node hack
|
---|
| 466 |
|
---|
[4] | 467 | # Stick in the allocation data
|
---|
[517] | 468 | $page->param(alloc_type => $webvar{alloctype});
|
---|
| 469 | $page->param(typefull => $q->escapeHTML($disp_alloctypes{$webvar{alloctype}}));
|
---|
| 470 | $page->param(alloc_from => $alloc_from);
|
---|
| 471 | $page->param(cidr => $cidr);
|
---|
| 472 | $page->param(city => $q->escapeHTML($webvar{city}));
|
---|
| 473 | $page->param(custid => $webvar{custid});
|
---|
| 474 | $page->param(circid => $q->escapeHTML($webvar{circid}));
|
---|
| 475 | $page->param(desc => $q->escapeHTML($webvar{desc}));
|
---|
[4] | 476 |
|
---|
[517] | 477 | ##fixme: find a way to have the displayed copy have <br> substitutions
|
---|
| 478 | # for newlines, and the <input> value have either encoded or bare newlines.
|
---|
| 479 | # Also applies to privdata.
|
---|
| 480 | $page->param(notes => $q->escapeHTML($webvar{notes},'y'));
|
---|
| 481 |
|
---|
[284] | 482 | # Check to see if user is allowed to do anything with sensitive data
|
---|
| 483 | my $privdata = '';
|
---|
[517] | 484 | $page->param(privdata => $q->escapeHTML($webvar{privdata},'y'))
|
---|
| 485 | if $IPDBacl{$authuser} =~ /s/;
|
---|
| 486 |
|
---|
| 487 | # Yay! This now has it's very own little home.
|
---|
| 488 | $page->param(billinguser => $webvar{userid})
|
---|
[299] | 489 | if $webvar{userid};
|
---|
[284] | 490 |
|
---|
[517] | 491 | ##fixme: this is only needed iff confirm.tmpl and
|
---|
| 492 | # confirmRemove.tmpl are merged (quite possible, just
|
---|
| 493 | # a little tedious)
|
---|
| 494 | $page->param(action => "insert");
|
---|
[284] | 495 |
|
---|
[4] | 496 | } # end confirmAssign
|
---|
| 497 |
|
---|
| 498 |
|
---|
| 499 | # Do the work of actually inserting a block in the database.
|
---|
| 500 | sub insertAssign {
|
---|
[233] | 501 | if ($IPDBacl{$authuser} !~ /a/) {
|
---|
[517] | 502 | $aclerr = 'addblock';
|
---|
[233] | 503 | return;
|
---|
| 504 | }
|
---|
[4] | 505 | # Some things are done more than once.
|
---|
[111] | 506 | return if !validateInput();
|
---|
[4] | 507 |
|
---|
[284] | 508 | if (!defined($webvar{privdata})) {
|
---|
| 509 | $webvar{privdata} = '';
|
---|
| 510 | }
|
---|
[106] | 511 | # $code is "success" vs "failure", $msg contains OK for a
|
---|
| 512 | # successful netblock allocation, the IP allocated for static
|
---|
| 513 | # IP, or the error message if an error occurred.
|
---|
[517] | 514 |
|
---|
[106] | 515 | my ($code,$msg) = allocateBlock($ip_dbh, $webvar{fullcidr}, $webvar{alloc_from},
|
---|
| 516 | $webvar{custid}, $webvar{alloctype}, $webvar{city}, $webvar{desc}, $webvar{notes},
|
---|
[397] | 517 | $webvar{circid}, $webvar{privdata}, $webvar{node});
|
---|
[4] | 518 |
|
---|
[111] | 519 | if ($code eq 'OK') {
|
---|
[106] | 520 | if ($webvar{alloctype} =~ /^.i$/) {
|
---|
[300] | 521 | $msg =~ s|/32||;
|
---|
[517] | 522 | $page->param(staticip => $msg);
|
---|
| 523 | $page->param(custid => $webvar{custid});
|
---|
| 524 | $page->param(billinguser => $webvar{billinguser});
|
---|
[416] | 525 | mailNotify($ip_dbh, "a$webvar{alloctype}", "ADDED: $disp_alloctypes{$webvar{alloctype}} allocation",
|
---|
| 526 | "$disp_alloctypes{$webvar{alloctype}} $msg allocated to customer $webvar{custid}\n".
|
---|
| 527 | "Description: $webvar{desc}\n\nAllocated by: $authuser\n");
|
---|
[106] | 528 | } else {
|
---|
[301] | 529 | my $netblock = new NetAddr::IP $webvar{fullcidr};
|
---|
[517] | 530 | $page->param(fullcidr => $webvar{fullcidr});
|
---|
| 531 | $page->param(alloctype => $disp_alloctypes{$webvar{alloctype}});
|
---|
| 532 | $page->param(custid => $webvar{custid});
|
---|
| 533 | if ($webvar{alloctype} eq 'pr' && $webvar{billinguser}) {
|
---|
| 534 | $page->param(billinguser => $webvar{billinguser});
|
---|
| 535 | $page->param(custid => $webvar{custid});
|
---|
| 536 | $page->param(netaddr => $netblock->addr);
|
---|
| 537 | $page->param(masklen => $netblock->masklen);
|
---|
| 538 | }
|
---|
[416] | 539 | mailNotify($ip_dbh, "a$webvar{alloctype}", "ADDED: $disp_alloctypes{$webvar{alloctype}} allocation",
|
---|
| 540 | "$disp_alloctypes{$webvar{alloctype}} $webvar{fullcidr} allocated to customer $webvar{custid}\n".
|
---|
| 541 | "Description: $webvar{desc}\n\nAllocated by: $authuser\n");
|
---|
[4] | 542 | }
|
---|
[106] | 543 | syslog "notice", "$authuser allocated '$webvar{fullcidr}' to '$webvar{custid}' as ".
|
---|
[256] | 544 | "'$webvar{alloctype}' ($msg)";
|
---|
[111] | 545 | } else {
|
---|
| 546 | syslog "err", "Allocation of '$webvar{fullcidr}' to '$webvar{custid}' as ".
|
---|
| 547 | "'$webvar{alloctype}' by $authuser failed: '$msg'";
|
---|
[517] | 548 | $page->param(err => "Allocation of $webvar{fullcidr} as '$disp_alloctypes{$webvar{alloctype}}'".
|
---|
[157] | 549 | " failed:<br>\n$msg\n");
|
---|
[106] | 550 | }
|
---|
[4] | 551 |
|
---|
| 552 | } # end insertAssign()
|
---|
| 553 |
|
---|
| 554 |
|
---|
| 555 | # Does some basic checks on common input data to make sure nothing
|
---|
| 556 | # *really* weird gets in to the database through this script.
|
---|
| 557 | # Does NOT do complete input validation!!!
|
---|
| 558 | sub validateInput {
|
---|
| 559 | if ($webvar{city} eq '-') {
|
---|
[517] | 560 | $page->param(err => 'Please choose a city');
|
---|
[111] | 561 | return;
|
---|
[4] | 562 | }
|
---|
[138] | 563 |
|
---|
| 564 | # Alloctype check.
|
---|
[4] | 565 | chomp $webvar{alloctype};
|
---|
[138] | 566 | if (!grep /$webvar{alloctype}/, keys %disp_alloctypes) {
|
---|
| 567 | # Danger! Danger! alloctype should ALWAYS be set by a dropdown. Anyone
|
---|
| 568 | # managing to call things in such a way as to cause this deserves a cryptic error.
|
---|
[517] | 569 | $page->param(err => 'Invalid alloctype');
|
---|
[138] | 570 | return;
|
---|
| 571 | }
|
---|
| 572 |
|
---|
| 573 | # CustID check
|
---|
[4] | 574 | # We have different handling for customer allocations and "internal" or "our" allocations
|
---|
[214] | 575 | if ($def_custids{$webvar{alloctype}} eq '') {
|
---|
[4] | 576 | if (!$webvar{custid}) {
|
---|
[517] | 577 | $page->param(err => 'Please enter a customer ID.');
|
---|
[111] | 578 | return;
|
---|
[4] | 579 | }
|
---|
[400] | 580 | if ($webvar{custid} !~ /^(?:\d{10}|\d{7}|STAFF)(?:-\d\d?)?$/) {
|
---|
| 581 | # Force uppercase for now...
|
---|
| 582 | $webvar{custid} =~ tr/a-z/A-Z/;
|
---|
| 583 | # Crosscheck with billing.
|
---|
| 584 | my $status = CustIDCK->custid_exist($webvar{custid});
|
---|
| 585 | if ($CustIDCK::Error) {
|
---|
[517] | 586 | $page->param(err => "Error verifying customer ID: ".$CustIDCK::ErrMsg);
|
---|
[400] | 587 | return;
|
---|
| 588 | }
|
---|
| 589 | if (!$status) {
|
---|
[517] | 590 | $page->param(err => "Customer ID not valid. Make sure the Customer ID ".
|
---|
[420] | 591 | "is correct.<br>\nUse STAFF for staff static IPs, and $IPDB::defcustid for any other ".
|
---|
[400] | 592 | "non-customer assignments.");
|
---|
| 593 | return;
|
---|
| 594 | }
|
---|
[4] | 595 | }
|
---|
[400] | 596 | # print "<!-- [ In validateInput(). Insert customer ID cross-check here. ] -->\n";
|
---|
[138] | 597 | } else {
|
---|
[167] | 598 | # New! Improved! And now Loaded From The Database!!
|
---|
[320] | 599 | if ((!$webvar{custid}) || ($webvar{custid} ne 'STAFF')) {
|
---|
| 600 | $webvar{custid} = $def_custids{$webvar{alloctype}};
|
---|
| 601 | }
|
---|
[4] | 602 | }
|
---|
[111] | 603 |
|
---|
| 604 | # Check POP location
|
---|
| 605 | my $flag;
|
---|
[187] | 606 | if ($webvar{alloctype} eq 'rm') {
|
---|
[111] | 607 | $flag = 'for a routed netblock';
|
---|
| 608 | foreach (@poplist) {
|
---|
| 609 | if (/^$webvar{city}$/) {
|
---|
| 610 | $flag = 'n';
|
---|
| 611 | last;
|
---|
| 612 | }
|
---|
| 613 | }
|
---|
| 614 | } else {
|
---|
| 615 | $flag = 'n';
|
---|
[442] | 616 | ##fixme: hook to force-set POP or city on certain alloctypes
|
---|
| 617 | # if ($webvar{alloctype =~ /foo,bar,bz/ { $webvar{pop} = 'blah'; }
|
---|
[400] | 618 | if ($webvar{pop} =~ /^-$/) {
|
---|
[111] | 619 | $flag = 'to route the block from/through';
|
---|
| 620 | }
|
---|
| 621 | }
|
---|
[517] | 622 |
|
---|
| 623 | # if the alloctype has a restricted city/POP list as determined above,
|
---|
| 624 | # and the reqested city/POP does not match that list, complain
|
---|
[111] | 625 | if ($flag ne 'n') {
|
---|
[517] | 626 | $page->param(err => "Please choose a valid POP location $flag. Valid ".
|
---|
[111] | 627 | "POP locations are currently:<br>\n".join (" - ", @poplist));
|
---|
| 628 | return;
|
---|
| 629 | }
|
---|
| 630 |
|
---|
| 631 | return 'OK';
|
---|
[4] | 632 | } # end validateInput
|
---|
| 633 |
|
---|
| 634 |
|
---|
| 635 | # Displays details of a specific allocation in a form
|
---|
| 636 | # Allows update/delete
|
---|
| 637 | # action=edit
|
---|
| 638 | sub edit {
|
---|
| 639 |
|
---|
| 640 | my $sql;
|
---|
| 641 |
|
---|
| 642 | # Two cases: block is a netblock, or block is a static IP from a pool
|
---|
| 643 | # because I'm lazy, we'll try to make the SELECT's bring out identical)ish) data
|
---|
[517] | 644 | ##fixme: allow "SWIP" (publication to rWHOIS) of static IP data
|
---|
[4] | 645 | if ($webvar{block} =~ /\/32$/) {
|
---|
[455] | 646 | $sql = "select ip,custid,type,city,circuitid,description,notes,modifystamp,privdata from poolips where ip='$webvar{block}'";
|
---|
[4] | 647 | } else {
|
---|
[455] | 648 | $sql = "select cidr,custid,type,city,circuitid,description,notes,modifystamp,privdata,swip from allocations where cidr='$webvar{block}'"
|
---|
[4] | 649 | }
|
---|
| 650 |
|
---|
| 651 | # gotta snag block info from db
|
---|
| 652 | $sth = $ip_dbh->prepare($sql);
|
---|
| 653 | $sth->execute;
|
---|
| 654 | my @data = $sth->fetchrow_array;
|
---|
| 655 |
|
---|
| 656 | # Clean up extra whitespace on alloc type
|
---|
| 657 | $data[2] =~ s/\s//;
|
---|
| 658 |
|
---|
| 659 | # We can't let the city be changed here; this block is a part of
|
---|
| 660 | # a larger routed allocation and therefore by definition can't be moved.
|
---|
| 661 | # block and city are static.
|
---|
| 662 | ##fixme
|
---|
| 663 | # Needs thinking. Have to allow changes to city to correct errors, no?
|
---|
[517] | 664 | # Also have areas where a routed block at a POP serves "many" cities/towns/named crossroads
|
---|
[4] | 665 |
|
---|
[517] | 666 | # @data: cidr,custid,type,city,circuitid,description,notes,modifystamp,privdata,swip
|
---|
[233] | 667 |
|
---|
[517] | 668 | $page->param(block => $webvar{block});
|
---|
[4] | 669 |
|
---|
[517] | 670 | $page->param(custid => $data[1]);
|
---|
| 671 | $page->param(city => $data[3]);
|
---|
| 672 | $page->param(circid => $data[4]);
|
---|
| 673 | $page->param(desc => $data[5]);
|
---|
| 674 | $page->param(notes => $data[6]);
|
---|
[4] | 675 |
|
---|
[187] | 676 | ##fixme The check here should be built from the database
|
---|
[517] | 677 | # Need to expand to support pool types too
|
---|
| 678 | if ($data[2] =~ /^.[ne]$/ && $IPDBacl{$authuser} =~ /c/) {
|
---|
| 679 | $page->param(changetype => 1);
|
---|
| 680 | $page->param(alloctype => [
|
---|
| 681 | { selme => ($data[2] eq 'me'), type => "me", disptype => "Dialup netblock" },
|
---|
| 682 | { selme => ($data[2] eq 'de'), type => "de", disptype => "Dynamic DSL netblock" },
|
---|
| 683 | { selme => ($data[2] eq 'ce'), type => "ce", disptype => "Dynamic cable netblock" },
|
---|
| 684 | { selme => ($data[2] eq 'we'), type => "we", disptype => "Dynamic wireless netblock" },
|
---|
| 685 | { selme => ($data[2] eq 'cn'), type => "cn", disptype => "Customer netblock" },
|
---|
| 686 | { selme => ($data[2] eq 'en'), type => "en", disptype => "End-use netblock" },
|
---|
| 687 | { selme => ($data[2] eq 'in'), type => "in", disptype => "Internal netblock" },
|
---|
| 688 | ]
|
---|
| 689 | );
|
---|
| 690 | } else {
|
---|
| 691 | $page->param(disptype => $disp_alloctypes{$data[2]});
|
---|
| 692 | $page->param(type => $data[2]);
|
---|
| 693 | }
|
---|
| 694 |
|
---|
[397] | 695 | ## node hack
|
---|
[530] | 696 | my ($nodeid,$nodename) = getNodeInfo($ip_dbh, $webvar{block});
|
---|
[517] | 697 | $page->param(havenodeid => $nodeid);
|
---|
| 698 |
|
---|
| 699 | if ($data[2] eq 'fr' || $data[2] eq 'bi') {
|
---|
| 700 | $page->param(typesupportsnodes => 1);
|
---|
| 701 | $page->param(nodename => $nodename);
|
---|
| 702 |
|
---|
| 703 | ##fixme: this whole hack needs cleanup and generalization for all alloctypes
|
---|
| 704 | ##fixme: arguably a bug that presence of a nodeid implies it can be changed..
|
---|
| 705 | # but except for manual database changes, only the two types fr and bi can
|
---|
| 706 | # (currently) have a nodeid set in the first place.
|
---|
| 707 | if ($IPDBacl{$authuser} =~ /c/) {
|
---|
[530] | 708 | my $nlist = getNodeList($ip_dbh);
|
---|
| 709 | foreach (@{$nlist}) {
|
---|
| 710 | $$_{selme} = ($$_{node_id} == $nodeid);
|
---|
[397] | 711 | }
|
---|
[530] | 712 | $page->param(nodelist => $nlist);
|
---|
[397] | 713 | }
|
---|
| 714 | }
|
---|
| 715 | ## end node hack
|
---|
[517] | 716 |
|
---|
[255] | 717 | my ($lastmod,undef) = split /\s+/, $data[7];
|
---|
[517] | 718 | $page->param(lastmod => $lastmod);
|
---|
[33] | 719 |
|
---|
[517] | 720 | # not happy with the upside-down logic, but...
|
---|
| 721 | $page->param(swipable => $data[2] !~ /.i/);
|
---|
| 722 | $page->param(swip => $data[10] ne 'n');
|
---|
[320] | 723 |
|
---|
[284] | 724 | # Check to see if we can display sensitive data
|
---|
[517] | 725 | $page->param(nocling => $IPDBacl{$authuser} =~ /s/);
|
---|
| 726 | $page->param(privdata => $data[8]);
|
---|
[284] | 727 |
|
---|
[517] | 728 | # ACL trickery - these two template booleans control the presence of all form/input tags
|
---|
| 729 | $page->param(maychange => $IPDBacl{$authuser} =~ /c/);
|
---|
| 730 | $page->param(maydel => $IPDBacl{$authuser} =~ /d/);
|
---|
[4] | 731 |
|
---|
| 732 | } # edit()
|
---|
| 733 |
|
---|
| 734 |
|
---|
| 735 | # Stuff new info about a block into the db
|
---|
| 736 | # action=update
|
---|
| 737 | sub update {
|
---|
[284] | 738 | if ($IPDBacl{$authuser} !~ /c/) {
|
---|
[517] | 739 | $aclerr = 'updateblock';
|
---|
[284] | 740 | return;
|
---|
| 741 | }
|
---|
[4] | 742 |
|
---|
| 743 | # Make sure incoming data is in correct format - custID among other things.
|
---|
[228] | 744 | return if !validateInput;
|
---|
[4] | 745 |
|
---|
[531] | 746 | my %updargs = (
|
---|
| 747 | custid => $webvar{custid},
|
---|
| 748 | city => $webvar{city},
|
---|
| 749 | description => $webvar{desc},
|
---|
| 750 | notes => $webvar{notes},
|
---|
| 751 | circuitid => $webvar{circid},
|
---|
| 752 | block => $webvar{block},
|
---|
| 753 | type => $webvar{alloctype},
|
---|
| 754 | );
|
---|
| 755 |
|
---|
| 756 | # Semioptional values
|
---|
| 757 | $updargs{privdata} = $webvar{privdata} if $IPDBacl{$authuser} =~ /s/;
|
---|
| 758 | $updargs{node} = $webvar{node} if $webvar{node};
|
---|
| 759 |
|
---|
| 760 | my ($code,$msg) = updateBlock($ip_dbh, %updargs);
|
---|
| 761 |
|
---|
| 762 | if ($code eq 'FAIL') {
|
---|
[166] | 763 | syslog "err", "$authuser could not update block/IP '$webvar{block}': '$msg'";
|
---|
[517] | 764 | $page->param(err => "Could not update block/IP $webvar{block}: $msg");
|
---|
[111] | 765 | return;
|
---|
[4] | 766 | }
|
---|
| 767 |
|
---|
| 768 | # If we get here, the operation succeeded.
|
---|
| 769 | syslog "notice", "$authuser updated $webvar{block}";
|
---|
[531] | 770 | ##fixme: log details of the change? old way is in the .debug stream anyway.
|
---|
[416] | 771 | ##fixme: need to wedge something in to allow "update:field" notifications
|
---|
| 772 | ## hmm. how to tell what changed? O_o
|
---|
[426] | 773 | mailNotify($ip_dbh, 's:swi', "SWIPed: $disp_alloctypes{$webvar{alloctype}} $webvar{block}",
|
---|
[416] | 774 | "$webvar{block} had SWIP status changed to \"Yes\" by $authuser") if $webvar{swip} eq 'on';
|
---|
[4] | 775 |
|
---|
[517] | 776 | ## node hack
|
---|
| 777 | if ($webvar{node} && $webvar{node} ne '-') {
|
---|
[530] | 778 | my $nodename = getNodeName($ip_dbh, $webvar{node});
|
---|
[517] | 779 | $page->param(nodename => $nodename);
|
---|
| 780 | }
|
---|
| 781 | ## end node hack
|
---|
| 782 |
|
---|
[380] | 783 | # Link back to browse-routed or list-pool page on "Update complete" page.
|
---|
| 784 | my $cblock; # to contain the CIDR of the container block we're retrieving.
|
---|
| 785 | my $sql;
|
---|
| 786 | if (my $pooltype = ($webvar{alloctype} =~ /^(.)i$/) ) {
|
---|
[517] | 787 | $page->param(backpool => 1);
|
---|
[380] | 788 | $sql = "select pool from poolips where ip='$webvar{block}'";
|
---|
| 789 | } else {
|
---|
| 790 | $sql = "select cidr from routed where cidr >>= '$webvar{block}'";
|
---|
| 791 | }
|
---|
| 792 | # I define there to be no errors on this operation... so we don't need to check for them.
|
---|
| 793 | $sth = $ip_dbh->prepare($sql);
|
---|
| 794 | $sth->execute;
|
---|
| 795 | $sth->bind_columns(\$cblock);
|
---|
| 796 | $sth->fetch();
|
---|
| 797 | $sth->finish;
|
---|
[517] | 798 | $page->param(backblock => $cblock);
|
---|
[380] | 799 |
|
---|
[517] | 800 | $page->param(cidr => $webvar{block});
|
---|
| 801 | $page->param(city => $webvar{city});
|
---|
| 802 | $page->param(disptype => $disp_alloctypes{$webvar{alloctype}});
|
---|
| 803 | $page->param(custid => $webvar{custid});
|
---|
| 804 | $page->param(swip => $webvar{swip} eq 'on' ? 'Yes' : 'No');
|
---|
| 805 | $page->param(circid => $q->escapeHTML($webvar{circid}));
|
---|
| 806 | $page->param(desc => $q->escapeHTML($webvar{desc}));
|
---|
| 807 | $page->param(notes => $q->escapeHTML($webvar{notes}));
|
---|
| 808 | $webvar{privdata} = ($webvar{privdata} ? $q->escapeHTML($webvar{privdata}) : " ");
|
---|
| 809 | $page->param(privdata => $webvar{privdata})
|
---|
| 810 | if $IPDBacl{$authuser} =~ /s/;
|
---|
[4] | 811 |
|
---|
| 812 | } # update()
|
---|
| 813 |
|
---|
| 814 |
|
---|
| 815 | # Delete an allocation.
|
---|
[106] | 816 | sub remove {
|
---|
[233] | 817 | if ($IPDBacl{$authuser} !~ /d/) {
|
---|
[517] | 818 | $aclerr = 'delblock';
|
---|
[233] | 819 | return;
|
---|
| 820 | }
|
---|
| 821 |
|
---|
[4] | 822 | # Serves'em right for getting here...
|
---|
| 823 | if (!defined($webvar{block})) {
|
---|
[517] | 824 | $page->param(err => "Can't delete a block that doesn't exist");
|
---|
[111] | 825 | return;
|
---|
[4] | 826 | }
|
---|
| 827 |
|
---|
[284] | 828 | my ($cidr, $custid, $type, $city, $circid, $desc, $notes, $alloctype, $privdata);
|
---|
[4] | 829 |
|
---|
[187] | 830 | if ($webvar{alloctype} eq 'rm') {
|
---|
[4] | 831 | $sth = $ip_dbh->prepare("select cidr,city from routed where cidr='$webvar{block}'");
|
---|
| 832 | $sth->execute();
|
---|
| 833 |
|
---|
| 834 | # This feels... extreme.
|
---|
| 835 | croak $sth->errstr() if($sth->errstr());
|
---|
| 836 |
|
---|
| 837 | $sth->bind_columns(\$cidr,\$city);
|
---|
| 838 | $sth->execute();
|
---|
| 839 | $sth->fetch || croak $sth->errstr();
|
---|
| 840 | $custid = "N/A";
|
---|
| 841 | $alloctype = $webvar{alloctype};
|
---|
[74] | 842 | $circid = "N/A";
|
---|
[4] | 843 | $desc = "N/A";
|
---|
| 844 | $notes = "N/A";
|
---|
[517] | 845 | $privdata = "N/A";
|
---|
[4] | 846 |
|
---|
| 847 | } elsif ($webvar{alloctype} eq 'mm') {
|
---|
[517] | 848 |
|
---|
[4] | 849 | $cidr = $webvar{block};
|
---|
| 850 | $city = "N/A";
|
---|
| 851 | $custid = "N/A";
|
---|
| 852 | $alloctype = $webvar{alloctype};
|
---|
[74] | 853 | $circid = "N/A";
|
---|
[4] | 854 | $desc = "N/A";
|
---|
| 855 | $notes = "N/A";
|
---|
[517] | 856 | $privdata = "N/A";
|
---|
| 857 |
|
---|
[189] | 858 | } elsif ($webvar{alloctype} =~ /^.i$/) { # done with alloctype=[rm]m
|
---|
[4] | 859 |
|
---|
| 860 | # Unassigning a static IP
|
---|
[284] | 861 | my $sth = $ip_dbh->prepare("select ip,custid,city,type,notes,circuitid,privdata".
|
---|
| 862 | " from poolips where ip='$webvar{block}'");
|
---|
[4] | 863 | $sth->execute();
|
---|
| 864 | # croak $sth->errstr() if($sth->errstr());
|
---|
| 865 |
|
---|
[284] | 866 | $sth->bind_columns(\$cidr, \$custid, \$city, \$alloctype, \$notes, \$circid,
|
---|
| 867 | \$privdata);
|
---|
[4] | 868 | $sth->fetch() || croak $sth->errstr;
|
---|
| 869 |
|
---|
[157] | 870 | } else { # done with alloctype=~ /^.i$/
|
---|
[4] | 871 |
|
---|
[284] | 872 | my $sth = $ip_dbh->prepare("select cidr,custid,type,city,circuitid,description,notes,privdata".
|
---|
| 873 | " from allocations where cidr='$webvar{block}'");
|
---|
[4] | 874 | $sth->execute();
|
---|
| 875 | # croak $sth->errstr() if($sth->errstr());
|
---|
| 876 |
|
---|
[284] | 877 | $sth->bind_columns(\$cidr, \$custid, \$alloctype, \$city, \$circid, \$desc,
|
---|
| 878 | \$notes, \$privdata);
|
---|
[74] | 879 | $sth->fetch() || carp $sth->errstr;
|
---|
[4] | 880 | } # end cases for different alloctypes
|
---|
| 881 |
|
---|
[517] | 882 | $page->param(block => $cidr);
|
---|
| 883 | $page->param(disptype => $disp_alloctypes{$alloctype});
|
---|
| 884 | $page->param(type => $alloctype);
|
---|
| 885 | $page->param(city => $city);
|
---|
| 886 | $page->param(custid => $custid);
|
---|
| 887 | $page->param(circid => $circid);
|
---|
| 888 | $page->param(desc => $desc);
|
---|
| 889 | $page->param(notes => $notes);
|
---|
| 890 | $privdata = ' ' if $privdata eq '';
|
---|
| 891 | $page->param(privdata => $privdata) if $IPDBacl{$authuser} =~ /s/;
|
---|
| 892 | $page->param(delpool => $alloctype =~ /^.[pd]$/);
|
---|
[4] | 893 |
|
---|
[517] | 894 | } # end remove()
|
---|
[4] | 895 |
|
---|
| 896 |
|
---|
| 897 | # Delete an allocation. Return it to the freeblocks table; munge
|
---|
| 898 | # data as necessary to keep as few records as possible in freeblocks
|
---|
| 899 | # to prevent weirdness when allocating blocks later.
|
---|
| 900 | # Remove IPs from pool listing if necessary
|
---|
| 901 | sub finalDelete {
|
---|
[233] | 902 | if ($IPDBacl{$authuser} !~ /d/) {
|
---|
[517] | 903 | $aclerr = 'delblock';
|
---|
[233] | 904 | return;
|
---|
| 905 | }
|
---|
[4] | 906 |
|
---|
[370] | 907 | # need to retrieve block data before deleting so we can notify on that
|
---|
[528] | 908 | my $blockinfo = getBlockData($ip_dbh, $webvar{block});
|
---|
[370] | 909 |
|
---|
[106] | 910 | my ($code,$msg) = deleteBlock($ip_dbh, $webvar{block}, $webvar{alloctype});
|
---|
[4] | 911 |
|
---|
[517] | 912 | $page->param(block => $webvar{block});
|
---|
[106] | 913 | if ($code eq 'OK') {
|
---|
[528] | 914 | syslog "notice", "$authuser deallocated '$webvar{alloctype}'-type netblock $webvar{block} ".
|
---|
| 915 | $blockinfo->{custid}.", ".$blockinfo->{city}.", desc='".$blockinfo->{description}."'";
|
---|
[416] | 916 | mailNotify($ip_dbh, 'da', "REMOVED: $disp_alloctypes{$webvar{alloctype}} $webvar{block}",
|
---|
| 917 | "$disp_alloctypes{$webvar{alloctype}} $webvar{block} deallocated by $authuser\n".
|
---|
[528] | 918 | "CustID: ".$blockinfo->{custid}."\nCity: ".$blockinfo->{city}.
|
---|
| 919 | "\nDescription: ".$blockinfo->{description}."\n");
|
---|
[106] | 920 | } else {
|
---|
[517] | 921 | $page->param(failmsg => $msg);
|
---|
[106] | 922 | if ($webvar{alloctype} =~ /^.i$/) {
|
---|
| 923 | syslog "err", "$authuser could not deallocate static IP '$webvar{block}': '$msg'";
|
---|
| 924 | } else {
|
---|
| 925 | syslog "err", "$authuser could not deallocate netblock '$webvar{block}': '$msg'";
|
---|
[517] | 926 | $page->param(netblock => 1);
|
---|
[4] | 927 | }
|
---|
[106] | 928 | }
|
---|
[4] | 929 |
|
---|
| 930 | } # finalDelete
|
---|