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