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