source: trunk/cgi-bin/admin.cgi@ 921

Last change on this file since 921 was 915, checked in by Kris Deugau, 7 years ago

/trunk

Start adding a generalized in-your-face infonotice space to attach warnings
to a netblock. See #17 and #23, sort of.

  • table to hold the notices, since they're likely to be far fewer than the overall allocation count
  • show any notices for the parent chain for new allocations in the admin tools
  • Property svn:executable set to *
  • Property svn:keywords set to Date Rev Author
File size: 20.8 KB
Line 
1#!/usr/bin/perl
2# ipdb/cgi-bin/admin.cgi
3# Hack interface to make specific changes to IPDB that (for one reason
4# or another) can't be made through the main interface.
5#
6###
7# SVN revision info
8# $Date: 2018-04-27 19:28:45 +0000 (Fri, 27 Apr 2018) $
9# SVN revision $Rev: 915 $
10# Last update by $Author: kdeugau $
11###
12# Copyright (C) 2004-2016 - Kris Deugau
13
14use strict;
15use warnings;
16use CGI::Carp qw(fatalsToBrowser);
17use CGI::Simple;
18use HTML::Template;
19use DBI;
20#use POSIX qw(ceil);
21use NetAddr::IP;
22
23use Sys::Syslog;
24
25# don't remove! required for GNU/FHS-ish install from tarball
26##uselib##
27
28# push "the directory the script is in" into @INC
29use FindBin;
30use lib "$FindBin::RealBin/";
31
32use CustIDCK;
33use MyIPDB;
34
35openlog "IPDB-admin","pid","$IPDB::syslog_facility";
36
37# Collect the username from HTTP auth. If undefined, we're in a test environment.
38my $authuser;
39if (!defined($ENV{'REMOTE_USER'})) {
40 $authuser = '__temptest';
41} else {
42 $authuser = $ENV{'REMOTE_USER'};
43}
44
45syslog "debug", "$authuser active";
46
47# Set up the CGI object...
48my $q = new CGI::Simple;
49# ... and get query-string params as well as POST params if necessary
50$q->parse_query_string;
51
52# Convenience; saves changing all references to %webvar
53##fixme: tweak for handling <select multiple='y' size=3> (list with multiple selection)
54my %webvar = $q->Vars;
55
56# anyone got a better name? :P
57my $thingroot = $ENV{SCRIPT_FILENAME};
58$thingroot =~ s|cgi-bin/admin.cgi||;
59
60# Set up some globals
61$ENV{HTML_TEMPLATE_ROOT} = $thingroot;
62my @templatepath = [ "localtemplates", "templates" ];
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
66my $ip_dbh;
67my $sth;
68my $errstr;
69($ip_dbh,$errstr) = connectDB_My;
70if (!$ip_dbh) {
71 $webvar{action} = "dberr";
72} else {
73 initIPDBGlobals($ip_dbh);
74}
75
76if(!defined($webvar{action})) {
77 $webvar{action} = "main"; #shuts up the warnings.
78}
79
80# handle DB error output
81if ($webvar{action} eq 'dberr') {
82 my $page = HTML::Template->new(filename => "admin/dberr.tmpl", path => @templatepath);
83 $page->param(errmsg => $errstr);
84 print "Content-Type: text/html\n\n".$page->output;
85 exit;
86}
87
88if ($IPDBacl{$authuser} !~ /A/) {
89 my $page = HTML::Template->new(filename => "admin/aclerr.tmpl", path => @templatepath);
90##fixme: need params for IPDB admin email and name
91 $page->param(ipdbadmin_email => 'ipdbadmin@example.com');
92 $page->param(ipdbadmin_name => 'the IPDB administrator');
93 print "Content-Type: text/html\n\n".$page->output;
94 exit;
95}
96
97my $header = HTML::Template->new(filename => "admin/header.tmpl", path => @templatepath);
98$header->param(mainpage => 1) if $webvar{action} eq 'main';
99$header->param(webpath => $IPDB::webpath);
100print "Content-type: text/html\n\n".$header->output;
101
102my $page;
103if (-e "$ENV{HTML_TEMPLATE_ROOT}/templates/admin/$webvar{action}.tmpl") {
104 $page = HTML::Template->new(filename => "admin/$webvar{action}.tmpl", path => @templatepath);
105} else {
106 $page = HTML::Template->new(filename => "admin/dunno.tmpl", path => @templatepath);
107}
108
109# handle index page
110if ($webvar{action} eq 'main') {
111 my $tlist = getTypeList($ip_dbh, 'a');
112 $tlist->[0]->{sel} = 1;
113 $page->param(typelist => $tlist);
114
115 my $mlist = getMasterList($ip_dbh, 'm');
116 $page->param(masterlist => $mlist);
117}
118
119## Non-default actions.
120
121elsif ($webvar{action} eq 'alloc') {
122
123 my $cidr = new NetAddr::IP $webvar{cidr};
124 if (!$cidr || "$cidr" =~ /^0/) {
125 $page->param(errmsg => "Can't allocate something that's not a netblock/ip");
126 goto ERRJUMP;
127 }
128
129 my $custid = $def_custids{$webvar{alloctype}};
130 if ($custid eq '') {
131 # Crosscheck with billing.
132 my $status = CustIDCK->custid_exist($webvar{custid});
133 if ($CustIDCK::Error) {
134 $page->param(errmsg => "Error verifying customer ID: ".$CustIDCK::ErrMsg);
135 goto ERRJUMP;
136 }
137 if (!$status) {
138 $page->param(errmsg => "Customer ID not valid. Make sure the Customer ID ".
139 "is correct.<br>\nUse STAFF for staff static IPs, and $IPDB::defcustid for any other ".
140 "non-customer assignments.");
141 goto ERRJUMP;
142 }
143 # Type that doesn't have a default custid
144 $custid = $webvar{custid};
145 }
146
147 my $maskbits = $cidr->masklen;
148 my ($fbid, $fb, $fbparent);
149 ($fbid, $fb, $fbparent) = findAllocateFrom($ip_dbh, $maskbits, $webvar{alloctype}, '','',
150 (gimme => "$cidr", allowpriv => 1));
151
152 # retrieve any notices
153 my $nlist = getBlockNotices($ip_dbh, $fbparent);
154 my @notices;
155 foreach (@$nlist) {
156 push @notices, $_->{notice} if $_->{notice};
157 }
158 my $blockmsg = join("<br>\n", @notices);
159 $page->param(blockmsg => $blockmsg);
160
161 $page->param(fbid => $fbid);
162 $page->param(parid => $fbparent);
163 my ($rdns,$rcached) = getBlockRDNS($ip_dbh, id => $fbparent, type => ($webvar{alloctype} =~ /^.i$/ ? 'i' : 'b'),
164 user => $authuser);
165 $page->param(rdns => $rdns);
166 if ($webvar{alloctype} =~ /^(.)i$/) {
167 my $iptype = $1;
168 my $ptmp = getBlockData($ip_dbh, $fbparent);
169 if ($ptmp->{type} =~ /^(.)[dp]$/) {
170 my $newiptype = "$1i";
171 if ($ptmp->{type} !~ /^$iptype./) {
172 $page->param(warnmsg => "Warning: Allocating IP as '".$disp_alloctypes{$newiptype}."' instead of '".
173 $disp_alloctypes{$webvar{alloctype}}."' to match pool ".$ptmp->{block}."\n");
174 $webvar{alloctype} = $newiptype;
175 }
176 }
177 if (!$fbid) {
178 $page->param(errmsg => "Can't allocate static IP from outside a pool!!");
179 goto ERRJUMP;
180 }
181 } else {
182 if (!$fbid) {
183 $page->param(errmsg => "Can't allocate from outside a free block!!");
184 goto ERRJUMP;
185 }
186 }
187
188 my $alloc_from = new NetAddr::IP $fb;
189
190 my @cities;
191 foreach my $city (@citylist) {
192 my %row = (city => $city);
193 push @cities, \%row;
194 }
195 $page->param(
196 cidr => $cidr,
197 disptype => $disp_alloctypes{$webvar{alloctype}},
198 type => $webvar{alloctype},
199 alloc_from => $alloc_from,
200 custid => $custid,
201 citylist => \@cities
202 );
203
204} elsif ($webvar{action} eq 'confirm') {
205
206 $page->param(
207 cidr => $webvar{cidr},
208 custid => $webvar{custid},
209 desc => $webvar{desc},
210 disptype => $disp_alloctypes{$webvar{alloctype}}
211 );
212 # Only need to check city here.
213 if ($webvar{city} eq '-') {
214 $page->param(locerr => "Invalid customer location! Go back and select customer's location.");
215 goto ERRJUMP;
216 }
217
218 # retrieve any notices
219 my $nlist = getBlockNotices($ip_dbh, $webvar{parent});
220 my @notices;
221 foreach (@$nlist) {
222 push @notices, $_->{notice} if $_->{notice};
223 }
224 my $blockmsg = join("<br>\n", @notices);
225 $page->param(blockmsg => $blockmsg);
226
227 my ($retcode,$msg) = allocateBlock($ip_dbh, cidr => $webvar{cidr}, fbid => $webvar{fbid},
228 parent => $webvar{parent}, custid => $webvar{custid}, type => $webvar{alloctype}, city => $webvar{city},
229 desc => $webvar{desc}, notes => $webvar{notes}, circid => $webvar{circid},
230 privdata => $webvar{privdata}, nodeid => $webvar{node}, rdns => $webvar{rdns}, user => $authuser);
231
232 if ($retcode eq 'OK') {
233 syslog "notice", "$authuser allocated '$webvar{cidr}' to '$webvar{custid}' as ".
234 "'$webvar{alloctype}'";
235 if ($webvar{alloctype} =~ /^.i$/) {
236 mailNotify($ip_dbh, "a$webvar{alloctype}", "ADDED: $disp_alloctypes{$webvar{alloctype}} allocation",
237 "$disp_alloctypes{$webvar{alloctype}} $webvar{cidr} allocated to customer $webvar{custid}\n".
238 "Description: $webvar{desc}\n".
239 ($webvar{rdns} ? "DNS name: $webvar{rdns}\n" : '').
240 "\nAllocated by: $authuser\n");
241 }
242 } else {
243 $page->param(errmsg => $msg);
244 syslog "err", "($authuser) Allocation of '$webvar{cidr}' to '$webvar{custid}' as ".
245 "'$webvar{alloctype}' failed: '$msg'";
246 }
247
248} elsif ($webvar{action} eq 'alloctweak') {
249
250 fix_allocfrom();
251 showAllocs($webvar{allocfrom});
252
253} elsif ($webvar{action} eq 'update') {
254
255 update();
256
257} elsif ($webvar{action} eq 'touch') {
258
259 my ($code,$msg) = touchMaster($ip_dbh, $webvar{whichmaster});
260 $page->param(errmsg => $msg) if $code eq 'FAIL';
261
262} elsif ($webvar{action} eq 'listcust') {
263
264 my $clist = $ip_dbh->selectall_arrayref("SELECT custid,name AS custname,tech_handle AS tech ".
265 "FROM customers ORDER BY custid", { Slice => {} } );
266 $page->param(custlist => $clist);
267
268} elsif ($webvar{action} eq 'edcust') {
269
270 if ($webvar{newcust}) {
271 $sth = $ip_dbh->prepare("INSERT INTO customers (custid) VALUES (?)");
272 $sth->execute($webvar{custid});
273 }
274 $sth = $ip_dbh->prepare("select custid,name,street,city,province,".
275 "country,pocode,phone,tech_handle,abuse_handle,admin_handle,special ".
276 "from customers where custid='$webvar{custid}'");
277 $sth->execute;
278 my ($custid, $name, $street, $city, $prov, $country, $pocode, $phone, $tech, $abuse, $admin, $special) =
279 $sth->fetchrow_array;
280
281 $page->param(
282 custid => $custid,
283 name => $name,
284 street => $street,
285 city => $city,
286 prov => $prov,
287 country => $country,
288 pocode => $pocode,
289 phone => $phone,
290 tech => $tech,
291 abuse => $abuse,
292 admin => $admin,
293 special => $special
294 );
295
296} elsif ($webvar{action} eq 'updcust') {
297
298 if ($webvar{abutton} eq 'Update') {
299 $ip_dbh->do(q(
300 UPDATE customers
301 SET name = ?, street = ?, city = ?, province=?, country=?, pocode=?,
302 phone = ?, tech_handle = ?, abuse_handle = ?, admin_handle = ?, special = ?
303 WHERE custid = ?
304 ), undef,
305 ($webvar{name}, $webvar{street}, $webvar{city}, $webvar{province}, $webvar{country}, $webvar{pocode},
306 $webvar{phone}, $webvar{tech_handle}, $webvar{abuse_handle}, $webvar{admin_handle}, $webvar{special},
307 $webvar{custid})
308 );
309 $page->param(whatact => "Updated");
310 } elsif ($webvar{abutton} eq 'Delete (immediate)') {
311 $ip_dbh->do("DELETE FROM customers WHERE custid = ?", undef, $webvar{custid});
312 $page->param(whatact => "Deleted");
313 } else {
314 # Your llama is on fire
315 }
316 # Show what we've just either updated or deleted.
317 # Deleted, so that in case of "OOOPS!!", the "special" data can be recovered.
318 $page->param(
319 custid => $webvar{custid},
320 name => $webvar{name},
321 street => $webvar{street},
322 city => $webvar{city},
323 prov => $webvar{province},
324 country => $webvar{country},
325 pocode => $webvar{pocode},
326 phone => $webvar{phone},
327 tech => $webvar{tech_handle},
328 abuse => $webvar{abuse_handle},
329 admin => $webvar{admin_handle},
330 special => $webvar{special}
331 );
332
333} elsif ($webvar{action} eq 'showpools') {
334
335 my $plist = $ip_dbh->selectall_arrayref("SELECT a.id,a.cidr AS pool, count(*) AS free FROM poolips p ".
336 "JOIN allocations a ON a.id=p.parent_id ".
337 "WHERE available='y' GROUP BY a.cidr,a.id ORDER BY a.cidr", { Slice => {} });
338 $page->param(poollist => $plist);
339
340} elsif ($webvar{action} eq 'tweakpool') {
341
342 showPool($webvar{pool});
343
344} elsif ($webvar{action} eq 'updatepool') {
345
346 my $ip = $ip_dbh->selectrow_array("SELECT ip FROM poolips WHERE id=?", undef, ($webvar{id}) );
347 $page->param(ip => $ip);
348 $sth = $ip_dbh->prepare("UPDATE poolips SET custid=?, city=?, type=?, available='".
349 (($webvar{available} eq 'y') ? 'y' : 'n').
350 "', notes=?, description=? ".
351 "WHERE id=?");
352 $sth->execute($webvar{custid}, $webvar{city}, $webvar{type}, $webvar{notes}, $webvar{desc}, $webvar{id});
353 if ($sth->err) {
354 $page->param(errmsg => $sth->errstr);
355 syslog "err", "$authuser could not update pool IP $ip: ".$sth->errstr;
356 } else {
357 syslog "notice", "$authuser updated pool IP $ip";
358 }
359 my $poolid = $ip_dbh->selectrow_array("SELECT parent_id FROM poolips WHERE id=?", undef, ($webvar{id}) );
360 $page->param(poolid => $poolid);
361 my $pool = $ip_dbh->selectrow_array("SELECT cidr FROM allocations WHERE id=?", undef, ($poolid) );
362 $page->param(pool => $pool);
363
364} elsif ($webvar{action} eq 'showusers') {
365
366 $sth = $ip_dbh->prepare("select username,acl from users order by username");
367 $sth->execute;
368 my @userlist;
369 while (my ($username,$acl) = $sth->fetchrow_array) {
370##fixme: funky things happening with HTML::Template here; shouldn't need the "logic ? iftrue : iffalse" structure
371 my %row = (
372 username => $username,
373 can_add => ($acl =~ /a/ ? 1 : 0),
374 can_change => ($acl =~ /c/ ? 1 : 0),
375 can_del => ($acl =~ /d/ ? 1 : 0),
376 sysnet => ($acl =~ /s/ ? 1 : 0),
377 can_merge => ($acl =~ /m/ ? 1 : 0),
378 is_admin => ($acl =~ /A/ ? 1 : 0),
379 acl => $acl
380 );
381 push @userlist, \%row;
382 }
383 $page->param(userlist => \@userlist);
384
385} elsif ($webvar{action} eq 'updacl') {
386
387 $page->param(username => $webvar{username});
388 my $acl = 'b';
389 if ($webvar{admin} eq 'on') {
390 # as per request "admin" users do not automatically get merge permission. Networkz iz hard.
391 # Admin users that add the priviledge and then shoot everybody in all the feet probably
392 # shouldn't have had admin access in the first place.
393 $acl .= "acdsA";
394 $acl .= 'm' if $webvar{merge} eq 'on';
395 } else {
396 $acl .= ($webvar{add} eq 'on' ? 'a' : '').
397 ($webvar{change} eq 'on' ? 'c' : '').
398 ($webvar{del} eq 'on' ? 'd' : '').
399 ($webvar{sysnet} eq 'on' ? 's' : '').
400 ($webvar{merge} eq 'on' ? 'm' : '');
401 }
402 $page->param(acl => $acl);
403
404 $sth = $ip_dbh->prepare("update users set acl='$acl' where username='$webvar{username}'");
405 $sth->execute;
406 $page->param(errmsg => $sth->errstr) if $sth->err;
407
408} elsif ($webvar{action} eq 'newuser') {
409
410 $page->param(username => $webvar{username});
411 my $cr_pass = ($webvar{preenc} ? $webvar{password} :
412 crypt $webvar{password}, join('',('.','/',0..9,'A'..'Z','a'..'z')[rand 64, rand 64]));
413 $sth = $ip_dbh->prepare("insert into users (username,password,acl) values ".
414 "('$webvar{username}','$cr_pass','b')");
415 $sth->execute;
416 $page->param(errmsg => $sth->errstr) if $sth->err;
417
418} elsif ($webvar{action} eq 'deluser') {
419
420 $page->param(username => $webvar{username});
421 $sth = $ip_dbh->prepare("delete from users where username='$webvar{username}'");
422 $sth->execute;
423 $page->param(errmsg => $sth->errstr) if $sth->err;
424
425} elsif ($webvar{action} eq 'emailnotice') {
426
427 $sth = $ip_dbh->prepare("SELECT action,reciplist FROM notify");
428 $sth->execute;
429 my @spamlist;
430 while (my ($notice_code,$reciplist) = $sth->fetchrow_array() ) {
431##fixme: hairy mess, only a few things call mailNotify() anyway, so many possible notices won't work.
432 my $action_out = dispNoticeCode($notice_code);
433 my %row = (
434 action => $action_out,
435 code => $notice_code,
436 recips => $reciplist
437 );
438 push @spamlist, \%row;
439 }
440 $page->param(spamlist => \@spamlist);
441
442 $sth = $ip_dbh->prepare("SELECT type,dispname FROM alloctypes WHERE listorder < 500 ".
443 "ORDER BY listorder");
444 $sth->execute;
445 my $i=0;
446 my @typelist;
447 while (my ($type,$disp) = $sth->fetchrow_array) {
448 my %row = (
449 type => $type,
450 disptype => $disp,
451# ahh, off-by-one counts, how we do love thee... NOT!
452 newrow => ($i+2 > $sth->rows ? 1 : (++$i % 4)),
453 );
454 push @typelist, \%row;
455 }
456 $page->param(typelist => \@typelist);
457
458} elsif ($webvar{action} eq 'addnotice') {
459
460 $webvar{alloctype} = $webvar{special} if $webvar{msgaction} eq 's:';
461 if ($webvar{msgaction} && $webvar{alloctype} && $webvar{reciplist}) {
462 $page->param(cantry => 1);
463 $webvar{reciplist} =~ s/[\r\n]+/,/g;
464 $webvar{msgaction} = "f:$webvar{msgaction}" if $webvar{onfail};
465 $page->param(reciplist => $webvar{reciplist});
466 $page->param(dispnotice => dispNoticeCode($webvar{msgaction}.$webvar{alloctype}));
467 $sth = $ip_dbh->prepare("INSERT INTO notify (action, reciplist) VALUES (?,?)");
468##fixme: automagically merge reciplists iff action already exists
469 $sth->execute($webvar{msgaction}.$webvar{alloctype}, $webvar{reciplist});
470 $page->param(addfailed => $sth->errstr) if $sth->err;
471 }
472
473} elsif ($webvar{action} eq 'delnotice') {
474
475 $page->param(dispnotice => dispNoticeCode($webvar{code}.$webvar{alloctype}));
476 $sth = $ip_dbh->prepare("DELETE FROM notify WHERE action=?");
477 $sth->execute($webvar{code});
478 $page->param(delfailed => $sth->errstr) if $sth->err;
479
480} elsif ($webvar{action} eq 'ednotice') {
481
482 $page->param(dispnotice => dispNoticeCode($webvar{code}));
483 $page->param(code => $webvar{code});
484 $sth = $ip_dbh->prepare("SELECT reciplist FROM notify WHERE action=?");
485 $sth->execute($webvar{code});
486 my ($reciplist) = $sth->fetchrow_array;
487 $reciplist =~ s/,/\n/g;
488 $page->param(reciplist => $reciplist);
489
490} elsif ($webvar{action} eq 'updnotice') {
491
492 $page->param(dispnotice => dispNoticeCode($webvar{code}));
493 $sth = $ip_dbh->prepare("UPDATE notify SET reciplist=? WHERE action=?");
494 $webvar{reciplist} =~ s/[\r\n]+/,/g;
495 $sth->execute($webvar{reciplist}, $webvar{code});
496 $page->param(updfailed => $sth->errstr) if $sth->err;
497
498} elsif ($webvar{action} ne '<NULL>') {
499 $page->param(dunno => $webvar{action});
500}
501
502ERRJUMP:
503print $page->output;
504
505##fixme: make me a footer param!
506print qq(<hr><div><a href="$IPDB::webpath/">Back</a> to the main IPDB</div>\n);
507
508# We print the footer here, so we don't have to do it elsewhere.
509my $footer = HTML::Template->new(filename => "footer.tmpl", path => @templatepath);
510# we're already in the admin tools, no need to provide a bottom link. maybe.
511#$footer->param(adminlink => ($IPDBacl{$authuser} =~ /A/));
512
513print $footer->output;
514
515$sth->finish if $sth;
516$ip_dbh->disconnect;
517
518exit;
519
520
521# Hokay. This is a little different. We have a few specific functions here:
522# -> Assign arbitrary subnet from arbitrary free space
523# -> Tweak individual DB fields
524#
525
526
527# Tweak allocfrom into shape.
528sub fix_allocfrom {
529 if ($webvar{allocfrom} =~ /^(\d+\.){2}\d+$/) {
530 # 3-octet class C specified
531 $webvar{allocfrom} .= ".0/24";
532 } elsif ($webvar{allocfrom} =~ /^(\d+\.){3}\d+$/) {
533 # 4-octet IP specified;
534 $webvar{allocfrom} .= "/24";
535 }
536}
537
538
539# Show allocations to allow editing.
540sub showAllocs {
541
542 my $within = new NetAddr::IP $_[0];
543 $page->param(within => $within);
544
545
546 $sth = $ip_dbh->prepare("SELECT id,vrf,cidr,custid,type,city,description FROM allocations".
547 " WHERE cidr <<= ? ORDER BY vrf,cidr");
548 $sth->execute($within);
549 my @blocklist;
550 while (my ($id,$vrf,$cidr,$custid,$type,$city,$desc) = $sth->fetchrow_array) {
551 my %row = (
552 id => $id,
553 cidr => $cidr,
554 custid => $custid,
555 city => $city,
556 desc => $desc,
557 );
558
559##fixme: don't wanna retrieve the whole type list *every time around the outer loop*
560 my $sth2 = $ip_dbh->prepare("SELECT type,listname FROM alloctypes".
561 " WHERE listorder < 999 AND NOT (type LIKE '_i') ORDER BY listorder");
562 $sth2->execute;
563 my @typelist;
564 while (my ($listtype,$dispname) = $sth2->fetchrow_array) {
565 my %subrow = (
566 type => $listtype,
567 dispname => $dispname,
568 selected => ($listtype eq $type)
569 );
570 push @typelist, \%subrow;
571 }
572 $row{typelist} = \@typelist;
573 push @blocklist, \%row;
574 }
575 $page->param(blocklist => \@blocklist);
576} # end showAllocs()
577
578
579# Stuff updates into DB
580sub update {
581 my $cidr = $ip_dbh->selectrow_array("SELECT cidr FROM allocations WHERE id=?", undef, ($webvar{block}) );
582
583 # Relatively simple SQL transaction here. Note that we're deliberately NOT
584 # updating notes/desc here as it's available through the main interface.
585 $ip_dbh->do("UPDATE allocations SET custid=?, city=?, type=? WHERE id=?", undef,
586 ($webvar{custid}, $webvar{city}, $webvar{alloctype}, $webvar{block}) );
587
588 $page->param(block => $cidr);
589 if ($ip_dbh->err) {
590 $page->param(updfailed => $ip_dbh->errstr);
591 syslog "err", "$authuser could not update block '$cidr': '".$ip_dbh->errstr."'";
592 } else {
593 syslog "notice", "$authuser updated $cidr";
594 }
595 # need to get /24 that block is part of
596 my @bits = split /\./, $cidr;
597 $bits[3] = "0/24";
598 showAllocs((join ".", @bits));
599} # end update()
600
601
602# showPool()
603# List all IPs in a pool, and allow arbitrary admin changes to each
604# Allow changes to ALL fields
605sub showPool {
606 my $pool = shift;
607
608 # arguably even presenting a list here is Wrong, because Pool IPs Should Alwasy Match The Pool Type, but...
609 # could also set "selected" on the "correct" type
610 my $tlist = getTypeList($ip_dbh, 'i');
611 $page->param(typelist => $tlist);
612
613 $sth = $ip_dbh->prepare("SELECT id,ip,custid,city,type,available,description,notes from poolips".
614 " WHERE parent_id=? ORDER BY ip");
615 $sth->execute($pool);
616 my @iplist;
617 while (my ($id,$ip,$custid,$city,$type,$avail,$desc,$notes) = $sth->fetchrow_array) {
618 my %row = (
619 id => $id,
620 ip => $ip,
621 custid => $custid,
622 city => $city,
623 type => $type,
624 avail => $avail,
625 desc => $desc,
626 notes => $notes
627 );
628 push @iplist, \%row;
629 }
630 $page->param(iplist => \@iplist);
631} # end showPool()
632
633
634# interpret the notify codes
635sub dispNoticeCode {
636 my $code = shift;
637 my $action_out = '';
638
639 if ($code =~ /^s:/) {
640 $code =~ s/^s:/Special: /;
641 return $code;
642 }
643 if ($code =~ /^f:(.+)$/) {
644 $code =~ s/^f://;
645 $action_out = "Failure on ";
646 }
647 if (my $target = $code =~ /^n(.+)/) {
648 $action_out .= "New ";
649 if ($1 eq 'ci') { $action_out .= "city"; }
650 elsif ($1 eq 'no') { $action_out .= "node"; }
651 else { $action_out .= '&lt;unknown&gt;'; }
652 } else {
653 my ($action,$target) = ($code =~ /^(.)(.+)$/);
654 if ($action eq 'a') { $action_out .= 'Add '; }
655 elsif ($action eq 'u') { $action_out .= 'Update '; }
656 elsif ($action eq 'd') { $action_out .= 'Delete '; }
657##fixme: what if we get something funky?
658# What about the eleventy-billion odd combinations possible?
659# this should give an idea of the structure tho
660 if ($target eq 'a') { $action_out .= "all"; }
661 elsif ($target eq '.i') {
662 $action_out .= "all static IPs";
663 }
664 else { $action_out .= $disp_alloctypes{$target}; }
665 }
666 return $action_out;
667}
Note: See TracBrowser for help on using the repository browser.