Index: branches/stable/cgi-bin/main.cgi
===================================================================
--- branches/stable/cgi-bin/main.cgi	(revision 310)
+++ branches/stable/cgi-bin/main.cgi	(revision 315)
@@ -754,5 +754,5 @@
 	    " chose a smaller blocksize.";
 	}
-	if ($webvar{allocfrom} ne '-') {
+	if (defined $webvar{allocfrom} && $webvar{allocfrom} ne '-') {
 	  $sql = "select cidr from freeblocks where city='$city' and maskbits<=$webvar{maskbits}".
 		" and cidr <<= '$webvar{allocfrom}' and routed='".
@@ -827,4 +827,7 @@
     $i++;
   }
+# We're going to abuse $$PRIVDATA$$ to stuff in some stuff for billing.
+  $privdata .= "<input type=hidden name=billinguser value=$webvar{userid}>\n"
+	if $webvar{userid};
   $html =~ s/\$\$PRIVDATA\$\$/$privdata/g;
 
@@ -858,5 +861,11 @@
   if ($code eq 'OK') {
     if ($webvar{alloctype} =~ /^.i$/) {
-      print qq(<div class="center"><div class="heading">The IP $msg has been allocated to customer $webvar{custid}</div></div>);
+      $msg =~ s|/32||;
+      print qq(<div class="center"><div class="heading">The IP $msg has been allocated to customer $webvar{custid}</div>).
+	( ($webvar{alloctype} eq 'di' && $webvar{billinguser}) ?
+		qq(<div><a href="https://billing.example.com/extserv.pl?).
+		"action=new_radius_user&custid=$webvar{custid}&userid=$webvar{billinguser}".
+		qq(&ipdb=1&ip=$msg">Add this IP to RADIUS user table</a></div>)
+	: "</div>");
       # Notify tech@example.com
       mailNotify('tech@example.com',"ADDED: $disp_alloctypes{$webvar{alloctype}} allocation",
@@ -864,6 +873,14 @@
 	"Description: $webvar{desc}\n\nAllocated by: $authuser\n");
     } else {
+      my $netblock = new NetAddr::IP $webvar{fullcidr};
       print qq(<div class="center"><div class="heading">The block $webvar{fullcidr} was ).
-	"sucessfully added as: $disp_alloctypes{$webvar{alloctype}}</div></div>";
+	"sucessfully added as: $disp_alloctypes{$webvar{alloctype}}</div>".
+	( ($webvar{alloctype} eq 'pr' && $webvar{billinguser}) ?
+		qq(<div><a href="https://billing.example.com/extserv.pl?).
+		"action=new_radius_user&custid=$webvar{custid}&userid=$webvar{billinguser}".
+		"&route_subnet=".$netblock->addr."&subnet_slash=".$netblock->masklen.
+		"&include_routed_subnet=1&ipdb=1".
+		qq(">Add this netblock to RADIUS user table</a></div>)
+	: "</div>");
     }
     syslog "notice", "$authuser allocated '$webvar{fullcidr}' to '$webvar{custid}' as ".
@@ -942,7 +959,9 @@
   } else {
     $flag = 'n';
-    if ($webvar{alloctype} =~ /w./) {
-      $webvar{pop} = "Sudbury";
-    } elsif ($webvar{pop} =~ /^-$/) {
+    if ($webvar{alloctype} =~ /[wp][cr]|[ds][pi]/) {
+      # Set this forcibly rather than messing around elsewhere.  Yes, this *is* a hack.  PTHBTT!!
+      $webvar{pop} = 'Sudbury';
+    }
+    if ($webvar{pop} =~ /^-$/) {
       $flag = 'to route the block from/through';
     }
