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

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

/trunk

Bulk addition of "add 'the directory the script is in' to @INC" for Perls
that have dropped '.' from @INC

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