source: branches/htmlform/cgi-bin/admin.cgi@ 488

Last change on this file since 488 was 488, checked in by Kris Deugau, 14 years ago

/branches/htmlform

Removed a few stray obsolete subs and blocks. admin.cgi pretty much done conversion
to HTML::Template. Validation failures are limited to the user ACL table and
block-tweaking table, both of which require complete forms which only span a single
row of the table. See #3

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