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

Last change on this file since 323 was 320, checked in by Kris Deugau, 19 years ago

/trunk

Merge all bugfixes, hacks, tweaks, and miscellaneous updates from
/branches/stable necessary to bring code into line. Aside from
CustID verification and notification bits, /trunk and
/branches/stable should now be identical.

  • Property svn:executable set to *
  • Property svn:keywords set to Date Rev Author
File size: 20.5 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: 2006-04-04 22:25:28 +0000 (Tue, 04 Apr 2006) $
9# SVN revision $Rev: 320 $
10# Last update by $Author: kdeugau $
11###
[320]12# Copyright (C) 2004-2006 - Kris Deugau
[54]13
14use strict;
15use warnings;
16use CGI::Carp qw(fatalsToBrowser);
17use DBI;
18use CommonWeb qw(:ALL);
[199]19use MyIPDB;
[54]20#use POSIX qw(ceil);
21use NetAddr::IP;
22
23use Sys::Syslog;
24
25openlog "IPDB-admin","pid","local2";
26
27# Collect the username from HTTP auth. If undefined, we're in a test environment.
28my $authuser;
29if (!defined($ENV{'REMOTE_USER'})) {
30 $authuser = '__temptest';
31} else {
32 $authuser = $ENV{'REMOTE_USER'};
33}
34
35syslog "debug", "$authuser active";
36
[199]37# Why not a global DB handle? (And a global statement handle, as well...)
38# Use the connectDB function, otherwise we end up confusing ourselves
39my $ip_dbh;
40my $sth;
41my $errstr;
42($ip_dbh,$errstr) = connectDB_My;
43if (!$ip_dbh) {
44 printAndExit("Database error: $errstr\n");
45}
46initIPDBGlobals($ip_dbh);
47
[233]48if ($IPDBacl{$authuser} !~ /A/) {
49 print "Content-Type: text/html\n\n".
50 "<html><head><title>Access denied</title></head><body>\n".
51 'Access to this tool is restricted. Contact <a href="mailto:kdeugau@vianet.ca">Kris</a> '.
52 "for more information.</body></html>\n";
53 exit;
54}
55
[54]56my %webvar = parse_post();
57cleanInput(\%webvar);
[58]58
[54]59print "Content-type: text/html\n\n".
[199]60 "<html>\n<head>\n\t<title>TEST [IPDB admin tools] TEST</title>\n".
61 qq(\t<link rel="stylesheet" type="text/css" href="/ip/ipdb.css">\n).
62 "</head>\n<body>\n".
[54]63 "<h2>IPDB - Administrative Tools</h2>\n<hr>\n";
64
65if(!defined($webvar{action})) {
66 $webvar{action} = "<NULL>"; #shuts up the warnings.
[199]67
68 my $typelist = '';
69 $sth = $ip_dbh->prepare("select type,listname from alloctypes where listorder < 900 order by listorder");
70 $sth->execute;
71 my @data = $sth->fetchrow_array;
72 $typelist .= "<option value='$data[0]' selected>$data[1]</option>\n";
73 while (my @data = $sth->fetchrow_array) {
74 $typelist .= "<option value='$data[0]'>$data[1]</option>\n";
75 }
76
[54]77 print qq(WARNING: There are FAR fewer controls on what you can do here. Use the
78main interface if at all possible.
[199]79<hr>
80<a href="admin.cgi?action=newalloc">Add allocation</a>
81<hr>
82<form action="admin.cgi" method="POST">
[54]83<input type=hidden name=action value=alloc>
[199]84Allocate block/IP: <input name=cidr> as <select name=alloctype>$typelist</select> to <input name=custid>
85<input type=submit value=" GIMME!! "></form>
[54]86<hr><form action="admin.cgi" method="POST">
87<input type=hidden name=action value=alloctweak>
88Manually update allocation data in this /24: <input name=allocfrom>
89<input type=submit value="Show allocations">
[65]90</form>
91<hr><a href="admin.cgi?action=showpools">List IP Pools</a> for manual tweaking and updates
[258]92<hr><a href="admin.cgi?action=showusers">Manage users</a> (add/remove users; change
93internal access controls - note that this does NOT include IP-based limits)
[320]94<hr>Consistency check tools<br>
95<a href="consistency-check.pl">General</a>: Check general netblock consistency.<br>
96<a href="freespace.pl">Free space</a>: List total and aggregate free space. Does not
97include private networks (192.168.0.0/16, 172.16.0.0/12, 10.0.0.0/8)
[54]98);
99} else {
100 print '<a href="/ip/cgi-bin/admin.cgi">Back</a> to main<hr>';
101}
102
[199]103
104## Possible actions.
[54]105if ($webvar{action} eq 'alloc') {
[199]106 # OK, we know what we're allocating.
107
108 if ($webvar{cidr} !~ /^\s*(\d{1,3}\.){3}\d{1,3}(\/\d{2})?\s*$/) {
109 printAndExit("Can't allocate something that's not a netblock/ip");
110 }
111
112 $sth = $ip_dbh->prepare("select def_custid from alloctypes where type='$webvar{alloctype}'");
113 $sth->execute;
114 my @data = $sth->fetchrow_array;
115 my $custid = $data[0];
116 if ($custid eq '') {
117 # Type that doesn't have a default custid
118 $custid = $webvar{custid};
119 }
120##fixme Check billing DB here
121
122 my $cidr = new NetAddr::IP $webvar{cidr};
123 my @data;
124 if ($webvar{alloctype} eq 'rm') {
125 $sth = $ip_dbh->prepare("select cidr from freeblocks where cidr >>='$cidr' and routed='n'");
126 $sth->execute;
127 @data = $sth->fetchrow_array;
128# User deserves errors if user can't be bothered to find the free block first.
129 printAndExit("Can't allocate from outside a free block!!\n")
130 if !$data[0];
[256]131 } elsif ($webvar{alloctype} =~ /^(.)i$/) {
132 $sth = $ip_dbh->prepare("select cidr from allocations where cidr >>='$cidr' and (type like '_d' or type like '_p')");
133 $sth->execute;
134 @data = $sth->fetchrow_array;
135# User deserves errors if user can't be bothered to find the pool and a free IP first.
136 printAndExit("Can't allocate static IP from outside a pool!!\n")
137 if !$data[0];
[199]138 } else {
139 $sth = $ip_dbh->prepare("select cidr from freeblocks where cidr >>='$cidr' and not (routed='n')");
140 $sth->execute;
141 @data = $sth->fetchrow_array;
142# User deserves errors if user can't be bothered to find the free block first.
143 printAndExit("Can't allocate from outside a routed block!!\n")
144 if !$data[0];
145 }
146
147 my $alloc_from = new NetAddr::IP $data[0];
148 $sth->finish;
149
150 my $cities = '';
151 foreach my $city (@citylist) {
152 $cities .= "<option>$city</option>\n";
153 }
154
155 print qq(<table class=regular>
156<form method=POST action=admin.cgi>
157<tr class=color1>
158<td>Allocating:</td>
159<td>$cidr<input type=hidden name=cidr value="$cidr"></td>
160</tr><tr class=color2>
161<td>Type:</td><td>$disp_alloctypes{$webvar{alloctype}}
162<input type=hidden name=alloctype value="$webvar{alloctype}"></td>
163</tr><tr class=color1>
164<td>Allocated from:</td>
165<td>$alloc_from<input type=hidden name=alloc_from value="$alloc_from"></td>
166</tr><tr class="color2">
167<td>Customer ID:</td><td>$custid<input type=hidden name=custid value="$custid"></td>
168</tr><tr class=color1>
169<td>Customer location:</td><td>
170<select name="city"><option selected>-</option>
171$cities
172</select>
173&nbsp;<a href="javascript:popNotes('/ip/newcity.html')">Add new location</a>
174</td>
175</tr>
176<tr class="color2">
177<td>Circuit ID:</td><td><input name=circid size=40></td>
178</tr><tr class="color1">
179<td>Description/Name:</td><td><input name="desc" size=40></td>
180</tr><tr class="color2">
181<td>Notes:</td><td><textarea name="notes" rows="3" cols="40"></textarea></td>
182</tr><tr class="warning">
183<td colspan=2><center>WARNING: This will IMMEDIATELY assign this block!!</center></td>
184</tr><tr class="color2">
185<td class="center" colspan="2"><input type="submit" value=" Assign "></td>
186<input type="hidden" name="action" value="confirm">
[293]187</form>
[199]188</tr>
189</table>
190);
191
192
193} elsif ($webvar{action} eq 'confirm') {
194
195 print "Assigning $webvar{cidr} to $webvar{custid} (\"$webvar{desc}\") as ".
196 "$disp_alloctypes{$webvar{alloctype}}...<br>\n";
197 # Only need to check city here.
198 if ($webvar{city} eq '-') {
199 printError("Invalid customer location! Go back and select customer's location.");
200 } else {
[293]201 if ($webvar{alloctype} =~ /^.i$/) {
202 $sth = $ip_dbh->prepare("update poolips set available='n', custid='$webvar{custid}', ".
203 "city='$webvar{city}', description='$webvar{desc}', notes='$webvar{notes}' ".
204 "where ip='$webvar{cidr}'");
205 $sth->execute;
206 if ($sth->err) {
207 print "Allocation failed! DBI said:\n".$sth->errstr."\n";
208 syslog "err", "($authuser) Allocation of '$webvar{cidr}' to '$webvar{custid}' as ".
209 "'$webvar{alloctype}' failed: '".$sth->errstr."'";
210 } else {
211 print "Allocation OK!\n";
212 syslog "notice", "$authuser allocated '$webvar{cidr}' to '$webvar{custid}' as ".
213 "'$webvar{alloctype}'";
214 # Notify tech@example.com
215 mailNotify('tech@example.com',"$disp_alloctypes{$webvar{alloctype}} allocation",
[295]216 "$disp_alloctypes{$webvar{alloctype}} $webvar{cidr} allocated to customer".
217 " $webvar{custid}\n".
[293]218 "Description: $webvar{desc}\n\nAllocated by: $authuser\n");
219 }
220 } else {
221 my ($retcode,$msg) = allocateBlock($ip_dbh, $webvar{cidr}, $webvar{alloc_from},
[199]222 $webvar{custid}, $webvar{alloctype}, $webvar{city}, $webvar{desc}, $webvar{notes},
223 $webvar{circid});
[293]224 if ($retcode eq 'OK') {
225 print "Allocation OK!\n";
226 syslog "notice", "$authuser allocated '$webvar{cidr}' to '$webvar{custid}' as ".
227 "'$webvar{alloctype}'";
228 } else {
229 print "Allocation failed! IPDB::allocateBlock said:\n$msg\n";
230 syslog "err", "($authuser) Allocation of '$webvar{cidr}' to '$webvar{custid}' as ".
231 "'$webvar{alloctype}' failed: '$msg'";
232 }
233 } # static IP vs netblock
[199]234
235 } # done city check
236
[54]237} elsif ($webvar{action} eq 'alloctweak') {
238 fix_allocfrom();
239 showAllocs($webvar{allocfrom});
240} elsif ($webvar{action} eq 'update') {
241 update();
[58]242} elsif ($webvar{action} eq 'assign') {
243 # Display a list of possible blocks within the requested block.
244 open (HTML, "../admin_alloc.html")
245 or croak "Could not open admin_alloc.html :$!";
246 my $html = join('', <HTML>);
247 $html =~ s/\$\$MASK\$\$/$webvar{masklen}/g;
248 $html =~ s/\$\$ALLOCFROM\$\$/$webvar{allocfrom}/g;
249
250 my $from = new NetAddr::IP $webvar{allocfrom};
251 my @blocklist = $from->split($webvar{masklen});
252 my $availblocks;
253 foreach (@blocklist) {
254 $availblocks .= qq(<tr><td colspan=2 align=center><input type=radio name=block value="$_">$_</td></tr>\n);
255 }
256 $html =~ s/\$\$BLOCKLIST\$\$/$availblocks/g;
257
258 print $html;
[65]259} elsif ($webvar{action} eq 'showpools') {
260 print "IP Pools currently allocated:\n".
261 "<table border=1>\n<tr><td>Pool</td><td># of free IPs</td></tr>\n";
[199]262 $sth = $ip_dbh->prepare("select cidr from allocations where type like '%p' or type like '%d' order by cidr");
[65]263 $sth->execute;
264 my %poolfree;
265 while (my @data = $sth->fetchrow_array) {
266 $poolfree{$data[0]} = 0;
267 }
268 $sth = $ip_dbh->prepare("select pool,ip from poolips where available='y' order by ip");
269 $sth->execute;
270 while (my @data = $sth->fetchrow_array) {
271 $poolfree{$data[0]}++;
272 }
273 foreach my $key (keys %poolfree) {
274 print qq(<tr><td><a href="admin.cgi?action=tweakpool&pool=$key">$key</a></td>).
275 "<td>$poolfree{$key}</td></tr>\n";
276 }
277 print "</table>\n";
278} elsif ($webvar{action} eq 'tweakpool') {
279 showPool($webvar{pool});
280} elsif ($webvar{action} eq 'updatepool') {
[199]281
[65]282 $sth = $ip_dbh->prepare("update poolips set custid='$webvar{custid}', ".
[199]283 "city='$webvar{city}', type='$webvar{type}', available='".
[65]284 (($webvar{available} eq 'y') ? 'y' : 'n').
285 "', notes='$webvar{notes}', description='$webvar{desc}' ".
286 "where ip='$webvar{ip}'");
287 $sth->execute;
288 if ($sth->err) {
289 print "Error updating pool IP $webvar{ip}: $@<hr>\n";
290 syslog "err", "$authuser could not update pool IP $webvar{ip}: $@";
291 } else {
292 $sth = $ip_dbh->prepare("select pool from poolips where ip='$webvar{ip}'");
293 $sth->execute;
294 my @data = $sth->fetchrow_array;
295 print "$webvar{ip} in $data[0] updated\n<hr>\n";
296 syslog "notice", "$authuser updated pool IP $webvar{ip}";
297 }
[258]298} elsif ($webvar{action} eq 'showusers') {
[233]299 print "Notes:<br>\n".
[258]300 "<li>Admin users automatically get all other priviledges.\n".
[320]301 "<li>Everyone has basic read access.\n".
[258]302 "<hr>Add new user:<form action=admin.cgi method=POST>\n".
303 "Username: <input name=username><br>\n".
[259]304 "Password: <input name=password> <input type=checkbox name=preenc>Password is pre-encrypted (MUST be crypt() encrypted)<br>\n".
[258]305 "<input type=submit value='Add user'><input type=hidden name=action value=newuser></form>\n";
[233]306
307 print "<hr>Users with access:\n<table border=1>\n";
[284]308 print "<tr><td></td><td align=center colspan=3>General access</td></tr>\n";
[233]309 print "<tr><td>Username</td><td>Add new</td><td>Change</td>".
[284]310 "<td>Delete</td><td>Systems/Networking</td><td>Admin user</td></tr>\n".
[233]311 "<form action=admin.cgi method=POST>\n";
312 $sth = $ip_dbh->prepare("select username,acl from users order by username");
313 $sth->execute;
314 while (my @data = $sth->fetchrow_array) {
315 print "<form action=admin.cgi method=POST><input type=hidden name=action value=updacl>".
316 qq(<tr><td>$data[0]<input type=hidden name=username value="$data[0]"></td><td>).
317 # Now for the fun bit. We have to pull apart the ACL field and
318 # output a bunch of checkboxes.
319 "<input type=checkbox name=add".($data[1] =~ /a/ ? ' checked=y' : '').
320 "></td><td><input type=checkbox name=change".($data[1] =~ /c/ ? ' checked=y' : '').
321 "></td><td><input type=checkbox name=del".($data[1] =~ /d/ ? ' checked=y' : '').
[284]322 "></td><td><input type=checkbox name=sysnet".($data[1] =~ /s/ ? ' checked=y' : '').
[233]323 "></td><td><input type=checkbox name=admin".($data[1] =~ /A/ ? ' checked=y' : '').
[258]324 qq(></td><td><input type=submit value="Update"></td></form>\n).
325 "<form action=admin.cgi method=POST><td><input type=hidden name=action value=deluser>".
326 "<input type=hidden name=username value=$data[0]>".
327 qq(<input type=submit value="Delete user"></tr></form>\n);
[233]328
329 }
330 print "</table>\n";
331} elsif ($webvar{action} eq 'updacl') {
332 print "Updating ACL for $webvar{username}:<br>\n";
333 my $acl = 'b';
334 if ($webvar{admin} eq 'on') {
[284]335 $acl .= "acdsA";
[233]336 } else {
337 $acl .= ($webvar{add} eq 'on' ? 'a' : '').
338 ($webvar{change} eq 'on' ? 'c' : '').
[284]339 ($webvar{del} eq 'on' ? 'd' : '').
340 ($webvar{sysnet} eq 'on' ? 's' : '');
[233]341 }
342 print "New ACL: $acl<br>\n";
343
344 $sth = $ip_dbh->prepare("update users set acl='$acl' where username='$webvar{username}'");
345 $sth->execute;
346 print "OK\n" if !$sth->err;
347
[258]348 print qq(<hr><a href="admin.cgi?action=showusers">Back</a> to user listing\n);
[233]349
[258]350} elsif ($webvar{action} eq 'newuser') {
351 print "Adding user $webvar{username}...\n";
[259]352 my $cr_pass = ($webvar{preenc} ? $webvar{password} :
353 crypt $webvar{password}, join('',('.','/',0..9,'A'..'Z','a'..'z')[rand 64, rand 64]));
[258]354 $sth = $ip_dbh->prepare("insert into users (username,password,acl) values ".
355 "('$webvar{username}','$cr_pass','b')");
356 $sth->execute;
357 if ($sth->err) {
358 print "<br>Error adding user: ".$sth->errstr;
359 } else {
360 print "OK\n";
361 }
362
363 print qq(<hr><a href="admin.cgi?action=showusers">Back</a> to user listing\n);
364
365} elsif ($webvar{action} eq 'deluser') {
366 print "Deleting user $webvar{username}.<br>\n";
367 $sth = $ip_dbh->prepare("delete from users where username='$webvar{username}'");
368 $sth->execute;
369 print "OK\n" if !$sth->err;
370
371 print qq(<hr><a href="admin.cgi?action=showusers">Back</a> to user listing\n);
372
[256]373} elsif ($webvar{action} ne '<NULL>') {
[233]374 print "webvar{action} check failed: Don't know how to $webvar{action}";
[54]375}
376
377# Hokay. This is a little different. We have a few specific functions here:
378# -> Assign arbitrary subnet from arbitrary free space
379# -> Tweak individual DB fields
380#
381
382
383printFooter;
384
385$ip_dbh->disconnect;
386
387exit;
388
389
390# Tweak allocfrom into shape.
391sub fix_allocfrom {
392 if ($webvar{allocfrom} =~ /^(\d+\.){2}\d+$/) {
393 # 3-octet class C specified
394 $webvar{allocfrom} .= ".0/24";
395 } elsif ($webvar{allocfrom} =~ /^(\d+\.){3}\d+$/) {
396 # 4-octet IP specified;
397 $webvar{allocfrom} .= "/24";
398 }
399}
400
401
[58]402# List free blocks in a /24 for arbitrary manual allocation
403sub showfree($) {
404 my $cidr = new NetAddr::IP $_[0];
405 print "Showing free blocks in $cidr<br>\n".
406 "<table border=1>\n";
407 $sth = $ip_dbh->prepare("select * from freeblocks where cidr <<= '$cidr' order by cidr");
408 $sth->execute;
409 while (my @data = $sth->fetchrow_array) {
410 my $temp = new NetAddr::IP $data[0];
411 print "<tr><form action=admin.cgi method=POST><input type=hidden name=action value=assign>\n".
412 qq(<td>$temp<input type=hidden name=allocfrom value="$temp"></td>\n).
413 "<td>".
414 (($temp->masklen == 30) ? '<input type=hidden name=masklen value=30>30'
415 : "<select name=masklen><option>30</option>\n<option>29</option>\n") .
416 (($temp->masklen < 29) ? "<option>28</option>\n" : '') .
417 (($temp->masklen < 28) ? "<option>27</option>\n" : '') .
418 (($temp->masklen < 27) ? "<option>26</option>\n" : '') .
419 (($temp->masklen < 26) ? "<option>25</option>\n" : '') .
420 (($temp->masklen < 25) ? "<option>24</option>\n" : '') .
421 "</td>".
422 qq(<td>$data[2]</td><td><input type=submit value="Allocate from here"></td>).
423 "\n</form></tr>\n";
424 }
425 print "</table>\n";
426}
427
428
[54]429# Show allocations to allow editing.
430sub showAllocs($) {
431 my $cidr = new NetAddr::IP $_[0];
432 print "Edit custID, allocation type, city for allocations in ".
433 "$cidr:\n<table border=1>";
434 $sth = $ip_dbh->prepare("select * from allocations where cidr <<= '$cidr' order by cidr");
435 $sth->execute;
436 while (my @data = $sth->fetchrow_array) {
437 print "<tr><form action=admin.cgi method=POST><input type=hidden name=action value=update>\n".
438 qq(<td>$data[0]<input type=hidden value="$data[0]" name=block></td>\n).
439 qq(<td><input name=custid value="$data[1]"></td>\n);
440
441 print "<td><select name=alloctype><option".
442 (($data[2] eq 'cn') ? ' selected' : '') ." value='cn'>Customer netblock</option>\n<option".
443 (($data[2] eq 'si') ? ' selected' : '') ." value='si'>Static IP - Server pool</option>\n<option".
444 (($data[2] eq 'ci') ? ' selected' : '') ." value='ci'>Static IP - Cable</option>\n<option".
445 (($data[2] eq 'di') ? ' selected' : '') ." value='di'>Static IP - DSL</option>\n<option".
446 (($data[2] eq 'mi') ? ' selected' : '') ." value='mi'>Static IP - Dialup</option>\n<option".
447 (($data[2] eq 'wi') ? ' selected' : '') ." value='wi'>Static IP - Wireless</option>\n<option".
[199]448 (($data[2] eq 'sd') ? ' selected' : '') ." value='sd'>Static Pool - Server pool</option>\n<option".
449 (($data[2] eq 'cd') ? ' selected' : '') ." value='cd'>Static Pool - Cable</option>\n<option".
[54]450 (($data[2] eq 'dp') ? ' selected' : '') ." value='dp'>Static Pool - DSL</option>\n<option".
451 (($data[2] eq 'mp') ? ' selected' : '') ." value='mp'>Static Pool - Dialup</option>\n<option".
452 (($data[2] eq 'wp') ? ' selected' : '') ." value='wp'>Static Pool - Wireless</option>\n<option".
[199]453 (($data[2] eq 'en') ? ' selected' : '') ." value='en'>End-use netblock</option>\n<option".
454 (($data[2] eq 'me') ? ' selected' : '') ." value='me'>Dialup netblock</option>\n<option".
455 (($data[2] eq 'de') ? ' selected' : '') ." value='de'>Dynamic DSL netblock</option>\n<option".
456 (($data[2] eq 'ce') ? ' selected' : '') ." value='ce'>Dynamic cable netblock</option>\n<option".
457 (($data[2] eq 'we') ? ' selected' : '') ." value='we'>Dynamic WiFi netblock</option>\n<option".
458 (($data[2] eq 'in') ? ' selected' : '') ." value='in'>Internal netblock</option>\n".
[54]459 "</select></td>\n";
460 print qq(<td><input name=city value="$data[3]"></td>\n).
461 "<td>$data[4]</td><td>$data[5]</td>".
462 qq(<td><input type=submit value="Update"></td></form></tr>\n);
463 }
464 print "</table>\n";
465
466 # notes
467 print "<hr><b>Notes:</b>\n".
468 "<ul>\n<li>Use the main interface to update description and notes fields\n".
469 "<li>Changing the allocation type here will NOT affect IP pool data.\n".
470 "</ul>\n";
471}
472
473
474# Stuff updates into DB
475sub update {
476 eval {
477 # Relatively simple SQL transaction here. Note that we're deliberately NOT
478 # updating notes/desc here as it's available through the main interface.
479 $sth = $ip_dbh->prepare("update allocations set custid='$webvar{custid}',".
480 "city='$webvar{city}',type='$webvar{alloctype}' where cidr='$webvar{block}'");
481 $sth->execute;
482 $ip_dbh->commit;
483 };
484 if ($@) {
485 carp "Transaction aborted because $@";
486 eval { $ip_dbh->rollback; };
[65]487 syslog "err", "$authuser could not update block '$webvar{block}': '$@'";
[54]488 } else {
489 # If we get here, the operation succeeded.
490 syslog "notice", "$authuser updated $webvar{block}";
491 print "Allocation $webvar{block} updated<hr>\n";
492 }
493 # need to get /24 that block is part of
494 my @bits = split /\./, $webvar{block};
495 $bits[3] = "0/24";
496 showAllocs((join ".", @bits));
497}
[65]498
499
500# showPool()
501# List all IPs in a pool, and allow arbitrary admin changes to each
502# Allow changes to ALL fields
503sub showPool($) {
504 my $pool = new NetAddr::IP $_[0];
505 print qq(Listing pool $pool:\n<table border=1>
506<form action=admin.cgi method=POST>
507<input type=hidden name=action value=updatepool>
508<tr><td align=right>Customer ID:</td><td><input name=custid></td></tr>
509<tr><td align=right>Customer location:</td><td><input name=city></td></tr>
[199]510<tr><td align=right>Type:</td><td><select name=type><option selected>-</option>
511<option value="si">Static IP - Server pool</option>
512<option value="ci">Static IP - Cable</option>
513<option value="di">Static IP - DSL</option>
514<option value="mi">Static IP - Dialup</option>
515<option value="wi">Static IP - Wireless</option>
[65]516</select></td></tr>
517<tr><td align=right>Available?</td><td><input type=checkbox value=y></td></tr>
518<tr><td align=right>Description/name:</td><td><input name=desc size=40></td></tr>
519<tr><td align=right>Notes:</td><td><textarea name=notes rows=3 cols=40></textarea></td></tr>
520<tr><td colspan=2 align=center><input type=submit value="Update"></td></tr>
521).
522 "</table>Update the following record:<table border=1>\n";
[199]523 $sth = $ip_dbh->prepare("select pool,ip,custid,city,type,available,description,notes from poolips where pool='$pool' order by ip");
[65]524 $sth->execute;
525 while (my @data = $sth->fetchrow_array) {
526 print qq(<tr><td><input type=radio name=ip value="$data[1]">$data[1]</td>).
527 "<td>$data[2]</td><td>$data[3]</td><td>$data[4]</td>".
528 "<td>$data[5]</td><td>$data[6]</td><td>$data[7]</td></tr>\n";
529 }
530 print "</form></table>\n";
531}
Note: See TracBrowser for help on using the repository browser.