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