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

Last change on this file since 544 was 544, checked in by Kris Deugau, 12 years ago

/trunk

Extend findAllocateFrom() to allow passing a target block to allocate
to restrict the freeblock selection
Remove local SQL for confirmation page for "assign this block" in
admin.cgi in favour of existing data and subs. See #34.
For admin.cgi "assign this block", if the requested IP type does not
match the pool, the type will be adjusted and a warning pushed out.
Add space on "assign this block" template for a warning.

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