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

Last change on this file since 541 was 541, checked in by Kris Deugau, 11 years ago

/trunk

Start on SQL in admin.cgi. See #34.

  • Convert Q-n-D allocation list on main page to use existing getTypeList()
  • Convert timestamp-update master block list to use new getMasterList(), with a flag set to return the last-modified time. Also convert main.cgi new assignment page to use this, with the flag set to not return the lastmod.
  • Tweak admin main template to match

While following the code for the master block list, I also removed
several useless globals (@masterblocks, %allocated, %free, and
%routed) since they were only used originally in one place (index
page from main.cgi), obsoleted by changes in r523, and in fact got
overridden locally before that anyway.

  • 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: 2012-11-02 19:54:31 +0000 (Fri, 02 Nov 2012) $
9# SVN revision $Rev: 541 $
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 $sth = $ip_dbh->prepare("select type,listname from alloctypes where listorder < 900 order by listorder");
106 $sth->execute;
107
108 my $tlist = getTypeList($ip_dbh, 'a');
109 $tlist->[0]->{sel} = 1;
110 $page->param(typelist => $tlist);
111
112 my $mlist = getMasterList($ip_dbh, 'm');
113 $page->param(masterlist => $mlist);
114
115}
116
117## Non-default actions.
118
119elsif ($webvar{action} eq 'alloc') {
120
121 if ($webvar{cidr} !~ /^\s*(\d{1,3}\.){3}\d{1,3}(\/\d{2})?\s*$/) {
122 $page->param(errmsg => "Can't allocate something that's not a netblock/ip");
123 goto ERRJUMP;
124 }
125
126 $sth = $ip_dbh->prepare("select def_custid from alloctypes where type='$webvar{alloctype}'");
127 $sth->execute;
128 my @data = $sth->fetchrow_array;
129 my $custid = $data[0];
130 if ($custid eq '') {
131 if ($webvar{custid} !~ /^(?:\d{10}|\d{7}|STAFF)(?:-\d\d?)?$/) {
132 # Force uppercase for now...
133 $webvar{custid} =~ tr/a-z/A-Z/;
134 # Crosscheck with billing.
135 my $status = CustIDCK->custid_exist($webvar{custid});
136 if ($CustIDCK::Error) {
137 $page->param(errmsg => "Error verifying customer ID: ".$CustIDCK::ErrMsg);
138 goto ERRJUMP;
139 }
140 if (!$status) {
141 $page->param(errmsg => "Customer ID not valid. Make sure the Customer ID ".
142 "is correct.<br>\nUse STAFF for staff static IPs, and $IPDB::defcustid for any other ".
143 "non-customer assignments.");
144 goto ERRJUMP;
145 }
146 }
147 # Type that doesn't have a default custid
148 $custid = $webvar{custid};
149 }
150
151 my $cidr = new NetAddr::IP $webvar{cidr};
152 my @data;
153 if ($webvar{alloctype} eq 'rm') {
154 $sth = $ip_dbh->prepare("select cidr from freeblocks where cidr >>='$cidr' and routed='n'");
155 $sth->execute;
156 @data = $sth->fetchrow_array;
157# User deserves errors if user can't be bothered to find the free block first.
158 if (!$data[0]) {
159 $page->param(errmsg => "Can't allocate from outside a free block!!");
160 goto ERRJUMP;
161 }
162 } elsif ($webvar{alloctype} =~ /^(.)i$/) {
163 $sth = $ip_dbh->prepare("select cidr from allocations where cidr >>='$cidr' and (type like '_d' or type like '_p')");
164 $sth->execute;
165 @data = $sth->fetchrow_array;
166# User deserves errors if user can't be bothered to find the pool and a free IP first.
167 if (!$data[0]) {
168 $page->param(errmsg => "Can't allocate static IP from outside a pool!!");
169 goto ERRJUMP;
170 }
171 } else {
172 $sth = $ip_dbh->prepare("select cidr from freeblocks where cidr >>='$cidr' and not (routed='n')");
173 $sth->execute;
174 @data = $sth->fetchrow_array;
175# User deserves errors if user can't be bothered to find the free block first.
176 if (!$data[0]) {
177 $page->param(errmsg => "Can't allocate from outside a routed block!!");
178 goto ERRJUMP;
179 }
180 }
181
182 my $alloc_from = new NetAddr::IP $data[0];
183 $sth->finish;
184
185 my @cities;
186 foreach my $city (@citylist) {
187 my %row = (city => $city);
188 push @cities, \%row;
189 }
190 $page->param(
191 cidr => $cidr,
192 disptype => $disp_alloctypes{$webvar{alloctype}},
193 type => $webvar{alloctype},
194 alloc_from => $alloc_from,
195 custid => $custid,
196 citylist => \@cities
197 );
198
199} elsif ($webvar{action} eq 'confirm') {
200
201 $page->param(
202 cidr => $webvar{cidr},
203 custid => $webvar{custid},
204 desc => $webvar{desc},
205 disptype => $disp_alloctypes{$webvar{alloctype}}
206 );
207 # Only need to check city here.
208 if ($webvar{city} eq '-') {
209 $page->param(locerr => "Invalid customer location! Go back and select customer's location.");
210 goto ERRJUMP;
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
499ERRJUMP: print "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="$IPDB::webpath/">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.