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