source: branches/htmlform/cgi-bin/admin.cgi@ 489

Last change on this file since 489 was 489, checked in by Kris Deugau, 14 years ago

/branches/htmlform

Remove use of printError() in admin.cgi. See #15, #26

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