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

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

/trunk

Tweak allocateBlock() to usefully handle passing an IP as an
override on the automatic IP-chooser.
Convert allocation of a pool IP in admin.cgi to use updated
allocateBlock(). See #34.

  • Property svn:executable set to *
  • Property svn:keywords set to Date Rev Author
File size: 19.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-07 22:20:58 +0000 (Wed, 07 Nov 2012) $
9# SVN revision $Rev: 545 $
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 }
206
207 my ($retcode,$msg) = allocateBlock($ip_dbh, $webvar{cidr}, $webvar{alloc_from},
208 $webvar{custid}, $webvar{alloctype}, $webvar{city}, $webvar{desc}, $webvar{notes},
209 $webvar{circid});
210 if ($retcode eq 'OK') {
211 syslog "notice", "$authuser allocated '$webvar{cidr}' to '$webvar{custid}' as ".
212 "'$webvar{alloctype}'";
213 if ($webvar{alloctype} =~ /^.i$/) {
214 mailNotify($ip_dbh, "a$webvar{alloctype}", "ADDED: $disp_alloctypes{$webvar{alloctype}} allocation",
215 "$disp_alloctypes{$webvar{alloctype}} $webvar{cidr} allocated to customer $webvar{custid}\n".
216 "Description: $webvar{desc}\n\nAllocated by: $authuser\n");
217 }
218 } else {
219 $page->param(errmsg => $msg);
220 syslog "err", "($authuser) Allocation of '$webvar{cidr}' to '$webvar{custid}' as ".
221 "'$webvar{alloctype}' failed: '$msg'";
222 }
223
224} elsif ($webvar{action} eq 'alloctweak') {
225
226 fix_allocfrom();
227 showAllocs($webvar{allocfrom});
228
229} elsif ($webvar{action} eq 'update') {
230
231 update();
232
233} elsif ($webvar{action} eq 'touch') {
234
235 $page->param(master => $webvar{whichmaster});
236 $sth = $ip_dbh->prepare("update masterblocks set mtime=now() where cidr='$webvar{whichmaster}'");
237 $sth->execute;
238 if ($sth->err) {
239 $page->param(errmsg => $sth->errstr);
240 }
241
242} elsif ($webvar{action} eq 'listcust') {
243
244 $sth = $ip_dbh->prepare("select custid,name,tech_handle from customers order by custid");
245 $sth->execute;
246 my @custlist;
247 while (my @data = $sth->fetchrow_array) {
248 my %row = (
249 custid => $data[0],
250 custname => $data[1],
251 tech => $data[2]
252 );
253 push @custlist, \%row;
254 }
255 $page->param(custlist => \@custlist);
256
257} elsif ($webvar{action} eq 'edcust') {
258
259 if ($webvar{newcust}) {
260 $sth = $ip_dbh->prepare("INSERT INTO customers (custid) VALUES (?)");
261 $sth->execute($webvar{custid});
262 }
263 $sth = $ip_dbh->prepare("select custid,name,street,city,province,".
264 "country,pocode,phone,tech_handle,abuse_handle,admin_handle,special ".
265 "from customers where custid='$webvar{custid}'");
266 $sth->execute;
267 my ($custid, $name, $street, $city, $prov, $country, $pocode, $phone, $tech, $abuse, $admin, $special) =
268 $sth->fetchrow_array;
269
270 $page->param(
271 custid => $custid,
272 name => $name,
273 street => $street,
274 city => $city,
275 prov => $prov,
276 country => $country,
277 pocode => $pocode,
278 phone => $phone,
279 tech => $tech,
280 abuse => $abuse,
281 admin => $admin,
282 special => $special
283 );
284
285} elsif ($webvar{action} eq 'updcust') {
286
287 $sth = $ip_dbh->prepare("UPDATE customers SET".
288 " name=?, street=?, city=?, province=?, country=?, pocode=?,".
289 " phone=?, tech_handle=?, abuse_handle=?, admin_handle=?, special=?".
290 " WHERE custid=?");
291 $sth->execute($webvar{name}, $webvar{street}, $webvar{city}, $webvar{province},
292 $webvar{country}, $webvar{pocode}, $webvar{phone}, $webvar{tech_handle},
293 $webvar{abuse_handle}, $webvar{admin_handle}, $webvar{special}, $webvar{custid});
294 $page->param(
295 custid => $webvar{custid},
296 name => $webvar{name},
297 street => $webvar{street},
298 city => $webvar{city},
299 prov => $webvar{province},
300 country => $webvar{country},
301 pocode => $webvar{pocode},
302 phone => $webvar{phone},
303 tech => $webvar{tech_handle},
304 abuse => $webvar{abuse_handle},
305 admin => $webvar{admin_handle},
306 special => $webvar{special}
307 );
308
309} elsif ($webvar{action} eq 'showpools') {
310
311 $sth = $ip_dbh->prepare("select pool, count(*) from poolips where available='y' group by pool order by pool");
312 $sth->execute;
313 my @poollist;
314 while (my ($pool,$free) = $sth->fetchrow_array) {
315 my %row = (
316 pool => $pool,
317 free => $free
318 );
319 push @poollist, \%row;
320 }
321 $page->param(poollist => \@poollist);
322
323} elsif ($webvar{action} eq 'tweakpool') {
324
325 showPool($webvar{pool});
326
327} elsif ($webvar{action} eq 'updatepool') {
328
329 $sth = $ip_dbh->prepare("update poolips set custid='$webvar{custid}', ".
330 "city=?, type='$webvar{type}', available='".
331 (($webvar{available} eq 'y') ? 'y' : 'n').
332 "', notes=?, description=? ".
333 "where ip='$webvar{ip}'");
334 $sth->execute($webvar{city},$webvar{notes},$webvar{desc});
335 $page->param(ip => $webvar{ip});
336 if ($sth->err) {
337 $page->param(errmsg => $sth->errstr);
338 syslog "err", "$authuser could not update pool IP $webvar{ip}: ".$sth->errstr;
339 } else {
340 syslog "notice", "$authuser updated pool IP $webvar{ip}";
341 }
342 $sth = $ip_dbh->prepare("select pool from poolips where ip='$webvar{ip}'");
343 $sth->execute;
344 my @data = $sth->fetchrow_array;
345 $page->param(pool => $data[0]);
346
347} elsif ($webvar{action} eq 'showusers') {
348
349 $sth = $ip_dbh->prepare("select username,acl from users order by username");
350 $sth->execute;
351 my @userlist;
352 while (my ($username,$acl) = $sth->fetchrow_array) {
353##fixme: funky things happening with HTML::Template here; shouldn't need the "logic ? iftrue : iffalse" structure
354 my %row = (
355 username => $username,
356 can_add => ($acl =~ /a/ ? 1 : 0),
357 can_change => ($acl =~ /c/ ? 1 : 0),
358 can_del => ($acl =~ /d/ ? 1 : 0),
359 sysnet => ($acl =~ /s/ ? 1 : 0),
360 is_admin => ($acl =~ /A/ ? 1 : 0),
361 acl => $acl
362 );
363 push @userlist, \%row;
364 }
365 $page->param(userlist => \@userlist);
366
367} elsif ($webvar{action} eq 'updacl') {
368
369 $page->param(username => $webvar{username});
370 my $acl = 'b';
371 if ($webvar{admin} eq 'on') {
372 $acl .= "acdsA";
373 } else {
374 $acl .= ($webvar{add} eq 'on' ? 'a' : '').
375 ($webvar{change} eq 'on' ? 'c' : '').
376 ($webvar{del} eq 'on' ? 'd' : '').
377 ($webvar{sysnet} eq 'on' ? 's' : '');
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: print "Content-type: text/html\n\n".$header->output;
480print $page->output;
481
482##fixme: make me a footer param!
483print qq(<hr><div><a href="$IPDB::webpath/">Back</a> to main interface</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");
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$ip_dbh->disconnect;
493
494exit;
495
496
497# Hokay. This is a little different. We have a few specific functions here:
498# -> Assign arbitrary subnet from arbitrary free space
499# -> Tweak individual DB fields
500#
501
502
503# Tweak allocfrom into shape.
504sub fix_allocfrom {
505 if ($webvar{allocfrom} =~ /^(\d+\.){2}\d+$/) {
506 # 3-octet class C specified
507 $webvar{allocfrom} .= ".0/24";
508 } elsif ($webvar{allocfrom} =~ /^(\d+\.){3}\d+$/) {
509 # 4-octet IP specified;
510 $webvar{allocfrom} .= "/24";
511 }
512}
513
514
515# Show allocations to allow editing.
516sub showAllocs {
517
518 my $within = new NetAddr::IP $_[0];
519 $page->param(within => $within);
520
521 $sth = $ip_dbh->prepare("select cidr,custid,type,city,description from allocations where cidr <<= '$within' order by cidr");
522 $sth->execute;
523 my @blocklist;
524 while (my ($cidr,$custid,$type,$city,$desc) = $sth->fetchrow_array) {
525 my %row = (
526 cidr => $cidr,
527 custid => $custid,
528 city => $city,
529 desc => $desc,
530 );
531
532##fixme: don't wanna retrieve the whole type list *every time around the outer loop*
533 my $sth2 = $ip_dbh->prepare("select type,listname from alloctypes".
534 " where listorder < 500 and not (type like '_i') order by listorder");
535 $sth2->execute;
536 my @typelist;
537 while (my ($listtype,$dispname) = $sth2->fetchrow_array) {
538 my %subrow = (
539 type => $listtype,
540 dispname => $dispname,
541 selected => ($listtype eq $type)
542 );
543 push @typelist, \%subrow;
544 }
545 $row{typelist} = \@typelist;
546 push @blocklist, \%row;
547 }
548 $page->param(blocklist => \@blocklist);
549} # end showAllocs()
550
551
552# Stuff updates into DB
553sub update {
554 # Relatively simple SQL transaction here. Note that we're deliberately NOT
555 # updating notes/desc here as it's available through the main interface.
556 $sth = $ip_dbh->prepare("update allocations set custid='$webvar{custid}',".
557 "city=?,type='$webvar{alloctype}' where cidr='$webvar{block}'");
558 $sth->execute($webvar{city});
559
560 $page->param(block => $webvar{block});
561 if ($sth->err) {
562 $page->param(updfailed => $sth->errstr);
563 syslog "err", "$authuser could not update block '$webvar{block}': '".$sth->errstr."'";
564 } else {
565 syslog "notice", "$authuser updated $webvar{block}";
566 }
567 # need to get /24 that block is part of
568 my @bits = split /\./, $webvar{block};
569 $bits[3] = "0/24";
570 showAllocs((join ".", @bits));
571} # end update()
572
573
574# showPool()
575# List all IPs in a pool, and allow arbitrary admin changes to each
576# Allow changes to ALL fields
577sub showPool($) {
578 my $pool = new NetAddr::IP $_[0];
579
580 $sth = $ip_dbh->prepare("select type,listname from alloctypes where type like '_i' order by listorder");
581 $sth->execute;
582 my @typelist;
583 while (my ($type,$dispname) = $sth->fetchrow_array) {
584 my %row = (
585 type => $type,
586 dispname => $dispname
587 );
588 push @typelist, \%row;
589 }
590 $page->param(typelist => \@typelist);
591
592 $sth = $ip_dbh->prepare("select ip,custid,city,type,available,description,notes from poolips where pool='$pool' order by ip");
593 $sth->execute;
594 my @iplist;
595 while (my ($ip,$custid,$city,$type,$avail,$desc,$notes) = $sth->fetchrow_array) {
596 my %row = (
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.