Index: branches/stable/cgi-bin/main.cgi
===================================================================
--- branches/stable/cgi-bin/main.cgi	(revision 356)
+++ branches/stable/cgi-bin/main.cgi	(revision 366)
@@ -81,30 +81,8 @@
     print "<div type=heading align=center>Adding $cidr as master block....</div>\n";
 
-    # Allow transactions, and raise an exception on errors so we can catch it later.
-    # Use local to make sure these get "reset" properly on exiting this block
-    local $ip_dbh->{AutoCommit} = 0;
-    local $ip_dbh->{RaiseError} = 1;
-
-    # Wrap the SQL in a transaction
-    eval {
-      $sth = $ip_dbh->prepare("insert into masterblocks values ('$webvar{cidr}')");
-      $sth->execute;
-
-# Unrouted blocks aren't associated with a city (yet).  We don't rely on this
-# elsewhere though;  legacy data may have traps and pitfalls in it to break this.
-# Thus the "routed" flag.
-
-      $sth = $ip_dbh->prepare("insert into freeblocks (cidr,maskbits,city,routed)".
-	" values ('$webvar{cidr}',".$cidr->masklen.",'<NULL>','n')");
-      $sth->execute;
-
-      # If we get here, everything is happy.  Commit changes.
-      $ip_dbh->commit;
-    }; # end eval
-
-    if ($@) {
-      my $msg = $@;
+    my ($code,$msg) = addMaster($ip_dbh, $webvar{cidr});
+
+    if ($code eq 'FAIL') {
       carp "Transaction aborted because $msg";
-      eval { $ip_dbh->rollback; };
       syslog "err", "Could not add master block '$webvar{cidr}' to database: '$msg'";
       printError("Could not add master block $webvar{cidr} to database: $msg");
