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

Last change on this file since 642 was 642, checked in by Kris Deugau, 10 years ago

/trunk

Commit really old work in admin.cgi adding rDNS

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