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