Index: branches/htmlform/cgi-bin/admin.cgi
===================================================================
--- branches/htmlform/cgi-bin/admin.cgi	(revision 483)
+++ branches/htmlform/cgi-bin/admin.cgi	(revision 484)
@@ -117,10 +117,7 @@
   $page->param(masterlist => \@masterlist);
 
-#} else {
-#  print '<a href="/ip/cgi-bin/admin.cgi">Back</a> to main<hr>';
-}
-
-
-## Possible actions.
+}
+
+## Non-default actions.
 elsif ($webvar{action} eq 'alloc') {
   # OK, we know what we're allocating.
@@ -290,10 +287,12 @@
 
   print $html;
+
 } elsif ($webvar{action} eq 'touch') {
-  print "Touching master $webvar{whichmaster}\n";
+
+  $page->param(master => $webvar{whichmaster});
   $sth = $ip_dbh->prepare("update masterblocks set mtime=now() where cidr='$webvar{whichmaster}'");
   $sth->execute;
   if ($sth->err) {
-    print "<p>Error updating modified timestamp on master $webvar{whichmaster}: ".$sth->errstr."\n";
+    $page->param(errmsg => $sth->errstr);
   }
 
@@ -366,22 +365,17 @@
 
 } elsif ($webvar{action} eq 'showpools') {
-  print "IP Pools currently allocated:\n".
-	"<table border=1>\n<tr><td>Pool</td><td># of free IPs</td></tr>\n";
-  $sth = $ip_dbh->prepare("select cidr from allocations where type like '%p' or type like '%d' order by cidr");
-  $sth->execute;
-  my %poolfree;
-  while (my @data = $sth->fetchrow_array) {
-    $poolfree{$data[0]} = 0;
-  }
-  $sth = $ip_dbh->prepare("select pool,ip from poolips where available='y' order by ip");
-  $sth->execute;
-  while (my @data = $sth->fetchrow_array) {
-    $poolfree{$data[0]}++;
-  }
-  foreach my $key (keys %poolfree) {
-    print qq(<tr><td><a href="admin.cgi?action=tweakpool&pool=$key">$key</a></td>).
-	"<td>$poolfree{$key}</td></tr>\n";
-  }
-  print "</table>\n";
+
+  $sth = $ip_dbh->prepare("select pool, count(*) from poolips where available='y' group by pool order by pool");
+  $sth->execute;
+  my @poollist;
+  while (my ($pool,$free) = $sth->fetchrow_array) {
+    my %row = (
+	pool => $pool,
+	free => $free
+	);
+    push @poollist, \%row;
+  }
+  $page->param(poollist => \@poollist);
+
 } elsif ($webvar{action} eq 'tweakpool') {
   showPool($webvar{pool});
@@ -389,9 +383,9 @@
 
   $sth = $ip_dbh->prepare("update poolips set custid='$webvar{custid}', ".
-	"city='$webvar{city}', type='$webvar{type}', available='".
+	"city=?, type='$webvar{type}', available='".
 	(($webvar{available} eq 'y') ? 'y' : 'n').
-	"', notes='$webvar{notes}', description='$webvar{desc}' ".
+	"', notes=?, description=? ".
 	"where ip='$webvar{ip}'");
-  $sth->execute;
+  $sth->execute($webvar{city},$webvar{notes},$webvar{desc});
   if ($sth->err) {
     print "Error updating pool IP $webvar{ip}: $@<hr>\n";
@@ -404,39 +398,28 @@
     syslog "notice", "$authuser updated pool IP $webvar{ip}";
   }
+
 } elsif ($webvar{action} eq 'showusers') {
-  print "Notes:<br>\n".
-	"<li>Admin users automatically get all other priviledges.\n".
-	"<li>Everyone has basic read access.\n".
-	"<hr>Add new user:<form action=admin.cgi method=POST>\n".
-	"Username: <input name=username><br>\n".
-	"Password: <input name=password> <input type=checkbox name=preenc>Password is pre-encrypted (MUST be crypt() encrypted)<br>\n".
-	"<input type=submit value='Add user'><input type=hidden name=action value=newuser></form>\n";
-
-  print "<hr>Users with access:\n<table border=1>\n";
-  print "<tr><td></td><td align=center colspan=3>General access</td></tr>\n";
-  print "<tr><td>Username</td><td>Add new</td><td>Change</td>".
-	"<td>Delete</td><td>Systems/Networking</td><td>Admin user</td></tr>\n".
-	"<form action=admin.cgi method=POST>\n";
+
   $sth = $ip_dbh->prepare("select username,acl from users order by username");
   $sth->execute;
-  while (my @data = $sth->fetchrow_array) {
-    print "<form action=admin.cgi method=POST><input type=hidden name=action value=updacl>".
-	qq(<tr><td>$data[0]<input type=hidden name=username value="$data[0]"></td><td>).
-    # Now for the fun bit.  We have to pull apart the ACL field and
-    # output a bunch of checkboxes.
-    	"<input type=checkbox name=add".($data[1] =~ /a/ ? ' checked=y' : '').
-	"></td><td><input type=checkbox name=change".($data[1] =~ /c/ ? ' checked=y' : '').
-	"></td><td><input type=checkbox name=del".($data[1] =~ /d/ ? ' checked=y' : '').
-	"></td><td><input type=checkbox name=sysnet".($data[1] =~ /s/ ? ' checked=y' : '').
-	"></td><td><input type=checkbox name=admin".($data[1] =~ /A/ ? ' checked=y' : '').
-	qq(></td><td><input type=submit value="Update"></td></form>\n).
-	"<form action=admin.cgi method=POST><td><input type=hidden name=action value=deluser>".
-	"<input type=hidden name=username value=$data[0]>".
-	qq(<input type=submit value="Delete user"></tr></form>\n);
-
-  }
-  print "</table>\n";
+  my @userlist;
+  while (my ($username,$acl) = $sth->fetchrow_array) {
+##fixme: funky things happening with HTML::Template here;  shouldn't need the "logic ? iftrue : iffalse" structure
+    my %row = (
+	username => $username,
+	can_add => ($acl =~ /a/ ? 1 : 0),
+	can_change => ($acl =~ /c/ ? 1 : 0),
+	can_del => ($acl =~ /d/ ? 1 : 0),
+	sysnet => ($acl =~ /s/ ? 1 : 0),
+	is_admin => ($acl =~ /A/ ? 1 : 0),
+	acl => $acl
+	);
+    push @userlist, \%row;
+  }
+  $page->param(userlist => \@userlist);
+
 } elsif ($webvar{action} eq 'updacl') {
-  print "Updating ACL for $webvar{username}:<br>\n";
+
+  $page->param(username => $webvar{username});
   my $acl = 'b';
   if ($webvar{admin} eq 'on') {
@@ -448,14 +431,13 @@
 	($webvar{sysnet} eq 'on' ? 's' : '');
   }
-  print "New ACL: $acl<br>\n";
+  $page->param(acl => $acl);
 
   $sth = $ip_dbh->prepare("update users set acl='$acl' where username='$webvar{username}'");
   $sth->execute;
-  print "OK\n" if !$sth->err;
-
-  print qq(<hr><a href="admin.cgi?action=showusers">Back</a> to user listing\n);
+  $page->param(errmsg => $sth->errstr) if $sth->err;
 
 } elsif ($webvar{action} eq 'newuser') {
-  print "Adding user $webvar{username}...\n";
+
+  $page->param(username => $webvar{username});
   my $cr_pass = ($webvar{preenc} ? $webvar{password} :
 	crypt $webvar{password}, join('',('.','/',0..9,'A'..'Z','a'..'z')[rand 64, rand 64]));
@@ -463,19 +445,12 @@
 	"('$webvar{username}','$cr_pass','b')");
   $sth->execute;
