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

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

/trunk

Trim dangling database op that should have gone away in r541. See #34.

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