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

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

/branches/htmlform

Remove use of printError() in admin.cgi. See #15, #26

  • 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 22:45:58 +0000 (Thu, 23 Sep 2010) $
9# SVN revision $Rev: 489 $
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.
126
127elsif ($webvar{action} eq 'alloc') {
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 $page->param(errmsg => "Error verifying customer ID: ".$CustIDCK::ErrMsg);
145 goto ERRJUMP;
146 }
147 if (!$status) {
148 $page->param(errmsg => "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 goto ERRJUMP;
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 $page->param(locerr => "Invalid customer location! Go back and select customer's location.");
211 goto ERRJUMP;
212 } else {
213 if ($webvar{alloctype} =~ /^.i$/) {
214 $sth = $ip_dbh->prepare("update poolips set available='n', custid='$webvar{custid}', ".
215 "city='$webvar{city}', description='$webvar{desc}', notes='$webvar{notes}' ".
216 "where ip='$webvar{cidr}'");
217 $sth->execute;
218 if ($sth->err) {
219 $page->param(errmsg => $sth->errstr);
220 syslog "err", "($authuser) Allocation of '$webvar{cidr}' to '$webvar{custid}' as ".
221 "'$webvar{alloctype}' failed: '".$sth->errstr."'";
222 } else {
223 syslog "notice", "$authuser allocated '$webvar{cidr}' to '$webvar{custid}' as ".
224 "'$webvar{alloctype}'";
225 mailNotify($ip_dbh, "a$webvar{alloctype}", "ADDED: $disp_alloctypes{$webvar{alloctype}} allocation",
226 "$disp_alloctypes{$webvar{alloctype}} $webvar{cidr} allocated to customer $webvar{custid}\n".
227 "Description: $webvar{desc}\n\nAllocated by: $authuser\n");
228 }
229 } else {
230 my ($retcode,$msg) = allocateBlock($ip_dbh, $webvar{cidr}, $webvar{alloc_from},
231 $webvar{custid}, $webvar{alloctype}, $webvar{city}, $webvar{desc}, $webvar{notes},
232 $webvar{circid});
233 if ($retcode eq 'OK') {
234 syslog "notice", "$authuser allocated '$webvar{cidr}' to '$webvar{custid}' as ".
235 "'$webvar{alloctype}'";
236 } else {
237 $page->param(errmsg => $msg);
238 syslog "err", "($authuser) Allocation of '$webvar{cidr}' to '$webvar{custid}' as ".
239 "'$webvar{alloctype}' failed: '$msg'";
240 }
241 } # static IP vs netblock
242
243 } # done city check
244
245} elsif ($webvar{action} eq 'alloctweak') {
246
247 fix_allocfrom();
248 showAllocs($webvar{allocfrom});
249
250} elsif ($webvar{action} eq 'update') {
251
252 update();
253
254} elsif ($webvar{action} eq 'touch') {
255
256 $page->param(master => $webvar{whichmaster});
257 $sth = $ip_dbh->prepare("update masterblocks set mtime=now() where cidr='$webvar{whichmaster}'");
258 $sth->execute;
259 if ($sth->err) {
260 $page->param(errmsg => $sth->errstr);
261 }
262
263} elsif ($webvar{action} eq 'listcust') {
264
265 $sth = $ip_dbh->prepare("select custid,name,tech_handle from customers order by custid");
266 $sth->execute;
267 my @custlist;
268 while (my @data = $sth->fetchrow_array) {
269 my %row = (
270 custid => $data[0],
271 custname => $data[1],
272 tech => $data[2]
273 );
274 push @custlist, \%row;
275 }
276 $page->param(custlist => \@custlist);
277
278} elsif ($webvar{action} eq 'edcust') {
279
280 if ($webvar{newcust}) {
281 $sth = $ip_dbh->prepare("INSERT INTO customers (custid) VALUES (?)");
282 $sth->execute($webvar{custid});
283 }
284 $sth = $ip_dbh->prepare("select custid,name,street,city,province,".
285 "country,pocode,phone,tech_handle,abuse_handle,admin_handle,special ".
286 "from customers where custid='$webvar{custid}'");
287 $sth->execute;
288 my ($custid, $name, $street, $city, $prov, $country, $pocode, $phone, $tech, $abuse, $admin, $special) =
289 $sth->fetchrow_array;
290
291 $page->param(
292 custid => $custid,
293 name => $name,
294 street => $street,
295 city => $city,
296 prov => $prov,
297 country => $country,
298 pocode => $pocode,
299 phone => $phone,
300 tech => $tech,
301 abuse => $abuse,
302 admin => $admin,
303 special => $special
304 );
305
306} elsif ($webvar{action} eq 'updcust') {
307
308 $sth = $ip_dbh->prepare("UPDATE customers SET".
309 " name=?, street=?, city=?, province=?, country=?, pocode=?,".
310 " phone=?, tech_handle=?, abuse_handle=?, admin_handle=?, special=?".
311 " WHERE custid=?");
312 $sth->execute($webvar{name}, $webvar{street}, $webvar{city}, $webvar{province},
313 $webvar{country}, $webvar{pocode}, $webvar{phone}, $webvar{tech_handle},
314 $webvar{abuse_handle}, $webvar{admin_handle}, $webvar{special}, $webvar{custid});
315 $page->param(
316 custid => $webvar{custid},
317 name => $webvar{name},
318 street => $webvar{street},
319 city => $webvar{city},
320 prov => $webvar{province},
321 country => $webvar{country},
322 pocode => $webvar{pocode},
323 phone => $webvar{phone},
324 tech => $webvar{tech_handle},
325 abuse => $webvar{abuse_handle},
326 admin => $webvar{admin_handle},
327 special => $webvar{special}
328 );
329
330} elsif ($webvar{action} eq 'showpools') {
331
332 $sth = $ip_dbh->prepare("select pool, count(*) from poolips where available='y' group by pool order by pool");
333 $sth->execute;
334 my @poollist;
335 while (my ($pool,$free) = $sth->fetchrow_array) {
336 my %row = (
337 pool => $pool,
338 free => $free
339 );
340 push @poollist, \%row;
341 }
342 $page->param(poollist => \@poollist);
343
344} elsif ($webvar{action} eq 'tweakpool') {
345
346 showPool($webvar{pool});
347
348} elsif ($webvar{action} eq 'updatepool') {
349
350 $sth = $ip_dbh->prepare("update poolips set custid='$webvar{custid}', ".
351 "city=?, type='$webvar{type}', available='".
352 (($webvar{available} eq 'y') ? 'y' : 'n').
353 "', notes=?, description=? ".
354 "where ip='$webvar{ip}'");
355 $sth->execute($webvar{city},$webvar{notes},$webvar{desc});
356 $page->param(ip => $webvar{ip});
357 if ($sth->err) {
358 $page->param(errmsg => $sth->errstr);
359 syslog "err", "$authuser could not update pool IP $webvar{ip}: ".$sth->errstr;
360 } else {
361 syslog "notice", "$authuser updated pool IP $webvar{ip}";
362 }
363 $sth = $ip_dbh->prepare("select pool from poolips where ip='$webvar{ip}'");
364 $sth->execute;
365 my @data = $sth->fetchrow_array;
366 $page->param(pool => $data[0]);
367
368} elsif ($webvar{action} eq 'showusers') {
369
370 $sth = $ip_dbh->prepare("select username,acl from users order by username");
371 $sth->execute;
372 my @userlist;
373 while (my ($username,$acl) = $sth->fetchrow_array) {
374##fixme: funky things happening with HTML::Template here; shouldn't need the "logic ? iftrue : iffalse" structure
375 my %row = (
376 username => $username,
377 can_add => ($acl =~ /a/ ? 1 : 0),
378 can_change => ($acl =~ /c/ ? 1 : 0),
379 can_del => ($acl =~ /d/ ? 1 : 0),
380 sysnet => ($acl =~ /s/ ? 1 : 0),
381 is_admin => ($acl =~ /A/ ? 1 : 0),
382 acl => $acl
383 );
384 push @userlist, \%row;
385 }
386 $page->param(userlist => \@userlist);
387
388} elsif ($webvar{action} eq 'updacl') {
389
390 $page->param(username => $webvar{username});
391 my $acl = 'b';
392 if ($webvar{admin} eq 'on') {
393 $acl .= "acdsA";
394 } else {
395 $acl .= ($webvar{add} eq 'on' ? 'a' : '').
396 ($webvar{change} eq 'on' ? 'c' : '').
397 ($webvar{del} eq 'on' ? 'd' : '').
398 ($webvar{sysnet} eq 'on' ? 's' : '');
399 }
400 $page->param(acl => $acl);
401
402 $sth = $ip_dbh->prepare("update users set acl='$acl' where username='$webvar{username}'");
403 $sth->execute;
404 $page->param(errmsg => $sth->errstr) if $sth->err;
405
406} elsif ($webvar{action} eq 'newuser') {
407
408 $page->param(username => $webvar{username});
409 my $cr_pass = ($webvar{preenc} ? $webvar{password} :
410 crypt $webvar{password}, join('',('.','/',0..9,'A'..'Z','a'..'z')[rand 64, rand 64]));
411 $sth = $ip_dbh->prepare("insert into users (username,password,acl) values ".
412 "('$webvar{username}','$cr_pass','b')");
413 $sth->execute;
414 $page->param(errmsg => $sth->errstr) if $sth->err;
415
416} elsif ($webvar{action} eq 'deluser') {
417
418 $page->param(username => $webvar{username});
419 $sth = $ip_dbh->prepare("delete from users where username='$webvar{username}'");
420 $sth->execute;
421 $page->param(errmsg => $sth->errstr) if $sth->err;
422
423} elsif ($webvar{action} eq 'emailnotice') {
424
425 $sth = $ip_dbh->prepare("SELECT action,reciplist FROM notify");
426 $sth->execute;
427 my @spamlist;
428 while (my ($notice_code,$reciplist) = $sth->fetchrow_array() ) {
429##fixme: hairy mess, only a few things call mailNotify() anyway, so many possible notices won't work.
430 my $action_out = dispNoticeCode($notice_code);
431 my %row = (
432 action => $action_out,
433 code => $notice_code,
434 recips => $reciplist
435 );
436 push @spamlist, \%row;
437 }
438 $page->param(spamlist => \@spamlist);
439
440 $sth = $ip_dbh->prepare("SELECT type,dispname FROM alloctypes WHERE listorder < 500 ".
441 "ORDER BY listorder");
442 $sth->execute;
443 my $i=0;
444 my @typelist;
445 while (my ($type,$disp) = $sth->fetchrow_array) {
446 my %row = (
447 type => $type,
448 disptype => $disp,
449# ahh, off-by-one counts, how we do love thee... NOT!
450 newrow => ($i+2 > $sth->rows ? 1 : (++$i % 4)),
451 );
452 push @typelist, \%row;
453 }
454 $page->param(typelist => \@typelist);
455
456} elsif ($webvar{action} eq 'addnotice') {
457
458 $webvar{alloctype} = $webvar{special} if $webvar{msgaction} eq 's:';
459 if ($webvar{msgaction} && $webvar{alloctype} && $webvar{reciplist}) {
460 $page->param(cantry => 1);
461 $webvar{reciplist} =~ s/[\r\n]+/,/g;
462 $webvar{msgaction} = "f:$webvar{msgaction}" if $webvar{onfail};
463 $page->param(reciplist => $webvar{reciplist});
464 $page->param(dispnotice => dispNoticeCode($webvar{msgaction}.$webvar{alloctype}));
465 $sth = $ip_dbh->prepare("INSERT INTO notify (action, reciplist) VALUES (?,?)");
466##fixme: automagically merge reciplists iff action already exists
467 $sth->execute($webvar{msgaction}.$webvar{alloctype}, $webvar{reciplist});
468 $page->param(addfailed => $sth->errstr) if $sth->err;
469 }
470
471} elsif ($webvar{action} eq 'delnotice') {
472
473 $page->param(dispnotice => dispNoticeCode($webvar{code}.$webvar{alloctype}));
474 $sth = $ip_dbh->prepare("DELETE FROM notify WHERE action=?");
475 $sth->execute($webvar{code});
476 $page->param(delfailed => $sth->errstr) if $sth->err;
477
478} elsif ($webvar{action} eq 'ednotice') {
479
480 $page->param(dispnotice => dispNoticeCode($webvar{code}));
481 $page->param(code => $webvar{code});
482 $sth = $ip_dbh->prepare("SELECT reciplist FROM notify WHERE action=?");
483 $sth->execute($webvar{code});
484 my ($reciplist) = $sth->fetchrow_array;
485 $reciplist =~ s/,/\n/g;
486 $page->param(reciplist => $reciplist);
487
488} elsif ($webvar{action} eq 'updnotice') {
489
490 $page->param(dispnotice => dispNoticeCode($webvar{code}));
491 $sth = $ip_dbh->prepare("UPDATE notify SET reciplist=? WHERE action=?");
492 $webvar{reciplist} =~ s/[\r\n]+/,/g;
493 $sth->execute($webvar{reciplist}, $webvar{code});
494 $page->param(updfailed => $sth->errstr) if $sth->err;
495
496} elsif ($webvar{action} ne '<NULL>') {
497 $page->param(dunno => $webvar{action});
498}
499
500ERRJUMP: print "Content-type: text/html\n\n".$header->output;
501print $page->output;
502
503##fixme: make me a footer param!
504print qq(<hr><div><a href="/ip/">Back</a> to main interface</div>\n);
505
506# We print the footer here, so we don't have to do it elsewhere.
507my $footer = HTML::Template->new(filename => "footer.tmpl");
508# we're already in the admin tools, no need to provide a bottom link. maybe.
509#$footer->param(adminlink => ($IPDBacl{$authuser} =~ /A/));
510
511print $footer->output;
512
513$ip_dbh->disconnect;
514
515exit;
516
517
518# Hokay. This is a little different. We have a few specific functions here:
519# -> Assign arbitrary subnet from arbitrary free space
520# -> Tweak individual DB fields
521#
522
523
524# Tweak allocfrom into shape.
525sub fix_allocfrom {
526 if ($webvar{allocfrom} =~ /^(\d+\.){2}\d+$/) {
527 # 3-octet class C specified
528 $webvar{allocfrom} .= ".0/24";
529 } elsif ($webvar{allocfrom} =~ /^(\d+\.){3}\d+$/) {
530 # 4-octet IP specified;
531 $webvar{allocfrom} .= "/24";
532 }
533}
534
535
536# Show allocations to allow editing.
537sub showAllocs {
538
539 my $within = new NetAddr::IP $_[0];
540 $page->param(within => $within);
541
542 $sth = $ip_dbh->prepare("select cidr,custid,type,city,description from allocations where cidr <<= '$within' order by cidr");
543 $sth->execute;
544 my @blocklist;
545 while (my ($cidr,$custid,$type,$city,$desc) = $sth->fetchrow_array) {
546 my %row = (
547 cidr => $cidr,
548 custid => $custid,
549 city => $city,
550 desc => $desc,
551 );
552
553##fixme: don't wanna retrieve the whole type list *every time around the outer loop*
554 my $sth2 = $ip_dbh->prepare("select type,listname from alloctypes".
555 " where listorder < 500 and not (type like '_i') order by listorder");
556 $sth2->execute;
557 my @typelist;
558 while (my ($listtype,$dispname) = $sth2->fetchrow_array) {
559 my %subrow = (
560 type => $listtype,
561 dispname => $dispname,
562 selected => ($listtype eq $type)
563 );
564 push @typelist, \%subrow;
565 }
566 $row{typelist} = \@typelist;
567 push @blocklist, \%row;
568 }
569 $page->param(blocklist => \@blocklist);
570} # end showAllocs()
571
572
573# Stuff updates into DB
574sub update {
575 # Relatively simple SQL transaction here. Note that we're deliberately NOT
576 # updating notes/desc here as it's available through the main interface.
577 $sth = $ip_dbh->prepare("update allocations set custid='$webvar{custid}',".
578 "city=?,type='$webvar{alloctype}' where cidr='$webvar{block}'");
579 $sth->execute($webvar{city});
580
581 $page->param(block => $webvar{block});
582 if ($sth->err) {
583 $page->param(updfailed => $sth->errstr);
584 syslog "err", "$authuser could not update block '$webvar{block}': '".$sth->errstr."'";
585 } else {
586 syslog "notice", "$authuser updated $webvar{block}";
587 }
588 # need to get /24 that block is part of
589 my @bits = split /\./, $webvar{block};
590 $bits[3] = "0/24";
591 showAllocs((join ".", @bits));
592} # end update()
593
594
595# showPool()
596# List all IPs in a pool, and allow arbitrary admin changes to each
597# Allow changes to ALL fields
598sub showPool($) {
599 my $pool = new NetAddr::IP $_[0];
600
601 $sth = $ip_dbh->prepare("select type,listname from alloctypes where type like '_i' order by listorder");
602 $sth->execute;
603 my @typelist;
604 while (my ($type,$dispname) = $sth->fetchrow_array) {
605 my %row = (
606 type => $type,
607 dispname => $dispname
608 );
609 push @typelist, \%row;
610 }
611 $page->param(typelist => \@typelist);
612
613 $sth = $ip_dbh->prepare("select ip,custid,city,type,available,description,notes from poolips where pool='$pool' order by ip");
614 $sth->execute;
615 my @iplist;
616 while (my ($ip,$custid,$city,$type,$avail,$desc,$notes) = $sth->fetchrow_array) {
617 my %row = (
618 ip => $ip,
619 custid => $custid,
620 city => $city,
621 type => $type,
622 avail => $avail,
623 desc => $desc,
624 notes => $notes
625 );
626 push @iplist, \%row;
627 }
628 $page->param(iplist => \@iplist);
629} # end showPool()
630
631
632# interpret the notify codes
633sub dispNoticeCode {
634 my $code = shift;
635 my $action_out = '';
636
637 if ($code =~ /^s:/) {
638 $code =~ s/^s:/Special: /;
639 return $code;
640 }
641 if ($code =~ /^f:(.+)$/) {
642 $code =~ s/^f://;
643 $action_out = "Failure on ";
644 }
645 if (my $target = $code =~ /^n(.+)/) {
646 $action_out .= "New ";
647 if ($1 eq 'ci') { $action_out .= "city"; }
648 elsif ($1 eq 'no') { $action_out .= "node"; }
649 else { $action_out .= '&lt;unknown&gt;'; }
650 } else {
651 my ($action,$target) = ($code =~ /^(.)(.+)$/);
652 if ($action eq 'a') { $action_out .= 'Add '; }
653 elsif ($action eq 'u') { $action_out .= 'Update '; }
654 elsif ($action eq 'd') { $action_out .= 'Delete '; }
655##fixme: what if we get something funky?
656# What about the eleventy-billion odd combinations possible?
657# this should give an idea of the structure tho
658 if ($target eq 'a') { $action_out .= "all"; }
659 elsif ($target eq '.i') {
660 $action_out .= "all static IPs";
661 }
662 else { $action_out .= $disp_alloctypes{$target}; }
663 }
664 return $action_out;
665}
Note: See TracBrowser for help on using the repository browser.