[4] | 1 | #!/usr/bin/perl
|
---|
| 2 | # ipdb/cgi-bin/main.cgi
|
---|
[8] | 3 | ###
|
---|
| 4 | # SVN revision info
|
---|
| 5 | # $Date: 2015-05-06 21:28:38 +0000 (Wed, 06 May 2015) $
|
---|
| 6 | # SVN revision $Rev: 717 $
|
---|
| 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;
|
---|
[582] | 19 | use Frontier::Client;
|
---|
[4] | 20 |
|
---|
| 21 | use Sys::Syslog;
|
---|
| 22 |
|
---|
[417] | 23 | # don't remove! required for GNU/FHS-ish install from tarball
|
---|
| 24 | ##uselib##
|
---|
| 25 |
|
---|
[515] | 26 | use CustIDCK;
|
---|
[417] | 27 | use MyIPDB;
|
---|
| 28 |
|
---|
[431] | 29 | openlog "IPDB","pid","$IPDB::syslog_facility";
|
---|
[4] | 30 |
|
---|
[517] | 31 | ## Environment. Collect some things, process some things, set some things...
|
---|
| 32 |
|
---|
[233] | 33 | # Collect the username from HTTP auth. If undefined, we're in
|
---|
| 34 | # a test environment, or called without a username.
|
---|
[4] | 35 | my $authuser;
|
---|
| 36 | if (!defined($ENV{'REMOTE_USER'})) {
|
---|
| 37 | $authuser = '__temptest';
|
---|
| 38 | } else {
|
---|
| 39 | $authuser = $ENV{'REMOTE_USER'};
|
---|
| 40 | }
|
---|
| 41 |
|
---|
[517] | 42 | # anyone got a better name? :P
|
---|
| 43 | my $thingroot = $ENV{SCRIPT_FILENAME};
|
---|
| 44 | $thingroot =~ s|cgi-bin/main.cgi||;
|
---|
| 45 |
|
---|
[402] | 46 | syslog "debug", "$authuser active, $ENV{'REMOTE_ADDR'}";
|
---|
[4] | 47 |
|
---|
[517] | 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 |
|
---|
[106] | 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;
|
---|
[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");
|
---|
[697] | 76 | my $utilbar = HTML::Template->new(filename => "utilbar.tmpl", loop_context_vars => 1, global_vars => 1);
|
---|
[233] | 77 |
|
---|
[697] | 78 | print "Content-type: text/html\n\n";
|
---|
| 79 |
|
---|
[517] | 80 | $header->param(version => $IPDB::VERSION);
|
---|
| 81 | $header->param(addperm => $IPDBacl{$authuser} =~ /a/);
|
---|
| 82 | $header->param(webpath => $IPDB::webpath);
|
---|
[4] | 83 |
|
---|
[697] | 84 | $utilbar->param(webpath => $IPDB::webpath);
|
---|
[4] | 85 |
|
---|
[697] | 86 | print $header->output;
|
---|
| 87 |
|
---|
| 88 |
|
---|
[4] | 89 | #main()
|
---|
[517] | 90 | my $aclerr;
|
---|
[4] | 91 |
|
---|
| 92 | if(!defined($webvar{action})) {
|
---|
[517] | 93 | $webvar{action} = "index"; #shuts up the warnings.
|
---|
[4] | 94 | }
|
---|
| 95 |
|
---|
[517] | 96 | my $page;
|
---|
| 97 | if (-e "$ENV{HTML_TEMPLATE_ROOT}/$webvar{action}.tmpl") {
|
---|
[553] | 98 | $page = HTML::Template->new(filename => "$webvar{action}.tmpl", loop_context_vars => 1, global_vars => 1);
|
---|
[517] | 99 | } else {
|
---|
| 100 | $page = HTML::Template->new(filename => "dunno.tmpl");
|
---|
| 101 | }
|
---|
| 102 |
|
---|
[4] | 103 | if($webvar{action} eq 'index') {
|
---|
| 104 | showSummary();
|
---|
[233] | 105 | } elsif ($webvar{action} eq 'addmaster') {
|
---|
| 106 | if ($IPDBacl{$authuser} !~ /a/) {
|
---|
[517] | 107 | $aclerr = 'addmaster';
|
---|
[233] | 108 | }
|
---|
[582] | 109 |
|
---|
| 110 | # Retrieve the list of DNS locations if we've got a place to grab them from
|
---|
| 111 | if ($IPDB::rpc_url) {
|
---|
| 112 |
|
---|
| 113 | my %rpcargs = (
|
---|
| 114 | rpcuser => $authuser,
|
---|
| 115 | group => 1, # bleh
|
---|
| 116 | defloc => '',
|
---|
| 117 | );
|
---|
[623] | 118 | my $result = IPDB::_rpc('getLocDropdown', %rpcargs);
|
---|
[582] | 119 | $page->param(loclist => $result);
|
---|
| 120 | }
|
---|
| 121 |
|
---|
[4] | 122 | } elsif ($webvar{action} eq 'newmaster') {
|
---|
| 123 |
|
---|
[233] | 124 | if ($IPDBacl{$authuser} !~ /a/) {
|
---|
[517] | 125 | $aclerr = 'addmaster';
|
---|
[233] | 126 | } else {
|
---|
| 127 | my $cidr = new NetAddr::IP $webvar{cidr};
|
---|
[517] | 128 | $page->param(cidr => "$cidr");
|
---|
[4] | 129 |
|
---|
[582] | 130 | my ($code,$msg) = addMaster($ip_dbh, $webvar{cidr}, (vrf => $webvar{vrf}, rdns => $webvar{rdns},
|
---|
| 131 | rwhois => $webvar{rwhois}, defloc => $webvar{loc}, user => $authuser) );
|
---|
[4] | 132 |
|
---|
[371] | 133 | if ($code eq 'FAIL') {
|
---|
[320] | 134 | syslog "err", "Could not add master block '$webvar{cidr}' to database: '$msg'";
|
---|
[517] | 135 | $page->param(err => $msg);
|
---|
[233] | 136 | } else {
|
---|
[624] | 137 | $page->param(parent => $msg);
|
---|
[582] | 138 | if ($code eq 'WARN') {
|
---|
[624] | 139 | $IPDB::errstr =~ s/\n\n/<br>\n/g;
|
---|
| 140 | $IPDB::errstr =~ s/:\n/:<br>\n/g;
|
---|
| 141 | $page->param(warn => $IPDB::errstr);
|
---|
[582] | 142 | }
|
---|
[233] | 143 | syslog "info", "$authuser added master block $webvar{cidr}";
|
---|
| 144 | }
|
---|
[4] | 145 |
|
---|
[233] | 146 | } # ACL check
|
---|
| 147 |
|
---|
[4] | 148 | } # end add new master
|
---|
| 149 |
|
---|
[567] | 150 | elsif ($webvar{action} eq 'showsubs') {
|
---|
| 151 | showSubs();
|
---|
| 152 | }
|
---|
| 153 |
|
---|
[4] | 154 | elsif($webvar{action} eq 'listpool') {
|
---|
[528] | 155 | showPool();
|
---|
[4] | 156 | }
|
---|
| 157 |
|
---|
| 158 | # Not modified or added; just shuffled
|
---|
| 159 | elsif($webvar{action} eq 'assign') {
|
---|
| 160 | assignBlock();
|
---|
| 161 | }
|
---|
| 162 | elsif($webvar{action} eq 'confirm') {
|
---|
| 163 | confirmAssign();
|
---|
| 164 | }
|
---|
| 165 | elsif($webvar{action} eq 'insert') {
|
---|
| 166 | insertAssign();
|
---|
| 167 | }
|
---|
| 168 | elsif($webvar{action} eq 'edit') {
|
---|
| 169 | edit();
|
---|
| 170 | }
|
---|
| 171 | elsif($webvar{action} eq 'update') {
|
---|
| 172 | update();
|
---|
| 173 | }
|
---|
[702] | 174 | elsif($webvar{action} eq 'split') {
|
---|
| 175 | prepSplit();
|
---|
| 176 | }
|
---|
| 177 | elsif($webvar{action} eq 'dosplit') {
|
---|
| 178 | doSplit();
|
---|
| 179 | }
|
---|
[717] | 180 | elsif($webvar{action} eq 'merge') {
|
---|
| 181 | prepMerge();
|
---|
| 182 | }
|
---|
[4] | 183 | elsif($webvar{action} eq 'delete') {
|
---|
| 184 | remove();
|
---|
| 185 | }
|
---|
| 186 | elsif($webvar{action} eq 'finaldelete') {
|
---|
| 187 | finalDelete();
|
---|
| 188 | }
|
---|
[397] | 189 | elsif ($webvar{action} eq 'nodesearch') {
|
---|
[519] | 190 | my $nodelist = getNodeList($ip_dbh);
|
---|
| 191 | $page->param(nodelist => $nodelist);
|
---|
[517] | 192 | }
|
---|
[397] | 193 |
|
---|
[517] | 194 | # DB failure. Can't do much here, really.
|
---|
| 195 | elsif ($webvar{action} eq 'dberr') {
|
---|
| 196 | $page->param(errmsg => $errstr);
|
---|
[397] | 197 | }
|
---|
| 198 |
|
---|
[517] | 199 | # Default is an error. It shouldn't be possible to get here unless you're
|
---|
| 200 | # randomly feeding in values for webvar{action}.
|
---|
[4] | 201 | else {
|
---|
| 202 | my $rnd = rand 500;
|
---|
| 203 | my $boing = sprintf("%.2f", rand 500);
|
---|
[517] | 204 | my @excuses = (
|
---|
| 205 | "Aether cloudy. Ask again later about $webvar{action}.",
|
---|
| 206 | "The gods are unhappy with your sacrificial $webvar{action}.",
|
---|
| 207 | "Because one of $webvar{action}'s legs are both the same",
|
---|
| 208 | "<b>wibble</b><br>Can't $webvar{action}, the grue will get me!<br>Can't $webvar{action}, the grue will get me!",
|
---|
| 209 | "Hey, man, you've had your free $webvar{action}. Next one's gonna... <i>cost</i>....",
|
---|
| 210 | "I ain't done $webvar{action}",
|
---|
| 211 | "Oooo, look! A flying $webvar{action}!",
|
---|
| 212 | "$webvar{action} too evil, avoiding.",
|
---|
| 213 | "Rocks fall, $webvar{action} dies.",
|
---|
| 214 | "Bit bucket must be emptied before I can $webvar{action}..."
|
---|
| 215 | );
|
---|
| 216 | $page->param(dunno => $excuses[$rnd/50.0]);
|
---|
[4] | 217 | }
|
---|
[111] | 218 | ## Finally! Done with that NASTY "case" emulation!
|
---|
[4] | 219 |
|
---|
| 220 |
|
---|
[517] | 221 | # Switch to a different template if we've tripped on an ACL error.
|
---|
| 222 | # Note that this should only be exercised in development, when
|
---|
| 223 | # deeplinked, or when being attacked; normal ACL handling should
|
---|
| 224 | # remove the links a user is not allowed to click on.
|
---|
| 225 | if ($aclerr) {
|
---|
| 226 | $page = HTML::Template->new(filename => "aclerror.tmpl");
|
---|
| 227 | $page->param(ipdbfunc => $aclmsg{$aclerr});
|
---|
| 228 | }
|
---|
[4] | 229 |
|
---|
[106] | 230 | # Clean up IPDB globals, DB handle, etc.
|
---|
[111] | 231 | finish($ip_dbh);
|
---|
[199] | 232 |
|
---|
[517] | 233 | ## Do all our printing here so we can generate errors and stick them into the slots in the templates.
|
---|
[199] | 234 |
|
---|
[517] | 235 | # can't do this yet, too many blowups
|
---|
| 236 | #print "Content-type: text/html\n\n", $header->output;
|
---|
| 237 | $page->param(webpath => $IPDB::webpath);
|
---|
[697] | 238 | print $utilbar->output;
|
---|
[517] | 239 | print $page->output;
|
---|
| 240 |
|
---|
| 241 | # include the admin tools link in the output?
|
---|
| 242 | $footer->param(adminlink => ($IPDBacl{$authuser} =~ /A/));
|
---|
| 243 | $footer->param(webpath => $IPDB::webpath);
|
---|
| 244 | print $footer->output;
|
---|
| 245 |
|
---|
[106] | 246 | # Just in case something waaaayyy down isn't in place
|
---|
| 247 | # properly... we exit explicitly.
|
---|
[517] | 248 | exit 0;
|
---|
[4] | 249 |
|
---|
| 250 |
|
---|
| 251 | # Initial display: Show master blocks with total allocated subnets, total free subnets
|
---|
[118] | 252 | sub showSummary {
|
---|
[523] | 253 | my $masterlist = listSummary($ip_dbh);
|
---|
| 254 | $page->param(masterlist => $masterlist);
|
---|
[106] | 255 |
|
---|
[517] | 256 | $page->param(addmaster => ($IPDBacl{$authuser} =~ /a/) );
|
---|
[4] | 257 | } # showSummary
|
---|
| 258 |
|
---|
| 259 |
|
---|
[566] | 260 | # Display blocks immediately within a given parent
|
---|
| 261 | sub showSubs {
|
---|
[682] | 262 | # Which layout?
|
---|
| 263 | if ($IPDB::sublistlayout == 2) {
|
---|
| 264 |
|
---|
| 265 | # 2-part layout; mixed containers and end-use allocations and free blocks.
|
---|
| 266 | # Containers have a second line for the subblock metadata.
|
---|
| 267 | # We need to load an alternate template for this case.
|
---|
| 268 | $page = HTML::Template->new(filename => "showsubs2.tmpl", loop_context_vars => 1, global_vars => 1);
|
---|
| 269 |
|
---|
| 270 | $page->param(maydel => ($IPDBacl{$authuser} =~ /d/));
|
---|
| 271 |
|
---|
| 272 | my $sublist = listSubs($ip_dbh, parent => $webvar{parent});
|
---|
| 273 | $page->param(sublist => $sublist);
|
---|
| 274 |
|
---|
| 275 | } else {
|
---|
| 276 |
|
---|
[685] | 277 | # 3-part layout; containers, end-use allocations, and free blocks
|
---|
[682] | 278 |
|
---|
| 279 | my $contlist = listContainers($ip_dbh, parent => $webvar{parent});
|
---|
| 280 | $page->param(contlist => $contlist);
|
---|
| 281 |
|
---|
| 282 | my $alloclist = listAllocations($ip_dbh, parent => $webvar{parent});
|
---|
| 283 | $page->param(alloclist => $alloclist);
|
---|
| 284 |
|
---|
| 285 | # only show "delete" button if we have no container or usage allocations
|
---|
| 286 | $page->param(maydel => ($IPDBacl{$authuser} =~ /d/) && !(@$contlist || @$alloclist));
|
---|
| 287 |
|
---|
| 288 | }
|
---|
| 289 |
|
---|
| 290 | # Common elements
|
---|
[627] | 291 | my $pinfo = getBlockData($ip_dbh, $webvar{parent});
|
---|
| 292 |
|
---|
[685] | 293 | ##fixme: do we add a wrapper to not show the edit link for master blocks?
|
---|
| 294 | #$page->param(editme => 1) unless $pinfo->{type} ne 'mm';
|
---|
| 295 |
|
---|
[697] | 296 | my $crumbs = getBreadCrumbs($ip_dbh, $pinfo->{parent_id});
|
---|
| 297 | my @rcrumbs = reverse (@$crumbs);
|
---|
| 298 | $utilbar->param(breadcrumb => \@rcrumbs);
|
---|
| 299 |
|
---|
[685] | 300 | $page->param(self_id => $webvar{parent});
|
---|
[627] | 301 | $page->param(block => $pinfo->{block});
|
---|
[566] | 302 | $page->param(mayadd => ($IPDBacl{$authuser} =~ /a/));
|
---|
[4] | 303 |
|
---|
[627] | 304 | my $flist = listFree($ip_dbh, parent => $webvar{parent});
|
---|
[566] | 305 | $page->param(freelist => $flist);
|
---|
| 306 | } # showSubs
|
---|
[4] | 307 |
|
---|
| 308 |
|
---|
| 309 | # List the IPs used in a pool
|
---|
[528] | 310 | sub showPool {
|
---|
[4] | 311 |
|
---|
[631] | 312 | my $poolinfo = getBlockData($ip_dbh, $webvar{pool});
|
---|
| 313 | my $cidr = new NetAddr::IP $poolinfo->{block};
|
---|
[4] | 314 |
|
---|
[697] | 315 | # Tree navigation
|
---|
| 316 | my $crumbs = getBreadCrumbs($ip_dbh, $poolinfo->{parent_id});
|
---|
| 317 | my @rcrumbs = reverse (@$crumbs);
|
---|
| 318 | $utilbar->param(breadcrumb => \@rcrumbs);
|
---|
| 319 |
|
---|
[631] | 320 | $page->param(block => $cidr);
|
---|
[517] | 321 | $page->param(netip => $cidr->addr);
|
---|
| 322 | $cidr++;
|
---|
| 323 | $page->param(gate => $cidr->addr);
|
---|
| 324 | $cidr--; $cidr--;
|
---|
| 325 | $page->param(bcast => $cidr->addr);
|
---|
| 326 | $page->param(mask => $cidr->mask);
|
---|
[157] | 327 |
|
---|
[528] | 328 | $page->param(disptype => $disp_alloctypes{$poolinfo->{type}});
|
---|
| 329 | $page->param(city => $poolinfo->{city});
|
---|
[517] | 330 |
|
---|
[157] | 331 | # Only display net/gw/bcast if it's a "real" netblock and not a PPP(oE) lunacy
|
---|
[528] | 332 | $page->param(realblock => $poolinfo->{type} =~ /^.d$/);
|
---|
[4] | 333 |
|
---|
| 334 | # probably have to add an "edit IP allocation" link here somewhere.
|
---|
| 335 |
|
---|
[528] | 336 | my $plist = listPool($ip_dbh, $webvar{pool});
|
---|
| 337 | # technically slightly more efficient to check the ACL in an if () once outside the foreach
|
---|
| 338 | foreach (@{$plist}) {
|
---|
| 339 | $$_{maydel} = $IPDBacl{$authuser} =~ /d/;
|
---|
[4] | 340 | }
|
---|
[528] | 341 | $page->param(poolips => $plist);
|
---|
| 342 | } # end showPool
|
---|
[4] | 343 |
|
---|
| 344 |
|
---|
[106] | 345 | # Show "Add new allocation" page. Note that the actual page may
|
---|
| 346 | # be one of two templates, and the lists come from the database.
|
---|
[4] | 347 | sub assignBlock {
|
---|
| 348 |
|
---|
[233] | 349 | if ($IPDBacl{$authuser} !~ /a/) {
|
---|
[517] | 350 | $aclerr = 'addblock';
|
---|
[233] | 351 | return;
|
---|
| 352 | }
|
---|
| 353 |
|
---|
[517] | 354 | # hack pthbttt eww
|
---|
[633] | 355 | $webvar{parent} = 0 if !$webvar{parent};
|
---|
[517] | 356 | $webvar{block} = '' if !$webvar{block};
|
---|
[21] | 357 |
|
---|
[575] | 358 | $page->param(allocfrom => $webvar{block}); # fb-assign flag, if block is set, we're in fb-assign
|
---|
[517] | 359 |
|
---|
[633] | 360 | if ($webvar{fbid} || $webvar{fbtype}) {
|
---|
[575] | 361 |
|
---|
| 362 | # Common case, according to reported usage. Block to assign is specified.
|
---|
[21] | 363 | my $block = new NetAddr::IP $webvar{block};
|
---|
[187] | 364 |
|
---|
[675] | 365 | my ($rdns,$cached) = getBlockRDNS($ip_dbh, id => $webvar{parent}, type => $webvar{fbtype}, user => $authuser);
|
---|
[585] | 366 | $page->param(rdns => $rdns) if $rdns;
|
---|
[633] | 367 | $page->param(parent => $webvar{parent});
|
---|
| 368 | $page->param(fbid => $webvar{fbid});
|
---|
[675] | 369 | # visual flag that we're working IPDB-local, not off more authoritative data in dnsadmin
|
---|
| 370 | $page->param(cached => $cached);
|
---|
[585] | 371 |
|
---|
[691] | 372 | my $pinfo = getBlockData($ip_dbh, $webvar{parent});
|
---|
| 373 | # seems reasonable that a new allocation would share a VRF with its parent
|
---|
| 374 | $page->param(pvrf => $pinfo->{vrf});
|
---|
| 375 |
|
---|
[697] | 376 | # Tree navigation
|
---|
| 377 | my $crumbs = getBreadCrumbs($ip_dbh, $webvar{parent});
|
---|
| 378 | my @rcrumbs = reverse (@$crumbs);
|
---|
| 379 | $utilbar->param(breadcrumb => \@rcrumbs);
|
---|
| 380 |
|
---|
[575] | 381 | $webvar{fbtype} = '' if !$webvar{fbtype};
|
---|
| 382 | if ($webvar{fbtype} eq 'i') {
|
---|
[633] | 383 | my $ipinfo = getBlockData($ip_dbh, $webvar{block}, 'i');
|
---|
[575] | 384 | $page->param(
|
---|
| 385 | fbip => 1,
|
---|
[633] | 386 | block => $ipinfo->{block},
|
---|
[575] | 387 | fbdisptype => $list_alloctypes{$ipinfo->{type}},
|
---|
| 388 | type => $ipinfo->{type},
|
---|
[633] | 389 | allocfrom => $pinfo->{block},
|
---|
[575] | 390 | );
|
---|
[187] | 391 | } else {
|
---|
[529] | 392 | # get "primary" alloctypes, since these are all that can correctly be assigned if we're in this branch
|
---|
[575] | 393 | my $tlist = getTypeList($ip_dbh, 'n');
|
---|
[529] | 394 | $tlist->[0]->{sel} = 1;
|
---|
[575] | 395 | $page->param(typelist => $tlist, block => $block);
|
---|
[106] | 396 | }
|
---|
[575] | 397 |
|
---|
[21] | 398 | } else {
|
---|
[575] | 399 |
|
---|
| 400 | # Uncommon case, according to reported usage. Block to assign needs to be found based on criteria.
|
---|
[541] | 401 | my $mlist = getMasterList($ip_dbh, 'c');
|
---|
| 402 | $page->param(masterlist => $mlist);
|
---|
[517] | 403 |
|
---|
| 404 | my @pops;
|
---|
[633] | 405 | foreach my $pop (@citylist) {
|
---|
[517] | 406 | my %row = (pop => $pop);
|
---|
| 407 | push (@pops, \%row);
|
---|
[92] | 408 | }
|
---|
[517] | 409 | $page->param(pops => \@pops);
|
---|
| 410 |
|
---|
[529] | 411 | # get all standard alloctypes
|
---|
| 412 | my $tlist = getTypeList($ip_dbh, 'a');
|
---|
| 413 | $tlist->[0]->{sel} = 1;
|
---|
| 414 | $page->param(typelist => $tlist);
|
---|
[21] | 415 | }
|
---|
[517] | 416 |
|
---|
| 417 | my @cities;
|
---|
[92] | 418 | foreach my $city (@citylist) {
|
---|
[517] | 419 | my %row = (city => $city);
|
---|
| 420 | push (@cities, \%row);
|
---|
[92] | 421 | }
|
---|
[517] | 422 | $page->param(citylist => \@cities);
|
---|
[4] | 423 |
|
---|
[397] | 424 | ## node hack
|
---|
[530] | 425 | my $nlist = getNodeList($ip_dbh);
|
---|
| 426 | $page->param(nodelist => $nlist);
|
---|
[397] | 427 | ## end node hack
|
---|
| 428 |
|
---|
[517] | 429 | $page->param(privdata => $IPDBacl{$authuser} =~ /s/);
|
---|
[284] | 430 |
|
---|
[4] | 431 | } # assignBlock
|
---|
| 432 |
|
---|
| 433 |
|
---|
| 434 | # Take info on requested IP assignment and see what we can provide.
|
---|
| 435 | sub confirmAssign {
|
---|
[233] | 436 | if ($IPDBacl{$authuser} !~ /a/) {
|
---|
[517] | 437 | $aclerr = 'addblock';
|
---|
[233] | 438 | return;
|
---|
| 439 | }
|
---|
[4] | 440 |
|
---|
| 441 | my $cidr;
|
---|
[692] | 442 | my $resv; # Reserved for expansion.
|
---|
[4] | 443 | my $alloc_from;
|
---|
[633] | 444 | my $fbid = $webvar{fbid};
|
---|
| 445 | my $p_id = $webvar{parent};
|
---|
[4] | 446 |
|
---|
| 447 | # Going to manually validate some items.
|
---|
| 448 | # custid and city are automagic.
|
---|
[111] | 449 | return if !validateInput();
|
---|
[4] | 450 |
|
---|
[665] | 451 | # make sure this is defined
|
---|
| 452 | $webvar{fbassign} = 'n' if !$webvar{fbassign};
|
---|
| 453 |
|
---|
[4] | 454 | # Several different cases here.
|
---|
| 455 | # Static IP vs netblock
|
---|
| 456 | # + Different flavours of static IP
|
---|
| 457 | # + Different flavours of netblock
|
---|
| 458 |
|
---|
[575] | 459 | if ($webvar{alloctype} =~ /^.i$/ && $webvar{fbassign} ne 'y') {
|
---|
[665] | 460 | if (!$webvar{pop}) {
|
---|
| 461 | $page->param(err => "Please select a location/POP site to allocate from.");
|
---|
| 462 | return;
|
---|
| 463 | }
|
---|
[532] | 464 | my $plist = getPoolSelect($ip_dbh, $webvar{alloctype}, $webvar{pop});
|
---|
[517] | 465 | $page->param(staticip => 1);
|
---|
[532] | 466 | $page->param(poollist => $plist) if $plist;
|
---|
[4] | 467 | $cidr = "Single static IP";
|
---|
[517] | 468 | ##fixme: need to handle "no available pools"
|
---|
[4] | 469 |
|
---|
| 470 | } else { # end show pool options
|
---|
[21] | 471 |
|
---|
[533] | 472 | if ($webvar{fbassign} && $webvar{fbassign} eq 'y') {
|
---|
[697] | 473 |
|
---|
| 474 | # Tree navigation
|
---|
| 475 | my $crumbs = getBreadCrumbs($ip_dbh, $webvar{parent});
|
---|
| 476 | my @rcrumbs = reverse (@$crumbs);
|
---|
| 477 | $utilbar->param(breadcrumb => \@rcrumbs);
|
---|
| 478 |
|
---|
[21] | 479 | $cidr = new NetAddr::IP $webvar{block};
|
---|
[575] | 480 | $alloc_from = new NetAddr::IP $webvar{allocfrom};
|
---|
[21] | 481 | $webvar{maskbits} = $cidr->masklen;
|
---|
[692] | 482 | # Some additional checks are needed for reserving free space
|
---|
| 483 | if ($webvar{reserve}) {
|
---|
| 484 | if ($cidr == $alloc_from) {
|
---|
| 485 | # We could still squirm and fiddle to try to find a way to reserve space, but the storage model for
|
---|
| 486 | # IPDB means that all continguous free space is kept in the smallest number of strict CIDR netblocks
|
---|
| 487 | # possible. (In theory.) If the request and the freeblock are the same, it is theoretically impossible
|
---|
| 488 | # to reserve an equivalent-sized block either ahead or behind the requested one, because the pair
|
---|
| 489 | # together would never be a strict CIDR block.
|
---|
| 490 | $page->param(warning => "Can't reserve space for expansion; free block and requested allocation are the same.");
|
---|
| 491 | delete $webvar{reserve};
|
---|
| 492 | } else {
|
---|
| 493 | # Find which new free block will match the reqested block.
|
---|
| 494 | # Take the requested mask, shift by one
|
---|
| 495 | my $tmpmask = $webvar{maskbits};
|
---|
| 496 | $tmpmask--;
|
---|
| 497 | # find the subnets with that mask in the selected free block
|
---|
| 498 | my @pieces = $alloc_from->split($tmpmask);
|
---|
| 499 | foreach my $slice (@pieces) {
|
---|
| 500 | if ($slice->contains($cidr)) {
|
---|
| 501 | # For the subnet that contains the requested block, split that in two,
|
---|
| 502 | # and flag/cache the one that's not the requested block.
|
---|
| 503 | my @bits = $slice->split($webvar{maskbits});
|
---|
| 504 | if ($bits[0] == $cidr) {
|
---|
| 505 | $resv = $bits[1];
|
---|
| 506 | } else {
|
---|
| 507 | $resv = $bits[0];
|
---|
| 508 | }
|
---|
| 509 | }
|
---|
| 510 | }
|
---|
| 511 | }
|
---|
| 512 | } # reserve block check
|
---|
| 513 |
|
---|
[21] | 514 | } else { # done with direct freeblocks assignment
|
---|
| 515 |
|
---|
| 516 | if (!$webvar{maskbits}) {
|
---|
[517] | 517 | $page->param(err => "Please specify a CIDR mask length.");
|
---|
[111] | 518 | return;
|
---|
[21] | 519 | }
|
---|
[533] | 520 |
|
---|
| 521 | ##fixme ick, ew, bleh. gotta handle the failure message generation better. push it into findAllocateFrom()?
|
---|
| 522 | my $failmsg = "No suitable free block found.<br>\n";
|
---|
[187] | 523 | if ($webvar{alloctype} eq 'rm') {
|
---|
[533] | 524 | $failmsg .= "We do not have a free routeable block of that size.<br>\n".
|
---|
| 525 | "You will have to either route a set of smaller netblocks or a single smaller netblock.";
|
---|
[4] | 526 | } else {
|
---|
[214] | 527 | if ($webvar{alloctype} =~ /^.[pc]$/) {
|
---|
[533] | 528 | $failmsg .= "You will have to route another superblock from one of the<br>\n".
|
---|
| 529 | "master blocks or chose a smaller block size for the pool.";
|
---|
[21] | 530 | } else {
|
---|
[517] | 531 | if (!$webvar{pop}) {
|
---|
| 532 | $page->param(err => 'Please select a POP to route the block from/through.');
|
---|
| 533 | return;
|
---|
| 534 | }
|
---|
[533] | 535 | $failmsg .= "You will have to route another superblock to $webvar{pop}<br>\n".
|
---|
[692] | 536 | "from one of the master blocks";
|
---|
| 537 | if ($webvar{reserve}) {
|
---|
| 538 | $failmsg .= ', choose a smaller blocksize, or uncheck "Reserve space for expansion".';
|
---|
| 539 | } else {
|
---|
| 540 | $failmsg .= " or chose a smaller blocksize.";
|
---|
| 541 | }
|
---|
[21] | 542 | }
|
---|
[4] | 543 | }
|
---|
[533] | 544 |
|
---|
[692] | 545 | # if requesting extra space "reserved for expansion", we need to find a free
|
---|
| 546 | # block at least double the size of the request.
|
---|
| 547 | if ($webvar{reserve}) {
|
---|
| 548 | $webvar{maskbits}--;
|
---|
| 549 | }
|
---|
| 550 |
|
---|
[633] | 551 | ($fbid,$cidr,$p_id) = findAllocateFrom($ip_dbh, $webvar{maskbits}, $webvar{alloctype},
|
---|
| 552 | $webvar{city}, $webvar{pop}, (master => $webvar{allocfrom}, allowpriv => $webvar{allowpriv}) );
|
---|
[533] | 553 | if (!$cidr) {
|
---|
[517] | 554 | $page->param(err => $failmsg);
|
---|
[111] | 555 | return;
|
---|
[21] | 556 | }
|
---|
[533] | 557 | $cidr = new NetAddr::IP $cidr;
|
---|
[575] | 558 |
|
---|
| 559 | $alloc_from = "$cidr";
|
---|
[692] | 560 |
|
---|
| 561 | # when autofinding a block to allocate from, use the first piece of the found
|
---|
| 562 | # block for the allocation, and the next piece for the "reserved for expansion".
|
---|
| 563 | if ($webvar{reserve}) {
|
---|
| 564 | # reset the mask to the real requested one, now that we've got a
|
---|
| 565 | # block large enough for the request plus reserve
|
---|
| 566 | $webvar{maskbits}++;
|
---|
| 567 | ($cidr,$resv) = $cidr->split($webvar{maskbits});
|
---|
| 568 | }
|
---|
| 569 |
|
---|
[575] | 570 | # If the block to be allocated is smaller than the one we found,
|
---|
| 571 | # figure out the "real" block to be allocated.
|
---|
| 572 | if ($cidr->masklen() ne $webvar{maskbits}) {
|
---|
| 573 | my $maskbits = $cidr->masklen();
|
---|
| 574 | my @subblocks;
|
---|
| 575 | while ($maskbits++ < $webvar{maskbits}) {
|
---|
| 576 | @subblocks = $cidr->split($maskbits);
|
---|
| 577 | }
|
---|
| 578 | $cidr = $subblocks[0];
|
---|
| 579 | }
|
---|
[21] | 580 | } # check for freeblocks assignment or IPDB-controlled assignment
|
---|
[4] | 581 |
|
---|
[674] | 582 | # Generate the IP list for the new allocation in case someone wants to set per-IP rDNS right away.
|
---|
| 583 | # We don't do this on the previous page because we don't know how big a block or even what IP range
|
---|
| 584 | # it's for (if following the "normal" allocation process)
|
---|
| 585 | if ($IPDBacl{$authuser} =~ /c/
|
---|
| 586 | && $cidr->masklen != $cidr->bits
|
---|
| 587 | && ($cidr->bits - $cidr->masklen) <= $IPDB::maxrevlist
|
---|
| 588 | && $webvar{alloctype} !~ /^.[dpi]/
|
---|
| 589 | # do we want to allow v6 at all?
|
---|
| 590 | #&& ! $cidr->{isv6}
|
---|
| 591 | ) {
|
---|
| 592 | my @list;
|
---|
| 593 | foreach my $ip (@{$cidr->splitref()}) {
|
---|
| 594 | my %row;
|
---|
| 595 | $row{r_ip} = $ip->addr;
|
---|
| 596 | $row{iphost} = '';
|
---|
| 597 | push @list, \%row;
|
---|
| 598 | }
|
---|
| 599 | $page->param(r_iplist => \@list);
|
---|
| 600 | # We don't use this here, because these IPs should already be bare.
|
---|
| 601 | # ... or should we be paranoid? Make it a config option?
|
---|
| 602 | #getRDNSbyIP($ip_dbh, type => $webvar{alloctype}, range => "$cidr", user => $authuser) );
|
---|
| 603 | }
|
---|
[157] | 604 | } # if ($webvar{alloctype} =~ /^.i$/)
|
---|
[4] | 605 |
|
---|
[397] | 606 | ## node hack
|
---|
| 607 | if ($webvar{node} && $webvar{node} ne '-') {
|
---|
[530] | 608 | my $nodename = getNodeName($ip_dbh, $webvar{node});
|
---|
[517] | 609 | $page->param(nodename => $nodename);
|
---|
| 610 | $page->param(nodeid => $webvar{node});
|
---|
[397] | 611 | }
|
---|
| 612 | ## end node hack
|
---|
| 613 |
|
---|
[692] | 614 | # reserve for expansion
|
---|
| 615 | $page->param(reserve => $webvar{reserve});
|
---|
| 616 | # probably just preventing a little log noise doing this; could just set the param
|
---|
| 617 | # all the time since it won't be shown if the reserve param above isn't set.
|
---|
| 618 | # if ($webvar{reserve}) {
|
---|
| 619 | $page->param(resvblock => $resv);
|
---|
| 620 | # }
|
---|
| 621 |
|
---|
[4] | 622 | # Stick in the allocation data
|
---|
[517] | 623 | $page->param(alloc_type => $webvar{alloctype});
|
---|
| 624 | $page->param(typefull => $q->escapeHTML($disp_alloctypes{$webvar{alloctype}}));
|
---|
| 625 | $page->param(alloc_from => $alloc_from);
|
---|
[633] | 626 | $page->param(parent => $p_id);
|
---|
| 627 | $page->param(fbid => $fbid);
|
---|
[517] | 628 | $page->param(cidr => $cidr);
|
---|
[585] | 629 | $page->param(rdns => $webvar{rdns});
|
---|
[691] | 630 | $page->param(vrf => $webvar{vrf});
|
---|
| 631 | $page->param(vlan => $webvar{vlan});
|
---|
[517] | 632 | $page->param(city => $q->escapeHTML($webvar{city}));
|
---|
| 633 | $page->param(custid => $webvar{custid});
|
---|
| 634 | $page->param(circid => $q->escapeHTML($webvar{circid}));
|
---|
| 635 | $page->param(desc => $q->escapeHTML($webvar{desc}));
|
---|
[4] | 636 |
|
---|
[517] | 637 | ##fixme: find a way to have the displayed copy have <br> substitutions
|
---|
| 638 | # for newlines, and the <input> value have either encoded or bare newlines.
|
---|
| 639 | # Also applies to privdata.
|
---|
| 640 | $page->param(notes => $q->escapeHTML($webvar{notes},'y'));
|
---|
| 641 |
|
---|
[284] | 642 | # Check to see if user is allowed to do anything with sensitive data
|
---|
| 643 | my $privdata = '';
|
---|
[517] | 644 | $page->param(privdata => $q->escapeHTML($webvar{privdata},'y'))
|
---|
| 645 | if $IPDBacl{$authuser} =~ /s/;
|
---|
| 646 |
|
---|
| 647 | # Yay! This now has it's very own little home.
|
---|
| 648 | $page->param(billinguser => $webvar{userid})
|
---|
[299] | 649 | if $webvar{userid};
|
---|
[284] | 650 |
|
---|
[517] | 651 | ##fixme: this is only needed iff confirm.tmpl and
|
---|
| 652 | # confirmRemove.tmpl are merged (quite possible, just
|
---|
| 653 | # a little tedious)
|
---|
| 654 | $page->param(action => "insert");
|
---|
[284] | 655 |
|
---|
[4] | 656 | } # end confirmAssign
|
---|
| 657 |
|
---|
| 658 |
|
---|
| 659 | # Do the work of actually inserting a block in the database.
|
---|
| 660 | sub insertAssign {
|
---|
[233] | 661 | if ($IPDBacl{$authuser} !~ /a/) {
|
---|
[517] | 662 | $aclerr = 'addblock';
|
---|
[233] | 663 | return;
|
---|
| 664 | }
|
---|
[4] | 665 | # Some things are done more than once.
|
---|
[111] | 666 | return if !validateInput();
|
---|
[4] | 667 |
|
---|
[284] | 668 | if (!defined($webvar{privdata})) {
|
---|
| 669 | $webvar{privdata} = '';
|
---|
| 670 | }
|
---|
[575] | 671 |
|
---|
| 672 | # split up some linked data for static IPs via guided allocation. needed for breadcrumbs lite.
|
---|
[584] | 673 | ($webvar{alloc_from},$webvar{rdepth}) = split /,/, $webvar{alloc_from} if $webvar{alloc_from} =~ /,/;
|
---|
[575] | 674 |
|
---|
[106] | 675 | # $code is "success" vs "failure", $msg contains OK for a
|
---|
| 676 | # successful netblock allocation, the IP allocated for static
|
---|
| 677 | # IP, or the error message if an error occurred.
|
---|
[517] | 678 |
|
---|
[677] | 679 | ##fixme: consider just passing \%webvar to allocateBlock()?
|
---|
| 680 | # collect per-IP rDNS fields. only copy over the ones that actually have something in them.
|
---|
| 681 | my %iprev;
|
---|
| 682 | foreach (keys %webvar) {
|
---|
| 683 | $iprev{$_} = $webvar{$_} if /host_[\d.a-fA-F:]+/ && $webvar{$_};
|
---|
| 684 | }
|
---|
| 685 |
|
---|
[691] | 686 | # Easier to see and cosmetically fiddle the list like this
|
---|
| 687 | my %insert_args = (
|
---|
| 688 | cidr => $webvar{fullcidr},
|
---|
| 689 | fbid => $webvar{fbid},
|
---|
[692] | 690 | reserve => $webvar{reserve},
|
---|
[691] | 691 | parent => $webvar{parent},
|
---|
| 692 | custid => $webvar{custid},
|
---|
| 693 | type => $webvar{alloctype},
|
---|
| 694 | city => $webvar{city},
|
---|
| 695 | desc => $webvar{desc},
|
---|
| 696 | notes => $webvar{notes},
|
---|
| 697 | circid => $webvar{circid},
|
---|
| 698 | privdata => $webvar{privdata},
|
---|
| 699 | nodeid => $webvar{node},
|
---|
| 700 | rdns => $webvar{rdns},
|
---|
| 701 | vrf => $webvar{vrf},
|
---|
| 702 | vlan => $webvar{vlan},
|
---|
| 703 | user => $authuser,
|
---|
| 704 | );
|
---|
[4] | 705 |
|
---|
[691] | 706 | my ($code,$msg) = allocateBlock($ip_dbh, %insert_args, iprev => \%iprev);
|
---|
| 707 |
|
---|
[111] | 708 | if ($code eq 'OK') {
|
---|
[106] | 709 | if ($webvar{alloctype} =~ /^.i$/) {
|
---|
[300] | 710 | $msg =~ s|/32||;
|
---|
[517] | 711 | $page->param(staticip => $msg);
|
---|
| 712 | $page->param(custid => $webvar{custid});
|
---|
[633] | 713 | $page->param(parent => $webvar{parent}, pool => $webvar{alloc_from});
|
---|
[517] | 714 | $page->param(billinguser => $webvar{billinguser});
|
---|
[416] | 715 | mailNotify($ip_dbh, "a$webvar{alloctype}", "ADDED: $disp_alloctypes{$webvar{alloctype}} allocation",
|
---|
| 716 | "$disp_alloctypes{$webvar{alloctype}} $msg allocated to customer $webvar{custid}\n".
|
---|
| 717 | "Description: $webvar{desc}\n\nAllocated by: $authuser\n");
|
---|
[106] | 718 | } else {
|
---|
[301] | 719 | my $netblock = new NetAddr::IP $webvar{fullcidr};
|
---|
[517] | 720 | $page->param(fullcidr => $webvar{fullcidr});
|
---|
| 721 | $page->param(alloctype => $disp_alloctypes{$webvar{alloctype}});
|
---|
| 722 | $page->param(custid => $webvar{custid});
|
---|
[697] | 723 |
|
---|
[575] | 724 | # breadcrumbs lite! provide at least a link to the parent of the block we just allocated.
|
---|
[633] | 725 | my $binfo = getBlockData($ip_dbh, $webvar{parent});
|
---|
| 726 | $page->param(parentid => $webvar{parent});
|
---|
| 727 | $page->param(parentblock => $binfo->{block});
|
---|
[697] | 728 |
|
---|
| 729 | # Full breadcrumbs
|
---|
| 730 | my $crumbs = getBreadCrumbs($ip_dbh, $webvar{parent});
|
---|
| 731 | my @rcrumbs = reverse (@$crumbs);
|
---|
| 732 | $utilbar->param(breadcrumb => \@rcrumbs);
|
---|
| 733 |
|
---|
[517] | 734 | if ($webvar{alloctype} eq 'pr' && $webvar{billinguser}) {
|
---|
| 735 | $page->param(billinguser => $webvar{billinguser});
|
---|
| 736 | $page->param(custid => $webvar{custid});
|
---|
| 737 | $page->param(netaddr => $netblock->addr);
|
---|
| 738 | $page->param(masklen => $netblock->masklen);
|
---|
| 739 | }
|
---|
[416] | 740 | mailNotify($ip_dbh, "a$webvar{alloctype}", "ADDED: $disp_alloctypes{$webvar{alloctype}} allocation",
|
---|
| 741 | "$disp_alloctypes{$webvar{alloctype}} $webvar{fullcidr} allocated to customer $webvar{custid}\n".
|
---|
| 742 | "Description: $webvar{desc}\n\nAllocated by: $authuser\n");
|
---|
[4] | 743 | }
|
---|
[106] | 744 | syslog "notice", "$authuser allocated '$webvar{fullcidr}' to '$webvar{custid}' as ".
|
---|
[256] | 745 | "'$webvar{alloctype}' ($msg)";
|
---|
[111] | 746 | } else {
|
---|
| 747 | syslog "err", "Allocation of '$webvar{fullcidr}' to '$webvar{custid}' as ".
|
---|
| 748 | "'$webvar{alloctype}' by $authuser failed: '$msg'";
|
---|
[517] | 749 | $page->param(err => "Allocation of $webvar{fullcidr} as '$disp_alloctypes{$webvar{alloctype}}'".
|
---|
[157] | 750 | " failed:<br>\n$msg\n");
|
---|
[106] | 751 | }
|
---|
[4] | 752 |
|
---|
| 753 | } # end insertAssign()
|
---|
| 754 |
|
---|
| 755 |
|
---|
| 756 | # Does some basic checks on common input data to make sure nothing
|
---|
| 757 | # *really* weird gets in to the database through this script.
|
---|
| 758 | # Does NOT do complete input validation!!!
|
---|
| 759 | sub validateInput {
|
---|
| 760 | if ($webvar{city} eq '-') {
|
---|
[517] | 761 | $page->param(err => 'Please choose a city');
|
---|
[111] | 762 | return;
|
---|
[4] | 763 | }
|
---|
[138] | 764 |
|
---|
| 765 | # Alloctype check.
|
---|
[4] | 766 | chomp $webvar{alloctype};
|
---|
[138] | 767 | if (!grep /$webvar{alloctype}/, keys %disp_alloctypes) {
|
---|
| 768 | # Danger! Danger! alloctype should ALWAYS be set by a dropdown. Anyone
|
---|
| 769 | # managing to call things in such a way as to cause this deserves a cryptic error.
|
---|
[517] | 770 | $page->param(err => 'Invalid alloctype');
|
---|
[138] | 771 | return;
|
---|
| 772 | }
|
---|
| 773 |
|
---|
| 774 | # CustID check
|
---|
[4] | 775 | # We have different handling for customer allocations and "internal" or "our" allocations
|
---|
[214] | 776 | if ($def_custids{$webvar{alloctype}} eq '') {
|
---|
[4] | 777 | if (!$webvar{custid}) {
|
---|
[517] | 778 | $page->param(err => 'Please enter a customer ID.');
|
---|
[111] | 779 | return;
|
---|
[4] | 780 | }
|
---|
[546] | 781 | # Crosscheck with billing.
|
---|
| 782 | my $status = CustIDCK->custid_exist($webvar{custid});
|
---|
| 783 | if ($CustIDCK::Error) {
|
---|
| 784 | $page->param(err => "Error verifying customer ID: ".$CustIDCK::ErrMsg);
|
---|
| 785 | return;
|
---|
[4] | 786 | }
|
---|
[546] | 787 | if (!$status) {
|
---|
| 788 | $page->param(err => "Customer ID not valid. Make sure the Customer ID ".
|
---|
| 789 | "is correct.<br>\nUse STAFF for staff static IPs, and $IPDB::defcustid for any other ".
|
---|
| 790 | "non-customer assignments.");
|
---|
| 791 | return;
|
---|
| 792 | }
|
---|
[400] | 793 | # print "<!-- [ In validateInput(). Insert customer ID cross-check here. ] -->\n";
|
---|
[138] | 794 | } else {
|
---|
[167] | 795 | # New! Improved! And now Loaded From The Database!!
|
---|
[320] | 796 | if ((!$webvar{custid}) || ($webvar{custid} ne 'STAFF')) {
|
---|
| 797 | $webvar{custid} = $def_custids{$webvar{alloctype}};
|
---|
| 798 | }
|
---|
[4] | 799 | }
|
---|
[111] | 800 |
|
---|
[571] | 801 | ## hmmm.... is this even useful?
|
---|
| 802 | if (0) {
|
---|
[111] | 803 | # Check POP location
|
---|
| 804 | my $flag;
|
---|
[187] | 805 | if ($webvar{alloctype} eq 'rm') {
|
---|
[111] | 806 | $flag = 'for a routed netblock';
|
---|
| 807 | foreach (@poplist) {
|
---|
| 808 | if (/^$webvar{city}$/) {
|
---|
| 809 | $flag = 'n';
|
---|
| 810 | last;
|
---|
| 811 | }
|
---|
| 812 | }
|
---|
| 813 | } else {
|
---|
| 814 | $flag = 'n';
|
---|
[442] | 815 | ##fixme: hook to force-set POP or city on certain alloctypes
|
---|
| 816 | # if ($webvar{alloctype =~ /foo,bar,bz/ { $webvar{pop} = 'blah'; }
|
---|
[536] | 817 | if ($webvar{pop} && $webvar{pop} =~ /^-$/) {
|
---|
[111] | 818 | $flag = 'to route the block from/through';
|
---|
| 819 | }
|
---|
| 820 | }
|
---|
[517] | 821 |
|
---|
| 822 | # if the alloctype has a restricted city/POP list as determined above,
|
---|
| 823 | # and the reqested city/POP does not match that list, complain
|
---|
[111] | 824 | if ($flag ne 'n') {
|
---|
[517] | 825 | $page->param(err => "Please choose a valid POP location $flag. Valid ".
|
---|
[111] | 826 | "POP locations are currently:<br>\n".join (" - ", @poplist));
|
---|
| 827 | return;
|
---|
| 828 | }
|
---|
[571] | 829 | }
|
---|
[111] | 830 |
|
---|
[691] | 831 | # VRF. Not a full validity check, just a basic sanity check.
|
---|
| 832 | if ($webvar{vrf}) {
|
---|
| 833 | # Trim leading and trailing whitespace first
|
---|
| 834 | $webvar{vrf} =~ s/^\s+//;
|
---|
| 835 | $webvar{vrf} =~ s/\s+$//;
|
---|
| 836 | if ($webvar{vrf} !~ /^[\w\d_.-]{1,32}$/) {
|
---|
| 837 | $page->param(err => "VRF values may only contain alphanumerics, and may not be more than 32 characters");
|
---|
| 838 | return;
|
---|
| 839 | }
|
---|
| 840 | }
|
---|
| 841 |
|
---|
| 842 | # VLAN. Should we allow/use VLAN names, or just the numeric ID?
|
---|
| 843 | if ($webvar{vlan}) {
|
---|
| 844 | # Trim leading and trailing whitespace first
|
---|
| 845 | $webvar{vlan} =~ s/^\s+//;
|
---|
| 846 | $webvar{vlan} =~ s/\s+$//;
|
---|
| 847 | # ... ve make it ze configurable thingy!
|
---|
| 848 | if ($IPDB::numeric_vlan) {
|
---|
| 849 | if ($webvar{vlan} !~ /^\d+$/) {
|
---|
| 850 | $page->param(err => "VLANs must be numeric");
|
---|
| 851 | return;
|
---|
| 852 | }
|
---|
| 853 | } else {
|
---|
| 854 | if ($webvar{vlan} !~ /^[\w\d_.-]+$/) {
|
---|
| 855 | $page->param(err => "VLANs must be alphanumeric");
|
---|
| 856 | return;
|
---|
| 857 | }
|
---|
| 858 | }
|
---|
| 859 | }
|
---|
| 860 |
|
---|
[111] | 861 | return 'OK';
|
---|
[4] | 862 | } # end validateInput
|
---|
| 863 |
|
---|
| 864 |
|
---|
| 865 | # Displays details of a specific allocation in a form
|
---|
| 866 | # Allows update/delete
|
---|
| 867 | # action=edit
|
---|
| 868 | sub edit {
|
---|
| 869 |
|
---|
[534] | 870 | # snag block info from db
|
---|
[634] | 871 | my $blockinfo = getBlockData($ip_dbh, $webvar{id}, $webvar{basetype});
|
---|
[691] | 872 | $page->param(id => $webvar{id});
|
---|
[634] | 873 | $page->param(basetype => $webvar{basetype});
|
---|
[4] | 874 |
|
---|
[697] | 875 | # Tree navigation
|
---|
| 876 | my $crumbs = getBreadCrumbs($ip_dbh, $blockinfo->{parent_id});
|
---|
| 877 | my @rcrumbs = reverse (@$crumbs);
|
---|
| 878 | $utilbar->param(breadcrumb => \@rcrumbs);
|
---|
| 879 |
|
---|
[705] | 880 | # Show link to IP list for pools
|
---|
| 881 | $page->param(ispool => 1) if $blockinfo->{type} =~ /^.[dp]$/;
|
---|
| 882 |
|
---|
[534] | 883 | # Clean up extra whitespace on alloc type. Mainly a legacy-data cleanup.
|
---|
| 884 | $blockinfo->{type} =~ s/\s//;
|
---|
[4] | 885 |
|
---|
[675] | 886 | my $cached;
|
---|
[586] | 887 | # Get rDNS info; duplicates a bit of getBlockData but also does the RPC call if possible
|
---|
[675] | 888 | ($blockinfo->{rdns},$cached) = getBlockRDNS($ip_dbh, id => $webvar{id}, type => $blockinfo->{type}, user => $authuser);
|
---|
| 889 | # visual flag that we're working IPDB-local, not off more authoritative data in dnsadmin
|
---|
[691] | 890 | $page->param(cached => $cached);
|
---|
[586] | 891 |
|
---|
[675] | 892 | my $cidr = new NetAddr::IP $blockinfo->{block};
|
---|
| 893 | # Limit the per-IP rDNS list based on CIDR length; larger ones just take up too much space.
|
---|
| 894 | # Also, don't show on IP pools; the individual IPs will have a space for rDNS
|
---|
| 895 | # Don't show on single IPs; these use the "pattern" field
|
---|
| 896 | if ($IPDBacl{$authuser} =~ /c/
|
---|
| 897 | && $cidr->masklen != $cidr->bits
|
---|
| 898 | && ($cidr->bits - $cidr->masklen) <= $IPDB::maxrevlist
|
---|
[683] | 899 | && $blockinfo->{type} !~ /^.[dpi]/
|
---|
[675] | 900 | # do we want to allow v6 at all?
|
---|
| 901 | #&& ! $cidr->{isv6}
|
---|
| 902 | ) {
|
---|
| 903 | $page->param(r_iplist => getRDNSbyIP($ip_dbh, id => $webvar{id}, type => $blockinfo->{type},
|
---|
| 904 | range => $blockinfo->{block}, user => $authuser) );
|
---|
| 905 | }
|
---|
| 906 |
|
---|
[691] | 907 | # consider extending this to show time as well as date
|
---|
| 908 | my ($lastmod,undef) = split /\s+/, $blockinfo->{lastmod};
|
---|
| 909 | $page->param(lastmod => $lastmod);
|
---|
| 910 | # $page->param(lastmod => $blockinfo->{lastmod});
|
---|
[4] | 911 |
|
---|
[691] | 912 | $page->param(block => $blockinfo->{block});
|
---|
| 913 | $page->param(city => $blockinfo->{city});
|
---|
| 914 | $page->param(custid => $blockinfo->{custid});
|
---|
[4] | 915 |
|
---|
[187] | 916 | ##fixme The check here should be built from the database
|
---|
[517] | 917 | # Need to expand to support pool types too
|
---|
[534] | 918 | if ($blockinfo->{type} =~ /^.[ne]$/ && $IPDBacl{$authuser} =~ /c/) {
|
---|
[517] | 919 | $page->param(changetype => 1);
|
---|
| 920 | $page->param(alloctype => [
|
---|
[534] | 921 | { selme => ($blockinfo->{type} eq 'me'), type => "me", disptype => "Dialup netblock" },
|
---|
| 922 | { selme => ($blockinfo->{type} eq 'de'), type => "de", disptype => "Dynamic DSL netblock" },
|
---|
| 923 | { selme => ($blockinfo->{type} eq 'ce'), type => "ce", disptype => "Dynamic cable netblock" },
|
---|
| 924 | { selme => ($blockinfo->{type} eq 'we'), type => "we", disptype => "Dynamic wireless netblock" },
|
---|
| 925 | { selme => ($blockinfo->{type} eq 'cn'), type => "cn", disptype => "Customer netblock" },
|
---|
| 926 | { selme => ($blockinfo->{type} eq 'en'), type => "en", disptype => "End-use netblock" },
|
---|
| 927 | { selme => ($blockinfo->{type} eq 'in'), type => "in", disptype => "Internal netblock" },
|
---|
[517] | 928 | ]
|
---|
| 929 | );
|
---|
| 930 | } else {
|
---|
[534] | 931 | $page->param(disptype => $disp_alloctypes{$blockinfo->{type}});
|
---|
| 932 | $page->param(type => $blockinfo->{type});
|
---|
[517] | 933 | }
|
---|
| 934 |
|
---|
[397] | 935 | ## node hack
|
---|
[634] | 936 | my ($nodeid,$nodename) = getNodeInfo($ip_dbh, $blockinfo->{block});
|
---|
| 937 | # $page->param(havenodeid => $nodeid);
|
---|
| 938 | $page->param(nodename => $nodename);
|
---|
[517] | 939 |
|
---|
| 940 | ##fixme: this whole hack needs cleanup and generalization for all alloctypes
|
---|
| 941 | ##fixme: arguably a bug that presence of a nodeid implies it can be changed..
|
---|
[634] | 942 | if ($IPDBacl{$authuser} =~ /c/) {
|
---|
| 943 | my $nlist = getNodeList($ip_dbh);
|
---|
| 944 | if ($nodeid) {
|
---|
[530] | 945 | foreach (@{$nlist}) {
|
---|
[634] | 946 | $$_{selme} = ($$_{node_id} == $nodeid);
|
---|
[397] | 947 | }
|
---|
| 948 | }
|
---|
[634] | 949 | $page->param(nodelist => $nlist);
|
---|
[397] | 950 | }
|
---|
| 951 | ## end node hack
|
---|
[517] | 952 |
|
---|
[691] | 953 | $page->param(rdns => $blockinfo->{rdns});
|
---|
| 954 | $page->param(vrf => $blockinfo->{vrf});
|
---|
| 955 | $page->param(vlan => $blockinfo->{vlan});
|
---|
[33] | 956 |
|
---|
[695] | 957 | # Reserved-for-expansion
|
---|
| 958 | $page->param(reserve => $blockinfo->{reserve});
|
---|
| 959 | $page->param(reserve_id => $blockinfo->{reserve_id});
|
---|
| 960 | my $newblock = NetAddr::IP->new($cidr->addr, $cidr->masklen - 1)->network;
|
---|
| 961 | $page->param(newblock => $newblock);
|
---|
| 962 |
|
---|
[517] | 963 | # not happy with the upside-down logic, but...
|
---|
[534] | 964 | $page->param(swipable => $blockinfo->{type} !~ /.i/);
|
---|
[691] | 965 | $page->param(swip => $blockinfo->{swip} ne 'n') if $blockinfo->{swip};
|
---|
[320] | 966 |
|
---|
[691] | 967 | $page->param(circid => $blockinfo->{circuitid});
|
---|
| 968 | $page->param(desc => $blockinfo->{description});
|
---|
| 969 | $page->param(notes => $blockinfo->{notes});
|
---|
| 970 |
|
---|
[284] | 971 | # Check to see if we can display sensitive data
|
---|
[691] | 972 | $page->param(nocling => $IPDBacl{$authuser} =~ /s/);
|
---|
[534] | 973 | $page->param(privdata => $blockinfo->{privdata});
|
---|
[284] | 974 |
|
---|
[517] | 975 | # ACL trickery - these two template booleans control the presence of all form/input tags
|
---|
| 976 | $page->param(maychange => $IPDBacl{$authuser} =~ /c/);
|
---|
| 977 | $page->param(maydel => $IPDBacl{$authuser} =~ /d/);
|
---|
[4] | 978 |
|
---|
[702] | 979 | # Need to find internal knobs to twist to actually vary these. (Ab)use "change" flag for now
|
---|
| 980 | $page->param(maymerge => ($IPDBacl{$authuser} =~ /c/ && $blockinfo->{type} !~ /^.i$/));
|
---|
| 981 | if ($IPDBacl{$authuser} =~ /c/ && $blockinfo->{type} !~ /^.i$/) {
|
---|
| 982 | if ($blockinfo->{type} =~ /^.p$/) {
|
---|
| 983 | # PPP pools
|
---|
| 984 | $page->param(maysplit => 1) if $cidr->masklen+1 < $cidr->bits;
|
---|
| 985 | } elsif ($blockinfo->{type} =~ /.d/) {
|
---|
| 986 | # Non-PPP pools
|
---|
| 987 | $page->param(maysplit => 1) if $cidr->masklen+2 < $cidr->bits;
|
---|
| 988 | } else {
|
---|
| 989 | # Standard netblocks. Arguably allowing splitting these down to single IPs
|
---|
| 990 | # doesn't make much sense, but forcing users to apply allocation types
|
---|
| 991 | # "properly" is worse than herding cats.
|
---|
| 992 | $page->param(maysplit => 1) if $cidr->masklen < $cidr->bits;
|
---|
| 993 | }
|
---|
| 994 | }
|
---|
| 995 |
|
---|
[4] | 996 | } # edit()
|
---|
| 997 |
|
---|
| 998 |
|
---|
| 999 | # Stuff new info about a block into the db
|
---|
| 1000 | # action=update
|
---|
| 1001 | sub update {
|
---|
[284] | 1002 | if ($IPDBacl{$authuser} !~ /c/) {
|
---|
[517] | 1003 | $aclerr = 'updateblock';
|
---|
[284] | 1004 | return;
|
---|
| 1005 | }
|
---|
[4] | 1006 |
|
---|
[706] | 1007 | # Collect existing block info here, since we need it for the breadcrumb nav
|
---|
| 1008 | my $binfo = getBlockData($ip_dbh, $webvar{block}, $webvar{basetype});
|
---|
| 1009 | my $crumbs = getBreadCrumbs($ip_dbh, $binfo->{parent_id});
|
---|
| 1010 | my @rcrumbs = reverse (@$crumbs);
|
---|
| 1011 | $utilbar->param(breadcrumb => \@rcrumbs);
|
---|
| 1012 |
|
---|
[4] | 1013 | # Make sure incoming data is in correct format - custID among other things.
|
---|
[228] | 1014 | return if !validateInput;
|
---|
[4] | 1015 |
|
---|
[536] | 1016 | $webvar{swip} = 'n' if !$webvar{swip};
|
---|
| 1017 |
|
---|
[531] | 1018 | my %updargs = (
|
---|
| 1019 | custid => $webvar{custid},
|
---|
| 1020 | city => $webvar{city},
|
---|
| 1021 | description => $webvar{desc},
|
---|
| 1022 | notes => $webvar{notes},
|
---|
| 1023 | circuitid => $webvar{circid},
|
---|
| 1024 | block => $webvar{block},
|
---|
| 1025 | type => $webvar{alloctype},
|
---|
[536] | 1026 | swip => $webvar{swip},
|
---|
[588] | 1027 | rdns => $webvar{rdns},
|
---|
[691] | 1028 | vrf => $webvar{vrf},
|
---|
| 1029 | vlan => $webvar{vlan},
|
---|
[588] | 1030 | user => $authuser,
|
---|
[531] | 1031 | );
|
---|
| 1032 |
|
---|
| 1033 | # Semioptional values
|
---|
| 1034 | $updargs{privdata} = $webvar{privdata} if $IPDBacl{$authuser} =~ /s/;
|
---|
| 1035 | $updargs{node} = $webvar{node} if $webvar{node};
|
---|
| 1036 |
|
---|
[677] | 1037 | # collect per-IP rDNS fields. only copy over the ones that actually have something in them.
|
---|
| 1038 | my %iprev;
|
---|
| 1039 | foreach (keys %webvar) {
|
---|
| 1040 | $iprev{$_} = $webvar{$_} if /host_[\d.a-fA-F:]+/ && $webvar{$_};
|
---|
| 1041 | }
|
---|
[531] | 1042 |
|
---|
[695] | 1043 | # Merge with reserved freeblock
|
---|
| 1044 | $updargs{fbmerge} = $webvar{expandme} if $webvar{expandme};
|
---|
| 1045 |
|
---|
[677] | 1046 | my ($code,$msg) = updateBlock($ip_dbh, %updargs, iprev => \%iprev);
|
---|
| 1047 |
|
---|
[531] | 1048 | if ($code eq 'FAIL') {
|
---|
[166] | 1049 | syslog "err", "$authuser could not update block/IP '$webvar{block}': '$msg'";
|
---|
[517] | 1050 | $page->param(err => "Could not update block/IP $webvar{block}: $msg");
|
---|
[111] | 1051 | return;
|
---|
[4] | 1052 | }
|
---|
| 1053 |
|
---|
| 1054 | # If we get here, the operation succeeded.
|
---|
| 1055 | syslog "notice", "$authuser updated $webvar{block}";
|
---|
[531] | 1056 | ##fixme: log details of the change? old way is in the .debug stream anyway.
|
---|
[416] | 1057 | ##fixme: need to wedge something in to allow "update:field" notifications
|
---|
| 1058 | ## hmm. how to tell what changed? O_o
|
---|
[426] | 1059 | mailNotify($ip_dbh, 's:swi', "SWIPed: $disp_alloctypes{$webvar{alloctype}} $webvar{block}",
|
---|
[416] | 1060 | "$webvar{block} had SWIP status changed to \"Yes\" by $authuser") if $webvar{swip} eq 'on';
|
---|
[4] | 1061 |
|
---|
[517] | 1062 | ## node hack
|
---|
| 1063 | if ($webvar{node} && $webvar{node} ne '-') {
|
---|
[530] | 1064 | my $nodename = getNodeName($ip_dbh, $webvar{node});
|
---|
[517] | 1065 | $page->param(nodename => $nodename);
|
---|
| 1066 | }
|
---|
| 1067 | ## end node hack
|
---|
| 1068 |
|
---|
[380] | 1069 | # Link back to browse-routed or list-pool page on "Update complete" page.
|
---|
[634] | 1070 | my $pblock = getBlockData($ip_dbh, $binfo->{parent_id});
|
---|
| 1071 | $page->param(backid => $binfo->{parent_id});
|
---|
| 1072 | $page->param(backblock => $pblock->{block});
|
---|
| 1073 | $page->param(backpool => ($webvar{basetype} eq 'i'));
|
---|
[380] | 1074 |
|
---|
[536] | 1075 | # Do some HTML fiddling here instead of using ESCAPE=HTML in the template,
|
---|
| 1076 | # because otherwise we can't convert \n to <br>. *sigh*
|
---|
| 1077 | $webvar{notes} = $q->escapeHTML($webvar{notes}); # escape first...
|
---|
| 1078 | $webvar{notes} =~ s/\n/<br>\n/; # ... then convert newlines
|
---|
| 1079 | $webvar{privdata} = ($webvar{privdata} ? $q->escapeHTML($webvar{privdata}) : " ");
|
---|
| 1080 | $webvar{privdata} =~ s/\n/<br>\n/;
|
---|
| 1081 |
|
---|
[634] | 1082 | $page->param(cidr => $binfo->{block});
|
---|
[588] | 1083 | $page->param(rdns => $webvar{rdns});
|
---|
[517] | 1084 | $page->param(city => $webvar{city});
|
---|
| 1085 | $page->param(disptype => $disp_alloctypes{$webvar{alloctype}});
|
---|
| 1086 | $page->param(custid => $webvar{custid});
|
---|
| 1087 | $page->param(swip => $webvar{swip} eq 'on' ? 'Yes' : 'No');
|
---|
[536] | 1088 | $page->param(circid => $webvar{circid});
|
---|
| 1089 | $page->param(desc => $webvar{desc});
|
---|
| 1090 | $page->param(notes => $webvar{notes});
|
---|
[517] | 1091 | $page->param(privdata => $webvar{privdata})
|
---|
| 1092 | if $IPDBacl{$authuser} =~ /s/;
|
---|
[4] | 1093 |
|
---|
| 1094 | } # update()
|
---|
| 1095 |
|
---|
| 1096 |
|
---|
[702] | 1097 | sub prepSplit {
|
---|
| 1098 | if ($IPDBacl{$authuser} !~ /c/) {
|
---|
| 1099 | $aclerr = 'splitblock';
|
---|
| 1100 | return;
|
---|
| 1101 | }
|
---|
| 1102 |
|
---|
| 1103 | my $blockinfo = getBlockData($ip_dbh, $webvar{block});
|
---|
| 1104 |
|
---|
[705] | 1105 | # Tree navigation
|
---|
| 1106 | my $crumbs = getBreadCrumbs($ip_dbh, $blockinfo->{parent_id});
|
---|
| 1107 | my @rcrumbs = reverse (@$crumbs);
|
---|
| 1108 | $utilbar->param(breadcrumb => \@rcrumbs);
|
---|
| 1109 |
|
---|
[702] | 1110 | if ($blockinfo->{type} =~ /^.i$/) {
|
---|
| 1111 | $page->param(err => "Can't split a single IP allocation");
|
---|
| 1112 | return;
|
---|
| 1113 | }
|
---|
| 1114 |
|
---|
| 1115 | # Info about current allocation
|
---|
| 1116 | $page->param(oldblock => $blockinfo->{block});
|
---|
| 1117 | $page->param(block => $webvar{block});
|
---|
| 1118 |
|
---|
| 1119 | # Note that there are probably different rules that should be followed to restrict splitting IPv6 blocks;
|
---|
| 1120 | # strictly speaking it will be exceptionally rare to see smaller than a /64 assigned to a customer, since that
|
---|
| 1121 | # breaks auto-addressing schemes.
|
---|
| 1122 |
|
---|
| 1123 | # Generate possible splits
|
---|
| 1124 | my $block = new NetAddr::IP $blockinfo->{block};
|
---|
| 1125 | my $oldmask = $block->masklen;
|
---|
| 1126 | if ($blockinfo->{type} =~ /^.d$/) {
|
---|
| 1127 | # Non-PPP pools
|
---|
[705] | 1128 | $page->param(ispool => 1);
|
---|
[702] | 1129 | if ($oldmask+2 >= $block->bits) {
|
---|
| 1130 | $page->param(err => "Can't split a standard netblock pool any further");
|
---|
| 1131 | return;
|
---|
| 1132 | }
|
---|
| 1133 | # Allow splitting down to v4 /30 (which results in one usable IP; dubiously useful)
|
---|
| 1134 | $page->param(sp4mask => $oldmask+2) if $oldmask+2 <= $block->bits-2;
|
---|
| 1135 | } elsif ($blockinfo->{type} =~ /.p/) {
|
---|
[705] | 1136 | $page->param(ispool => 1);
|
---|
[702] | 1137 | # Allow splitting PPP pools down to v4 /31
|
---|
| 1138 | $page->param(sp4mask => $oldmask+2) if $oldmask+2 <= $block->bits-1;
|
---|
| 1139 | } else {
|
---|
| 1140 | # Allow splitting all other non-pool netblocks down to single IPs, which...
|
---|
| 1141 | # arguably should be *aggregated* in a pool. Except where they shouldn't.
|
---|
| 1142 | $page->param(sp4mask => $oldmask+2) if $oldmask+2 <= $block->bits;
|
---|
| 1143 | }
|
---|
| 1144 | # set the split-in-half mask
|
---|
| 1145 | $page->param(sp2mask => $oldmask+1);
|
---|
| 1146 |
|
---|
| 1147 | # Generate possible shrink targets
|
---|
| 1148 | my @keepers = $block->split($block->masklen+1);
|
---|
| 1149 | $page->param(newblockA => $keepers[0]);
|
---|
| 1150 | $page->param(newblockB => $keepers[1]);
|
---|
| 1151 | } # prepSplit()
|
---|
| 1152 |
|
---|
| 1153 |
|
---|
| 1154 | sub doSplit {
|
---|
| 1155 | if ($IPDBacl{$authuser} !~ /c/) {
|
---|
| 1156 | $aclerr = 'splitblock';
|
---|
| 1157 | return;
|
---|
| 1158 | }
|
---|
| 1159 |
|
---|
| 1160 | ##fixme: need consistent way to identify "this thing that is this thing" with only the ID
|
---|
| 1161 | # also applies to other locations
|
---|
| 1162 | my $blockinfo = getBlockData($ip_dbh, $webvar{block});
|
---|
| 1163 |
|
---|
[705] | 1164 | # Tree navigation
|
---|
| 1165 | my $crumbs = getBreadCrumbs($ip_dbh, $blockinfo->{parent_id});
|
---|
| 1166 | my @rcrumbs = reverse (@$crumbs);
|
---|
| 1167 | $utilbar->param(breadcrumb => \@rcrumbs);
|
---|
| 1168 |
|
---|
[702] | 1169 | if ($blockinfo->{type} =~ /^.i$/) {
|
---|
| 1170 | $page->param(err => "Can't split a single IP allocation");
|
---|
| 1171 | return;
|
---|
| 1172 | }
|
---|
| 1173 |
|
---|
| 1174 | if ($webvar{subact} eq 'split') {
|
---|
| 1175 | $page->param(issplit => 1);
|
---|
[705] | 1176 | my $block = new NetAddr::IP $blockinfo->{block};
|
---|
[707] | 1177 | my $newblocks = splitBlock($ip_dbh, id => $webvar{block}, basetype => 'b', newmask => $webvar{split},
|
---|
| 1178 | user => $authuser);
|
---|
[702] | 1179 | if ($newblocks) {
|
---|
| 1180 | $page->param(newblocks => $newblocks);
|
---|
| 1181 | } else {
|
---|
| 1182 | $page->param(err => $IPDB::errstr);
|
---|
| 1183 | }
|
---|
| 1184 |
|
---|
[705] | 1185 | } elsif ($webvar{subact} eq 'shrink') {
|
---|
| 1186 | $page->param(nid => $webvar{block});
|
---|
| 1187 | $page->param(newblock => $webvar{shrink});
|
---|
| 1188 | my $newfree = shrinkBlock($ip_dbh, $webvar{block}, $webvar{shrink});
|
---|
| 1189 | if ($newfree) {
|
---|
| 1190 | $page->param(newfb => $newfree);
|
---|
| 1191 | } else {
|
---|
| 1192 | $page->param(err => $IPDB::errstr);
|
---|
| 1193 | }
|
---|
| 1194 |
|
---|
[702] | 1195 | } else {
|
---|
[705] | 1196 | # Your llama is on fire.
|
---|
| 1197 | $page->param(err => "Missing form field that shouldn't be missing.");
|
---|
| 1198 | return;
|
---|
[702] | 1199 | }
|
---|
[705] | 1200 |
|
---|
| 1201 | # common bits
|
---|
| 1202 | $page->param(cidr => $blockinfo->{block});
|
---|
| 1203 | # and the backlink to the parent container
|
---|
| 1204 | my $pinfo = getBlockData($ip_dbh, $blockinfo->{parent_id});
|
---|
| 1205 | $page->param(backid => $blockinfo->{parent_id});
|
---|
| 1206 | $page->param(backblock => $pinfo->{block});
|
---|
[702] | 1207 | } # doSplit()
|
---|
| 1208 |
|
---|
| 1209 |
|
---|
[717] | 1210 | # Set up for merge
|
---|
| 1211 | sub prepMerge {
|
---|
| 1212 | my $binfo = getBlockData($ip_dbh, $webvar{block});
|
---|
| 1213 | $page->param(block => $webvar{block});
|
---|
| 1214 | $page->param(ispool => $binfo->{type} =~ /.[dp]/);
|
---|
| 1215 | $page->param(ismaster => $binfo->{type} eq 'mm');
|
---|
| 1216 | $page->param(oldblock => $binfo->{block});
|
---|
| 1217 | $page->param(oldtype => $disp_alloctypes{$binfo->{type}});
|
---|
| 1218 | $page->param(typelist => getTypeList($ip_dbh, 'n', $binfo->{type})); # down the rabbit hole we go...
|
---|
| 1219 |
|
---|
| 1220 | # Tree navigation
|
---|
| 1221 | my $crumbs = getBreadCrumbs($ip_dbh, $binfo->{parent_id});
|
---|
| 1222 | my @rcrumbs = reverse (@$crumbs);
|
---|
| 1223 | $utilbar->param(breadcrumb => \@rcrumbs);
|
---|
| 1224 | } # prepMerge()
|
---|
| 1225 |
|
---|
| 1226 |
|
---|
[4] | 1227 | # Delete an allocation.
|
---|
[106] | 1228 | sub remove {
|
---|
[233] | 1229 | if ($IPDBacl{$authuser} !~ /d/) {
|
---|
[517] | 1230 | $aclerr = 'delblock';
|
---|
[233] | 1231 | return;
|
---|
| 1232 | }
|
---|
| 1233 |
|
---|
[4] | 1234 | # Serves'em right for getting here...
|
---|
| 1235 | if (!defined($webvar{block})) {
|
---|
[517] | 1236 | $page->param(err => "Can't delete a block that doesn't exist");
|
---|
[111] | 1237 | return;
|
---|
[4] | 1238 | }
|
---|
| 1239 |
|
---|
[538] | 1240 | my $blockdata;
|
---|
[638] | 1241 | $blockdata = getBlockData($ip_dbh, $webvar{block}, $webvar{basetype});
|
---|
[4] | 1242 |
|
---|
[638] | 1243 | if ($blockdata->{parent_id} == 0) { # $webvar{alloctype} eq 'mm'
|
---|
[538] | 1244 | $blockdata->{city} = "N/A";
|
---|
| 1245 | $blockdata->{custid} = "N/A";
|
---|
| 1246 | $blockdata->{circuitid} = "N/A";
|
---|
| 1247 | $blockdata->{description} = "N/A";
|
---|
| 1248 | $blockdata->{notes} = "N/A";
|
---|
| 1249 | $blockdata->{privdata} = "N/A";
|
---|
[638] | 1250 | } # end cases for different alloctypes
|
---|
[517] | 1251 |
|
---|
[638] | 1252 | $page->param(blockid => $webvar{block});
|
---|
| 1253 | $page->param(basetype => $webvar{basetype});
|
---|
[4] | 1254 |
|
---|
[538] | 1255 | $page->param(block => $blockdata->{block});
|
---|
[589] | 1256 | $page->param(rdns => $blockdata->{rdns});
|
---|
| 1257 |
|
---|
| 1258 | # maybe need to apply more magic here?
|
---|
| 1259 | # most allocations we *do* want to autodelete the forward as well as reverse; for a handful we don't.
|
---|
| 1260 | # -> all real blocks (nb: pool IPs need extra handling)
|
---|
| 1261 | # -> NOC/private-IP (how to ID?)
|
---|
| 1262 | # -> anything with a pattern matching $IPDB::domain?
|
---|
| 1263 | if ($blockdata->{type} !~ /^.i$/) {
|
---|
| 1264 | $page->param(autodel => 1);
|
---|
| 1265 | }
|
---|
| 1266 |
|
---|
[538] | 1267 | $page->param(disptype => $disp_alloctypes{$blockdata->{type}});
|
---|
| 1268 | $page->param(city => $blockdata->{city});
|
---|
| 1269 | $page->param(custid => $blockdata->{custid});
|
---|
| 1270 | $page->param(circid => $blockdata->{circuitid});
|
---|
| 1271 | $page->param(desc => $blockdata->{description});
|
---|
| 1272 | $blockdata->{notes} = $q->escapeHTML($blockdata->{notes});
|
---|
| 1273 | $blockdata->{notes} =~ s/\n/<br>\n/;
|
---|
| 1274 | $page->param(notes => $blockdata->{notes});
|
---|
| 1275 | $blockdata->{privdata} = $q->escapeHTML($blockdata->{privdata});
|
---|
[540] | 1276 | $blockdata->{privdata} = ' ' if !$blockdata->{privdata};
|
---|
[538] | 1277 | $blockdata->{privdata} =~ s/\n/<br>\n/;
|
---|
| 1278 | $page->param(privdata => $blockdata->{privdata}) if $IPDBacl{$authuser} =~ /s/;
|
---|
| 1279 | $page->param(delpool => $blockdata->{type} =~ /^.[pd]$/);
|
---|
[4] | 1280 |
|
---|
[517] | 1281 | } # end remove()
|
---|
[4] | 1282 |
|
---|
| 1283 |
|
---|
| 1284 | # Delete an allocation. Return it to the freeblocks table; munge
|
---|
| 1285 | # data as necessary to keep as few records as possible in freeblocks
|
---|
| 1286 | # to prevent weirdness when allocating blocks later.
|
---|
| 1287 | # Remove IPs from pool listing if necessary
|
---|
| 1288 | sub finalDelete {
|
---|
[233] | 1289 | if ($IPDBacl{$authuser} !~ /d/) {
|
---|
[517] | 1290 | $aclerr = 'delblock';
|
---|
[233] | 1291 | return;
|
---|
| 1292 | }
|
---|
[4] | 1293 |
|
---|
[370] | 1294 | # need to retrieve block data before deleting so we can notify on that
|
---|
[638] | 1295 | my $blockinfo = getBlockData($ip_dbh, $webvar{block}, $webvar{basetype});
|
---|
| 1296 | my $pinfo = getBlockData($ip_dbh, $blockinfo->{parent_id}, 'b');
|
---|
[370] | 1297 |
|
---|
[638] | 1298 | my ($code,$msg) = deleteBlock($ip_dbh, $webvar{block}, $webvar{basetype}, $webvar{delforward}, $authuser);
|
---|
[4] | 1299 |
|
---|
[638] | 1300 | $page->param(block => $blockinfo->{block});
|
---|
[651] | 1301 | $page->param(bdisp => $q->escapeHTML($disp_alloctypes{$blockinfo->{type}}));
|
---|
[638] | 1302 | $page->param(delparent_id => $blockinfo->{parent_id});# if $webvar{rdepth};
|
---|
[651] | 1303 | if ($pinfo) {
|
---|
| 1304 | $page->param(delparent => $pinfo->{block});
|
---|
| 1305 | $page->param(pdisp => $q->escapeHTML($disp_alloctypes{$pinfo->{type}}));
|
---|
| 1306 | }
|
---|
[638] | 1307 | $page->param(returnpool => ($webvar{basetype} eq 'i') );
|
---|
[591] | 1308 | if ($code =~ /^WARN(POOL|MERGE)/) {
|
---|
[638] | 1309 | my ($pid,$pcidr) = split /,/, $msg;
|
---|
[654] | 1310 | my $real_pinfo = getBlockData($ip_dbh, $pid, 'b');
|
---|
[638] | 1311 | $page->param(parent_id => $pid);
|
---|
| 1312 | $page->param(parent => $pcidr);
|
---|
[654] | 1313 | $page->param(real_disp => $q->escapeHTML($disp_alloctypes{$real_pinfo->{type}}));
|
---|
[577] | 1314 | $page->param(mergeip => $code eq 'WARNPOOL');
|
---|
| 1315 | }
|
---|
[591] | 1316 | if ($code eq 'WARN') {
|
---|
| 1317 | $msg =~ s/\n/<br>\n/g;
|
---|
| 1318 | $page->param(genwarn => $msg);
|
---|
| 1319 | }
|
---|
[577] | 1320 | if ($code eq 'OK' || $code =~ /^WARN/) {
|
---|
[638] | 1321 | syslog "notice", "$authuser deallocated '".$blockinfo->{type}."'-type netblock $webvar{block} ".
|
---|
[528] | 1322 | $blockinfo->{custid}.", ".$blockinfo->{city}.", desc='".$blockinfo->{description}."'";
|
---|
[638] | 1323 | mailNotify($ip_dbh, 'da', "REMOVED: ".$disp_alloctypes{$blockinfo->{type}}." $webvar{block}",
|
---|
| 1324 | $disp_alloctypes{$blockinfo->{type}}." $webvar{block} deallocated by $authuser\n".
|
---|
[528] | 1325 | "CustID: ".$blockinfo->{custid}."\nCity: ".$blockinfo->{city}.
|
---|
| 1326 | "\nDescription: ".$blockinfo->{description}."\n");
|
---|
[106] | 1327 | } else {
|
---|
[517] | 1328 | $page->param(failmsg => $msg);
|
---|
[106] | 1329 | if ($webvar{alloctype} =~ /^.i$/) {
|
---|
| 1330 | syslog "err", "$authuser could not deallocate static IP '$webvar{block}': '$msg'";
|
---|
| 1331 | } else {
|
---|
| 1332 | syslog "err", "$authuser could not deallocate netblock '$webvar{block}': '$msg'";
|
---|
[517] | 1333 | $page->param(netblock => 1);
|
---|
[4] | 1334 | }
|
---|
[106] | 1335 | }
|
---|
[4] | 1336 |
|
---|
| 1337 | } # finalDelete
|
---|