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