[4] | 1 | #!/usr/bin/perl
|
---|
| 2 | # ipdb/cgi-bin/main.cgi
|
---|
[8] | 3 | ###
|
---|
| 4 | # SVN revision info
|
---|
| 5 | # $Date: 2015-01-14 17:58:58 +0000 (Wed, 14 Jan 2015) $
|
---|
| 6 | # SVN revision $Rev: 674 $
|
---|
| 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
|
---|
| 72 | $ENV{HTML_TEMPLATE_ROOT} = $thingroot."templates";
|
---|
[233] | 73 |
|
---|
[517] | 74 | my $header = HTML::Template->new(filename => "header.tmpl");
|
---|
| 75 | my $footer = HTML::Template->new(filename => "footer.tmpl");
|
---|
[233] | 76 |
|
---|
[517] | 77 | $header->param(version => $IPDB::VERSION);
|
---|
| 78 | $header->param(addperm => $IPDBacl{$authuser} =~ /a/);
|
---|
| 79 | $header->param(webpath => $IPDB::webpath);
|
---|
| 80 | print "Content-type: text/html\n\n", $header->output;
|
---|
[4] | 81 |
|
---|
| 82 |
|
---|
| 83 | #main()
|
---|
[517] | 84 | my $aclerr;
|
---|
[4] | 85 |
|
---|
| 86 | if(!defined($webvar{action})) {
|
---|
[517] | 87 | $webvar{action} = "index"; #shuts up the warnings.
|
---|
[4] | 88 | }
|
---|
| 89 |
|
---|
[517] | 90 | my $page;
|
---|
| 91 | if (-e "$ENV{HTML_TEMPLATE_ROOT}/$webvar{action}.tmpl") {
|
---|
[553] | 92 | $page = HTML::Template->new(filename => "$webvar{action}.tmpl", loop_context_vars => 1, global_vars => 1);
|
---|
[517] | 93 | } else {
|
---|
| 94 | $page = HTML::Template->new(filename => "dunno.tmpl");
|
---|
| 95 | }
|
---|
| 96 |
|
---|
[4] | 97 | if($webvar{action} eq 'index') {
|
---|
| 98 | showSummary();
|
---|
[233] | 99 | } elsif ($webvar{action} eq 'addmaster') {
|
---|
| 100 | if ($IPDBacl{$authuser} !~ /a/) {
|
---|
[517] | 101 | $aclerr = 'addmaster';
|
---|
[233] | 102 | }
|
---|
[582] | 103 |
|
---|
| 104 | # Retrieve the list of DNS locations if we've got a place to grab them from
|
---|
| 105 | if ($IPDB::rpc_url) {
|
---|
| 106 |
|
---|
| 107 | my %rpcargs = (
|
---|
| 108 | rpcuser => $authuser,
|
---|
| 109 | group => 1, # bleh
|
---|
| 110 | defloc => '',
|
---|
| 111 | );
|
---|
[623] | 112 | my $result = IPDB::_rpc('getLocDropdown', %rpcargs);
|
---|
[582] | 113 | $page->param(loclist => $result);
|
---|
| 114 | }
|
---|
| 115 |
|
---|
[4] | 116 | } elsif ($webvar{action} eq 'newmaster') {
|
---|
| 117 |
|
---|
[233] | 118 | if ($IPDBacl{$authuser} !~ /a/) {
|
---|
[517] | 119 | $aclerr = 'addmaster';
|
---|
[233] | 120 | } else {
|
---|
| 121 | my $cidr = new NetAddr::IP $webvar{cidr};
|
---|
[517] | 122 | $page->param(cidr => "$cidr");
|
---|
[4] | 123 |
|
---|
[582] | 124 | my ($code,$msg) = addMaster($ip_dbh, $webvar{cidr}, (vrf => $webvar{vrf}, rdns => $webvar{rdns},
|
---|
| 125 | rwhois => $webvar{rwhois}, defloc => $webvar{loc}, user => $authuser) );
|
---|
[4] | 126 |
|
---|
[371] | 127 | if ($code eq 'FAIL') {
|
---|
[320] | 128 | syslog "err", "Could not add master block '$webvar{cidr}' to database: '$msg'";
|
---|
[517] | 129 | $page->param(err => $msg);
|
---|
[233] | 130 | } else {
|
---|
[624] | 131 | $page->param(parent => $msg);
|
---|
[582] | 132 | if ($code eq 'WARN') {
|
---|
[624] | 133 | $IPDB::errstr =~ s/\n\n/<br>\n/g;
|
---|
| 134 | $IPDB::errstr =~ s/:\n/:<br>\n/g;
|
---|
| 135 | $page->param(warn => $IPDB::errstr);
|
---|
[582] | 136 | }
|
---|
[233] | 137 | syslog "info", "$authuser added master block $webvar{cidr}";
|
---|
| 138 | }
|
---|
[4] | 139 |
|
---|
[233] | 140 | } # ACL check
|
---|
| 141 |
|
---|
[4] | 142 | } # end add new master
|
---|
| 143 |
|
---|
[567] | 144 | elsif ($webvar{action} eq 'showsubs') {
|
---|
| 145 | showSubs();
|
---|
| 146 | }
|
---|
| 147 |
|
---|
[4] | 148 | elsif($webvar{action} eq 'listpool') {
|
---|
[528] | 149 | showPool();
|
---|
[4] | 150 | }
|
---|
| 151 |
|
---|
| 152 | # Not modified or added; just shuffled
|
---|
| 153 | elsif($webvar{action} eq 'assign') {
|
---|
| 154 | assignBlock();
|
---|
| 155 | }
|
---|
| 156 | elsif($webvar{action} eq 'confirm') {
|
---|
| 157 | confirmAssign();
|
---|
| 158 | }
|
---|
| 159 | elsif($webvar{action} eq 'insert') {
|
---|
| 160 | insertAssign();
|
---|
| 161 | }
|
---|
| 162 | elsif($webvar{action} eq 'edit') {
|
---|
| 163 | edit();
|
---|
| 164 | }
|
---|
| 165 | elsif($webvar{action} eq 'update') {
|
---|
| 166 | update();
|
---|
| 167 | }
|
---|
| 168 | elsif($webvar{action} eq 'delete') {
|
---|
| 169 | remove();
|
---|
| 170 | }
|
---|
| 171 | elsif($webvar{action} eq 'finaldelete') {
|
---|
| 172 | finalDelete();
|
---|
| 173 | }
|
---|
[397] | 174 | elsif ($webvar{action} eq 'nodesearch') {
|
---|
[519] | 175 | my $nodelist = getNodeList($ip_dbh);
|
---|
| 176 | $page->param(nodelist => $nodelist);
|
---|
[517] | 177 | }
|
---|
[397] | 178 |
|
---|
[517] | 179 | # DB failure. Can't do much here, really.
|
---|
| 180 | elsif ($webvar{action} eq 'dberr') {
|
---|
| 181 | $page->param(errmsg => $errstr);
|
---|
[397] | 182 | }
|
---|
| 183 |
|
---|
[517] | 184 | # Default is an error. It shouldn't be possible to get here unless you're
|
---|
| 185 | # randomly feeding in values for webvar{action}.
|
---|
[4] | 186 | else {
|
---|
| 187 | my $rnd = rand 500;
|
---|
| 188 | my $boing = sprintf("%.2f", rand 500);
|
---|
[517] | 189 | my @excuses = (
|
---|
| 190 | "Aether cloudy. Ask again later about $webvar{action}.",
|
---|
| 191 | "The gods are unhappy with your sacrificial $webvar{action}.",
|
---|
| 192 | "Because one of $webvar{action}'s legs are both the same",
|
---|
| 193 | "<b>wibble</b><br>Can't $webvar{action}, the grue will get me!<br>Can't $webvar{action}, the grue will get me!",
|
---|
| 194 | "Hey, man, you've had your free $webvar{action}. Next one's gonna... <i>cost</i>....",
|
---|
| 195 | "I ain't done $webvar{action}",
|
---|
| 196 | "Oooo, look! A flying $webvar{action}!",
|
---|
| 197 | "$webvar{action} too evil, avoiding.",
|
---|
| 198 | "Rocks fall, $webvar{action} dies.",
|
---|
| 199 | "Bit bucket must be emptied before I can $webvar{action}..."
|
---|
| 200 | );
|
---|
| 201 | $page->param(dunno => $excuses[$rnd/50.0]);
|
---|
[4] | 202 | }
|
---|
[111] | 203 | ## Finally! Done with that NASTY "case" emulation!
|
---|
[4] | 204 |
|
---|
| 205 |
|
---|
[517] | 206 | # Switch to a different template if we've tripped on an ACL error.
|
---|
| 207 | # Note that this should only be exercised in development, when
|
---|
| 208 | # deeplinked, or when being attacked; normal ACL handling should
|
---|
| 209 | # remove the links a user is not allowed to click on.
|
---|
| 210 | if ($aclerr) {
|
---|
| 211 | $page = HTML::Template->new(filename => "aclerror.tmpl");
|
---|
| 212 | $page->param(ipdbfunc => $aclmsg{$aclerr});
|
---|
| 213 | }
|
---|
[4] | 214 |
|
---|
[106] | 215 | # Clean up IPDB globals, DB handle, etc.
|
---|
[111] | 216 | finish($ip_dbh);
|
---|
[199] | 217 |
|
---|
[517] | 218 | ## Do all our printing here so we can generate errors and stick them into the slots in the templates.
|
---|
[199] | 219 |
|
---|
[517] | 220 | # can't do this yet, too many blowups
|
---|
| 221 | #print "Content-type: text/html\n\n", $header->output;
|
---|
| 222 | $page->param(webpath => $IPDB::webpath);
|
---|
| 223 | print $page->output;
|
---|
| 224 |
|
---|
| 225 | # include the admin tools link in the output?
|
---|
| 226 | $footer->param(adminlink => ($IPDBacl{$authuser} =~ /A/));
|
---|
| 227 | $footer->param(webpath => $IPDB::webpath);
|
---|
| 228 | print $footer->output;
|
---|
| 229 |
|
---|
[106] | 230 | # Just in case something waaaayyy down isn't in place
|
---|
| 231 | # properly... we exit explicitly.
|
---|
[517] | 232 | exit 0;
|
---|
[4] | 233 |
|
---|
| 234 |
|
---|
| 235 | # Initial display: Show master blocks with total allocated subnets, total free subnets
|
---|
[118] | 236 | sub showSummary {
|
---|
[523] | 237 | my $masterlist = listSummary($ip_dbh);
|
---|
| 238 | $page->param(masterlist => $masterlist);
|
---|
[106] | 239 |
|
---|
[517] | 240 | $page->param(addmaster => ($IPDBacl{$authuser} =~ /a/) );
|
---|
[4] | 241 | } # showSummary
|
---|
| 242 |
|
---|
| 243 |
|
---|
[566] | 244 | # Display blocks immediately within a given parent
|
---|
| 245 | sub showSubs {
|
---|
[627] | 246 | my $pinfo = getBlockData($ip_dbh, $webvar{parent});
|
---|
| 247 |
|
---|
| 248 | $page->param(del_id => $webvar{parent});
|
---|
| 249 | $page->param(block => $pinfo->{block});
|
---|
[566] | 250 | $page->param(mayadd => ($IPDBacl{$authuser} =~ /a/));
|
---|
| 251 | $page->param(maydel => ($IPDBacl{$authuser} =~ /d/));
|
---|
[4] | 252 |
|
---|
[627] | 253 | my $sublist = listSubs($ip_dbh, parent => $webvar{parent});
|
---|
[566] | 254 | $page->param(sublist => $sublist);
|
---|
[4] | 255 |
|
---|
[627] | 256 | my $flist = listFree($ip_dbh, parent => $webvar{parent});
|
---|
[566] | 257 | $page->param(freelist => $flist);
|
---|
| 258 | } # showSubs
|
---|
[4] | 259 |
|
---|
| 260 |
|
---|
| 261 | # List the IPs used in a pool
|
---|
[528] | 262 | sub showPool {
|
---|
[4] | 263 |
|
---|
[631] | 264 | my $poolinfo = getBlockData($ip_dbh, $webvar{pool});
|
---|
| 265 | my $cidr = new NetAddr::IP $poolinfo->{block};
|
---|
[4] | 266 |
|
---|
[631] | 267 | $page->param(block => $cidr);
|
---|
[517] | 268 | $page->param(netip => $cidr->addr);
|
---|
| 269 | $cidr++;
|
---|
| 270 | $page->param(gate => $cidr->addr);
|
---|
| 271 | $cidr--; $cidr--;
|
---|
| 272 | $page->param(bcast => $cidr->addr);
|
---|
| 273 | $page->param(mask => $cidr->mask);
|
---|
[157] | 274 |
|
---|
[528] | 275 | $page->param(disptype => $disp_alloctypes{$poolinfo->{type}});
|
---|
| 276 | $page->param(city => $poolinfo->{city});
|
---|
[517] | 277 |
|
---|
[157] | 278 | # Only display net/gw/bcast if it's a "real" netblock and not a PPP(oE) lunacy
|
---|
[528] | 279 | $page->param(realblock => $poolinfo->{type} =~ /^.d$/);
|
---|
[4] | 280 |
|
---|
| 281 | # probably have to add an "edit IP allocation" link here somewhere.
|
---|
| 282 |
|
---|
[528] | 283 | my $plist = listPool($ip_dbh, $webvar{pool});
|
---|
| 284 | # technically slightly more efficient to check the ACL in an if () once outside the foreach
|
---|
| 285 | foreach (@{$plist}) {
|
---|
| 286 | $$_{maydel} = $IPDBacl{$authuser} =~ /d/;
|
---|
[4] | 287 | }
|
---|
[528] | 288 | $page->param(poolips => $plist);
|
---|
| 289 | } # end showPool
|
---|
[4] | 290 |
|
---|
| 291 |
|
---|
[106] | 292 | # Show "Add new allocation" page. Note that the actual page may
|
---|
| 293 | # be one of two templates, and the lists come from the database.
|
---|
[4] | 294 | sub assignBlock {
|
---|
| 295 |
|
---|
[233] | 296 | if ($IPDBacl{$authuser} !~ /a/) {
|
---|
[517] | 297 | $aclerr = 'addblock';
|
---|
[233] | 298 | return;
|
---|
| 299 | }
|
---|
| 300 |
|
---|
[517] | 301 | # hack pthbttt eww
|
---|
[633] | 302 | $webvar{parent} = 0 if !$webvar{parent};
|
---|
[517] | 303 | $webvar{block} = '' if !$webvar{block};
|
---|
[21] | 304 |
|
---|
[517] | 305 | # hmm. TMPL_IF block and TMPL_ELSE block on these instead?
|
---|
| 306 | $page->param(rowa => 'row'.($webvar{block} eq '' ? 1 : 0));
|
---|
| 307 | $page->param(rowb => 'row'.($webvar{block} eq '' ? 0 : 1));
|
---|
[575] | 308 | $page->param(allocfrom => $webvar{block}); # fb-assign flag, if block is set, we're in fb-assign
|
---|
[517] | 309 |
|
---|
[633] | 310 | if ($webvar{fbid} || $webvar{fbtype}) {
|
---|
[575] | 311 |
|
---|
| 312 | # Common case, according to reported usage. Block to assign is specified.
|
---|
[21] | 313 | my $block = new NetAddr::IP $webvar{block};
|
---|
[187] | 314 |
|
---|
[633] | 315 | my $rdns = getBlockRDNS($ip_dbh, id => $webvar{parent}, type => $webvar{fbtype}, user => $authuser);
|
---|
[585] | 316 | $page->param(rdns => $rdns) if $rdns;
|
---|
[633] | 317 | $page->param(parent => $webvar{parent});
|
---|
| 318 | $page->param(fbid => $webvar{fbid});
|
---|
[585] | 319 |
|
---|
[575] | 320 | $webvar{fbtype} = '' if !$webvar{fbtype};
|
---|
| 321 | if ($webvar{fbtype} eq 'i') {
|
---|
[633] | 322 | my $ipinfo = getBlockData($ip_dbh, $webvar{block}, 'i');
|
---|
| 323 | my $pinfo = getBlockData($ip_dbh, $webvar{parent});
|
---|
[575] | 324 | $page->param(
|
---|
| 325 | fbip => 1,
|
---|
[633] | 326 | block => $ipinfo->{block},
|
---|
[575] | 327 | fbdisptype => $list_alloctypes{$ipinfo->{type}},
|
---|
| 328 | type => $ipinfo->{type},
|
---|
[633] | 329 | allocfrom => $pinfo->{block},
|
---|
[575] | 330 | );
|
---|
[187] | 331 | } else {
|
---|
[529] | 332 | # get "primary" alloctypes, since these are all that can correctly be assigned if we're in this branch
|
---|
[575] | 333 | my $tlist = getTypeList($ip_dbh, 'n');
|
---|
[529] | 334 | $tlist->[0]->{sel} = 1;
|
---|
[575] | 335 | $page->param(typelist => $tlist, block => $block);
|
---|
[106] | 336 | }
|
---|
[575] | 337 |
|
---|
[21] | 338 | } else {
|
---|
[575] | 339 |
|
---|
| 340 | # Uncommon case, according to reported usage. Block to assign needs to be found based on criteria.
|
---|
[541] | 341 | my $mlist = getMasterList($ip_dbh, 'c');
|
---|
| 342 | $page->param(masterlist => $mlist);
|
---|
[517] | 343 |
|
---|
| 344 | my @pops;
|
---|
[633] | 345 | foreach my $pop (@citylist) {
|
---|
[517] | 346 | my %row = (pop => $pop);
|
---|
| 347 | push (@pops, \%row);
|
---|
[92] | 348 | }
|
---|
[517] | 349 | $page->param(pops => \@pops);
|
---|
| 350 |
|
---|
[529] | 351 | # get all standard alloctypes
|
---|
| 352 | my $tlist = getTypeList($ip_dbh, 'a');
|
---|
| 353 | $tlist->[0]->{sel} = 1;
|
---|
| 354 | $page->param(typelist => $tlist);
|
---|
[21] | 355 | }
|
---|
[517] | 356 |
|
---|
| 357 | my @cities;
|
---|
[92] | 358 | foreach my $city (@citylist) {
|
---|
[517] | 359 | my %row = (city => $city);
|
---|
| 360 | push (@cities, \%row);
|
---|
[92] | 361 | }
|
---|
[517] | 362 | $page->param(citylist => \@cities);
|
---|
[4] | 363 |
|
---|
[397] | 364 | ## node hack
|
---|
[530] | 365 | my $nlist = getNodeList($ip_dbh);
|
---|
| 366 | $page->param(nodelist => $nlist);
|
---|
[397] | 367 | ## end node hack
|
---|
| 368 |
|
---|
[517] | 369 | $page->param(privdata => $IPDBacl{$authuser} =~ /s/);
|
---|
[284] | 370 |
|
---|
[4] | 371 | } # assignBlock
|
---|
| 372 |
|
---|
| 373 |
|
---|
| 374 | # Take info on requested IP assignment and see what we can provide.
|
---|
| 375 | sub confirmAssign {
|
---|
[233] | 376 | if ($IPDBacl{$authuser} !~ /a/) {
|
---|
[517] | 377 | $aclerr = 'addblock';
|
---|
[233] | 378 | return;
|
---|
| 379 | }
|
---|
[4] | 380 |
|
---|
| 381 | my $cidr;
|
---|
| 382 | my $alloc_from;
|
---|
[633] | 383 | my $fbid = $webvar{fbid};
|
---|
| 384 | my $p_id = $webvar{parent};
|
---|
[4] | 385 |
|
---|
| 386 | # Going to manually validate some items.
|
---|
| 387 | # custid and city are automagic.
|
---|
[111] | 388 | return if !validateInput();
|
---|
[4] | 389 |
|
---|
[665] | 390 | # make sure this is defined
|
---|
| 391 | $webvar{fbassign} = 'n' if !$webvar{fbassign};
|
---|
| 392 |
|
---|
[4] | 393 | # Several different cases here.
|
---|
| 394 | # Static IP vs netblock
|
---|
| 395 | # + Different flavours of static IP
|
---|
| 396 | # + Different flavours of netblock
|
---|
| 397 |
|
---|
[575] | 398 | if ($webvar{alloctype} =~ /^.i$/ && $webvar{fbassign} ne 'y') {
|
---|
[665] | 399 | if (!$webvar{pop}) {
|
---|
| 400 | $page->param(err => "Please select a location/POP site to allocate from.");
|
---|
| 401 | return;
|
---|
| 402 | }
|
---|
[532] | 403 | my $plist = getPoolSelect($ip_dbh, $webvar{alloctype}, $webvar{pop});
|
---|
[517] | 404 | $page->param(staticip => 1);
|
---|
[532] | 405 | $page->param(poollist => $plist) if $plist;
|
---|
[4] | 406 | $cidr = "Single static IP";
|
---|
[517] | 407 | ##fixme: need to handle "no available pools"
|
---|
[4] | 408 |
|
---|
| 409 | } else { # end show pool options
|
---|
[21] | 410 |
|
---|
[533] | 411 | if ($webvar{fbassign} && $webvar{fbassign} eq 'y') {
|
---|
[21] | 412 | $cidr = new NetAddr::IP $webvar{block};
|
---|
[575] | 413 | $alloc_from = new NetAddr::IP $webvar{allocfrom};
|
---|
[21] | 414 | $webvar{maskbits} = $cidr->masklen;
|
---|
| 415 | } else { # done with direct freeblocks assignment
|
---|
| 416 |
|
---|
| 417 | if (!$webvar{maskbits}) {
|
---|
[517] | 418 | $page->param(err => "Please specify a CIDR mask length.");
|
---|
[111] | 419 | return;
|
---|
[21] | 420 | }
|
---|
[533] | 421 |
|
---|
| 422 | ##fixme ick, ew, bleh. gotta handle the failure message generation better. push it into findAllocateFrom()?
|
---|
| 423 | my $failmsg = "No suitable free block found.<br>\n";
|
---|
[187] | 424 | if ($webvar{alloctype} eq 'rm') {
|
---|
[533] | 425 | $failmsg .= "We do not have a free routeable block of that size.<br>\n".
|
---|
| 426 | "You will have to either route a set of smaller netblocks or a single smaller netblock.";
|
---|
[4] | 427 | } else {
|
---|
[214] | 428 | if ($webvar{alloctype} =~ /^.[pc]$/) {
|
---|
[533] | 429 | $failmsg .= "You will have to route another superblock from one of the<br>\n".
|
---|
| 430 | "master blocks or chose a smaller block size for the pool.";
|
---|
[21] | 431 | } else {
|
---|
[517] | 432 | if (!$webvar{pop}) {
|
---|
| 433 | $page->param(err => 'Please select a POP to route the block from/through.');
|
---|
| 434 | return;
|
---|
| 435 | }
|
---|
[533] | 436 | $failmsg .= "You will have to route another superblock to $webvar{pop}<br>\n".
|
---|
| 437 | "from one of the master blocks or chose a smaller blocksize.";
|
---|
[21] | 438 | }
|
---|
[4] | 439 | }
|
---|
[533] | 440 |
|
---|
[575] | 441 | ## fixme: add rdepth?
|
---|
[633] | 442 | ($fbid,$cidr,$p_id) = findAllocateFrom($ip_dbh, $webvar{maskbits}, $webvar{alloctype},
|
---|
| 443 | $webvar{city}, $webvar{pop}, (master => $webvar{allocfrom}, allowpriv => $webvar{allowpriv}) );
|
---|
[533] | 444 | if (!$cidr) {
|
---|
[517] | 445 | $page->param(err => $failmsg);
|
---|
[111] | 446 | return;
|
---|
[21] | 447 | }
|
---|
[533] | 448 | $cidr = new NetAddr::IP $cidr;
|
---|
[575] | 449 |
|
---|
| 450 | # this chunk now specific to "guided" allocation; freeblock-select can now slice-n-dice on its own.
|
---|
| 451 | $alloc_from = "$cidr";
|
---|
| 452 | # If the block to be allocated is smaller than the one we found,
|
---|
| 453 | # figure out the "real" block to be allocated.
|
---|
| 454 | if ($cidr->masklen() ne $webvar{maskbits}) {
|
---|
| 455 | my $maskbits = $cidr->masklen();
|
---|
| 456 | my @subblocks;
|
---|
| 457 | while ($maskbits++ < $webvar{maskbits}) {
|
---|
| 458 | @subblocks = $cidr->split($maskbits);
|
---|
| 459 | }
|
---|
| 460 | $cidr = $subblocks[0];
|
---|
| 461 | }
|
---|
[21] | 462 | } # check for freeblocks assignment or IPDB-controlled assignment
|
---|
[4] | 463 |
|
---|
[674] | 464 | # Generate the IP list for the new allocation in case someone wants to set per-IP rDNS right away.
|
---|
| 465 | # We don't do this on the previous page because we don't know how big a block or even what IP range
|
---|
| 466 | # it's for (if following the "normal" allocation process)
|
---|
| 467 | if ($IPDBacl{$authuser} =~ /c/
|
---|
| 468 | && $cidr->masklen != $cidr->bits
|
---|
| 469 | && ($cidr->bits - $cidr->masklen) <= $IPDB::maxrevlist
|
---|
| 470 | && $webvar{alloctype} !~ /^.[dpi]/
|
---|
| 471 | # do we want to allow v6 at all?
|
---|
| 472 | #&& ! $cidr->{isv6}
|
---|
| 473 | ) {
|
---|
| 474 | my @list;
|
---|
| 475 | foreach my $ip (@{$cidr->splitref()}) {
|
---|
| 476 | my %row;
|
---|
| 477 | $row{r_ip} = $ip->addr;
|
---|
| 478 | $row{iphost} = '';
|
---|
| 479 | push @list, \%row;
|
---|
| 480 | }
|
---|
| 481 | $page->param(r_iplist => \@list);
|
---|
| 482 | # We don't use this here, because these IPs should already be bare.
|
---|
| 483 | # ... or should we be paranoid? Make it a config option?
|
---|
| 484 | #getRDNSbyIP($ip_dbh, type => $webvar{alloctype}, range => "$cidr", user => $authuser) );
|
---|
| 485 | }
|
---|
[157] | 486 | } # if ($webvar{alloctype} =~ /^.i$/)
|
---|
[4] | 487 |
|
---|
[397] | 488 | ## node hack
|
---|
| 489 | if ($webvar{node} && $webvar{node} ne '-') {
|
---|
[530] | 490 | my $nodename = getNodeName($ip_dbh, $webvar{node});
|
---|
[517] | 491 | $page->param(nodename => $nodename);
|
---|
| 492 | $page->param(nodeid => $webvar{node});
|
---|
[397] | 493 | }
|
---|
| 494 | ## end node hack
|
---|
| 495 |
|
---|
[4] | 496 | # Stick in the allocation data
|
---|
[517] | 497 | $page->param(alloc_type => $webvar{alloctype});
|
---|
| 498 | $page->param(typefull => $q->escapeHTML($disp_alloctypes{$webvar{alloctype}}));
|
---|
| 499 | $page->param(alloc_from => $alloc_from);
|
---|
[633] | 500 | $page->param(parent => $p_id);
|
---|
| 501 | $page->param(fbid => $fbid);
|
---|
[517] | 502 | $page->param(cidr => $cidr);
|
---|
[585] | 503 | $page->param(rdns => $webvar{rdns});
|
---|
[517] | 504 | $page->param(city => $q->escapeHTML($webvar{city}));
|
---|
| 505 | $page->param(custid => $webvar{custid});
|
---|
| 506 | $page->param(circid => $q->escapeHTML($webvar{circid}));
|
---|
| 507 | $page->param(desc => $q->escapeHTML($webvar{desc}));
|
---|
[4] | 508 |
|
---|
[517] | 509 | ##fixme: find a way to have the displayed copy have <br> substitutions
|
---|
| 510 | # for newlines, and the <input> value have either encoded or bare newlines.
|
---|
| 511 | # Also applies to privdata.
|
---|
| 512 | $page->param(notes => $q->escapeHTML($webvar{notes},'y'));
|
---|
| 513 |
|
---|
[284] | 514 | # Check to see if user is allowed to do anything with sensitive data
|
---|
| 515 | my $privdata = '';
|
---|
[517] | 516 | $page->param(privdata => $q->escapeHTML($webvar{privdata},'y'))
|
---|
| 517 | if $IPDBacl{$authuser} =~ /s/;
|
---|
| 518 |
|
---|
| 519 | # Yay! This now has it's very own little home.
|
---|
| 520 | $page->param(billinguser => $webvar{userid})
|
---|
[299] | 521 | if $webvar{userid};
|
---|
[284] | 522 |
|
---|
[517] | 523 | ##fixme: this is only needed iff confirm.tmpl and
|
---|
| 524 | # confirmRemove.tmpl are merged (quite possible, just
|
---|
| 525 | # a little tedious)
|
---|
| 526 | $page->param(action => "insert");
|
---|
[284] | 527 |
|
---|
[4] | 528 | } # end confirmAssign
|
---|
| 529 |
|
---|
| 530 |
|
---|
| 531 | # Do the work of actually inserting a block in the database.
|
---|
| 532 | sub insertAssign {
|
---|
[233] | 533 | if ($IPDBacl{$authuser} !~ /a/) {
|
---|
[517] | 534 | $aclerr = 'addblock';
|
---|
[233] | 535 | return;
|
---|
| 536 | }
|
---|
[4] | 537 | # Some things are done more than once.
|
---|
[111] | 538 | return if !validateInput();
|
---|
[4] | 539 |
|
---|
[284] | 540 | if (!defined($webvar{privdata})) {
|
---|
| 541 | $webvar{privdata} = '';
|
---|
| 542 | }
|
---|
[575] | 543 |
|
---|
| 544 | # split up some linked data for static IPs via guided allocation. needed for breadcrumbs lite.
|
---|
[584] | 545 | ($webvar{alloc_from},$webvar{rdepth}) = split /,/, $webvar{alloc_from} if $webvar{alloc_from} =~ /,/;
|
---|
[575] | 546 |
|
---|
[106] | 547 | # $code is "success" vs "failure", $msg contains OK for a
|
---|
| 548 | # successful netblock allocation, the IP allocated for static
|
---|
| 549 | # IP, or the error message if an error occurred.
|
---|
[517] | 550 |
|
---|
[633] | 551 | my ($code,$msg) = allocateBlock($ip_dbh, cidr => $webvar{fullcidr}, fbid => $webvar{fbid},
|
---|
| 552 | parent => $webvar{parent}, custid => $webvar{custid}, type => $webvar{alloctype}, city => $webvar{city},
|
---|
[575] | 553 | desc => $webvar{desc}, notes => $webvar{notes}, circid => $webvar{circid},
|
---|
[585] | 554 | privdata => $webvar{privdata}, nodeid => $webvar{node}, rdns => $webvar{rdns}, user => $authuser);
|
---|
[4] | 555 |
|
---|
[111] | 556 | if ($code eq 'OK') {
|
---|
[106] | 557 | if ($webvar{alloctype} =~ /^.i$/) {
|
---|
[300] | 558 | $msg =~ s|/32||;
|
---|
[517] | 559 | $page->param(staticip => $msg);
|
---|
| 560 | $page->param(custid => $webvar{custid});
|
---|
[633] | 561 | $page->param(parent => $webvar{parent}, pool => $webvar{alloc_from});
|
---|
[517] | 562 | $page->param(billinguser => $webvar{billinguser});
|
---|
[416] | 563 | mailNotify($ip_dbh, "a$webvar{alloctype}", "ADDED: $disp_alloctypes{$webvar{alloctype}} allocation",
|
---|
| 564 | "$disp_alloctypes{$webvar{alloctype}} $msg allocated to customer $webvar{custid}\n".
|
---|
| 565 | "Description: $webvar{desc}\n\nAllocated by: $authuser\n");
|
---|
[106] | 566 | } else {
|
---|
[301] | 567 | my $netblock = new NetAddr::IP $webvar{fullcidr};
|
---|
[517] | 568 | $page->param(fullcidr => $webvar{fullcidr});
|
---|
| 569 | $page->param(alloctype => $disp_alloctypes{$webvar{alloctype}});
|
---|
| 570 | $page->param(custid => $webvar{custid});
|
---|
[575] | 571 | # breadcrumbs lite! provide at least a link to the parent of the block we just allocated.
|
---|
[633] | 572 | my $binfo = getBlockData($ip_dbh, $webvar{parent});
|
---|
| 573 | $page->param(parentid => $webvar{parent});
|
---|
| 574 | $page->param(parentblock => $binfo->{block});
|
---|
[517] | 575 | if ($webvar{alloctype} eq 'pr' && $webvar{billinguser}) {
|
---|
| 576 | $page->param(billinguser => $webvar{billinguser});
|
---|
| 577 | $page->param(custid => $webvar{custid});
|
---|
| 578 | $page->param(netaddr => $netblock->addr);
|
---|
| 579 | $page->param(masklen => $netblock->masklen);
|
---|
| 580 | }
|
---|
[416] | 581 | mailNotify($ip_dbh, "a$webvar{alloctype}", "ADDED: $disp_alloctypes{$webvar{alloctype}} allocation",
|
---|
| 582 | "$disp_alloctypes{$webvar{alloctype}} $webvar{fullcidr} allocated to customer $webvar{custid}\n".
|
---|
| 583 | "Description: $webvar{desc}\n\nAllocated by: $authuser\n");
|
---|
[4] | 584 | }
|
---|
[106] | 585 | syslog "notice", "$authuser allocated '$webvar{fullcidr}' to '$webvar{custid}' as ".
|
---|
[256] | 586 | "'$webvar{alloctype}' ($msg)";
|
---|
[111] | 587 | } else {
|
---|
| 588 | syslog "err", "Allocation of '$webvar{fullcidr}' to '$webvar{custid}' as ".
|
---|
| 589 | "'$webvar{alloctype}' by $authuser failed: '$msg'";
|
---|
[517] | 590 | $page->param(err => "Allocation of $webvar{fullcidr} as '$disp_alloctypes{$webvar{alloctype}}'".
|
---|
[157] | 591 | " failed:<br>\n$msg\n");
|
---|
[106] | 592 | }
|
---|
[4] | 593 |
|
---|
| 594 | } # end insertAssign()
|
---|
| 595 |
|
---|
| 596 |
|
---|
| 597 | # Does some basic checks on common input data to make sure nothing
|
---|
| 598 | # *really* weird gets in to the database through this script.
|
---|
| 599 | # Does NOT do complete input validation!!!
|
---|
| 600 | sub validateInput {
|
---|
| 601 | if ($webvar{city} eq '-') {
|
---|
[517] | 602 | $page->param(err => 'Please choose a city');
|
---|
[111] | 603 | return;
|
---|
[4] | 604 | }
|
---|
[138] | 605 |
|
---|
| 606 | # Alloctype check.
|
---|
[4] | 607 | chomp $webvar{alloctype};
|
---|
[138] | 608 | if (!grep /$webvar{alloctype}/, keys %disp_alloctypes) {
|
---|
| 609 | # Danger! Danger! alloctype should ALWAYS be set by a dropdown. Anyone
|
---|
| 610 | # managing to call things in such a way as to cause this deserves a cryptic error.
|
---|
[517] | 611 | $page->param(err => 'Invalid alloctype');
|
---|
[138] | 612 | return;
|
---|
| 613 | }
|
---|
| 614 |
|
---|
| 615 | # CustID check
|
---|
[4] | 616 | # We have different handling for customer allocations and "internal" or "our" allocations
|
---|
[214] | 617 | if ($def_custids{$webvar{alloctype}} eq '') {
|
---|
[4] | 618 | if (!$webvar{custid}) {
|
---|
[517] | 619 | $page->param(err => 'Please enter a customer ID.');
|
---|
[111] | 620 | return;
|
---|
[4] | 621 | }
|
---|
[546] | 622 | # Crosscheck with billing.
|
---|
| 623 | my $status = CustIDCK->custid_exist($webvar{custid});
|
---|
| 624 | if ($CustIDCK::Error) {
|
---|
| 625 | $page->param(err => "Error verifying customer ID: ".$CustIDCK::ErrMsg);
|
---|
| 626 | return;
|
---|
[4] | 627 | }
|
---|
[546] | 628 | if (!$status) {
|
---|
| 629 | $page->param(err => "Customer ID not valid. Make sure the Customer ID ".
|
---|
| 630 | "is correct.<br>\nUse STAFF for staff static IPs, and $IPDB::defcustid for any other ".
|
---|
| 631 | "non-customer assignments.");
|
---|
| 632 | return;
|
---|
| 633 | }
|
---|
[400] | 634 | # print "<!-- [ In validateInput(). Insert customer ID cross-check here. ] -->\n";
|
---|
[138] | 635 | } else {
|
---|
[167] | 636 | # New! Improved! And now Loaded From The Database!!
|
---|
[320] | 637 | if ((!$webvar{custid}) || ($webvar{custid} ne 'STAFF')) {
|
---|
| 638 | $webvar{custid} = $def_custids{$webvar{alloctype}};
|
---|
| 639 | }
|
---|
[4] | 640 | }
|
---|
[111] | 641 |
|
---|
[571] | 642 | ## hmmm.... is this even useful?
|
---|
| 643 | if (0) {
|
---|
[111] | 644 | # Check POP location
|
---|
| 645 | my $flag;
|
---|
[187] | 646 | if ($webvar{alloctype} eq 'rm') {
|
---|
[111] | 647 | $flag = 'for a routed netblock';
|
---|
| 648 | foreach (@poplist) {
|
---|
| 649 | if (/^$webvar{city}$/) {
|
---|
| 650 | $flag = 'n';
|
---|
| 651 | last;
|
---|
| 652 | }
|
---|
| 653 | }
|
---|
| 654 | } else {
|
---|
| 655 | $flag = 'n';
|
---|
[442] | 656 | ##fixme: hook to force-set POP or city on certain alloctypes
|
---|
| 657 | # if ($webvar{alloctype =~ /foo,bar,bz/ { $webvar{pop} = 'blah'; }
|
---|
[536] | 658 | if ($webvar{pop} && $webvar{pop} =~ /^-$/) {
|
---|
[111] | 659 | $flag = 'to route the block from/through';
|
---|
| 660 | }
|
---|
| 661 | }
|
---|
[517] | 662 |
|
---|
| 663 | # if the alloctype has a restricted city/POP list as determined above,
|
---|
| 664 | # and the reqested city/POP does not match that list, complain
|
---|
[111] | 665 | if ($flag ne 'n') {
|
---|
[517] | 666 | $page->param(err => "Please choose a valid POP location $flag. Valid ".
|
---|
[111] | 667 | "POP locations are currently:<br>\n".join (" - ", @poplist));
|
---|
| 668 | return;
|
---|
| 669 | }
|
---|
[571] | 670 | }
|
---|
[111] | 671 |
|
---|
| 672 | return 'OK';
|
---|
[4] | 673 | } # end validateInput
|
---|
| 674 |
|
---|
| 675 |
|
---|
| 676 | # Displays details of a specific allocation in a form
|
---|
| 677 | # Allows update/delete
|
---|
| 678 | # action=edit
|
---|
| 679 | sub edit {
|
---|
| 680 |
|
---|
[534] | 681 | # snag block info from db
|
---|
[634] | 682 | my $blockinfo = getBlockData($ip_dbh, $webvar{id}, $webvar{basetype});
|
---|
| 683 | $page->param(id => $webvar{id});
|
---|
| 684 | $page->param(basetype => $webvar{basetype});
|
---|
[4] | 685 |
|
---|
[534] | 686 | # Clean up extra whitespace on alloc type. Mainly a legacy-data cleanup.
|
---|
| 687 | $blockinfo->{type} =~ s/\s//;
|
---|
[4] | 688 |
|
---|
[586] | 689 | # Get rDNS info; duplicates a bit of getBlockData but also does the RPC call if possible
|
---|
[634] | 690 | $blockinfo->{rdns} = getBlockRDNS($ip_dbh, id => $webvar{id}, type => $blockinfo->{type}, user => $authuser);
|
---|
[586] | 691 |
|
---|
[634] | 692 | $page->param(block => $blockinfo->{block});
|
---|
[586] | 693 | $page->param(rdns => $blockinfo->{rdns});
|
---|
[4] | 694 |
|
---|
[534] | 695 | $page->param(custid => $blockinfo->{custid});
|
---|
| 696 | $page->param(city => $blockinfo->{city});
|
---|
| 697 | $page->param(circid => $blockinfo->{circuitid});
|
---|
| 698 | $page->param(desc => $blockinfo->{description});
|
---|
| 699 | $page->param(notes => $blockinfo->{notes});
|
---|
[4] | 700 |
|
---|
[187] | 701 | ##fixme The check here should be built from the database
|
---|
[517] | 702 | # Need to expand to support pool types too
|
---|
[534] | 703 | if ($blockinfo->{type} =~ /^.[ne]$/ && $IPDBacl{$authuser} =~ /c/) {
|
---|
[517] | 704 | $page->param(changetype => 1);
|
---|
| 705 | $page->param(alloctype => [
|
---|
[534] | 706 | { selme => ($blockinfo->{type} eq 'me'), type => "me", disptype => "Dialup netblock" },
|
---|
| 707 | { selme => ($blockinfo->{type} eq 'de'), type => "de", disptype => "Dynamic DSL netblock" },
|
---|
| 708 | { selme => ($blockinfo->{type} eq 'ce'), type => "ce", disptype => "Dynamic cable netblock" },
|
---|
| 709 | { selme => ($blockinfo->{type} eq 'we'), type => "we", disptype => "Dynamic wireless netblock" },
|
---|
| 710 | { selme => ($blockinfo->{type} eq 'cn'), type => "cn", disptype => "Customer netblock" },
|
---|
| 711 | { selme => ($blockinfo->{type} eq 'en'), type => "en", disptype => "End-use netblock" },
|
---|
| 712 | { selme => ($blockinfo->{type} eq 'in'), type => "in", disptype => "Internal netblock" },
|
---|
[517] | 713 | ]
|
---|
| 714 | );
|
---|
| 715 | } else {
|
---|
[534] | 716 | $page->param(disptype => $disp_alloctypes{$blockinfo->{type}});
|
---|
| 717 | $page->param(type => $blockinfo->{type});
|
---|
[517] | 718 | }
|
---|
| 719 |
|
---|
[397] | 720 | ## node hack
|
---|
[634] | 721 | my ($nodeid,$nodename) = getNodeInfo($ip_dbh, $blockinfo->{block});
|
---|
| 722 | # $page->param(havenodeid => $nodeid);
|
---|
| 723 | $page->param(nodename => $nodename);
|
---|
[517] | 724 |
|
---|
| 725 | ##fixme: this whole hack needs cleanup and generalization for all alloctypes
|
---|
| 726 | ##fixme: arguably a bug that presence of a nodeid implies it can be changed..
|
---|
[634] | 727 | if ($IPDBacl{$authuser} =~ /c/) {
|
---|
| 728 | my $nlist = getNodeList($ip_dbh);
|
---|
| 729 | if ($nodeid) {
|
---|
[530] | 730 | foreach (@{$nlist}) {
|
---|
[634] | 731 | $$_{selme} = ($$_{node_id} == $nodeid);
|
---|
[397] | 732 | }
|
---|
| 733 | }
|
---|
[634] | 734 | $page->param(nodelist => $nlist);
|
---|
[397] | 735 | }
|
---|
| 736 | ## end node hack
|
---|
[517] | 737 |
|
---|
[534] | 738 | my ($lastmod,undef) = split /\s+/, $blockinfo->{lastmod};
|
---|
[517] | 739 | $page->param(lastmod => $lastmod);
|
---|
[33] | 740 |
|
---|
[517] | 741 | # not happy with the upside-down logic, but...
|
---|
[534] | 742 | $page->param(swipable => $blockinfo->{type} !~ /.i/);
|
---|
| 743 | $page->param(swip => $blockinfo->{swip} ne 'n') if $blockinfo->{swip};
|
---|
[320] | 744 |
|
---|
[284] | 745 | # Check to see if we can display sensitive data
|
---|
[517] | 746 | $page->param(nocling => $IPDBacl{$authuser} =~ /s/);
|
---|
[534] | 747 | $page->param(privdata => $blockinfo->{privdata});
|
---|
[284] | 748 |
|
---|
[517] | 749 | # ACL trickery - these two template booleans control the presence of all form/input tags
|
---|
| 750 | $page->param(maychange => $IPDBacl{$authuser} =~ /c/);
|
---|
| 751 | $page->param(maydel => $IPDBacl{$authuser} =~ /d/);
|
---|
[4] | 752 |
|
---|
| 753 | } # edit()
|
---|
| 754 |
|
---|
| 755 |
|
---|
| 756 | # Stuff new info about a block into the db
|
---|
| 757 | # action=update
|
---|
| 758 | sub update {
|
---|
[284] | 759 | if ($IPDBacl{$authuser} !~ /c/) {
|
---|
[517] | 760 | $aclerr = 'updateblock';
|
---|
[284] | 761 | return;
|
---|
| 762 | }
|
---|
[4] | 763 |
|
---|
| 764 | # Make sure incoming data is in correct format - custID among other things.
|
---|
[228] | 765 | return if !validateInput;
|
---|
[4] | 766 |
|
---|
[536] | 767 | $webvar{swip} = 'n' if !$webvar{swip};
|
---|
| 768 |
|
---|
[531] | 769 | my %updargs = (
|
---|
| 770 | custid => $webvar{custid},
|
---|
| 771 | city => $webvar{city},
|
---|
| 772 | description => $webvar{desc},
|
---|
| 773 | notes => $webvar{notes},
|
---|
| 774 | circuitid => $webvar{circid},
|
---|
| 775 | block => $webvar{block},
|
---|
| 776 | type => $webvar{alloctype},
|
---|
[536] | 777 | swip => $webvar{swip},
|
---|
[588] | 778 | rdns => $webvar{rdns},
|
---|
| 779 | user => $authuser,
|
---|
[531] | 780 | );
|
---|
| 781 |
|
---|
| 782 | # Semioptional values
|
---|
| 783 | $updargs{privdata} = $webvar{privdata} if $IPDBacl{$authuser} =~ /s/;
|
---|
| 784 | $updargs{node} = $webvar{node} if $webvar{node};
|
---|
| 785 |
|
---|
| 786 | my ($code,$msg) = updateBlock($ip_dbh, %updargs);
|
---|
| 787 |
|
---|
| 788 | if ($code eq 'FAIL') {
|
---|
[166] | 789 | syslog "err", "$authuser could not update block/IP '$webvar{block}': '$msg'";
|
---|
[517] | 790 | $page->param(err => "Could not update block/IP $webvar{block}: $msg");
|
---|
[111] | 791 | return;
|
---|
[4] | 792 | }
|
---|
| 793 |
|
---|
| 794 | # If we get here, the operation succeeded.
|
---|
| 795 | syslog "notice", "$authuser updated $webvar{block}";
|
---|
[531] | 796 | ##fixme: log details of the change? old way is in the .debug stream anyway.
|
---|
[416] | 797 | ##fixme: need to wedge something in to allow "update:field" notifications
|
---|
| 798 | ## hmm. how to tell what changed? O_o
|
---|
[426] | 799 | mailNotify($ip_dbh, 's:swi', "SWIPed: $disp_alloctypes{$webvar{alloctype}} $webvar{block}",
|
---|
[416] | 800 | "$webvar{block} had SWIP status changed to \"Yes\" by $authuser") if $webvar{swip} eq 'on';
|
---|
[4] | 801 |
|
---|
[517] | 802 | ## node hack
|
---|
| 803 | if ($webvar{node} && $webvar{node} ne '-') {
|
---|
[530] | 804 | my $nodename = getNodeName($ip_dbh, $webvar{node});
|
---|
[517] | 805 | $page->param(nodename => $nodename);
|
---|
| 806 | }
|
---|
| 807 | ## end node hack
|
---|
| 808 |
|
---|
[380] | 809 | # Link back to browse-routed or list-pool page on "Update complete" page.
|
---|
[634] | 810 | my $binfo = getBlockData($ip_dbh, $webvar{block}, $webvar{basetype});
|
---|
| 811 | my $pblock = getBlockData($ip_dbh, $binfo->{parent_id});
|
---|
| 812 | $page->param(backid => $binfo->{parent_id});
|
---|
| 813 | $page->param(backblock => $pblock->{block});
|
---|
| 814 | $page->param(backpool => ($webvar{basetype} eq 'i'));
|
---|
[380] | 815 |
|
---|
[536] | 816 | # Do some HTML fiddling here instead of using ESCAPE=HTML in the template,
|
---|
| 817 | # because otherwise we can't convert \n to <br>. *sigh*
|
---|
| 818 | $webvar{notes} = $q->escapeHTML($webvar{notes}); # escape first...
|
---|
| 819 | $webvar{notes} =~ s/\n/<br>\n/; # ... then convert newlines
|
---|
| 820 | $webvar{privdata} = ($webvar{privdata} ? $q->escapeHTML($webvar{privdata}) : " ");
|
---|
| 821 | $webvar{privdata} =~ s/\n/<br>\n/;
|
---|
| 822 |
|
---|
[634] | 823 | $page->param(cidr => $binfo->{block});
|
---|
[588] | 824 | $page->param(rdns => $webvar{rdns});
|
---|
[517] | 825 | $page->param(city => $webvar{city});
|
---|
| 826 | $page->param(disptype => $disp_alloctypes{$webvar{alloctype}});
|
---|
| 827 | $page->param(custid => $webvar{custid});
|
---|
| 828 | $page->param(swip => $webvar{swip} eq 'on' ? 'Yes' : 'No');
|
---|
[536] | 829 | $page->param(circid => $webvar{circid});
|
---|
| 830 | $page->param(desc => $webvar{desc});
|
---|
| 831 | $page->param(notes => $webvar{notes});
|
---|
[517] | 832 | $page->param(privdata => $webvar{privdata})
|
---|
| 833 | if $IPDBacl{$authuser} =~ /s/;
|
---|
[4] | 834 |
|
---|
| 835 | } # update()
|
---|
| 836 |
|
---|
| 837 |
|
---|
| 838 | # Delete an allocation.
|
---|
[106] | 839 | sub remove {
|
---|
[233] | 840 | if ($IPDBacl{$authuser} !~ /d/) {
|
---|
[517] | 841 | $aclerr = 'delblock';
|
---|
[233] | 842 | return;
|
---|
| 843 | }
|
---|
| 844 |
|
---|
[4] | 845 | # Serves'em right for getting here...
|
---|
| 846 | if (!defined($webvar{block})) {
|
---|
[517] | 847 | $page->param(err => "Can't delete a block that doesn't exist");
|
---|
[111] | 848 | return;
|
---|
[4] | 849 | }
|
---|
| 850 |
|
---|
[538] | 851 | my $blockdata;
|
---|
[638] | 852 | $blockdata = getBlockData($ip_dbh, $webvar{block}, $webvar{basetype});
|
---|
[4] | 853 |
|
---|
[638] | 854 | if ($blockdata->{parent_id} == 0) { # $webvar{alloctype} eq 'mm'
|
---|
[538] | 855 | $blockdata->{city} = "N/A";
|
---|
| 856 | $blockdata->{custid} = "N/A";
|
---|
| 857 | $blockdata->{circuitid} = "N/A";
|
---|
| 858 | $blockdata->{description} = "N/A";
|
---|
| 859 | $blockdata->{notes} = "N/A";
|
---|
| 860 | $blockdata->{privdata} = "N/A";
|
---|
[638] | 861 | } # end cases for different alloctypes
|
---|
[517] | 862 |
|
---|
[638] | 863 | $page->param(blockid => $webvar{block});
|
---|
| 864 | $page->param(basetype => $webvar{basetype});
|
---|
[4] | 865 |
|
---|
[538] | 866 | $page->param(block => $blockdata->{block});
|
---|
[589] | 867 | $page->param(rdns => $blockdata->{rdns});
|
---|
| 868 |
|
---|
| 869 | # maybe need to apply more magic here?
|
---|
| 870 | # most allocations we *do* want to autodelete the forward as well as reverse; for a handful we don't.
|
---|
| 871 | # -> all real blocks (nb: pool IPs need extra handling)
|
---|
| 872 | # -> NOC/private-IP (how to ID?)
|
---|
| 873 | # -> anything with a pattern matching $IPDB::domain?
|
---|
| 874 | if ($blockdata->{type} !~ /^.i$/) {
|
---|
| 875 | $page->param(autodel => 1);
|
---|
| 876 | }
|
---|
| 877 |
|
---|
[538] | 878 | $page->param(disptype => $disp_alloctypes{$blockdata->{type}});
|
---|
| 879 | $page->param(city => $blockdata->{city});
|
---|
| 880 | $page->param(custid => $blockdata->{custid});
|
---|
| 881 | $page->param(circid => $blockdata->{circuitid});
|
---|
| 882 | $page->param(desc => $blockdata->{description});
|
---|
| 883 | $blockdata->{notes} = $q->escapeHTML($blockdata->{notes});
|
---|
| 884 | $blockdata->{notes} =~ s/\n/<br>\n/;
|
---|
| 885 | $page->param(notes => $blockdata->{notes});
|
---|
| 886 | $blockdata->{privdata} = $q->escapeHTML($blockdata->{privdata});
|
---|
[540] | 887 | $blockdata->{privdata} = ' ' if !$blockdata->{privdata};
|
---|
[538] | 888 | $blockdata->{privdata} =~ s/\n/<br>\n/;
|
---|
| 889 | $page->param(privdata => $blockdata->{privdata}) if $IPDBacl{$authuser} =~ /s/;
|
---|
| 890 | $page->param(delpool => $blockdata->{type} =~ /^.[pd]$/);
|
---|
[4] | 891 |
|
---|
[517] | 892 | } # end remove()
|
---|
[4] | 893 |
|
---|
| 894 |
|
---|
| 895 | # Delete an allocation. Return it to the freeblocks table; munge
|
---|
| 896 | # data as necessary to keep as few records as possible in freeblocks
|
---|
| 897 | # to prevent weirdness when allocating blocks later.
|
---|
| 898 | # Remove IPs from pool listing if necessary
|
---|
| 899 | sub finalDelete {
|
---|
[233] | 900 | if ($IPDBacl{$authuser} !~ /d/) {
|
---|
[517] | 901 | $aclerr = 'delblock';
|
---|
[233] | 902 | return;
|
---|
| 903 | }
|
---|
[4] | 904 |
|
---|
[370] | 905 | # need to retrieve block data before deleting so we can notify on that
|
---|
[638] | 906 | my $blockinfo = getBlockData($ip_dbh, $webvar{block}, $webvar{basetype});
|
---|
| 907 | my $pinfo = getBlockData($ip_dbh, $blockinfo->{parent_id}, 'b');
|
---|
[370] | 908 |
|
---|
[638] | 909 | my ($code,$msg) = deleteBlock($ip_dbh, $webvar{block}, $webvar{basetype}, $webvar{delforward}, $authuser);
|
---|
[4] | 910 |
|
---|
[638] | 911 | $page->param(block => $blockinfo->{block});
|
---|
[651] | 912 | $page->param(bdisp => $q->escapeHTML($disp_alloctypes{$blockinfo->{type}}));
|
---|
[638] | 913 | $page->param(delparent_id => $blockinfo->{parent_id});# if $webvar{rdepth};
|
---|
[651] | 914 | if ($pinfo) {
|
---|
| 915 | $page->param(delparent => $pinfo->{block});
|
---|
| 916 | $page->param(pdisp => $q->escapeHTML($disp_alloctypes{$pinfo->{type}}));
|
---|
| 917 | }
|
---|
[638] | 918 | $page->param(returnpool => ($webvar{basetype} eq 'i') );
|
---|
[591] | 919 | if ($code =~ /^WARN(POOL|MERGE)/) {
|
---|
[638] | 920 | my ($pid,$pcidr) = split /,/, $msg;
|
---|
[654] | 921 | my $real_pinfo = getBlockData($ip_dbh, $pid, 'b');
|
---|
[638] | 922 | $page->param(parent_id => $pid);
|
---|
| 923 | $page->param(parent => $pcidr);
|
---|
[654] | 924 | $page->param(real_disp => $q->escapeHTML($disp_alloctypes{$real_pinfo->{type}}));
|
---|
[577] | 925 | $page->param(mergeip => $code eq 'WARNPOOL');
|
---|
| 926 | }
|
---|
[591] | 927 | if ($code eq 'WARN') {
|
---|
| 928 | $msg =~ s/\n/<br>\n/g;
|
---|
| 929 | $page->param(genwarn => $msg);
|
---|
| 930 | }
|
---|
[577] | 931 | if ($code eq 'OK' || $code =~ /^WARN/) {
|
---|
[638] | 932 | syslog "notice", "$authuser deallocated '".$blockinfo->{type}."'-type netblock $webvar{block} ".
|
---|
[528] | 933 | $blockinfo->{custid}.", ".$blockinfo->{city}.", desc='".$blockinfo->{description}."'";
|
---|
[638] | 934 | mailNotify($ip_dbh, 'da', "REMOVED: ".$disp_alloctypes{$blockinfo->{type}}." $webvar{block}",
|
---|
| 935 | $disp_alloctypes{$blockinfo->{type}}." $webvar{block} deallocated by $authuser\n".
|
---|
[528] | 936 | "CustID: ".$blockinfo->{custid}."\nCity: ".$blockinfo->{city}.
|
---|
| 937 | "\nDescription: ".$blockinfo->{description}."\n");
|
---|
[106] | 938 | } else {
|
---|
[517] | 939 | $page->param(failmsg => $msg);
|
---|
[106] | 940 | if ($webvar{alloctype} =~ /^.i$/) {
|
---|
| 941 | syslog "err", "$authuser could not deallocate static IP '$webvar{block}': '$msg'";
|
---|
| 942 | } else {
|
---|
| 943 | syslog "err", "$authuser could not deallocate netblock '$webvar{block}': '$msg'";
|
---|
[517] | 944 | $page->param(netblock => 1);
|
---|
[4] | 945 | }
|
---|
[106] | 946 | }
|
---|
[4] | 947 |
|
---|
| 948 | } # finalDelete
|
---|