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