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