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

Last change on this file since 898 was 893, checked in by Kris Deugau, 8 years ago

/trunk

Finally review and refresh copyright years again

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