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

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

/trunk

Trim dangling database op that should have gone away in r541. See #34.

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