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

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

/trunk

admin.cgi cleanup; block listing and allocation (block/IP) update

  • Property svn:executable set to *
  • Property svn:keywords set to Date Rev Author
File size: 19.2 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 21:16:41 +0000 (Fri, 17 Oct 2014) $
9# SVN revision $Rev: 647 $
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
[644]304 my $plist = $ip_dbh->selectall_arrayref("SELECT a.id,a.cidr AS pool, count(*) AS free FROM poolips p ".
305 "JOIN allocations a ON a.id=p.parent_id ".
306 "WHERE available='y' GROUP BY a.cidr,a.id ORDER BY a.cidr", { Slice => {} });
307 $page->param(poollist => $plist);
[517]308
[65]309} elsif ($webvar{action} eq 'tweakpool') {
[517]310
[65]311 showPool($webvar{pool});
[517]312
[65]313} elsif ($webvar{action} eq 'updatepool') {
[199]314
[644]315 my $ip = $ip_dbh->selectrow_array("SELECT ip FROM poolips WHERE id=?", undef, ($webvar{id}) );
316 $page->param(ip => $ip);
317 $sth = $ip_dbh->prepare("UPDATE poolips SET custid=?, city=?, type=?, available='".
[65]318 (($webvar{available} eq 'y') ? 'y' : 'n').
[517]319 "', notes=?, description=? ".
[644]320 "WHERE id=?");
321 $sth->execute($webvar{custid}, $webvar{city}, $webvar{type}, $webvar{notes}, $webvar{desc}, $webvar{id});
[65]322 if ($sth->err) {
[517]323 $page->param(errmsg => $sth->errstr);
[644]324 syslog "err", "$authuser could not update pool IP $ip: ".$sth->errstr;
[517]325 } else {
[644]326 syslog "notice", "$authuser updated pool IP $ip";
[65]327 }
[644]328 my $poolid = $ip_dbh->selectrow_array("SELECT parent_id FROM poolips WHERE id=?", undef, ($webvar{id}) );
329 $page->param(poolid => $poolid);
330 my $pool = $ip_dbh->selectrow_array("SELECT cidr FROM allocations WHERE id=?", undef, ($poolid) );
331 $page->param(pool => $pool);
[517]332
[258]333} elsif ($webvar{action} eq 'showusers') {
[233]334
335 $sth = $ip_dbh->prepare("select username,acl from users order by username");
336 $sth->execute;
[517]337 my @userlist;
338 while (my ($username,$acl) = $sth->fetchrow_array) {
339##fixme: funky things happening with HTML::Template here; shouldn't need the "logic ? iftrue : iffalse" structure
340 my %row = (
341 username => $username,
342 can_add => ($acl =~ /a/ ? 1 : 0),
343 can_change => ($acl =~ /c/ ? 1 : 0),
344 can_del => ($acl =~ /d/ ? 1 : 0),
345 sysnet => ($acl =~ /s/ ? 1 : 0),
346 is_admin => ($acl =~ /A/ ? 1 : 0),
347 acl => $acl
348 );
349 push @userlist, \%row;
350 }
351 $page->param(userlist => \@userlist);
[233]352
353} elsif ($webvar{action} eq 'updacl') {
[517]354
355 $page->param(username => $webvar{username});
[233]356 my $acl = 'b';
357 if ($webvar{admin} eq 'on') {
[284]358 $acl .= "acdsA";
[233]359 } else {
360 $acl .= ($webvar{add} eq 'on' ? 'a' : '').
361 ($webvar{change} eq 'on' ? 'c' : '').
[284]362 ($webvar{del} eq 'on' ? 'd' : '').
363 ($webvar{sysnet} eq 'on' ? 's' : '');
[233]364 }
[517]365 $page->param(acl => $acl);
[233]366
367 $sth = $ip_dbh->prepare("update users set acl='$acl' where username='$webvar{username}'");
368 $sth->execute;
[517]369 $page->param(errmsg => $sth->errstr) if $sth->err;
[233]370
[517]371} elsif ($webvar{action} eq 'newuser') {
[233]372
[517]373 $page->param(username => $webvar{username});
[259]374 my $cr_pass = ($webvar{preenc} ? $webvar{password} :
375 crypt $webvar{password}, join('',('.','/',0..9,'A'..'Z','a'..'z')[rand 64, rand 64]));
[258]376 $sth = $ip_dbh->prepare("insert into users (username,password,acl) values ".
377 "('$webvar{username}','$cr_pass','b')");
378 $sth->execute;
[517]379 $page->param(errmsg => $sth->errstr) if $sth->err;
[258]380
[517]381} elsif ($webvar{action} eq 'deluser') {
[258]382
[517]383 $page->param(username => $webvar{username});
[258]384 $sth = $ip_dbh->prepare("delete from users where username='$webvar{username}'");
385 $sth->execute;
[517]386 $page->param(errmsg => $sth->errstr) if $sth->err;
[258]387
[517]388} elsif ($webvar{action} eq 'emailnotice') {
[258]389
[422]390 $sth = $ip_dbh->prepare("SELECT action,reciplist FROM notify");
391 $sth->execute;
[517]392 my @spamlist;
[422]393 while (my ($notice_code,$reciplist) = $sth->fetchrow_array() ) {
394##fixme: hairy mess, only a few things call mailNotify() anyway, so many possible notices won't work.
395 my $action_out = dispNoticeCode($notice_code);
[517]396 my %row = (
397 action => $action_out,
398 code => $notice_code,
399 recips => $reciplist
400 );
401 push @spamlist, \%row;
[422]402 }
[517]403 $page->param(spamlist => \@spamlist);
[423]404
405 $sth = $ip_dbh->prepare("SELECT type,dispname FROM alloctypes WHERE listorder < 500 ".
406 "ORDER BY listorder");
407 $sth->execute;
408 my $i=0;
[517]409 my @typelist;
[423]410 while (my ($type,$disp) = $sth->fetchrow_array) {
[517]411 my %row = (
412 type => $type,
413 disptype => $disp,
414# ahh, off-by-one counts, how we do love thee... NOT!
415 newrow => ($i+2 > $sth->rows ? 1 : (++$i % 4)),
416 );
417 push @typelist, \%row;
[423]418 }
[517]419 $page->param(typelist => \@typelist);
[423]420
[517]421} elsif ($webvar{action} eq 'addnotice') {
[423]422
[426]423 $webvar{alloctype} = $webvar{special} if $webvar{msgaction} eq 's:';
424 if ($webvar{msgaction} && $webvar{alloctype} && $webvar{reciplist}) {
[517]425 $page->param(cantry => 1);
[426]426 $webvar{reciplist} =~ s/[\r\n]+/,/g;
[438]427 $webvar{msgaction} = "f:$webvar{msgaction}" if $webvar{onfail};
[517]428 $page->param(reciplist => $webvar{reciplist});
429 $page->param(dispnotice => dispNoticeCode($webvar{msgaction}.$webvar{alloctype}));
[426]430 $sth = $ip_dbh->prepare("INSERT INTO notify (action, reciplist) VALUES (?,?)");
[423]431##fixme: automagically merge reciplists iff action already exists
[426]432 $sth->execute($webvar{msgaction}.$webvar{alloctype}, $webvar{reciplist});
[517]433 $page->param(addfailed => $sth->errstr) if $sth->err;
[423]434 }
435
[424]436} elsif ($webvar{action} eq 'delnotice') {
[517]437
438 $page->param(dispnotice => dispNoticeCode($webvar{code}.$webvar{alloctype}));
[424]439 $sth = $ip_dbh->prepare("DELETE FROM notify WHERE action=?");
440 $sth->execute($webvar{code});
[517]441 $page->param(delfailed => $sth->errstr) if $sth->err;
[424]442
[422]443} elsif ($webvar{action} eq 'ednotice') {
[517]444
445 $page->param(dispnotice => dispNoticeCode($webvar{code}));
446 $page->param(code => $webvar{code});
[422]447 $sth = $ip_dbh->prepare("SELECT reciplist FROM notify WHERE action=?");
448 $sth->execute($webvar{code});
449 my ($reciplist) = $sth->fetchrow_array;
450 $reciplist =~ s/,/\n/g;
[517]451 $page->param(reciplist => $reciplist);
452
[422]453} elsif ($webvar{action} eq 'updnotice') {
[517]454
455 $page->param(dispnotice => dispNoticeCode($webvar{code}));
[422]456 $sth = $ip_dbh->prepare("UPDATE notify SET reciplist=? WHERE action=?");
457 $webvar{reciplist} =~ s/[\r\n]+/,/g;
458 $sth->execute($webvar{reciplist}, $webvar{code});
[517]459 $page->param(updfailed => $sth->errstr) if $sth->err;
460
[256]461} elsif ($webvar{action} ne '<NULL>') {
[517]462 $page->param(dunno => $webvar{action});
[54]463}
464
[643]465ERRJUMP:
[517]466print $page->output;
[54]467
[517]468##fixme: make me a footer param!
[643]469print qq(<hr><div><a href="$IPDB::webpath/">Back</a> to the main IPDB</div>\n);
[54]470
[517]471# We print the footer here, so we don't have to do it elsewhere.
472my $footer = HTML::Template->new(filename => "footer.tmpl");
473# we're already in the admin tools, no need to provide a bottom link. maybe.
474#$footer->param(adminlink => ($IPDBacl{$authuser} =~ /A/));
[54]475
[517]476print $footer->output;
477
[54]478$ip_dbh->disconnect;
479
480exit;
481
482
[517]483# Hokay. This is a little different. We have a few specific functions here:
484# -> Assign arbitrary subnet from arbitrary free space
485# -> Tweak individual DB fields
486#
487
488
[54]489# Tweak allocfrom into shape.
490sub fix_allocfrom {
491 if ($webvar{allocfrom} =~ /^(\d+\.){2}\d+$/) {
492 # 3-octet class C specified
493 $webvar{allocfrom} .= ".0/24";
494 } elsif ($webvar{allocfrom} =~ /^(\d+\.){3}\d+$/) {
495 # 4-octet IP specified;
496 $webvar{allocfrom} .= "/24";
497 }
498}
499
500
[517]501# Show allocations to allow editing.
502sub showAllocs {
[58]503
[517]504 my $within = new NetAddr::IP $_[0];
505 $page->param(within => $within);
[58]506
[647]507
508 $sth = $ip_dbh->prepare("SELECT id,vrf,cidr,custid,type,city,description FROM allocations".
509 " WHERE cidr <<= ? ORDER BY vrf,cidr");
510 $sth->execute($within);
[517]511 my @blocklist;
[647]512 while (my ($id,$vrf,$cidr,$custid,$type,$city,$desc) = $sth->fetchrow_array) {
[517]513 my %row = (
[647]514 id => $id,
[517]515 cidr => $cidr,
516 custid => $custid,
517 city => $city,
518 desc => $desc,
519 );
[54]520
[517]521##fixme: don't wanna retrieve the whole type list *every time around the outer loop*
[647]522 my $sth2 = $ip_dbh->prepare("SELECT type,listname FROM alloctypes".
523 " WHERE listorder < 999 AND NOT (type LIKE '_i') ORDER BY listorder");
[348]524 $sth2->execute;
[517]525 my @typelist;
526 while (my ($listtype,$dispname) = $sth2->fetchrow_array) {
527 my %subrow = (
528 type => $listtype,
529 dispname => $dispname,
530 selected => ($listtype eq $type)
531 );
532 push @typelist, \%subrow;
[348]533 }
[517]534 $row{typelist} = \@typelist;
535 push @blocklist, \%row;
[54]536 }
[517]537 $page->param(blocklist => \@blocklist);
538} # end showAllocs()
[54]539
540
541# Stuff updates into DB
542sub update {
[647]543 my $cidr = $ip_dbh->selectrow_array("SELECT cidr FROM allocations WHERE id=?", undef, ($webvar{block}) );
544
[517]545 # Relatively simple SQL transaction here. Note that we're deliberately NOT
546 # updating notes/desc here as it's available through the main interface.
[647]547 $ip_dbh->do("UPDATE allocations SET custid=?, city=?, type=? WHERE id=?", undef,
548 ($webvar{custid}, $webvar{city}, $webvar{alloctype}, $webvar{block}) );
[517]549
[647]550 $page->param(block => $cidr);
551 if ($ip_dbh->err) {
552 $page->param(updfailed => $ip_dbh->errstr);
553 syslog "err", "$authuser could not update block '$cidr': '".$ip_dbh->errstr."'";
[54]554 } else {
[647]555 syslog "notice", "$authuser updated $cidr";
[54]556 }
557 # need to get /24 that block is part of
[647]558 my @bits = split /\./, $cidr;
[54]559 $bits[3] = "0/24";
560 showAllocs((join ".", @bits));
[517]561} # end update()
[65]562
563
564# showPool()
565# List all IPs in a pool, and allow arbitrary admin changes to each
566# Allow changes to ALL fields
[548]567sub showPool {
[647]568 my $pool = shift;
[348]569
[647]570 # arguably even presenting a list here is Wrong, because Pool IPs Should Alwasy Match The Pool Type, but...
571 # could also set "selected" on the "correct" type
572 my $tlist = getTypeList($ip_dbh, 'i');
573 $page->param(typelist => $tlist);
[348]574
[647]575 $sth = $ip_dbh->prepare("SELECT id,ip,custid,city,type,available,description,notes from poolips".
576 " WHERE parent_id=? ORDER BY ip");
[548]577 $sth->execute($pool);
[517]578 my @iplist;
[647]579 while (my ($id,$ip,$custid,$city,$type,$avail,$desc,$notes) = $sth->fetchrow_array) {
[517]580 my %row = (
[647]581 id => $id,
[517]582 ip => $ip,
583 custid => $custid,
584 city => $city,
585 type => $type,
586 avail => $avail,
587 desc => $desc,
588 notes => $notes
589 );
590 push @iplist, \%row;
[65]591 }
[517]592 $page->param(iplist => \@iplist);
593} # end showPool()
[422]594
595
596# interpret the notify codes
597sub dispNoticeCode {
598 my $code = shift;
599 my $action_out = '';
[426]600
601 if ($code =~ /^s:/) {
602 $code =~ s/^s:/Special: /;
603 return $code;
604 }
[422]605 if ($code =~ /^f:(.+)$/) {
606 $code =~ s/^f://;
607 $action_out = "Failure on ";
608 }
609 if (my $target = $code =~ /^n(.+)/) {
610 $action_out .= "New ";
611 if ($1 eq 'ci') { $action_out .= "city"; }
612 elsif ($1 eq 'no') { $action_out .= "node"; }
613 else { $action_out .= '&lt;unknown&gt;'; }
614 } else {
615 my ($action,$target) = ($code =~ /^(.)(.+)$/);
616 if ($action eq 'a') { $action_out .= 'Add '; }
617 elsif ($action eq 'u') { $action_out .= 'Update '; }
618 elsif ($action eq 'd') { $action_out .= 'Delete '; }
619##fixme: what if we get something funky?
[423]620# What about the eleventy-billion odd combinations possible?
621# this should give an idea of the structure tho
[422]622 if ($target eq 'a') { $action_out .= "all"; }
[438]623 elsif ($target eq '.i') {
[423]624 $action_out .= "all static IPs";
625 }
[422]626 else { $action_out .= $disp_alloctypes{$target}; }
627 }
628 return $action_out;
629}
Note: See TracBrowser for help on using the repository browser.