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

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

/trunk

Extend findAllocateFrom() to allow passing a target block to allocate
to restrict the freeblock selection
Remove local SQL for confirmation page for "assign this block" in
admin.cgi in favour of existing data and subs. See #34.
For admin.cgi "assign this block", if the requested IP type does not
match the pool, the type will be adjusted and a warning pushed out.
Add space on "assign this block" template for a warning.

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