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

Last change on this file since 932 was 929, checked in by Kris Deugau, 2 years ago

/trunk

Trim errant whitespace from "gimme" CIDR in admin.cgi.
Update copyright dates

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