-  if ($sth->err) {
-    print "<br>Error adding user: ".$sth->errstr;
-  } else {
-    print "OK\n";
-  }
-
-  print qq(<hr><a href="admin.cgi?action=showusers">Back</a> to user listing\n);
+  $page->param(errmsg => $sth->errstr) if $sth->err;
 
 } elsif ($webvar{action} eq 'deluser') {
-  print "Deleting user $webvar{username}.<br>\n";
+
+  $page->param(username => $webvar{username});
   $sth = $ip_dbh->prepare("delete from users where username='$webvar{username}'");
   $sth->execute;
-  print "OK\n" if !$sth->err;
-
-  print qq(<hr><a href="admin.cgi?action=showusers">Back</a> to user listing\n);
+  $page->param(errmsg => $sth->errstr) if $sth->err;
 
 } elsif ($webvar{action} eq 'emailnotice') {
Index: branches/htmlform/templates/admin/deluser.tmpl
===================================================================
--- branches/htmlform/templates/admin/deluser.tmpl	(revision 484)
+++ branches/htmlform/templates/admin/deluser.tmpl	(revision 484)
@@ -0,0 +1,3 @@
+Deleting user <TMPL_VAR NAME=username>...
+<TMPL_IF errmsg><br>Error deleting user: <TMPL_VAR NAME=errmsg><TMPL_ELSE>OK</TMPL_IF>
+<hr><a href="admin.cgi?action=showusers">Back</a> to user listing
Index: branches/htmlform/templates/admin/newuser.tmpl
===================================================================
--- branches/htmlform/templates/admin/newuser.tmpl	(revision 484)
+++ branches/htmlform/templates/admin/newuser.tmpl	(revision 484)
@@ -0,0 +1,3 @@
+Adding user <TMPL_VAR NAME=username>...
+<TMPL_IF errmsg><br>Error adding user: <TMPL_VAR NAME=errmsg><TMPL_ELSE>OK</TMPL_IF>
+<hr><a href="admin.cgi?action=showusers">Back</a> to user listing
Index: branches/htmlform/templates/admin/showpools.tmpl
===================================================================
--- branches/htmlform/templates/admin/showpools.tmpl	(revision 484)
+++ branches/htmlform/templates/admin/showpools.tmpl	(revision 484)
@@ -0,0 +1,7 @@
+IP Pools currently allocated:
+<table border=1>
+<tr><td>Pool</td><td># of free IPs</td></tr>
+<TMPL_LOOP NAME=poollist>
+<tr><td><a href="admin.cgi?action=tweakpool&amp;pool=<TMPL_VAR NAME=pool>"><TMPL_VAR NAME=pool></a></td><td><TMPL_VAR NAME=free></td></tr>
+</TMPL_LOOP>
+</table>
Index: branches/htmlform/templates/admin/showusers.tmpl
===================================================================
--- branches/htmlform/templates/admin/showusers.tmpl	(revision 484)
+++ branches/htmlform/templates/admin/showusers.tmpl	(revision 484)
@@ -0,0 +1,43 @@
+Notes:
+<ul>
+<li>Admin users automatically get all other priviledges.
+<li>Everyone has basic read access.
+</ul>
+<hr>Add new user:<form action="admin.cgi" method="POST">
+<fieldset><legend></legend>
+Username: <input name=username><br>
+Password: <input name=password> <input type=checkbox name=preenc>Password is pre-encrypted (MUST be crypt() encrypted)<br>
+<input type=submit value='Add user'><input type=hidden name=action value=newuser>
+</fieldset></form>
+
+<hr>Users with access:
+
+<table border="1">
+<tr><td></td><td align="center" colspan="3">General access</td></tr>
+<tr><td>Username</td><td>Add new</td><td>Change</td><td>Delete</td><td>Systems/Networking</td><td>Admin user</td></tr>
+
+<TMPL_LOOP name=userlist>
+<tr>
+<form action="admin.cgi" method="POST">
+<fieldset><legend></legend>
+<input type="hidden" name="action" value="updacl">
+<td><TMPL_VAR NAME=username><input type="hidden" name="username" value="<TMPL_VAR NAME=username>"></td>
+<td><input type=checkbox name="add"<TMPL_IF can_add> checked="checked"</TMPL_IF>></td>
+<td><input type=checkbox name="change"<TMPL_IF can_change> checked="checked"</TMPL_IF>></td>
+<td><input type=checkbox name="del"<TMPL_IF can_del> checked="checked"</TMPL_IF>></td>
+<td><input type=checkbox name="sysnet"<TMPL_IF sysnet> checked="checked"</TMPL_IF>></td>
+<td><input type=checkbox name="admin"<TMPL_IF is_admin> checked="checked"</TMPL_IF>></td>
+<td><input type=submit value="Update"></td>
+</fieldset></form> 
+<td>
+<form action="admin.cgi" method="POST">
+<fieldset><legend></legend>
+<input type=hidden name=action value=deluser>
+<input type=hidden name=username value="<TMPL_VAR NAME=username>">
+<input type=submit value="Delete user">
+</fieldset></form> 
+</td>
+<td><TMPL_VAR NAME=acl></td>
+</tr>
+</TMPL_LOOP>
+</table>
Index: branches/htmlform/templates/admin/touch.tmpl
===================================================================
--- branches/htmlform/templates/admin/touch.tmpl	(revision 484)
+++ branches/htmlform/templates/admin/touch.tmpl	(revision 484)
@@ -0,0 +1,5 @@
+Touching master <TMPL_VAR NAME=master>...<br>
+<TMPL_IF errmsg><p>Error updating modified timestamp on master <TMPL_VAR NAME=master>: <TMPL_VAR NAME=errmsg></p>
+<TMPL_ELSE>OK!
+</TMPL_IF>
+
Index: branches/htmlform/templates/admin/updacl.tmpl
===================================================================
--- branches/htmlform/templates/admin/updacl.tmpl	(revision 484)
+++ branches/htmlform/templates/admin/updacl.tmpl	(revision 484)
@@ -0,0 +1,4 @@
+Updating ACL for <TMPL_VAR NAME=username>:<br>
+New ACL: <TMPL_VAR NAME=acl><br>
+<TMPL_UNLESS errmsg>OK!<TMPL_ELSE><TMPL_VAR NAME=errmsg></TMPL_UNLESS>
+<hr><a href="admin.cgi?action=showusers">Back</a> to user listing
